Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 04-14-2012, 05:13 AM   #1
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default Off-axis view angles.

So I'm working on a tail-sitter but I want the cockpit camera to be oriented along the Y-axis (parralel to the horizon) instead of the Z-axis (axis of thrust).

I placed the following code in my setclasscaps but when I load my test scenario the camera is still oriented along the Z-Axis.

Code:
SetCameraOffset (_V( 0.00, 0.00, 1.00)); // (x,y,z)
SetCameraDefaultDirection (_V( 0.00,-1.00, 0.00)); // (x,y,z)
SetCameraRotationRange (RAD*45,RAD*45,RAD*90,RAD*30); // (Left, Right, Up, Down)
Is there something I'm missing?

---------- Post added at 05:13 AM ---------- Previous post was at 02:10 AM ----------



Another Question

Is there a function to rotate a vessles frame of reference. AKA cause the Z+ axis to become the Y+ axis or vice versa?

Alternately is there a function that I can use to simply rotate my vessel by a given amount in the global frame? (and by rotating the mesh in the opposite direction achieve a similar effect)

Last edited by Hlynkacg; 04-14-2012 at 05:06 AM.
Hlynkacg is offline   Reply With Quote
Old 04-14-2012, 04:22 PM   #2
Donamy
Beta Tester


Default

Can you switch between 2 meshes ?
One in the Z_axis and one in the Y-axis. I do this (rather clumsily) with my Jason Lunar Lander, as a SC3.
Donamy is offline   Reply With Quote
Old 04-14-2012, 06:52 PM   #3
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Quote:
Originally Posted by Donamy View Post
 Can you switch between 2 meshes ?
One in the Z_axis and one in the Y-axis. I do this (rather clumsily) with my Jason Lunar Lander, as a SC3.
That would be the "rotated mesh" in my alternate plan but as you say, it's rather clumsy.
Hlynkacg is offline   Reply With Quote
Old 04-14-2012, 07:09 PM   #4
N_Molson
Addon Developer
 
N_Molson's Avatar

Default

For my lander docking cam I did the following, it works very well :

Code:
case OAPI_KEY_B:

         // checking that the view is in cockpit mode
	if (!oapiCameraInternal() || CamMode == 2 || CamMode == 1) return 0;
        
        // location of the camera : 2.4 meters on the +Y axis
	SetCameraOffset (_V(0.0,2.4628,1));

        // Direction of the camera : +Y axis
	SetCameraDefaultDirection (_V(0,1,0));
        
        // Important, don't forget this
	oapiCameraSetCockpitDir(0,0);

         // I wanted a fixed view (camera)
	SetCameraRotationRange(0,0,0,0);

        // a variable to remember the active camera
	CamMode = 2;

return 1;

Last edited by N_Molson; 04-14-2012 at 07:17 PM.
N_Molson is offline   Reply With Quote
Old 04-14-2012, 07:11 PM   #5
Bibi Uncle
50% Orbinaut, 50% Developer
 
Bibi Uncle's Avatar
Default

Adding oapiCameraSetCockpitDir(0,0); after your SetCameraDefaultDirection (_V( 0.00,-1.00, 0.00)); should do the trick.
Bibi Uncle is offline   Reply With Quote
Thanked by:
Old 04-14-2012, 08:44 PM   #6
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Quote:
Originally Posted by Bibi Uncle View Post
 Adding oapiCameraSetCockpitDir(0,0); after your SetCameraDefaultDirection (_V( 0.00,-1.00, 0.00)); should do the trick.
That did it! thankyou kindly

Now for the 2nd part of the question, any ideas?
Hlynkacg is offline   Reply With Quote
Old 04-14-2012, 08:53 PM   #7
N_Molson
Addon Developer
 
N_Molson's Avatar

Default

Quote:
Is there a function to rotate a vessles frame of reference. AKA cause the Z+ axis to become the Y+ axis or vice versa?
AFAIK, no.

Quote:
Alternately is there a function that I can use to simply rotate my vessel by a given amount in the global frame? (and by rotating the mesh in the opposite direction achieve a similar effect)
An animation like MESHGROUP_ROTATE can probably do it. You make it instant so that there is no transition between the two states. For the vessel you can always copy-paste the thrusters definitions & Co, modifying the direction & location vectors so that it fits the rotated mesh.

