我正在免费使用 Pitch pRTI 和“世界地图”模拟器。我尝试查看“The HLA Tutorial.pdf”的第 50 页来设置和更新联邦实例,但我失败了,我不知道为什么。事先,我的代码中的对象在世界地图中被实例化和渲染,但它只是不更新它的位置。我粘贴了与属性、对象句柄、属性句柄和 RTIambassador 相关的代码部分。您可能会注意到有一些结构,它们基于 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);