Skip to content

Commit

Permalink
Merge pull request #34 from schveiguy/addrcamera
Browse files Browse the repository at this point in the history
Add rcamera.d binding
  • Loading branch information
schveiguy authored Apr 10, 2023
2 parents 040b38f + 49582d2 commit 30c97fa
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ void main()
}
```

# Port of raylib examples

@D-a-n-i-l-o has been kind enough to port a large amount of the raylib examples from the C library to D (maybe all of them at this point!)

Please see his [repository](https://github.com/D-a-n-i-l-o/raylib-d_examples) for more information.

# BetterC support (Experimental)

[BetterC](https://dlang.org/spec/betterc.html) support has been added for the raylib-d binding. This should work just as well as the original binding, but be usable with the `betterC` compilation option. No specific configuration is necessary.
Expand Down
14 changes: 10 additions & 4 deletions generating.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

In order to update `raylib-d` to work with a newer version of `raylib`, the headers must be regenerated with [dstep].

Three modules should be regenerated: `raylib`, `raymath` and `rlgl`.
Four modules should be regenerated: `raylib`, `raymath`, `rlgl`, and `rcamera`.

`rcamera.h` is an odd one, because it depends on raylib types, but does not include `raylib.h` directly. So dstep has trouble with it. In order to properly generate the binding, you must add the following to the file, inside the header. I prefer to do it in an `#else` clause after the `#ifdef RCAMERA_STANDALONE`:

```c
#include "raylib.h"
```

Run the following command from the `raylib/src` directory. Note: path/to/raylib-d should be the path to the raylib-d repository that you have on your system.

```
dstep raylib.h raymath.h rlgl.h -o path/to/raylib-d/source/raylib --space-after-function-name=false --skip Vector2 \
--skip Vector3 --skip Vector4 --skip Quaternion --skip Matrix --skip Rectangle --skip RL_MALLOC --skip RL_CALLOC \
--skip RL_REALLOC --skip RL_FREE
dstep raylib.h raymath.h rlgl.h rcamera.h -o path/to/raylib-d/source/raylib --space-after-function-name=false \
--skip Vector2 --skip Vector3 --skip Vector4 --skip Quaternion --skip Matrix --skip Rectangle \
--skip RL_MALLOC --skip RL_CALLOC --skip RL_REALLOC --skip RL_FREE
```

Note: we're skipping a couple symbols because we define them manually in `raylib_types`. We also skip memory functions
Expand Down
2 changes: 1 addition & 1 deletion source/raygui.d
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,6 @@ private const(char)* CodepointToUTF8(int codepoint, int* byteSize) {

return utf8;
}
} // RAYGUI_STANDALONE

// Get next codepoint in a UTF-8 encoded text, scanning until '\0' is found
// When a invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned
Expand Down Expand Up @@ -4378,5 +4377,6 @@ private int GetCodepointNext(const(char)* text, int* codepointSize) {

return codepoint;
}
} // RAYGUI_STANDALONE

//! #endif // RAYGUI_IMPLEMENTATION
1 change: 1 addition & 0 deletions source/raylib/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public
import raylib.rlgl;
import raylib.reasings;
import raylib.raymath;
import raylib.rcamera;
import raylib.raymathext;
import raylib.raylib_types;
import raylib.binding;
Expand Down
316 changes: 316 additions & 0 deletions source/raylib/rcamera.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
/*******************************************************************************************
*
* rcamera - Basic camera system with support for multiple camera modes
*
* CONFIGURATION:
*
* #define CAMERA_IMPLEMENTATION
* Generates the implementation of the library into the included file.
* If not defined, the library is in header only mode and can be included in other headers
* or source files without problems. But only ONE file should hold the implementation.
*
* #define CAMERA_STANDALONE
* If defined, the library can be used as standalone as a camera system but some
* functions must be redefined to manage inputs accordingly.
*
* CONTRIBUTORS:
* Ramon Santamaria: Supervision, review, update and maintenance
* Christoph Wagner: Complete redesign, using raymath (2022)
* Marc Palau: Initial implementation (2014)
*
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2022-2023 Christoph Wagner (@Crydsch) & Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
module raylib.rcamera;

import raylib;

extern (C) @nogc nothrow:

//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
// Function specifiers definition // Functions defined as 'extern' by default (implicit specifiers)

enum CAMERA_CULL_DISTANCE_NEAR = RL_CULL_DISTANCE_NEAR;
enum CAMERA_CULL_DISTANCE_FAR = RL_CULL_DISTANCE_FAR;

//----------------------------------------------------------------------------------
// Types and Structures Definition
// NOTE: Below types are required for CAMERA_STANDALONE usage
//----------------------------------------------------------------------------------

// Vector2, 2 components

// Vector x component
// Vector y component

// Vector3, 3 components

// Vector x component
// Vector y component
// Vector z component

// Camera type, defines a camera position/orientation in 3d space

// Camera position
// Camera target it looks-at
// Camera up vector (rotation over its axis)
// Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
// Camera projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC

// Camera type fallback, defaults to Camera3D

// Camera projection

// Perspective projection
// Orthographic projection

// Camera system modes

// Camera custom, controlled by user (UpdateCamera() does nothing)
// Camera free mode
// Camera orbital, around target, zoom supported
// Camera first person
// Camera third person

//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------

// Prevents name mangling of functions

Vector3 GetCameraForward(Camera* camera);
Vector3 GetCameraUp(Camera* camera);
Vector3 GetCameraRight(Camera* camera);

// Camera movement
void CameraMoveForward(Camera* camera, float distance, bool moveInWorldPlane);
void CameraMoveUp(Camera* camera, float distance);
void CameraMoveRight(Camera* camera, float distance, bool moveInWorldPlane);
void CameraMoveToTarget(Camera* camera, float delta);

// Camera rotation
void CameraYaw(Camera* camera, float angle, bool rotateAroundTarget);
void CameraPitch(Camera* camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
void CameraRoll(Camera* camera, float angle);

Matrix GetCameraViewMatrix(Camera* camera);
Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);

// CAMERA_H

/***********************************************************************************
*
* CAMERA IMPLEMENTATION
*
************************************************************************************/