N_Molson is offline   Reply With Quote
Old 04-15-2012, 02:03 PM   #8
Bibi Uncle
50% Orbinaut, 50% Developer
 
Bibi Uncle's Avatar
Default

To rotate the whole vessel, VESSEL::SetRotationMatrix is your friend.

An example:

m_pVessel is a pointer to the vessel, rotation is a VECTOR3 defining the rotations around each axis.
Code:
 
MATRIX3 mat, matX, matY, matZ, matF;
 
// Get the current rotation matrix
m_pVessel->GetRotationMatrix(mat);
 
// X axis rotation
double sina = sin(rotation.x*RAD);
double cosa = cos(rotation.x*RAD);
matX = _M(1,0,0, 0,cosa,sina, 0,-sina,cosa);
 
// Y axis rotation
sina = sin(rotation.y*RAD);
cosa = cos(rotation.y*RAD);
matY = _M(cosa,0,sina, 0,1,0, -sina,0,cosa);
 
// Z axis rotation
sina = sin(rotation.z*RAD);
cosa = cos(.rotation.z*RAD);
matZ = _M(cosa,sina,0, -sina,cosa,0, 0,0,1);
 
// Multiply everything and set the current rotation matrix
matF = mul(mat, mul(matX, mul(matY, matZ)));
m_pVessel->SetRotationMatrix(matF);
Bibi Uncle is offline   Reply With Quote
Thanked by:
Old 04-15-2012, 06:54 PM   #9
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Thankyou ^ this looks like exactly what I was looking for.

Now please forgive the newbie questions but...

1: how do I set 'm_pVessel' to be the currently focused vessel?

2: what x,y,z values would I enter into 'rotation' to rotate the vessel +90 degrees (pi/2 RAD) around the X axis?

and

3: I want to set the rotation as a void function so I can call it at will. Would something like...

Code:
void Spider::Rotate(VECTOR3 rotation){}
...(where 'Spider' is the vessel class) be sufficient or do I need more?

Last edited by Hlynkacg; 04-15-2012 at 07:00 PM.
Hlynkacg is offline   Reply With Quote
Old 04-15-2012, 07:43 PM   #10
Bibi Uncle
50% Orbinaut, 50% Developer
 
Bibi Uncle's Avatar
Default

If you write this code inside your vessel class, just remove every "m_pVessel->" (Ctrl-H in Visual Studio, type "m_pVessel->" without the quotes in the first field, nothing in the second field, and click OK). I have this because this code is copied from another class.

Your vector would look like _V(90, 0, 0). My function uses degrees.

This would be sufficient. For speed concerns, you could take a reference to the vector, but the difference will be unnoticeable. In the case you want it, just write:
void Spider::Rotate(const VECTOR3& rotation)
Bibi Uncle is offline   Reply With Quote
Thanked by:
Old 04-15-2012, 10:25 PM   #11
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Ok I got it up and running

Related question, is there a way to rotate a mesh as a whole instead of having to define each group?

---------- Post added at 10:25 PM ---------- Previous post was at 09:10 PM ----------

I really appreciate the help so far but there's still more to do.

As I rotated the vessel I want to apply a eqivilent counter rotation to my thrusters, docking ports, etc. so that the vessel maintains the same physical orientation.

this is what I've got so far but I could use some help on the math and someone with more experiance than I to make sure that it'll do what I want.

Code:
VECTOR3 Spider::RotateVector(const VECTOR3& input, const VECTOR3& rotation)
	{
		VECTOR3 output = {input.x, input.y, input.z}; // Set initial values for output
		
		// Apply X axis rotation 
		double sina = sin(rotation.x*RAD);
		double cosa = cos(rotation.x*RAD);
		output.y = output.y*cosa - output.z*sina;
		output.z = output.y*sina + output.z*cosa;

		// Apply Y axis rotation
		sina = sin(rotation.y*RAD);
		cosa = cos(rotation.y*RAD);
		output.z = output.z*cosa - output.x*sina;
		output.x = output.z*sina + output.x*cosa;

		// Apply Z axis rotation
		sina = sin(rotation.z*RAD);
		cosa = cos(rotation.z*RAD);
		output.x = output.x*cosa - output.y*sina;
		output.y = output.x*sina + output.y*cosa;

		return output; // Return rotated vector
	}
