• What is your GameDev Story?

Archived

This topic is now archived and is closed to further replies.

3D Space. Moving in it...?

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

Recommended Posts

Ok, I have all these components- x, y, z Two angles, a and b Speed I need to move x, y, z in the rotated direction. a = angle YZ and b = angle XZ Y Z | / | / |a/b |/_______X This formula seemed to work. ( A and B start as angles ) // Convert angles to radians fA = DegToRad( fA ); fB = DegToRad( fB ); x -= (float)cos(fA)*fVel; z -= (float)sin(fA)*fVel; y += (float)sin(fB)*fVel; This works until angle B is within the range of 90-270. Then you go the wrong way. I hope this makes sense. I am not very good at explaining things. Basically, I need to know why this does not work in those ranges.

Share on other sites

What is X,Y,Z?
Is your angles (fa,fb) the angles between the velocityvector and coordinate axis?

/Mankind gave birth to God.

Share on other sites
I had the same exact problem, its annoying isn''t it. I could never figure it out, but I can help give a better explanation.

What happens is this. Say you are in a space ship, you pull up, and do a complete loop, instead of going forwards at the end of the loop, you end up going backwards. I have no clue why that happens, it this Gimble lock? I''ve heard that term, but never really understood it. Oh well, I hope I gave some more light on this problem.

Share on other sites
x, y, and z are coordinates in 3d space.

fA is the angle to rotate around the Y axis and fB is to rotate around the X axis.

Share on other sites
Sweet. I figured it out (I think). If I just subtract 180 from the fA then it works great. I kinda hacked it though so if you can give an explanation of why it works then I would be very thankful.

Share on other sites
f = sin(240)
a = asin(f)

guess what the value of a is.

1) 240
2) -60
3) a loud rasberry

if you picked 2 you are right. Why?

Sine values go from -90 to 90 (as do cosine). So if you are farting about with values outside this range, you gotta add or subtract 90, 180 90 - ang, 180 - ang.

IMHO: My experience tells me that when I start doing stuff like this (adjusting my values) it is because I am using the wrong approach. It may work now, but when you start to expand upon your engine, you quickly run into all sorts of HORRIBLE problems.

D.V.

Edited by - DeltaVee on September 23, 2001 5:45:30 PM

Share on other sites
So what do I do? Just keep the ranges within -90 to 90?

Share on other sites
If you do that then you loose 2 quadrants along the x/z, y/z or x/y plane. Behind you left and behind you right.

I''m sorry to say that in my particular instance (trying to calculate the delta vee from one object to the one it was tracking) I failed. I have gone back to rethink the problem and solution (after taking a quick maths tutorial).

Sorry.

D.V.

Share on other sites
Ug. And it seems so simple too!

Share on other sites
ok, if had the same problem, after a few sweaty hours I came up with a workin result:

void Delta::rotPoint( double value, int direction ){	bool yhalf;	bool xhalf;	double rx;	double ry;	double oldang;	double newang;	double radius;	double newx;	double newy;/* ok, the point that should be rotated is (in this case) located in some arrays - Xpoint/Ypoint/Zpoint, with the address "tell" just so that isnt to confusing */	if(direction == 1)	{		rx = (float)Xpoint[tell];		ry = (float)Ypoint[tell];	}	if(direction == 2)	{		rx = (float)Xpoint[tell];		ry = (float)Zpoint[tell];	}	if(direction == 3)	{		rx = (float)Ypoint[tell];		ry = (float)Zpoint[tell];	}     // next thing is to determine which quadrant the point is in	if(rx < 0)	{		xhalf = false;	}	else	{		xhalf = true;	}	if(ry < 0)	{		yhalf = false;	}	else	{		yhalf = true;	}     //the radius is the distance from the point to origo (0,0,0)      radius = sqrt((rx * rx) + (ry * ry));      if(xhalf && yhalf)	{		oldang = asin(rx/radius);      	newang = oldang - value;		newx = sin( newang ) * radius;		newy = sqrt((radius * radius) - (newx * newx));	}	if(!xhalf && yhalf)	{		oldang = asin(ry/radius);		newang = oldang - value;		newy = radius * sin(newang);		newx = -sqrt((radius * radius) - (newy * newy));	}	if(!xhalf && !yhalf)	{		oldang = -asin(rx/radius);		newang = oldang - value;		newx = -sin(newang) * radius;		newy = -sqrt((radius * radius) - (newx * newx));	}	if(xhalf && !yhalf)	{		oldang = -asin(ry/radius);		newang = oldang - value;		newy = -sin(newang) * radius;		newx = sqrt((radius * radius) - (newy * newy));	}/* the new position is found, the code below only adjusts the original coordinate in the array */	if(direction == 1)	{		Xpoint[tell] = (float)newx;		Ypoint[tell] = (float)newy;	}	if(direction == 2)	{		Xpoint[tell] = (float)newx;		Zpoint[tell] = (float)newy;	}	if(direction == 3)	{		Ypoint[tell] = (float)newx;		Zpoint[tell] = (float)newy;	}}

.. this code is not commented im afraid, just ask about any parts that is confusing.

Edit: added some comments and removed a few irrelevant sections

Edited by - Jesper T on September 24, 2001 5:58:20 PM

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 28
• 16
• 10
• 10
• 11
• Forum Statistics

• Total Topics
634111
• Total Posts
3015564
×