Getting the angle and heading based on
by Davis Ray Sickmon, Jr · in Torque Game Engine · 01/21/2003 (9:55 pm) · 5 replies
Ok, I've got a 'duh' type thing goin' here. I'm having a serious problem understanding how to do some work with the camera.
What I'm tryin' to do is make a nice little display for the player that shows the current heading, and angle they have thier turret at. No problem. Except... I can't figure out how ta' get the heading and angle based on the horizion, and a 'true north' type arrangement.
Right now, I'm using cam.getrow(1, &camAngle) to get the heading and convert it to degrees using Matt Webster's guiradar as an example. Problem is, if you move the turret up and down, the heading angle changes just a bit.
So what's the best way (hopefully in small words or code snippet, since I'm matrix math impaired ;-) to pull this off?
What I'm tryin' to do is make a nice little display for the player that shows the current heading, and angle they have thier turret at. No problem. Except... I can't figure out how ta' get the heading and angle based on the horizion, and a 'true north' type arrangement.
Right now, I'm using cam.getrow(1, &camAngle) to get the heading and convert it to degrees using Matt Webster's guiradar as an example. Problem is, if you move the turret up and down, the heading angle changes just a bit.
So what's the best way (hopefully in small words or code snippet, since I'm matrix math impaired ;-) to pull this off?
About the author
#2
Shoulda done the trick, I thought. How... odd.
02/19/2003 (6:20 pm)
Oddly enough - getAnglesFromVector ends up returning me the same whacky problem. I'm looking at the camera... could that be my problem? I have no idea. But, here's the wierd part://------------------------------------------------------------------------------ // Returns yaw and pitch angles from a given vector. Angles are in RADIANS. // Assumes north is (0.0, 1.0, 0.0), the degrees move upwards clockwise. // The range of yaw is 0 - 2PI. The range of pitch is -PI/2 - PI/2. // ASSUMES Z AXIS IS UP //------------------------------------------------------------------------------
Shoulda done the trick, I thought. How... odd.
#3
If someone has my answer, please please please let me know. Since there isn't anyplace in the ShapeBase that stores current roll/pitch/yaw (it's in the object transform matrix, but I'm no math guru) it has to be gotten.
Anyhoo.. Share a solution with me and I'll drop your name into the credits just before I release the code. It's just a GuiControl that derives from the wonderful rotated bitmap functions all over the forums.
- Brett
02/20/2003 (8:01 am)
This one was easy... I found the code you need in the player.cs file around the part for mouse looking. I'm using it for two parts of an attitude indicator (artificial horizon for those not in the know). The *hard* part is roll. No one seems to have this tackled in a simple way. I would figure that I could derive it from the forementioned code, but I haven't been able to figure it out.If someone has my answer, please please please let me know. Since there isn't anyplace in the ShapeBase that stores current roll/pitch/yaw (it's in the object transform matrix, but I'm no math guru) it has to be gotten.
Anyhoo.. Share a solution with me and I'll drop your name into the credits just before I release the code. It's just a GuiControl that derives from the wonderful rotated bitmap functions all over the forums.
- Brett
#4
Are you sure you're not assuming degrees in some of your code when you're actually getting radians? "Just a bit" implies only moving a couple of degrees, which is of course what would happen if you were using radians as input to something you should be using degrees with..
02/20/2003 (8:21 am)
Quote:
Problem is, if you move the turret up and down, the heading angle changes just a bit.
Are you sure you're not assuming degrees in some of your code when you're actually getting radians? "Just a bit" implies only moving a couple of degrees, which is of course what would happen if you were using radians as input to something you should be using degrees with..
#5
// get the transform, i.e. position and vector of the muzzle
MatrixF muzzleTrans;
S32 nWeaponSlot = 0;
pShapeBaseObject->getMuzzleTransform(nWeaponSlot, &muzzleTrans);
// get the position, i.e. x,y,z coordinates of the muzzle
Point3F position;
S32 nColumn = 3;
muzzleTrans.getColumn(nColumn, &position);
Thanks goes to ICE. I just learned this myself. I'm not sure if it will help you.
Robert
02/20/2003 (9:59 am)
Snippet-time!// get the transform, i.e. position and vector of the muzzle
MatrixF muzzleTrans;
S32 nWeaponSlot = 0;
pShapeBaseObject->getMuzzleTransform(nWeaponSlot, &muzzleTrans);
// get the position, i.e. x,y,z coordinates of the muzzle
Point3F position;
S32 nColumn = 3;
muzzleTrans.getColumn(nColumn, &position);
Thanks goes to ICE. I just learned this myself. I'm not sure if it will help you.
Robert
Torque 3D Owner Phil Carlisle
Why not use the getAnglesFromVector function? that would presumably return angles related to world space. Its in MathUtils.h
Otherwise, simply dot product the forward heading of your turret with a vector aligned with "north" in world space.
i.e. if we are looking down positive Z, then
cosangle = headingvector.dot(vector.set(0,0,1));
would give you the cosine of the inner angle between your heading and world north. Then simple acosf(cosangle) gives you the angle in radians.
But I'd recommend getAnglesFromVector first, these give you yaw and pitch :)
Phil.