Sfoglia il codice sorgente

Merge pull request #34 from schveiguy/addrcamera

Add rcamera.d binding
Steven Schveighoffer 2 anni fa
parent
commit
30c97fa287
6 ha cambiato i file con 335 aggiunte e 6 eliminazioni
  1. 6 0
      README.md
  2. 10 4
      generating.md
  3. 1 1
      source/raygui.d
  4. 1 0
      source/raylib/package.d
  5. 316 0
      source/raylib/rcamera.d
  6. 1 1
      source/raylib/rlgl.d

+ 6 - 0
README.md

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

+ 10 - 4
generating.md

@@ -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

+ 1 - 1
source/raygui.d

@@ -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
@@ -4378,5 +4377,6 @@ private int GetCodepointNext(const(char)* text, int* codepointSize) {
 
     return codepoint;
 }
+}      // RAYGUI_STANDALONE
 
 //! #endif      // RAYGUI_IMPLEMENTATION

+ 1 - 0
source/raylib/package.d

@@ -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;

+ 316 - 0
source/raylib/rcamera.d

@@ -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

+ 1 - 1
source/raylib/rlgl.d

@@ -106,7 +106,7 @@ import raylib;
 *
 **********************************************************************************************/
 
-extern (C):
+extern (C) @nogc nothrow:
 
 enum RLGL_VERSION = "4.5";