API Question DefSetState() requires any specific callbacks or flags ?

dumbo2007

Crazy about real time sims
Joined
Nov 29, 2009
Messages
675
Reaction score
0
Points
0
Location
India
More issues.....it seems some special callback needs to be implemented by a derived class of VESSEL3 or some flag needs to be set for the following to work on the vessel.

Code:
[B]VESSELSTATUS2 mystat;
memset(&mystat,0,sizeof(VESSELSTATUS2));
mystat.version = 2;
VESSEL* v = oapiGetVesselInterface(oapiGetObjectByName("Ferrari"));
v->GetStatusEx(&mystat);[/B]
 
VECTOR3 loc = _V(pkt.shapes.m[12] + 400, 0.2, pkt.shapes.m[14] + 500);//_V(400,10,500);
    VECTOR3 moonpos, correct_ecliptic_orientation;
    oapiLocalToGlobal(oapiGetBaseByName(oapiGetObjectByName("Moon"),"Brighton Beach"),&loc , &correct_ecliptic_orientation);
    

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

    v->DefSetStateEx(&mystat);

For this to work on vessel v some callback or flag has to be set which I dont seem to be able to figure out. I tried setting different types of Vessel in the scenario file :

Code:
...
BEGIN_SHIPS
Brighton2:BulletBase
  STATUS Landed Moon
  BASE Brighton Beach:4
  HEADING 70.00
  FUEL 1.000
  GEAR 1 1.0
  NOSECONE 0 0.0000
END
[B]Ferrari:DeltaGlider[/B]
STATUS Landed Moon
  BASE Brighton Beach:3
  HEADING 70.00
  FUEL 1.000
  GEAR 1 1.0
  NOSECONE 0 0.0000
END
.....

So Ferrari:DeltaGlider works and I see Ferrari positioned at every step correctly. But Ferrari:ShuttlePB or Ferrari:BulletBaseVehicle (my class) does not. I am guessing the ShuttlePB class is too basic and for the same reason DefSetState() does not work if called on the same BulletBaseVehicle (my VESSEL3 derived class) itself.

The delta glider code is too huge....and eliminating members one by one will take me too long to find the required mechanism I am missing.
 
Last edited:
Did you try to set mystat.flag to zero?

EDIT: scratch that... I missed your memset...

EDIT: The DefSetStateEx should be OK. I do the same in OMP and it works for about everything. No flag needed that I know of.
 
Last edited:
Did you ever have this issue with your own vessel classes, Face ? I assume you use DefSetState() to put the vessels of other players in their correct position in OMP.
 
Is "v->DefSetStateEx(&mystat);" line causing an exception in Orbiter when you test your code in debugger, or what?
 
Did you ever have this issue with your own vessel classes, Face ? I assume you use DefSetState() to put the vessels of other players in their correct position in OMP.

No, it always worked with my own classes, too. E.g. the OMPDefault vessel is at simple as it gets. I also had ShuttlePB working flawlessly with DefSetStateEx().

Maybe you can nail the bug by means of using a fixed position first. Set the rpos to a fixed vector far away from the surface and try with your vessels.
Also watch out for what I call "sticky landing"... if you re-position a vessel with state "landed", you will not get the propagator working on it. You'll have to apply a little thrust to get it out of the landed state first.
Maybe this is the difference between your vessel instances? One at full stop - thus having state "landed" -, one still moving?

regards,
Face
 
No it does not cause any exception. The mesh simply stays in its position. I did some experiments with the following in the scenario file now :
Code:
Ferrari:ShuttlePB
STATUS Landed Moon
  BASE Brighton Beach:3
  HEADING 70.00
  FUEL 1.000
  GEAR 1 1.0
  NOSECONE 0 0.0000
END

The minute I fired the thrusters of the ShuttlePB it zipped into the position set by DefSetStateEx(). So it seems that unless some forces are applied on the vessel it wont start accepting state info. Maybe its marked as idle in the Orbiter physics engine and that is why its new state is not updated.

Since my vehicle class does not supply any thrusters, I ll have to see how to set the initial state correctly. But its strange that this happens only with the ShuttlePB. The Delta Glider is in position right from the first frame with out any thrusters being fired, so somehow it is not marked as idle.

