API Question Conversion of co-ordinates wrt base to vessel co-ordinates

dumbo2007

Crazy about real time sims
Joined
Nov 29, 2009
Messages
675
Reaction score
0
Points
0
Location
India
Hi,

I want to convert and set the co-ordinates of another vessel from inside the vessel class of a vessel. I am using the following method.

Code:
VESSELSTATUS2 mystat;
    memset(&mystat,0,sizeof(VESSELSTATUS2));
    mystat.version = 2;
    VESSEL* v = oapiGetVesselInterface(oapiGetObjectByName("GL-NT"));
    v->GetStatusEx(&mystat);


VECTOR3 loc = _V(10,0,0), glob;
    oapiLocalToGlobal(oapiGetBaseByName(oapiGetObjectByName("Moon"),"Brighton Beach"),&loc , &mystat.rpos);
    //oapiGetRotationMatrix(mystat.rbody, &mat); 
    //mystat.rpos = mul(mat, position_wrt_moon_frame);

    v->DefSetStateEx(&mystat);
I have the co-ordinates wrt the base Brighton Beach as _V(10,0,0). I want to convert these co-ordinates to global co-ordinates such that I can set them through v->DefSetStateEx(). But the above method places the vessel no where near brighton but somewhere in deep space. Any one knows what I could be doing wrong ?

Thanks
 
DefSetStateEx uses coordinates relative to the reference body, not global coordinates.
 
ok....so I guess the co-ordinates should be wrt the moon in this case. I think a reference to the Moon will be present in mystat.rbody as well. So how do I go about the conversion in this case: There does not seem to be any function present to get the co-ordinates wrt a particular body.

Another question - I tried to set the state of a vessel inside its own class using the technique above, but it does not seem to affect the vessel. Can GetStatusEx(&mystat); & DefSetStateEx() be used to set the state of the same vessel its being called inside ?
 
Please remember that the specification of a coordinate frame requires two components: its orientation and its location of origin.

DefSetStateEx requires a frame that is centered at the origin of the reference body, and has the orientation of the ecliptic frame. Your oapiLocalToGlobal call already gives you the correct (ecliptic) orientation. Now you only need to shift the origin from the global (0,0,0) coordinates to the centre of the moon. You can of course do that simply by subtracting the moon's position, given by oapiGetGlobalPos.

A slight problem may arise from the fact that your basis-relative coordinates of (10,0,0) are placing the centre of gravity of the vessel right on the surface, that is, half burying it under ground. In this case, the moon's surface is modelled as infinitely elastic, and might therefore catapult your vessel into space at infinite acceleration (for an infinitesimal duration, i.e. one frame).
 
Until the conversion system is created I do a more simple method for converting base to global in my Texas airport-hopping campaign:

Position the first airport, go in orbiter, fly to second airport and record position off the Map MFD or scenario file. Proceed to add all Texas airports :D
 
ok this works :

Code:
VESSELSTATUS2 mystat;
memset(&mystat,0,sizeof(VESSELSTATUS2));
mystat.version = 2;
VESSEL* v = oapiGetVesselInterface(oapiGetObjectByName("GL-NT"));
v->GetStatusEx(&mystat);

VECTOR3 loc = _V(400,10,500), moonpos;

oapiLocalToGlobal(oapiGetBaseByName(oapiGetObjectByName("Moon"),"Brighton Beach"),&loc , &correct_ecliptic_orientation);

oapiGetGlobalPos(oapiGetObjectByName("Moon"), &moonpos);
mystat.rpos = correct_ecliptic_orientation - moonpos;

v->DefSetStateEx(&mystat);

I have raised the vessel a bit along the y axis in base frame.
But the orientation of the vessel is not fixed. It keeps on changing and if a wing tip dips low enough to hit the ground then the vessel swings about violently(but stays in its position). Is there a way to fix the orientation of the vessel in every step ?


To addon to the questions, this method does not seem to effect the position of the vessel from inside whose class I am evoking these functions. This has no effect on the current vessel for eg. :

Code:
VESSELSTATUS2 mystat;
memset(&mystat,0,sizeof(VESSELSTATUS2));
mystat.version = 2;
	
GetStatusEx(&mystat);

VECTOR3 loc = _V(400,10,500), moonpos;
oapiLocalToGlobal(oapiGetBaseByName(oapiGetObjectByName("Moon"),"Brighton Beach"),&loc , &correct_ecliptic_orientation);
	

oapiGetGlobalPos(oapiGetObjectByName("Moon"), &moonpos);
mystat.rpos = correct_ecliptic_orientation - moonpos;

	
DefSetStateEx(&mystat);


I would like a vessel to be able to set its own position on the ground within its own class upon pressing arrow keys(for modeling surface vehicles)

Another issue :

If i raise the vessel along the y axis by 2.57m exactly then there is no swinging or violent rotations. The vessel stays oriented along its axis correctly and at its position. But there is this a very slight and noticeable motion along the y axis of the vessel(i.e. vertically up and down as if it was on some suspension). I ll try and post a video later. I would rather have no motion at all as I am planning to set the positions and orientations of vehicles on the ground(calculated through the Bullet Physics engine) in every time step, using this method. So any vertical motion will be immediately noticeable.
 
Last edited:
If i raise the vessel along the y axis by 2.57m exactly then there is no swinging or violent rotations.
Most likely because your touchdown points are no longer below the surface. See Martin's comments above about the elasticity of the surface.

The vessel stays oriented along its axis correctly and at its position. But there is this a very slight and noticeable motion along the y axis of the vessel(i.e. vertically up and down as if it was on some suspension).
It sounds like the same issue we were discussing here: http://www.orbiter-forum.com/showthread.php?p=237171#post237171. Still unresolved as far as I'm concerned and I haven't had time to see if I can reproduce it myself.
 
Back
Top