Re: Euphoria Chipmunk Physics

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...

I fixed the typo in the code. At cpDampedSpringInit. http://www.rapideuphoria.com/uploads/euchipmunkphy.zip

I assume you didn't get any closer to getting this working on OE.
If you study the inline assembly, at least you know precisely what needs to happen, and hopefully can then figure out a fudge, eg:

--public constant xcpBodyGetPosition = define_c_func(chip,"cpBodyGetPosition",{C_POINTER},C_POINTER) 
public constant xcpBodyGetPosition = define_c_proc(chip,"cpBodyGetPosition",{C_POINTER,C_POINTER}) 
 
global function cpBodyGetPosition(atom body) 
atom pMem = allocate(16) -- (actually a pair of 64-bit float return values) 
atom x, y 
 
    c_proc(xcpBodyGetPosition,{pMem,body}) 
    x = float64_to_atom(peek({pMem,8})) 
    y = float64_to_atom(peek({pMem+8,8})) 
    free(pMem) 
    return {x,y} 
end function 
 
--public constant xcpBodySetPosition = define_c_proc(chip,"cpBodySetPosition",{C_POINTER,C_POINTER}) 
public constant xcpBodySetPosition = define_c_proc(chip,"cpBodySetPosition",{C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_POINTER}) 
--                                                                       (parameters are really one pointer and two 64-bit floats) 
 
global procedure cpBodySetPosition(atom body, atom x, atom y) 
atom pMem = allocate(16) -- (for conversion only) 
sequence xy4 
    poke(pMem,atom_to_float64(x)) 
    poke(pMem+8,atom_to_float64(y)) 
    xy4 = peek4u({pMem,4}) -- (pass two 64-bit floats as 4 dwords) 
    free(pMem) 
    c_proc(xcpBodySetPosition,body&xy4) 
end procedure 
 
--public constant xcpBodyGetVelocity = define_c_func(chip,"cpBodyGetVelocity",{C_POINTER},C_POINTER) 
public constant xcpBodyGetVelocity = define_c_proc(chip,"cpBodyGetVelocity",{C_POINTER,C_POINTER}) 
 
global function cpBodyGetVelocity(atom body) 
atom pMem = allocate(16) 
atom x, y 
 
    c_proc(xcpBodyGetVelocity,{pMem,body}) 
    x = float64_to_atom(peek({pMem,8})) 
    y = float64_to_atom(peek({pMem+8,8})) 
    free(pMem) 
    return {x,y} 
end function 

HTH, Pete

EDIT: added a couple of missing ) and swapped body/pMem order, it now seems to work (on Phix anyway)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu