Changeset 92bc4fe in opengl-game for common/controls-new.cpp


Ignore:
Timestamp:
Jun 25, 2017, 7:15:12 PM (7 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
fe70cd3
Parents:
8a6d19d
Message:

Make the game window fullscreen, hide the mouse cursor, and change the view to an overhead one as the player moves around the scene

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/controls-new.cpp

    r8a6d19d r92bc4fe  
    22#include <GLFW/glfw3.h>
    33extern GLFWwindow* window; // The "extern" keyword here is to access the variable "window" declared in tutorialXXX.cpp. This is a hack to keep the tutorials simple. Please avoid this.
     4
     5#include <iostream>
     6
     7using namespace std;
    48
    59// Include GLM
     
    2226
    2327// Initial position : on +Z
    24 glm::vec3 position = glm::vec3(4,3,-3); //glm::vec3( 0, 0, 5 );
     28glm::vec3 position = glm::vec3(4,6,-3); //glm::vec3( 0, 0, 5 );
    2529// Initial horizontal angle : toward -Z
    2630float horizontalAngleBase = 3.14f * 3.0f / 2.0f; // 3.14f;
     
    3640
    3741
    38 void computeMatricesFromInputs(){
     42void computeMatricesFromInputs(int windowWidth, int windowHeight) {
    3943
    4044        // glfwGetTime is called only once, the first time this function is called
     
    5256  // The call has no effect the first several times it's called
    5357  if (centeredCount < 100) {
    54     glfwSetCursorPos(window, 1024/2, 768/2);
     58    glfwSetCursorPos(window, windowWidth/2, windowHeight/2);
    5559    centeredCount++;
    5660  }
     
    5862        // Compute new orientation
    5963  /* STOP ROTATION FOR NOW */
    60   float horizontalAngle = horizontalAngleBase + mouseSpeed * float(1024/2 - xpos );
    61   // verticalAngle   += mouseSpeed * float( 768/2 - ypos );
     64  float horizontalAngle = horizontalAngleBase + mouseSpeed * float(windowWidth/2 - xpos );
     65  // verticalAngle   += mouseSpeed * float( windowHeight/2 - ypos );
    6266
    6367        // Direction : Spherical coordinates to Cartesian coordinates conversion
     
    6771                cos(verticalAngle) * cos(horizontalAngle)
    6872        );
     73  glm::vec3 lookDirection(
     74    0.0f,
     75    -3.0f,
     76    0.0f
     77  );
     78  lookDirection = lookDirection + 3.0f * direction;
    6979
    7080        // Right vector
     
    105115                // and looks here : at the same position, plus "direction"
    106116                                                                // position+glm::vec3(-4,0,0), // position+glm::vec3(-4,-3,3),
    107                                                                 position+direction,
     117                                                                position+lookDirection,
    108118                                                                glm::vec3(0,1,0) //up                  // Head is up (set to 0,-1,0 to look upside-down)
    109119                                                   );
Note: See TracChangeset for help on using the changeset viewer.