HOME > natural science Laboratory > コンピュータ・シミュレーション講座 > 仮想物理実験室

クォータニオンによる視点の移動 (WebGL(Three.js))

文責:遠藤 理平 (2012年4月16日) カテゴリ:WebGL(46)仮想物理実験室(325)

3 3 3 稿3 WebGLThree.js  Javascript 


\mathbf{R}\mathbf{v}\theta\mathbf{R'}



314 \mathbf{R'}\mathbf{R}2 70使4 Quaternion 70

Javascript


WebGL 使glMatrix.js

glMatrix.js


glMatrix.js 
var P = new quat4.create([x,y,z,w]);

x,y,z  i,j,k w2
var P = new quat4.create([x1,y1,z1,w1]);
var Q = new quat4.create([x2,y2,z2,w2]);
var R = quat4.multiply(P,Q, quat4.create());



 v = [vx, vy, vz]   u = [ux, uy, uz] theta 
function QuaternionRotation(theta, u, v){ //(回転角, 回転軸, 座標ベクトル)
  var P = new quat4.create([v[0],v[1],v[2],0]);
  var Q = new quat4.create([-u[0]*Math.sin(theta/2), -u[1]*Math.sin(theta/2), -u[2]*Math.sin(theta/2), Math.cos(theta/2)]);
  var R = new quat4.create([u[0]*Math.sin(theta/2), u[1]*Math.sin(theta/2), u[2]*Math.sin(theta/2), Math.cos(theta/2)]);
  var S0 = quat4.multiply(P,Q, quat4.create());
  var S =  quat4.multiply(R,S0,quat4.create());  
  var V = [S[0],S[1],S[2]];
  return V;
}




20123 google  WebGL  google z=x^2+y^23 3


 dx, dy  稿2 canvas 


canvas dxdy 0,0,0 3360,0,01

 dx, dy  \mathbf{R}\mathbf{a}



dx\mathbf{u}dy\mathbf{w} Ra2 \mathbf{u}=\mathbf{a}\mathbf{w}=\mathbf{R} imes\mathbf{u} 稿

1R\mathbf{a}
2R\mathbf{a}2\mathbf{u},\mathbf{w}
3 dx, dy \theta_u\theta_w
4\mathbf{u}, \mathbf{w}\theta_u\theta_w
5

稿


HTML5 canvas  WebGLThree.js WebGL



HTML5 canvas  WebGL  Three.js 

1R\mathbf{a}

R = new vec3.create([camera.position.x,camera.position.y,camera.position.z]); // 視点の位置ベクトルの取得
a = new vec3.create([camera.up.x, camera.up.y, camera.up.z]);                 // 視点の上向きベクトルの取得

vec3  glMatrix.js 3 \mathbf{u}\mathbf{w}

2R\mathbf{a}2\mathbf{u},\mathbf{w}

u = vec3.set(a, vec3.create());       // a のコピー
u = vec3.normalize(u, vec3.create()); // u の規格化
w = vec3.cross(R, u ,vec3.create());  // R × u の演算
w = vec3.normalize(w, vec3.create()); // w の規格化

glMatrix.js  vec3 3
vec3.setvec3.normalizevec3.cross

3 dx, dy \theta_u\theta_w

theta_u =  dx / 100;
theta_w = -dz / 100;

100  50  100  200 

4\mathbf{u}, \mathbf{w}\theta_u\theta_w


\mathbf{u}\theta_u \mathbf{w}
S = QuaternionRotation(theta_u, u, [camera.position.x, camera.position.y, camera.position.z]);
S = QuaternionRotation(theta_w, w, [S[0],S[1],S[2]]);

5


4google 3D \mathbf{w}
S = QuaternionRotation(theta_w, w, [camera.up.x,camera.up.y,camera.up.z]);
camera.up.set(S[0],S[1],S[2]);

稿姿WebGL


▲このページのトップNPO法人 natural science トップ

関連記事

WebGL

仮想物理実験室







▲このページのトップNPO法人 natural science トップ




Warning: mysqli_connect(): (28000/1045): Access denied for user 'xsvx1015071_ri'@'sv102.xserver.jp' (using password: YES) in /home/xsvx1015071/include/natural-science/include_counter-d.php on line 8
MySQL DBとの接続に失敗しました