![]() |
|
|||||||
| Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
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) ---------- 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. |
|
|
|
|
|
#2 |
|
Beta Tester
![]() ![]() ![]() |
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. |
|
|
|
|
|
#3 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
|
|
|
|
|
|
#4 |
|
Addon Developer
![]() ![]() |
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. |
|
|
|
|
|
#6 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
![]() Now for the 2nd part of the question, any ideas? |
|
|
|
|
|
#7 |
|
Addon Developer
![]() ![]() |
Quote:
Quote:
|
|
|
|
|
|
#8 |
|
50% Orbinaut, 50% Developer
![]() |
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); |
|
|
|
|
|
#9 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
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){}
Last edited by Hlynkacg; 04-15-2012 at 07:00 PM. |
|
|
|
|
|
#10 |
|
50% Orbinaut, 50% Developer
![]() |
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) |
|
|
|
| Thanked by: |
|
|
#11 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
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
}
Code:
// Reposition thrusters GetThrusterRef (th_descent, input); SetThrusterRef (th_descent, LEM::RotateVector(input, rotation) ); Last edited by Hlynkacg; 04-16-2012 at 12:21 AM. |
|
|
|
|
|
#12 |
|
Addon Developer
![]() |
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);
}
Code:
auto srcVector = _V(1.0, 0.0, 0.0); auto res = mul(rotMat, srcVector); Last edited by asmi; 04-18-2012 at 12:38 AM. |
|
|
|
| Thanked by: |
|
|
#13 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
Never mind I figured it out, I use the "VECTOR3 mul" function. Last edited by Hlynkacg; 04-17-2012 at 10:14 PM. |
|
|
|
|
|
#14 |
|
Addon Developer
![]() |
Quote:
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);
}
Code:
VECTOR3 srcVector = _V(1.0, 0.0, 0.0); VECTOR3 res = mul(rotMat, srcVector); Code:
std::vector<std::wstring> list;
for(auto it = list.begin(); it != list.end(); it++)
{
}
Code:
std::vector<std::wstring> list;
for(std::vector<std::wstring>::iterator it = list.begin(); it != list.end(); it++)
{
}
Last edited by asmi; 04-18-2012 at 12:48 AM. |
|
|
|
| Thanked by: |
![]() |
|
| Thread Tools | |
|
|
|||||
| Quick Links | Need Help? |