# Camera rotating

I want to allow to rotate my camera around x an y in 360 degrees - rotations around y axis are ok but around x axis it rotates only from -180 to 180 then it doesn’t turn to the positive z axis as it should.
Next problem is why can’t i draw to the positive z axis ? even when i turn the camera to positive z axis i don’t see anything drawn.

``````
void CalculateNewPos(float time)
{
float x_velocity;
float xz_velocity;
float y_velocity;
float z_velocity;
float pointx;			//point for glulookat
float pointy;
float pointz;
y_velocity=(float)sin((double)my_position.rot_x)*my_position.velocity;
xz_velocity=(float)cos((double)my_position.rot_x)*my_position.velocity;
z_velocity=-1*(float)sin((double)my_position.rot_y)*xz_velocity;
x_velocity=(float)cos((double)my_position.rot_y)*xz_velocity;
my_position.x+=x_velocity*(float)time;
my_position.y+=y_velocity*(float)time;
my_position.z+=z_velocity*(float)time;
pointx=(float)cos((double)my_position.rot_y);
pointy=(float)sin((double)my_position.rot_x);
pointz=-1*(float)sin((double)my_position.rot_y);
gluLookAt(my_position.x,my_position.y,my_position.z,my_position.x+pointx,my_position.y+pointy,my_position.z+pointz,0.0f,1.0f,0.0f);
}

``````

and draw function

``````
void DrawGLScene()
{
double deltat;
deltat=GetTime();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
CalculateNewPos((float)deltat);
DrawSkybox();
glPushMatrix();
glTranslatef(EARTH->x,EARTH->y,EARTH->z); //this is ok earth position is 0.0,0.0,-15.0
ShowObject(EARTH->model);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0f,0.0f,12.0f);
glBegin(GL_TRIANGLES);
glVertex3f(-2.0f,-2.0f,0.0f);
glVertex3f(2.0f,-2.0f,0.0f);
glVertex3f(0.0f,2.0f,0.0f);
glEnd();
glPopMatrix();

}

``````

It seems to me your letting the movement drive the camera, instead of letting the camera drive the movement. In a first person view, that is usually what you want; the user looks somewhere, and then moves in that direction. Try reversing your calculation, figurte out where the the user is looking, and then point your velocity in that direction.