Re: Wrapping Functions When Matrix is Involved

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

You just need to allocate the space for the floats, poke them into that space, and then pass the pointer to the function.

Not sure why we don't have peek/poke float functions in the standard library. But this is how you'd do it:

procedure poke_float32( atom ptr, object value ) 
 
    if atom( value ) then 
        value = {value} 
    end if 
 
    for i = 1 to length( value ) do 
        poke( ptr, atom_to_float32(value[i]) ) 
        ptr += sizeof(C_FLOAT) 
    end for 
 
end procedure 
 
public constant xNewtonCreateBox = define_c_func( nd,"NewtonCreateBox", {C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_INT,C_POINTER}, C_POINTER ) 
 
public function NewtonCreateBox( atom world, atom x, atom y, atom z, atom id, sequence matrix ) 
 
    -- we assume matrix is of non-zero length 
    atom p_matrix = allocate_data( sizeof(C_FLOAT) * length(matrix), TRUE ) -- cleanup = TRUE 
 
    poke_float32( p_matrix, matrix ) 
 
    return c_func( xNewtonCreateBox, {world,x,y,z,id,p_matrix} ) 
end function 

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu