Java 如何正确更新联邦成员的实例?

Java 如何正确更新联邦成员的实例?,java,high-level-architecture,dis,Java,High Level Architecture,Dis,我使用的是无音高pRTI和“世界地图”模拟器。 我试图通过查看“HLA Tutorial.pdf”的第50页来设置和更新联邦成员实例,但我失败了,我不知道为什么。 事先,我的代码中的对象在世界地图中被实例化和渲染,但它只是不更新它的位置。 我粘贴了与属性、对象句柄、属性句柄和属性相关的代码部分。 您可能会注意到有一些结构,它们基于RPR Fom,其中一些可能不是最好的实现。 更新属性的尝试在最后15行中 谢谢大家! private RTIambassador _rtiAmbassador;

我使用的是无音高pRTI和“世界地图”模拟器。 我试图通过查看“HLA Tutorial.pdf”的第50页来设置和更新联邦成员实例,但我失败了,我不知道为什么。 事先,我的代码中的对象在世界地图中被实例化和渲染,但它只是不更新它的位置。 我粘贴了与属性、对象句柄、属性句柄和属性相关的代码部分。 您可能会注意到有一些结构,它们基于RPR Fom,其中一些可能不是最好的实现。 更新属性的尝试在最后15行中

谢谢大家!

   private RTIambassador _rtiAmbassador;
   private final String[] _args;
   private InteractionClassHandle interactionHandle;   
   private ObjectInstanceHandle _userId;

   private AttributeHandle _attributeEntityType;
   private AttributeHandle _attributeSpatial;   
   private AttributeHandle _attributeEntityId; 
   private AttributeHandle _attributeDamageState; 
   private AttributeHandle _attributeForceId; 
   private AttributeHandle _attributeIsConcealed; 
   private AttributeHandle _attributeMarking; 
.
.
.
   private EncoderFactory _encoderFactory;
.
.
.
         ObjectClassHandle participantId = _rtiAmbassador.getObjectClassHandle("BaseEntity.PhysicalEntity.Platform.Aircraft");          

         //Atributos da entidade criada. Esses campos foram retirados do FOM base, nesse caso o netn2_2010.xml
         _attributeEntityType = _rtiAmbassador.getAttributeHandle(participantId, "EntityType");        
         _attributeEntityId = _rtiAmbassador.getAttributeHandle(participantId, "EntityIdentifier");  
         _attributeSpatial = _rtiAmbassador.getAttributeHandle(participantId, "Spatial");  
         _attributeDamageState = _rtiAmbassador.getAttributeHandle(participantId, "DamageState");   
         _attributeForceId = _rtiAmbassador.getAttributeHandle(participantId, "ForceIdentifier");  
         _attributeIsConcealed = _rtiAmbassador.getAttributeHandle(participantId, "IsConcealed");   
         _attributeMarking = _rtiAmbassador.getAttributeHandle(participantId, "Marking");  
.
.
.
         AttributeHandleSet attributeSet = _rtiAmbassador.getAttributeHandleSetFactory().create();
         attributeSet.add(_attributeEntityType);
         attributeSet.add(_attributeSpatial);
         attributeSet.add(_attributeEntityId);
         attributeSet.add(_attributeForceId);
         attributeSet.add(_attributeIsConcealed);
         attributeSet.add(_attributeMarking);
.
.
.

         //Spatial

         WorldLocationStruct worldLocation = new WorldLocationStruct( 7.291122019556398e-304, 4114673.3659611, -4190319.2556862);
         VelocityVectorStruct velocityVectorStruct = new VelocityVectorStruct(0.5415523,-0.5452158,-1.1100446);
         OrientationStruct orientationStruct = new OrientationStruct(-12.183228,-7.050103e+07,0.0);
         SpatialFPStruct spatialFPStruct = new SpatialFPStruct(worldLocation,velocityVectorStruct,orientationStruct);
         SpatialFPStructEncoder spatialFPStructEncoder = new SpatialFPStructEncoder(spatialFPStruct);     

         /////////////////// Entity Type

             EntityTypeStruct entityTypeStruct = new EntityTypeStruct(1,2,29,20,13,3,0);
             EntityTypeStructEncoder entityTypeStructEncoder = new EntityTypeStructEncoder(entityTypeStruct);

         ///////////// Force Identifier         
             ForceIdentifierEnum forceIdEnum = ForceIdentifierEnum.NEUTRAL;
             ForceIdentifierEnumEncoder forceIdEnumEncoder = new ForceIdentifierEnumEncoder(forceIdEnum);
         /////////////// Entity Identifier         

             EntityIdentifierStruct entityIdentifierStruct = new EntityIdentifierStruct(3001,101,102);
             EntityIdentifierStructEncoder entityIdentifierStructEncoder = new EntityIdentifierStructEncoder(entityIdentifierStruct);


         // IsConcealed
         HLAoctet isConcealed = _encoderFactory.createHLAoctet();           
         isConcealed.setValue((byte) 0);

         //Marking ----

         MarkingStruct markingStruct = new MarkingStruct(1,"TesteXplane");
         MarkingStructEncoder markingStructEncoder = new MarkingStructEncoder(markingStruct);

         AttributeHandleValueMap attributes = _rtiAmbassador.getAttributeHandleValueMapFactory().create(7);

         attributes.put(_attributeEntityType , entityTypeStructEncoder.toByteArray());
         attributes.put(_attributeSpatial , spatialFPStructEncoder.toByteArray());       
         attributes.put(_attributeForceId, forceIdEnumEncoder.toByteArray());
         attributes.put(_attributeEntityId , entityIdentifierStructEncoder.toByteArray());
         attributes.put(_attributeIsConcealed, isConcealed.toByteArray());  
         attributes.put(_attributeMarking, markingStructEncoder.toByteArray());          

.
.
.
         _rtiAmbassador.subscribeObjectClassAttributes(participantId, attributeSet);
         _rtiAmbassador.publishObjectClassAttributes(participantId, attributeSet);  
.
.
.
                 forceIdEnum = ForceIdentifierEnum.OPPOSING;
                 forceIdEnumEncoder = new ForceIdentifierEnumEncoder(forceIdEnum);
                 attributes.put(_attributeForceId, forceIdEnumEncoder.toByteArray());

                  worldLocation = new WorldLocationStruct(542543245345.9, 4114673.3659611, -4190319.2556862);
                  velocityVectorStruct = new VelocityVectorStruct(0.5415523, -0.5452158, -1.1100446);
                  orientationStruct = new OrientationStruct(-12.183228,-7.050103e+07,0.0);
                  spatialFPStruct = new SpatialFPStruct(worldLocation,velocityVectorStruct,orientationStruct);
                  spatialFPStructEncoder = new SpatialFPStructEncoder(spatialFPStruct);        

                 attributes.put(_attributeSpatial, spatialFPStructEncoder.toByteArray());
                 System.out.println("Updating position");

             _rtiAmbassador.updateAttributeValues( _userId, attributes, null);

在提供的代码中,有几件事情可能会出错:1_调用registerObjectInstance 2时应设置用户ID。编码器可能对数据进行错误编码3。代码是否引发任何异常?刚刚注意到在此行worldLocation=new WorldLocationStruct(54254325345.9,4114673.3659611,-4190319.2556862)中出现异常“反序列化对象上的属性'spatial'时出错:反序列化错误:在0可用时尝试读取4个字节”;第一个参数与预期参数不兼容,因此我只是复制并粘贴了此参数中的previus值“7.291122019556398e-304”。现在我对这个参数中的错误有了新的怀疑。我会把它放到一个新的帖子里。再次感谢您的帮助!在提供的代码中,有几件事情可能会出错:1_调用registerObjectInstance 2时应设置用户ID。编码器可能对数据进行错误编码3。代码是否引发任何异常?刚刚注意到在此行worldLocation=new WorldLocationStruct(54254325345.9,4114673.3659611,-4190319.2556862)中出现异常“反序列化对象上的属性'spatial'时出错:反序列化错误:在0可用时尝试读取4个字节”;第一个参数与预期参数不兼容,因此我只是复制并粘贴了此参数中的previus值“7.291122019556398e-304”。现在我对这个参数中的错误有了新的怀疑。我会把它放到一个新的帖子里。再次感谢您的帮助!