forum-msg-id-134055-edit

Original date:2019-07-11 10:01:59 Edited by: ghaberek Subject: Re: Raylib 3D

Icy_Viking said...

When it comes to Euphoria port, I'm not sure how I'd get around that camera stuff. There is no function for something like SetCameraPosition() in RayLib. If anyone has a workaround, that would be great.

Here is the header for the camera stuff: https://github.com/raysan5/raylib/blob/master/src/camera.h

It looks like Camera is just a typedef for struct Camera3D. So when you see Camera camera = {0}, that's just allocating a Camera3D structure on the stack and initializing it to zero. We have to create our structs on the heap with allocate_data().

-- Camera camera = { 0 }; 
atom camera = allocate_data( SIZEOF_CAMERA3D ) 
mem_set( camera, 0, SIZEOF_CAMERA3D ) 

The rest of the values are structure members, some of which are nested structures themselves, in this case Vector3D. So we need to determine the member offsets and then poke values into the allocated memory manually. Here are the structure offsets.

constant 
    Vector3__x      =  0, -- float 
    Vector3__y      =  4, -- float 
    Vector3__z      =  8, -- float 
    SIZEOF_VECTOR3  = 12, 
$ 
 
constant 
    Camera3D__position  =  0, -- Vector3  
    Camera3D__target    = 12, -- Vector3 
    Camera3D__up        = 24, -- Vector3 
    Camera3D__fovy      = 36, -- float 
    Camera3D__type      = 40, -- int 
    SIZEOF_CAMERA3D     = 44, 
$ 

And here are the routines to poke each of the member values.

procedure poke_float( atom p, atom f ) 
    poke( p, atom_to_float32(f) ) 
end procedure 
 
public procedure SetCameraPosition( atom camera, atom x, atom y, atom z ) 
     
    poke_float( camera + Camera3D__position + Vector3__x, x ) 
    poke_float( camera + Camera3D__position + Vector3__y, y ) 
    poke_float( camera + Camera3D__position + Vector3__z, z ) 
     
end procedure 
 
public procedure SetCameraTarget( atom camera, atom x, atom y, atom z ) 
     
    poke_float( camera + Camera3D__target + Vector3__x, x ) 
    poke_float( camera + Camera3D__target + Vector3__y, y ) 
    poke_float( camera + Camera3D__target + Vector3__z, z ) 
     
end procedure 
 
public procedure SetCameraUp( atom camera, atom x, atom y, atom z ) 
     
    poke_float( camera + Camera3D__up + Vector3__x, x ) 
    poke_float( camera + Camera3D__up + Vector3__y, y ) 
    poke_float( camera + Camera3D__up + Vector3__z, z ) 
     
end procedure 
 
public procedure SetCameraFOVY( atom camera, atom fovy ) 
     
    poke_float( camera + Camera3D__fovy, fovy ) 
     
end procedure 
 
public procedure SetCameraType( atom camera, integer _type ) 
     
    poke4( camera + Camera3D__type, _type ) 
     
end procedure 

Hope that helps.

-Greg

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu