diff options
Diffstat (limited to 'examples/web/models/models_yaw_pitch_roll.c')
| -rw-r--r-- | examples/web/models/models_yaw_pitch_roll.c | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/examples/web/models/models_yaw_pitch_roll.c b/examples/web/models/models_yaw_pitch_roll.c index e1ec513..e57b357 100644 --- a/examples/web/models/models_yaw_pitch_roll.c +++ b/examples/web/models/models_yaw_pitch_roll.c @@ -5,9 +5,9 @@ * 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) * -* Example based on Berni work on Raspberry Pi +* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5) * -* Copyright (c) 2017 Ramon Santamaria (@raysan5) +* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -21,19 +21,19 @@ //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -int screenWidth = 800; -int screenHeight = 450; +const int screenWidth = 800; +const int screenHeight = 450; // Define our custom camera to look into our 3d world Camera camera = { 0 }; -Texture2D texAngleGauge; -Texture2D texBackground; -Texture2D texPitch; -Texture2D texPlane; +Texture2D texAngleGauge = { 0 }; +Texture2D texBackground = { 0 }; +Texture2D texPitch = { 0 }; +Texture2D texPlane = { 0 }; -RenderTexture2D framebuffer; -Model model; +RenderTexture2D framebuffer = { 0 }; +Model model = { 0 }; float pitch = 0.0f; float roll = 0.0f; @@ -48,7 +48,7 @@ void UpdateDrawFrame(void); // Update and Draw one frame void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color); //---------------------------------------------------------------------------------- -// Main Enry Point +// Program Main Entry Point //---------------------------------------------------------------------------------- int main(void) { @@ -56,30 +56,31 @@ int main(void) //-------------------------------------------------------------------------------------- InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); - texAngleGauge = LoadTexture("resources/angle_gauge.png"); + texAngleGauge = LoadTexture("resources/angle_gauge.png"); texBackground = LoadTexture("resources/background.png"); - texPitch = LoadTexture("resources/pitch.png"); + texPitch = LoadTexture("resources/pitch.png"); texPlane = LoadTexture("resources/plane.png"); framebuffer = LoadRenderTexture(192, 192); - + // Model loading model = LoadModel("resources/plane.obj"); // Load OBJ model - model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture - - GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture); + model.materials[0].maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture + + GenTextureMipmaps(&model.materials[0].maps[MAP_DIFFUSE].texture); camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 30.0f; // Camera field-of-view Y + camera.type = CAMERA_PERSPECTIVE; // Camera type #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -89,17 +90,17 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- - + // Unload all loaded data UnloadModel(model); - + UnloadRenderTexture(framebuffer); - - UnloadTexture(texAngleGauge); + + UnloadTexture(texAngleGauge); UnloadTexture(texBackground); - UnloadTexture(texPitch); + UnloadTexture(texPitch); UnloadTexture(texPlane); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- @@ -121,7 +122,7 @@ void UpdateDrawFrame(void) if (roll > 0.0f) roll -= 0.5f; else if (roll < 0.0f) roll += 0.5f; } - + // Plane yaw (y-axis) controls if (IsKeyDown(KEY_S)) yaw += 1.0f; else if (IsKeyDown(KEY_A)) yaw -= 1.0f; @@ -130,7 +131,7 @@ void UpdateDrawFrame(void) if (yaw > 0.0f) yaw -= 0.5f; else if (yaw < 0.0f) yaw += 0.5f; } - + // Plane pitch (z-axis) controls if (IsKeyDown(KEY_DOWN)) pitch += 0.6f; else if (IsKeyDown(KEY_UP)) pitch -= 0.6f; @@ -139,7 +140,7 @@ void UpdateDrawFrame(void) if (pitch > 0.3f) pitch -= 0.3f; else if (pitch < -0.3f) pitch += 0.3f; } - + // Wraps the phase of an angle to fit between -180 and +180 degrees int pitchOffset = pitch; while (pitchOffset > 180) pitchOffset -= 360; @@ -151,16 +152,16 @@ void UpdateDrawFrame(void) transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll)); transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch)); transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw)); - + model.transform = transform; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + // Draw framebuffer texture (Ahrs Display) int centerX = framebuffer.texture.width/2; int centerY = framebuffer.texture.height/2; @@ -177,28 +178,28 @@ void UpdateDrawFrame(void) DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height }, (Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor }, (Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); - + DrawTexturePro(texPlane, (Rectangle){0,0,texPlane.width, texPlane.height }, - (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, + (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, (Vector2){texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); - + EndBlendMode(); EndTextureMode(); // Draw 3D model (recomended to draw 3D always before 2D) - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(model, (Vector3){ 0, 6.0f, 0 }, 1.0f, WHITE); // Draw 3d model with texture DrawGrid(10, 10.0f); - End3dMode(); + EndMode3D(); // Draw 2D GUI stuff - DrawAngleGauge(texAngleGauge, 80, 80, roll, "roll", RED); - DrawAngleGauge(texAngleGauge, 190, 80, pitch, "pitch", GREEN); - DrawAngleGauge(texAngleGauge, 300, 80, yaw, "yaw", SKYBLUE); - + DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED); + DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN); + DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE); + DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f)); DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY); @@ -206,11 +207,11 @@ void UpdateDrawFrame(void) DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY); // Draw framebuffer texture - DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, + DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, (Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f)); - + DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY); - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -224,7 +225,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[ int textSize = 20; DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); - - DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY); - DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); + + DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY); + DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); }
\ No newline at end of file |
