TheTrueHelix

05-17-2016, 11:05 PM

Ok, I would like to welcome everyone ! I'm a new member on this OpenGL forum and I hope to find the knowledge I am searching for.

I currently working on an ArcBall camera but I can't seem to be able to make it work properly. It's been a while I can't find everyone who can help me. I don't only want the answers, I want the explanation if possible. So my goal is to make a Camera that rotates around its target. I'm using GLM and I'm trying to stop using it and building my own MATH class. I tried multiple ways of having my camera work.

Before the code, I need to explain that my function receive the Target (PointToFix) position, 2 Rotation Angle between 0 and 359 and the zoom level. Additionnaly, It receive the main and actual View Matrix which I overwrite at the end of the function since its by reference.

My first one was this :

void t_Math::ChangeViewLookAt(glm::mat4& InMatrix, glm::vec3 InPointToFix, GLfloat InPitchValue, GLfloat InYawValue, GLfloat InScalingValue)

{

glm::vec3 cameraTarget = glm::vec3(InPointToFix.x, InPointToFix.y, InPointToFix.z);

const GLfloat x_Rotation = InPitchValue / 57.5829;

const GLfloat y_Rotation = InYawValue / 57.5829;

const GLfloat scaling = InScalingValue;

glm::vec4 tempoMatrix = InMatrix * glm::vec4(1,1,1,1);

tempoMatrix = glm::normalize(tempoMatrix);

tempoMatrix = glm::rotate(tempoMatrix, x_Rotation, glm::vec3(1.0, 0.0, 0.0));

tempoMatrix = glm::rotate(tempoMatrix, y_Rotation, glm::vec3(0.0, 1.0, 0.0));

glm::mat4 rot_mat = glm::rotate(glm::mat4(1.f), x_Rotation, glm::vec3(1,0,0));

rot_mat = glm::rotate(glm::mat4(1.f), y_Rotation, glm::vec3(0,1,0)) * rot_mat;

glm::vec4 cameraPosition = (tempoMatrix * glm::vec4(scaling,scaling,scaling,1));

InMatrix = glm::lookAt(glm::vec3(cameraPosition + (rot_mat * glm::vec4(cameraTarget - glm::vec3(cameraPosition),0.f))), cameraTarget, glm::vec3(0.0, 1.0, 0.0));

}

then someone told me that I didn't need to use the LookAt but instead just use a identity matrice and apply the rotation to get my View Matrice. What I understand is that, in my case, you cannot rotate the Entire View matrix because it countain more than just the position and so, I need to rotate the position before creating the view matrix.

So I ended up with this

void t_Math::ChangeViewLookAt(glm::mat4& InMatrix, glm::vec3 InPointToFix, GLfloat InPitchValue, GLfloat InYawValue, GLfloat InScalingValue)

{

const GLfloat x_Rotation = InPitchValue / 57.5829;

const GLfloat y_Rotation = InYawValue / 57.5829;

const glm::vec3 cameraTarget = glm::vec3(InPointToFix.x, InPointToFix.y, InPointToFix.z);

const glm::vec3 scaling = glm::vec3(InScalingValue, InScalingValue, InScalingValue);

glm::mat4 view = glm::mat4(1.0);

view = glm::scale(view, scaling);

view = glm::rotate(view, x_Rotation, glm::vec3(1.0, 0.0, 0.0));

view = glm::rotate(view, y_Rotation, glm::vec3(0.0, 1.0, 0.0));

view = glm::translate(view, cameraTarget);

InMatrix = view;

}

and right now, I have a smooth camera but it doesn't move. The camera itself rotate but it's not around a Target. I don't want the camera itself to rotate on-place but instead I want its position to change around at a static distance from a target creating an ArcBall Camera.

Thank you very much. I really need some answers. I have read a book "Anton's OpenGL Tutorial" and I don't really like the way he explains things. He doesn't explain much and he is using MakeFile and GLFW which doesn't explain how they work. Additionnaly, he doesn't explain but he just do which I don't find to help me. For example, he will show you code and tell you why it's better to do so but he doesn't explain why and what happen in the hardware itself.

Then I tried LearnOpenGL.com which is a nice website, except it goes too fast. Literally, you are there working with Matrice and next Tutorial you are creating a Phong Lighting. Do you guys have any tips on book I should buy ? A good one which explain everything. Even more, In both Anton's Book or LearnOpenGL.com, Camera are explained but they do not explain camera movement, they just show you how to make a Bird-Eye Camera (the one who is super free and can move around and rotate). Thank you, I'm starting to get deseperated. :sorrow:

