forum-msg-id-133890-edit

Original date:2019-05-27 00:56:52 Edited by: Icy_Viking Subject: Re: Wrapping Functions When Matrix is Involved

ghaberek said...

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

Thanks, this works, except for I don't think Euphoria has a sizeof function. I briefed through the manual, but didn't find anything.

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu