diff options
| author | raysan5 <raysan5@gmail.com> | 2015-08-27 16:13:31 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2015-08-27 16:13:49 +0200 |
| commit | 997170a317bb8077cb96d3fc757c6cde0c0ea466 (patch) | |
| tree | 139171eed30f8d0f77ea4873ca1f0510dc5b0812 /examples/core_3d_picking.c | |
| parent | 8745d733f98e1c9a647a8bd8b85cf0781782d4b7 (diff) | |
| download | raylib-997170a317bb8077cb96d3fc757c6cde0c0ea466.tar.gz raylib-997170a317bb8077cb96d3fc757c6cde0c0ea466.zip | |
Examples reviewed
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 |
