OgreVolume with bullet and OgreBullet

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
emmanuel1359
Kobold
Posts: 32
Joined: Mon Feb 02, 2015 11:05 pm

OgreVolume with bullet and OgreBullet

Post by emmanuel1359 »

hello,

i would like to use the OgreVolume with bullet , so i call:

Code: Select all

	myMeshBuilderCallback callback(this);
	mVolumeRoot->load(mVolumeRootNode, OgreFramework::getSingletonPtr()->m_pSceneMgr, "volumeTerrain.cfg", false, &callback);
with the class:

Code: Select all

void myMeshBuilderCallback::ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess)
{
	size_t count = indices.size();
	for (size_t i = 0; i < count; i += 3)
	{
		Vertex v1 = vertices[indices[i]];
		Vertex v2 = vertices[indices[i + 1]];
		Vertex v3 = vertices[indices[i + 2]];

		// Do something with the Triangle...


		);
is the good choice is
VertexIndexToShape
or
StaticMeshToShapeConverter
or ...
(from OgreBullet)


and how to create an Entity or a Mesh wih the VecVertex and VecIndices ?
with the ManualObject ?

is all this explained into some ogre3D books (1.8 ?)

thanks
emmanuel1359
Kobold
Posts: 32
Joined: Mon Feb 02, 2015 11:05 pm

Re: OgreVolume with bullet and OgreBullet

Post by emmanuel1359 »

i've tried this code:

Code: Select all

void myMeshBuilderCallback::ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess)
{
		// create the bullet shape and rigid body
		OgreBulletCollisions::StaticMeshToShapeConverter *terrainShape = new OgreBulletCollisions::StaticMeshToShapeConverter(simpleRenderable, Ogre::Matrix4::IDENTITY);
but the error is about const into one side, and not the other ...

Code: Select all

/media/emmanuel/ce72ce91-e57a-47d5-a6a5-ebf8dc2f2d54/mes_projets/mytruc/myMeshBuilderCallback.cpp|43|error: invalid conversion from ‘const Ogre::Renderable*’ to ‘Ogre::Renderable*’ [-fpermissive]|
is someone have some good solution for this problem ?
emmanuel1359
Kobold
Posts: 32
Joined: Mon Feb 02, 2015 11:05 pm

Re: OgreVolume with bullet and OgreBullet

Post by emmanuel1359 »

i can add
-fpermissive

to avoid this error bu i wonder if it is a good idea...
emmanuel1359
Kobold
Posts: 32
Joined: Mon Feb 02, 2015 11:05 pm

Re: OgreVolume with bullet and OgreBullet

Post by emmanuel1359 »

a solution is to cast a const to none const:

const_cast<SimpleRenderable*> (simpleRenderable)

what do you think about that ?

should i modify:

StaticMeshToShapeConverter::StaticMeshToShapeConverter(Ogre::Renderable *rend, const Ogre::Matrix4 &transform)
to
StaticMeshToShapeConverter::StaticMeshToShapeConverter(const Ogre::Renderable *rend, const Ogre::Matrix4 &transform)

instead ?

because StaticMeshToShapeConverter must not modify the renderable ?
emmanuel1359
Kobold
Posts: 32
Joined: Mon Feb 02, 2015 11:05 pm

Re: OgreVolume with bullet and OgreBullet

Post by emmanuel1359 »

finally all compiled:

Code: Select all

void myMeshBuilderCallback::ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess)
{
OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready");


		// create the bullet shape and rigid body
		SimpleRenderable *simpleRenderable2 = const_cast<SimpleRenderable*> (simpleRenderable);

OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready 0");

		OgreBulletCollisions::CollisionShape *terrainShape = (OgreBulletCollisions::CollisionShape *)new OgreBulletCollisions::StaticMeshToShapeConverter(simpleRenderable2, Ogre::Matrix4::IDENTITY);

OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready 1");

		OgreBulletDynamics::RigidBody *terrainBody = new OgreBulletDynamics::RigidBody(
			"VolumeTerrain",
			m_ptheApp->getBulletWorld()
		);


OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready 2");

		Ogre::SceneNode *pTerrainNode = OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode();
		const Ogre::Vector3 v3 = Ogre::Vector3::ZERO;
		const Ogre::Quaternion q = Ogre::Quaternion::IDENTITY;
OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready 3");
		terrainBody->setStaticShape(pTerrainNode, terrainShape, 0.0f, 0.8f, v3, q);
		terrainBody->setPosition(terrainBody->getWorldPosition());

OgreFramework::getSingletonPtr()->m_pLog->logMessage("-> myMeshBuilderCallback::ready 4");
		// push the created objects to the deques
		m_ptheApp->getBulletShapes().push_back(terrainShape);
		m_ptheApp->getBulletBodies().push_back(terrainBody);

	OgreFramework::getSingletonPtr()->m_pLog->logMessage("<- myMeshBuilderCallback::ready");
}


but i've got a runtime error :
i don't understand why the renderable object has
Ogre::RenderOperation.useIndexes = true
but
Ogre::RenderOperation.indexData = false (returned by Ogre::StringConverter::toString(op.indexData)=null in fact ?)

Code: Select all

StaticMeshToShapeConverter::StaticMeshToShapeConverter(Ogre::Renderable *rend,
                                                       const Ogre::Matrix4 &transform)
    : VertexIndexToShape(transform),
      mEntity(NULL),
      mNode(NULL)
{
Ogre::LogManager::getSingleton().logMessage("-> StaticMeshToShapeConverter::StaticMeshToShapeConverter");
    Ogre::RenderOperation op;
	rend->getRenderOperation(op);
	VertexIndexToShape::addStaticVertexData(op.vertexData);
    if (op.useIndexes)
    {
Ogre::LogManager::getSingleton().logMessage(Ogre::String("op.indexData ")+Ogre::StringConverter::toString(op.indexData));
Ogre::LogManager::getSingleton().logMessage("-> StaticMeshToShapeConverter::StaticMeshToShapeConverter 4");
		VertexIndexToShape::addIndexData(op.indexData);
    }

Ogre::LogManager::getSingleton().logMessage("<- StaticMeshToShapeConverter::StaticMeshToShapeConverter");
}
Post Reply