The idea is that in the 'RotateVesselFrame' script I can enter something along the lines of...

Code:
	// Reposition thrusters 
	GetThrusterRef (th_descent, input);
	SetThrusterRef (th_descent, LEM::RotateVector(input, rotation) );
Right now the project compiles but nothing happens when I try to apply the rotation.

Last edited by Hlynkacg; 04-16-2012 at 12:21 AM.
Hlynkacg is offline   Reply With Quote
Old 04-17-2012, 07:39 PM   #12
asmi
Addon Developer
Default

Here is a function that builds rotation matrix along arbitrary axis:
Code:
void BuildRotationMatrix(MATRIX3& result, const VECTOR3& rotationAxis, double angle)
{
	auto c = cos(angle);
	auto s = sin(angle);
	auto t = 1.0 - c;
	auto x = rotationAxis.x, y = rotationAxis.y, z = rotationAxis.z;
	result = _M(t * x * x + c,	t * x * y - s * z,	t * x * z + s * y,
		t * x * y + s * z,	t * y * y + c,		t * y * z - s * x,
		t * x * z - s * y,	t * y * z + s * x,	t * z * z + c);
}
Usage is like that:
Code:
auto srcVector = _V(1.0, 0.0, 0.0);
auto res = mul(rotMat, srcVector);
One important note - the rotation axis has to be a unit vector!

Last edited by asmi; 04-18-2012 at 12:38 AM.
asmi is offline   Reply With Quote
Thanked by:
Old 04-17-2012, 08:17 PM   #13
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

Quote:
Originally Posted by asmi View Post
 Here is a function that builds rotation matrix along arbitrary axis...
Ok, more newbie questions, what is auto? and how do I go about applying the matrix to a VECTOR3?

Never mind I figured it out, I use the "VECTOR3 mul" function.

Last edited by Hlynkacg; 04-17-2012 at 10:14 PM.
Hlynkacg is offline   Reply With Quote
Old 04-18-2012, 12:33 AM   #14
asmi
Addon Developer
Default

Quote:
Originally Posted by Hlynkacg View Post
 Ok, more newbie questions, what is auto? and how do I go about applying the matrix to a VECTOR3?

Never mind I figured it out, I use the "VECTOR3 mul" function.
auto is a keyword from C++11 Saves some typing by deducing the type of a variable from the type of expression to the right of equal sign. Works in MS VS 2010 and higher.
Here is "old-fashion" version:
Code:
void BuildRotationMatrix(MATRIX3& result, const VECTOR3& rotationAxis, double angle)
{
	double c = cos(angle);
	double s = sin(angle);
	double t = 1.0 - c;
	double x = rotationAxis.x, y = rotationAxis.y, z = rotationAxis.z;
	result = _M(t * x * x + c,	t * x * y - s * z,	t * x * z + s * y,
		t * x * y + s * z,	t * y * y + c,		t * y * z - s * x,
		t * x * z - s * y,	t * y * z + s * x,	t * z * z + c);
}
And second piece:
Code:
VECTOR3 srcVector = _V(1.0, 0.0, 0.0);
VECTOR3 res = mul(rotMat, srcVector);
This keyword is very useful when used with STL containers. Compare this:
Code:
std::vector<std::wstring> list;
for(auto it = list.begin(); it != list.end(); it++)
{
}
with "old-fashioned" version:
Code:
std::vector<std::wstring> list;
for(std::vector<std::wstring>::iterator it = list.begin(); it != list.end(); it++)
{
}
I think difference is pretty obvious

Last edited by asmi; 04-18-2012 at 12:48 AM.
asmi is offline   Reply With Quote
Thanked by:
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 01:49 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2007 - 2012, Orbiter-Forum.com. All rights reserved.