当前位置: 首页>>代码示例>>C++>>正文


C++ PhysicalObject类代码示例

本文整理汇总了C++中PhysicalObject的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalObject类的具体用法?C++ PhysicalObject怎么用?C++ PhysicalObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PhysicalObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getRelativePositions

void HUDBase::getRelativePositions(list<Vertex<float> > &above, list<Vertex<float> > &below)
{
    // Reset the vectors
    above.clear();
    below.clear();

    set<PhysicalObject*>::iterator it;
    m_mutex.lock();
    for(it = m_destroyables.begin(); it != m_destroyables.end(); it++)
    {
        // Calculate the mapping of the difference vector:
        PhysicalObject* obj = *it;
        Vertex<float> diff = obj->getPosition() - m_fighter->getPosition();

        // Project onto current flight axis
        float x = diff * m_fighter->getXAxis();
        float y = diff * m_fighter->getYAxis();
        float z = diff * m_fighter->getZAxis();

        // Create new relative position
        Vertex<float> rel(x,y,z);

        //And add to the relative positions
        if(z<0)
        {
            below.push_back(rel);
        }
        else
        {
            above.push_back(rel);
        }
    }
    m_mutex.unlock();
}
开发者ID:apoddubn,项目名称:cprakt,代码行数:34,代码来源:HUDBase.cpp

示例2: applyPhysics

PhysicalObject* PhysicsSim::applyPhysics(SceneObject* object, Shape shape, float mass)
{
	PhysicalObject* phyObject;
	switch(shape)
	{
		case shSphere: phyObject = new Sphere(object, mass);
					break;

		case shBox: phyObject = new Box(object, mass);
					break;

		case shCapsule: phyObject = new Capsule(object, mass);
					break;

		case shCylinder: phyObject = new Cylinder(object, mass);
					break;

		case shCone: phyObject = new Cone(object, mass);
					break;

		case shConvexHull: phyObject = new ConvexHull(object, mass);
					break;

		case shTriMesh: phyObject = new TriMesh(object, mass);
					break;
	}

	objects_list.push_back(phyObject);
	dynamicsWorld->addRigidBody(phyObject->getRigidBody());

	updateObjects();

	return phyObject;
}
开发者ID:mikeiasNS,项目名称:SnowHero-irrlich-Game-,代码行数:34,代码来源:PhysicsSim.cpp

示例3: while

/** Update the world and the track.
 *  \param dt Time step size. 
 */
void ThreeStrikesBattle::update(float dt)
{
    WorldWithRank::update(dt);
    WorldWithRank::updateTrack(dt);
    
    core::vector3df tire_offset;
    std::string tire;
    float scale = 0.5f;
    float radius = 0.5f;
    PhysicalObject::bodyTypes tire_model;

    // insert blown away tire(s) now if was requested
    while (m_insert_tire > 0)
    {        
        if(m_insert_tire == 1)
        {
            tire_offset = core::vector3df(0.0f, 0.0f, 0.0f);
            tire = file_manager->getModelFile("tire.b3d");
            scale = 0.5f;
            radius = 0.5f;
            tire_model = PhysicalObject::MP_CYLINDER_Y;
        }
        else
        {
            scale = 1.0f;
            tire_model = PhysicalObject::MP_CYLINDER_X;
            radius = m_tire_radius[m_insert_tire-2];
            tire_offset = m_tire_offsets[m_insert_tire-2];
            if     (m_insert_tire == 2)
                tire = m_tire_dir+"/wheel-rear-left.b3d";
            else if(m_insert_tire == 3)
                tire = m_tire_dir+"/wheel-front-left.b3d";
            else if(m_insert_tire == 4)
                tire = m_tire_dir+"/wheel-front-right.b3d";
            else if(m_insert_tire == 5)
                tire = m_tire_dir+"/wheel-rear-right.b3d";
        }

        TrackObjectManager* tom = m_track->getTrackObjectManager();        
        PhysicalObject* obj = 
            tom->insertObject(tire,
                              tire_model,
                              15 /* mass */,
                              radius /* radius */,
                              core::vector3df(800.0f,0,m_tire_rotation 
                                                      / M_PI * 180 + 180) ,
                              m_tire_position + tire_offset,
                              core::vector3df(scale,scale,scale) /* scale */);
        
        // FIXME: orient the force relative to kart orientation
        obj->getBody()->applyCentralForce(btVector3(60.0f, 0.0f, 0.0f));

        m_insert_tire--;
        if(m_insert_tire == 1)
            m_insert_tire = 0;
        
        m_tires.push_back(obj);
    }
}   // update
开发者ID:langresser,项目名称:stk,代码行数:62,代码来源:three_strikes_battle.cpp

