Пример #1
0
bool dgCollisionConvexHull::OOBBTest (const dgMatrix& matrix, const dgCollisionConvex* const shape, void* const cacheOrder) const
{
	bool ret;
	_ASSERTE (cacheOrder);

	ret = dgCollisionConvex::OOBBTest (matrix, shape, cacheOrder);
	if (ret) {
		const dgConvexSimplexEdge* const* faceArray = m_faceArray;
		dgCollisionBoundPlaneCache* const cache = (dgCollisionBoundPlaneCache*)cacheOrder;

		for (dgInt32 i = 0; i < dgInt32 (sizeof (cache->m_planes) / sizeof (dgPlane)); i ++) {
			dgFloat32 dist;
			const dgPlane& plane = cache->m_planes[i];
			if ((plane % plane) > dgFloat32 (0.0f)) {
				dgVector dir (matrix.UnrotateVector(plane.Scale (-1.0f)));
				dir.m_w = dgFloat32 (0.0f);
				dgVector p (matrix.TransformVector (shape->SupportVertex(dir)));
				dist = plane.Evalue (p);
				if (dist > dgFloat32 (0.1f)){
					return false;
				} 
			}
		}

		for (dgInt32 i = 0; i < m_boundPlanesCount; i ++) {
			dgInt32 i0;
			dgInt32 i1;
			dgInt32 i2;
			dgFloat32 dist;

			const dgConvexSimplexEdge* const face = faceArray[i];
			i0 = face->m_prev->m_vertex;
			i1 = face->m_vertex;
			i2 = face->m_next->m_vertex;
			const dgVector& p0 = m_vertex[i0];

			dgVector normal ((m_vertex[i1] - p0) * (m_vertex[i2] - p0));
			normal = normal.Scale (dgFloat32 (1.0f) / dgSqrt (normal % normal));

			dgVector dir (matrix.UnrotateVector(normal.Scale (-1.0f)));
			dir.m_w = dgFloat32 (0.0f);
			dgVector p (matrix.TransformVector (shape->SupportVertex(dir)));

			//_ASSERTE ((normal % (m_boxOrigin - p0)) < 0.0f);
			dist = normal % (p - p0);
			if (dist > dgFloat32 (0.1f)){
				for (dgInt32 j = 0; j < (dgInt32 (sizeof (cache->m_planes) / sizeof (dgPlane)) - 1); j ++) {
					cache->m_planes[j + 1] = cache->m_planes[j];
				}
				cache->m_planes[1] = dgPlane (normal, - (normal % p0));
				return false;
			} 
		}
	}
	return ret;
}
Пример #2
0
	// Compute axis aligned box
	static void BoundingBox (const dgMatrix &Mat, const hacd::HaF32 vertex[], hacd::HaI32 vertexCount, hacd::HaI32 stride, dgVector &min, dgVector &max)
	{
		hacd::HaF32 xmin = hacd::HaF32 (1.0e10f);
		hacd::HaF32 ymin = hacd::HaF32 (1.0e10f);
		hacd::HaF32 zmin = hacd::HaF32 (1.0e10f);

		hacd::HaF32 xmax = hacd::HaF32 (-1.0e10f);
		hacd::HaF32 ymax = hacd::HaF32 (-1.0e10f);
		hacd::HaF32 zmax = hacd::HaF32 (-1.0e10f);

		const hacd::HaF32* ptr = vertex;
		for (hacd::HaI32 i = 0 ; i < vertexCount; i ++ ) {
			dgVector tmp (ptr[0], ptr[1], ptr[2], hacd::HaF32 (0.0f));
			ptr += stride;
			tmp = Mat.UnrotateVector (tmp);
			if (tmp.m_x < xmin) xmin = tmp.m_x;
			if (tmp.m_y < ymin) ymin = tmp.m_y;
			if (tmp.m_z < zmin) zmin = tmp.m_z;
			if (tmp.m_x > xmax) xmax = tmp.m_x;
			if (tmp.m_y > ymax) ymax = tmp.m_y;
			if (tmp.m_z > zmax) zmax = tmp.m_z;
		}

		min = dgVector (xmin, ymin, zmin, hacd::HaF32 (0.0f));
		max = dgVector (xmax, ymax, zmax, hacd::HaF32 (0.0f));
	}
