2014-04-19 18:54:48 +04:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2015-08-27 17:13:31 +03:00
|
|
|
* raylib [core] example - Picking in 3d mode
|
2014-04-19 18:54:48 +04:00
|
|
|
*
|
2015-08-27 17:13:31 +03:00
|
|
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
2014-04-19 18:54:48 +04:00
|
|
|
* 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()
|
2014-09-30 01:41:05 +04:00
|
|
|
{
|
2014-04-19 18:54:48 +04:00
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
int screenWidth = 800;
|
|
|
|
int screenHeight = 450;
|
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
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 }};
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
|
|
|
|
|
|
|
|
Ray pickingLine;
|
2015-07-18 20:26:13 +03:00
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
SetCameraMode(CAMERA_FREE);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
SetTargetFPS(60);
|
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
2015-08-27 17:13:31 +03:00
|
|
|
camera = UpdateCamera(0);
|
|
|
|
|
|
|
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pickingLine = GetMouseRay(GetMousePosition(), camera);
|
2014-04-19 18:54:48 +04:00
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
ClearBackground(RAYWHITE);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
Begin3dMode(camera);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2015-08-27 17:13:31 +03:00
|
|
|
DrawCube(cubePosition, 2, 2, 2, RED);
|
|
|
|
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
|
|
|
|
|
|
|
|
DrawGrid(10.0, 1.0);
|
|
|
|
|
|
|
|
DrawRay(pickingLine, MAROON);
|
|
|
|
|
|
|
|
End3dMode();
|
|
|
|
|
|
|
|
DrawFPS(10, 10);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2015-08-27 17:13:31 +03:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2014-04-19 18:54:48 +04:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
return 0;
|
|
|
|
}
|