示例4: InternalMessage

    void Laser::fire()
    {
      InternalMessage("Model","entering fire") ;

      // handle firing rate
      if (m_time_to_fire.Second() > 0)
        return ;

      Positioned* positioned = getObject()->getParent<Positioned>() ;
      Oriented* oriented = getObject()->getParent<Oriented>() ;
      PhysicalObject* object = getObject()->getParent<PhysicalObject>() ;
      PhysicalWorld* world = object ? object->getObject()->getAncestor<PhysicalWorld>() : NULL ;

      if (world && positioned && oriented)
      {
        InternalMessage("Model","firing") ;
        // create a laser beam object
        Kernel::Object* beam = world->getObject()->createObject() ;

        // should apply local rotation to have correct local position..
        Orientation orientation_of_laser = oriented->getOrientation(world->getObject()) ;

        Position position_of_the_beam =
          positioned->getPosition(world->getObject()) + m_out_position*orientation_of_laser ;

        beam->addTrait(new Positioned(position_of_the_beam)) ;

        Orientation orientation_of_the_beam =
          orientation_of_laser*m_out_orientation ;

        beam->addTrait(new Oriented(orientation_of_the_beam)) ;

        // orientation gives speed vector
        // basic_speed(full Z oriented) * orientation
        Speed speed = Speed::MeterPerSecond(0,0,-getLaserSpeedMeterPerSecond())*orientation_of_the_beam ;

        // maybe we should add the object speed ?? (i.e. the speed of the ship)

        beam->addTrait(new Mobile(speed)) ;
        beam->addTrait(new Massive(Mass(m_laser_beam_energy,speed))) ;

        beam->addTrait(new LaserBeam(object->getObject(),m_beam_length,m_beam_radius)) ;
        beam->addTrait(new WithLifetime(getLaserBeamLifeDuration())) ;

        // shot
        Kernel::Object* shot = world->getObject()->createObject() ;
        shot->addTrait(new Positioned(position_of_the_beam)) ;
        shot->addTrait(new Shot()) ;

        // re-init timer
        m_time_to_fire = m_time_between_shots ;
        // done

      }
      // else : not much sense thus do nothing
      InternalMessage("Model","leaving fire") ;
    }
开发者ID:BackupTheBerlios,项目名称:projet-univers-svn,代码行数:57,代码来源:laser.cpp

示例5: Render

		void PhysicalGroup::Render(float minX, float minY, float maxX, float maxY)
		{
			if(m_physicsHandler)
				m_physicsHandler->Render(minX, minY, maxX, maxY);
			else //- TODO: Determine if this is necessary -
			{
				for(vector<Group::Member *>::iterator it = m_members.begin(); it != m_members.end(); it++)
				{
					PhysicalObject *object = (PhysicalObject *)*it;
					object->Render();
				}
			}
		}
开发者ID:Boushi,项目名称:centhra-engine,代码行数:13,代码来源:PhysicalGroup.cpp

示例6: removeObject

void PhysicsSim::shootTestSphere()
{
	removeObject(testSphere);

	testSphere = loadSceneObject("lemon.dae");
	testSphere->setPosition(fpscam->getPosition());
	testSphere->setScale(Vector3D(2,2,2));
	PhysicalObject* phyObj = applyPhysics(testSphere, shSphere, 20);

	vector3df dir = fpscam->getTarget() - fpscam->getPosition();
	dir = 250*dir.normalize();
	phyObj->getRigidBody()->applyCentralImpulse(btVector3(dir.X, dir.Y, dir.Z));

}
开发者ID:mikeiasNS,项目名称:SnowHero-irrlich-Game-,代码行数:14,代码来源:PhysicsSim.cpp

