Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Trouble panning camera

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    7

    Trouble panning camera

    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.

    Code :
    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.
    Last edited by Doggies; 08-09-2012 at 08:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •