Gimbling problem

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Hello. I am using the following to gimble the main engines based on user input:

Code:
     VESSEL *   vessel = oapiGetFocusInterface();
     VECTOR3    dir;
     OBJHANDLE  thruster;
     double     cLevel=vessel->GetControlSurfaceLevel(AIRCTRL_ELEVATOR);
     double     dLevel = vessel->GetControlSurfaceLevel(AIRCTRL_RUDDER);
     dir.x=-dLevel;
     dir.y=-cLevel;
     dir.z=1-cLevel-dLevel;
         dir  = nrmvec3(dir);
     for (int i = 0; i < vessel->GetGroupThrusterCount(THGROUP_MAIN); i++)
     {
         thruster = vessel->GetGroupThruster(THGROUP_MAIN, i);
         vessel->SetThrusterDir(thruster,dir);
     }

The problem is that when you pitch down, the thrusters don't go to the 0,-1,0 direction, instead it stops about half way there. The same with the yaw. I don't know what I am doing in terms of the math, any help would be appreciated:).
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
What do you expect? Mathematically, it would be impossible to get that. I would calculate with the trigonometry functions if you have more than +/- 5° deflection.
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
What do you expect? Mathematically, it would be impossible to get that. I would calculate with the trigonometry functions if you have more than +/- 5° deflection.

In school, we have done no more trigonometry then calculating sides/angles of a right triangle. Apparently the trigonometric functions are used for far more then that, as I see them being used all the time. I have been trying to learn more about them, and their uses, but I haven't had any luck yet. Even Google has failed me!:blink: So using trigonometry, how would you calculate the vector?

BTW, you have no idea of my ignorance, I have absolutely no clue whatsoever of how it's managing to work (partially, very usable). I just started assigning random values until it worked. ;)
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Well, what you want to do is basically speaking a rotation of the vector (0,0,1) around two axes. The order of the axes is not too important as long as you keep it the same.

A rotation can be mathematically described as matrix M. (3 x 3 matrix for VECTOR3) and the projection thus as "x' = M * x" with x being the vector.

Lets do it with x first and then y (pitch, then yaw).

The projection or Ez will look like that:

Ez' = My * Mx * Ez

Now, you just need Mx and My and the result of the matrix multiplication...
As you did not do such math for a long time, I think it is now the time where you will shout "Bull****", enter the cheat code (IDNFMM) and just want get the result. :rofl:

dir = _V(-sin(yaw), -sin(pitch)*cos(Yaw), cos(pitch)*cos(yaw));


Maybe you need to change some signs, I am not sure of the math is correct in a left handed coordinate system.
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
I think it's time I learn matrix multiplication...Hey don't think I don't want to learn and get the answers the easy way, you really start learning this stuff at the end of Algebra 2. I will hopefully take that next year, assuming I pass the exit exam for Geometry. Thanks for the formula, even though I have no idea how to use it for this particular appliction. ;)
 

MajorTom

Ker-splash!
Addon Developer
Donator
Joined
Mar 28, 2008
Messages
354
Reaction score
1
Points
0
Location
Puget Sound
Computerex,

If you're looking at a simple refresher of trig, for the purpose of figuring "unit vectors," try this:

1. Unit vectors provide direction only, and are of length 1.
2. All components, when squared, add up to 1.
3. Components are determined by simple cos and sin functions of their angles respective to the x, y and z axes.
4. Unit vectors are expressed in Orbiter as (x,y,z)

So the following are unit vectors:
(1,0,0) Length = 1, pointing in positive x direction
(0,1,0) Ditto, for y direction

How about an angle? Try a unit vector tilted 30 degrees, measured from x axis toward y, with no z component:

x component is cos 30
y component is sin 30
z component is zero
or
(0.866, 0.5, 0)

Square each component... (0.866)^2 + (0.5)^2 + (0)^2 = 1

This might get you moving again...

MT
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
I found some code on m6 by siamesecat

Code:
VECTOR3 RotateVectorY(const VECTOR3 &v, double angle)
{
    VECTOR3 Output;
    Output.y=v.y;
    Output.x=v.x*cos(angle*RAD)-v.z*sin(angle*RAD);
    Output.z=v.z*cos(angle*RAD)+v.x*sin(angle*RAD);
    return Output;
}

VECTOR3 RotateVectorX(const VECTOR3 &v, double angle)
{
    VECTOR3 Output;
    Output.x=v.x;
    Output.z=v.z*cos(angle*RAD)-v.y*sin(angle*RAD);
    Output.y=v.y*cos(angle*RAD)+v.z*sin(angle*RAD);
    return Output;
}

So I got it working by:
Code:
 VESSEL *   vessel = oapiGetFocusInterface();
     VECTOR3    dir = _V(0,0,1);
     OBJHANDLE  thruster;
     double     cLevel = vessel->GetControlSurfaceLevel(AIRCTRL_ELEVATOR)*-1;
     double     dLevel = vessel->GetControlSurfaceLevel(AIRCTRL_RUDDER)*-1;
     dir = RotateVectorX(dir, cLevel*90);
     dir = RotateVectorY(dir, dLevel*90);
     dir  = nrmvec3(dir);

Thanks for the replies.
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
computerex, perhaps Ar81's [ame="http://www.orbithangar.com/searchid.php?ID=3178"]Vectors for Dummies[/ame] tutorial might be helpful to understand some of the background math. You will see from his diagrams how the vector rotations discussed above are related to the triangles you have been learning about at school.
 
Top