示例7: collided

    const SUCCESS PhysicalObject::collided(PhysicalObject &object, const Radians angle)
    {
        Vector initVec(getVelocity()-object.getVelocity());
        Mag_t<double> initVel(initVec.mag());
        Radians initTheta(initVec.theta());
        
		if(fabs(getX(initVel, initTheta-angle)) < REST_THRESHOLD)
        {
			setVelocity(getVelocity()+initVec/2.0);
			object.setVelocity(object.getVelocity()-initVec/2.0);
            antigravitate(object);
            object.antigravitate(*this);
			return SUCCEEDED;
		}
		
        // Frame of reference with the object at rest with this approaching it with an angle of 0
        Point<double> p2(Vector(Mag_t<double>(2.0*getMass()*getX(initVel, initTheta-angle)/(getMass()+object.getMass())), initTheta-angle));  // Gets the velocity of 2 based on elastic collision equation
        Point<double> p1((initVel*getMass()-p2.x()*object.getMass())/getMass(), -p2.y()*object.getMass()/getMass());   // Gets the velocity of 1 based off of elastic collision rulez
        
        if(fabs(p1.x()) < REST_THRESHOLD && fabs(p2.x()) < REST_THRESHOLD)
        {
            p1.x(0.0);
            p2.x(0.0);
        }
        
        Vector v1(p1);
        Vector v2(p2);
        
        v1.theta(-v1.theta()+initTheta);
        v2.theta(angle);
        
        v1 += object.getVelocity();
        v2 += object.getVelocity();
        
        Point<double> dif(object.getPosition()-*position);
        while(getCollider()->collides(*object.getCollider()))
            acceleration.set(*position-dif/pythagoras<double>(dif));
        
        setVelocity(v1);
        object.setVelocity(v2);
        
        return SUCCEEDED;
    }
开发者ID:JERlabs,项目名称:JERonimo,代码行数:43,代码来源:PhysicalObject.cpp

示例8: checkCollision

 const SUCCESS StaticObject::checkCollision(PhysicalObject &object)
 {
     if(getCollider() == NULL || object.getCollider() == NULL)
     {
         return SUCCEEDED;
     }
     else
     {
         Radians angle;
         if(getCollider()->canCollide(object.getCollider()->getType()))
             if(getCollider()->collides(*object.getCollider(), &angle))
                 return collided(object, angle);   // this ensures that object collider is called by this collided function, likewise a derived class needs to make sure its own derived collided function is called
             else
                  return SUCCEEDED;
         else if(object.getCollider()->canCollide(getCollider()->getType()))
             if(object.getCollider()->collides(*getCollider(), &angle))
                  return collided(object, angle);
             else
                  return SUCCEEDED;
         else
              return FAILED;
     }
 }
开发者ID:JERlabs,项目名称:JERonimo,代码行数:23,代码来源:StaticObject.cpp

示例9: collided

 const SUCCESS StaticObject::collided(PhysicalObject &object, const Radians angle)
 {
     Vector v(object.getVelocity());
     v.theta() -= angle;
     Point<double> appliedMomentum(v);
     if(fabs(appliedMomentum.x()) < REST_THRESHOLD)
     {
         appliedMomentum.x(0);
     }
     appliedMomentum.x() *= -1;
     v = appliedMomentum;
     v.theta() += angle;
     object.setVelocity(v);
     
     Point<double> dif(getPosition()-object.getPosition());
     while(getCollider()->collides(*object.getCollider()))
         object.setPosition(object.getPosition()-dif/pythagoras<double>(dif));
     
     return SUCCEEDED;
 }
开发者ID:JERlabs,项目名称:JERonimo,代码行数:20,代码来源:StaticObject.cpp

示例10: gInput

