finding new origin

I know how to set my camera view and I have my object position stored in variables.Thats ok but how do I find the objects coordinates after i set camera somewhere else not in position(0,0,0);

code so far(not working-earth is still in centre(0.0f,0.0f,-10.0f)

 
void CalculateNewPos(float time)
{
	float matrix[16];
	float x_velocity;
	float xz_velocity;
	float y_velocity;
	float z_velocity;
	QUATERNION Qx;
	QUATERNION Qy;
	QUATERNION Qz;
	QUATERNION Qxy;
	QUATERNION Qxyz;
	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;
	Qx.w=(float)cos(my_position.rot_x/2.0f);
	Qx.x=(float)sin(my_position.rot_x/2.0f);
	Qx.y=0;
	Qx.z=0;
	Qy.w=(float)cos(my_position.rot_y/2.0f);
	Qy.x=0;
	Qy.y=(float)sin(my_position.rot_y/2.0f);
	Qy.z=0;
	Qz.w=(float)cos(0);
	Qz.x=0;
	Qz.y=0;
	Qz.z=(float)sin(0);
	Qxy=MultiplyQuaternion(Qx,Qy);							//this calculations works
	Qxyz=MultiplyQuaternion(Qxy,Qz);
	NormalizeQuaternion(&Qxyz);
	matrix[0]=1.0f-2.0f*Qxyz.y*Qxyz.y-2.0f*Qxyz.z*Qxyz.z;
	matrix[1]=2.0f*Qxyz.x*Qxyz.y+2.0f*Qxyz.w*Qxyz.z;
	matrix[2]=2.0f*Qxyz.x*Qxyz.z-2.0f*Qxyz.w*Qxyz.y;
	matrix[3]=0.0f;
	matrix[4]=2.0f*Qxyz.x*Qxyz.y-2.0f*Qxyz.w*Qxyz.z;
	matrix[5]=1.0f-2.0f*Qxyz.x*Qxyz.x-2.0f*Qxyz.z*Qxyz.z;
	matrix[6]=2.0f*Qxyz.y*Qxyz.z+2.0f*Qxyz.w*Qxyz.x;
	matrix[7]=0.0f;
	matrix[8]=2.0f*Qxyz.x*Qxyz.z+2.0f*Qxyz.w*Qxyz.y;
	matrix[9]=2.0f*Qxyz.y*Qxyz.z-2.0f*Qxyz.w*Qxyz.x;
	matrix[10]=1.0f-2.0f*Qxyz.x*Qxyz.x-2.0f*Qxyz.y*Qxyz.y;
	matrix[11]=0.0f;
	matrix[12]=0.0f;
	matrix[13]=0.0f;
	matrix[14]=0.0f;
	matrix[15]=1.0f;
	glLoadMatrixf((const float*)&matrix);
	glTranslatef(my_position.x,my_position.y,my_position.z);
}

void DrawGLScene()
{
	double deltat;
	deltat=GetTime();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glLoadIdentity();
	CalculateNewPos((float)deltat);
	DrawSkybox();
	glPushMatrix();
		glLoadIdentity();
		glPushMatrix();
			glTranslatef(EARTH->x,EARTH->y,EARTH->z);
			ShowObject(EARTH->model);
		glPopMatrix();
		glPushMatrix();
	        glTranslatef(0.0f,0.0f,5.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();
	glPopMatrix();
}
 

how should it be done correctly ?

Generally vertices of an object surround (0,0,0) and you keep track of how glTranslate and glRotate would affect the object’s position.

If you run your program and can’t see anything drawn, comment out your camera rotations and draw some polys with positive z-coordinates. You can make small adjustments from there to better understand what your rotations are doing.

Don’t try anything too complicated until you feel comfortable predicting where you are moving objects to.

My object is located at position 0,0,-15 relative to identity.now if i move or rotate camera new coordinates are calculated according to CalculateNewPosition().The problem is that object still remains in coordinates 0,0,-15 relative to new position - it is still centered on the screen - and doesn’t move.