//下の関数が呼ばれる前にこれをしておく if(x3domRuntime == undefined) x3domRuntime = document.getElementById('x3dom_ID名').runtime; //lookat//注視 function viewp() { if(!x3domRuntime) return; var elm = document.getElementById('viewp001'); var SWM = x3domRuntime.viewMatrix().inverse(); //ワールド回転行列取得 var WM = new N6LMatrix().FromX3DOM(SWM); var Seye = SWM.multMatrixPnt(new x3dom.fields.SFVec3f(0, 0, 0)); //視点位置取得 var sp = bx.ToX3DOM(true); //注視目標 var Sat = x3dom.fields.SFVec3f.copy(sp); var lookat = new N6LVector([1.0, Sat.x, Sat.y, Sat.z], true); //注視目標セット var LAM = WM.LookAtMat2(lookat); //目的の関数 var Vec = LAM.Vector(); var ori = Vec.ToX3DOM(); elm.setAttribute('position', Seye.toString()); elm.setAttribute('orientation', ori.toString()); //elm.setAttribute('centerOfRotation', sp.toString()); }
//オブジェクト位置情報 //位置4*4マトリクス(継続パラメータ) var A = false; //速度(継続パラメータ) var V = 0.1; var a = 0; var pyr = new N6LVector([1, 0, 0, 0], true); //以上のように初期化してから、下の関数を呼び続ける //加速度a,(スカラー量)(新規パラメータ) //ピッチヨーロール(1, θp, θy, θr)(新規パラメータ) function moveobj(wa, wpyr) { if(!A) { if(x3domRuntime) { var vm = x3domRuntime.viewMatrix().inverse(); //ワールド回転行列取得 A = new N6LMatrix().FromX3DOM(vm); } else return; } var outmat = []; var outv = []; var WA = A.MoveMat(outmat, outv, new N6LVector(4, true).ZeroVec(), wpyr, V, wa, 0, 5); //目的の関数 //値を適用 V = outv[0].Abs(); A = new N6LMatrix(WA); pyr = new N6LVector([1, 0, 0, 0], true); //x3domに適用 var Vec = A.Vector(); var pos = A.Pos(); var eye = pos.ToX3DOM(true); var ori = Vec.ToX3DOM(); var elm = document.getElementById('viewp001'); elm.setAttribute('position', eye.toString()); elm.setAttribute('orientation', ori.toString()); } //キー入力 var KBLock7 = 0; var KBLock9 = 0; var KBIntvl = 5; function chkKeyBoard(){ if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N1'))]) {//N1Key pyr.x[3] -= 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N2'))]) {//N2Key pyr.x[1] -= 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N3'))]) {//N3Key pyr.x[3] += 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N4'))]) {//N4Key pyr.x[2] -= 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N5'))]) {//N5Key a = 0; } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N6'))]) {//N6Key pyr.x[2] += 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N7'))]) {//N7Key if(KBIntvl < KBLock7) KBLock7 = 0; if(KBLock7 == 0) { a -= 0.005; if(a < -0.5) a = -0.5; } KBLock7++; } else KBLock7 = 0; if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N8'))]) {//N8Key pyr.x[1] += 1 * (Math.PI / 180); } if(KeyB.keystate[KeyB.indexof(KeyB.ToReal('VK_N9'))]) {//N9Key if(KBIntvl < KBLock9) KBLock9 = 0; if(KBLock9 == 0) { a += 0.005; if(0.5 < a) a = 0.5; } KBLock9++; } else KBLock9 = 0; };