2017-08-04 14:38:21 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2017-09-30 01:45:03 +03:00
|
|
|
* raylib [models] example - Plane rotations (yaw, pitch, roll)
|
2017-08-04 14:38:21 +03:00
|
|
|
*
|
|
|
|
* This example has been created using raylib 1.8 (www.raylib.com)
|
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
2019-05-14 16:34:23 +03:00
|
|
|
* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
|
2017-08-04 14:38:21 +03:00
|
|
|
*
|
2019-05-14 16:34:23 +03:00
|
|
|
* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
|
2017-08-04 14:38:21 +03:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "raymath.h"
|
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2017-08-04 14:38:21 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
2021-03-26 02:11:48 +03:00
|
|
|
//SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI);
|
2017-09-30 01:45:03 +03:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
|
2017-08-04 14:38:21 +03:00
|
|
|
|
|
|
|
Camera camera = { 0 };
|
2021-03-20 00:39:39 +03:00
|
|
|
camera.position = (Vector3){ 0.0f, 50.0f, -120.0f };// Camera position perspective
|
|
|
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
2017-08-04 14:38:21 +03:00
|
|
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
|
|
|
camera.fovy = 30.0f; // Camera field-of-view Y
|
2021-03-20 00:39:39 +03:00
|
|
|
camera.projection = CAMERA_PERSPECTIVE; // Camera type
|
2021-04-22 19:55:24 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
// Model loading
|
|
|
|
// NOTE: Diffuse map loaded automatically
|
|
|
|
Model model = LoadModel("resources/plane/plane.gltf");
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
float pitch = 0.0f;
|
|
|
|
float roll = 0.0f;
|
|
|
|
float yaw = 0.0f;
|
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2017-08-04 14:38:21 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
// Main game loop
|
2017-08-04 14:38:21 +03:00
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
2021-03-20 00:39:39 +03:00
|
|
|
// Plane pitch (x-axis) controls
|
|
|
|
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f;
|
|
|
|
else if (IsKeyDown(KEY_UP)) pitch -= 0.6f;
|
2017-08-04 14:38:21 +03:00
|
|
|
else
|
|
|
|
{
|
2021-03-20 00:39:39 +03:00
|
|
|
if (pitch > 0.3f) pitch -= 0.3f;
|
|
|
|
else if (pitch < -0.3f) pitch += 0.3f;
|
2017-08-04 14:38:21 +03:00
|
|
|
}
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-09-30 01:45:03 +03:00
|
|
|
// Plane yaw (y-axis) controls
|
|
|
|
if (IsKeyDown(KEY_S)) yaw += 1.0f;
|
|
|
|
else if (IsKeyDown(KEY_A)) yaw -= 1.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (yaw > 0.0f) yaw -= 0.5f;
|
|
|
|
else if (yaw < 0.0f) yaw += 0.5f;
|
|
|
|
}
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
// Plane roll (z-axis) controls
|
|
|
|
if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
|
|
|
|
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f;
|
2017-08-04 14:38:21 +03:00
|
|
|
else
|
|
|
|
{
|
2021-03-20 00:39:39 +03:00
|
|
|
if (roll > 0.0f) roll -= 0.5f;
|
|
|
|
else if (roll < 0.0f) roll += 0.5f;
|
2017-08-04 14:38:21 +03:00
|
|
|
}
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
// Tranformation matrix for rotations
|
2021-03-26 02:11:48 +03:00
|
|
|
model.transform = MatrixRotateXYZ((Vector3){ DEG2RAD*pitch, DEG2RAD*yaw, DEG2RAD*roll });
|
2019-08-09 18:04:52 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
2021-04-22 19:55:24 +03:00
|
|
|
|
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
ClearBackground(RAYWHITE);
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
// Draw 3D model (recomended to draw 3D always before 2D)
|
2018-05-04 17:54:05 +03:00
|
|
|
BeginMode3D(camera);
|
2017-08-04 14:38:21 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
DrawModel(model, (Vector3){ 0.0f, 0.0f, 15.0f }, 0.25f, WHITE); // Draw 3d model with texture
|
2017-08-04 14:38:21 +03:00
|
|
|
DrawGrid(10, 10.0f);
|
|
|
|
|
2018-05-04 17:54:05 +03:00
|
|
|
EndMode3D();
|
2021-04-22 19:55:24 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
// Draw controls info
|
|
|
|
DrawRectangle(30, 370, 260, 70, Fade(GREEN, 0.5f));
|
|
|
|
DrawRectangleLines(30, 370, 260, 70, Fade(DARKGREEN, 0.5f));
|
|
|
|
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 380, 10, DARKGRAY);
|
|
|
|
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 400, 10, DARKGRAY);
|
|
|
|
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 420, 10, DARKGRAY);
|
2017-08-04 14:38:21 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
DrawText("(c) WWI Plane Model created by GiaHanLam", screenWidth - 240, screenHeight - 20, 10, DARKGRAY);
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
2021-04-22 19:55:24 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
2021-03-20 00:39:39 +03:00
|
|
|
UnloadModel(model); // Unload model data
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2021-03-20 00:39:39 +03:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2017-08-04 14:38:21 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
2018-03-13 19:04:49 +03:00
|
|
|
|
2017-08-04 14:38:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|