Skip to content

Commit

Permalink
chore: update deps & fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shiryel committed Aug 26, 2024
1 parent 48ab1a6 commit 8119386
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 149 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ rayex-*.tar

/c_src/rayex/_generated/
.ccls-cache/
/.direnv
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[![API Docs](https://img.shields.io/badge/api-docs-blue.svg?style=flat)](https://hexdocs.pm/rayex/)
[![Run Tests](https://github.com/shiryel/rayex/actions/workflows/test.yml/badge.svg)](https://github.com/shiryel/rayex/actions/workflows/test.yml)

[![Twitter](https://img.shields.io/twitter/follow/shiryel_.svg?style=social)](https://twitter.com/shiryel_)
[![BlueSky](https://img.shields.io/badge/bsky-follow-blue.svg?logo=data:image/svg%2bxml;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAMZlWElmTU0AKgAAAAgABgESAAMAAAABAAEAAAEaAAUAAAABAAAAVgEbAAUAAAABAAAAXgEoAAMAAAABAAIAAAExAAIAAAAVAAAAZodpAAQAAAABAAAAfAAAAAAAAABIAAAAAQAAAEgAAAABUGl4ZWxtYXRvciBQcm8gMy41LjEAAAAEkAQAAgAAABQAAACyoAEAAwAAAAEAAQAAoAIABAAAAAEAAAAQoAMABAAAAAEAAAAQAAAAADIwMjM6MTI6MjEgMTg6NDc6NTUAs+CevwAAAAlwSFlzAAALEwAACxMBAJqcGAAAA7BpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDYuMC4wIj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OkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgojNmzBAAAB2klEQVQ4EaVTPWsUURS95824grqJMRuSSlMkdUQ0pNHOP2Al+AMklSKIBhEXkmFRsbFKE2zERtFKIY0khR+IYCystDAiajDGzfoBupl3vPe5s/tc1CZ3Pu45995z5857MyKbNPTOcL8DqyJ4lKRydfUMvvyvZ+Uiyxu5nAA54R0uoC/LZ1V8vCV6TYcj9Sk8+1uT3oz7nPC25vb8znPWKWBUPAzPxf4aD0SxAPtnOK7iBSUtcQjTGnwKsHMre897PTWOFKGeaY568K7ychEzD5HVVOg+COIhQkklyXlruMoJY+vgTXWVkIluFLeSKl+OYh0IGVtP/TQh0HOsk4gQZBmDl7n95w++0nmGolQBmwp0UrEHddv7UgmjbuU0vuUJDmp2Xi8TxLZFSbfYauZzh0OmtUWUxhR0AmQKbaHqFvuHren+3/Aek0GjRTae7My4F8KnChPjkRWrG+qi+Ec0MbJWRSNMoJuwQ5PdYqt/ol/JUiQs4MBGIoNGQoPP5+SB4odFtu2J6wTutHkL6Lbcb5zHS6Ohgb4/9Tiq/E2rxtzb0la5lqYyp/hrOw55kaQ4VvA/3m3gEofypq9pw936o5yqn8VzK9yV8TDJkzrN421NufKuiu9Fg037X+nGlJl3fvK1AAAAAElFTkSuQmCC)](shiryel.bsky.social)

Rayex provides Elixir NIF bindings to [Raylib](https://www.raylib.com/)

> WIP: many of the functions on raylib are yet not implemented, check the [contributing section](#contributing) to help
> NOTE: some of the functions on raylib are not implemented yet, check the [contributing section](#contributing) to help
![](examples/3d_picking.gif)

Expand All @@ -19,7 +19,7 @@ The package can be installed by adding `rayex` to your list of dependencies in `
```elixir
def deps do
[
{:rayex, "~> 0.0.2"}
{:rayex, "~> 0.0.3"}
]
end
```
Expand All @@ -32,7 +32,7 @@ You need the following packages installed on your system:
* elixir
* erlang (headers)
* pkg-config
* raylib v4.2
* raylib v5
* glibc
* clang-tools (formatter)

Expand Down Expand Up @@ -62,7 +62,7 @@ You can also run our examples!!

```bash
cd examples/3d_picking/
mix deps.gen
mix deps.get
iex -S mix
```
```exs
Expand Down
6 changes: 4 additions & 2 deletions bundlex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def project() do
[
natives: natives(Bundlex.platform())
natives: natives(Bundlex.get_target())
]
end

Expand All @@ -12,7 +12,9 @@
rayex: [
sources: ["rayex.c"],
interface: [:nif, :cnode],
pkg_configs: ["raylib"],
os_deps: [
raylib: {:pkg_config, "raylib"}
],
preprocessor: Unifex
]
]
Expand Down
37 changes: 34 additions & 3 deletions c_src/rayex/rayex.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ UNIFEX_TERM toggle_fullscreen(UnifexEnv *env) {

// Cursor-related functions

UNIFEX_TERM show_cursor(UnifexEnv *env) {
ShowCursor();
return show_cursor_result_ok(env);
}

UNIFEX_TERM hide_cursor(UnifexEnv *env) {
HideCursor();
return hide_cursor_result_ok(env);
}

UNIFEX_TERM is_cursor_hidden(UnifexEnv *env) {
bool res = IsCursorHidden();
return is_cursor_hidden_result(env, res);
}

UNIFEX_TERM enable_cursor(UnifexEnv *env) {
EnableCursor();
return enable_cursor_result_ok(env);
}

UNIFEX_TERM disable_cursor(UnifexEnv *env) {
DisableCursor();
return disable_cursor_result_ok(env);
}

UNIFEX_TERM is_cursor_on_screen(UnifexEnv *env) {
bool res = IsCursorOnScreen();
return is_cursor_on_screen_result(env, res);
}

// Drawing-related functions

UNIFEX_TERM clear_background(UnifexEnv *env, color c) {
Expand Down Expand Up @@ -346,13 +376,14 @@ UNIFEX_TERM get_mouse_position(UnifexEnv *env) {
UNIFEX_TERM update_camera(UnifexEnv *env, camera_3d c, int mode) {
Camera3D camera = CAMERA3D(c);
UpdateCamera(&camera, mode);
return update_camera_result_ok(env);
return update_camera_result(env, E_CAMERA3D(camera));
}

UNIFEX_TERM update_camera_pro(UnifexEnv *env, camera_3d c, vector3 movement, vector3 rotation, double zoom) {
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);
return update_camera_pro_result(env, E_CAMERA3D(camera));
}

/**********
Expand Down
12 changes: 9 additions & 3 deletions c_src/rayex/rayex.spec.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec toggle_fullscreen() :: :ok :: label

# Cursor-related functions

spec show_cursor() :: :ok :: label
spec hide_cursor() :: :ok :: label
spec is_cursor_hidden() :: result :: bool
spec enable_cursor() :: :ok :: label
spec disable_cursor() :: :ok :: label
spec is_cursor_on_screen() :: result :: bool

# Drawing-related functions
spec clear_background(color :: color) :: :ok :: label
spec begin_drawing() :: :ok :: label
Expand Down Expand Up @@ -79,15 +86,14 @@ spec get_mouse_position() :: xy :: vector2
# Gestures and Touch Handling Functions (Module: rgestures)

# Camera System Functions (Module: rcamera)
spec update_camera(camera :: camera_3d, mode :: int) :: :ok :: label
spec update_camera(camera :: camera_3d, mode :: int) :: camera :: camera_3d

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

##########
# SHAPES #
Expand Down
16 changes: 14 additions & 2 deletions examples/3d_picking/lib/the3d_picking.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule The3dPicking do

@cube_position %S.Vector3{x: 0.0, y: 1.0, z: 0.0}
@mouse_left 0
@mouse_right 1
@camera_first_person 4
@color_white %S.Color{r: 245, g: 245, b: 245, a: 255}
@color_darkgray %S.Color{r: 80, g: 80, b: 80, a: 255}
@color_gray %S.Color{r: 130, g: 130, b: 130, a: 255}
Expand All @@ -25,15 +27,18 @@ defmodule The3dPicking do
target: %S.Vector3{x: 0.0, y: 0.0, z: 0.0},
up: %S.Vector3{x: 0.0, y: 1.0, z: 0.0},
fovy: 45.0,
# perspective projection
projection: 0
}

update_camera(camera, 1)
camera = update_camera(camera, @camera_first_person)

game_loop(%{camera: camera, hit?: false})
end

defp game_loop(%{camera: camera, hit?: hit?} = state) do
camera = (is_cursor_hidden?() && update_camera(camera, @camera_first_person)) || camera

ray = get_mouse_position() |> get_mouse_ray(camera)

hit? =
Expand All @@ -43,7 +48,12 @@ defmodule The3dPicking do
hit?
end

state = %{state | hit?: hit?, camera: update_camera(camera, 1)}
if mouse_button_pressed?(@mouse_right) do
(is_cursor_hidden?() && enable_cursor()) ||
disable_cursor()
end

state = %{state | hit?: hit?, camera: camera}

#
# draw
Expand All @@ -70,6 +80,8 @@ defmodule The3dPicking do
# --- 3D ---

draw_text("Try selecting the box with mouse!", 240, 10, 20, @color_darkgray)
draw_text("Right click mouse to toggle camera controls", 10, 430, 10, @color_gray)

draw_fps(10, 10)

end_drawing()
Expand Down
Loading

0 comments on commit 8119386

Please sign in to comment.