Problem Failing to spawn a vessel at the desired position [solved, use clbkPreStep]

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
8,879
Reaction score
2,628
Points
203
Location
Toulouse
Hello,

Still on the Tianwen Mars project, I'm trying to spawn the parts jettisoned by the lander during the descent (shell and parachute, heatshield...). So I searched for a code sample doing this and I came with the below piece of code. It sort of works, but it seems it isn't accurate enough. The discarded vessel is created like 10 meters above my lander, and it seems tilted at a 90° angle. I'd expect it to spawn exactly where my vessel is, and oriented the same way. Right now, it looks crappy. So, what am I missing there ? ? My lander is oriented like a capsule, -Z axis is towards the heatshield +Z axis is towards the parachute. It is a rather small vessel so I don't see where that 10 meters (or more) offset is coming from...

C++:
void TIANWEN_LANDER::SpawnObject(void)
{
    VESSELSTATUS2 vs;
    vs.flag = 0;
    vs.version = 2;

    char name[256];
    VECTOR3 sofs = { 0, 0, 0 };        // Seperation offset         
    VECTOR3    sdir = { 0, 0, 1 };        // Seperation direction
    double    svel = 0;                // Separation velocity[/COLOR]

    // Get vessel status structure
    VECTOR3 rofs;
    GetStatusEx(&vs);
    Local2Rel(sofs, vs.rpos);
    GlobalRot(sdir, rofs);
    vs.rvel += rofs * svel;

    // Create descent stage as seperate vessel
    strcpy(name, GetName());
    strcat(name, "-Shell");
    oapiCreateVesselEx(name, "Tianwen_shell", &vs);
}
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,304
Reaction score
1,503
Points
203
Location
between the planets
The discarded vessel is created like 10 meters above my lander, and it seems tilted at a 90° angle. I'd expect it to spawn exactly where my vessel is, and oriented the same way.
Rotation and position of a vessel when spawning in landed state depend on the first three touchdown points!
 

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
696
Reaction score
254
Points
78
Location
This place called "home".
Are you spawning the vessel from PostStep? I've experienced the same offset in position when spawning from there. Moving it to PreStep fixed it for me.

As for the rotation, is it precisely 90°? If so, it could be you have forgotten that Orbiter uses a left-handed coordinate system, so you may have to swap y and z.
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
8,879
Reaction score
2,628
Points
203
Location
Toulouse
Are you spawning the vessel from PostStep? I've experienced the same offset in position when spawning from there. Moving it to PreStep fixed it for me.

You're the best ! That was it, now it works perfectly. The rotation issue was related. (y)

Rotation and position of a vessel when spawning in landed state depend on the first three touchdown points!

In this particular case you have "vs.flag = 0;" which means "in flight". Landed state is 1 (or the now famous "special" -10 value). ;)
 
Top