// Required for vector maths:
// Vector3Add()
// Vector3Subtract()
// Vector3Scale()
// Vector3Normalize()
// Vector3Distance()
// Vector3CrossProduct()
// Vector3RotateByAxisAngle()
// Vector3Angle()
// Vector3Negate()
// MatrixLookAt()
// MatrixPerspective()
// MatrixOrtho()
// MatrixIdentity()

// raylib required functionality:
// GetMouseDelta()
// GetMouseWheelMove()
// IsKeyDown()
// IsKeyPressed()
// GetFrameTime()

//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------

// Camera mouse movement sensitivity
// TODO: it should be independant of framerate

// Radians per second

// PLAYER (used by camera)

//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
//...

//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
// Returns the cameras forward vector (normalized)

// Returns the cameras up vector (normalized)
// Note: The up vector might not be perpendicular to the forward vector

// Returns the cameras right vector (normalized)

// Moves the camera in its forward direction

// Project vector onto world plane

// Scale by distance

// Move position and target

// Moves the camera in its up direction

// Scale by distance

// Move position and target

// Moves the camera target in its current right direction

// Project vector onto world plane

// Scale by distance

// Move position and target

// Moves the camera position closer/farther to/from the camera target

// Apply delta

// Distance must be greater than 0

// Set new distance by moving the position along the forward vector

// Rotates the camera around its up vector
// Yaw is "looking left and right"
// If rotateAroundTarget is false, the camera rotates around its position
// Note: angle must be provided in radians

// Rotation axis

// View vector

// Rotate view vector around up axis

// Move position relative to target

// rotate around camera.position

// Move target relative to position

// Rotates the camera around its right vector, pitch is "looking up and down"
// - lockView prevents camera overrotation (aka "somersaults")
// - rotateAroundTarget defines if rotation is around target or around its position
// - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
// NOTE: angle must be provided in radians

// Up direction

// View vector

// In these camera modes we clamp the Pitch angle
// to allow only viewing straight up or down.

// Clamp view up

// avoid numerical errors

// Clamp view down

// downwards angle is negative
// avoid numerical errors

// Rotation axis

// Rotate view vector around right axis

// Move position relative to target

// rotate around camera.position

// Move target relative to position

// Rotate up direction around right axis

// Rotates the camera around its forward vector
// Roll is "turning your head sideways to the left or right"
// Note: angle must be provided in radians

// Rotation axis

// Rotate up direction around forward axis

// Returns the camera view matrix

// Returns the camera projection matrix

// Update camera position for selected mode
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM

// Orbital can just orbit

// Camera rotation

// Camera movement

//if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
//if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);

// Zoom target distance

// !CAMERA_STANDALONE

// Update camera movement, movement/rotation values should be provided by user

// Required values
// movement.x - Move forward/backward
// movement.y - Move right/left
// movement.z - Move up/down
// rotation.x - yaw
// rotation.y - pitch
// rotation.z - roll
// zoom - Move towards target

// Camera rotation

// Camera movement

// Zoom target distance

// CAMERA_IMPLEMENTATION
2 changes: 1 addition & 1 deletion source/raylib/rlgl.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import raylib;
*
**********************************************************************************************/

extern (C):
extern (C) @nogc nothrow:

enum RLGL_VERSION = "4.5";

Expand Down

0 comments on commit 30c97fa

Please sign in to comment.