Skip to content

Commit

Permalink
chore: updates to get rayex working with raylib 5 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleclair authored Aug 26, 2024
1 parent 8aa6baf commit 48ab1a6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 79 deletions.
38 changes: 7 additions & 31 deletions c_src/rayex/rayex.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,40 +343,16 @@ UNIFEX_TERM get_mouse_position(UnifexEnv *env) {
// Gestures and Touch Handling Functions (Module: rgestures)

// Camera System Functions (Module: rcamera)
UNIFEX_TERM set_camera_mode(UnifexEnv *env, camera_3d c, int mode) {
SetCameraMode(CAMERA3D(c), mode);
uintptr_t res = (uintptr_t)&c;
return set_camera_mode_result(env, res);
}

UNIFEX_TERM update_camera(UnifexEnv *env, camera_3d c) {
UNIFEX_TERM update_camera(UnifexEnv *env, camera_3d c, int mode) {
Camera3D camera = CAMERA3D(c);
UpdateCamera(&camera);
return update_camera_result(env, E_CAMERA3D(camera));
UpdateCamera(&camera, mode);
return update_camera_result_ok(env);
}

UNIFEX_TERM set_camera_pan_control(UnifexEnv *env, int key_pan) {
SetCameraPanControl(key_pan);
return set_camera_pan_control_result_ok(env);
}

UNIFEX_TERM set_camera_alt_control(UnifexEnv *env, int key_alt) {
SetCameraAltControl(key_alt);
return set_camera_alt_control_result_ok(env);
}

UNIFEX_TERM set_camera_smooth_zoom_control(UnifexEnv *env,
int key_smooth_zoom) {
SetCameraSmoothZoomControl(key_smooth_zoom);
return set_camera_smooth_zoom_control_result_ok(env);
}

UNIFEX_TERM set_camera_move_controls(UnifexEnv *env, int key_front,
int key_back, int key_right, int key_left,
int key_up, int key_down) {
SetCameraMoveControls(key_front, key_back, key_right, key_left, key_up,
key_down);
return set_camera_move_controls_result_ok(env);
UNIFEX_TERM update_camera_pro(UnifexEnv *env, camera_3d c, vector3 movement, vector3 rotation, double zoom) {
Camera3D camera = CAMERA3D(c);
UpdateCameraPro(&camera, VECTOR3(movement), VECTOR3(rotation), zoom);
return update_camera_pro_result_ok(env);
}

/**********
Expand Down
24 changes: 9 additions & 15 deletions c_src/rayex/rayex.spec.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,15 @@ spec get_mouse_position() :: xy :: vector2
# Gestures and Touch Handling Functions (Module: rgestures)

# Camera System Functions (Module: rcamera)
spec set_camera_mode(camera :: camera_3d, mode :: int) :: camera_id :: ulong
spec update_camera(camera :: camera_3d) :: camera :: camera_3d

spec set_camera_pan_control(key_pan :: int) :: :ok :: label
spec set_camera_alt_control(key_alt :: int) :: :ok :: label
spec set_camera_smooth_zoom_control(key_smooth_zoom :: int) :: :ok :: label

spec set_camera_move_controls(
key_front :: int,
key_back :: int,
key_right :: int,
key_left :: int,
key_up :: int,
key_down :: int
) :: :ok :: label
spec update_camera(camera :: camera_3d, mode :: int) :: :ok :: label

spec update_camera_pro(
camera :: camera_3d,
movement :: vector3,
rotation :: vector3,
zoom :: float
) ::
:ok :: label

##########
# SHAPES #
Expand Down
4 changes: 2 additions & 2 deletions examples/3d_picking/lib/the3d_picking.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule The3dPicking do
projection: 0
}

set_camera_mode(camera, 1)
update_camera(camera, 1)

game_loop(%{camera: camera, hit?: false})
end
Expand All @@ -43,7 +43,7 @@ defmodule The3dPicking do
hit?
end

state = %{state | hit?: hit?, camera: update_camera(camera)}
state = %{state | hit?: hit?, camera: update_camera(camera, 1)}

#
# draw
Expand Down
37 changes: 6 additions & 31 deletions lib/rayex/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,11 @@ defmodule Rayex.Core do

# Camera System Functions (Module: rcamera)

@doc "Set camera mode (multiple camera modes available)"
@spec set_camera_mode(S.Camera3D.t(), integer()) :: integer()
defdelegate set_camera_mode(camera_3d, mode), to: Raylib

@doc "Update camera position for selected mode"
@spec update_camera(S.Camera3D.t()) :: S.Camera3D.t()
defdelegate update_camera(camera_3d), to: Raylib

@doc "Set camera pan key to combine with mouse movement (free camera)"
@spec set_camera_pan_control(integer()) :: :ok
defdelegate set_camera_pan_control(key_pan), to: Raylib

@doc "Set camera alt key to combine with mouse movement (free camera)"
@spec set_camera_alt_control(integer()) :: :ok
defdelegate set_camera_alt_control(key_alt), to: Raylib

@doc "Set camera smooth zoom key to combine with mouse (free camera)"
@spec set_camera_smooth_zoom_control(integer()) :: :ok
defdelegate set_camera_smooth_zoom_control(key_smooth_zoom), to: Raylib

@doc "Set camera move controls (1st person and 3rd person cameras)"
@spec set_camera_move_controls(integer(), integer(), integer(), integer(), integer(), integer()) ::
:ok
defdelegate set_camera_move_controls(
key_front,
key_back,
key_right,
key_left,
key_up,
key_down
),
to: Raylib
@spec update_camera(S.Camera3D.t(), integer()) :: :ok
defdelegate update_camera(camera_3d, mode), to: Raylib

@doc "Update camera movement/rotation"
@spec update_camera_pro(S.Camera3D.t(), S.Vector3.t(), S.Vector3.t(), float()) :: :ok
defdelegate update_camera_pro(camera_3d, movement, rotation, zoom), to: Raylib
end

0 comments on commit 48ab1a6

Please sign in to comment.