vsTASKER 7 Tutorial
|
|||||
|
|||||
Copyright VirtualSim 2004-2020 - All rights reserved |
if (local) {
local->Spatial <-(SpatialStruct);
SpatialRVStruct& data = &local->Spatial.DeadReckoningAlgorithm_A_Alternatives.SpatialRVW;
ENDIAN_SWAP_DOUBLE64(data.WorldLocation.X);
ENDIAN_SWAP_DOUBLE64(data.WorldLocation.Y);
ENDIAN_SWAP_DOUBLE64(data.WorldLocation.Z);
ENDIAN_SWAP_FLOAT32(data.Orientation.Psi);
ENDIAN_SWAP_FLOAT32(data.Orientation.Theta);
ENDIAN_SWAP_FLOAT32(data.Orientation.Phi);
ENDIAN_SWAP_FLOAT32(data.VelocityVector.XVelocity);
ENDIAN_SWAP_FLOAT32(data.VelocityVector.YVelocity);
ENDIAN_SWAP_FLOAT32(data.VelocityVector.ZVelocity);
ENDIAN_SWAP_FLOAT32(data.AngularVelocity.XAngularVelocity);
ENDIAN_SWAP_FLOAT32(data.AngularVelocity.YAngularVelocity);
ENDIAN_SWAP_FLOAT32(data.AngularVelocity.ZAngularVelocity);
}
|
if (local) {
local->EntityIdentifier <-(EntityIdentifierStruct);
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.FederateIdentifier.SiteID);
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.FederateIdentifier.ApplicationID);
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.EntityNumber);
}
|
if (local) {
local->EntityType <-(EntityTypeStruct);
ENDIAN_SWAP_SHORT16(local->EntityType.CountryCode);
}
|
SpatialRVStruct& data = &local->Spatial.DeadReckoningAlgorithm_A_Alternatives.SpatialRVW;
WCoord pos(WC_ECEF, data.WorldLocation.X, data.WorldLocation.Y, data.WorldLocation.Z);
pos.convertECEFtoXYZ();
entity->pos = pos;
pos.convertXYZtoLLA();
pos.setOrigin(pos.lat, pos.lon);
Vec3d& hpr = pos.eulerToHpr(data.Orientation.Psi, data.Orientation.Theta, data.Orientation.Phi);
entity->getDyn()->setHeading(-hpr[0]);
Vec3d& spd = pos.remoteToLocal(data.VelocityVector.XVelocity, data.VelocityVector.YVelocity, data.VelocityVector.ZVelocity);
float s = sqrt(SQR(spd[0])+SQR(spd[1])+SQR(spd[2]));
entity->getDyn()->setSpeed(s);
data.AngularVelocity.XAngularVelocity = 0;
data.AngularVelocity.YAngularVelocity = 0;
data.AngularVelocity.ZAngularVelocity = 0;
PtfDisType& type = *(PtfDisType*) entity->findComponent("PtfDisType"); // this component belongs to MilLib
if (type) {
type.kind = local->EntityType.EntityKind;
type.domain = local->EntityType.Domain;
type.country = local->EntityType.CountryCode;
type.category = local->EntityType.Category;
type.subcategory = local->EntityType.Subcategory;
type.specific = local->EntityType.Specific;
type.extra = local->EntityType.Extra;
}
else
printf("Warning: %s does not have %s DataModel!\n", entity->getName(), "PtfDisType");
PtfStatus* status = (PtfStatus*) entity->findDataModel("PtfStatus");
if (status) {
type->update(status);
status->updateSymbol(SM_2525B);
}
else printf("Warning: %s does not have %s DataModel!\n", entity->getName(), "PtfStatus");
|
if (local) {
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.FederateIdentifier.SiteID);
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.FederateIdentifier.ApplicationID);
ENDIAN_SWAP_SHORT16(local->EntityIdentifier.EntityNumber);
"EntityIdentifier" <- (EntityIdentifierStruct) &local->EntityIdentifier;
}
|
if (local) {
ENDIAN_SWAP_SHORT16(local->EntityType.CountryCode);
"EntityType" <- (EntityTypeStruct) &local->EntityType;
}
|
if (ent_idx >= getEntities().count()) { ent_idx = 0; return LEAVE; }
else {
entity = getEntity(ent_idx++);
local = entity? (hlaAircraft*)entity->findDataModel("hlaAircraft"): NULL;
// User can add his code here...
if (local) {
SpatialRVStruct& data = local->Spatial.DeadReckoningAlgorithm_A_Alternatives.SpatialRVW;
double h = entity->getDyn()->getHeading();
double p = entity->getDyn()->getElev();
double r = entity->getDyn()->getRoll();
// position
WCoord pos(WC_XYZ, entity->pos.x, entity->pos.y, entity->pos.z);
pos.convertXYZtoECEF();
data.WorldLocation.X = pos.x;
data.WorldLocation.Y = pos.y;
data.WorldLocation.Z = pos.z;
// orientation
pos.convertECEFtoLLA();
pos.setOrigin(pos.lat, pos.lon);
Vec3d& vec = pos.hprToEuler(-h,p,r);
data.Orientation.Psi = vec[0];
data.Orientation.Theta = vec[1];
data.Orientation.Phi = vec[2];
// speed
double s = entity->getDyn()->getSpeed();
Vec3d& spd = pos.localToRemote(s*sin(h)*cos(p), s*cos(h)*cos(p), s*sin(p));
data.VelocityVector.XVelocity = spd[0];
data.VelocityVector.YVelocity = spd[1];
data.VelocityVector.ZVelocity = spd[2];
// identifier
local->EntityIdentifier.FederateIdentifier.SiteID = 1;
local->EntityIdentifier.FederateIdentifier.ApplicationID = 1;
local->EntityIdentifier.EntityNumber = entity->getId();
// DIS type
PtfDisType& type = *(PtfDisType*) entity->findComponent("PtfDisType");
if (type) {
local->EntityType.EntityKind = type.kind;
local->EntityType.Domain = type.domain;
local->EntityType.CountryCode = type.country;
local->EntityType.Category = type.category;
local->EntityType.Subcategory = type.subcategory;
local->EntityType.Specific = type.specific;
local->EntityType.Extra = type.extra;
}
else printf("Warning: %s does not have %s DataModel!\n", entity->getName(), "PtfDisType");
}
return CONTINUE;
}
return PROCEED;
|
// No entity paired yet with the Handle.
if (!entity) {
// We must look for an external entity whose name is given by the ID
entity = S:findEntity(rti_data.HostObjectIdentifier.ID);
// if one is found...
if (entity) {
add(entity); // we add it to the used_by list of the FedItem, for tracability mainly
store(entity); // we associate it with the handle. Next time, we will not come here
}
}
|
if (entity) local = (hlaEmitterSystem*) entity->findComponent("hlaEmitterSystem");
if (local) {
local->EntityIdentifier = rti_data.EntityIdentifier;
local->HostObjectIdentifier = rti_data.HostObjectIdentifier;
local->EmitterIndex = rti_data.EmitterIndex;
}
|
if (local) {
local->EmitterSystemIdentifier <-(RTIObjectIdStruct);
}
else {
rti_data.EmitterSystemIdentifier <-;
}
|
if (local) {
local->EffectiveRadiatedPower <-(HLAfloat32BEdBmperfectalways);
ENDIAN_SWAP_FLOAT32(local->EffectiveRadiatedPower);
}
else {
rti_data.EffectiveRadiatedPower <-;
ENDIAN_SWAP_FLOAT32(rti_data.EffectiveRadiatedPower);
}
|
if (local) {
local->BeamAzimuthSweep <-(HLAfloat32BEradiansperfectalways);
ENDIAN_SWAP_FLOAT32(local->BeamAzimuthSweep);
}
else {
rti_data.BeamAzimuthSweep <-;
ENDIAN_SWAP_FLOAT32(rti_data.BeamAzimuthSweep);
}
|
if (local) {
local->BeamAzimuthCenter <-(HLAfloat32BEradiansperfectalways);
ENDIAN_SWAP_FLOAT32(local->BeamAzimuthCenter);
}
else {
rti_data.BeamAzimuthCenter <-;
ENDIAN_SWAP_FLOAT32(rti_data.BeamAzimuthCenter);
}
|
// ******************************************************
void Dml::init()
{
gfx_dome.id = -1;
}
// ******************************************************
void Dml::draw()
{
if (gfx_dome.id <0) { // not displayed yet
// Dome
vt_rtc->gui_map.drawDome(entity->getName(), // base
BeamAzimuthCenter-BeamAzimuthSweep,
BeamAzimuthCenter+BeamAzimuthSweep,
0, 0,
EffectiveRadiatedPower*10,
entity->db->getColor());
gfx_dome = vt_rtc->gui_map.getLastItem();
}
else {
if (gfx_dome.id >= 0) {
gfx_dome.color = entity->db->getColor();
gfx_dome.dome.min_azim = BeamAzimuthCenter-BeamAzimuthSweep;
gfx_dome.dome.max_azim = BeamAzimuthCenter+BeamAzimuthSweep;
gfx_dome.dome.min_elev = DEG2RAD(0);
gfx_dome.dome.max_elev = DEG2RAD(0);
gfx_dome.dome.radius = EffectiveRadiatedPower*10;
vt_rtc->gui_map.updateGraphic(gfx_dome);
}
}
}
// ******************************************************
void Dml::clean()
{
if (gfx_dome.id > -1) {
vt_rtc->gui_map.removeGraphic(gfx_dome.id);
gfx_dome.id = -1;
}
}
|
rti_data.FiringLocation <-(WorldLocationStruct);
ENDIAN_SWAP_DOUBLE64(rti_data.FiringLocation.X);
ENDIAN_SWAP_DOUBLE64(rti_data.FiringLocation.Y);
ENDIAN_SWAP_DOUBLE64(rti_data.FiringLocation.Z);
WCoord pos(WC_ECEF, rti_data.FiringLocation.X, rti_data.FiringLocation.Y, rti_data.FiringLocation.Z);
pos.convertECEFtoXYZ();
R:gui_map.drawCircle(pos, 100, clBlue, 3);
|
Vt_Entity* from = S:findEntity(rti_data.FiringObjectIdentifier.ID);
Vt_Entity* to = S:findEntity(rti_data.TargetObjectIdentifier.ID);
if (from && to) R:gui_map.drawLine(from->pos, to->pos, clRed, 2);
|
rti_data.DetonationLocation <-(WorldLocationStruct);
ENDIAN_SWAP_DOUBLE64(rti_data.DetonationLocation.X);
ENDIAN_SWAP_DOUBLE64(rti_data.DetonationLocation.Y);
ENDIAN_SWAP_DOUBLE64(rti_data.DetonationLocation.Z);
WCoord pos(WC_ECEF, rti_data.DetonationLocation.X, rti_data.DetonationLocation.Y, rti_data.DetonationLocation.Z);
pos.convertECEFtoXYZ();
R:gui_map.drawCircle(pos, 100, clRed, 3);
|
Entity* target = (Entity*) S:findEntity(rti_data.TargetObjectIdentifier.ID);
if (target) {
target->status->setDamage(_Damaged);
target->dyn->startCrash();
}
|
![]() |
This demo is available in HLA/Mak/1516/vrlink20017-F18-1516 and Hla/Mak/1516/vrlink-F18-1516.
See the Scenario description to know how to launch the VR-Link demo part.
If you do not have VR-Link, you can still use the /HLA/Mak/1516/multisensors_master1516 and slave with two vsTASKER running (available also on Pitch/1516)
Rely on the Scenario explanations to see how to manipulate the demos.
|