REVIEWED: Camera redesign PR
This commit is contained in:
parent
73989a4981
commit
ea590c44a9
34 changed files with 321 additions and 268 deletions
|
@ -30,12 +30,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (position, target, up vector)
|
// Define the camera to look into our 3d world (position, target, up vector)
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 0.0f, 2.0f, 4.0f };
|
camera.position = (Vector3){ 0.0f, 2.0f, 4.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 60.0f;
|
camera.fovy = 60.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
camera.swingCounter = 1; // Enable view bobbing
|
|
||||||
|
|
||||||
int cameraMode = CAMERA_FIRST_PERSON;
|
int cameraMode = CAMERA_FIRST_PERSON;
|
||||||
|
|
||||||
|
@ -51,36 +50,46 @@ int main(void)
|
||||||
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
||||||
}
|
}
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Switch camera mode
|
// Switch camera mode
|
||||||
if (IsKeyPressed(KEY_ONE)) {
|
if (IsKeyPressed(KEY_ONE))
|
||||||
|
{
|
||||||
cameraMode = CAMERA_FREE;
|
cameraMode = CAMERA_FREE;
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_TWO)) {
|
|
||||||
|
if (IsKeyPressed(KEY_TWO))
|
||||||
|
{
|
||||||
cameraMode = CAMERA_FIRST_PERSON;
|
cameraMode = CAMERA_FIRST_PERSON;
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_THREE)) {
|
|
||||||
|
if (IsKeyPressed(KEY_THREE))
|
||||||
|
{
|
||||||
cameraMode = CAMERA_THIRD_PERSON;
|
cameraMode = CAMERA_THIRD_PERSON;
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_FOUR)) {
|
|
||||||
|
if (IsKeyPressed(KEY_FOUR))
|
||||||
|
{
|
||||||
cameraMode = CAMERA_ORBITAL;
|
cameraMode = CAMERA_ORBITAL;
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch camera projection
|
// Switch camera projection
|
||||||
if (IsKeyPressed(KEY_P)) {
|
if (IsKeyPressed(KEY_P))
|
||||||
if (camera.projection == CAMERA_PERSPECTIVE) {
|
{
|
||||||
|
if (camera.projection == CAMERA_PERSPECTIVE)
|
||||||
|
{
|
||||||
// Create isometric view
|
// Create isometric view
|
||||||
cameraMode = CAMERA_THIRD_PERSON;
|
cameraMode = CAMERA_THIRD_PERSON;
|
||||||
// Note: The target distance is related to the render distance in the orthographic projection
|
// Note: The target distance is related to the render distance in the orthographic projection
|
||||||
|
|
|
@ -31,10 +31,12 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -31,16 +31,13 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
||||||
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
||||||
|
|
||||||
Ray ray = { 0 }; // Picking line ray
|
Ray ray = { 0 }; // Picking line ray
|
||||||
|
RayCollision collision = { 0 }; // Ray collision hit info
|
||||||
RayCollision collision = { 0 };
|
|
||||||
|
|
||||||
EnableCursor(); // Disable camera controls
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -50,7 +47,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON); // Update camera
|
if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON);
|
||||||
|
|
||||||
// Toggle camera controls
|
// Toggle camera controls
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
|
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
|
||||||
|
|
|
@ -95,12 +95,12 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector
|
||||||
camera.fovy = 60.0f; // Camera field-of-view Y
|
camera.fovy = 60.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
camera.swingCounter = 1; // Enable view bobbing
|
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -27,16 +27,17 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f };
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
Vector2 cubeScreenPosition = { 0.0f, 0.0f };
|
Vector2 cubeScreenPosition = { 0.0f, 0.0f };
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -67,7 +68,9 @@ int main(void)
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
|
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
|
||||||
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))/2, 25, 20, GRAY);
|
|
||||||
|
DrawText(TextFormat("Cube position in screen space coordinates: [%i, %i]", (int)cubeScreenPosition.x, (int)cubeScreenPosition.y), 10, 10, 20, LIME);
|
||||||
|
DrawText("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
@ -102,15 +100,11 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texture); // Unload texture
|
UnloadTexture(texture); // Unload texture
|
||||||
|
UnloadModelAnimations(anims, animsCount); // Unload model animations data
|
||||||
|
UnloadModel(model); // Unload model
|
||||||
|
|
||||||
// Unload model animations data
|
CloseWindow(); // Close window and OpenGL context
|
||||||
for (unsigned int i = 0; i < animsCount; i++) UnloadModelAnimation(anims[i]);
|
|
||||||
RL_FREE(anims);
|
|
||||||
|
|
||||||
UnloadModel(model); // Unload model
|
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -28,15 +28,15 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 5.0f, 4.0f, 5.0f };
|
camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture
|
Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture
|
||||||
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of billboard
|
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
|
||||||
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f };
|
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
|
||||||
|
|
||||||
// Entire billboard texture, source is used to take a segment from a larger texture.
|
// Entire billboard texture, source is used to take a segment from a larger texture.
|
||||||
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
|
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
|
||||||
|
@ -55,11 +55,13 @@ int main(void)
|
||||||
float distanceRotating;
|
float distanceRotating;
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -26,7 +26,12 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { { 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 16.0f, 14.0f, 16.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||||
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
||||||
|
@ -36,18 +41,19 @@ int main(void)
|
||||||
|
|
||||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||||
|
|
||||||
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
|
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
|
||||||
|
|
||||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -28,7 +28,13 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { { 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 0.2f, 0.4f, 0.2f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.185f, 0.4f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
Image imMap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
Image imMap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||||
Texture2D cubicmap = LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM)
|
Texture2D cubicmap = LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM)
|
||||||
|
@ -37,7 +43,7 @@ int main(void)
|
||||||
|
|
||||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||||
|
|
||||||
// Get map image data to be used for collision detection
|
// Get map image data to be used for collision detection
|
||||||
Color *mapPixels = LoadImageColors(imMap);
|
Color *mapPixels = LoadImageColors(imMap);
|
||||||
|
@ -45,7 +51,8 @@ int main(void)
|
||||||
|
|
||||||
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
|
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -26,25 +26,31 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||||
|
|
||||||
// Define our custom camera to look into our 3d world
|
// Define our custom camera to look into our 3d world
|
||||||
Camera camera = { { 18.0f, 18.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 18.0f, 21.0f, 18.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||||
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
||||||
|
|
||||||
Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM)
|
Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM)
|
||||||
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
|
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
|
||||||
|
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||||
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position
|
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position
|
||||||
|
|
||||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -59,7 +59,8 @@ int main(void)
|
||||||
|
|
||||||
bool selected = false; // Selected object flag
|
bool selected = false; // Selected object flag
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load gltf model
|
// Load gltf model
|
||||||
Model model = LoadModel("resources/models/gltf/robot.glb");
|
Model model = LoadModel("resources/models/gltf/robot.glb");
|
||||||
|
@ -51,11 +51,13 @@ int main(void)
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -33,11 +33,12 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 1.5f, 1.5f, 1.5f }; // Camera position
|
camera.position = (Vector3){ 1.5f, 1.5f, 1.5f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.4f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.4f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
char modelFileName[128] = "resources/models/m3d/CesiumMan.m3d";
|
char modelFileName[128] = "resources/models/m3d/CesiumMan.m3d";
|
||||||
|
@ -53,12 +54,13 @@ int main(void)
|
||||||
int animFrameCounter = 0, animId = 0;
|
int animFrameCounter = 0, animId = 0;
|
||||||
ModelAnimation *anims = LoadModelAnimations(modelFileName, &animsCount); // Load skeletal animation data
|
ModelAnimation *anims = LoadModelAnimations(modelFileName, &animsCount); // Load skeletal animation data
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -43,7 +43,7 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load MagicaVoxel files
|
// Load MagicaVoxel files
|
||||||
Model models[MAX_VOX_FILES] = { 0 };
|
Model models[MAX_VOX_FILES] = { 0 };
|
||||||
|
@ -69,7 +69,8 @@ int main(void)
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,8 @@ int main(void)
|
||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 8.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 8.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Ray ray = { 0 }; // Picking ray
|
Ray ray = { 0 }; // Picking ray
|
||||||
|
|
||||||
|
@ -64,7 +64,6 @@ int main(void)
|
||||||
Vector3 sp = (Vector3){ -30.0f, 5.0f, 5.0f };
|
Vector3 sp = (Vector3){ -30.0f, 5.0f, 5.0f };
|
||||||
float sr = 4.0f;
|
float sr = 4.0f;
|
||||||
|
|
||||||
EnableCursor(); // Disable camera controls
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
@ -43,11 +43,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 16.0f, 16.0f, 16.0f };
|
camera.position = (Vector3){ 16.0f, 16.0f, 16.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
float rotationSpeed = 0.2f; // General system rotation speed
|
float rotationSpeed = 0.2f; // General system rotation speed
|
||||||
|
|
||||||
|
@ -56,7 +56,8 @@ int main(void)
|
||||||
float moonRotation = 0.0f; // Rotation of moon around itself
|
float moonRotation = 0.0f; // Rotation of moon around itself
|
||||||
float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
|
float moonOrbitRotation = 0.0f; // Rotation of moon around earth in degrees
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,12 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { { 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 1.0f, 1.0f, 1.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 4.0f, 1.0f, 4.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load skybox model
|
// Load skybox model
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
|
@ -87,12 +92,13 @@ int main(void)
|
||||||
UnloadImage(img);
|
UnloadImage(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -31,11 +31,11 @@ int main()
|
||||||
|
|
||||||
// Initialize the camera
|
// Initialize the camera
|
||||||
Camera3D camera = { 0 };
|
Camera3D camera = { 0 };
|
||||||
camera.position = (Vector3){ 30.0f, 20.0f, 30.0f };
|
camera.position = (Vector3){ 30.0f, 20.0f, 30.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 70.0f;
|
camera.fovy = 70.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Specify the amount of blocks in each direction
|
// Specify the amount of blocks in each direction
|
||||||
const int numBlocks = 15;
|
const int numBlocks = 15;
|
||||||
|
|
|
@ -50,7 +50,7 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load plane model from a generated mesh
|
// Load plane model from a generated mesh
|
||||||
Model model = LoadModelFromMesh(GenMeshPlane(10.0f, 10.0f, 3, 3));
|
Model model = LoadModelFromMesh(GenMeshPlane(10.0f, 10.0f, 3, 3));
|
||||||
|
@ -80,12 +80,12 @@ int main(void)
|
||||||
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ -2, 1, 2 }, Vector3Zero(), GREEN, shader);
|
lights[2] = CreateLight(LIGHT_POINT, (Vector3){ -2, 1, 2 }, Vector3Zero(), GREEN, shader);
|
||||||
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 2, 1, -2 }, Vector3Zero(), BLUE, shader);
|
lights[3] = CreateLight(LIGHT_POINT, (Vector3){ 2, 1, -2 }, Vector3Zero(), BLUE, shader);
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -42,11 +42,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 8.0f, 8.0f, 8.0f };
|
camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 1.5f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model
|
Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map)
|
Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map)
|
||||||
|
@ -67,7 +67,6 @@ int main(void)
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,12 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - fog");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - fog");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {
|
Camera camera = { 0 };
|
||||||
(Vector3){ 2.0f, 2.0f, 6.0f }, // position
|
camera.position = (Vector3){ 2.0f, 2.0f, 6.0f }; // Camera position
|
||||||
(Vector3){ 0.0f, 0.5f, 0.0f }, // target
|
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
|
||||||
(Vector3){ 0.0f, 1.0f, 0.0f }, // up
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
45.0f, CAMERA_PERSPECTIVE }; // fov, type
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load models and texture
|
// Load models and texture
|
||||||
Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
|
Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
|
||||||
|
@ -84,12 +85,12 @@ int main(void)
|
||||||
// Using just 1 point lights
|
// Using just 1 point lights
|
||||||
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
|
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -44,11 +44,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ -125.0f, 125.0f, -125.0f };
|
camera.position = (Vector3){ -125.0f, 125.0f, -125.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Define mesh to be instanced
|
// Define mesh to be instanced
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
|
@ -94,12 +94,12 @@ int main(void)
|
||||||
Material matDefault = LoadMaterialDefault();
|
Material matDefault = LoadMaterialDefault();
|
||||||
matDefault.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
|
matDefault.maps[MATERIAL_MAP_DIFFUSE].color = BLUE;
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -42,11 +42,11 @@ int main(void)
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f };
|
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 1.0f, -1.0f };
|
camera.target = (Vector3){ 0.0f, 1.0f, -1.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model
|
Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/models/watermill_diffuse.png"); // Load model texture
|
Texture2D texture = LoadTexture("resources/models/watermill_diffuse.png"); // Load model texture
|
||||||
|
@ -60,12 +60,12 @@ int main(void)
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -75,13 +75,18 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { { 2.0f, 3.0f, 2.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 2.0f, 3.0f, 2.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
Model model = LoadModel("resources/models/church.obj"); // Load OBJ model
|
Model model = LoadModel("resources/models/church.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map)
|
Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map)
|
||||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set model diffuse texture
|
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set model diffuse texture
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
// Load all postpro shaders
|
// Load all postpro shaders
|
||||||
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
||||||
|
@ -107,12 +112,12 @@ int main(void)
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -40,6 +40,7 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.7f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.7f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 65.0f; // Camera field-of-view Y
|
camera.fovy = 65.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Load raymarching shader
|
// Load raymarching shader
|
||||||
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
||||||
|
@ -56,12 +57,12 @@ int main(void)
|
||||||
|
|
||||||
float runTime = 0.0f;
|
float runTime = 0.0f;
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -39,15 +39,15 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib - simple shader mask");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - simple shader mask");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 0.0f, 1.0f, 2.0f };
|
camera.position = (Vector3){ 0.0f, 1.0f, 2.0f }; // Camera position
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
// Define our three models to show the shader on
|
// Define our three models to show the shader on
|
||||||
Mesh torus = GenMeshTorus(0.3f, 1, 16, 32);
|
Mesh torus = GenMeshTorus(0.3f, 1, 16, 32);
|
||||||
|
@ -83,14 +83,14 @@ int main(void)
|
||||||
model2.materials[0].shader = shader;
|
model2.materials[0].shader = shader;
|
||||||
|
|
||||||
int framesCounter = 0;
|
int framesCounter = 0;
|
||||||
Vector3 rotation = { 0 }; // Model rotation angles
|
Vector3 rotation = { 0 }; // Model rotation angles
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
SetTargetFPS(60); // Set to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -116,9 +116,9 @@ int main(void)
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
DrawModel(model1, (Vector3){0.5,0,0}, 1, WHITE);
|
DrawModel(model1, (Vector3){ 0.5f, 0.0f, 0.0f }, 1, WHITE);
|
||||||
DrawModelEx(model2, (Vector3){-.5,0,0}, (Vector3){1,1,0}, 50, (Vector3){1,1,1}, WHITE);
|
DrawModelEx(model2, (Vector3){ -0.5f, 0.0f, 0.0f }, (Vector3){ 1.0f, 1.0f, 0.0f }, 50, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
|
||||||
DrawModel(model3,(Vector3){0,0,-1.5}, 1, WHITE);
|
DrawModel(model3,(Vector3){ 0.0f, 0.0f, -1.5f }, 1, WHITE);
|
||||||
DrawGrid(10, 1.0f); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
|
@ -29,10 +29,8 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include "raymath.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
#define GLSL_VERSION 330
|
#define GLSL_VERSION 330
|
||||||
|
@ -44,26 +42,26 @@
|
||||||
#define MAX_STARS 400
|
#define MAX_STARS 400
|
||||||
|
|
||||||
// Spot data
|
// Spot data
|
||||||
typedef struct {
|
typedef struct Spot {
|
||||||
Vector2 pos;
|
Vector2 position;
|
||||||
Vector2 vel;
|
Vector2 speed;
|
||||||
float inner;
|
float inner;
|
||||||
float radius;
|
float radius;
|
||||||
|
|
||||||
// Shader locations
|
// Shader locations
|
||||||
unsigned int posLoc;
|
unsigned int positionLoc;
|
||||||
unsigned int innerLoc;
|
unsigned int innerLoc;
|
||||||
unsigned int radiusLoc;
|
unsigned int radiusLoc;
|
||||||
} Spot;
|
} Spot;
|
||||||
|
|
||||||
// Stars in the star field have a position and velocity
|
// Stars in the star field have a position and velocity
|
||||||
typedef struct Star {
|
typedef struct Star {
|
||||||
Vector2 pos;
|
Vector2 position;
|
||||||
Vector2 vel;
|
Vector2 speed;
|
||||||
} Star;
|
} Star;
|
||||||
|
|
||||||
void UpdateStar(Star *s);
|
static void UpdateStar(Star *s);
|
||||||
void ResetStar(Star *s);
|
static void ResetStar(Star *s);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
@ -75,7 +73,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib - shader spotlight");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shader spotlight");
|
||||||
HideCursor();
|
HideCursor();
|
||||||
|
|
||||||
Texture texRay = LoadTexture("resources/raysan.png");
|
Texture texRay = LoadTexture("resources/raysan.png");
|
||||||
|
@ -108,7 +106,7 @@ int main(void)
|
||||||
innerName[6] = '0' + i;
|
innerName[6] = '0' + i;
|
||||||
radiusName[6] = '0' + i;
|
radiusName[6] = '0' + i;
|
||||||
|
|
||||||
spots[i].posLoc = GetShaderLocation(shdrSpot, posName);
|
spots[i].positionLoc = GetShaderLocation(shdrSpot, posName);
|
||||||
spots[i].innerLoc = GetShaderLocation(shdrSpot, innerName);
|
spots[i].innerLoc = GetShaderLocation(shdrSpot, innerName);
|
||||||
spots[i].radiusLoc = GetShaderLocation(shdrSpot, radiusName);
|
spots[i].radiusLoc = GetShaderLocation(shdrSpot, radiusName);
|
||||||
|
|
||||||
|
@ -124,20 +122,20 @@ int main(void)
|
||||||
// and initialize the shader locations
|
// and initialize the shader locations
|
||||||
for (int i = 0; i < MAX_SPOTS; i++)
|
for (int i = 0; i < MAX_SPOTS; i++)
|
||||||
{
|
{
|
||||||
spots[i].pos.x = (float)GetRandomValue(64, screenWidth - 64);
|
spots[i].position.x = (float)GetRandomValue(64, screenWidth - 64);
|
||||||
spots[i].pos.y = (float)GetRandomValue(64, screenHeight - 64);
|
spots[i].position.y = (float)GetRandomValue(64, screenHeight - 64);
|
||||||
spots[i].vel = (Vector2){ 0, 0 };
|
spots[i].speed = (Vector2){ 0, 0 };
|
||||||
|
|
||||||
while ((fabs(spots[i].vel.x) + fabs(spots[i].vel.y)) < 2)
|
while ((fabs(spots[i].speed.x) + fabs(spots[i].speed.y)) < 2)
|
||||||
{
|
{
|
||||||
spots[i].vel.x = GetRandomValue(-400, 40) / 10.0f;
|
spots[i].speed.x = GetRandomValue(-400, 40) / 10.0f;
|
||||||
spots[i].vel.y = GetRandomValue(-400, 40) / 10.0f;
|
spots[i].speed.y = GetRandomValue(-400, 40) / 10.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
spots[i].inner = 28.0f * (i + 1);
|
spots[i].inner = 28.0f * (i + 1);
|
||||||
spots[i].radius = 48.0f * (i + 1);
|
spots[i].radius = 48.0f * (i + 1);
|
||||||
|
|
||||||
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
|
SetShaderValue(shdrSpot, spots[i].positionLoc, &spots[i].position.x, SHADER_UNIFORM_VEC2);
|
||||||
SetShaderValue(shdrSpot, spots[i].innerLoc, &spots[i].inner, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shdrSpot, spots[i].innerLoc, &spots[i].inner, SHADER_UNIFORM_FLOAT);
|
||||||
SetShaderValue(shdrSpot, spots[i].radiusLoc, &spots[i].radius, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shdrSpot, spots[i].radiusLoc, &spots[i].radius, SHADER_UNIFORM_FLOAT);
|
||||||
}
|
}
|
||||||
|
@ -161,21 +159,21 @@ int main(void)
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
Vector2 mp = GetMousePosition();
|
Vector2 mp = GetMousePosition();
|
||||||
spots[i].pos.x = mp.x;
|
spots[i].position.x = mp.x;
|
||||||
spots[i].pos.y = screenHeight - mp.y;
|
spots[i].position.y = screenHeight - mp.y;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spots[i].pos.x += spots[i].vel.x;
|
spots[i].position.x += spots[i].speed.x;
|
||||||
spots[i].pos.y += spots[i].vel.y;
|
spots[i].position.y += spots[i].speed.y;
|
||||||
|
|
||||||
if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
|
if (spots[i].position.x < 64) spots[i].speed.x = -spots[i].speed.x;
|
||||||
if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
|
if (spots[i].position.x > (screenWidth - 64)) spots[i].speed.x = -spots[i].speed.x;
|
||||||
if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
|
if (spots[i].position.y < 64) spots[i].speed.y = -spots[i].speed.y;
|
||||||
if (spots[i].pos.y > (screenHeight - 64)) spots[i].vel.y = -spots[i].vel.y;
|
if (spots[i].position.y > (screenHeight - 64)) spots[i].speed.y = -spots[i].speed.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
|
SetShaderValue(shdrSpot, spots[i].positionLoc, &spots[i].position.x, SHADER_UNIFORM_VEC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
@ -188,7 +186,7 @@ int main(void)
|
||||||
for (int n = 0; n < MAX_STARS; n++)
|
for (int n = 0; n < MAX_STARS; n++)
|
||||||
{
|
{
|
||||||
// Single pixel is just too small these days!
|
// Single pixel is just too small these days!
|
||||||
DrawRectangle((int)stars[n].pos.x, (int)stars[n].pos.y, 2, 2, WHITE);
|
DrawRectangle((int)stars[n].position.x, (int)stars[n].position.y, 2, 2, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
|
@ -213,7 +211,6 @@ int main(void)
|
||||||
DrawText("Pitch Black", (int)(screenWidth*0.2f), screenHeight/2, 20, GREEN);
|
DrawText("Pitch Black", (int)(screenWidth*0.2f), screenHeight/2, 20, GREEN);
|
||||||
DrawText("Dark", (int)(screenWidth*.66f), screenHeight/2, 20, GREEN);
|
DrawText("Dark", (int)(screenWidth*.66f), screenHeight/2, 20, GREEN);
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
@ -230,26 +227,26 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ResetStar(Star *s)
|
static void ResetStar(Star *s)
|
||||||
{
|
{
|
||||||
s->pos = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
s->position = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
s->vel.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
s->speed.x = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
s->vel.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
s->speed.y = (float)GetRandomValue(-1000, 1000)/100.0f;
|
||||||
|
|
||||||
} while (!(fabs(s->vel.x) + (fabs(s->vel.y) > 1)));
|
} while (!(fabs(s->speed.x) + (fabs(s->speed.y) > 1)));
|
||||||
|
|
||||||
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8.0f, 8.0f }));
|
s->position = Vector2Add(s->position, Vector2Multiply(s->speed, (Vector2){ 8.0f, 8.0f }));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateStar(Star *s)
|
static void UpdateStar(Star *s)
|
||||||
{
|
{
|
||||||
s->pos = Vector2Add(s->pos, s->vel);
|
s->position = Vector2Add(s->position, s->speed);
|
||||||
|
|
||||||
if ((s->pos.x < 0) || (s->pos.x > GetScreenWidth()) ||
|
if ((s->position.x < 0) || (s->position.x > GetScreenWidth()) ||
|
||||||
(s->pos.y < 0) || (s->pos.y > GetScreenHeight()))
|
(s->position.y < 0) || (s->position.y > GetScreenHeight()))
|
||||||
{
|
{
|
||||||
ResetStar(s);
|
ResetStar(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,16 +96,13 @@ int main(void)
|
||||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
int camera_mode = CAMERA_ORBITAL;
|
int camera_mode = CAMERA_ORBITAL;
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
||||||
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
||||||
|
|
||||||
DisableCursor(); // Catch cursor
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
// Use the default font
|
// Use the default font
|
||||||
Font font = GetFontDefault();
|
Font font = GetFontDefault();
|
||||||
float fontSize = 8.0f;
|
float fontSize = 8.0f;
|
||||||
|
@ -135,6 +132,10 @@ int main(void)
|
||||||
|
|
||||||
// Array filled with multiple random colors (when multicolor mode is set)
|
// Array filled with multiple random colors (when multicolor mode is set)
|
||||||
Color multi[TEXT_MAX_LAYERS] = {0};
|
Color multi[TEXT_MAX_LAYERS] = {0};
|
||||||
|
|
||||||
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
@ -265,6 +265,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "audio_stream_effects", "exa
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textures_textured_curve", "examples\textures_textured_curve.vcxproj", "{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textures_textured_curve", "examples\textures_textured_curve.vcxproj", "{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "models_loading_m3d", "examples\models_loading_m3d.vcxproj", "{6D9E00D8-2893-45E4-9363-3F7F61D416BD}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug.DLL|x64 = Debug.DLL|x64
|
Debug.DLL|x64 = Debug.DLL|x64
|
||||||
|
@ -2225,6 +2227,22 @@ Global
|
||||||
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x64.Build.0 = Release|x64
|
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x64.Build.0 = Release|x64
|
||||||
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x86.ActiveCfg = Release|Win32
|
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x86.ActiveCfg = Release|Win32
|
||||||
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x86.Build.0 = Release|Win32
|
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug.DLL|x64.Build.0 = Debug.DLL|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release.DLL|x64.ActiveCfg = Release.DLL|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release.DLL|x64.Build.0 = Release.DLL|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release.DLL|x86.Build.0 = Release.DLL|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release|x64.Build.0 = Release|x64
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD}.Release|x86.Build.0 = Release|Win32
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -2359,6 +2377,7 @@ Global
|
||||||
{1DE84812-E143-4C4B-A61D-9267AAD55401} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}
|
{1DE84812-E143-4C4B-A61D-9267AAD55401} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}
|
||||||
{4A87569C-4BD3-4113-B4B9-573D65B3D3F8} = {CC132A4D-D081-4C26-BFB9-AB11984054F8}
|
{4A87569C-4BD3-4113-B4B9-573D65B3D3F8} = {CC132A4D-D081-4C26-BFB9-AB11984054F8}
|
||||||
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}
|
{769FF0C1-4424-4FA3-BC44-D7A7DA312A06} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}
|
||||||
|
{6D9E00D8-2893-45E4-9363-3F7F61D416BD} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}
|
SolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}
|
||||||
|
|
|
@ -1156,7 +1156,7 @@ RLAPI float GetGesturePinchAngle(void); // Get gesture pinch ang
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Camera System Functions (Module: rcamera)
|
// Camera System Functions (Module: rcamera)
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
RLAPI void UpdateCamera(Camera3D *camera, int mode); // Update camera position for selected mode
|
RLAPI void UpdateCamera(Camera *camera, int mode); // Update camera position for selected mode
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Basic Shapes Drawing Functions (Module: shapes)
|
// Basic Shapes Drawing Functions (Module: shapes)
|
||||||
|
|
106
src/rcamera.h
106
src/rcamera.h
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* rcamera - Basic camera system for multiple camera modes
|
* rcamera - Basic camera system with support for multiple camera modes
|
||||||
*
|
*
|
||||||
* CONFIGURATION:
|
* CONFIGURATION:
|
||||||
*
|
*
|
||||||
|
@ -15,13 +15,13 @@
|
||||||
*
|
*
|
||||||
* CONTRIBUTORS:
|
* CONTRIBUTORS:
|
||||||
* Ramon Santamaria: Supervision, review, update and maintenance
|
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||||
* Christoph Wagner: Redesign (2022)
|
* Christoph Wagner: Complete redesign, using raymath (2022)
|
||||||
* Marc Palau: Initial implementation (2014)
|
* Marc Palau: Initial implementation (2014)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
|
* 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
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
@ -43,9 +43,6 @@
|
||||||
#ifndef RCAMERA_H
|
#ifndef RCAMERA_H
|
||||||
#define RCAMERA_H
|
#define RCAMERA_H
|
||||||
|
|
||||||
// The only dependency // TODO review standalone mode
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -86,6 +83,8 @@
|
||||||
int projection; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
int projection; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||||
} Camera3D;
|
} Camera3D;
|
||||||
|
|
||||||
|
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
|
||||||
|
|
||||||
// Camera system modes
|
// Camera system modes
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CAMERA_CUSTOM = 0,
|
CAMERA_CUSTOM = 0,
|
||||||
|
@ -115,19 +114,21 @@
|
||||||
extern "C" { // Prevents name mangling of functions
|
extern "C" { // Prevents name mangling of functions
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Vector3 GetCameraForward(Camera3D* camera);
|
Vector3 GetCameraForward(Camera *camera);
|
||||||
Vector3 GetCameraUp(Camera3D* camera);
|
Vector3 GetCameraUp(Camera *camera);
|
||||||
Vector3 GetCameraRight(Camera3D* camera);
|
Vector3 GetCameraRight(Camera *camera);
|
||||||
void CameraMoveForward(Camera3D* camera, float distance, bool moveInWorldPlane);
|
|
||||||
void CameraMoveUp(Camera3D* camera, float distance);
|
void CameraMoveForward(Camera *camera, float distance, bool moveInWorldPlane);
|
||||||
void CameraMoveRight(Camera3D* camera, float distance, bool moveInWorldPlane);
|
void CameraMoveUp(Camera *camera, float distance);
|
||||||
void CameraZoom(Camera3D* camera, float delta);
|
void CameraMoveRight(Camera *camera, float distance, bool moveInWorldPlane);
|
||||||
void CameraYaw(Camera3D* camera, float angle, bool rotateAroundTarget);
|
void CameraMoveToTarget(Camera *camera, float delta);
|
||||||
void CameraPitch(Camera3D* camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
|
|
||||||
void CameraRoll(Camera3D* camera, float angle);
|
void CameraYaw(Camera *camera, float angle, bool rotateAroundTarget);
|
||||||
void CameraViewBobbing(Camera3D* camera);
|
void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
|
||||||
Matrix GetCameraViewMatrix(Camera3D* camera);
|
void CameraRoll(Camera *camera, float angle);
|
||||||
Matrix GetCameraProjectionMatrix(Camera3D* camera, float aspect);
|
|
||||||
|
Matrix GetCameraViewMatrix(Camera *camera);
|
||||||
|
Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
@ -144,10 +145,12 @@ Matrix GetCameraProjectionMatrix(Camera3D* camera, float aspect);
|
||||||
|
|
||||||
#if defined(CAMERA_IMPLEMENTATION)
|
#if defined(CAMERA_IMPLEMENTATION)
|
||||||
|
|
||||||
|
|
||||||
|
#include "raymath.h" // Required for some vector maths
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#define CAMERA_MOVE_SPEED 0.09f
|
#define CAMERA_MOVE_SPEED 0.09f
|
||||||
#define CAMERA_ROTATION_SPEED 0.03f
|
#define CAMERA_ROTATION_SPEED 0.03f
|
||||||
|
|
||||||
|
@ -185,20 +188,20 @@ Matrix GetCameraProjectionMatrix(Camera3D* camera, float aspect);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Returns the cameras forward vector (normalized)
|
// Returns the cameras forward vector (normalized)
|
||||||
Vector3 GetCameraForward(Camera3D *camera)
|
Vector3 GetCameraForward(Camera *camera)
|
||||||
{
|
{
|
||||||
return Vector3Normalize(Vector3Subtract(camera->target, camera->position));
|
return Vector3Normalize(Vector3Subtract(camera->target, camera->position));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the cameras up vector (normalized)
|
// Returns the cameras up vector (normalized)
|
||||||
// Note: The up vector might not be perpendicular to the forward vector
|
// Note: The up vector might not be perpendicular to the forward vector
|
||||||
Vector3 GetCameraUp(Camera3D *camera)
|
Vector3 GetCameraUp(Camera *camera)
|
||||||
{
|
{
|
||||||
return Vector3Normalize(camera->up);
|
return Vector3Normalize(camera->up);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the cameras right vector (normalized)
|
// Returns the cameras right vector (normalized)
|
||||||
Vector3 GetCameraRight(Camera3D *camera)
|
Vector3 GetCameraRight(Camera *camera)
|
||||||
{
|
{
|
||||||
Vector3 forward = GetCameraForward(camera);
|
Vector3 forward = GetCameraForward(camera);
|
||||||
Vector3 up = GetCameraUp(camera);
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
@ -206,7 +209,7 @@ Vector3 GetCameraRight(Camera3D *camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves the camera in its forward direction
|
// Moves the camera in its forward direction
|
||||||
void CameraMoveForward(Camera3D *camera, float distance, bool moveInWorldPlane)
|
void CameraMoveForward(Camera *camera, float distance, bool moveInWorldPlane)
|
||||||
{
|
{
|
||||||
Vector3 forward = GetCameraForward(camera);
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
|
||||||
|
@ -226,7 +229,7 @@ void CameraMoveForward(Camera3D *camera, float distance, bool moveInWorldPlane)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves the camera in its up direction
|
// Moves the camera in its up direction
|
||||||
void CameraMoveUp(Camera3D *camera, float distance)
|
void CameraMoveUp(Camera *camera, float distance)
|
||||||
{
|
{
|
||||||
Vector3 up = GetCameraUp(camera);
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
|
||||||
|
@ -239,7 +242,7 @@ void CameraMoveUp(Camera3D *camera, float distance)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves the camera target in its current right direction
|
// Moves the camera target in its current right direction
|
||||||
void CameraMoveRight(Camera3D *camera, float distance, bool moveInWorldPlane)
|
void CameraMoveRight(Camera *camera, float distance, bool moveInWorldPlane)
|
||||||
{
|
{
|
||||||
Vector3 right = GetCameraRight(camera);
|
Vector3 right = GetCameraRight(camera);
|
||||||
|
|
||||||
|
@ -259,7 +262,7 @@ void CameraMoveRight(Camera3D *camera, float distance, bool moveInWorldPlane)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves the camera position closer/farther to/from the camera target
|
// Moves the camera position closer/farther to/from the camera target
|
||||||
void CameraZoom(Camera3D *camera, float delta)
|
void CameraMoveToTarget(Camera *camera, float delta)
|
||||||
{
|
{
|
||||||
float distance = Vector3Distance(camera->position, camera->target);
|
float distance = Vector3Distance(camera->position, camera->target);
|
||||||
|
|
||||||
|
@ -278,7 +281,7 @@ void CameraZoom(Camera3D *camera, float delta)
|
||||||
// Yaw is "looking left and right"
|
// Yaw is "looking left and right"
|
||||||
// If rotateAroundTarget is false, the camera rotates around its position
|
// If rotateAroundTarget is false, the camera rotates around its position
|
||||||
// Note: angle must be provided in radians
|
// Note: angle must be provided in radians
|
||||||
void CameraYaw(Camera3D *camera, float angle, bool rotateAroundTarget)
|
void CameraYaw(Camera *camera, float angle, bool rotateAroundTarget)
|
||||||
{
|
{
|
||||||
// Rotation axis
|
// Rotation axis
|
||||||
Vector3 up = GetCameraUp(camera);
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
@ -307,7 +310,7 @@ void CameraYaw(Camera3D *camera, float angle, bool rotateAroundTarget)
|
||||||
// If rotateAroundTarget is false, the camera rotates around its position
|
// If rotateAroundTarget is false, the camera rotates around its position
|
||||||
// rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
// rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
||||||
// Note: angle must be provided in radians
|
// Note: angle must be provided in radians
|
||||||
void CameraPitch(Camera3D *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
|
void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
|
||||||
{
|
{
|
||||||
// Up direction
|
// Up direction
|
||||||
Vector3 up = GetCameraUp(camera);
|
Vector3 up = GetCameraUp(camera);
|
||||||
|
@ -359,7 +362,7 @@ void CameraPitch(Camera3D *camera, float angle, bool lockView, bool rotateAround
|
||||||
// Rotates the camera around its forward vector
|
// Rotates the camera around its forward vector
|
||||||
// Roll is "turning your head sideways to the left or right"
|
// Roll is "turning your head sideways to the left or right"
|
||||||
// Note: angle must be provided in radians
|
// Note: angle must be provided in radians
|
||||||
void CameraRoll(Camera3D *camera, float angle)
|
void CameraRoll(Camera *camera, float angle)
|
||||||
{
|
{
|
||||||
// Rotation axis
|
// Rotation axis
|
||||||
Vector3 forward = GetCameraForward(camera);
|
Vector3 forward = GetCameraForward(camera);
|
||||||
|
@ -368,30 +371,14 @@ void CameraRoll(Camera3D *camera, float angle)
|
||||||
camera->up = Vector3RotateByAxisAngle(camera->up, forward, angle);
|
camera->up = Vector3RotateByAxisAngle(camera->up, forward, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves camera slightly to simulate a walking motion
|
|
||||||
// Note: Only active if camera->swingCounter > 0
|
|
||||||
void CameraViewBobbing(Camera3D *camera)
|
|
||||||
{
|
|
||||||
if (camera->swingCounter > 0)
|
|
||||||
{
|
|
||||||
// NOTE: We delay the target movement relative to the position movement to create a little pitch with each step.
|
|
||||||
camera->position.y = camera->position.y - 0.25f * sinf((camera->swingCounter + 1) / CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER) / CAMERA_FIRST_PERSON_STEP_DIVIDER;
|
|
||||||
camera->target.y = camera->target.y - 0.25f * sinf((camera->swingCounter - 1) / CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER) / CAMERA_FIRST_PERSON_STEP_DIVIDER;
|
|
||||||
|
|
||||||
// Update counter for next frame
|
|
||||||
camera->swingCounter %= 2147483647 /* INT_MAX */; // Counter must be positive
|
|
||||||
camera->swingCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the camera view matrix
|
// Returns the camera view matrix
|
||||||
Matrix GetCameraViewMatrix(Camera3D *camera)
|
Matrix GetCameraViewMatrix(Camera *camera)
|
||||||
{
|
{
|
||||||
return MatrixLookAt(camera->position, camera->target, camera->up);
|
return MatrixLookAt(camera->position, camera->target, camera->up);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the camera projection matrix
|
// Returns the camera projection matrix
|
||||||
Matrix GetCameraProjectionMatrix(Camera3D *camera, float aspect)
|
Matrix GetCameraProjectionMatrix(Camera *camera, float aspect)
|
||||||
{
|
{
|
||||||
if (camera->projection == CAMERA_PERSPECTIVE)
|
if (camera->projection == CAMERA_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
|
@ -407,11 +394,10 @@ Matrix GetCameraProjectionMatrix(Camera3D *camera, float aspect)
|
||||||
return MatrixIdentity();
|
return MatrixIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef CAMERA_STANDALONE
|
#ifndef CAMERA_STANDALONE
|
||||||
// Update camera position for selected mode
|
// Update camera position for selected mode
|
||||||
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
|
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
|
||||||
void UpdateCamera(Camera3D *camera, int mode)
|
void UpdateCamera(Camera *camera, int mode)
|
||||||
{
|
{
|
||||||
Vector2 mousePositionDelta = GetMouseDelta();
|
Vector2 mousePositionDelta = GetMouseDelta();
|
||||||
|
|
||||||
|
@ -422,11 +408,11 @@ void UpdateCamera(Camera3D *camera, int mode)
|
||||||
|
|
||||||
// Camera movement
|
// Camera movement
|
||||||
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
|
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||||
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
//if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
|
||||||
if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
|
//if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
|
||||||
if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
|
|
||||||
|
|
||||||
// Camera rotation
|
// Camera rotation
|
||||||
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
@ -436,17 +422,13 @@ void UpdateCamera(Camera3D *camera, int mode)
|
||||||
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
|
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
|
||||||
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
|
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
|
||||||
|
|
||||||
CameraYaw(camera, mousePositionDelta.x * -CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
CameraYaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||||
CameraPitch(camera, mousePositionDelta.y * -CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
CameraPitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||||
|
|
||||||
// Zoom target distance
|
// Zoom target distance
|
||||||
CameraZoom(camera, -GetMouseWheelMove());
|
CameraMoveToTarget(camera, -GetMouseWheelMove());
|
||||||
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraZoom(camera, 2.0f);
|
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
|
||||||
if (IsKeyPressed(KEY_KP_ADD)) CameraZoom(camera, -2.0f);
|
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
|
||||||
|
|
||||||
|
|
||||||
// Apply view bobbing when moving around (per default only active in CAMERA_FIRST_PERSON)
|
|
||||||
if (mode == CAMERA_FIRST_PERSON && (IsKeyDown(KEY_W) || IsKeyDown(KEY_A) || IsKeyDown(KEY_S) || IsKeyDown(KEY_D))) CameraViewBobbing(camera);
|
|
||||||
}
|
}
|
||||||
#endif // !CAMERA_STANDALONE
|
#endif // !CAMERA_STANDALONE
|
||||||
|
|
||||||
|
|
13
src/rcore.c
13
src/rcore.c
|
@ -926,6 +926,8 @@ void InitWindow(int width, int height, const char *title)
|
||||||
CORE.Input.Mouse.currentPosition.x = (float)CORE.Window.screen.width/2.0f;
|
CORE.Input.Mouse.currentPosition.x = (float)CORE.Window.screen.width/2.0f;
|
||||||
CORE.Input.Mouse.currentPosition.y = (float)CORE.Window.screen.height/2.0f;
|
CORE.Input.Mouse.currentPosition.y = (float)CORE.Window.screen.height/2.0f;
|
||||||
|
|
||||||
|
SetMousePosition((int)CORE.Input.Mouse.currentPosition.x, (int)CORE.Input.Mouse.currentPosition.x);
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
||||||
events = (AutomationEvent *)malloc(MAX_CODE_AUTOMATION_EVENTS*sizeof(AutomationEvent));
|
events = (AutomationEvent *)malloc(MAX_CODE_AUTOMATION_EVENTS*sizeof(AutomationEvent));
|
||||||
CORE.Time.frameCounter = 0;
|
CORE.Time.frameCounter = 0;
|
||||||
|
@ -2024,6 +2026,13 @@ void DisableCursor(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
|
||||||
|
// Set cursor position in the middle of screen and update delta accordingly
|
||||||
|
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
|
||||||
|
CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/2;
|
||||||
|
CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.width/2;
|
||||||
|
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.currentPosition.x;
|
||||||
|
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.currentPosition.y;
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
emscripten_request_pointerlock("#canvas", 1);
|
emscripten_request_pointerlock("#canvas", 1);
|
||||||
|
@ -2189,7 +2198,7 @@ void EndMode2D(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes 3D mode with custom camera (3D)
|
// Initializes 3D mode with custom camera (3D)
|
||||||
void BeginMode3D(Camera3D camera)
|
void BeginMode3D(Camera camera)
|
||||||
{
|
{
|
||||||
rlDrawRenderBatchActive(); // Update and draw internal render batch
|
rlDrawRenderBatchActive(); // Update and draw internal render batch
|
||||||
|
|
||||||
|
@ -3788,7 +3797,7 @@ Vector2 GetMousePosition(void)
|
||||||
// Get mouse delta between frames
|
// Get mouse delta between frames
|
||||||
Vector2 GetMouseDelta(void)
|
Vector2 GetMouseDelta(void)
|
||||||
{
|
{
|
||||||
Vector2 delta = {0};
|
Vector2 delta = { 0 };
|
||||||
|
|
||||||
delta.x = CORE.Input.Mouse.currentPosition.x - CORE.Input.Mouse.previousPosition.x;
|
delta.x = CORE.Input.Mouse.currentPosition.x - CORE.Input.Mouse.previousPosition.x;
|
||||||
delta.y = CORE.Input.Mouse.currentPosition.y - CORE.Input.Mouse.previousPosition.y;
|
delta.y = CORE.Input.Mouse.currentPosition.y - CORE.Input.Mouse.previousPosition.y;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue