Advertisement

Calculating Translations using Rotations

Started by November 13, 2005 05:26 PM
0 comments, last by dawidjoubert 19 years ago
I'm designing a 3-dimensional game with tanks. Here is my problem: The tank is rotated to match the incline of the terrain on the x and y axes. The gun of the tank can also be rotated in the z axis, and the barrel can be rotated vertically to adjust the trajectory of the shell. I want the shell to originate precisely where the barrel of the tank is, but can't seem to derive a successful algorithm to translate from the base of the tank to the tip of the barrel using the rotations (ie, I need to get x, y, and z coordinates using only the original coordinates and the way the tank is rotated). Anyone have an idea on how to simplify this math?
2 Solutions exists for your problem but its basically 1 solution in 2 diffrent mehtods.

A. U could take the 3d Algebra , re-arrange it to get the algorithm
B. Matrices

B.

Matrices. Firstly each part that rotates on its own is an object on its own and thus a child to its attactchment

Tank_Base---->Tank_Turrret---->Tank_Barrel

Now the tank_base moves over the terrain like usual, the Tank_Turret can only rotate on 1 axis in this case Z and is used 2 align to a target, and then the Tank_Barrel is used to align the hieght of the shot.

Once all three of these are aligned you can use Matrix Multiplication to get the position of ur Shell(Bullet) remembering that the shell is child to the Tank_Barrel and in this case starts at the barrels end.

Now When working with matrices each Object has its own SPACE/Coordinate System. Look into md3 models for a better understanding. The Way to render objects which are matrix &Parent dependant is to go from the parent downwards example.

TankBase.MultiplyMatrix(); // Multiple with current WORLD_MATRIX
TankBase.Render();
TankTurret.MultiplyMatrix()
TankTurrent.Render
Tank_Barrel.MultiplyMAtrix()
Tank_Barrel.Render()

Now rendering is easy because OpenGL Handles the Matrix Multiplication, but when you need to do geometrical operations you must do the matrix calculations on ur own.

I have a lite DLL that u can use for simple/basic matrix operations. Drop ur email and ill send it.

... Here is how 2 get where the shell starts... *Assuming the barrels end is at 5,0,0 Barrel -> Space

float m[16];
mIdentity(m)
mMultiply(m,TankBase)
mMultiply(m,TankTurret)
mMultiply(m,TankBarrel)
..................
// Now we need to transform our point to get it into world space
Start = Transform(m,5,0,0);
End = EnemyTankBase.Position;

And there u have it a Ray Start-->End which will go through the enemy tank. Ofcourse this assumes a direct line to the enemy, which may not be the case when making arty.
----------------------------

http://djoubert.co.uk

This topic is closed to new replies.

Advertisement