Exemplo n.º 1
0
bool PointInQuadSS( Vector3f *pQuad, const Vector3f p )
{
    return (SameSide( p, pQuad[2], pQuad[0], pQuad[1] ) && 
			SameSide( p, pQuad[3], pQuad[1], pQuad[2] ) &&
			SameSide( p, pQuad[0], pQuad[2], pQuad[3] ) && 
			SameSide( p, pQuad[1], pQuad[3], pQuad[0]) );
}
Exemplo n.º 2
0
bool
Triangle::is_point_in_polygon2(const Point &p)
{
    if (SameSide(p, *p1, *p2, *p3) && SameSide(p, *p2, *p1, *p3) && SameSide(p, *p3, *p1, *p2)) {
        return true;
    }
    return false;
}
bool IT_PointOnPolygon(D3DXVECTOR3 A, D3DXVECTOR3 B, D3DXVECTOR3 C, D3DXVECTOR3 P)
{
	if(SameSide(A,B, P,C) && 
		SameSide(A,C, P,B) &&
		SameSide(B,C, P,A) )
		return true;
	
	return false;
}
Exemplo n.º 4
0
void LineClipping_Clip(const struct LineClipping_Rectangle *r,
	struct LineClipping_Segment *s, 
	int *done)
{
	const int maxIter = 4;
	int outcode0, outcode1, i;
	double x, y;
	
	/*Cohen-Sutherland line clipping algorithm*/
	outcode0 = Outcode(s->x0, s->y0, r);
	outcode1 = Outcode(s->x1, s->y1, r);
	i = 0;
	while (! Inside(outcode0, outcode1) && ! SameSide(outcode0, outcode1) && (i < maxIter)) {
		if (outcode0 != 0) {
			GetIntersection(r, s, outcode0, &x, &y);
			s->x0 = x;
			s->y0 = y;
			outcode0 = Outcode(x, y, r);
		} else {
			GetIntersection(r, s, outcode1, &x, &y);
			s->x1 = x;
			s->y1 = y;
			outcode1 = Outcode(x, y, r);
		}
		i++;
	}
	assert(i < maxIter);
	*done = Inside(outcode0, outcode1);
}
Exemplo n.º 5
0
/*
 *	
		neBool found = false;

		f32 dist, ratio, factor, depth;

		neV3 contact;

		s32 i;

		for (i = 0; i < 3; i++)
		{
			if (!neIsConsiderZero(sensorA.dir[i]))
			{
				if (sensorA.dir[i] > 0.0f)
				{
					if (sensorA.pos[i] > -convexB.as.box.boxSize[i])
						continue;
		
					factor = 1.0f;
				}
				else
				{
					if (sensorA.pos[i] < convexB.as.box.boxSize[i])
						continue;

					factor = -1.0f;
				}
				dist = factor * (convexB.as.box.boxSize[i] - sensorA.pos[i]);

				assert(dist > 0.0f);

				if (dist > neAbs(sensorA.dir[i]))
					return;

				ratio = dist / neAbs(sensorA.dir[i]);

				contact = sensorA.pos + sensorA.dir * ratio;

				s32 other1, other2;

				other1 = (i + 1)%3;
				
				other2 = (i + 2)%3;

				if (contact[other1] >= convexB.as.box.boxSize[other1] || contact[other1] <= -convexB.as.box.boxSize[other1])
					continue;

				if (contact[other2] >= convexB.as.box.boxSize[other2] || contact[other2] <= -convexB.as.box.boxSize[other2])
					continue;

				found = true;

				depth = (1.0f - ratio) * sensorA.length;

				break;
			}
			else if (sensorA.pos[i] >= convexB.as.box.boxSize[i] || sensorA.pos[i] <= -convexB.as.box.boxSize[i])
			{
				return;
			}
		}
		if (found)
		{
			sensorA.depth = depth;

			sensorA.normal = transB.rot[i] * factor * -1.0f;

			sensorA.contactPoint = contact;

			sensorA.materialID = convexB.matIndex;
		}

 */
