
|
May 2005
|
|
|
| |
|
One of the major differences between JSR-184 and Mascot Capsule v3 is camera implementation. JSR-184 supports camera handling with a matrix stack, i.e. the camera can be moved by using regular transform objects. Mascot Capsule v3 relies on a "look-at" method which is common in several 3D APIs. The look-at method creates a camera transform matrix from a position, a look-at direction and an up vector. To ease the porting between Mascot Capsule v3 and JSR-184, Digital Chocolate has adopted the Mascot Capsule v3 camera design and written a wrapper to support it in JSR-184. The JSR-184 API specifies an alignment method for NodeTransform classes. This could have been useful for implementing a look-at method for JSR-184. However, it has been recognized that vendors of JSR-184 implementations interpret the specification differently and sometimes even ignore the align method. Writing a look-at method of your own is actually not that hard. The following code sample illustrates how Digital Chocolate handled the camera in their wrapper design. Note that Digital Chocolate have abstracted the use of fixed point values in Mascot Capsule v3 and rely fully on floating point math in the design of the higher level game classes. /**
* Wrapper method for setting look at camera. * * The method requires that look and up vectors normalized. */ public static final void setLookAt(float a_posX, float a_posY, float a_posZ, float a_lookX, float a_lookY, float a_lookZ, float a_upX, float a_upY, float a_upZ) { // JSR-184 version if (USE_M3G) { // Cross product to get side vector float sideX = (a_lookY * a_upZ) - (a_lookZ * a_upY); float sideY = (a_lookZ * a_upX) - (a_lookX * a_upZ); float sideZ = (a_lookX * a_upY) - (a_lookY * a_upX); 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); } } More information
| |
Copyright © 2001 - 2009 Sony Ericsson Mobile Communications AB. All Rights Reserved.