コード例 #1
0
ファイル: Collidable.cpp プロジェクト: Burnsidious/FSGDEngine
    void BoundingVolume::GetSplitAxis(const float *pointsPtr, unsigned int numPoints, 
		Float3 &splitAxis, float &_min, float &_max)
    {
        Float3 vMin( FLT_MAX, FLT_MAX, FLT_MAX );
        Float3 vMax( -FLT_MAX, -FLT_MAX, -FLT_MAX );

        for(unsigned int i = 0; i < numPoints; i +=3 )
            for(unsigned int j = 0; j < 3; ++j)
            {
                vMin.v[j] = min( vMin.v[j], pointsPtr[i+j] );
                vMax.v[j] = max( vMax.v[j], pointsPtr[i+j] );
            }

            unsigned int axis = 0;
            if( vMax.v[axis] - vMin.v[axis] < vMax.v[1] - vMin.v[1] )
                axis = 1;
            if( vMax.v[axis] - vMin.v[axis] < vMax.v[2] - vMin.v[2] )
                axis = 2;

            splitAxis.makeZero();
            splitAxis.v[axis] = 1.0f;

            _min = vMin.v[axis];
            _max = vMax.v[axis];
    }
コード例 #2
0
ファイル: Physics.cpp プロジェクト: Burnsidious/FSGDEngine
	void Physics::OnApplyReaction(IBehavior* invokingBehavior, IMessage* message)
	{
		Physics* pPhysics = (Physics*)invokingBehavior;
		MessageT<CollisionContact>* msg = (MessageT<CollisionContact>*)message;
	
		Float3 velocity = pPhysics->m_X[0] - pPhysics->m_OldX[0];
		
		velocity += msg->value.m_ContactNormal * msg->value.m_PenetrationDepth;

		float ndotv = DotProduct( msg->value.m_ContactNormal, velocity );
		Float3 normalVelocity = msg->value.m_ContactNormal * ndotv;
		Float3 tangentialVelocity = velocity - normalVelocity;
		Float3 oldTV = tangentialVelocity;

		float m_COF = 0.0f;
		float m_COR = 0.0f;

		float tvMagSq = DotProduct(tangentialVelocity, tangentialVelocity);
		if( tvMagSq > 0.0f )
		{
			float tvMag = sqrt(tvMagSq);
			tangentialVelocity *= (1.0f / tvMag);
			Float3 tvNorm = tangentialVelocity;
			tangentialVelocity *= max( 0.0f, tvMag - msg->value.m_PenetrationDepth*m_COF);				
		}
		else
			tangentialVelocity.makeZero();

		pPhysics->gameObject->TranslateGlobal( velocity );
		pPhysics->m_X[0] = pPhysics->m_OldX[0] + velocity;
		pPhysics->m_OldX[0] = pPhysics->m_X[0] - tangentialVelocity - normalVelocity * m_COR;

		//pPhysics->m_OldX[0] += (oldTV - tangentialVelocity);
		//pPhysics->m_OldX[0] = pPhysics->m_X[0] - tangentialVelocity - normalVelocity;
		//pPhysics->m_OldX[0] -= normalVelocity;
	}