PDA

View Full Version : Trouble panning camera



Doggies
08-09-2012, 08:11 PM
I am having a little trouble with panning my camera. What i am trying to achieve is an orbital camera like you see in maya. So far the camera rotates about the target point and this works great :). The problem is when i pan the camera (dragging the mouse). If i rotate the camera 180 degrees (about the y axis), right becomes left and left becomes right. If i rotate 90 degrees, it feels like you are now moving the z axis in and out.



void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
mCamera.place();
glPushMatrix();
float size2 = size *0.5;
glTranslatef(-size2,0.01f,-size2);
glBegin(GL_LINES);
for(int i=0;i<=size;i++)
{
glVertex3f(i,0.0f,0.0f);
glVertex3f(i,0,size);
glVertex3f(0.0f,0.0f,i);
glVertex3f(size,0.0f,i);
};
glEnd();
glPopMatrix();
//render other objects......
}


void Camera::place()
{
cam.x = zoom * sinf(theta)*sinf(phi);
cam.y = zoom * -cosf(phi);
cam.z = zoom * -cosf(theta)*sinf(phi);
lookat(cam.x+target.x, cam.y+target.y, cam.z+target.z,target.x,target.y,target.z, 0.0f, 1.0f, 0.0f);
}


void Camera::mouseMoveEvent(Event *e)
{
vec2 delta = e->pos() - mOldMousePos;
if (e->button() == LeftButton)
{
camTheta += (delta.x())*compensation;
camTheta = fixAngle(camTheta, TWO_PI);
camPhi += (delta.y())*compensation;
camPhi = fixAngle(camPhi, PI);
}
else if (e->button() == RightButton)
{
float x = delta.x()*compensation;
float y = delta.y()*compensation;
target.x += x;
target.y += y;
}
mOldMousePos = e->pos();
}

Any help is very much appreciated.

Doggies
10-09-2012, 03:44 PM
Forgot about this, i am still having having troubles with it.