Chipmunk queries

About Monkey 2 Forums Monkey 2 Programming Help Chipmunk queries

Tagged: 

This topic contains 20 replies, has 4 voices, and was last updated by  abakobo 2 years, 4 months ago.

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #6571

    peterigz
    Participant

    Having trouble figuring out how to use cpSpaceBBQuery (and I assume I’ll have trouble with the other queries as well). I guess I’m not using pointers properly but not sure how, anyone any ideas? Getting the error:

     Can’t find overload for ‘cpSpaceBBQuery:Void(chipmunk.cpSpace,chipmunk.cpBB,chipmunk.cpShapeFilter,Void(chipmunk.cpShape,Void Ptr),Void Ptr)’ with argument types (chipmunk.cpSpace,chipmunk.cpBB,chipmunk.cpShapeFilter,Void(chipmunk.cpShape,Void),Void Ptr)

    Have tried with lambda, function pointer and various other things. I’d like to pass in some meaningful data as well… test code:

    The chipmunk docs for AABB queries is here for reference: http://chipmunk-physics.net/release/ChipmunkLatest-Docs/#Queries-AABBQueries

    #6572

    codifies
    Participant

    initial guess would be to try using a function instead of a lambda ?

    #6573

    peterigz
    Participant

    I tried that first, see the CallBack function in the class, but unfortunately same issue. The void pointers are confusing me, as far as I know they are function pointers but in the chipmunk docs it seems you can pass data. I’m don’t know much about c though!

    #6574

    codifies
    Participant

    afaik you’d still need to cast the value to a void pointer tho… better yet a void pointer to a struct

    – sorry the lambda was only a guess, do let us all know how you get on, examples of stuff like this would be rather useful…

    #6576

    peterigz
    Participant

    Thanks. It was Ptr I was missing, this compiles ok now, will see how it goes with an actual sample and data going through it:

    Works with the callback as well.

    #6577

    peterigz
    Participant

    Next problem is the UserData in cpShape, I’m having trouble casting it to anything. It does equal something but gives a memory access error if I try and access it. This feels like a bug in Monkey now but not sure:

    The App object that I’m passing in seems to cast fine though so that’s something.

    #6578

    codifies
    Participant
    [/crayon]

    for

    [/crayon]

    (Linux difference??)

    so you might beat me to it, but you’re trying to print data.Test when it should probably be a ptr ? (initial guess!) edit: missed the [0] doh so not that…

    #6579

    codifies
    Participant

    if you do this

    [/crayon]

    then the whole thing works

    I had to do this tho!

    [/crayon]

    which seems wrong!

    I think it might possibly be to do with string assignment and class creating but even if I assign Test in a MyClass’s new Method (and print it) the issue still exists the only thing that seems to work is if I print the field from outside the class

    I’d say this is defiantly one to report on github

    btw assume you know you can set body userdata ?

    Probably teaching grannie to suck eggs here but I’d recommend wrapping all the body specific stuff into its own class and keeping it in its own seperate file, that way you can just create/draw and object and keep all the chipmonk stuff out of your main code. you could probably set a class global (static) field with things like world etc that you need for object creation…

    #6580

    abakobo
    Participant

    I haven’t read all the topic… but I made some little things with chipmunk: https://github.com/abakobo/chipmunk_monkey2

    It includes a modified hellochipmunk.monkey2 with MouseJoint/DistanceQuery and a debugdraw with rounded end fat segment and rounded corner polys that were missing on Mark’s debugdraw.
    The debugdraw also includes a “complete”/”fast draw” and a camera using affineMat3 matrix that you can test in the stress_test example. I plan to work on it a bit more but have no time for now..

    For the mouse joint I use filter this way:

    [/crayon]

    Used stringToULong because there’s no stringToUInt…

    No data however..

    As c2mx2 is not copying the api docs I use the original official C api doc: https://chipmunk-physics.net/release/ChipmunkLatest-API-Reference/

    #6581

    peterigz
    Participant

    Thanks for looking at this. Still the same issue here, I’m on Windows 10 so looks like there’s differences in behaviour as I don’t get the error on the filter (maybe I should?). Will post on GitHub as I think there’s something odd going on. This is the current test code with a separate function for a sanity check:

    #6586

    codifies
    Participant

    did you try the print immediately after

    [/crayon]

    I’d be curious to know if that makes it work like it does here…

    #6588

    peterigz
    Participant

    Yeah I tried that but it didn’t make any difference here on Windows 10 – I should try on my Mac as well really. I think the memory pointer doesn’t point to the right place for whatever reason but I guess you need to run it though a proper c debugger to get a better idea of what’s going on, hopefully Mark can do that.

    #6589

    codifies
    Participant

    The crash is happening when the string is being retained, and indeed works fine if you use an int instead – so looks like you might have stumbled on something fundamental…

    #6591

    Mark Sibly
    Keymaster
    This wont work…

    …because ‘data’ is a local variable and will go out of scope when the ctor returns, meaning there will be nothing keeping the MyClass instance alive.

    The main problem here is binding an mx2 object to a ‘native’ cp object. I think a ‘generic’ way to do this would be very useful and will look into it soon.

    #6592

    peterigz
    Participant

    I just posted on github and closed that as it makes sense now, here’s updated code, a field that references itself seems a bit funny, but why not? If you have a gameobject, that has a cpShape as field that needs to reference the gameobject when passed to a callback, then it seems like an ok solution to me:

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.