LoginSignup
5
4

More than 5 years have passed since last update.

OimoPhysicsとAway3Dの連携

Last updated at Posted at 2013-07-18

剛体の計算後、以下のコードを実行し、剛体の位置、回転をメッシュに適用するという方針です。
OimoPhysicsの回転系とAway3Dの回転系が異なっていたため、一旦新しくQuaternion を作成しなおしています。

// Away3Dオブジェクト
var box:Mesh;

// OimoPhysicの剛体
var rb:RigidBody;

// OimoPhysicsの回転クォータニオンから回転行列への変換
var qx:Number = rb.orientation.x;
var qy:Number = rb.orientation.y;
var qz:Number = rb.orientation.z;
var qw:Number = rb.orientation.s;
var q:Quaternion = new Quaternion(-qx,-qy, qz, qw);
var qm:Matrix3D = Matrix3DUtils.quaternion2matrix(q);

// Away3Dオブジェクトに割り当てる
var m:Matrix3D = new Matrix3D();
m.append(qm);
var px:Number = rb.position.x * ratio;
var py:Number = rb.position.y * ratio;
var pz:Number = rb.position.z * ratio * -1;
m.appendTranslation(px, py, pz);
box.transform = m;

※実際に使用する際は最適化が必要です。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4