Stop the camera from spinning on startup
This commit is contained in:
parent
8f489ea7f1
commit
9bdaf0e1c3
|
@ -55,7 +55,7 @@ void Application::initialize()
|
|||
// Set GL Attributes
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
m_glContext = SDL_GL_CreateContext(m_window);
|
||||
|
@ -72,7 +72,7 @@ void Application::initialize()
|
|||
glewInit();
|
||||
|
||||
// Create camera
|
||||
m_camera = new Camera();
|
||||
m_camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), 90.0f, 0.0f);
|
||||
|
||||
// Run the engine
|
||||
run();
|
||||
|
@ -114,6 +114,12 @@ void Application::handleEvents()
|
|||
}
|
||||
|
||||
glm::vec2 mousepos = Input::getInstance().getMouseCoords();
|
||||
// Force mouse to the center of the screen
|
||||
SDL_SetWindowGrab(m_window, SDL_TRUE);
|
||||
SDL_WarpMouseInWindow(m_window, m_width/2, m_height/2);
|
||||
|
||||
// Handle Camera Movement
|
||||
m_camera->processMouseMovement(-(m_width/2 - mousepos.x), m_height/2 - mousepos.y, GL_TRUE);
|
||||
|
||||
// Handle Camera Movement Keys
|
||||
if(Input::getInstance().isKeyDown(SDLK_w))
|
||||
|
@ -131,12 +137,6 @@ void Application::handleEvents()
|
|||
// Handle Camera Zoom
|
||||
m_camera->processMouseScroll((float) Input::getInstance().getMouseWheelVertical() / 10.0f);
|
||||
|
||||
// Force mouse to the center of the screen
|
||||
SDL_WarpMouseInWindow(m_window, m_width/2, m_height/2);
|
||||
|
||||
// Handle Camera Movement
|
||||
m_camera->processMouseMovement(-(m_width/2 - mousepos.x), m_height/2 - mousepos.y, GL_TRUE);
|
||||
|
||||
// Print mouse position on click
|
||||
if(Input::getInstance().isKeyPressed(SDL_BUTTON_LEFT))
|
||||
std::cout << "mX: " << mousepos.x << " mY: " << mousepos.y << std::endl;
|
||||
|
@ -154,6 +154,9 @@ void Application::run()
|
|||
m_last = 0;
|
||||
|
||||
// TEST CODE
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
Input::getInstance().setMouseCoords(m_width/2, m_height/2);
|
||||
|
||||
static const GLfloat vertices[] = {
|
||||
-1.0f,-1.0f,-1.0f, 0.0f, 1.0f, 1.0f, // triangle 1 : begin
|
||||
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||
|
@ -218,7 +221,6 @@ void Application::run()
|
|||
skyboxShader.setAttribute("color", 3, GL_FALSE, 6, 3, GL_FLOAT);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
// END TEST CODE
|
||||
|
||||
|
@ -230,13 +232,13 @@ void Application::run()
|
|||
handleEvents();
|
||||
|
||||
// Clear color buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.39f, 0.58f, 0.93f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
deltaTime = ((m_now - m_last) / (double)SDL_GetPerformanceFrequency());
|
||||
|
||||
// TEST CODE
|
||||
|
||||
|
||||
glm::vec3 cameraPos = m_camera->getPosition();
|
||||
|
||||
glm::mat4 projection = glm::perspective(m_camera->getFOV(), (GLfloat)m_width/(GLfloat)m_height, 0.1f, 100.0f);
|
||||
|
|
|
@ -33,10 +33,9 @@ class Application : public Singleton<Application>
|
|||
friend class Singleton<Application>;
|
||||
private:
|
||||
int m_width, m_height;
|
||||
|
||||
|
||||
Camera* m_camera;
|
||||
SDL_Window* m_window;
|
||||
SDL_Event m_event;
|
||||
SDL_GLContext m_glContext;
|
||||
|
||||
GLuint m_now;
|
||||
|
|
Loading…
Reference in New Issue