SDK Question Rotating a Mesh, and a Jettisoned Payload

Piper

Orbiting Space Addict
Addon Developer
Tutorial Publisher
Donator
Joined
Apr 7, 2008
Messages
356
Reaction score
0
Points
0
Location
Ottawa, Canada
So I've finally decided on taking the great leap from Spacecraft3 to creating proper modules for all my spacecraft. Right now I'm working with my Io Orbiter, and I've got all the basics down for creating and releasing a payload, but for the Lander I need to rotate the mesh 90deg first, and of course it needs to be rotated the same amount and direction when it's released.

I've tried MeshgroupTransform to rotate the mesh, but I've absolutely gotten no where with that one. No matter what I do I can't get the mesh to rotate, even in the wrong direction. I know I could just create a mesh that's physically rotated the right way, I'd rather see if I can do it with code.

With the released payload I can rotate it, but I just can't get it rotated in the right direction. I've tried applying a rotation matix to the vessel's orientation, but that only rotates it against the ecliptic, and not the axis of the spacecraft.

Anyone able to give me any help on this?
 
You should be able to use a regular animation. Instead of passing an array when creating the MGROUP_ROTATE struct, set the 'grp' pointer to NULL - this will animate the entire mesh.
 
I'm not sure I quite follow... is the payload a separate vessel all the time, or is its mesh integrated into the main vessel and only becomes its own vessel on release?

If the first, The easiest thing is to rotate the attachment point it is attached to. If the second, things get a bit more involved.
 
I'm not sure I quite follow... is the payload a separate vessel all the time, or is its mesh integrated into the main vessel and only becomes its own vessel on release?

If the first, The easiest thing is to rotate the attachment point it is attached to. If the second, things get a bit more involved.

It's the second. With that said, maybe I should be doing this as an attachment instead. I guess it would solve both problems. I'll give that a try.
 
With the released payload I can rotate it, but I just can't get it rotated in the right direction. I've tried applying a rotation matix to the vessel's orientation, but that only rotates it against the ecliptic, and not the axis of the spacecraft.
That could indicate that you are applying the rotations in the wrong order. If R_local is the rotation of the payload relative to the parent vessel, and R_vessel is the parent vessel's global rotation matrix, you want to set the payload's rotation matrix to

R_vessel R_local

not the other way round.
 
I wrote this function for jettisonning a payload with specified angle (x is pitch, y is roll and z is yaw, rotation is a VECTOR3):
Code:
MATRIX3 mat, matX, matY, matZ, matF;

// Getting current rotation matrix
m_pVessel->GetRotationMatrix(mat);

// rotation in pitch
double sina = sin(rotation.x*RAD);
double cosa = cos(rotation.x*RAD);
matX = _M(1,0,0,  0,cosa,sina,  0,-sina,cosa);

// rotation in roll
sina = sin(rotation.y*RAD);
cosa = cos(rotation.y*RAD);
matY = _M(cosa,0,sina,  0,1,0,  -sina,0,cosa);

// rotation in yaw
sina = sin(rotation.z*RAD);
cosa = cos(rotation.z*RAD);
matZ = _M(cosa,sina,0,  -sina,cosa,0,  0,0,1);

// multiply everything
matF = mul(mat, mul(matX, mul(matY, matZ)));

// calculate the angles
vs.arot.x = atan2(matF.m23, matF.m33);
vs.arot.y = -asin(matF.m13);
vs.arot.z = atan2(matF.m12, matF.m11);

// create the vessel
OBJHANDLE obj = oapiCreateVessel(GetName().c_str(), configName.c_str(), vs);
 
Yaaay!!! I got it to work using attachments :) Thank you so much guys.
 
Back
Top