<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/10114" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2014-09-11T05:49:10+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/10114</id>

		<entry>
		<author><name><![CDATA[lucky7456969]]></name></author>
		<updated>2014-09-11T05:49:10+00:00</updated>

		<published>2014-09-11T05:49:10+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=33998#p33998</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=33998#p33998"/>
		<title type="html"><![CDATA[How to prevent wall penetrations?]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=33998#p33998"><![CDATA[
Hello,<br>I am a newbie of bullet.<br>And I am using the Ogre3D renderer with OgreBullet wrapper.<br>Here comes the question....<br><br>Here I iterate the scene and add walls to bullet so that later when I add cubes to the scene,<br>they will bounce off the walls naturally,<div class="codebox"><p>Code: </p><pre><code>Ogre::SceneManager::MovableObjectIterator iterator = mSceneMgr-&gt;getMovableObjectIterator("Entity");while(iterator.hasMoreElements()){          Ogre::Entity* e = static_cast&lt;Ogre::Entity*&gt;(iterator.getNext());     addWorldObject(e-&gt;getName(), e, e-&gt;getParentSceneNode(), 1.0f);} </code></pre></div><div class="codebox"><p>Code: </p><pre><code>void OgreBulletListener::addWorldObject(Ogre::String name, Ogre::Entity* pEntity, Ogre::SceneNode* pNode, btScalar mass){        if(!pEntity) return;        if(!pNode) return; AxisAlignedBox aabb = pEntity-&gt;getWorldBoundingBox(true); Ogre::Vector3 h = aabb.getHalfSize(); OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(h);OgreBulletCollisions::CompoundCollisionShape* comShape = new OgreBulletCollisions::CompoundCollisionShape();comShape-&gt;addChildShape(sceneBoxShape, Ogre::Vector3(0,-0.7,-1.3), Ogre::Quaternion(1,0,0,0)); Ogre::Vector3 position = pNode-&gt;getPosition();Ogre::Quaternion direction = pNode-&gt;getOrientation();   OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody("defaultBoxRigid" + Ogre::StringConverter::toString(mNumEntitiesInstanced++),mWorld); defaultBody-&gt;setStaticShape(sceneBoxShape,0.6f,        0.8f,    position,direction); mBodies.push_back(defaultBody); mNumEntitiesInstanced++;          }</code></pre></div><div class="codebox"><p>Code: </p><pre><code>RigidBody *OgreBulletListener::addCube(const Ogre::String instanceName,                                       const Ogre::Vector3 &amp;pos, const Ogre::Quaternion &amp;q, const Ogre::Vector3 &amp;size,                                       const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,                                        const Ogre::Real bodyMass){    Entity *entity = mSceneMgr-&gt;createEntity(        instanceName + StringConverter::toString(mNumEntitiesInstanced),        "Bulletbox.mesh");    // "Crate.mesh");    // "Crate1.mesh");    // "Crate2.mesh");    entity-&gt;setQueryFlags (GEOMETRY_QUERY_MASK);#if (OGRE_VERSION &lt; ((1 &lt;&lt; 16) | (5 &lt;&lt; 8) | 0)) // only applicable before shoggoth (1.5.0)    entity-&gt;setNormaliseNormals(true);#endifentity-&gt;setCastShadows(true);    entity-&gt;setMaterialName("Bullet/box");    BoxCollisionShape *sceneCubeShape = new BoxCollisionShape(size);    RigidBody *defaultBody = new RigidBody(        "defaultCubeRigid" + StringConverter::toString(mNumEntitiesInstanced),         mWorld);    SceneNode *node = mSceneMgr-&gt;getRootSceneNode ()-&gt;createChildSceneNode ();    node-&gt;attachObject (entity);    defaultBody-&gt;setShape (node,  sceneCubeShape, bodyRestitution, bodyFriction, bodyMass, pos, q);    mEntities.push_back(entity);    mShapes.push_back(sceneCubeShape);    mBodies.push_back(defaultBody);    mNumEntitiesInstanced++;    return defaultBody;}</code></pre></div><div class="codebox"><p>Code: </p><pre><code>void OgreBulletListener::throwDynamicObject(BULLET_KEY_CODE key){    const float trowDist = 2.0f;    switch(key)    {    case KC_N:         if ( checkIfEnoughPlaceToAddObject(trowDist))        {            const Ogre::Vector3 vec (mCamera-&gt;getDerivedPosition());            OgreBulletDynamics::RigidBody *body = addCube("cube", vec, Quaternion(0,0,0,1),                 gCubeBodyBounds, gDynamicBodyRestitution, gDynamicBodyFriction, gDynamicBodyMass);            body-&gt;setLinearVelocity(                mCamera-&gt;getDerivedDirection().normalisedCopy() * mShootSpeed); }        break;</code></pre></div>And I am probing the keypressed event and change the camera accordingly, however, when I pressed 'N'<br>on the keyboard, the cube is always located at the same location, and it doesn't move at all.<br>Note: When I don't addWorldObject (walls etc), the cubes will run thru walls, if I do, they will be trapped in the same location.<br>Could anyone shed some lights on this?<br><br>Thanks<br>Jacl<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11008">lucky7456969</a> — Thu Sep 11, 2014 5:49 am</p><hr />
]]></content>
	</entry>
	</feed>
