//--------------------------------------------------------------------------- const Rvector6 Barycenter::GetMJ2000State(const A1Mjd &atTime) { // if it's built-in, get the state from the SpacePoint if (isBuiltIn) { lastStateTime = atTime; lastState = builtInSP->GetMJ2000State(atTime); #ifdef DEBUG_BARYCENTER_STATE MessageInterface::ShowMessage("Computing state for Barycenter %s, whose builtInSP is %s\n", instanceName.c_str(), (builtInSP->GetName()).c_str()); #endif return lastState; } // otherwise, sum the masses and states CheckBodies(); #ifdef DEBUG_BARYCENTER MessageInterface::ShowMessage("Entering BaryCenter::GetMJ2000EqState at time %12.10f\n", atTime.Get()); #endif Real bodyMass = 0.0; Rvector3 bodyPos(0.0,0.0,0.0); Rvector3 bodyVel(0.0,0.0,0.0); Real weight = 0.0; Rvector3 sumMassPos(0.0,0.0,0.0); Rvector3 sumMassVel(0.0,0.0,0.0); Rvector6 bodyState; Real sumMass = GetMass(); for (unsigned int i = 0; i < bodyList.size() ; i++) { bodyMass = ((CelestialBody*) (bodyList.at(i)))->GetMass(); bodyState = (bodyList.at(i))->GetMJ2000State(atTime); bodyPos = bodyState.GetR(); bodyVel = bodyState.GetV(); weight = bodyMass/sumMass; #ifdef DEBUG_BARYCENTER MessageInterface::ShowMessage("Mass (and weight) of body %s = %12.10f (%12.10f)\n", ((bodyList.at(i))->GetName()).c_str(), bodyMass, weight); MessageInterface::ShowMessage(" pos = %s\n", (bodyPos.ToString()).c_str()); MessageInterface::ShowMessage(" vel = %s\n", (bodyVel.ToString()).c_str()); #endif sumMassPos += (weight * bodyPos); sumMassVel += (weight * bodyVel); } #ifdef DEBUG_BARYCENTER MessageInterface::ShowMessage("sumMassPos = %s\n", (sumMassPos.ToString()).c_str()); #endif lastState.Set(sumMassPos(0), sumMassPos(1), sumMassPos(2), sumMassVel(0), sumMassVel(1), sumMassVel(2)); lastStateTime = atTime; return lastState; }
// ============================================================================ // Constructor AntiAirBattery::AntiAirBattery ( World* pWorld, double location, double angle ) : Machine ( pWorld ) { setLayers( PhysLayerBuildings ); setRenderLayer( LayerBuildings ); setName("Flak"); double locationY = world()->ground()->height( location ); b2Vec2 basePos( location, locationY ); b2Vec2 bodyPos( location, locationY + 1.5 ); // create damage manager _dmMain = new DamageManager(); addDamageManager( _dmMain ); _bodyMain = BodyProvider::loadBody( "installations/flak1-body.body" ); _bodyMain->setPosition( bodyPos ); _bodyMain->create( pWorld ); addBody( _bodyMain, BodyRendered1 ); _bodyBase = BodyProvider::loadBody( "installations/flak1-base.body" ); _bodyBase->setPosition( basePos ); _bodyBase->create( pWorld ); addBody( _bodyBase, BodyRendered1 ); setMainBody( _bodyBase ); _bodyMain->setDamageManager( _dmMain ); // create gun _sysGun = Gun::berezin( this, "Gun" ); _sysGun->setBody( _bodyMain ); _sysGun->setMuzzle( QPointF( 0.0, 0.0 ) ); _sysGun->setMuzzleShift( 4.0 ); _sysGun->setNormal( QPointF( cos( angle), sin(angle) ) ); addSystem( _sysGun, SystemSimulated ); // create operator _sysOperator = new AntiAirGunOperator( this, "operator" ); _sysOperator->setGun( _sysGun ); _sysOperator->setMinAngle( 0.5 ); _sysOperator->setMaxAngle( M_PI/2 ); _sysOperator->setDamageCapacity( 100E3 ); addSystem( _sysOperator, SystemSimulated ); _lastDisplayedAngle = 0.5; // min angle from zenith; // add systems to damage manager _dmMain->addSystem( _sysGun, 1 ); _dmMain->addSystem( _sysOperator, 1 ); _dmMain->addSystem( NULL, 2 ); }
void CPlayer::InitPosition() { m_vHeadPosRecord = CVector3(0, GetHeadRadius(), 0); m_pHead->SetPosition(m_vHeadPosRecord); float dis = m_pHead->GetRadius() * 1.5f; int i = 0; for (auto it = m_listBody.begin(); it != m_listBody.end(); ++it) { CVector3 bodyPos(0, GetBodyRadius(), (++i) * dis); (*it)->SetPosition(bodyPos); } m_pTail->SetPosition(CVector3(0, GetBodyRadius(), (++i) * dis)); }