void HumanMovementPlugin::Refresh(const float &fDeltaTime)
{
    if (m_vControlledObjects.size() > 0)
    {
        int			dwAlphaInput			= gInput()->GetKeyboardAlphaFlags();

        VECTOR3 vVelocity;

        if (dwAlphaInput & INPUT_CHAR_W)
        {
            vVelocity.y				+= 1.0f;
        }

        if (dwAlphaInput & INPUT_CHAR_S)
        {
            vVelocity.y				-= 1.0f;
        }

        if (dwAlphaInput & INPUT_CHAR_D)
        {
            vVelocity.x				+= 1.0f;
        }

        if (dwAlphaInput & INPUT_CHAR_A)
        {
            vVelocity.x				-= 1.0f;
        }

        float	fMagnitudeSquared	= MagnitudeSquaredVECTOR3(vVelocity);
        bool	bNoChange			= false;

        if (fMagnitudeSquared > 0.0f)
        {
            NormalizeVECTOR3(vVelocity);

            vVelocity.x		*= m_fSpeed;
            vVelocity.y		*= m_fSpeed;
            vVelocity.z		*= m_fSpeed;
        }
        else if (fMagnitudeSquared == 0.0f)
        {
            bNoChange		= true;
        }

        vector<PhysicalObject *>::iterator			iter;
        PhysicalObject								*pPhysObject			= 0;
        for (iter = m_vControlledObjects.begin(); iter != m_vControlledObjects.end(); iter++)
        {
            pPhysObject = *iter;
            if (pPhysObject)
            {
                if (bNoChange)
                {
                    vVelocity.x *= 0.0f;
                    vVelocity.y *= 0.0f;
                    vVelocity.z *= 0.0f;
                }

                pPhysObject->SetVelocity(vVelocity);
            }
        }
    }
}
开发者ID:scottrick,项目名称:dgame,代码行数:63,代码来源:HumanMovementPlugin.cpp

示例11: MenuMode