Пример #3
0
	static void BoundingBox (const dgMatrix &matrix, const hacd::HaF32 vertex[], hacd::HaI32 stride, const hacd::HaI32 index[], hacd::HaI32 indexCount, dgVector &min, dgVector &max)
	{
	   hacd::HaF32 xmin = hacd::HaF32 (1.0e10f);
	   hacd::HaF32 ymin = hacd::HaF32 (1.0e10f);
	   hacd::HaF32 zmin = hacd::HaF32 (1.0e10f);

	   hacd::HaF32 xmax = hacd::HaF32 (-1.0e10f);
	   hacd::HaF32 ymax = hacd::HaF32 (-1.0e10f);
	   hacd::HaF32 zmax = hacd::HaF32 (-1.0e10f);

	   const hacd::HaF32*	const ptr = vertex;
	   for (hacd::HaI32 j = 0 ; j < indexCount; j ++ ) {
			hacd::HaI32 i = index[j] * stride;
			dgVector tmp (ptr[i + 0], ptr[i + 1], ptr[i + 2], hacd::HaF32 (0.0f));
			tmp = matrix.UnrotateVector (tmp);
			if (tmp.m_x < xmin) xmin = tmp.m_x;
			if (tmp.m_y < ymin) ymin = tmp.m_y;
			if (tmp.m_z < zmin) zmin = tmp.m_z;
			if (tmp.m_x > xmax) xmax = tmp.m_x;
			if (tmp.m_y > ymax) ymax = tmp.m_y;
			if (tmp.m_z > zmax) zmax = tmp.m_z;
	   }
		
	   min = dgVector (xmin, ymin, zmin, hacd::HaF32 (0.0f));
	   max = dgVector (xmax, ymax, zmax, hacd::HaF32 (0.0f));
	}
Пример #4
0
	static void BoundingBox (
		const dgMatrix &matrix,
		const dgFloat32 vertex[], 
		dgInt32 stride, 
		const dgInt32 index[],
		dgInt32 indexCount, 
		dgVector &min, 
		dgVector &max)
	{
		dgInt32 i;
		dgInt32 j;
		const dgFloat32 *ptr;
		dgFloat32 xmin;
		dgFloat32 xmax;
		dgFloat32 ymin;
		dgFloat32 ymax;
		dgFloat32 zmin;
		dgFloat32 zmax;
		
	   xmin = dgFloat32 (1.0e10f);
	   ymin = dgFloat32 (1.0e10f);
	   zmin = dgFloat32 (1.0e10f);

	   xmax = dgFloat32 (-1.0e10f);
	   ymax = dgFloat32 (-1.0e10f);
	   zmax = dgFloat32 (-1.0e10f);


		ptr = vertex;
	   for (j = 0 ; j < indexCount; j ++ ) {
			i = index[j] * stride;
			dgVector tmp (ptr[i + 0], ptr[i + 1], ptr[i + 2], dgFloat32 (0.0f));
			tmp = matrix.UnrotateVector (tmp);
			if (tmp.m_x < xmin) xmin = tmp.m_x;
			if (tmp.m_y < ymin) ymin = tmp.m_y;
			if (tmp.m_z < zmin) zmin = tmp.m_z;
			if (tmp.m_x > xmax) xmax = tmp.m_x;
			if (tmp.m_y > ymax) ymax = tmp.m_y;
			if (tmp.m_z > zmax) zmax = tmp.m_z;
	   }
		
	   min = dgVector (xmin, ymin, zmin, dgFloat32 (0.0f));
	   max = dgVector (xmax, ymax, zmax, dgFloat32 (0.0f));
	}
Пример #5
0
	// Compute axis aligned box
	static void BoundingBox (
		const dgMatrix &Mat,
		const dgFloat32 vertex[], 
		dgInt32 vertexCount, 
		dgInt32 stride,
		dgVector &min, 
		dgVector &max)
	{
		dgInt32 i;
		const dgFloat32 *ptr;
		dgFloat32 xmin;
		dgFloat32 xmax;
		dgFloat32 ymin;
		dgFloat32 ymax;
		dgFloat32 zmin;
		dgFloat32 zmax;

		xmin = dgFloat32 (1.0e10f);
		ymin = dgFloat32 (1.0e10f);
		zmin = dgFloat32 (1.0e10f);

		xmax = dgFloat32 (-1.0e10f);
		ymax = dgFloat32 (-1.0e10f);
		zmax = dgFloat32 (-1.0e10f);

		ptr = vertex;
		for (i = 0 ; i < vertexCount; i ++ ) {
			dgVector tmp (ptr[0], ptr[1], ptr[2], dgFloat32 (0.0f));
			ptr += stride;
			tmp = Mat.UnrotateVector (tmp);
			if (tmp.m_x < xmin) xmin = tmp.m_x;
			if (tmp.m_y < ymin) ymin = tmp.m_y;
			if (tmp.m_z < zmin) zmin = tmp.m_z;
			if (tmp.m_x > xmax) xmax = tmp.m_x;
			if (tmp.m_y > ymax) ymax = tmp.m_y;
			if (tmp.m_z > zmax) zmax = tmp.m_z;
		}

		min = dgVector (xmin, ymin, zmin, dgFloat32 (0.0f));
		max = dgVector (xmax, ymax, zmax, dgFloat32 (0.0f));
	}