How to update vertics in a hkpShape which already add in hkpRigidBody?

How to update vertics in a hkpShape which already add in hkpRigidBody?

 Hi,everyone.

For topic problem,i found two function  in class hkpRigidBody:

hkWorldOperation::Result updateShape(hkpShapeModifier* shapeModifier = HK_NULL);
hkWorldOperation::Result setShape(const hkpShape* shape);

and i do a test like this:

hkGeometry *pGem = hkpShapeConverter::toSingleGeometry(it->second.pShape);
if(NULL != pGem)
{
     if (NULL != vertex_indexs)
     {
         for (mys3_uint i = 0;i < vertex_num; ++i)
         {
             pGem->m_vertices[vertex_indexs[i]].set(vertexs[i].flag.coord.x,vertexs[i].flag.coord.y,vertexs[i].flag.coord.z);
         }
     }
     else
     {
         assert(vertex_num <= pGem->m_vertices.getSize());
         for (mys3_uint i = 0;i < vertex_num; ++i)
         {
             pGem->m_vertices[i].set(vertexs[i].flag.coord.x,vertexs[i].flag.coord.y,vertexs[i].flag.coord.z);
         }
    }
}
it->second.pRigidBody->setShape(it->second.pShape);//it is error
m_pWorld->unlock();

so i found another Method,like this:

mys3_shape_modifier:public hkpShapeModifier
{
public:
mys3_shape_modifier(const mys3_uint* vertex_indexs,const mys3_float3* vertexs,mys3_uint vertex_num):
m_vertex_indexs(vertex_indexs),
m_vertexs(vertexs),
m_vertex_num(vertex_num)
{
}
void modifyShape(hkpShape* shapeInOut)
{
hkGeometry *pGem = hkpShapeConverter::toSingleGeometry(shapeInOut);
if(NULL != pGem)
{
if (NULL != m_vertex_indexs)
{
for (mys3_uint i = 0;i < m_vertex_num; ++i)
{
pGem->m_vertices[m_vertex_indexs[i]].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);
}
}
else
{
assert(m_vertex_num <= pGem->m_vertices.getSize());
for (mys3_uint i = 0;i < m_vertex_num; ++i)
{
pGem->m_vertices[i].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);
}
}
}
}
private:
const mys3_uint * m_vertex_indexs;
const mys3_float3* m_vertexs;
mys3_uint m_vertex_num;
};
void myclass:: update_shape()
{
stdext::hash_map<mys3_uint,mys3_physic_body>::iterator it = m_PhysicBodyMap.find(obj_hash);
if(it == m_PhysicBodyMap.end())
{
return ;
}
it->second.pRigidBody->markForWrite();
mys3_shape_modifier shapeModifier(vertex_indexs,vertexs,vertex_num);
it->second.pRigidBody->updateShape(&shapeModifier);//this step,i get a crash.
it->second.pRigidBody->unmarkForWrite();
}

the last test:

mys3_shape_modifier:public hkpShapeModifier
{
public:
 mys3_shape_modifier(const mys3_uint* vertex_indexs,const mys3_float3* vertexs,mys3_uint vertex_num):
 m_vertex_indexs(vertex_indexs),
 m_vertexs(vertexs),
 m_vertex_num(vertex_num)
 {
 }
void modifyShape(hkpShape* shapeInOut)
 {
 hkGeometry *pGem = hkpShapeConverter::toSingleGeometry(shapeInOut);
 if(NULL != pGem)
 {
 if (NULL != m_vertex_indexs)
 {
 for (mys3_uint i = 0;i < m_vertex_num; ++i)
 {
 pGem->m_vertices[m_vertex_indexs[i]].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);
 }
 }
 else
 {
 assert(m_vertex_num <= pGem->m_vertices.getSize());
 for (mys3_uint i = 0;i < m_vertex_num; ++i)
 {
 pGem->m_vertices[i].set(m_vertexs[i].flag.coord.x,m_vertexs[i].flag.coord.y,m_vertexs[i].flag.coord.z);
 }
 }
 }
 }
private:
 const mys3_uint * m_vertex_indexs;
 const mys3_float3* m_vertexs;
 mys3_uint m_vertex_num;
};
void myclass:: update_shape()
{
stdext::hash_map<mys3_uint,mys3_physic_body>::iterator it = m_PhysicBodyMap.find(obj_hash);
 if(it == m_PhysicBodyMap.end())
 {
 return ;
 }
hkWorldOperation::UpdateWorldObjectShape shapeUpdateOpera;
 mys3_shape_modifier shapeModifier(vertex_indexs,vertexs,vertex_num);
 shapeUpdateOpera.m_shapeModifier = &shapeModifier;
 it->second.pRigidBody->markForWrite();
 shapeUpdateOpera.m_worldObject = it->second.pRigidBody;
 m_pWorld->lockCriticalOperations();
 m_pWorld->queueOperation(shapeUpdateOpera);
 m_pWorld->attemptToExecutePendingOperations();
 m_pWorld->unlockCriticalOperations();
 it->second.pRigidBody->unmarkForWrite();
}

but it is a error code yet,i get a crash!

how can i do for Correct code?

2 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi Jins,
what is the crash you are getting?

Josh S. Havok Developer Support Engineer www.havok.com

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!