<?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/6220" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2011-01-13T16:35:58+00:00</updated>

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

		<entry>
		<author><name><![CDATA[jrk]]></name></author>
		<updated>2011-01-13T16:35:58+00:00</updated>

		<published>2011-01-13T16:35:58+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21742#p21742</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21742#p21742"/>
		<title type="html"><![CDATA[Re: Newbie: stepSimulation does nothing]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21742#p21742"><![CDATA[
I don't see what is going wrong, but I have made a successful ogre/bullet hello world (ogre head falls to the ground)<br>The code I've attached is derived from a class called BaseApplication which is derived from:<br>public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::SdkTrayListener<br><br>That architecture comes from running the appwizard found here:<br><a href="http://code.google.com/p/ogreappwizards/" class="postlink">http://code.google.com/p/ogreappwizards/</a><br><br>Hopefully that is enough background, here is the code:<br><br>header:<div class="codebox"><p>Code: </p><pre><code>/*-----------------------------------------------------------------------------Filename:    OgreBulletHelloWorldApp.h-----------------------------------------------------------------------------This source file is generated by the   ___                   _              __    __ _                  _   /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| | //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|      |___/                 |_|   |_|                                       Ogre 1.7.x Application Wizard for VC10 (August 2010)      http://code.google.com/p/ogreappwizards/-----------------------------------------------------------------------------*/#ifndef __OgreBulletHelloWorldApp_h_#define __OgreBulletHelloWorldApp_h_#include "btBulletDynamicsCommon.h"#include "BaseApplication.h"#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32#include "../res/resource.h"#endifclass OgreBulletHelloWorldApp : public BaseApplication{public:    OgreBulletHelloWorldApp(void);    virtual ~OgreBulletHelloWorldApp(void);protected:    virtual void createScene(void);// Ogre::FrameListener    virtual bool frameRenderingQueued(const Ogre::FrameEvent&amp; evt);private:btDiscreteDynamicsWorld* dynamicsWorld;btSequentialImpulseConstraintSolver* solver;btBroadphaseInterface* overlappingPairCache;btCollisionDispatcher* dispatcher;btDefaultCollisionConfiguration* collisionConfiguration;btAlignedObjectArray&lt;btCollisionShape*&gt; collisionShapes;};#endif // #ifndef __OgreBulletHelloWorldApp_h_</code></pre></div>.cpp<div class="codebox"><p>Code: </p><pre><code>/*-----------------------------------------------------------------------------Filename:    OgreBulletHelloWorldApp.cpp-----------------------------------------------------------------------------This source file is generated by the   ___                   _              __    __ _                  _   /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| | //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|      |___/                 |_|   |_|                                       Ogre 1.7.x Application Wizard for VC10 (August 2010)      http://code.google.com/p/ogreappwizards/-----------------------------------------------------------------------------*/#include "OgreBulletHelloWorldApp.h"//-------------------------------------------------------------------------------------OgreBulletHelloWorldApp::OgreBulletHelloWorldApp(void){}//-------------------------------------------------------------------------------------OgreBulletHelloWorldApp::~OgreBulletHelloWorldApp(void){int i;//remove the rigidbodies from the dynamics world and delete themfor (i=dynamicsWorld-&gt;getNumCollisionObjects()-1; i&gt;=0 ;i--){btCollisionObject* obj = dynamicsWorld-&gt;getCollisionObjectArray()[i];btRigidBody* body = btRigidBody::upcast(obj);if (body &amp;&amp; body-&gt;getMotionState()){delete body-&gt;getMotionState();}dynamicsWorld-&gt;removeCollisionObject( obj );delete obj;}//delete collision shapesfor (int j=0;j&lt;collisionShapes.size();j++){btCollisionShape* shape = collisionShapes[j];collisionShapes[j] = 0;delete shape;}//delete dynamics worlddelete dynamicsWorld;//delete solverdelete solver;//delete broadphasedelete overlappingPairCache;//delete dispatcherdelete dispatcher;delete collisionConfiguration;}//-------------------------------------------------------------------------------------void OgreBulletHelloWorldApp::createScene(void){    Ogre::Entity* ogreHead = mSceneMgr-&gt;createEntity("Head", "ogrehead.mesh");    Ogre::SceneNode* headNode = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode();    headNode-&gt;attachObject(ogreHead);    // Set ambient light    mSceneMgr-&gt;setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));    // Create a light    Ogre::Light* l = mSceneMgr-&gt;createLight("MainLight");    l-&gt;setPosition(20,80,50);/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.collisionConfiguration = new btDefaultCollisionConfiguration();///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)dispatcher = newbtCollisionDispatcher(collisionConfiguration);///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.overlappingPairCache = new btDbvtBroadphase();///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)solver = new btSequentialImpulseConstraintSolver;dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);dynamicsWorld-&gt;setGravity(btVector3(0,-10,0));///create a few basic rigid bodiesbtCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));//keep track of the shapes, we release memory at exit.//make sure to re-use collision shapes among rigid bodies whenever possible!//btAlignedObjectArray&lt;btCollisionShape*&gt; collisionShapes;collisionShapes.push_back(groundShape);btTransform groundTransform;groundTransform.setIdentity();groundTransform.setOrigin(btVector3(0,-56,0));{btScalar mass(0.);//rigidbody is dynamic if and only if mass is non zero, otherwise staticbool isDynamic = (mass != 0.f);btVector3 localInertia(0,0,0);if (isDynamic)groundShape-&gt;calculateLocalInertia(mass,localInertia);//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objectsbtDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);btRigidBody* body = new btRigidBody(rbInfo);//add the body to the dynamics worlddynamicsWorld-&gt;addRigidBody(body);}{//create a dynamic rigidbody//btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));btCollisionShape* colShape = new btSphereShape(btScalar(1.));collisionShapes.push_back(colShape);/// Create Dynamic ObjectsbtTransform startTransform;startTransform.setIdentity();startTransform.setOrigin(btVector3(0,0,0));btScalarmass(1.f);//rigidbody is dynamic if and only if mass is non zero, otherwise staticbool isDynamic = (mass != 0.f);btVector3 localInertia(0,0,0);if (isDynamic)colShape-&gt;calculateLocalInertia(mass,localInertia);startTransform.setOrigin(btVector3(2,10,0));//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objectsbtDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);btRigidBody* body = new btRigidBody(rbInfo);body-&gt;setUserPointer(headNode);dynamicsWorld-&gt;addRigidBody(body);}/////////////////////////////////////////////////////////////////////////}bool OgreBulletHelloWorldApp::frameRenderingQueued(const Ogre::FrameEvent&amp; evt){    if(mWindow-&gt;isClosed())        return false;    if(mShutDown)        return false;    //Need to capture/update each device    mKeyboard-&gt;capture();    mMouse-&gt;capture();    mTrayMgr-&gt;frameRenderingQueued(evt);    if (!mTrayMgr-&gt;isDialogVisible())    {        mCameraMan-&gt;frameRenderingQueued(evt);   // if dialog isn't up, then update the camera        if (mDetailsPanel-&gt;isVisible())   // if details panel is visible, then update its contents        {            mDetailsPanel-&gt;setParamValue(0, Ogre::StringConverter::toString(mCamera-&gt;getDerivedPosition().x));            mDetailsPanel-&gt;setParamValue(1, Ogre::StringConverter::toString(mCamera-&gt;getDerivedPosition().y));            mDetailsPanel-&gt;setParamValue(2, Ogre::StringConverter::toString(mCamera-&gt;getDerivedPosition().z));            mDetailsPanel-&gt;setParamValue(4, Ogre::StringConverter::toString(mCamera-&gt;getDerivedOrientation().w));            mDetailsPanel-&gt;setParamValue(5, Ogre::StringConverter::toString(mCamera-&gt;getDerivedOrientation().x));            mDetailsPanel-&gt;setParamValue(6, Ogre::StringConverter::toString(mCamera-&gt;getDerivedOrientation().y));            mDetailsPanel-&gt;setParamValue(7, Ogre::StringConverter::toString(mCamera-&gt;getDerivedOrientation().z));        }    }double dt = evt.timeSinceLastFrame;///////////////////////BULLET STUFF///////////////////////////dynamicsWorld-&gt;stepSimulation(1.f/60.f,10);dynamicsWorld-&gt;stepSimulation(dt,10);//print positions of all objectsfor (int j=dynamicsWorld-&gt;getNumCollisionObjects()-1; j&gt;=0 ;j--){btCollisionObject* obj = dynamicsWorld-&gt;getCollisionObjectArray()[j];btRigidBody* body = btRigidBody::upcast(obj);if (body &amp;&amp; body-&gt;getMotionState()){btTransform trans;body-&gt;getMotionState()-&gt;getWorldTransform(trans);printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode *&gt; (body-&gt;getUserPointer());if (node){Ogre::Vector3 pos(float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));node-&gt;setPosition(pos);}}}///////////////////////BULLET STUFF/////////////////////////    return true;}#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32#define WIN32_LEAN_AND_MEAN#include "windows.h"#endif#ifdef __cplusplusextern "C" {#endif#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )#else    int main(int argc, char *argv[])#endif    {        // Create application object        OgreBulletHelloWorldApp app;        try {            app.go();        } catch( Ogre::Exception&amp; e ) {#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);#else            std::cerr &lt;&lt; "An exception has occured: " &lt;&lt;                e.getFullDescription().c_str() &lt;&lt; std::endl;#endif        }        return 0;    }#ifdef __cplusplus}#endif</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=5518">jrk</a> — Thu Jan 13, 2011 4:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Papierkorb]]></name></author>
		<updated>2011-01-12T17:57:35+00:00</updated>

		<published>2011-01-12T17:57:35+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21735#p21735</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21735#p21735"/>
		<title type="html"><![CDATA[Newbie: stepSimulation does nothing]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=21735#p21735"><![CDATA[
Hello,<br>I want to use Bullet in my game project.<br>The first thing i did was implementing the HelloWorld code in some function which is<br>often called (Quick n' dirty, just to test). This worked out pretty good for a "hack".<br>Next thing was of course implementing the complete necessary code in the engine<br>(I'm using OGRE3D for graphics). I've set up everything and I'm calling stepSimulation<br>after every frame (I had some output code, so the handler function is called). But<br>the function seems to do nothing at all. Via output I could see, that Bullet once<br>retrieves the position and rotation of new objects (getWorldTransform) but never<br>calls "setWorldTransform". I've also recently tried using btDefaultMotionState and<br>setting the new positions in a loop, but stepSimulation does nothing. So, after<br>trying about 4 days getting this to work, I have no clue what to do to get it to<br>work :/<br><br>Here are the code chunks that are doing something with Bullet:<div class="codebox"><p>Code: </p><pre><code>/ ProjektilMotionState.h - My custom MotionState#ifndef _PROJEKTIL_MOTION_STATE_H_#define _PROJEKTIL_MOTION_STATE_H_ class ProjektilMotionState : public btMotionState {protected:        ork_object *mObj;        //Ogre::SceneNode *mNode; public:        btTransform mPos;         ProjektilMotionState (const btTransform &amp;initpos, ork_object *obj);        virtual ~ProjektilMotionState ();        void setObject (ork_object *newobj);        //void setPosition (float x, float y, float z);        virtual void getWorldTransform (btTransform &amp;worldTrans) const;        virtual void setWorldTransform (const btTransform &amp;worldTrans); }; #endif // _PROJEKTIL_MOTION_STATE_H_ // ProjektilMotionState.cpp#include &lt;kaym_common.h&gt; ProjektilMotionState::ProjektilMotionState (const btTransform &amp;initpos, ork_object *obj) {        mPos = initpos;        mObj = obj;         DBG ("Neue ProjektilMotionState Instanz");} ProjektilMotionState::~ProjektilMotionState () { } void ProjektilMotionState::setObject (ork_object *newobj) {        mObj = newobj;} void ProjektilMotionState::getWorldTransform (btTransform &amp;worldTrans) const {        DBG ("ProjektilMotionState::getWorldTransform");         worldTrans = mPos;} void ProjektilMotionState::setWorldTransform (const btTransform &amp;worldTrans) {        if (!mObj || !mObj-&gt;node)                return;         DBG ("ProjektilMotionState::setWorldTransform");         btQuaternion rot = worldTrans.getRotation ();        mObj-&gt;node-&gt;setOrientation(rot.w(), rot.x(), rot.y(), rot.z());        //object_rotate (mObj, rot.w (), rot.x (), rot.z (), rot.y ());         btVector3 pos = worldTrans.getOrigin ();        mObj-&gt;node-&gt;setPosition(pos.x(), pos.y(), pos.z());        //object_move (mObj, pos.x (), pos.z (), pos.y ());} // projektil.cpp - (De-)Inits Bullet and calls stepSimulation#include &lt;kaym_common.h&gt; /* Richtet Bullet ein * Parameter: Ork Handle * Rückgaben: Keine */void projektil_setup (ork_t *ork) { // &lt;- called on start up        ork-&gt;broadphase = new btDbvtBroadphase();        ork-&gt;collisionConfiguration = new btDefaultCollisionConfiguration();        ork-&gt;dispatcher = new btCollisionDispatcher(ork-&gt;collisionConfiguration);        ork-&gt;solver = new btSequentialImpulseConstraintSolver;        ork-&gt;dynamicsWorld = new btDiscreteDynamicsWorld(ork-&gt;dispatcher, ork-&gt;broadphase, ork-&gt;solver, ork-&gt;collisionConfiguration);        ork-&gt;dynamicsWorld-&gt;setGravity(btVector3(0,-10,0));} /* Gibt Daten von Bullet im Ork Handle wieder frei * Parameter: Ork Handle * Rückgaben: Keine */void projektil_shutdown (ork_t *ork) {        delete ork-&gt;broadphase;        delete ork-&gt;collisionConfiguration;;        delete ork-&gt;dispatcher;        delete ork-&gt;solver;        delete ork-&gt;dynamicsWorld;} /* Berechnet den nächsten Physik Schritt und setzt die Objekte entsprechend * Parameter: Ork Handle, FrameEvent (von OGRE) * Rückgaben: Keine */void projektil_update_handler (int eventid, ork_t *ork, const Ogre::FrameEvent *evt, void *user_data) {        float hz = ((float)evt-&gt;timeSinceLastFrame) ? 1.0f / (float)evt-&gt;timeSinceLastFrame : 1.0f;         //DBG ("projektil_update_handler, %fHz", hz);        ork-&gt;dynamicsWorld-&gt;stepSimulation (1.0f/hz);/* Other things I tried: (No change)//DBG ("projektil_update_handler, %fHz", hz);//ork-&gt;dynamicsWorld-&gt;stepSimulation ((btScalar)evt-&gt;timeSinceLastFrame, 10); //(hz);//ork-&gt;dynamicsWorld-&gt;stepSimulation (0.01f, 20);ork-&gt;dynamicsWorld-&gt;stepSimulation (1/60.f, 10);*/} // I use this function to add a rigidBody (Planes or Boxes)void primitive_setup_physics (ork_primitive *ret, btVector3 pos, btQuaternion rot, btVector3 size, btScalar mass, btVector3 inertia) {        INFO("Richte Physik ein für ein OrkPrimitive. type = %i Pos(%f %f %f) Size(%f %f %f) Inertia(%f %f %f) State: %p",                ret-&gt;type, pos.getX(), pos.getY(), pos.getZ(), size.getX(), size.getY(), size.getZ(),                inertia.getX(), inertia.getY(), inertia.getZ(), ret-&gt;state);         if (ret-&gt;state) {                ret-&gt;world-&gt;ork-&gt;dynamicsWorld-&gt;removeRigidBody (ret-&gt;rigidBody);                 ret-&gt;state-&gt;~ProjektilMotionState ();                delete ret-&gt;state;                 ret-&gt;rigidBody-&gt;~btRigidBody ();                delete ret-&gt;rigidBody;        }         //printf ("Erstelle Physikform... ");        switch (ret-&gt;type) {                case TYPE_BOX:                //      printf ("TYPE_BOX ");                        ret-&gt;shape = new btBoxShape (size);                        break;                case TYPE_PLANE:                //      printf ("TYPE_PLANE ");                        ret-&gt;shape = new btStaticPlaneShape (size, 1); // Wofür ist die 1 ?                        break;                default:                        FAIL("Unbekannter OrkPrimitive Typ: %i", ret-&gt;type);                        break;        }        //printf ("OK\n");         ret-&gt;mass = mass;        ret-&gt;inertia.x = (float)inertia.getX();        ret-&gt;inertia.y = (float)inertia.getY();        ret-&gt;inertia.z = (float)inertia.getZ();        ret-&gt;state = new ProjektilMotionState (btTransform(rot, pos), (ork_object*)ret);        ret-&gt;shape-&gt;calculateLocalInertia (mass, inertia);        btRigidBody::btRigidBodyConstructionInfo BodyCI (mass, ret-&gt;state, ret-&gt;shape, inertia);        ret-&gt;rigidBody = new btRigidBody (BodyCI);         ret-&gt;world-&gt;ork-&gt;dynamicsWorld-&gt;addRigidBody (ret-&gt;rigidBody);        //printf ("OK\n");}</code></pre></div>Some info about my code:<br>1. In my code the Z-axis is the one pointing up ("Internal" functions are using the "Y-Axis is upwards" scheme though)<br>2. <em class="text-italics">ork_t</em> is a structure that holds all the data used by the engines. <em class="text-italics">ork_object</em> is a structure that<br>holds data about a single object.<br>3. I don't like C++, so I'm using C function names (Have to add <em class="text-italics">extern "C"</em>), so I can code a game in plain C.<br>4. The obvious one: I hope i didn't forgot any important code part. When you need more info about something, please ask<br>rather than ignoring my post ...<br><br>Here are the ork_t and ork_object Structures:<div class="codebox"><p>Code: </p><pre><code>#define ORK_OBJECT_HEADER const ork_object_header *header; \  ork_world *world; \  bool linked; \  Ogre::SceneNode *node; \  Ogre::MeshPtr mesh; \  Ogre::Entity *entity; \  btCollisionShape *shape; \  btDefaultMotionState *state; \  btRigidBody *rigidBody;/* The ork_object struct is reimplemented by any displayable object * Its used so that one can use the "standard functions" (like object_move, _rotate, ...) * on any graphical object. The only thing any of these structures shares * is the ORK_OBJECT_HEADER */typedef struct struct_ork_object {ORK_OBJECT_HEADER} ork_object;// The OrkPrimitive struct is one of these graphical objectstypedef struct {ORK_OBJECT_HEADERint type;vec3 pos;vec3 rot;vec3 scale;vec3 inertia;btScalar mass;bool visible;} ork_primitive;typedef struct struct_ork_t {/// Ork.Worldork_world *world;/// OGRERoot *mRoot;RenderWindow *mWindow;OrkFrameListener *mFrameListener;/// BulletbtBroadphaseInterface *broadphase;btDefaultCollisionConfiguration *collisionConfiguration;btCollisionDispatcher *dispatcher;btSequentialImpulseConstraintSolver *solver;btDiscreteDynamicsWorld *dynamicsWorld;/// Pythonpyork_t *py;/// LibLenlen_handle_t *events;} ork_t;// My 3D vectortypedef struct {float x;float y;float z;} vec3;</code></pre></div>So, i hope that was enough (too much...?) input for understanding my code so far <img class="smilies" src="https://pybullet.org/Bullet/phpBB3/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><br>Thanks in advance <img class="smilies" src="https://pybullet.org/Bullet/phpBB3/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=7638">Papierkorb</a> — Wed Jan 12, 2011 5:57 pm</p><hr />
]]></content>
	</entry>
	</feed>