I currently working on an ArcBall camera but I can't seem to be able to make it work properly. It's been a while I can't find everyone who can help me. I don't only want the answers, I want the explanation if possible. So my goal is to make a Camera that rotates around its target. I'm using GLM and I'm trying to stop using it and building my own MATH class. I tried multiple ways of having my camera work.

Before the code, I need to explain that my function receive the Target (PointToFix) position, 2 Rotation Angle between 0 and 359 and the zoom level. Additionnaly, It receive the main and actual View Matrix which I overwrite at the end of the function since its by reference.

My first one was this :

void t_Math::ChangeViewLookAt(glm::mat4& InMatrix, glm::vec3 InPointToFix, GLfloat InPitchValue, GLfloat InYawValue, GLfloat InScalingValue)

{

glm::vec3 cameraTarget = glm::vec3(InPointToFix.x, InPointToFix.y, InPointToFix.z);

const GLfloat x_Rotation = InPitchValue / 57.5829;

const GLfloat y_Rotation = InYawValue / 57.5829;

const GLfloat scaling = InScalingValue;

glm::vec4 tempoMatrix = InMatrix * glm::vec4(1,1,1,1);

tempoMatrix = glm::normalize(tempoMatrix);

tempoMatrix = glm::rotate(tempoMatrix, x_Rotation, glm::vec3(1.0, 0.0, 0.0));

tempoMatrix = glm::rotate(tempoMatrix, y_Rotation, glm::vec3(0.0, 1.0, 0.0));

glm::mat4 rot_mat = glm::rotate(glm::mat4(1.f), x_Rotation, glm::vec3(1,0,0));

rot_mat = glm::rotate(glm::mat4(1.f), y_Rotation, glm::vec3(0,1,0)) * rot_mat;

glm::vec4 cameraPosition = (tempoMatrix * glm::vec4(scaling,scaling,scaling,1));

InMatrix = glm::lookAt(glm::vec3(cameraPosition + (rot_mat * glm::vec4(cameraTarget - glm::vec3(cameraPosition),0.f))), cameraTarget, glm::vec3(0.0, 1.0, 0.0));

}

then someone told me that I didn't need to use the LookAt but instead just use a identity matrice and apply the rotation to get my View Matrice. What I understand is that, in my case, you cannot rotate the Entire View matrix because it countain more than just the position and so, I need to rotate the position before creating the view matrix.

So I ended up with this

void t_Math::ChangeViewLookAt(glm::mat4& InMatrix, glm::vec3 InPointToFix, GLfloat InPitchValue, GLfloat InYawValue, GLfloat InScalingValue)

{

const GLfloat x_Rotation = InPitchValue / 57.5829;

const GLfloat y_Rotation = InYawValue / 57.5829;

const glm::vec3 cameraTarget = glm::vec3(InPointToFix.x, InPointToFix.y, InPointToFix.z);

const glm::vec3 scaling = glm::vec3(InScalingValue, InScalingValue, InScalingValue);

glm::mat4 view = glm::mat4(1.0);

view = glm::scale(view, scaling);

view = glm::rotate(view, x_Rotation, glm::vec3(1.0, 0.0, 0.0));

view = glm::rotate(view, y_Rotation, glm::vec3(0.0, 1.0, 0.0));

view = glm::translate(view, cameraTarget);

InMatrix = view;

}

and right now, I have a smooth camera but it doesn't move. The camera itself rotate but it's not around a Target. I don't want the camera itself to rotate on-place but instead I want its position to change around at a static distance from a target creating an ArcBall Camera.

Thank you very much. I really need some answers. I have read a book "Anton's OpenGL Tutorial" and I don't really like the way he explains things. He doesn't explain much and he is using MakeFile and GLFW which doesn't explain how they work. Additionnaly, he doesn't explain but he just do which I don't find to help me. For example, he will show you code and tell you why it's better to do so but he doesn't explain why and what happen in the hardware itself.

Then I tried LearnOpenGL.com which is a nice website, except it goes too fast. Literally, you are there working with Matrice and next Tutorial you are creating a Phong Lighting. Do you guys have any tips on book I should buy ? A good one which explain everything. Even more, In both Anton's Book or LearnOpenGL.com, Camera are explained but they do not explain camera movement, they just show you how to make a Bird-Eye Camera (the one who is super free and can move around and rotate). Thank you, I'm starting to get deseperated. :sorrow: