这篇教程C++ velocity函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中velocity函数的典型用法代码示例。如果您正苦于以下问题:C++ velocity函数的具体用法?C++ velocity怎么用?C++ velocity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了velocity函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: velocity/** * Simulates the timestep for the capsule. * @param timestep The step length in ms. * @param capsule The capsule, that is the projectile in the world. */void ProjectileSplitting::step( int timestep, BodyProjectile &capsule ){ Vector velocity( capsule.getVelocity() ); float splitAngle = M_PI * this->parameters.getParameterValue( this->indexSplittingAngle ) / 180.0; float stepAngle = splitAngle / this->splitCount; velocity.scale( this->splittingVelocity / velocity.getLength() ); velocity.rotate( ( stepAngle - splitAngle ) / 2 ); if ( this->timeLived >= this->parameters.getParameterValue( this->indexSplittingTime ) ) { for ( int i = 0; i < this->splitCount; i++ ) { Projectile *model = this->splittingProjectile.getCopy(); model->setShooter( this->getShooter() ); BodyProjectile *newProjectile = new BodyProjectile( capsule.getWorld(), capsule.getLocation().getX(), capsule.getLocation().getY(), *model ); newProjectile->setVelocity( capsule.getVelocity().getX() + velocity.getX(), capsule.getVelocity().getY() + velocity.getY() ); velocity.rotate( stepAngle ); newProjectile->setActionFlag( capsule.getActionFlag() ); capsule.getWorld().addBody( *newProjectile ); } capsule.destroy(); } Projectile::step( timestep, capsule ); }
开发者ID:jluttine,项目名称:ipag,代码行数:50,
示例2: findLinevoid findLine(void){ nodeMissEnable = 0; int tempLeftCount = ShaftCountLeft; int tempRightCount = ShaftCountRight; velocity(180, 150); sensorRight = ADC_Conversion(1); left(); while(sensorRight < 20) { centre = ADC_Conversion(2); if(centre > 30) { forward(); nodeMissEnable = 1; return; } sensorRight = ADC_Conversion(1); } stop(); _delay_ms(100); sensorLeft = ADC_Conversion(3); right(); while(sensorLeft < 20) { centre = ADC_Conversion(2); if(centre > 30) { forward(); nodeMissEnable = 1; return; } sensorLeft = ADC_Conversion(3); } ShaftCountLeft = tempLeftCount; ShaftCountRight = tempRightCount; nodeMissEnable = 1;}
开发者ID:kdsouza1496,项目名称:Cargo-alignment-robot,代码行数:45,
示例3: spin//------------------------------------------------------------------------------// protected://------------------------------------------------------------------------------voidCloud::doInit(){ if ( m_black ) { m_sprite = Engine::rm()->GetSprite( BLACK[m_size] ); } else { m_sprite = Engine::rm()->GetSprite( WHITE[m_size] ); } m_zoom = 0; m_life = 4.0f; b2BodyDef bodyDef; bodyDef.userData = static_cast<void*> (this); m_body = Engine::b2d()->CreateDynamicBody(&bodyDef); b2CircleDef shapeDef; shapeDef.radius = 0.5f * 0.95f * m_sprite->GetWidth() * m_scale; shapeDef.density = 10.0f; shapeDef.friction = 0.0f; shapeDef.restitution = 1.0f; if ( m_size == 0 ) { shapeDef.density = 0.001f; } m_body->CreateShape(&shapeDef); m_body->SetMassFromShapes(); m_body->m_linearDamping = 0.0f; if ( m_size == 0 ) { m_body->m_linearDamping = 0.99f; m_body->m_angularDamping = 0.8f; } m_body->m_angularDamping = 0.0f; float spin( 5.0f / static_cast<float>(m_size + 1.0f) ); m_body->SetAngularVelocity( Engine::hge()->Random_Float( -spin, spin ) ); float speed( SPEED[m_size] ); b2Vec2 velocity( Engine::hge()->Random_Float( -speed, speed ), Engine::hge()->Random_Float( -speed, speed ) ); m_body->SetLinearVelocity( velocity );}
开发者ID:jasonhutchens,项目名称:99sheep,代码行数:48,
示例4: Update//*************************************************************************************************************void Update(float delta){ D3DXVECTOR2 velocity(mousedx, mousedy); cameraangle.prev = cameraangle.curr; if( mousedown == 1 ) cameraangle.curr += velocity * 0.004f; // clamp to [-pi, pi] if( cameraangle.curr.y >= 1.5f ) cameraangle.curr.y = 1.5f; if( cameraangle.curr.y <= -1.5f ) cameraangle.curr.y = -1.5f; system1.Update();}
开发者ID:IwishIcanFLighT,项目名称:Asylum_Tutorials,代码行数:19,
示例5: while void ParticleEmitterCircle::Update(GLfloat delta) { m_currentDelay+=delta; while(m_currentDelay>=m_spawnDelay) { m_currentDelay-=m_spawnDelay; Particle *pParticle=new Particle; pParticle->m_position=m_position; pParticle->m_angularVelocity=Core::Random::Double(m_minAngularVelocity,m_maxAngularVelocity); pParticle->m_maxLife=Core::Random::Double(m_minParticleLife,m_maxParticleLife); pParticle->m_life=pParticle->m_maxLife; pParticle->m_texture=m_texture; Vector2f velocity(1.0f,0.0f); velocity.Rotate(Core::Random::Double(0.0f,360.0f)); pParticle->m_velocity=velocity*Core::Random::Double(m_minVelocity,m_maxVelocity); pParticle->m_modifiers=&m_modifiers; } }
开发者ID:gitter-badger,项目名称:MPACK,代码行数:18,
示例6: AddParticleStartingAtvoid AddParticleStartingAt(Vec4<float> WorldPoint) { ParticleSystem* ps = ModelerApplication::Instance()->GetParticleSystem(); for (int i = 0; i < VAL(PARTICLE_COUNT) * 5 ; i++) { float mag = rand() % 10 / 10.0 + 0.2; float theta = rand() % 360 / 57.3; float yVelocity = rand() % 10 / 10.0 + 2; float xVelocity = cos(theta) * mag; float zVelocity = sin(theta) * mag * 3; //printf("add: %f, %f, %f/n", WorldPoint[0], WorldPoint[1], WorldPoint[2]); Vec3f position(WorldPoint[0], WorldPoint[1], WorldPoint[2]); Vec3f velocity(xVelocity, 5, zVelocity); Particle* p = new PointObj(1.0f, position, velocity); //printf("added: %f, %f, %f/n", p->getPosition()[0], p->getPosition()[1], p->getPosition()[2]); ps->addParticle(p); }}
开发者ID:billytotochan,项目名称:anime,代码行数:18,
示例7: velocityDOUBLE2 MassProjList::HandleCircularCollision(DOUBLE2 otherCirclePos,DOUBLE2 otherCircleVelocity, double radius, double mass){ DOUBLE2 velocity(0,0), newVelocity(0,0); velocity=otherCircleVelocity; for (int count=0; count < MAX_MASSPROJECTILES; ++count) { if (m_MassProjectilePtrArr[count] != nullptr) { newVelocity=m_MassProjectilePtrArr[count]->HandleCircularCollision(otherCirclePos,velocity ,radius, mass ); if (newVelocity!=DOUBLE2(0,0)) velocity= newVelocity; } } return velocity;}
开发者ID:kennethdeman,项目名称:escape_into_space,代码行数:18,
示例8: totalForceVec3D<> CVX_Voxel::force(){ //forces from internal bonds Vec3D<> totalForce(0,0,0); for (int i=0; i<6; i++){ if (links[i]) totalForce += links[i]->force(isNegative((linkDirection)i)); //total force in LCS } totalForce = orient.RotateVec3D(totalForce); //other forces totalForce += extForce; //external forces totalForce -= velocity()*mat->globalDampingTranslateC(); //global damping if (isGravityEnabled()) totalForce.z -= mat->_mass*9.80665; //gravity, according to f=mg if (isFloorEnabled()) addFloorForces(&totalForce); //adds forces from interacting with the floor //Collisions: todo return totalForce;}
开发者ID:CreativeMachinesLab,项目名称:voxcadNASA,代码行数:18,
示例9: switch//figures out what needs to happen at an intersection based on the direction we want to turnvoid Robot::handleIntersection(Direction direction){ switch (direction) { case StraightAhead: break; case Left: Tape::resetErrors(); resetVelocity(); turnAtIntersection(false, millis()); break; case Right: Tape::resetErrors(); resetVelocity(); turnAtIntersection(true, millis()); break; case TurnAround: Tape::resetErrors(); resetVelocity(); turnOntoTape(direction); break; case SlightRight: Actuators::drive(velocity(), SLIGHT_RIGHT_AT_SPECIAL_INTERSECTION_TURN); delay(SLIGHT_RIGHT_AT_SPECIAL_INTERSECTION_DURATION); Tape::resetErrors(); resetVelocity(); findTape(); break; case SlightLeft: Actuators::drive(VELOCITY_SLOW, -SLIGHT_LEFT_AT_SPECIAL_INTERSECTION_TURN); delay(SLIGHT_LEFT_AT_SPECIAL_INTERSECTION_DURATION); Tape::resetErrors(); resetVelocity(); findTape(); break; }}
开发者ID:NooberRobotics,项目名称:TheRay,代码行数:45,
示例10: positionvoid Emitter::prepareParticles(){ // Shotgun stuff if(hasFired && isShotgun){ return; } hasFired = true; for(int i(0); i < density; ++i){ // Shitty random generation for now float rand1 = ((rand()%100)/100.0f)-0.5f; float rand2 = ((rand()%100)/100.0f)-0.5f; float rand3 = ((rand()%100)/100.0f)-0.5f; glm::vec3 position(-1.3f+rand1, 0.0f, rand2); // Emitter parented to camera // position+=camera->getPosition(); glm::vec3 velocity(0.0f, 0.01f+(0.01f*rand3), 0.0f); glm::vec3 acceleration(0.0f, 0.0f, 0.0f); // Random wind interaction for snow particles. // if (rand() % 1000){ // velocity += glm::vec3(0.001 * (rand() % 5), - abs(0.0005 * (rand() % 5)), 0.001 * (rand() % 5)); // } float rotation = 0.0f; // Particle recycling! // Weird that the pointer must be explicitly set to 0, but crashes without this Particle* ptr = 0; if(particles.size() < maxParticles){ ptr = new Particle(*billboard, shader); ptr->setEmissive(particle_texture); } if(particles.size() > 0 && particles[0]->isDead()){ ptr = particles[0]; particles.pop_front(); } if(ptr){ ptr->setInitialValues(position, velocity, acceleration, rotation, lifespan, Particle::ScalingOption::SCALE_DOWN_WITH_AGE, Particle::FadingOption::FADE_NONE); particles.push_back(ptr); } }}
开发者ID:donutmonger,项目名称:Game,代码行数:44,
示例11: collision_timeint collision_time(double *pos, double *vel, double h, double r, double *tcoll, double *cup){ int result, napproaches, i; double tpos[3], tvel[3], poly[DEGSIZE], tcloseapproaches[2]; int event = RESULT_NOTHING; double tevent = NAN; // find where the trajectory intersects the z=h plane build_plane_poly(pos, vel, r, poly); find_all_roots(poly, 2, tcloseapproaches, &napproaches); for (i=0; i<napproaches; i++){ if (tcloseapproaches[i] < 0) continue; position(pos, vel, tcloseapproaches[i], tpos); velocity(vel, tcloseapproaches[i], tvel); result = collision_near(tpos, tvel, h, r, tcoll, cup); *tcoll = *tcoll + tcloseapproaches[i]; if (result == RESULT_COLLISION || result == RESULT_INCUP){ if ((isnan(tevent) || tevent > *tcoll) && *tcoll > 0){ event = result; tevent = *tcoll; } } } result = collision_near(pos, vel, h, r, tcoll, cup); if (result == RESULT_COLLISION || result == RESULT_INCUP){ if ((isnan(tevent) || tevent > *tcoll) && *tcoll > 0){ event = result; tevent = *tcoll; } } if (event == RESULT_NOTHING){ build_zero_poly(pos, vel, poly); find_all_roots(poly, 2, tcloseapproaches, &napproaches); tevent = tcloseapproaches[0] > 0 ? tcloseapproaches[0] : tcloseapproaches[1]; } *tcoll = tevent; return event;}
开发者ID:mattbierbaum,项目名称:cupgame,代码行数:44,
示例12: spinvoid spin(int which, int direction){ int lVel, rVel; switch (direction) { case CLOCKWISE : lVel = (int)(48 * gSpinVelocityScaling + 0.5); //rVel = (int)(-48 * gSpinVelocityScaling + 0.5); rVel = -lVel; break; case ANTICLOCKWISE : rVel = (int)(48 * gSpinVelocityScaling + 0.5); //lVel = (int)(-48 * gSpinVelocityScaling + 0.5); lVel = -rVel; break; } velocity(which, lVel, rVel); return;} //---- spin()
开发者ID:RealityFork,项目名称:Robot-Soccer,代码行数:19,
示例13: getParticleSet /** * returns current status of particle set in a general form * * /return filled particle vector */ const ParticleSet& getParticleSet( base::Vector3d transformation = base::Vector3d::Zero()) { assert(particles.size() > 0); ps.particles.clear(); ps.timestamp = timestamp; for(ParticleIterator it = particles.begin(); it != particles.end(); it++) { Particle p; p.position = position(*it) + transformation; p.velocity = velocity(*it); p.yaw = base::getYaw(orientation(*it).orientation); p.main_confidence = confidence(*it); ps.particles.push_back(p); } return ps; }
开发者ID:auv-avalon,项目名称:uw_localization,代码行数:24,
示例14: envManager::Manager() : env( SDL_putenv(const_cast<char*>("SDL_VIDEO_CENTERED=center")) ), gdata( Gamedata::getInstance() ), drawTheStupidHud(false), io( IOManager::getInstance() ), clock( ), screen( io->getScreen() ), clouds( SpriteFrameFactory::getInstance()->getFrame("back", "back"), 2 ), hills( SpriteFrameFactory::getInstance()->getFrame("hill", "hill"), 1 ), ghostbcknd(SpriteFrameFactory::getInstance()->getFrame("ghostbcknd", "ghostbcknd"), 1 ), view(Viewport::getInstance()), pter( NULL ), pterleft(NULL), var1(0), var2(0), gui(), remainingTime(60), orbs(){ if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw string("Unable to initialize SDL: "); } Vector2f position(gdata->getXmlInt("pterX"), gdata->getXmlInt("pterY")); Vector2f velocity(gdata->getXmlInt("pterXspeed"), gdata->getXmlInt("pterYspeed")); pter = new MultiSprite(position, velocity, MultiSpriteFrameFactory::getInstance()->getFrame("pter","pter"), "pter"); pterleft= new MultiSprite(position, velocity, MultiSpriteFrameFactory::getInstance()->getFrame("pterleft","pterleft"), "pterleft"); orbs.pter = pter; orbs.pterLeft = pterleft; view->setObjectToTrack(pter); atexit(SDL_Quit); SDL_WM_SetCaption( "*** CpSc 870: Nikhil Bendre - Ghost Busters ***", NULL );}
开发者ID:npbendre,项目名称:2D-Game-Engine-,代码行数:43,
示例15: velocitycoment::Entity EntityFactory::createParticle(coment::World& world, float x, float y){ coment::Entity entity = world.createEntity(); //return entity; // First working solution with SFML //sf::Vector2f velocity(0.f, (float)(std::rand() % 800 - 400)); //sf::Transform rotationTransform; //rotationTransform.rotate((rand() % 36000) / 100.f); //velocity = rotationTransform.transformPoint(velocity); // Second working solution // http://stackoverflow.com/a/5838055/1702695 float t = 2.f * 3.141592654f * MathUtils::randomFloat(); float u = MathUtils::randomFloat() + MathUtils::randomFloat(); float r = (u>1) ? 2.f-u : u; Vector2f velocity(r * std::cos(t), r * std::sin(t)); velocity = velocity * (MathUtils::randomFloat() * 800.f - 400.f); // I benchmark it and it's faster than the first solution // Bench (in Release mode): // solution 1: 192ms for 1'000'000 iterations // solution 2: 50ms for 1'000'000 iterations world.addComponent(entity, Position(x, y)); world.addComponent(entity, Velocity(velocity.x, velocity.y)); world.addComponent(entity, Expires(7.f)); Sprite sprite; sprite.name = "particle"; sprite.color = Color({1.0f, 0.84f, 0.0f, 0.5f}); sprite.layer = Sprite::Layer::PARTICLES; world.addComponent(entity, sprite); ColorAnimation colorAnimation; colorAnimation.animate[ColorAnimation::A] = true; colorAnimation.speed[ColorAnimation::A] = -0.2f; colorAnimation.min[ColorAnimation::A] = 0.f; colorAnimation.max[ColorAnimation::A] = 1.f; colorAnimation.repeat = false; world.addComponent(entity, colorAnimation);}
开发者ID:Polyfructol,项目名称:starwarriorcoment,代码行数:42,
示例16: pCentervoid MetalineEnemy::checkToFire(){ if (fireCounter >= FIRE_COUNTER_THRESHOLD) { GameState *gs = GameState::GetInstance(); Vector3f playerPos = gs->GetPlayerPosition(); Vector3f pCenter(this->center.x, this->center.y, this->center.z); Vector3f projectileDirection = (playerPos - pCenter).normalized(); Vector3f velocity(projectileDirection(0) * PROJECTILE_SPEED, projectileDirection(1) * PROJECTILE_SPEED, projectileDirection(2) * PROJECTILE_SPEED); Projectile *p = new Ball(pCenter, velocity, PROJECTILE_RADIUS); gs->GetParticleSystems()->AddBullet(p); fireCounter = 0; } else if (fireCounter < FIRE_COUNTER_THRESHOLD) { fireCounter++; }}
开发者ID:austinhulse,项目名称:SpaceGame,代码行数:20,
示例17: velocityvoid ExplosionEmitter::resetParticle(ParticleAttribute *particle){ particle->_position = _origin; D3DXVECTOR3 velocity(0.0f, 0.0f, 1.0f); ParticleEmitter::jitterVector( velocity, (-D3DX_PI / 2) + util::EPSILON, (D3DX_PI / 2) - util::EPSILON, 0.0f, (2 * D3DX_PI) - util::EPSILON); velocity *= std::pow(util::randFloat(00.0f, 1.0f),3)*1000; particle->_velocity = velocity; particle->_acceleration = D3DXVECTOR3(0.0f, -100.0f, 0.0f); particle->_alive = true; particle->_age = 0.0f; particle->_lifeTime = 1.0f; particle->_color = D3DCOLOR_RGBA(255, 255, 255, 0);}
开发者ID:yixu34,项目名称:RestlessMoon2,代码行数:20,
|