Game Theory
#1
Posted 01 February 2003 - 12:33 AM
my problem is with complete 360 degree rotations about 3D space. I tried trig functions sin and cos to rotate about a plane and that works fine but in 3D space it only works on the 'positive' quadrants. I tried vector manipulations (cross product of a general UP vector with the forward vector to get the "left-right" orientation and then crossing the left-right vector with the forward to get the "up-down" vector...). now i'm back to trig functions in combination with spherical coords and i run to a similar problem [one of the 'axis' remains positive]. anybody got any hints?
I also wanted to grease the wheels of just having a theoretical discussion about anything game-related: from cool effects, AI, whatever.
thanks
#2
Posted 01 February 2003 - 02:38 PM
Hope this is what you were looking for.
struct VectorStruct
{
float X, Y, Z;
}
VectorStruct RotateLeftXAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.Z = TempV1.Z * (cos(Degrees*PI/180)) + TempV1.Y * (sin(Degrees*PI/180));
V1.Y = TempV1.Y * (cos(Degrees*PI/180)) - TempV1.Z * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateLeftYAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.X = TempV1.X * (cos(Degrees*PI/180)) + TempV1.Z * (sin(Degrees*PI/180));
V1.Z = TempV1.Z * (cos(Degrees*PI/180)) - TempV1.X * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateLeftZAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.Y = TempV1.Y * (cos(Degrees*PI/180)) + TempV1.X * (sin(Degrees*PI/180));
V1.X = TempV1.X * (cos(Degrees*PI/180)) - TempV1.Y * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateLeftAllAxis(VectorStruct V1, float Degrees[])
{
V1 = RotateLeftXAxis(V1, Degrees[x]);
V1 = RotateLeftYAxis(V1, Degrees[y]);
V1 = RotateLeftZAxis(V1, Degrees[z]);
return V1;
}
VectorStruct RotateRightXAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.Z = TempV1.Z * (cos(Degrees*PI/180)) - TempV1.Y * (sin(Degrees*PI/180));
V1.Y = TempV1.Y * (cos(Degrees*PI/180)) + TempV1.Z * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateRightYAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.X = TempV1.X * (cos(Degrees*PI/180)) - TempV1.Z * (sin(Degrees*PI/180));
V1.Z = TempV1.Z * (cos(Degrees*PI/180)) + TempV1.X * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateRightZAxis(VectorStruct V1, float Degrees)
{
VectorStruct TempV1;
if(Degrees < 0)
{
Degrees = 360 + Degrees;
}
TempV1 = V1;
V1.Y = TempV1.Y * (cos(Degrees*PI/180)) - TempV1.X * (sin(Degrees*PI/180));
V1.X = TempV1.X * (cos(Degrees*PI/180)) + TempV1.Y * (sin(Degrees*PI/180));
return V1;
}
VectorStruct RotateRightAllAxis(VectorStruct V1, float Degrees[])
{
V1 = RotateRightXAxis(V1, Degrees[x]);
V1 = RotateRightYAxis(V1, Degrees[y]);
V1 = RotateRightZAxis(V1, Degrees[z]);
return V1;
}
#3
Posted 01 February 2003 - 08:29 PM
#4
Posted 01 February 2003 - 11:32 PM
thanks
#5
Posted 02 February 2003 - 05:04 PM
#6
Posted 02 February 2003 - 06:02 PM
http://www.gametutorials.com/Tutorials/ope.../OpenGL_Pg4.htm
4th tutorial down on the page.
<a href='http://www.c3command.com' target='_blank'>C3 Command</a>
#7
Posted 04 February 2003 - 03:05 AM
again, thanks.
#8
Posted 04 February 2003 - 04:08 PM
at any rate i really appreciate everybody's input.
again, thanks.
#9
Posted 05 February 2003 - 08:00 AM
donBerto said:
at any rate i really appreciate everybody's input.
again, thanks.
#10
Posted 05 February 2003 - 12:45 PM
rough definition of gimbal lock: calculation of some angles may 'override' another, preventing an angle from being positive/negative or whatever.
good definition: http://www.gamedev.net/reference/articles/...article1095.asp
[third blue heading down the page].
and excuse me, the site is from UCberkely, not UCLA. sorry. here:
http://www.cs.berkeley.edu/~laura/cs184/qu...quaternion.html
an example of gimbal lock [similar to what I encountered]:
struct vector
{
float x, y, z;
};
void func(float horizAngle, float vertAngle)
{
vector forwardv;
// looking up and down
forwardv.z = cos(vertAngle); // first z calculation
forwardv.y = sin(vertAngle);
// looking left and right
forwardv.x = cos(horizAngle);
forwardv.z = sin(horizAngle); // gimbal lock - overrides first z's calculation
}
i hope this will helpl people in the long-run.
cheers,
-berto
#11
Posted 08 February 2003 - 03:20 PM
reading through it now and I'm finding it very useful. I hope it is for you too.
here it is:
http://skal.planet-d...o/matrixfaq.htm
#12
Posted 08 February 2003 - 03:45 PM
http://skal.planet-d...o/matrixfaq.htm
sub-pixel interpolation for motion estimation.
Two Convex Hull algorithms for finding good bounding slabs
Just to name a few, but many more.
<a href='http://www.c3command.com' target='_blank'>C3 Command</a>
#13
Posted 12 February 2003 - 02:32 AM
#14
Posted 15 February 2003 - 07:44 AM
using your implementation i had some time to test and i'm still testing. so far, here's the lock. THE MISTAKE COULD BE IN MY END:
individual rotation works great. so far, the only case i have is when i rotate 90 degrees about the y axis and then rotating about the x axis -- instead of looking up and down, it looks "roll-left" to "roll-right" -- z rotation.
but like i said, the error could be on my part I have a forward vector [using your vector struct] and then i cross with a global up to get the side axis. I then cross forward with side to get the relative up axis. i place the 3 vectors in a matrix and glMultMatrix.
let's beat the hell out of this problem so that no one will ever have to go through with it :yes:
#15
Posted 22 February 2003 - 11:20 PM
thanks for everybody's support. I appreciate that a lot.
:yes:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












