void dMeshNodeInfo::CalcutateAABB (dVector& p0, dVector& p1) const
{
//	int strideInBytes = NewtonMeshGetVertexStrideInByte(m_mesh);
//	dFloat64* const vertexList = NewtonMeshGetVertexArray(m_mesh);
//	dFloat t = 1.2f;
//	for (void* face = NewtonMeshGetFirstFace (m_mesh); face; face = NewtonMeshGetNextFace (m_mesh, face)) {
//		if (!NewtonMeshIsFaceOpen (m_mesh, face)) {

//	dMatrix matrix (GetIdentityMatrix());
//	NewtonMeshCalculateOOBB(const NewtonMesh* const mesh, dFloat* const matrix, dFloat* const x, dFloat* const y, dFloat* const z);

	p0 = dVector (1.0e10f, 1.0e10f, 1.0e10f, 0.0f);
	p1 = dVector (-1.0e10f, -1.0e10f, -1.0e10f, 0.0f);

	int strideInBytes = NewtonMeshGetVertexStrideInByte(m_mesh);
	int stride = strideInBytes / sizeof (dFloat64) ;
	const dFloat64* const vertexList = NewtonMeshGetVertexArray(m_mesh);
	for (void* ptr = NewtonMeshGetFirstVertex(m_mesh); ptr; ptr = NewtonMeshGetNextVertex(m_mesh, ptr)) {
		int index = NewtonMeshGetVertexIndex (m_mesh, ptr);

		dFloat x = dFloat (vertexList[index * stride + 0]);
		dFloat y = dFloat (vertexList[index * stride + 1]);
		dFloat z = dFloat (vertexList[index * stride + 2]);
		dVector v (m_matrix.TransformVector(dVector (x, y, z, 0.0f)));

		p0[0] = dMin(v[0], p0[0]);
		p0[1] = dMin(v[1], p0[1]);
		p0[2] = dMin(v[2], p0[2]);
					   
		p1[0] = dMax(v[0], p1[0]);
		p1[1] = dMax(v[1], p1[1]);
		p1[2] = dMax(v[2], p1[2]);
	}
}
Esempio n. 2
0
void dMeshNodeInfo::CalculateOOBBGizmo (const dMatrix& matrix, dVector& p0, dVector& p1) const
{
	p0 = dVector ( 1.0e10f,  1.0e10f,  1.0e10f, 1.0f);
	p1 = dVector (-1.0e10f, -1.0e10f, -1.0e10f, 1.0f);

	dMatrix tranform (m_matrix * matrix) ;

	int stride = NewtonMeshGetVertexStrideInByte(m_mesh) / sizeof(dFloat);
	float* const vertexList = NewtonMeshGetVertexArray(m_mesh);

	for (void* vertex = NewtonMeshGetFirstVertex(m_mesh); vertex; vertex = NewtonMeshGetNextVertex(m_mesh, vertex)) {
		int index = NewtonMeshGetVertexIndex(m_mesh, vertex) * stride;

		dVector p (vertexList[index + 0], vertexList[index + 1],  vertexList[index + 2],  1.0);
		p = tranform.TransformVector(p);
		p0.m_x = min (p.m_x, p0.m_x);
		p0.m_y = min (p.m_y, p0.m_y);
		p0.m_z = min (p.m_z, p0.m_z);

		p1.m_x = max (p.m_x, p1.m_x);
		p1.m_y = max (p.m_y, p1.m_y);
		p1.m_z = max (p.m_z, p1.m_z);
	}
}