NewtonCreateConvexHull not working.

Ivancho

07-01-2009 22:35:34

I rewrite ConvexHull::ConvexHull method to work with child scenes,
function just do:

ConvexHull::ConvexHull( const World* world, Ogre::SceneNode* scnode, const Ogre::Quaternion& orient, const Ogre::Vector3& pos ) : ConvexCollision( world )
{
size_t total_verts = 0;
unsigned int offset = 0;
Ogre::Vector3* vertices = new Ogre::Vector3[500000];
Ogre::Vector3 scale(1.0,1.0,1.0);

Ogre::SceneNode::ChildNodeIterator child_it=scnode->getChildIterator();

while(child_it.hasMoreElements())
{
Ogre::SceneNode *node=(Ogre::SceneNode *)child_it.getNext();
if(node==0)
return;

//get the mesh!
Ogre::Entity* obj = (Ogre::Entity*)node->getAttachedObject(0);
Ogre::MeshPtr mesh = obj->getMesh();

//get scale
scale = node->getScale();

//find number of submeshes
unsigned short sub = mesh->getNumSubMeshes();



Ogre::VertexData* v_data;
bool addedShared = false;

for (unsigned short i=0;i<sub;i++)
{
Ogre::SubMesh* sub_mesh = mesh->getSubMesh(i);
if (sub_mesh->useSharedVertices)
{
if (!addedShared)
{
v_data = mesh->sharedVertexData;
total_verts += v_data->vertexCount;

addedShared = true;
}
}
else
{
v_data = sub_mesh->vertexData;
total_verts += v_data->vertexCount;
}
}

addedShared = false;

//make array to hold vertex positions!
Ogre::Vector3* vertices = new Ogre::Vector3[total_verts];


//loop back through, adding vertices as we go!
for (unsigned short i=0;i<sub;i++)
{
Ogre::SubMesh* sub_mesh = mesh->getSubMesh(i);
Ogre::VertexDeclaration* v_decl;
const Ogre::VertexElement* p_elem;
float* v_Posptr;
size_t v_count;

v_data = NULL;

if (sub_mesh->useSharedVertices)
{
if (!addedShared)
{
v_data = mesh->sharedVertexData;
v_count = v_data->vertexCount;
v_decl = v_data->vertexDeclaration;
p_elem = v_decl->findElementBySemantic( Ogre::VES_POSITION );
addedShared = true;
}
}
else
{
v_data = sub_mesh->vertexData;
v_count = v_data->vertexCount;
v_decl = v_data->vertexDeclaration;
p_elem = v_decl->findElementBySemantic( Ogre::VES_POSITION );
}

if (v_data)
{
size_t start = v_data->vertexStart;
//pointer
Ogre::HardwareVertexBufferSharedPtr v_sptr = v_data->vertexBufferBinding->getBuffer( p_elem->getSource() );
unsigned char* v_ptr = static_cast<unsigned char*>(v_sptr->lock( Ogre::HardwareBuffer::HBL_READ_ONLY ));
unsigned char* v_offset;

//loop through vertex data...
for (size_t j=start; j<(start+v_count); j++)
{
//get offset to Position data!
v_offset = v_ptr + (j * v_sptr->getVertexSize());
p_elem->baseVertexPointerToElement( v_offset, &v_Posptr );

//now get vertex positions...
vertices[offset].x = *v_Posptr; v_Posptr++;
vertices[offset].y = *v_Posptr; v_Posptr++;
vertices[offset].z = *v_Posptr; v_Posptr++;

vertices[offset] *= scale;

offset++;
}

//unlock buffer
v_sptr->unlock();
}


}
}

float matrix[16];

OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] );

//okay, let's try making the ConvexHull!
m_col = NewtonCreateConvexHull( m_world->getNewtonWorld(),
(int)total_verts,
(float*)&vertices[0].x,
sizeof(Ogre::Vector3),
&matrix[0] );

delete []vertices;
}


that code inaccurate in Ogre::Vector3* vertices = new Ogre::Vector3[500000];,
but my mesh contain only 14000 vertices.

i debug with visual studio to NewtonCreateConvexHull method. it accept right total_verts param, and right vertices param,
but mesh are get down through plane.
plane are ok, another simple mesh ::Cilynder are work with plane ok.

Ivancho

07-01-2009 23:55:36

thats a video http://www.youtube.com/watch?v=qf2_qHoyrWc 1 mb.