PDA

View Full Version : (Maya like) Camera errors (help)



Limingdu
07-22-2013, 09:55 PM
I was trying to make a camera similar to Maya and having trouble with the rotation

The camera flips when looking down the yaxis, does a Z rotation when I only want x,y like maya
and when I translate and then rotate does some really funky things when not at the origin

Can anyone help me debug this?





if( Buttons[0] )
{
roty = -(float) 1.0f * diffx;
rotx = -(float) 1.0f * diffy;

float phi = (rotx);
float theta = (roty);


glm::vec3 cameraW = glm::normalize(myCamera.getLookAtPosition()-myCamera.getCameraPosition());
glm::vec3 cameraU = glm::normalize(glm::cross( myCamera.getupVector(), cameraW ) );

glm::quat myQuat = glm::normalize(glm::angleAxis(theta, glm::vec3(myCamera.getupVector().x, myCamera.getupVector().y, myCamera.getupVector().z)) *glm::angleAxis(phi, glm::vec3(cameraU.x, cameraU.y, cameraU.z)) );
glm::mat4 rotmat = glm::toMat4( myQuat );


glm::vec4 myPoint(myCamera.getCameraPosition().x,myCamera.ge tCameraPosition().y,myCamera.getCameraPosition().z ,1.0f);
glm::vec4 myVector(0.0, 1.0, 0.0, 0.0f);

glm::vec4 newPosition = rotmat * myPoint;
glm::vec4 newUpVector = myQuat* myVector ;//* glm::conjugate(glm::angleAxis(phi, glm::vec3(1.0f, 0.0f, 0.0f))) );



myCamera.setCameraPosition(newPosition.x,newPositi on.y,newPosition.z);
myCamera.setupVector(newUpVector.x, newUpVector.y, newUpVector.z);


myCamera.setViewMatrix(myCamera.getCameraPosition( ),myCamera.getLookAtPosition(),myCamera.getupVecto r());

Limingdu
07-23-2013, 09:48 AM
So this ended up working correctly as long as I do not translate

as so as I translate the camera, it spins and wobbles out of control...


any thoughts how to deal with rotation after the translation with this?




if( Buttons[0] )
{
roty = -(float) 1.5f * diffx;
rotx = -(float) 1.5f * diffy;

float phi = (rotx);
float theta = (roty);

glm::vec3 cameraW = glm::normalize(myCamera.getLookAtPosition()-myCamera.getCameraPosition());
glm::vec3 cameraU = glm::normalize(glm::cross( cameraW ,myCamera.getupVector()) );

glm::quat myQuat = glm::normalize(glm::angleAxis(theta, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::angleAxis(phi, glm::vec3(cameraU.x, cameraU.y, cameraU.z)) ); //change back
glm::mat4 rotmat = glm::toMat4( myQuat );

glm::vec4 myPoint(myCamera.getCameraPosition().x,myCamera.ge tCameraPosition().y,myCamera.getCameraPosition().z ,1.0f);
glm::vec4 myVector(myCamera.getupVector().x, myCamera.getupVector().y, myCamera.getupVector().z, 0.0f);
glm::vec4 newPosition = rotmat * myPoint;
glm::vec4 newUpVector = rotmat * myVector;
newUpVector = glm::normalize(newUpVector);


myCamera.setCameraPosition(newPosition.x,newPositi on.y,newPosition.z);
myCamera.setupVector(newUpVector.x, newUpVector.y, newUpVector.z);


myCamera.setViewMatrix(myCamera.getCameraPosition( ),myCamera.getLookAtPosition(),myCamera.getupVecto r());