# Find Degrees

This topic is 5412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to know how to find the degrees when I have eyeX,eyeY,eyeZ,centerX,centerY and centerZ already plugged into gluLookat... I use degrees to set my camera to properly look around like so...
targetX = eyeX + sin(facing*PI/180.0);
targetY = eyeY + tan(facing2*PI/180.0);
targetZ = eyeZ + cos(facing*PI/180.0);


target is the same as center for gluLookAt Now I would inverse the formula to find each I suppose...
facing = asin((targetX - eyeX)* 180.0 / PI);
facing2 = atan((targetY - eyeY)* 180.0 / PI);

or

facing = asin(targetX - eyeX) * 180.0 / PI;
facing2 = atan(targetY - eyeY) * 180.0 / PI;


Both give me incorrect degrees....So how do I get the degrees?

##### Share on other sites
Well I suppose no one knows when you throw in the Z coordinate...

Ive gotten a little closer but I cannot figure out the horizontal angle of rotation when Y is the up vector...

wrong: horizontalfacing = atan2(targetX - eyeX, targetY - eyeY) * 180 / PI;right: vertical (this one works)facing2 = atan2(targetY - eyeY, targetX - eyeX) * 180 / PI;

##### Share on other sites
the z coordinate shouldn't be any problem at all, sorry i dont have the time to figure out the formulas so i'll leave you with some advice.

draw it out on paper and form a triangle, then remember the SOHCAHTOA rule. Sin = Opposite/Hypotenuse, Cos = Adjacent/Hypotenuse and Tan = Opposite/Adjacent. Just using those rules and the triangle you drew (draw the 2 points, extend the lengths in 2 dimenstions) and you should be able to see it by just looking at it. Take one of those rules and find the angle in the corner that you wont. Opposite is the edge opposite to the corner, adjacent runs along it and connects to opposite at a 90 degree angle.

Hope that helped

##### Share on other sites
Actually I do better with formulas...I am rusty on my trig so please forgive me...

Oh and my last post...disregard...Neither of those formulas came even close...I absolutely have no idea at this point...

Anyone else?

##### Share on other sites
trust me draw it out,

this is purely off the top of my head, imagining the system as two triangles, one vertical the other horizontal. It may not be correct but what i got, took a minute.

vert = tan ((center.x - cam.x) / (center.y - cam.y));horz = tan ((center.x - cam.x) / (center.z - cam.z));

##### Share on other sites
Yeah I tried drawing it but I dont have a clue what I need to be looking for...Its the 3d thats throwing me in a loop...

Oh and your right those didnt work...Now I know im facing the right direction when I plot in the position of an object into the center vectors of gluLookAt the problem is my camera class uses angles to find the center position so if I dont find the angle I moved to by placing those new center points in my camera just resets to the previous view. Every damn cos sin tan ive tried gives me shit...

Heres my plane...

0-----------360

up and down is
270 top
90 bottom

Heres the camera plotting function if it clears things up:
void computeFacing(int old_x, int old_y, int new_x, int new_y) {	double mX,mY;	mX = abs((old_x - new_x)*0.355);	mY = abs((old_y - new_y)*0.64);	if ( new_x > old_x )	{		facing -= mX;		if (facing < 0.0) facing += 360.0;	}	if ( new_x < old_x )	{		facing += mX;		if (facing > 360.0) facing -= 360.0;	}	if ( new_y > old_y )	{		facing2 -= mY;		/* limit user's range of head movement */		if ( facing2 < 91.0f ) /* 120.0 */		facing2 = 91.0;	}	if ( new_y < old_y )	{		facing2 += mY;		/* limit user's range of head movement */		if ( facing2 > 269.0f )		facing2 = 269.0;	}}void processMouseMove(int x, int y){	mouseX = x;	mouseY = y;	if(move_state != MOVEMENT) {		prev_mouse_x = x;		prev_mouse_y = y;		return;	}	if(fxWindow != TOPO) {		double mX,mY;		/* make mouse turn variable on how fast mouse is turned */		if(x > screenX-2)			glutWarpPointer(10,y);		else if(x < 1)			glutWarpPointer(screenX-10,y);		computeFacing(prev_mouse_x, prev_mouse_y, x, y);		prev_mouse_x = x;		prev_mouse_y = y;	}} /* end mouseFunc */

Oh and if you havent figured it out yet I am trying to move to an object and center it on my screen.

Also Ive found out arctan is NOT the method I can use it gives me ONLY the following NO MATTER WHAT I put in eye and center...

135
45
-45
-135

And thats it...for targetx - eyex,targetY-eyeY targetz-eyez - target x-eyex whatever...All as above...So do I use asin2 or something...Ill try that and find a def for acos2 while im at it...

[Edited by - keyofrassilon on September 28, 2004 12:02:31 AM]

• 13
• 18
• 29
• 11