const Vector& NineFourNodeQuadUP::getResistingForceIncInertia() { int i, j, ik; static double a[22]; for (i=0; i<nenu; i++) { const Vector &accel = theNodes[i]->getTrialAccel(); if ((i<nenp && 3 != accel.Size()) || (i>=nenp && 2 != accel.Size())) { opserr << "NineFourNodeQuadUP::getResistingForceIncInertia matrix and vector sizes are incompatable\n"; return P; } if (i<nenp) ik = i*3; if (i>=nenp) ik = nenp*3 + (i-nenp)*2; a[ik] = accel(0); a[ik+1] = accel(1); if (i<nenp) a[ik+2] = accel(2); } // Compute the current resisting force this->getResistingForce(); // opserr<<"K "<<P<<endln; // Compute the mass matrix this->getMass(); for (i = 0; i < 22; i++) { for (j = 0; j < 22; j++) P(i) += K(i,j)*a[j]; } // opserr<<"K+M "<<P<<endln; for (i=0; i<nenu; i++) { const Vector &vel = theNodes[i]->getTrialVel(); if ((i<nenp && 3 != vel.Size()) || (i>=nenp && 2 != vel.Size())) { opserr << "NineFourNodeQuadUP::getResistingForceIncInertia matrix and vector sizes are incompatable\n"; return P; } if (i<nenp) ik = i*3; if (i>=nenp) ik = nenp*3 + (i-nenp)*2; a[ik] = vel(0); a[ik+1] = vel(1); if (i<nenp) a[ik+2] = vel(2); } this->getDamp(); for (i = 0; i < 22; i++) { for (j = 0; j < 22; j++) { P(i) += K(i,j)*a[j]; } } // opserr<<"final "<<P<<endln; return P; }
void test_mainTET(void) { typedef CSimuStaticRod T; CMeMaterialProperty mtl; mtl.setYoung(3.00e5); mtl.setPoisson(0.40); mtl.setDamping(40.00, 0.0); mtl.setMassDamping(1.0e-4); int nv=4, nelm=6; Vector3d pVertex[]={ Vector3d(0,0,0), Vector3d(1,0,0), Vector3d(0,1,0), Vector3d(0,0,1), }; Vector3d init_velocity(0,0,0); int element[12]={3,0, 0,1, 1, 2, 2, 0, 3, 1, 3, 2}; const double rod_crossarea=1e-5; T *s = new T(pVertex, nv, init_velocity, element, nelm, rod_crossarea, mtl); //set constraints int fixednodes[]={0,1, 2}; const int len = sizeof(fixednodes)/sizeof(int); CFixedPositionConstraint* fixpos = new CFixedPositionConstraint(10, 0, 1e10, len, fixednodes); s->addConstraint(fixpos); s->setGravityAccelertion(Vector3d(0,0,0)); const double dx = 1; const double dy = 0.0; const double dz= 0.99; { int movenodes[]={3}; Vector3d vel(dx, dy, dz); vel*=1.00e-3; CVelocityConstraint *velo = new CVelocityConstraint(10, 1, 1000, 1, movenodes, vel); s->addConstraint(velo); } { int movenodes[]={3}; Vector3d vel(-dx, -dy, -dz); vel*=1.000e-3; CVelocityConstraint *velo = new CVelocityConstraint(20, 1001, 2000, 1, movenodes, vel); //s->addConstraint(velo); } CSimuEngine e; e.addSimuObject(s); e.setTimestep(2.00e-4); // max step for verlet const int timerid = 0; startFastTimer(timerid); e.startSimulationInMiliSeconds(10000, 50); //e.startSimulation(100, 1); stopFastTimer(timerid); reportTimeDifference(timerid, "Hemi sphere simmu. run time:"); s->exportElementState(0, mtl, stdout); //s->exportElementState(4, mtl, stdout); //s->exportElementState(5, mtl, stdout); }
Real NSEnergyInviscidFlux::computeQpOffDiagJacobian(unsigned int jvar) { RealVectorValue vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]); Real V2 = vel.norm_sq(); // Ratio of specific heats const Real gam = _fp.gamma(); // Derivative wrt density if (jvar == _rho_var_number) return -((0.5 * (gam - 1) * V2 - _enthalpy[_qp]) * _phi[_j][_qp] * (vel * _grad_test[_i][_qp])); // Derivatives wrt momentums else if ((jvar == _rhou_var_number) || (jvar == _rhov_var_number) || (jvar == _rhow_var_number)) { // Map jvar into jlocal = {0,1,2}, regardless of how Moose has numbered things. unsigned jlocal = 0; if (jvar == _rhov_var_number) jlocal = 1; else if (jvar == _rhow_var_number) jlocal = 2; // Scale the velocity vector by the scalar (1-gamma)*vel(jlocal) vel *= (1.0 - gam) * vel(jlocal); // Add in the enthalpy in the jlocal'th entry vel(jlocal) += _enthalpy[_qp]; // Return -1 * (vel * grad(phi_i)) * phi_j return -(vel * _grad_test[_i][_qp]) * _phi[_j][_qp]; } else { std::ostringstream oss; oss << "Invalid jvar=" << jvar << " requested!\n" << "Did not match:\n" << " _rho_var_number =" << _rho_var_number << "\n" << " _rhou_var_number=" << _rhou_var_number << "\n" << " _rhov_var_number=" << _rhov_var_number << "\n" << " _rhow_var_number=" << _rhow_var_number << std::endl; mooseError(oss.str()); } // Won't get here! return 0; }
bool Projectile::Update(double dt) { GameObject::Update(dt); if (CheckDespawn()) // Callback for despawn { return true; } else // Continue moving { Vector2 pos(x, y); switch (type) { case PROJ_BULLET: { // Straight movement Vector2 vel(velocity_x, velocity_y); pos = pos + (vel * dt); x = pos.x; y = pos.y; return false; } break; case PROJ_SEEKING_MISSLE: { if (target) { // Seeking Vector2 newPos = Vector2::MoveToPoint(pos, Vector2(target->GetX(), target->GetY()), speed * dt); x = newPos.x; y = newPos.y; w = -Application::CalcW((newPos - Vector2(target->GetX(), target->GetY()))); return false; } else { // Straight movement Vector2 vel(velocity_x, velocity_y); pos = pos + (vel * dt); x = pos.x; y = pos.y; return false; } } break; } } return false; }
const Vector& PFEMElement2DBubble::getResistingForceIncInertia() { // resize P int ndf = this->getNumDOF(); P.resize(ndf); P.Zero(); // get velocity, accleration Vector v(ndf), vdot(ndf); for(int i=0; i<3; i++) { const Vector& accel = nodes[2*i]->getTrialAccel(); vdot(numDOFs(2*i)) = accel(0); vdot(numDOFs(2*i)+1) = accel(1); const Vector& accel2 = nodes[2*i+1]->getTrialAccel(); // pressure vdot(numDOFs(2*i+1)) = accel2(0); const Vector& vel = nodes[2*i]->getTrialVel(); v(numDOFs(2*i)) = vel(0); v(numDOFs(2*i)+1) = vel(1); const Vector& vel2 = nodes[2*i+1]->getTrialVel(); // pressure v(numDOFs(2*i+1)) = vel2(0); } // bubble force Vector fp(3); getFp(fp); // internal force P.addMatrixVector(1.0, getMass(), vdot, 1.0); P.addMatrixVector(1.0, getDamp(), v, 1.0); // external force Vector F(6); getF(F); for(int i=0; i<3; i++) { P(numDOFs(2*i)) -= F(2*i); P(numDOFs(2*i)+1) -= F(2*i+1); P(numDOFs(2*i+1)) -= fp(i); } //opserr<<"F = "<<F; return P; }
void AddKinematicUnitMessage::process() { std::cout << "Message: AddKinematicUnitMessage\n"; Vector2D pos(100.0f, 100.0f); Vector2D vel(0.0f, 0.0f); KinematicUnit *temp = new KinematicUnit(gpGame->getSpriteManager()->getSprite(2), "SpawnAI", pos, 1, vel, 0.0f, 180.0f, 100.0f); switch (mSteerType) { case 0: temp->dynamicSeek(UNIT_MANAGER->getKinematicUnit("player")); break; case 1: temp->dynamicArrive(UNIT_MANAGER->getKinematicUnit("player")); break; case 2: temp->dynamicFlee(UNIT_MANAGER->getKinematicUnit("player")); break; case 3: temp->wander(); break; } UNIT_MANAGER->addKinematicUnit(temp); }
void Officer::ChangeHealth( int amount ) { bool dead = m_dead; if( amount < 0 && m_shield > 0 ) { int shieldLoss = min( m_shield*10, -amount ); for( int i = 0; i < shieldLoss/10.0f; ++i ) { Vector3 vel( syncsfrand(40.0f), 0.0f, syncsfrand(40.0f) ); g_app->m_location->SpawnSpirit( m_pos, vel, 0, WorldObjectId() ); } m_shield -= shieldLoss/10.0f; amount += shieldLoss; } Entity::ChangeHealth( amount ); if( !dead && m_dead ) { // We just died Matrix34 transform( m_front, g_upVector, m_pos ); g_explosionManager.AddExplosion( m_shape, transform ); } }
void Rigidbody::Update(float dt) { //////////linearvelocity update Vector3h vec = Velocity + acc*dt; SetVelocity(vec); pos =pos + Velocity*dt; ///////rotation update Quath vel(0,AngVelocity.x,AngVelocity.y,AngVelocity.z); vel = vel*rotation; vel*=0.5*dt; rotation += vel; rotation.Normalize(); //////////////////// float damping=0.8; damping = powf(damping,dt); Velocity *= damping; AngVelocity*= damping; UpdateMatrix(); }
string LogicalAndInterfaceElement::display( ostream& stream , const ParametersVector& parameters , VariablesMap& variables , const void* object /*= NULL*/ , const server::Request* request /*= NULL*/ ) const { ValueElementList vel(_parameters); try { int number(lexical_cast<int>(vel.front()->getValue(parameters, variables, object, request))); while (!vel.isEmpty()) { number &= lexical_cast<int>(vel.front()->getValue(parameters, variables, object, request)); } stream << number; } catch(bad_lexical_cast) { stream << "0"; } return string(); }
TYPED_TEST(HomogeneousTransformationTest, testGenericRotateVectorCompilable) { pose::HomogeneousTransformationPosition3RotationQuaternionD test(pos::Position3D(1,2,3),rot::RotationQuaternionPD(rot::AngleAxisPD(0.5,1.0,0,0))); pos::Velocity3D vel(-1,2,3); test.getRotation().rotate(vel); }
void CharacterJump::Enter() { mSprite.Play(1.0f, true); SVector2 vel(mpOwner->GetVelocity()); vel.y = -25.0f; mpOwner->SetVelocity(vel); }
gamePicture::gamePicture(D3DXVECTOR3 seed,LPDIRECT3DDEVICE9 d3dDev, D3DXVECTOR2 cCount):GameObject(D3DXVECTOR3()) { D3DXVECTOR3 vel(0,-2.0f,0); // Start off velocity D3DXVECTOR3 acc(0,0,0); D3DXVECTOR3 nav(0, -250.0f, 0); // Used for rotating this->cellSize = D3DXVECTOR2(1,1); this->size = D3DXVECTOR2(1,1); this->pVtxBuf = NULL; this->cellCount = cCount; this->cellSize.x = 1/cCount.x; this->cellSize.y = 1/cCount.y; this->vel = vel; this->acc = acc; this->navVector = nav; this->orient=-90; this->rotationStep = 0; this->speed = 8; this->curTexture = gamePicture::textureList.at(1); this->cellPosition.x = 0; this->cellPosition.y = 0; this->initGeom(seed,d3dDev); // get the velocity vector from an initial speed vel.x = this->speed * cos(D3DXToRadian(this->orient)); vel.y = this->speed * sin(D3DXToRadian(this->orient)); }
void Boid::update() { // Update velocity m_velocity->add(*m_acceleration); // Limit speed m_velocity->limit(m_maxspeed); // Reset accelertion to 0 each cycle Vector vel(m_velocity->getX(), m_velocity->getY()); vel.normalise(); Vector pos(m_pos->getX(), m_pos->getY()); m_rotation -= Vector::angleBetween(pos, vel); m_pos->add(*m_velocity); //float angle = vel //angle+=90; m_shape->setRotation(m_rotation); m_acceleration->setVector(Vector(0,0)); m_shape->setPosition(m_pos->getX(), m_pos->getY()); }
void GameStartState::start() { Timer t; started_ = t.getTime(); srand(0xadadadad); for (int i = 0; i < 100; ++i) { vector3 vel(1.0f*(rand() - 32767/2), 1.0f*(rand() - 32767/2), 1.0f*(rand() - 32767/2)); vel.norm(); vel *= 20; ADot* dot = new ADot(vector3(0,0,0), vel); owned_.push_back(dot); parts_.push_back(&dot->p_); } owned_.push_back(new TestFloor); for (std::vector<Renderable*>::iterator itt = owned_.begin(); itt != owned_.end(); ++itt) { App::instance().getWindowManager().add(*itt); } }
void JumpToTargetMovement::activate() { // Code from Weitsprung without Talentprobe AbstractMovement::activate(); mState = DOWNTOUP; mMovingCreature->setAnimation(mAnimationAbsprung.first,mAnimationAbsprung.second,1,mAnimationForCollision.first); mTimer = 0; calculateBaseVelocity(mWidth); // the person will only achieve this width if it is running // retrieve run movement AbstractMovement *run = mMovingCreature->getMovementFromId(CreatureController::MT_RENNEN); if( run != NULL ) { Real vel(0); run->calculateBaseVelocity(vel); Real factor = -mMovingCreature->getVelocity().z / vel; factor = std::max(Real(0),factor); // without moving before, the width will be 1/3 mWidth = mWidth/3. + mWidth * 2./3. * factor; } mMovingCreature->getCreature()->damageAu(1./3); // not as much AU as Weitsprung }
const Vector& GenericClient::getResistingForceIncInertia() { theVector = this->getResistingForce(); // subtract external load theVector.addVector(1.0, theLoad, -1.0); if (massFlag == false) this->getMass(); int ndim = 0, i; Vector vel(numDOF), accel(numDOF); // add the damping forces from remote element damping // (if addRayleigh==1, C matrix already includes rayleigh damping) Matrix C = this->getDamp(); // assemble vel vector for (i=0; i<numExternalNodes; i++ ) { vel.Assemble(theNodes[i]->getTrialVel(), ndim); ndim += theNodes[i]->getNumberDOF(); } theVector.addMatrixVector(1.0, C, vel, 1.0); // add inertia forces from element mass ndim = 0; // assemble accel vector for (i=0; i<numExternalNodes; i++ ) { accel.Assemble(theNodes[i]->getTrialAccel(), ndim); ndim += theNodes[i]->getNumberDOF(); } theVector.addMatrixVector(1.0, theMass, accel, 1.0); return theVector; }
void Sound::update(const float dt) { // done when path is completely travelled if (nextAnchor_ < 0 || nextAnchor_ >= path_.size()) { nextAnchor_ = -1; return; } // get direction to next anchor vec2i next = path_[nextAnchor_]; vec2f d1 = vec2f(next.x - position_.x, next.y - position_.y); // if we are at an anchor, continue to next one if (d1.x == 0 && d1.y == 0) { nextAnchor_++; return; } // move forward vec2f v = d1 / d1.norm() * velocity_; position_ += dt * v; // test if we shot over the anchor vec2f d2 = vec2f(next.x - position_.x, next.y - position_.y); if (dot(d1, d2) <= 0) { position_ = vec2f(next.x, next.y); nextAnchor_++; if (soundRenderer_) { // turn! play sound vec3f pos(position_.x, 0.5f, position_.y); vec3f vel(0, 0, 0); soundRenderer_->playSound(pos, vel, sound_); } else { if (nextAnchor_ >= path_.size()) { stop(); } } if (dsp_ != nullptr) { float value; dsp_->getParameterFloat(FMOD_DSP_OSCILLATOR_RATE, &value, nullptr, 0); dsp_->setParameterFloat(FMOD_DSP_OSCILLATOR_RATE, value * 1.1f); } } if (channel_ != nullptr) { // update sound position and velocity accordingly FMOD_VECTOR fpos = {static_cast<float>(position_.x), 0.5f, static_cast<float>(position_.y)}; FMOD_VECTOR fvel = {static_cast<float>(v.x), 0, static_cast<float>(v.y)}; channel_->set3DAttributes(&fpos, &fvel); } }
void CPowerUp::Respawn() { int x, y; CRenderer *pRenderer = CRenderer::Instance(); CUniverse* universe = CODEManager::Instance()->m_pUniverse; do { x = rand()%((int) universe->m_fWidth*2) - (int) universe->m_fWidth; y = rand()%((int) universe->m_fHeight*2) - (int) universe->m_fHeight; } while ( pRenderer->ObjectsInRange( x, y, 100 ) ); Vector v = Vector( (float)x, (float)y, 0.0f ); SetPosition( v ); Vector n; Vector vel((float) (rand() % 10), (float) (rand() % 10), 0); m_oPhysicsData.m_pOwner->SetLinVelocity(vel); SetForce(n); this->m_bIsGrabable = true; this->m_oPhysicsData.m_bHasCollision = true; CSound *pSound = (CSound *)CResourceManager::Instance()->GetResource("media/sounds/powerup_spawn.wav", RT_SOUND); if ( pSound ) pSound->Play(); }
double DynNewtonian::getSquareCellCollision2(const Particle& part, const Vector & origin, const Vector & width) const { Vector rpos(part.getPosition() - origin); Vector vel(part.getVelocity()); Sim->BCs->applyBC(rpos, vel); #ifdef DYNAMO_DEBUG for (size_t iDim = 0; iDim < NDIM; ++iDim) if ((vel[iDim] == 0) && (std::signbit(vel[iDim]))) M_throw() << "You have negative zero velocities, don't use them."; #endif double retVal; if (vel[0] < 0) retVal = -rpos[0] / vel[0]; else retVal = (width[0]-rpos[0]) / vel[0]; for (size_t iDim = 1; iDim < NDIM; ++iDim) { double tmpdt((vel[iDim] < 0) ? -rpos[iDim]/vel[iDim] : (width[iDim]-rpos[iDim]) / vel[iDim]); if (tmpdt < retVal) retVal = tmpdt; } return retVal; }
void Demo::doSimulation(GameTime timeStep) { // Simulation Vector3 originalTrans = app->debugController.getCoordinateFrame().translation; app->debugController.doSimulation(clamp(timeStep, 0.0, 0.1)); CoordinateFrame newCframe; app->debugController.getCoordinateFrame(newCframe); if (app->clipMovement) { Vector3 extent(14, 14, 14); extent *= BSPMAP::LOAD_SCALE; Vector3 pos(originalTrans.x, originalTrans.y, originalTrans.z); Vector3 vel(newCframe.translation.x - originalTrans.x, newCframe.translation.y - originalTrans.y, newCframe.translation.z - originalTrans.z); app->map->slideCollision(pos, vel, extent); newCframe.translation.x = pos.x; newCframe.translation.y = pos.y; newCframe.translation.z = pos.z; app->debugController.setPosition(newCframe.translation); } app->debugCamera.setCoordinateFrame(newCframe); }
void CharacterJump::Update(float fSeconds) { // Update sprite mSprite.Update(fSeconds); // Update physics const float kSpeed = 500.0f; SVector2 vel(mpOwner->GetVelocity()); if (Input_IsKeyDown(Keys::RIGHT)) { vel.x = kSpeed * fSeconds; mpOwner->SetFacingLeft(false); } else if (Input_IsKeyDown(Keys::LEFT)) { vel.x = -kSpeed * fSeconds; mpOwner->SetFacingLeft(true); } else { vel.x = 0.0f; } mpOwner->SetVelocity(vel); // State transitions if (vel.y >= 0.0f) { mpOwner->ChangeState(AS_Fall); } }
NEventData DynGravity::enforceParabola(Particle& part) const { updateParticle(part); const Species& species = *Sim->species(part); NEventData retval(ParticleEventData(part, species, VIRTUAL)); Vector pos(part.getPosition()), vel(part.getVelocity()); Sim->BCs->applyBC(pos, vel); //Find the dimension that is closest to size_t dim = NDIM; double time = std::numeric_limits<float>::infinity(); for (size_t iDim(0); iDim < NDIM; ++iDim) if (g[iDim] != 0) { double tmpTime = std::abs(- vel[iDim] / g[iDim]); if ((std::abs(tmpTime) < time)) { time = tmpTime; dim = iDim; } } #ifdef DYNAMO_DEBUG if (dim >= NDIM) M_throw() << "Could not find a dimension to enforce the parabola in!"; #endif part.getVelocity()[dim] = 0; return retval; }
Vec2 getVelocity(const Vec2 & pos, float inSec, float durationSec, float massKg, float scalar) { Vec2 vel(0.0, 0.0); for (size_t i = 0; i < _points.size(); ++i) { Vec2 dir(pos - _points[i]); const float r = length(dir); if (r == 0.0f) continue; float w = _weights[i]; if (_useInverseSquare) { const float k = 1.0/(r*r); w *= clamp(k, 0.0001, 1.0); } vel += (w/r) * dir; } Random rng; Mat4 mat; const float theta = rng.uniform(_minRadians, _maxRadians); mat.makeRotationRadians(theta, 0.0f, 0.0f, 1.0f); const Vec4 v = mat * Vec4(vel.x(), vel.y(), 0.0f, 0.0f); const float s = rng.uniform(_minSpeed, _maxSpeed); return s * Vec2(v.x(), v.y()); }
void DynGravity::enforceParabola(Particle& part) const { updateParticle(part); Vector pos(part.getPosition()), vel(part.getVelocity()); Sim->BCs->applyBC(pos, vel); //Find the dimension that is closest to size_t dim = NDIM; double time = HUGE_VAL; for (size_t iDim(0); iDim < NDIM; ++iDim) if (g[iDim] != 0) { double tmpTime = std::abs(- vel[iDim] / g[iDim]); if ((std::abs(tmpTime) < time)) { time = tmpTime; dim = iDim; } } #ifdef DYNAMO_DEBUG if (dim >= NDIM) M_throw() << "Could not find a dimension to enforce the parabola in!"; #endif part.getVelocity()[dim] = 0; }
void XScalarAdvectionResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { std::vector<ScalarT> vel(numLevels); for (int level=0; level < numLevels; ++level) { vel[level] = (level+1)*Re; } for (int i=0; i < workset.numCells; ++i) for (int node=0; node < numNodes; ++node) Residual(i, node)=0.0; for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { for (int node=0; node < numNodes; ++node) { if (2==numRank) { Residual(cell,node) += XDot(cell,qp)*wBF(cell,node,qp); for (int j=0; j < numDims; ++j) Residual(cell,node) += vel[0] * XGrad(cell,qp,j)*wBF(cell,node,qp); } else { TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "no impl"); //Irina TOFIX /* for (int level=0; level < numLevels; ++level) { Residual(cell,node,level) += XDot(cell,qp,level)*wBF(cell,node,qp); for (int j=0; j < numDims; ++j) Residual(cell,node,level) += vel[level] * XGrad(cell,qp,level,j)*wBF(cell,node,qp); } */ } } } } }
Cell FluidSimulator::advectCell(int i, int j){ if (simulationGrid->cells[i][j].cellType == SOLID) return simulationGrid->cells[i][j]; Vector vel(simulationGrid->getHVelocityAt(i, j), simulationGrid->getVVelocityAt(i, j), 0); if (vel[0] == 0 && vel[1]==0) return simulationGrid->cells[i][j]; Vector position = simulationGrid->getCellPosition(i, j); Vector midPos = position - vel*dt / 2; Vector tracedParticle = position - simulationGrid->interpolateVelocity(midPos)*dt; /*std::cout << "\n" << "i" << i << " j" << j << "\n"; std::cout << "vel" << vel << "\n"; std::cout << "pos" << position << "\n"; std::cout << "midpos" << midPos << "\n"; std::cout << "tracedP" << tracedParticle << "\n"; std::cout<< "intrp" << simulationGrid->interpolateVelocity(tracedParticle) << "\n";*/ if (simulationGrid->getCell(tracedParticle).cellType == SOLID) return simulationGrid->cells[i][j]; Cell cell = simulationGrid->getCell(tracedParticle); cell.u = simulationGrid->interpolateVelocity(tracedParticle)[0]; cell.v = simulationGrid->interpolateVelocity(tracedParticle)[1]; return cell; }
static vector3d GetVelInFrame(Frame *frame, Frame *target, const vector3d &offset) { matrix4x4d m; vector3d vel(0.0); Frame::GetFrameTransform(target, frame, m); if (target != frame) vel = -target->GetStasisVelocityAtPosition(offset); return (m.ApplyRotationOnly(vel) + Frame::GetFrameRelativeVelocity(frame, target)); }
std::pair<float, float> StateMachine::changeBulletSpread(WEAPON wp) { float b2x, b3x; switch (wp) { case WEAPON::STANDARD: b2x = -1.0f; b3x = 1.0f; break; case WEAPON::WEAPON1: b2x = -2.0f; b3x = 2.0; break; case WEAPON::WEAPON2: b2x = -3.0f; b3x = 3.0f; break; case WEAPON::WEAPON3: b2x = -4.0f; b3x = 4.0f; break; default: b2x = -1.0f; b3x = 1.0f; } std::pair<float, float> vel(b2x, b3x); return vel; }
bool Monitor::dispplayer( const char * command ) { // a player is given new position by the monitor int side, unum; int x, y, a; if ( std::sscanf( command, " ( dispplayer %d %d %d %d %d ) ", &side, &unum, &x, &y, &a ) != 5 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } double real_x = x / SHOWINFO_SCALE; double real_y = y / SHOWINFO_SCALE; double angle = Deg2Rad( a ); PVector vel( 0.0, 0.0 ); return M_stadium.movePlayer( static_cast< Side >( side ), unum, PVector( real_x, real_y ), &angle, &vel ); }
void GSOCells::runEvent(Particle& part, const double) const { Sim->dynamics->updateParticle(part); Vector CellOrigin; size_t ID(part.getID()); for (size_t iDim(0); iDim < NDIM; ++iDim) { CellOrigin[iDim] = (ID % cuberootN) * cellDimension[iDim] - 0.5*Sim->primaryCellSize[iDim]; ID /= cuberootN; } //Determine the cell transition direction, its saved int cellDirectionInt(Sim->dynamics-> getSquareCellCollision3 (part, CellOrigin, cellDimension)); size_t cellDirection = abs(cellDirectionInt) - 1; GlobalEvent iEvent(getEvent(part)); #ifdef DYNAMO_DEBUG if (std::isnan(iEvent.getdt())) M_throw() << "A NAN Interaction collision time has been found" << iEvent.stringData(Sim); if (iEvent.getdt() == HUGE_VAL) M_throw() << "An infinite Interaction (not marked as NONE) collision time has been found\n" << iEvent.stringData(Sim); #endif Sim->systemTime += iEvent.getdt(); Sim->ptrScheduler->stream(iEvent.getdt()); Sim->stream(iEvent.getdt()); Vector vNorm(0,0,0); Vector pos(part.getPosition()), vel(part.getVelocity()); Sim->BCs->applyBC(pos, vel); vNorm[cellDirection] = (cellDirectionInt > 0) ? -1 : +1; //Run the collision and catch the data NEventData EDat(Sim->dynamics->runPlaneEvent(part, vNorm, 1.0, 0.0)); Sim->_sigParticleUpdate(EDat); //Now we're past the event update the scheduler and plugins Sim->ptrScheduler->fullUpdate(part); for (shared_ptr<OutputPlugin> & Ptr : Sim->outputPlugins) Ptr->eventUpdate(iEvent, EDat); }