Advertisement
Guest User

Untitled

a guest
Aug 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.76 KB | None | 0 0
  1. /*******************************************************************************************
  2. *
  3. *   raylib [core] example - Initialize 3d mode
  4. *
  5. *   This example has been created using raylib 1.0 (www.raylib.com)
  6. *   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. *   Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11.  
  12. #include "raylib.h"
  13.  
  14. const Vector3 cameraOffset = { 0.0f, 10.0f, 10.0f };
  15.  
  16. Vector3 getCameraPosition( const Vector3& basePos )
  17. {
  18.     return (Vector3){ basePos.x + cameraOffset.x, basePos.y + cameraOffset.y, basePos.z + cameraOffset.z };
  19. }
  20.  
  21. int main()
  22. {
  23.     // Initialization
  24.     //--------------------------------------------------------------------------------------
  25.     const int screenWidth = 800;
  26.     const int screenHeight = 450;
  27.     const float cubeSpeed = 0.4f;
  28.  
  29.     InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
  30.  
  31.     // Define the camera to look into our 3d world
  32.     Camera3D camera;
  33.     camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };  // Camera position
  34.     camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };      // Camera looking at point
  35.     camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };          // Camera up vector (rotation towards target)
  36.     camera.fovy = 45.0f;                                // Camera field-of-view Y
  37.     camera.type = CAMERA_PERSPECTIVE;                   // Camera mode type
  38.  
  39.     Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
  40.  
  41.     Model model = LoadModel("gfx/obj/dungeon.obj");
  42.     Texture2D texture = LoadTexture("gfx/txt/dungeon_1_diff.png"); // Load model texture
  43.     model.material.maps[MAP_DIFFUSE].texture = texture;                     // Set map diffuse texture
  44.    
  45.     SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
  46.     //--------------------------------------------------------------------------------------
  47.  
  48.     // Main game loop
  49.     while (!WindowShouldClose())    // Detect window close button or ESC key
  50.     {
  51.         // Update
  52.         //----------------------------------------------------------------------------------
  53.         // TODO: Update your variables here
  54.         //----------------------------------------------------------------------------------
  55.  
  56.         if (IsKeyDown(KEY_RIGHT)) cubePosition.x += cubeSpeed;
  57.         if (IsKeyDown(KEY_UP)) cubePosition.z    -= cubeSpeed;
  58.         if (IsKeyDown(KEY_LEFT)) cubePosition.x  -= cubeSpeed;
  59.         if (IsKeyDown(KEY_DOWN)) cubePosition.z  += cubeSpeed;
  60.  
  61.  
  62.         camera.target = cubePosition;
  63.         //camera.position = getCameraPosition( cubePosition );
  64.         // Draw
  65.         //----------------------------------------------------------------------------------
  66.         BeginDrawing();
  67.  
  68.             ClearBackground(RAYWHITE);
  69.  
  70.             BeginMode3D(camera);
  71.  
  72.                 DrawModel(model, cubePosition, 1.f, WHITE);
  73.                 //DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  74.                 DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  75.  
  76.                 DrawGrid(20, 1.0f);
  77.  
  78.             EndMode3D();
  79.  
  80.             DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
  81.  
  82.             DrawFPS(10, 10);
  83.  
  84.         EndDrawing();
  85.         //----------------------------------------------------------------------------------
  86.     }
  87.  
  88.     // De-Initialization
  89.     //--------------------------------------------------------------------------------------
  90.     UnloadTexture(texture);     // Unload texture
  91.     UnloadModel(model);         // Unload model
  92.     CloseWindow();        // Close window and OpenGL context
  93.     //--------------------------------------------------------------------------------------
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement