DailyFrankPeter

11-15-2016, 02:09 PM

Hi all,

I'm trying to rotate a tutorial cube, just like probably everyone in the beginning, except without using the glm::lookAt(). This code works now, but I don't get why... I probably just need a nudge in the right direction and someone to tell me that I've been missing something obvious.

The question is this: why does this code work (produce a cube which is NOT off screen) when translation (zoom) comes first, before the rotation?

Previous code used to have rotation first, and translation (zoom) at the end but the result looked like the cube rotated off the screen around the camera's already translated position (obviously an order of multiplications problem).

Many, many thanks.

//5. MODEL-VIEW-PROJECTION TRANSFORMATIONS

glm::mat4 m_MODEL;

glm::mat4 m_VIEW;

glm::mat4 m_PROJ;

const glm::vec3 X(1.0f, 0.0f, 0.0f);

const glm::vec3 Y(0.0f, 1.0f, 0.0f);

const glm::vec3 Z(0.0f, 0.0f, 1.0f);

//view (this is basically inverse of camera movement, applied to all meshes)?

//zoom

float dolly; //+ means content gets closer

dolly = -3;

m_VIEW = glm::translate(m_VIEW, glm::vec3(0, 0, dolly));

//orbit

float angle_x, angle_y; //+ means content rotates left/down

angle_x = glm::radians(10.0f);

angle_y = glm::radians(5.0f);

m_VIEW = glm::rotate(m_VIEW, angle_x, X);

//m_VIEW = glm::rotate(m_VIEW, angle_y, Y);

//pan

float pan_x, pan_y; //pan content with respect to camera

pan_x = 0;

pan_y = 0;

m_VIEW = glm::translate(m_VIEW, glm::vec3(pan_x, pan_y, 0));

I'm trying to rotate a tutorial cube, just like probably everyone in the beginning, except without using the glm::lookAt(). This code works now, but I don't get why... I probably just need a nudge in the right direction and someone to tell me that I've been missing something obvious.

The question is this: why does this code work (produce a cube which is NOT off screen) when translation (zoom) comes first, before the rotation?

Previous code used to have rotation first, and translation (zoom) at the end but the result looked like the cube rotated off the screen around the camera's already translated position (obviously an order of multiplications problem).

Many, many thanks.

//5. MODEL-VIEW-PROJECTION TRANSFORMATIONS

glm::mat4 m_MODEL;

glm::mat4 m_VIEW;

glm::mat4 m_PROJ;

const glm::vec3 X(1.0f, 0.0f, 0.0f);

const glm::vec3 Y(0.0f, 1.0f, 0.0f);

const glm::vec3 Z(0.0f, 0.0f, 1.0f);

//view (this is basically inverse of camera movement, applied to all meshes)?

//zoom

float dolly; //+ means content gets closer

dolly = -3;

m_VIEW = glm::translate(m_VIEW, glm::vec3(0, 0, dolly));

//orbit

float angle_x, angle_y; //+ means content rotates left/down

angle_x = glm::radians(10.0f);

angle_y = glm::radians(5.0f);

m_VIEW = glm::rotate(m_VIEW, angle_x, X);

//m_VIEW = glm::rotate(m_VIEW, angle_y, Y);

//pan

float pan_x, pan_y; //pan content with respect to camera

pan_x = 0;

pan_y = 0;

m_VIEW = glm::translate(m_VIEW, glm::vec3(pan_x, pan_y, 0));