diff options
Diffstat (limited to 'examples/core_3d_picking.c')
| -rw-r--r-- | examples/core_3d_picking.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c new file mode 100644 index 00000000..a7a96fa9 --- /dev/null +++ b/examples/core_3d_picking.c @@ -0,0 +1,74 @@ +/******************************************************************************************* +* +* raylib [core] example - Picking in 3d mode +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); + + // 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 }}; + + Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + + Ray pickingLine; + + SetCameraMode(CAMERA_FREE); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + camera = UpdateCamera(0); + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pickingLine = GetMouseRay(GetMousePosition(), camera); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + DrawCube(cubePosition, 2, 2, 2, RED); + DrawCubeWires(cubePosition, 2, 2, 2, MAROON); + + DrawGrid(10.0, 1.0); + + DrawRay(pickingLine, MAROON); + + End3dMode(); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file |
