1. Raylib 3D

Hello,

So I recently tried making an example in 3D using the Euraylib wrapper I wrote. However I notice when it comes to camera functions, there's a little bit of things that might get a little iffy. I'm trying to make a Euphoria port of the 3D shapes example. However the camera C code is like this.

EDIT: I've added raymath functions to the raylib wrapper. I noticed they were included in the raylib.DLL when I used a program to view the functions in the DLL.

Camera camera = { 0 }; 
    camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; 
    camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; 
    camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; 
    camera.fovy = 45.0f; 
    camera.type = CAMERA_PERSPECTIVE; 

include std/machine.e 
include std/convert.e 
 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 600 
 
InitWindow(width,height,"3D Stuff") 
 
atom Camera = 0 
 
SetCameraMode(Camera,CAMERA_THIRD_PERSON) 
 
atom blue = bytes_to_int({0,0,255,255}) 
atom white = bytes_to_int({255,255,255,255}) 
 
SetTargetFPS(60) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(white) 
	 
	BeginMode3D(Camera) 
	 
	UpdateCamera(Camera) 
	 
        --first are x,y,z positions, next are for width,height and scale, then the color 
	DrawCube(-4.0,0.0,2.0,2.0,5.0,2.0,blue) 
	 
	EndMode3D() 
 
	DrawFPS(1,1) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 

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.

new topic     » topic index » view message » categorize

2. 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

P.S. I think that "fovy" is the FOV (field of view) Y offset value.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Raylib 3D

Thanks Greg,

I made the adjustments, I still can't see the cube in the example program I'm trying to make, though. I have updated the flags.e for the camera flags, which can be found at my github.

include std/machine.e 
include std/convert.e 
 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"3D Stuff") 
 
constant Vector3_X = 0, 
		 Vector3_Y = 4, 
		 Vector3_Z = 8, 
		 SIZEOF_VECTOR3 = 12, 
		 $ 
		  
constant Camera3D_Position = 0, 
		 Camera3D_Target = 12, 
		 Camera3D_Up = 24, 
		 Camera3D_Fovy = 36, 
		 Camera3D_Type = 40, 
		 SIZEOF_CAMERA3D = 44, 
		 $ 
 
atom cam = allocate_data(SIZEOF_CAMERA3D) 
mem_set(cam,0,SIZEOF_CAMERA3D) 
 
procedure poke_float(atom p,atom f) 
 
  poke(p,atom_to_float32(f)) 
	 
end procedure 
 
atom blue = bytes_to_int({0,0,255,255}) 
atom white = bytes_to_int({255,255,255,255}) 
 
SetTargetFPS(60) 
 
