C++ Question (math) yaw/pitch -> vector3, vector3 -> yaw/pitch?

atomicdryad

Fracking toaster
Addon Developer
Joined
Dec 25, 2010
Messages
46
Reaction score
0
Points
0
Okay so I fail at math >.>
I've created a system for customized camera/telescope mounts, which works spiffy save for the fact that I have no bloody clue how to pan/tilt the things. Actually, I have an idea, just no clue on how to translate:

pan(rad) + tilt(rad) -> SetCameraDefaultDirection(x,y,z) (from a default of 0,0,1) and vice versa. The range of movement would be 360deg pan and 220deg tilt (-20 -> +90 -> -20) if that has any bearing (bada-bum!).

Eventually this will be tied into a (couple of?) MGROUP_ROTATE animations and have the ability to target and track objects...but before all that, I must obtain a clue on the whole euler angle <-> vector3 direction/rotation thing.

Woefully ignorant of scary math terminology, my mind would grasp (pseudo) code best, however I'm not asking for actual functions...it could cpp, php, or perl, but please no forth...while doable, I generally do not like turning my brain inside out. XD
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,660
Reaction score
2,381
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
if you just do elevation and azimuth, it is simply a transformation from spherical coordinates into cartesian. Nothing that should scare you.

What you must remember: Orbiter uses a left-handed coordinate system. Most math books use a right-handed one.

---------- Post added at 09:52 PM ---------- Previous post was at 09:34 PM ----------

Ok, lets give you the math:

Lets assume you have 0° pitch and 0° yaw in vessel coordinates as Z = 1.0.

Then the direction vector for the camera is simply:

[math]{\vec{d}}^{0} = \begin{pmatrix} \sin{\alpha} \cdot \cos{\beta} \\ \sin{\beta} \\ \cos{\alpha} \cdot \cos{\beta} \end{pmatrix}[/math]
 

atomicdryad

Fracking toaster
Addon Developer
Joined
Dec 25, 2010
Messages
46
Reaction score
0
Points
0
if you just do elevation and azimuth, it is simply a transformation from spherical coordinates into cartesian. Nothing that should scare you.

What you must remember: Orbiter uses a left-handed coordinate system. Most math books use a right-handed one.

---------- Post added at 09:52 PM ---------- Previous post was at 09:34 PM ----------

Ok, lets give you the math:

Lets assume you have 0° pitch and 0° yaw in vessel coordinates as Z = 1.0.

Then the direction vector for the camera is simply:

[math]{\vec{d}}^{0} = \begin{pmatrix} \sin{\alpha} \cdot \cos{\beta} \\ \sin{\beta} \\ \cos{\alpha} \cdot \cos{\beta} \end{pmatrix}[/math]

livQ0.png

Sorry for the slow response, it's been a hectic couple of weeks here. The formula works great for the camera functions! Thank you!

Code:
yawpitch2cart(double yaw, double pitch) {
	return _V(sin(yaw)*cos(pitch), sin(pitch), cos(yaw)*cos(pitch) );
}
I've tied it into relevant MESHGROUP_ROTATE animations (where appropriate) as so: SetCameraDefaultDirection(yawpitch2cart(cameras[cfg->cam].yaw_proc*PI*2, cameras[cfg->cam].pitch_proc*PI*2));

If curious, it's implemented in http://orbiterfixes.googlecode.com/files/orion-2011-2.1beta1.zip (code at http://code.google.com/p/orbiterfix...-2010fix/Orbitersdk/samples/orion-20m-2010fix )
 
Top