JSR-184與Mascot Capsule v3主要的不同就是關(guān)于照相機的實現(xiàn)。JSR-184支持照相機結(jié)合矩陣堆棧處理,例如,我們經(jīng)常使用transform對象移動照相機。而Mascot Capsule v3依靠”look-at”方法,這是在某些3D API里的通用方法。look-at方法從一個position,一個 look-at direction和一個up vector創(chuàng)建一個照相機轉(zhuǎn)換矩陣,為了方便Mascot Capsule v3與JSR-184之間的轉(zhuǎn)換,Digital Chocolate采納了Mascot Capsule v3照相機設(shè)計方法,并寫了一個支持JSR-184的包。
在JSR-184 API規(guī)范里,NodeTransform類指定了一系列方法。這些方法有利于在JSR-184實現(xiàn)look-at方法。然而,它被認為與JSR-184執(zhí)行說明規(guī)范有所不同,有時甚至會忽略這一系列方法。
自己實現(xiàn)look-at方法其實并不復(fù)雜。下面的代碼例子是Digital Chocolate公司如何處理照相機的封裝設(shè)計。請注意Digital Chocolate公司在Mascot Capsule v3中使用整數(shù)來處理,而在設(shè)計更高層的游戲類設(shè)計中使用浮點數(shù)來處理。
/**  float inv_len = 1.0f / 
(float) java.lang.Math.sqrt(sideX * sideX 
+ sideY * sideY 
+ sideZ * sideZ);
  sideX *= inv_len;
  sideY *= inv_len;
  sideZ *= inv_len;
    
  // make up vector perpendicular
  a_upX = (sideY * a_lookZ) - (sideZ * a_lookY);
  a_upY = (sideZ * a_lookX) - (sideX * a_lookZ);
  a_upZ = (sideX * a_lookY) - (sideY * a_lookX);
  // footnote: up is unit size because side and look are perpendicular
 
  sm_mtx[0] = sideX;
  sm_mtx[1] = a_upX;
  sm_mtx[2] = -a_lookX;
  sm_mtx[3] = a_posX; 
  sm_mtx[4] = sideY;
  sm_mtx[5] = a_upY;
  sm_mtx[6] = -a_lookY;
  sm_mtx[7] = a_posY; 
  sm_mtx[8] = sideZ;
  sm_mtx[9] = a_upZ;
  sm_mtx[10] = -a_lookZ;
  sm_mtx[11] = a_posZ; 
  sm_mtx[12] = 0.0f;
  sm_mtx[13] = 0.0f;
  sm_mtx[14] = 0.0f;
  sm_mtx[15] = 1.0f;
 
  sm_m3gTransform.set(sm_mtx); 
 }
 // Mascot version
 if (USE_MASCOT) 
{
  sm_mascotTmpVectorA.set((int)a_posX, (int)a_posY, (int)a_posZ);
  sm_mascotTmpVectorB.set((int)(a_lookX * MASCOT_ONE),
(int)(a_lookY * MASCOT_ONE), 
(int)(a_lookZ * MASCOT_ONE));
  sm_mascotTmpVectorC.set(0, DajmGraphics.MASCOT_ONE, 0);
  sm_mascotAffineTrans.lookAt(sm_mascotTmpVectorA, 
sm_mascotTmpVectorB, 
sm_mascotTmpVectorC);
 }
}
(出處:http://m.survivalescaperooms.com)
新聞熱點
疑難解答