void SensorTest(neSensor_ & sensorA, TConvex & convexB, neT3 & transB)
{
	if (convexB.type == TConvex::BOX)
	{
		int nearDim = -1;
		int farDim = -1;

//	set Tnear = - infinity, Tfar = infinity
//	For each pair of planes P associated with X, Y, and Z do:
//	(example using X planes)
//	if direction Xd = 0 then the ray is parallel to the X planes, so
//	if origin Xo is not between the slabs ( Xo < Xl or Xo > Xh) then return false
//	else, if the ray is not parallel to the plane then
//	begin
//	compute the intersection distance of the planes
//	T1 = (Xl - Xo) / Xd
//	T2 = (Xh - Xo) / Xd
//	If T1 > T2 swap (T1, T2) /* since T1 intersection with near plane */
//	If T1 > Tnear set Tnear =T1 /* want largest Tnear */
//	If T2 < Tfar set Tfar="T2" /* want smallest Tfar */
//	If Tnear > Tfar box is missed so return false
//	If Tfar < 0 box is behind ray return false end


		float tNear = -1.0e6;
		float tFar = 1.0e6;

		for (int i = 0; i < 3; i++)
		{
			if (neIsConsiderZero(sensorA.dir[i]))
			{
				if (sensorA.pos[i] < -convexB.as.box.boxSize[i] ||
					sensorA.pos[i] > convexB.as.box.boxSize[i])
				{
					return;
				}
			}
			float t1 = (-convexB.as.box.boxSize[i] - sensorA.pos[i]) / sensorA.dir[i];
			
			float t2 = (convexB.as.box.boxSize[i] - sensorA.pos[i]) / sensorA.dir[i];

			float tt;

			if (t1 > t2)
			{
				tt = t1;
				t1 = t2;
				t2 = tt;
			}

			if (t1 > tNear)
			{
				tNear = t1;
				nearDim = i;
			}

			if (t2 < tFar)
			{
				tFar = t2;
				farDim = i;
			}

			if (tNear > tFar)
				return;

			if (tFar < 0)
				return;

		}
		//assert(nearDim != -1);
		//assert(farDim != -1);

		if (tNear > 1.0f)
			return;

		neV3 contact = sensorA.pos + tNear * sensorA.dir;

		neV3 sensorEnd = sensorA.pos + sensorA.dir;

		f32 depth = (sensorEnd - contact).Length();

		sensorA.depth = depth;

		f32 factor = (sensorA.dir[nearDim] >= 0) ? -1.0f : 1.0f;
		sensorA.normal = transB.rot[nearDim] * factor;

		sensorA.contactPoint = contact;

		sensorA.materialID = convexB.matIndex;
	}
	else if (convexB.type == TConvex::TERRAIN)
	{
		neSimpleArray<s32> & _triIndex = *convexB.as.terrain.triIndex;

		s32 triangleCount = _triIndex.GetUsedCount();

		neArray<neTriangle_> & triangleArray = *convexB.as.terrain.triangles;
		
		for (s32 i = 0; i < triangleCount; i++)
		{
			s32 test = _triIndex[i];

			neTriangle_ * t = &triangleArray[_triIndex[i]];

			neV3 * vert[3];

			neV3 edges[3];

			neV3 normal;

			f32 d;

			vert[0] = &convexB.vertices[t->indices[0]];
			vert[1] = &convexB.vertices[t->indices[1]];
			vert[2] = &convexB.vertices[t->indices[2]];

			edges[0] = *vert[1] - *vert[0];
			edges[1] = *vert[2] - *vert[1];
			edges[2] = *vert[0] - *vert[2];
			normal = edges[0].Cross(edges[1]);

			normal.Normalize();

			d = normal.Dot(*vert[0]);

			f32 nd = normal.Dot(sensorA.dir);

			f32 np = normal.Dot(sensorA.pos);

			f32 t1;

			t1 = (d - np) / nd;

			if (t1 > 1.0f || t1 < 0.0f)
				continue;

			neV3 contactPoint = sensorA.pos + sensorA.dir * t1;

			if (!SameSide(contactPoint, *vert[2], *vert[0], edges[0]))
				continue;

			if (!SameSide(contactPoint, *vert[0], *vert[1], edges[1]))
				continue;

			if (!SameSide(contactPoint, *vert[1], *vert[2], edges[2]))
				continue;

			sensorA.depth = (1.0f - t1) * sensorA.length;

			if (nd > 0.0)
				sensorA.normal = normal * -1.0f;
			else
				sensorA.normal = normal;

			sensorA.contactPoint = contactPoint;

			sensorA.materialID = t->materialID;
		}
	}
	else
	{
		// other primitives to do
	}
}
Exemplo n.º 6
0
bool PointInTriangle( bVector p, bVector a, bVector b, bVector c )
{
	if( SameSide( p, a, b, c ) && SameSide( p, b, a, c) && SameSide( p, c, a, b ) ) return true; else return false;
}
Exemplo n.º 7
0
bool PointInTriangleSS( const Vector3f *pTri, const Vector3f p )
{
    return (SameSide( p, pTri[2], pTri[0], pTri[1] ) &&
			SameSide( p, pTri[0], pTri[1], pTri[2] ) &&
			SameSide( p, pTri[1], pTri[2], pTri[0] ));
}
Exemplo n.º 8
0
int Piano::IsOnSurf1(Vettore *P){
  if( SameSide(P,&P1,&P2,&P3) && SameSide(P,&P2,&P1,&P3) && SameSide(P,&P3,&P1,&P2)) return 1;
  return 0;
}
Exemplo n.º 9
0
bool PointInTriangle(const vec3& p, const vec3& a, const vec3& b, const vec3& c)
{
	return (SameSide(p, a, b, c) && SameSide(p, b, a, c) && SameSide(p, c, a, b));
}