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