예제 #1
0
파일: HUDBase.cpp 프로젝트: apoddubn/cprakt
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();
}
예제 #2
0
 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;
 }
예제 #3
0
    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;
    }
예제 #4
0
 void PhysicalObject::antigravitate(const PhysicalObject &other)
 {
     Vector distance(getPosition()-other.getPosition());
     force(Vector(Mag_t<double>(Mass::GetGravityForce(getMass(), other.getMass(), distance.mag())/getMass()), distance.theta()));
 }