Beispiel #1
0
vec Line::ClosestPoint(const Ray &other, float &d, float &d2) const
{
    ClosestPointLineLine(pos, dir, other.pos, other.dir, d, d2);
    if (d2 >= 0.f)
        return GetPoint(d);
    else
    {
        d2 = 0.f;
        return ClosestPoint(other.pos, d);
    }
}
Beispiel #2
0
vec Line::ClosestPoint(const LineSegment &other, float &d, float &d2) const
{
    ClosestPointLineLine(pos, dir, other.a, other.b - other.a, d, d2);
    if (d2 < 0.f)
    {
        d2 = 0.f;
        return ClosestPoint(other.a, d);
    }
    else if (d2 > 1.f)
    {
        d2 = 1.f;
        return ClosestPoint(other.b, d);
    }
    else
        return GetPoint(d);
}
Beispiel #3
0
vec Line::ClosestPoint(const Ray &other, float *d, float *d2) const
{
	float t2;
	vec closestPoint = ClosestPointLineLine(pos, pos + dir, other.pos, other.pos + other.dir, d, &t2);
	if (t2 <= 0.f)
	{
		if (d2)
			*d2 = 0.f;
		return ClosestPoint(other.pos, d);
	}
	else
	{
		if (d2)
			*d2 = t2;
		return closestPoint;
	}
}
Beispiel #4
0
vec Line::ClosestPoint(const LineSegment &other, float *d, float *d2) const
{
	float t2;
	vec closestPoint = ClosestPointLineLine(pos, pos + dir, other.a, other.b, d, &t2);
	if (t2 <= 0.f)
	{
		if (d2)
			*d2 = 0.f;
		return ClosestPoint(other.a, d);
	}
	else if (t2 >= 1.f)
	{
		if (d2)
			*d2 = 1.f;
		return ClosestPoint(other.b, d);
	}
	else
	{
		if (d2)
			*d2 = t2;
		return closestPoint;
	}
}
Beispiel #5
0
void CCollisionManager::CalculateHitPoint(  CCube* cube1, 
                                          CCube* cube2,
                                          const float penetration,
                                          vec3 &hitNormal,
                                          vector<vec3> &hitPoints,
                                          int &numHitPoints )
{
   vec3 verts0[8];
	int vertIndex0[8];
	vec3 norm0 = hitNormal;
	int numVerts0 = GetNumHitPoints( cube1,
									 norm0,
									 penetration,
									 verts0,
									 vertIndex0);

	vec3 verts1[8];
	int vertIndex1[8];
	vec3 norm1 = -hitNormal;
	int numVerts1 = GetNumHitPoints( cube2,
									 norm1,
									 penetration,
									 verts1,
									 vertIndex1);

	// This should never really happen!
	if (numVerts0==0 || numVerts1==0)
	{
		return;
	}


	int numVertsX		= numVerts0;
	vec3* vertsX  = verts0;

	if (numVerts0>=4 && numVerts1>=4)
	{
		static vec3 clipVerts[50];
		
		ClipFaceFaceVerts(	verts0, vertIndex0, 
							verts1, vertIndex1,
							clipVerts, &numVertsX);

		vertsX = clipVerts;
	}
	

	{
		if (numVerts1 < numVerts0)
		{
			numVertsX = numVerts1;
			vertsX    = verts1;
			hitNormal = -norm1;
		}

		if (numVerts1==2 && numVerts0==2)
		{
			static vec3 V[2];
			static int numV = 0;

			ClosestPointLineLine(verts0,
								 verts1,
								 V,		numV);

			vertsX = V;
			numVertsX = numV;
		}

		if (numVerts0==2 && numVerts1==4)
		{
			ClipLinePlane(	verts0,		vertIndex0,  cube1,
							verts1,		vertIndex1,  cube2,
							vertsX,		numVertsX);
		}

		if (numVerts0==4 && numVerts1==2)
		{
			ClipLinePlane(	verts1,		vertIndex1,   cube1,
							verts0,		vertIndex0,   cube2,
							vertsX,		numVertsX);
		}

		numHitPoints = numVertsX;
		for (int i=0; i<numVertsX; i++)
		{
         hitPoints.push_back( vertsX[i] );
		}
	}
}
Beispiel #6
0
vec Line::ClosestPoint(const Line &other, float &d, float &d2) const
{
    ClosestPointLineLine(pos, dir, other.pos, other.dir, d, d2);
    return GetPoint(d);
}
Beispiel #7
0
vec Line::ClosestPoint(const Line &other, float *d, float *d2) const
{
	return ClosestPointLineLine(pos, pos + dir, other.pos, other.pos + other.dir, d, d2);
}