EDIT : just saw your post Face, I think its a "landed" issue. Will see if I can mark the vessel as moving.

EDIT : There does not seem to be any easy function to set it's state to moving...seems like I ll have to add some thrusters,apply the thrust and shut off the thrusters in the very next time step....thats just a bit annoying
 
Last edited:
The vessel is inactive when landed. Change the mystat.status to 0.
 
The minute I fired the thrusters of the ShuttlePB it zipped into the position set by DefSetStateEx(). So it seems that unless some forces are applied on the vessel it wont start accepting state info. Maybe its marked as idle in the Orbiter physics engine and that is why its new state is not updated.

Since my vehicle class does not supply any thrusters, I ll have to see how to set the initial state correctly. But its strange that this happens only with the ShuttlePB. The Delta Glider is in position right from the first frame with out any thrusters being fired, so somehow it is not marked as idle.

EDIT : just saw your post Face, I think its a "landed" issue. Will see if I can mark the vessel as moving.

Yeah, that pretty much sound like it. What I'm doing in OMP is defining a thruster to fake that little thrust. Just applying AddForce() seems to make no difference unfortunately...
 
Well I tried setting mystat.status to 0 and the vessel was placed near the Sun. I think it suddenly began taking positions wrt the Sun instead of Brighton Beach.

However the little thrust did do the trick. Given the "bumpy" nature of DefSetStateEx() when used in every frame, I am going to shift to using attachment points for maintaining the vessel's position with respect to another vessel. The use of DefSetStateEx() for fixing the vessel position has to be looked into more carefully later.

I can directly shift the attachment point to correspond to the co-ordinates given to me by Bullet and there is no jerking of the vessel position after the position is set. Moreover I can still use VESSEL::SetRotationMatrix to rotate the vessels mesh when needed.

Does anyone know if VESSEL::SetRotationMatrix can be directly passed an OpenGL transform matrix . Bullet gives me the world transform of the chassis of the vehicle I am trying to model as a 4 by 4 opengl matrix. It can be directly multiplied to the current matrix in opengl using glMultMatrix() to set the position and orientation of a rigid body. But I am not sure if I can use it directly in Orbiter as well (the 1st 3 by 3 elements of the OpenGL matrix passed directly to SetRotationMatrix() I mean). It would simplify things hugely if it was possible, even if after a transpose.
 
Last edited:
Well I tried setting mystat.status to 0 and the vessel was placed near the Sun. I think it suddenly began taking positions wrt the Sun instead of Brighton Beach.

Was mystat.rbody set to the body to which the position (rpos) is relative? Try to set rbody to the handle of Moon. When a vessel is landed/inactive it uses base and surf_lng, surf_lat of VESSELSTATUS2 instead.
 
Well I tried that. The Vessel is now close to the base. But its about 50 metres above the base and not in the correct position.
 
I don't know what you try to accomplish. Does this vessel need to be landed, or in flight? The Y component of 0.2 you are adding suggests it should be landed, so why are you in need for using rpos instead of surf_lng and surf_lat?
 
Well I want the vessel to be landed. The vessel represents a vehicle thats on the ground. The vehicle position is known to me. Its movement is simulated through code so each time step, its position may change. In every time step I have the position of the vehicle with respect to the origin(which in this case is the location of Brighton Beach).

Since the vehicle can move around the base, I use DefSetStateEx to set the vessel position depending on the vehicle position. I was using rpos so far as I thought that was the only way to set the vessel position reliably. I convert the co-ordinates of the vehicle with respect to Brighton Beach , to the global position with respect to the moon and pass it to DefSetStateEx() .....which is why you see the api transformation function calls.

The vessel which represents the vehicle has its position set by another vessel which represents a base(this base vessel is fixed in position). My first try with calling v->DefSetStateEx() from the vessel representing the base, did not have any effect.

All I need is to be able to smoothy change the position of vessel on the ground. They never leave the ground. I see now that surf_lng and surf_lat can also be used, so I ll try that as well.
 
Back
Top