public procedure SetCameraPosition(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Position + Vector3_X,x) 
 poke_float(cam + Camera3D_Position + Vector3_Y,y) 
 poke_float(cam + Camera3D_Position + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraTarget(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Target + Vector3_X,x) 
 poke_float(cam + Camera3D_Target + Vector3_Y,y) 
 poke_float(cam + Camera3D_Target + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraUp(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Up + Vector3_X,x) 
 poke_float(cam + Camera3D_Up + Vector3_Y,y) 
 poke_float(cam + Camera3D_Up + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraFOVY(atom cam,atom fovy) 
 
 poke_float(cam + Camera3D_Fovy,fovy) 
	 
end procedure 
 
public procedure SetCameraType(atom cam,integer xtype) 
 
 poke4(cam + Camera3D_Type,xtype) 
	 
end procedure 
 
SetCameraPosition(cam,0,10.0,10.0) 
SetCameraTarget(cam,0,0,0) 
SetCameraUp(cam,0,1,0) 
SetCameraFOVY(cam,45.0) 
SetCameraType(cam,CAMERA_PERSPECTIVE) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(white) 
	 
	BeginMode3D(cam) 
	 
	DrawCube(-4.0,0.0,2.0,2.0,5.0,2.0,blue) 
	 
	DrawGrid(10,1.0) 
	 
	EndMode3D() 
 
	DrawFPS(1,1) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
new topic     » goto parent     » topic index » view message » categorize

4. Re: Raylib 3D

Hi, maybe it does not work, because the BeginMode3D argument should not be a pointer to struct? Am I correct?

 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UINT}), 
				xBeginDrawing = define_c_proc(ray,"+BeginDrawing",{}), 
				xEndDrawing = define_c_proc(ray,"+EndDrawing",{}), 
				xBeginMode2D = define_c_proc(ray,"+BeginMode2D",{C_POINTER}), 
				xEndMode2D = define_c_proc(ray,"+EndMode2D",{}), 
				xBeginMode3D = define_c_proc(ray,"+BeginMode3D",{C_POINTER}), 
				xEndMode3D = define_c_proc(ray,"+EndMode3D",{}), 
				xBeginTextureMode = define_c_proc(ray,"+BeginTextureMode",{C_POINTER}), 
				xEndTextureMode = define_c_proc(ray,"+EndTextureMode",{}) 
				 
 

void BeginMode3D(Camera3D camera);       

https://www.raylib.com/cheatsheet/cheatsheet.html

new topic     » goto parent     » topic index » view message » categorize

5. Re: Raylib 3D

Maccuq said...

Hi, maybe it does not work, because the BeginMode3D argument should not be a pointer to struct? Am I correct?

 
public constant xClearBackground = define_c_proc(ray,"+ClearBackground",{C_UINT}), 
				xBeginDrawing = define_c_proc(ray,"+BeginDrawing",{}), 
				xEndDrawing = define_c_proc(ray,"+EndDrawing",{}), 
				xBeginMode2D = define_c_proc(ray,"+BeginMode2D",{C_POINTER}), 
				xEndMode2D = define_c_proc(ray,"+EndMode2D",{}), 
				xBeginMode3D = define_c_proc(ray,"+BeginMode3D",{C_POINTER}), 
				xEndMode3D = define_c_proc(ray,"+EndMode3D",{}), 
				xBeginTextureMode = define_c_proc(ray,"+BeginTextureMode",{C_POINTER}), 
				xEndTextureMode = define_c_proc(ray,"+EndTextureMode",{}) 
				 
 

void BeginMode3D(Camera3D camera);       

https://www.raylib.com/cheatsheet/cheatsheet.html

I changed it to a C_UINT and it still doesen't work.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Raylib 3D

It works when you write it this way.

xBeginMode3D = define_c_proc(ray,"+BeginMode3D",{C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_INT}), 
 
public procedure BeginMode3D(atom px, atom py, atom pz, atom tx, atom ty, atom tz, atom ux, atom uy, atom uz, atom fov, integer mode) 
 
 c_proc(xBeginMode3D,{px, py, pz, tx, ty, tz, ux, uy, uz, fov, mode}) 
	 
end procedure 
new topic     » goto parent     » topic index » view message » categorize

7. Re: Raylib 3D

Maccuq said...

It works when you write it this way.

xBeginMode3D = define_c_proc(ray,"+BeginMode3D",{C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_INT}), 
 
public procedure BeginMode3D(atom px, atom py, atom pz, atom tx, atom ty, atom tz, atom ux, atom uy, atom uz, atom fov, integer mode) 
 
 c_proc(xBeginMode3D,{px, py, pz, tx, ty, tz, ux, uy, uz, fov, mode}) 
	 
end procedure 

Thank you Maccuq, it works!

EDIT: I've also updated some of the functions for rectangles and the Camera2D function as well. After looking at the raylib.h and structs and making Euraylib more Euphoria friendly. With all these structs, it sure would be nice if Euphoria had a built in struct system, hopefully in the very near future. ;)

include std/machine.e 
include std/convert.e 
 
include flags.e 
include Euraylib.ew 
 
atom width = 800 
atom height = 450 
 
InitWindow(width,height,"3D Stuff") 
 
constant Vector3_X = 0, 
		 Vector3_Y = 4, 
		 Vector3_Z = 8, 
		 SIZEOF_VECTOR3 = 12, 
		 $ 
		  
constant Camera3D_Position = 0, 
		 Camera3D_Target = 12, 
		 Camera3D_Up = 24, 
		 Camera3D_Fovy = 36, 
		 Camera3D_Type = 40, 
		 SIZEOF_CAMERA3D = 44, 
		 $ 
 
atom cam = allocate_data(SIZEOF_CAMERA3D) 
mem_set(cam,0,SIZEOF_CAMERA3D) 
 
procedure poke_float(atom p,atom f) 
 
  poke(p,atom_to_float32(f)) 
	 
end procedure 
 
atom blue = bytes_to_int({0,0,255,255}) 
atom white = bytes_to_int({255,255,255,255}) 
 
SetTargetFPS(60) 
 
public procedure SetCameraPosition(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Position + Vector3_X,x) 
 poke_float(cam + Camera3D_Position + Vector3_Y,y) 
 poke_float(cam + Camera3D_Position + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraTarget(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Target + Vector3_X,x) 
 poke_float(cam + Camera3D_Target + Vector3_Y,y) 
 poke_float(cam + Camera3D_Target + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraUp(atom cam,atom x,atom y,atom z) 
 
 poke_float(cam + Camera3D_Up + Vector3_X,x) 
 poke_float(cam + Camera3D_Up + Vector3_Y,y) 
 poke_float(cam + Camera3D_Up + Vector3_Z,z) 
	 
end procedure 
 
public procedure SetCameraFOVY(atom cam,atom fovy) 
 
 poke_float(cam + Camera3D_Fovy,fovy) 
	 
end procedure 
 
public procedure SetCameraType(atom cam,integer xtype) 
 
 poke4(cam + Camera3D_Type,xtype) 
	 
end procedure 
 
SetCameraPosition(cam,0,10.0,10.0) 
SetCameraTarget(cam,0,0,0) 
SetCameraUp(cam,0,1,0) 
SetCameraFOVY(cam,45.0) 
SetCameraType(cam,CAMERA_PERSPECTIVE) 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
	 
	ClearBackground(white) 
	 
	BeginMode3D(0,10.0,10.0,0,0,0,0,1,0,45.0,CAMERA_PERSPECTIVE) 
	 
	DrawCube(-4.0,0.0,2.0,2.0,5.0,2.0,blue) 
	 
	DrawGrid(10,1.0) 
	 
	EndMode3D() 
 
	DrawFPS(1,1) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu