Page 1 of 1

SimObject Api, GetProperty and Sim Variables?

Posted: Mon Dec 05, 2016 7:40 am
by zamirk
hi,
i am using SimObject Api to create Custom Missile Object in P3D, i want to get Parent Aircraft Properties like "Total Velocity" and other simulation variables, so i found this sample code :

Code: Select all

   CComPtr<IBaseObject> spOwner;
   CComPtr<IBaseObject> spOwnerV01;
   if( SUCCEEDED( GETSimOBjectManager()->GetObject(m_uOwnerId, &spOwner) )
      && spOwner->QueryInterface(IID_IBaseObjectV01, (void**)&spOwnerV01)
   ){
      spOwnerV01->GetProperty("TotalVelocity", "knots", dParentVel, 0);
   }

first thing is that this if condition remain always false so i do not able to get Total Velocity of parent object, How this can be solve?
and the 2nd problem is that i want to get other simulation variables of parent object how this can be possible?

Thanks

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Tue Dec 06, 2016 4:40 am
by zamirk
hi everyone,
i found the solution for above if condition that was missing SUCCEEDED() function in this P3D sample code for Missile SimObject

error code

Code: Select all

   CComPtr<IBaseObject> spOwner;
   CComPtr<IBaseObject> spOwnerV01;
   if( SUCCEEDED( GETSimOBjectManager()->GetObject(m_uOwnerId, &spOwner) )
      && [color=#FF4000]spOwner->QueryInterface(IID_IBaseObjectV01, (void**)&spOwnerV01[/color])
   ){
      spOwnerV01->GetProperty("TotalVelocity", "knots", dParentVel, 0);
   }
 


solved code

Code: Select all

   CComPtr<IBaseObject> spOwner;
   CComPtr<IBaseObject> spOwnerV01;
   if( SUCCEEDED( GETSimOBjectManager()->GetObject(m_uOwnerId, &spOwner) )
      && [color=#00BF00]SUCCEEDED(spOwner->QueryInterface(IID_IBaseObjectV01, (void**)&spOwnerV01)[/color] )
   ){
      [color=#00BF40]//Method 1[/color]
      spOwnerV01->GetProperty("TotalVelocity", "knots", dParentVel, 0);
     
       [color=#00BF40]//Method 2[/color]
       [color=#FF4000]
       int iPropertyCode;
       int iIndex = -1;
       int iUnitCode;
       if(SUCCEEDED( spOwnerV01->GetPropertyCodeAndIndex(PROPRTY_TYPE_DOUBLE, "TotalVelocity", iPropertyCode, iIndex) ) && UCCEEDED( GetSimObjectManager()->GetUnitCode("knots", iUnitCode) ) )
       {
              spOwnerV01->GetProperty(iPropertyCode, iUnitCode, dParentVel, iIndex);
       }[/color]
   }
 



And also there is a problem with method 2 for getting TotalVelocity of Parent Object i do not understand why this is not working? But method 1 is working properly.

So now i want to get other simulation variables of Parent Object like :

Simulation Variable Units Settable * Multiplayer
FCS TARGETED OBJECT ID Number Y -
NUMBER OF ENGINES Number N -
GROUND VELOCITY Knots N -
ATC ID String (10) Y -
PLANE HEADING DEGREES TRUE Radians Y -
SIM ON GROUND Bool Y -

how this can be possible with GetProperty() function or any other way to get these variables?

Any one from LM..!!

Thanks

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Tue Dec 06, 2016 11:43 pm
by Clifton Crane
Hello,

Thanks for pointing the documentation error. The "TotalVelocity" property is a property associated with the SimpleAirplane ISimObject sample. Is this the parent object you are referring to?

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Wed Dec 07, 2016 4:17 am
by zamirk
hi,
Thanks for guiding me i am using another SimObject as parent not SimpleAirplane ISimObject sample, can i get
these Sim Variables without implementing SimConnect in Missile ISimObject Sample?

Simulation Variable
FCS TARGETED OBJECT ID Number
NUMBER OF ENGINES Number
GROUND VELOCITY Knots
ATC ID String (10)
PLANE HEADING DEGREES TRUE Radians
SIM ON GROUND Bool

Thanks..!!

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Wed Dec 07, 2016 3:02 pm
by Clifton Crane
Hello,

Yes, if the object you are querying properties on is a native SimObject (i.e. Airplane or Rotorcraft), you should have access to Simulation Variables. If you still have issues querying properties, you might try changing the value of the iIndex from -1 to 0.

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Fri Dec 09, 2016 5:08 am
by zamirk
hi Clifton,

Thanks, my problem has been resolved.
One thing more when i attach the Custom Missile ISimObject with my aircraft its show some default effects but in code there is no function call of VisulaEffectOn(), so kindly help me how i can Off this default Visual Effect on attachment?

Thanks..!!

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Fri Dec 09, 2016 2:33 pm
by Clifton Crane
Zamirk,

Are the effects visible all of the time (i.e. even when attached)? The effects of the sample Missile model are attached to the model itself, so there is no code controlling them in the sample. I believe the effects are also driven by native Simulation Variables which are not available to the ISimObject Missile. You would have to create a new model and use the VisualEffectOn and VisualEffectOff functions in your Missile sim.

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Sat Dec 10, 2016 11:33 am
by WarpD
zamirk wrote:Thanks, my problem has been resolved.


For others who may have the same issue(s), please state how your problem has been resolved. It's one of the purposes of the forum, after all. Sharing. :)

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Thu Dec 15, 2016 3:51 am
by zamirk
Clifton,

no there is no default effect on missile model because when i attach the missile model with my aircraft without using Missile.dll (of Missile Sample Code) then there is no default effect shows, but when i load Missile.dll for attached missile model then its shows some effect like Fired Weapon?
so i want to Off this effect in Missile Sample Code because i think this effect On by Missile Sample Code..!!
Or there is any way to OFF all effects?

Thanks

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Thu Dec 15, 2016 3:57 am
by zamirk
hi WarpD,

my problem was to get Simulation Variables in Missile Sample Code using GetProperty() function, when i was get any variable and print value of this variable in simple text file its shows garbage value so then i post this question here.

issue was in writing format in text file i was writing like :
frpintf(txtfile, "var : %f", variable);

when i change %f to %0.2f its show correct value so i get correct value of simulation variable :-)

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Thu Dec 15, 2016 2:24 pm
by Clifton Crane
zamirk,

That won't be possible from within Missile.dll since the effects are part of the model. You would have to create a new model an control the effects yourself.

The reason the effects work correctly when using the native Weapon SimObject type and not the Missile.dll ISimObject is due to the animations and effects being driven by native simulation variables.

Re: SimObject Api, GetProperty and Sim Variables?

Posted: Thu Dec 22, 2016 8:51 am
by zamirk
Thanks Clifton for you guidance.