# Problem with my rotation code?

Show 80 post(s) from this thread on one page
Page 3 of 3 First 123
• 12-20-2003
Isn't there a more efficient way of doing things? cause basically from what you're telling is that I have to translate to where the center of my needed rotation is for every single object that needs rotated? what is the computational expense by doing it?

Also, it means I will have to restructure my math yet again, as if I had two points, <0,0,-24> and <10,0,-24> (stored in vectors)and I wanted to rotate around the y-axis, translating to <0,0,-24>, then that second point would be way off in its rotation, as it should then be <10,0,0>, as <0,0,-24> is the new origin for it(however, I could just write out my objects so that each object has a center point, and all the rest of its points are relative to that center).

P.S.

Silvercord:

thank god for you recommending that book, as it has all the collision detection I could ever need, and it leaves the implementation codewise up to the individual pretty much.

A little NOTE: I am thinking that in a little bit I might need help with some of the collision detection, as most of it uses time to predict the collision, instead of distance; however I dont know how I could implement time into consideration(unless I always solve for "t" in my equations and when "t" is almost equal to 0 count it as a collision)
• 12-20-2003
Silvercord
I don't like the way they explain collision detection in that book, however ultimately it's very close to what i actually do.

If you plan on implementing quake3 BSP, you are going to need to learn the brush collision detection algorithm for colliding against the world. Also, collision detection was one of the more complicated things I had to code up. Ultimately the tutorials you'll read all have problems which I've had to work around or solve.
• 12-20-2003
VirtualAce
You are creating your objects around 0,0,0 aren't you? In local space that is or model space? If you create a model around another point when you create it, you are asking for troubles because every rotation you do is compounded upon the fact that the original model was not built around 0,0,0.
• 12-20-2003
Silvercord
blade i don't know what your problem is with the rotations/translations.
• 12-20-2003
Quote:

blade i don't know what your problem is with the rotations/translations.
I'm trying to remake the wheel(trying to code up my own solutions) it seems....it's something I unfortunatly do sometimes(AKA making things harder than they are).

so besides the practice I get by doing this coding, is there even a real purpose for it?
• 12-20-2003
Silvercord
what exactly are you doing, and what exactly is the problem? a little bit of intuition here and there never hurt anybody, but, like, I have no clue what you are trying to actually accomplish.
• 12-20-2003
Quote:

then that second point would be way off in its rotation
Right, like I said:
Quote:

Originally posted by grady
Code:

```struct angvelocity {         float x,y,z,degrees; };```
[snip]
So in addition to the above struct, you have to specify a point to adjust the axis away from the origin of the scene. Rotating not through the origin also makes you have to do a little pre and post processing on the vertex you are rotating.
Bubba is right but he left out what I referred to as the post processing. first tranlate to (x,y,z), rotate, then translate to (-x,-y,-z). This puts your rotated vector back in its proper place.

Quote:

There's an extremely easy way to do this....
I like that, but it only works if the velocity vector is the axis of rotation. There is no reason to assume in advance that a torque applied to your object will rotate the object about the velocity vector. The axis of rotation can point in any direction depending on where the torque is applied on the object.
• 12-20-2003
Silvercord
grady, I'm just wondering, have you ever programmed anything? If so, post it. Otherwise, I'm just going to continue ignoring absolutely everything you say.
• 12-20-2003
I am trying to program up Rotation code for the purpose of rotating the view vector of a camera, unless one could use a combination of Translating and rotating to do that.
• 12-20-2003
VirtualAce
Code:

```void Translate(double dx,double dy,double dz) {   double trans[4][4];   double result[4][4];     trans[0][0]=1.0;   trans[0][1]=0.0;   trans[0][2]=0.0;   trans[0][3]=dx;   trans[1][0]=0.0;   trans[1][1]=1.0;   trans[1][2]=0.0;   trans[1][3]=dy;   trans[2][0]=0.0;   trans[2][1]=0.0;   trans[2][2]=1.0;   trans[2][3]=dz;   trans[3][0]=0.0;   trans[3][1]=0.0;   trans[3][2]=0.0;   trans[3][3]=1.0;   MatMult(trans,master,result);   MatCopy(result,master); } //Would be faster for one-dimensional array void MatMult(double m1[4][4], double m2[4][4], double r[4][4]) {   for (int i=0;i<4;i++)   {     for (int j=0;j<4;j++     {         result[i][j]=((m1[i][0]*m2[0][j])+(m1[i][1]*m2[1][j])+(m1[i][2]*m2[2][j])+(m1[i][3]*m2[3][j]));     }   } } void MatCopy(double source[4][4],double target[4][4]) {   for (int i=0;i<4;i++)   {     target[i][0]=source[i][0];     target[i][1]=source[i][1];     target[i][2]=source[i][2];     target[i][3]=source[i][3];   } }```
This is part of my DOS 3D engine setup. Now OpenGL and DirectX both do this stuff for you. Before you transform your object - translate it to where you want it. Then rotate it and transform it.

The -x,-y,-z comes into play when you wish to move your player through the world - translate all objects by the negative vector of the player.
• 12-20-2003
VirtualAce
I'm just not sure what you are asking. I thought you were trying to rotate an object around a certain point.

Rotating the camera view vector and rotating an object around a set point are two different things.
• 12-20-2003
Quote:

Rotating the camera view vector and rotating an object around a set point are two different things.
I've been needing both...

the question is, is there any advantage of making one's own rotating function(for rotation around points) over using glRotate3f()?
• 12-20-2003
VirtualAce
You do not need a separate rotation function for rotating around points.

Here is what you need to determine:

In your world, what objects need to rotate around certain points?

Create a base class for this type of object that will auto-translate them to their correct position in local space and then derive from this class.

I have no idea as to your structure for vertexes, polies, complete 3D objects, etc.
• 12-20-2003