2017年9月10日日曜日

dRFromAxisAndAngle ode

dRFromAxisAndAngle ode


dRFromAxisAndAngleの回転方向がわからなったのでテスト
以下コードを付け加えると上画像のように回転する
   //x軸を中心にx軸+方向で時計回転方向にに30°まわす
    dMatrix3 R;
  dRFromAxisAndAngle( R, 1.0, 0.0, 0.0, 30.0*M_PI/180 );
  dBodySetRotation( box.body, R );



c:\ode-0.11.1\myprg\dRFromAxisAndAngle_my\dRFromAxisAndAngle_my.cpp


/* ODE tutorial  by Kosei Demura     */
/* sample4.cpp :Lesson 4 3D Graphics */
// ボックス,を描画するプログラム
//dRFromAxisAndAngleで姿勢を回転させる
// 衝突検出,動力学計算はしていません.

#include
#include

#ifdef _MSC_VER
#pragma warning(disable:4244 4305)  // VC++用警告を止める
#endif

#ifdef dDOUBLE
#define dsDrawBox      dsDrawBoxD
#define dsDrawSphere   dsDrawSphereD
#define dsDrawCylinder dsDrawCylinderD
#define dsDrawCapsule  dsDrawCapsuleD
#define dsDrawLine     dsDrawLineD
#endif

#define DENSITY (5.0)    // 密度


struct MyObject {
  dBodyID body;        // ボディ(剛体)
};

dReal sides[3] = {0.5,0.5,1.0}; // 辺の長さ
dReal pos[3]   = {0.0,0.0,3.0};


static dWorldID world;  // 動力学計算ワールド
static MyObject sphere, box, capsule, cylinder; // 物体

// start simulation
static void start()
{
  static float xyz[3] = {5,3,0.5};    // 視点[m]
  static float hpr[3] = {-180, 0, 0}; // 視線[°]
  dsSetViewpoint (xyz,hpr);           // 視点と視線の設定
}


// シミュレーションループ
static void simLoop (int pause)
{
  const dReal *pos1,*R1,*pos2,*R2,*pos3,*R3;

  // ボックスの描画
  dsSetColorAlpha (0,0,1,1);
  pos3 = dBodyGetPosition(box.body);
  R3   = dBodyGetRotation(box.body);
  dsDrawBox(pos3,R3,sides);             // ボックスの描画

}

int main (int argc, char **argv)
{
  // drawstuffの設定
  dsFunctions fn;
  fn.version = DS_VERSION;
  fn.start   = &start;
  fn.step    = &simLoop;
  fn.command = NULL;
  fn.stop    = NULL;
  fn.path_to_textures = "../../drawstuff/textures";


  dInitODE();              // ODEの初期化
  world = dWorldCreate();  // 動力学計算用ワールドの生成

  dMass m;                 // 質量パラメータ
  dMassSetZero (&m);       // 質量パラメータの設定



  // ボックス
  box.body = dBodyCreate (world);
  dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]);
  dBodySetMass (box.body,&m);
  dBodySetPosition (box.body,pos[0],pos[1],pos[2]);

    //x軸を中心にx軸+方向で時計回転方向にに30°まわす
    dMatrix3 R;
  dRFromAxisAndAngle( R, 1.0, 0.0, 0.0, 30.0*M_PI/180 );
  dBodySetRotation( box.body, R );

  // シミュレーションの実行
  dsSimulationLoop (argc,argv,960,480,&fn);

  dWorldDestroy (world); // ワールドの破壊
  dCloseODE();           // ODEの終了

  return 0;
}

0 件のコメント:

コメントを投稿

About

参加ユーザー

連絡フォーム

名前

メール *

メッセージ *

ページ

Featured Posts