Updates some examples
This commit is contained in:
parent
535b9e606f
commit
32330801c9
91
examples/core_3d_camera_first_person.c
Normal file
91
examples/core_3d_camera_first_person.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - 3d camera first person
|
||||
*
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#define MAX_COLUMNS 20
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
||||
|
||||
// Generates some random columns
|
||||
float heights[MAX_COLUMNS];
|
||||
Vector3 positions[MAX_COLUMNS] = { 0.0, 2.5, 0.0 };
|
||||
Color colors[MAX_COLUMNS];
|
||||
|
||||
for (int i = 0; i < MAX_COLUMNS; i++)
|
||||
{
|
||||
heights[i] = (float)GetRandomValue(1, 12);
|
||||
positions[i] = (Vector3){ GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) };
|
||||
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
||||
}
|
||||
|
||||
Vector3 playerPosition = { 4, 2, 4 }; // Define player position
|
||||
|
||||
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCameraPlayer(&camera, &playerPosition); // Update camera and player position
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
Begin3dMode(camera);
|
||||
|
||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground
|
||||
DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall
|
||||
DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall
|
||||
DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall
|
||||
|
||||
// Draw some cubes around
|
||||
for (int i = 0; i < MAX_COLUMNS; i++)
|
||||
{
|
||||
DrawCube(positions[i], 2, heights[i], 2, colors[i]);
|
||||
DrawCubeWires(positions[i], 2, heights[i], 2, MAROON);
|
||||
}
|
||||
|
||||
End3dMode();
|
||||
|
||||
DrawText("First person camera default controls:", 20, 20, 10, GRAY);
|
||||
DrawText("- Move with keys: W, A, S, D", 40, 50, 10, DARKGRAY);
|
||||
DrawText("- Mouse move to lokk around", 40, 70, 10, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
BIN
examples/core_3d_camera_first_person.png
Normal file
BIN
examples/core_3d_camera_first_person.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@ -37,7 +37,7 @@ int main()
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera = UpdateCamera(0); // Update internal camera and our camera
|
||||
UpdateCamera(&camera); // Update internal camera and our camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -38,7 +38,7 @@ int main()
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera = UpdateCamera(0); // Update internal camera and our camera
|
||||
UpdateCamera(&camera); // Update internal camera and our camera
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ int main()
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera = UpdateCamera(0); // Update internal camera and our camera
|
||||
UpdateCamera(&camera); // Update internal camera and our camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -35,18 +35,18 @@ int main()
|
||||
|
||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
||||
|
||||
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
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera = UpdateCamera(0); // Update internal camera and our camera
|
||||
UpdateCamera(&camera); // Update internal camera and our camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -29,20 +29,20 @@ int main()
|
||||
SetModelTexture(&map, texture); // Bind texture to model
|
||||
Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!)
|
||||
|
||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position
|
||||
|
||||
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
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
camera = UpdateCamera(0); // Update internal camera and our camera
|
||||
UpdateCamera(&camera); // Update internal camera and our camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -2,10 +2,10 @@
|
||||
*
|
||||
* raylib [text] example - Font selector
|
||||
*
|
||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
@ -41,7 +41,7 @@ int main()
|
||||
|
||||
const char text[50] = "THIS is THE FONT you SELECTED!"; // Main text
|
||||
|
||||
Vector2 textSize = MeasureTextEx(fonts[currentFont], text, GetFontBaseSize(fonts[currentFont])*3, 1);
|
||||
Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1);
|
||||
|
||||
Vector2 mousePoint;
|
||||
|
||||
@ -118,7 +118,7 @@ int main()
|
||||
}
|
||||
|
||||
// Text measurement for better positioning on screen
|
||||
textSize = MeasureTextEx(fonts[currentFont], text, GetFontBaseSize(fonts[currentFont])*3, 1);
|
||||
textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@ -140,7 +140,7 @@ int main()
|
||||
DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor);
|
||||
|
||||
DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2,
|
||||
260 + (70 - textSize.y)/2 }, GetFontBaseSize(fonts[currentFont])*3,
|
||||
260 + (70 - textSize.y)/2 }, fonts[currentFont].size*3,
|
||||
1, colors[currentFont]);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -5,10 +5,10 @@
|
||||
* NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!)
|
||||
* To view details and credits for those fonts, check raylib license file
|
||||
*
|
||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
@ -50,8 +50,8 @@ int main()
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], GetFontBaseSize(fonts[i])*2, spacings[i]).x/2;
|
||||
positions[i].y = 60 + GetFontBaseSize(fonts[i]) + 50*i;
|
||||
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2;
|
||||
positions[i].y = 60 + fonts[i].size + 50*i;
|
||||
}
|
||||
|
||||
Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD };
|
||||
@ -76,7 +76,7 @@ int main()
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
DrawTextEx(fonts[i], messages[i], positions[i], GetFontBaseSize(fonts[i])*2, spacings[i], colors[i]);
|
||||
DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].size*2, spacings[i], colors[i]);
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
|
@ -31,14 +31,14 @@ int main()
|
||||
|
||||
Vector2 fontPosition1, fontPosition2, fontPosition3;
|
||||
|
||||
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, GetFontBaseSize(font1), -3).x/2;
|
||||
fontPosition1.y = screenHeight/2 - GetFontBaseSize(font1)/2 - 80;
|
||||
fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2;
|
||||
fontPosition1.y = screenHeight/2 - font1.size/2 - 80;
|
||||
|
||||
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, GetFontBaseSize(font2), -2).x/2;
|
||||
fontPosition2.y = screenHeight/2 - GetFontBaseSize(font2)/2 - 10;
|
||||
fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2;
|
||||
fontPosition2.y = screenHeight/2 - font2.size/2 - 10;
|
||||
|
||||
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, GetFontBaseSize(font3), 2).x/2;
|
||||
fontPosition3.y = screenHeight/2 - GetFontBaseSize(font3)/2 + 50;
|
||||
fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2;
|
||||
fontPosition3.y = screenHeight/2 - font3.size/2 + 50;
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@ -56,9 +56,9 @@ int main()
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawTextEx(font1, msg1, fontPosition1, GetFontBaseSize(font1), -3, WHITE);
|
||||
DrawTextEx(font2, msg2, fontPosition2, GetFontBaseSize(font2), -2, WHITE);
|
||||
DrawTextEx(font3, msg3, fontPosition3, GetFontBaseSize(font3), 2, WHITE);
|
||||
DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE);
|
||||
DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE);
|
||||
DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user