void MapMode::_UpdateExplore()
{
    // First go to menu mode if the user requested it
    if(_menu_enabled && InputManager->MenuPress()) {
        MenuMode *MM = new MenuMode();
        ModeManager->Push(MM);
        return;
    }

    // Only update the status effect supervisor in Exploration mode
    // and if they are allowed.
    if (_status_effects_enabled)
        _status_effect_supervisor.UpdateEffects();

    // Update the running state of the camera object. Check if the character is running and if so,
    // update the stamina value if the operation is permitted
    _camera->is_running = false;
    if(_camera->moved_position && !_running_disabled && InputManager->CancelState() &&
            (InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState())) {
        if(_unlimited_stamina) {
            _camera->is_running = true;
        } else if(_run_stamina > SystemManager->GetUpdateTime() * 2) {
            _run_stamina -= (SystemManager->GetUpdateTime() * 2);
            _camera->is_running = true;
        } else {
            _run_stamina = 0;
        }
    }
    // Regenerate the stamina at 1/2 the consumption rate
    else if(_run_stamina < 10000) {
        _run_stamina += SystemManager->GetUpdateTime();
        if(_run_stamina > 10000)
            _run_stamina = 10000;
    }

    // If the user requested a confirm event, check if there is a nearby object that the player may interact with
    // Interactions are currently limited to dialogue with sprites and opening of treasures
    if(InputManager->ConfirmPress()) {
        MapObject *obj = _object_supervisor->FindNearestInteractionObject(_camera);

        if(obj != NULL) {
            if(obj->GetType() == PHYSICAL_TYPE) {
                PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(obj);

                if(!phs->GetEventIdWhenTalking().empty()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    if (!_event_supervisor->IsEventActive(phs->GetEventIdWhenTalking()))
                        _event_supervisor->StartEvent(phs->GetEventIdWhenTalking());
                    return;
                }
            }
            else if(obj->GetType() == SPRITE_TYPE) {
                MapSprite *sp = reinterpret_cast<MapSprite *>(obj);

                if(sp->HasAvailableDialogue()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    sp->InitiateDialogue();
                    return;
                }
            } else if(obj->GetType() == TREASURE_TYPE) {
                TreasureObject *treasure_object = reinterpret_cast<TreasureObject *>(obj);

                if(!treasure_object->GetTreasure()->IsTaken()) {
                    _camera->moving = false;
                    treasure_object->Open();
                }
            } else if(obj->GetType() == SAVE_TYPE && _save_points_enabled) {
                // Make sure the character will be centered in the save point
                SaveMode *save_mode = new SaveMode(true, obj->GetXPosition(), obj->GetYPosition() - 1.0f);
                ModeManager->Push(save_mode, false, false);
            }
        }
    }

    // Detect movement input from the user
    if(InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState()) {
        _camera->moving = true;
    } else {
        _camera->moving = false;
    }

    // Determine the direction of movement. Priority of movement is given to: up, down, left, right.
    // In the case of diagonal movement, the direction that the sprite should face also needs to be deduced.
    if(_camera->moving == true) {
        if(InputManager->UpState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_NORTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_NORTHEAST);
            else
                _camera->SetDirection(NORTH);
        } else if(InputManager->DownState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_SOUTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_SOUTHEAST);
            else
                _camera->SetDirection(SOUTH);
//.........这里部分代码省略.........
开发者ID:akien-mga,项目名称:ValyriaTear,代码行数:101,代码来源:map_mode.cpp

示例12: PROFILER_PUSH_CPU_MARKER

/** Updates the physics simulation and handles all collisions.
 *  \param dt Time step.
 */
void Physics::update(float dt)
{
    PROFILER_PUSH_CPU_MARKER("Physics", 0, 0, 0);

    m_physics_loop_active = true;
    // Bullet can report the same collision more than once (up to 4
    // contact points per collision). Additionally, more than one internal
    // substep might be taken, resulting in potentially even more
    // duplicates. To handle this, all collisions (i.e. pair of objects)
    // are stored in a vector, but only one entry per collision pair
    // of objects.
    m_all_collisions.clear();

    // Maximum of three substeps. This will work for framerate down to
    // 20 FPS (bullet default frequency is 60 HZ).
    m_dynamics_world->stepSimulation(dt, 3);

    // Now handle the actual collision. Note: flyables can not be removed
    // inside of this loop, since the same flyables might hit more than one
    // other object. So only a flag is set in the flyables, the actual
    // clean up is then done later in the projectile manager.
    std::vector<CollisionPair>::iterator p;
    for(p=m_all_collisions.begin(); p!=m_all_collisions.end(); ++p)
    {
        // Kart-kart collision
        // --------------------
        if(p->getUserPointer(0)->is(UserPointer::UP_KART))
        {
            KartKartCollision(p->getUserPointer(0)->getPointerKart(),
                              p->getContactPointCS(0),
                              p->getUserPointer(1)->getPointerKart(),
                              p->getContactPointCS(1)                );
            continue;
        }  // if kart-kart collision

        if(p->getUserPointer(0)->is(UserPointer::UP_PHYSICAL_OBJECT))
        {
            // Kart hits physical object
            // -------------------------
            PhysicalObject *obj = p->getUserPointer(0)
                                   ->getPointerPhysicalObject();
            if(obj->isCrashReset())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                new RescueAnimation(kart);
            }
            else if (obj->isExplodeKartObject())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                ExplosionAnimation::create(kart);
            }
            else if (obj->isFlattenKartObject())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                const KartProperties* kp = kart->getKartProperties();
                kart->setSquash(kp->getSquashDuration(), kp->getSquashSlowdown());
            }
            else if(obj->isSoccerBall())
            {
                int kartId = p->getUserPointer(1)->getPointerKart()->getWorldKartId();
                SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
                soccerWorld->setLastKartTohitBall(kartId);
            }
            continue;
        }

        if(p->getUserPointer(0)->is(UserPointer::UP_ANIMATION))
        {
            // Kart hits animation
            ThreeDAnimation *anim=p->getUserPointer(0)->getPointerAnimation();
            if(anim->isCrashReset())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                new RescueAnimation(kart);
            }
            else if (anim->isExplodeKartObject())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                ExplosionAnimation::create(kart);
            }
            else if (anim->isFlattenKartObject())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                const KartProperties* kp = kart->getKartProperties();
                kart->setSquash(kp->getSquashDuration(), kp->getSquashSlowdown());
            }
            continue;

        }
        // now the first object must be a projectile
        // =========================================
        if(p->getUserPointer(1)->is(UserPointer::UP_TRACK))
        {
            // Projectile hits track
            // ---------------------
            p->getUserPointer(0)->getPointerFlyable()->hitTrack();
        }
