void CRigidBody::HandlePushCollision(CCollisionMessage* ColMsg)
{
	CVehicle* Car = (CVehicle*)ColMsg->GetEntity();


	CLog::GetLog().Write(LOG_MISC, "In HandlePushCollision()");

	/***************** First, findout how hard Car was hit **************/
	float force = ColMsg->GetPushForce()->Length();

	//CLog::GetLog().Write(LOG_MISC, "force = %f", force);

	Vector3f Direction = (*ColMsg->GetNormal())*force;

	CLog::GetLog().Write(LOG_MISC, "\n\n\nforce = %f", force);
	CLog::GetLog().Write(LOG_MISC, "Direction = (%f, %f, %f)",
		Direction.X(), Direction.Y(), Direction.Z());

	/***************** Next, findout where along body Car was hit *********/
	float where; 
	Rectangle3f Rect = *ColMsg->GetPlane();
	Vector3f ColPoint = *ColMsg->GetColPoint();
	Plane3f P1 = Plane3f(Rect.Edge0(), Rect.Origin());
	where = P1.DistanceTo(ColPoint)/Rect.Edge0().Length();
	// So where = [1,0]. 0 - at origin, 1 - opposite origin

}
int FrustumContainsSphere( CD3DCamera * pCamera, Sphere3f pSphere)
{
   	// various distances
	float fDistance;

    //$$$TEMP get the frustum planes from the camera's CULLINFO
    Plane3f plane[6];
    CULLINFO *cInfo = pCamera->GetCullInfo();
    for (int j=0; j<6; j++)  {
        plane[j] = Plane3f( Vector3f(cInfo->planeFrustum[j].a,  cInfo->planeFrustum[j].b,  cInfo->planeFrustum[j].c), cInfo->planeFrustum[j].d);
    }


	// calculate our distances to each of the planes
	for(int i = 0; i < 6; ++i) {

		// find the distance to this plane
		//fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i].GetNormal().Length();
        //fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i].DistanceTo(pSphere.Center());
        fDistance = plane[i].GetNormal().Dot(pSphere.Center()) + plane[i][3];

		// if this distance is < -sphere.radius, we are outside
		if(fDistance < -pSphere.Radius())
			return(OUTSIDE);

		// else if the distance is between +- radius, then we intersect
		if((float)fabs(fDistance) < pSphere.Radius())
			return(INTERSECT);
	}

	// otherwise we are fully in view
    return (INSIDE);
}
//----------------------------------------------------------------------------
void BouncingTetrahedra::CalculateNormal (const Vector3f* vertices,
    const Vector3f& closest, Contact& contact)
{
    float diff = Mathf::MAX_REAL;
    for (int i = 0; i < 4; ++i)
    {
        Plane3f plane = Plane3f(vertices[mFaces[i][0]],
            vertices[mFaces[i][1]], vertices[mFaces[i][2]]);

        float temp = Mathf::FAbs(plane.DistanceTo(closest));
        if (temp < diff)
        {
            contact.N = plane.Normal;
            diff = temp;
        }
    }
}
//----------------------------------------------------------------------------
void PointInPolyhedron::CreateQuery (TriMesh* mesh)
{
    const VertexBuffer* vbuffer = mesh->GetVertexBuffer();
    const int numVertices = vbuffer->GetNumElements();
    const Vector3f* vertices = (Vector3f*)vbuffer->GetData();

    const IndexBuffer* ibuffer = mesh->GetIndexBuffer();
    const int numIndices = ibuffer->GetNumElements();
    const int numFaces = numIndices/3;
    const int* indices = (int*)ibuffer->GetData();
    const int* currentIndex = indices;
    int i;

#ifdef TRIFACES
    mTFaces = new1<PointInPolyhedron3f::TriangleFace>(numFaces);

    for (i = 0; i < numFaces; ++i)
    {
        int v0 = *currentIndex++;
        int v1 = *currentIndex++;
        int v2 = *currentIndex++;

        mTFaces[i].Indices[0] = v0;
        mTFaces[i].Indices[1] = v1;
        mTFaces[i].Indices[2] = v2;
        mTFaces[i].Plane = Plane3f(vertices[v0], vertices[v1], vertices[v2]);
    }

    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mTFaces, mNumRays, mRayDirections);
#endif

#if defined(CVXFACES0) || defined(CVXFACES1) || defined(CVXFACES2)
    mCFaces = new1<PointInPolyhedron3f::ConvexFace>(numFaces);

    for (i = 0; i < numFaces; ++i)
    {
        int v0 = *currentIndex++;
        int v1 = *currentIndex++;
        int v2 = *currentIndex++;

        mCFaces[i].Indices.resize(3);
        mCFaces[i].Indices[0] = v0;
        mCFaces[i].Indices[1] = v1;
        mCFaces[i].Indices[2] = v2;
        mCFaces[i].Plane = Plane3f(vertices[v0], vertices[v1], vertices[v2]);
    }

#ifdef CVXFACES0
    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mCFaces, mNumRays, mRayDirections, 0);
#else
#ifdef CVXFACES1
    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mCFaces, mNumRays, mRayDirections, 1);
#else
    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mCFaces, mNumRays, mRayDirections, 2);
#endif
#endif
#endif

#if defined (SIMFACES0) || defined (SIMFACES1)
    mSFaces = new1<PointInPolyhedron3f::SimpleFace>(numFaces);

    for (i = 0; i < numFaces; ++i)
    {
        int v0 = *currentIndex++;
        int v1 = *currentIndex++;
        int v2 = *currentIndex++;

        mSFaces[i].Indices.resize(3);
        mSFaces[i].Indices[0] = v0;
        mSFaces[i].Indices[1] = v1;
        mSFaces[i].Indices[2] = v2;
        mSFaces[i].Plane = Plane3f(vertices[v0], vertices[v1], vertices[v2]);

        mSFaces[i].Triangles.resize(3);
        mSFaces[i].Triangles[0] = v0;
        mSFaces[i].Triangles[1] = v1;
        mSFaces[i].Triangles[2] = v2;
    }

#ifdef SIMFACES0
    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mSFaces, mNumRays, mRayDirections, 0);
#else
    mQuery = new0 PointInPolyhedron3f(numVertices, vertices, numFaces,
        mSFaces, mNumRays, mRayDirections, 1);
#endif
#endif
}
Example #5
0
// static
Plane3f Plane3f::XY()
{
	return Plane3f( 0, 0, 1, 0 );
}
Example #6
0
// static
Plane3f Plane3f::ZX()
{
	return Plane3f( 0, 1, 0, 0 );
}
Example #7
0
Plane3f Plane3f::offset( float z ) const
{
    return Plane3f( a, b, c, d - z * ( a + b + c ) );
}
Example #8
0
Plane3f Plane3f::flipped() const
{
    return Plane3f( -a, -b, -c, -d );
}
Example #9
0
// static
Plane3f Plane3f::YZ()
{
	return Plane3f( 1, 0, 0, 0 );
}