SimObject Api, GetProperty and Sim Variables?

For topics related to the creation of simulation objects (SimObjects). This includes development of aircraft, ground, and maritime vehicles.
Locked
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

SimObject Api, GetProperty and Sim Variables?

Post 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
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: SimObject Api, GetProperty and Sim Variables?

Post 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?
Clifton Crane
Prepar3D® Software Engineer Sr.
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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..!!
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: SimObject Api, GetProperty and Sim Variables?

Post 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.
Clifton Crane
Prepar3D® Software Engineer Sr.
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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..!!
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: SimObject Api, GetProperty and Sim Variables?

Post 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.
Clifton Crane
Prepar3D® Software Engineer Sr.
User avatar
WarpD
Posts: 1469
Joined: Mon Feb 14, 2011 5:29 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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. :)
Ed Wilson
Senior Developer
Mindstar Aviation
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post 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 :-)
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: SimObject Api, GetProperty and Sim Variables?

Post 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.
Clifton Crane
Prepar3D® Software Engineer Sr.
zamirk
Posts: 132
Joined: Mon Jul 21, 2014 8:39 am

Re: SimObject Api, GetProperty and Sim Variables?

Post by zamirk »

Thanks Clifton for you guidance.
Locked