findOrAddVertex and addIndex usage?

Mars_999
Posts: 25
Joined: Tue Dec 04, 2007 7:48 pm

findOrAddVertex and addIndex usage?

Post by Mars_999 »

I think this is a bug...

Code: Select all

#include <iostream>
#include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h>

float pyramidVertices[] = {
0.000000f,1.000000f,0.000000f,
0.500000f,0.000000f,-0.500000f,
0.500000f,0.000000f,0.500000f,
0.000000f,1.000000f,0.000000f,
0.500000f,0.000000f,0.500000f,
-0.500000f,0.000000f,0.500000f,
0.000000f,1.000000f,0.000000f,
-0.500000f,0.000000f,0.500000f,
-0.500000f,0.000000f,-0.500000f,
0.000000f,1.000000f,0.000000f,
-0.500000f,0.000000f,-0.500000f,
0.500000f,0.000000f,-0.500000f,
0.500000f,0.000000f,-0.500000f,
0.000000f,0.000000f,0.000000f,
0.500000f,0.000000f,0.500000f,
0.500000f,0.000000f,0.500000f,
-0.500000f,0.000000f,0.500000f,
-0.500000f,0.000000f,-0.500000f,
-0.500000f,0.000000f,-0.500000f,
0.500000f,0.000000f,-0.500000f};

unsigned short pyramidIndices[] = {
0,1,2,
3,4,5,
6,7,8,
9,10,11,
12,13,14,
15,13,16,
16,13,17,
18,13,19};

int main (int argc, const char* argv[]) 
{
	int i = 0;
	btTransform t;
	btVector3 aabbMin, aabbMax;
	
	btTriangleMesh* mesh = new btTriangleMesh(false);

//issue here with findOrAddVertex()

	while(i < sizeof(pyramidVertices) / sizeof(float))
		mesh->findOrAddVertex(btVector3(pyramidVertices[i++], pyramidVertices[i++], pyramidVertices[i++]), true);
	i = 0;
	while(i < sizeof(pyramidIndices) / sizeof(unsigned short))
		mesh->addIndex(pyramidIndices[i++]);
	
	btSphereShape* sphereCDShape = new btSphereShape(.5f);
	sphereCDShape->getAabb(t, aabbMin, aabbMax);
	std::cout << aabbMin.getX() << ","
		      << aabbMin.getY() << ","
			  << aabbMin.getZ() << ","
			  << aabbMax.getX() << ","
			  << aabbMax.getY() << ","
			  << aabbMax.getZ() << std::endl << std::endl;
	
	mesh->calculateAabbBruteForce(aabbMin, aabbMax);
	std::cout << aabbMin.getX() << ","
	<< aabbMin.getY() << ","
	<< aabbMin.getZ() << ","
	<< aabbMax.getX() << ","
	<< aabbMax.getY() << ","
	<< aabbMax.getZ() << std::endl;	
	
	delete mesh;
	delete sphereCDShape;	
    return 0;
}	

Here is the link to gamedev where we discussed the fix to this...

http://www.gamedev.net/community/forums ... _id=541145
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

findOrAddVertex and addIndex are internal methods of btTriangleMesh, you need to use btTriangleMesh::addTriangle.

To avoid confusion, we'll make the methods protected.
Thanks for bringing this up,
Erwin