凡人の日々の経過を記録
カレンダー
カテゴリー
リンク
最新記事
(03/21)
(03/11)
(03/05)
(03/02)
(02/06)
ブログ内検索
コガネモチ
ODEユーザ?としては、とりあえずdrawstuffで表示できるとなんとなくわかるような気になれるので、
とりあえずdrawstuffで表示出来るかを試してみました。 #include <btBulletDynamicsCommon.h> #include <iostream> #include <drawstuff/drawstuff.h> btDiscreteDynamicsWorld* dynamicsWorld = NULL; btCollisionShape* fallShape = NULL; btRigidBody* fallRigidBody = NULL; void QtoR( float Q[4], float R[12] ) { // q = (s,vx,vy,vz) float qq1 = 2*Q[1]*Q[1]; float qq2 = 2*Q[2]*Q[2]; float qq3 = 2*Q[3]*Q[3]; R[0*4+0] = 1 - qq2 - qq3; R[0*4+1] = 2*(Q[1]*Q[2] - Q[0]*Q[3]); R[0*4+2] = 2*(Q[1]*Q[3] + Q[0]*Q[2]); R[0*4+3] = 0.0; R[1*4+0] = 2*(Q[1]*Q[2] + Q[0]*Q[3]); R[1*4+1] = 1 - qq1 - qq3; R[1*4+2] = 2*(Q[2]*Q[3] - Q[0]*Q[1]); R[1*4+3] = 0.0; R[2*4+0] = 2*(Q[1]*Q[3] - Q[0]*Q[2]); R[2*4+1] = 2*(Q[2]*Q[3] + Q[0]*Q[1]); R[2*4+2] = 1 - qq1 - qq2; R[2*4+3] = 0.0; } // start simulation - set viewpoint static void start() { static float xyz[3] = { 0.f, -15.f, 5.f }; static float hpr[3] = { 90.f, -5.f, 0.f }; dsSetViewpoint( xyz, hpr ); // カメラ位置と方向設定 } // simulation loop static void simLoop( int pause ) { // Ctl+p が押されたらifに入らない if (!pause) { dynamicsWorld->stepSimulation( 0.01f, 10 );// 世界を進める } if (fallRigidBody) { btTransform trans; fallRigidBody->getMotionState()->getWorldTransform(trans); float pos[3] = { trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ() }; float Q[4] = { trans.getRotation().getW(), trans.getRotation().getX(), trans.getRotation().getY(), trans.getRotation().getZ() }; float R[12]; QtoR( Q, R ); dsSetColor( 1, 1, 0 ); // RGB Color // 球体の表示 if (fallShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE) { float radius = reinterpret_cast<btSphereShape*>(fallShape)->getRadius(); dsDrawSphere( pos, R, radius ); } // Boxの表示 if (fallShape->getShapeType() == BOX_SHAPE_PROXYTYPE) { const btVector3 halfext = reinterpret_cast<btBoxShape*>(fallShape)->getHalfExtentsWithoutMargin(); float size[3] = { halfext.getX()*2, halfext.getY()*2, halfext.getZ()*2 }; dsDrawBox( pos, R, size ); } } } int main( int argc, char* argv[] ) { /////////////////////////////////////////////////////////////////////////// // setup pointers to drawstuff callback functions dsFunctions fn; fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = 0; fn.stop = 0; fn.path_to_textures = "../drawstuff/textures"; /////////////////////////////////////////////////////////////////////////// // ワールドの広さ (10km 四方) btVector3 worldAabbMin(-10000,-10000,-10000); // プロキシ最大数 btVector3 worldAabbMax(10000,10000,10000); int maxProxies = 1024; btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies); // broadphase準備 // デフォルトの衝突設定 btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); // ディスパッチャ作成 btCollisionDispatcher* dispatcher = new btCollisionDispatcher( collisionConfiguration ); // ソルバ btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; // ワールド生成 dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); // 重力設定 dynamicsWorld->setGravity(btVector3(0,0,-10)); // z軸方向(-10m/s^2) // 地面の生成 btCollisionShape* groundShape; btRigidBody* groundRigidBody; { groundShape = new btStaticPlaneShape(btVector3(0,0,1),1); btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,-1))); btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0,0,0)); groundRigidBody = new btRigidBody(groundRigidBodyCI); dynamicsWorld->addRigidBody(groundRigidBody); } // 落下物体の生成 btDefaultMotionState* fallMotionState; { //fallShape = new btSphereShape(1); // 球体 (半径) fallShape = new btBoxShape(btVector3(1,1,1)); // Box(サイズx, y, z) fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,10))); // 姿勢と位置 btScalar mass = 1; // 質量 btVector3 fallInertia(0,0,0); // 慣性 fallShape->calculateLocalInertia(mass, fallInertia); btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallShape, fallInertia ); fallRigidBody = new btRigidBody(fallRigidBodyCI); dynamicsWorld->addRigidBody( fallRigidBody ); } /////////////////////////////////////////////////////////////////////////// // シミュレーション dsSimulationLoop( argc, argv, 600, 400, &fn ); /////////////////////////////////////////////////////////////////////////// // 終了処理 dynamicsWorld->removeRigidBody( fallRigidBody ); delete fallRigidBody->getMotionState(); delete fallRigidBody; dynamicsWorld->removeRigidBody( groundRigidBody ); delete groundRigidBody->getMotionState(); delete groundRigidBody; delete fallShape; delete groundShape; delete dynamicsWorld; delete solver; delete collisionConfiguration; delete dispatcher; delete broadphase; //btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld( dispatcher, ); return 0; } とりあえず、できたっぽいです。 1034 PR この記事にコメントする
この記事へのトラックバック
Powered by 忍者ブログ
Design by © まめの
Copyright © [ ずくのない凡人の日記 ] All Rights Reserved. http://bambooflow.blog.shinobi.jp/ |