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

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2013-08-28T20:40:21+00:00</updated>

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

		<entry>
		<author><name><![CDATA[konri100]]></name></author>
		<updated>2013-08-28T20:40:21+00:00</updated>

		<published>2013-08-28T20:40:21+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=31630#p31630</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=31630#p31630"/>
		<title type="html"><![CDATA[btKinematicCharacterController, forward dir is not forward]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=31630#p31630"><![CDATA[
So i've got problem with btKinematicCharacterController.<br><br>White lines are bullet debug lines.<br>Red arrow is where the forward dir is supposed to be.<br>Red lines is where the front of the object is supposed to be.<br>Green arrow is where the forward dir really is, at least in this direction the object is going to.<br><br>Ogre mesh has inverted rotation so it faces the right direction.<br><br><img src="http://img845.imageshack.us/img845/4027/bb1g.jpg" class="postimage" alt="Image"><br><img src="http://img59.imageshack.us/img59/3897/iyz5.jpg" class="postimage" alt="Image"><br><img src="http://img692.imageshack.us/img692/9766/je8e.jpg" class="postimage" alt="Image"><br><br>Some code:<br><div class="codebox"><p>Code: </p><pre><code>    Ogre::Entity* ent = pSceneMgr-&gt;createEntity("SinbadBody", "Sinbad.mesh");    Ogre::SceneNode* sphereNode = pSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode();    sphereNode-&gt;attachObject(ent);    Ogre::Vector3 halfsize = ent-&gt;getBoundingBox().getHalfSize();    ent-&gt;setCastShadows(true);    sphereNode-&gt;setPosition(0,20,0);    btConvexShape* capsule = new btBoxShape(ToBullet(halfsize));    characterBody = pBullet-&gt;addGhostObject(sphereNode-&gt;getPosition(), capsule, sphereNode);    btScalar stepHeight = btScalar(0.35);    Character = new btKinematicCharacterController(characterBody,capsule,stepHeight);    Character-&gt;setJumpSpeed(15);    pBullet-&gt;getWorld()-&gt;addCollisionObject(characterBody,btBroadphaseProxy::CharacterFilter,     btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);    pBullet-&gt;getWorld()-&gt;addAction(Character);</code></pre></div>in main loop:<div class="codebox"><p>Code: </p><pre><code>//character    Ogre::SceneNode* characterNode = (Ogre::SceneNode*)(characterBody-&gt;getUserPointer());    bool forward = false, backward = false, left = false, right = false, jump = false;    if(pKeyboard-&gt;isKeyDown(OIS::KC_A))    {        left = true;    }    else if(pKeyboard-&gt;isKeyDown(OIS::KC_D))    {        right = true;    }    if(pKeyboard-&gt;isKeyDown(OIS::KC_W))    {        forward = true;    }    else if(pKeyboard-&gt;isKeyDown(OIS::KC_S))    {        backward = true;    }    if(pKeyboard-&gt;isKeyDown(OIS::KC_SPACE))    {        jump = true;    }    btTransform xform;    xform = characterBody-&gt;getWorldTransform();    btVector3 forwardDir = xform.getBasis()[2];    btVector3 upDir = xform.getBasis()[1];    btVector3 strafeDir = xform.getBasis()[1];    forwardDir.normalized();    upDir.normalized();    strafeDir.normalized();    btVector3 walkDirection(0,0,0);    btScalar walkVelocity(1.1*8.0);// 4 km/h -&gt; 1.1 m/s    btScalar walkSpeed(walkVelocity*(DeltaTime/1000.0f));    Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode*&gt;(characterBody-&gt;getUserPointer());    if(left)    {        turnAngle -= DeltaTime * 0.003f;    }    if(right)    {        turnAngle += DeltaTime * 0.003f;    }    xform.setRotation(btQuaternion (btVector3(0.0, 1.0, 0.0), turnAngle));    characterBody-&gt;setWorldTransform (xform);    //here is inverted(?) turnAngle of ogre mesh, so it faces the right direction that the bullet kinematic character is going to    node-&gt;setOrientation(Ogre::Quaternion(-(Ogre::Radian)turnAngle, Ogre::Vector3(0.0, 1.0, 0.0)));    if(forward)    {        walkDirection += forwardDir;    }    if(backward)    {        walkDirection -= forwardDir;    }    if(jump &amp;&amp; Character-&gt;canJump())    {        Character-&gt;jump();    }    Character-&gt;setWalkDirection(walkDirection * walkSpeed);</code></pre></div>in main loop:<div class="codebox"><p>Code: </p><pre><code>    World-&gt;stepSimulation(Delta, 60);    for(list&lt;btRigidBody*&gt;::iterator It = Objects.begin(); It != Objects.end(); ++It)    {        Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode*&gt;((*It)-&gt;getUserPointer());        btVector3 Point = (*It)-&gt;getCenterOfMassPosition();        node-&gt;setPosition(Ogre::Vector3((float)Point[0], (float)Point[1], (float)Point[2]));        btQuaternion btq = (*It)-&gt;getOrientation();        Ogre::Quaternion quart = Ogre::Quaternion(btq.w(),btq.x(),btq.y(),btq.z());        node-&gt;setOrientation(quart);}for(list&lt;btPairCachingGhostObject*&gt;::iterator it = GhostObjects.begin(); it != GhostObjects.end(); ++it)    {Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode*&gt;((*it)-&gt;getUserPointer());        btVector3 Point = (*it)-&gt;getWorldTransform().getOrigin();        node-&gt;setPosition(Ogre::Vector3(Point[0], Point[1], Point[2]));}World-&gt;debugDrawWorld();</code></pre></div>EDIT:<br><br>I did some more tests and here is the code that works perfectly, but i get forward dir not from bullet but from ogre, so maybe i did something wrong with bullet or the forward dir from bullet is wrong:<br><div class="codebox"><p>Code: </p><pre><code>    btTransform xform;    xform = characterBody-&gt;getWorldTransform();    btVector3 walkDirection(0,0,0);    btScalar walkVelocity(1.1*8.0);// 4 km/h -&gt; 1.1 m/s    btScalar walkSpeed(walkVelocity*(DeltaTime/1000.0f));    Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode*&gt;(characterBody-&gt;getUserPointer());    btVector3 forwardDir = ToBullet(node-&gt;getOrientation() * Ogre::Vector3(0, 0, 1));    forwardDir.normalized();    if(left)    {        turnAngle += DeltaTime * 0.003f;    }    if(right)    {        turnAngle -= DeltaTime * 0.003f;    }    xform.setRotation(btQuaternion (btVector3(0.0, 1.0, 0.0), turnAngle));    characterBody-&gt;setWorldTransform (xform);    if(forward)    {        walkDirection = forwardDir;    }    if(backward)    {        walkDirection = -forwardDir;    }    if(jump &amp;&amp; Character-&gt;canJump())    {        Character-&gt;jump();    }    Character-&gt;setWalkDirection(walkDirection * walkSpeed);</code></pre></div>in main loop:<div class="codebox"><p>Code: </p><pre><code>    for(list&lt;btPairCachingGhostObject*&gt;::iterator it = GhostObjects.begin(); it != GhostObjects.end(); ++it)    {Ogre::SceneNode* node = static_cast&lt;Ogre::SceneNode*&gt;((*it)-&gt;getUserPointer());        btVector3 Point = (*it)-&gt;getWorldTransform().getOrigin();        node-&gt;setPosition(Ogre::Vector3(Point.getX(), Point.getY(), Point.getZ()));        btQuaternion btq = (*it)-&gt;getWorldTransform().getRotation();        Ogre::Quaternion quart = Ogre::Quaternion(btq.w(),btq.x(),btq.y(),btq.z());        node-&gt;setOrientation(quart);}</code></pre></div>So did i just get forward dir from bullet in wrong way or it's buggy?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=10416">konri100</a> — Wed Aug 28, 2013 8:40 pm</p><hr />
]]></content>
	</entry>
	</feed>