//.........这里部分代码省略.........
开发者ID:Shreesha-S,项目名称:stk-code,代码行数:101,代码来源:physics.cpp

示例13: GetXPosition

void VirtualSprite::_SetNextPosition()
{

    // Next sprite's position holders
    float next_pos_x = GetXPosition();
    float next_pos_y = GetYPosition();
    float distance_moved = CalculateDistanceMoved();

    // Move the sprite the appropriate distance in the appropriate Y and X direction
    if(_direction & (NORTH | MOVING_NORTHWEST | MOVING_NORTHEAST))
        next_pos_y -= distance_moved;
    else if(_direction & (SOUTH | MOVING_SOUTHWEST | MOVING_SOUTHEAST))
        next_pos_y += distance_moved;
    if(_direction & (WEST | MOVING_NORTHWEST | MOVING_SOUTHWEST))
        next_pos_x -= distance_moved;
    else if(_direction & (EAST | MOVING_NORTHEAST | MOVING_SOUTHEAST))
        next_pos_x += distance_moved;

    // When not moving, do not check anything else.
    if(next_pos_x == GetXPosition() && next_pos_y == GetYPosition())
        return;

    // We've got the next position, let's check whether the next position
    // should be revised.

    // Used to know whether we could fall back to a straight move
    // in case of collision.
    bool moving_diagonally = (_direction & (MOVING_NORTHWEST | MOVING_NORTHEAST
                                           | MOVING_SOUTHEAST | MOVING_SOUTHWEST));

    // Handle collision with the first object encountered
    MapObject* collision_object = nullptr;
    MapMode* map_mode = MapMode::CurrentInstance();
    ObjectSupervisor* object_supervisor = map_mode->GetObjectSupervisor();
    COLLISION_TYPE collision_type = object_supervisor->DetectCollision(this, next_pos_x,
                     next_pos_y,
                     &collision_object);
    // Try to fall back to straight direction
    if(moving_diagonally && collision_type != NO_COLLISION) {
        // Try on x axis
        if(object_supervisor->DetectCollision(this, _tile_position.x, next_pos_y, &collision_object) == NO_COLLISION) {
            next_pos_x = _tile_position.x;
            collision_type = NO_COLLISION;
        } // and then on y axis
        else if(object_supervisor->DetectCollision(this, next_pos_x, _tile_position.y, &collision_object) == NO_COLLISION) {
            next_pos_y = _tile_position.y;
            collision_type = NO_COLLISION;
        }
    }

    // Handles special collision handling first
    if(_control_event) {
        switch(_control_event->GetEventType()) {
            // Don't stuck the player's character or a sprite being controlled by a prepared path.
            // Plus, it's better not to change a path with encountered beings once started
            // for simplification purpose.
        case PATH_MOVE_SPRITE_EVENT:
            collision_type = NO_COLLISION;
            break;
            // Change the direction whenever something blocking is in the way.
        case RANDOM_MOVE_SPRITE_EVENT:
            if(collision_type != NO_COLLISION) {
                SetRandomDirection();
                return;
            }
        default:
            break;
        }
    }

    // Try to handle wall and physical collisions after a failed straight or diagonal move
    switch(collision_type) {
    case NO_COLLISION:
    default:
        break;
    case WALL_COLLISION:
        // When being blocked and moving diagonally, the npc is stuck.
        if(moving_diagonally)
            return;

        // Don't consider physical objects with an event to avoid sliding on their edges,
        // making them harder to "talk with".
        if (collision_object && this == map_mode->GetCamera()) {
            PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(collision_object);
            if(phs && !phs->GetEventIdWhenTalking().empty())
                return;
        }

        // Fix the direction and destination to walk-around obstacles
        if (_HandleWallEdges(next_pos_x, next_pos_y, distance_moved, collision_object))
            break;
        // We don't do any other checks for the player sprite.
        else if (this == map_mode->GetCamera())
            return;

        // NPC sprites:

        // When it's a true wall, try against the collision grid
        if(!collision_object) {
            // Try a random diagonal to avoid the wall in straight direction
//.........这里部分代码省略.........
开发者ID:ValyriaTear,项目名称:ValyriaTear,代码行数:101,代码来源:map_virtual_sprite.cpp

示例14: PROFILER_PUSH_CPU_MARKER

/** Updates the physics simulation and handles all collisions.
 *  \param dt Time step.
 */
void Physics::update(float dt)
{
    PROFILER_PUSH_CPU_MARKER("Physics", 0, 0, 0);

    m_physics_loop_active = true;
    // Bullet can report the same collision more than once (up to 4
    // contact points per collision). Additionally, more than one internal
    // substep might be taken, resulting in potentially even more
    // duplicates. To handle this, all collisions (i.e. pair of objects)
    // are stored in a vector, but only one entry per collision pair
    // of objects.
    m_all_collisions.clear();

    // Maximum of three substeps. This will work for framerate down to
    // 20 FPS (bullet default frequency is 60 HZ).
    m_dynamics_world->stepSimulation(dt, 3);

    // Now handle the actual collision. Note: flyables can not be removed
    // inside of this loop, since the same flyables might hit more than one
    // other object. So only a flag is set in the flyables, the actual
    // clean up is then done later in the projectile manager.
    std::vector<CollisionPair>::iterator p;
    for(p=m_all_collisions.begin(); p!=m_all_collisions.end(); ++p)
    {
        // Kart-kart collision
        // --------------------
        if(p->getUserPointer(0)->is(UserPointer::UP_KART))
        {
            KartKartCollision(p->getUserPointer(0)->getPointerKart(),
                              p->getContactPointCS(0),
                              p->getUserPointer(1)->getPointerKart(),
                              p->getContactPointCS(1)                );
            Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
            int kartid1 = p->getUserPointer(0)->getPointerKart()->getWorldKartId();
            int kartid2 = p->getUserPointer(1)->getPointerKart()->getWorldKartId();
            script_engine->runFunction("void onKartKartCollision(int, int)",
                [=](asIScriptContext* ctx) {
                    ctx->SetArgDWord(0, kartid1);
                    ctx->SetArgDWord(1, kartid2);
                });
            continue;
        }  // if kart-kart collision

        if(p->getUserPointer(0)->is(UserPointer::UP_PHYSICAL_OBJECT))
        {
            // Kart hits physical object
            // -------------------------
            Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
            AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
            int kartId = kart->getWorldKartId();
            PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject();
            std::string obj_id = obj->getID();
            std::string scripting_function = obj->getOnKartCollisionFunction();
            if (scripting_function.size() > 0)
            {
                script_engine->runFunction("void " + scripting_function + "(int, const string)",
                    [&](asIScriptContext* ctx) {
                        ctx->SetArgDWord(0, kartId);
                        ctx->SetArgObject(1, &obj_id);
                    });
            }
            if (obj->isCrashReset())
            {
                new RescueAnimation(kart);
            }
            else if (obj->isExplodeKartObject())
            {
                ExplosionAnimation::create(kart);
            }
            else if (obj->isFlattenKartObject())
            {
                const KartProperties* kp = kart->getKartProperties();
                kart->setSquash(kp->getSquashDuration() * kart->getPlayerDifficulty()->getSquashDuration(),
                    kp->getSquashSlowdown() * kart->getPlayerDifficulty()->getSquashSlowdown());
            }
            else if(obj->isSoccerBall() && 
                    race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
            {
                SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
                soccerWorld->setLastKartTohitBall(kartId);
            }
            continue;
        }

        if (p->getUserPointer(0)->is(UserPointer::UP_ANIMATION))
        {
            // Kart hits animation
            ThreeDAnimation *anim=p->getUserPointer(0)->getPointerAnimation();
            if(anim->isCrashReset())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                new RescueAnimation(kart);
            }
            else if (anim->isExplodeKartObject())
            {
                AbstractKart *kart = p->getUserPointer(1)->getPointerKart();
                ExplosionAnimation::create(kart);
//.........这里部分代码省略.........
开发者ID:droidterry,项目名称:stk-code,代码行数:101,代码来源:physics.cpp

示例15: EnkiPlayground

	EnkiPlayground(World *world, QWidget *parent = 0) :
		ViewerWidget(world, parent),
		subjectiveView(false)
	{
		#define PROBLEM_GENERIC_TOY
		#define PROBLEM_BALL_LINE
		//#define PROBLEM_LONE_EPUCK
		
		#ifdef PROBLEM_GENERIC_TOY
		{
			const double amount = 9;
			const double radius = 5;
			const double height = 20;
			Polygone p;
			for (double a = 0; a < 2*M_PI; a += 2*M_PI/amount)
				p.push_back(Point(radius * cos(a), radius * sin(a)));
			
			PhysicalObject* o = new PhysicalObject;
			PhysicalObject::Hull hull(Enki::PhysicalObject::Part(p, height));
			o->setCustomHull(hull, -1);
			o->setColor(Color(0.4,0.6,0.8));
			o->pos = Point(100, 100);
			world->addObject(o);
		}
		
		for (int i = 0; i < 20; i++)
		{
			PhysicalObject* o = new PhysicalObject;
			o->pos = Point(UniformRand(20, 100)(), UniformRand(20, 100)());
			o->setCylindric(1, 1, 10);
			o->setColor(Color(0.9, 0.2, 0.2));
			o->dryFrictionCoefficient = 0.01;
			world->addObject(o);
		}
		
		Polygone p2;
		p2.push_back(Point(5,1));
		p2.push_back(Point(-5,1));
		p2.push_back(Point(-5,-1));
		p2.push_back(Point(5,-1));
		for (int i = 0; i < 5; i++)
		{
			PhysicalObject* o = new PhysicalObject;
			PhysicalObject::Hull hull(Enki::PhysicalObject::Part(p2, 3));
			o->setCustomHull(hull, 30);
			o->setColor(Color(0.2, 0.1, 0.6));
			o->collisionElasticity = 0.2;
			o->pos = Point(UniformRand(20, 100)(), UniformRand(20, 100)());
			world->addObject(o);
		}
		
		// cross shape
		{
			PhysicalObject* o = new PhysicalObject;
			PhysicalObject::Hull hull;
			hull.push_back(Enki::PhysicalObject::Part(Polygone() << Point(5,1) << Point(-5,1) << Point(-5,-1) << Point(5,-1), 2));
			hull.push_back(Enki::PhysicalObject::Part(Polygone() << Point(1,5) << Point(-1,5) << Point(-1,-5) << Point(1,-5), 4));
			o->setCustomHull(hull, 60);
			o->setColor(Color(0.2, 0.4, 0.6));
			o->collisionElasticity = 0.2;
			o->pos = Point(UniformRand(20, 100)(), UniformRand(20, 100)());
			world->addObject(o);
		}
		#endif // PROBLEM_GENERIC_TOY
		
		#ifdef PROBLEM_BALL_LINE
		for (double d = 40; d < 60; d += 8)
		{
			PhysicalObject* o = new PhysicalObject;
			o->pos = Point(d, 20);
			o->setCylindric(4, 2, 10);
			o->setColor(Color(0.2, 0.2, 0.6));
			o->dryFrictionCoefficient = 0.;
			world->addObject(o);
		}
		#endif // PROBLEM_BALL_LINE
		
		#ifdef PROBLEM_LONE_EPUCK
		addDefaultsRobots(world);
		#endif // PROBLEM_LONE_EPUCK
		
		Marxbot *marxbot = new Marxbot;
		marxbot->pos = Point(60, 50);
		marxbot->leftSpeed = 8;
		marxbot->rightSpeed = 2;
		world->addObject(marxbot);
		
		#ifdef USE_SDL
		if((SDL_Init(SDL_INIT_JOYSTICK)==-1))
		{
			cerr << "Error : Could not initialize SDL: " << SDL_GetError() << endl;
			addDefaultsRobots(world);
			return;
		}
		
		int joystickCount = SDL_NumJoysticks();
		for (int i = 0; i < joystickCount; ++i)
		{
			SDL_Joystick* joystick = SDL_JoystickOpen(i);
			if (!joystick)
//.........这里部分代码省略.........
开发者ID:plsm,项目名称:enki,代码行数:101,代码来源:Playground.cpp


注:本文中的PhysicalObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。