09
Nov
Black Art of Java Game Programming by Joel
Mathematically this can be expressed using matrix operations in the following way (the matrixes can be found in Appendix E, 3D Transforms): Using the generic matrix class implemented in Appendix E, this series of transforms can be coded like this: //– transform the vertices from MCS to WCS matrix.makeIdentity(); //– make the identity matrix matrix.concatS(Sx,Sy,Sz); //– scaling matrix.concatRx(Ax); //– rotate about X-axis matrix.concatRy(Ay); //– rotate about Y-axis matrix.concatRz(Az); //– rotate about Z-axis matrix.concatT(Xpos,Ypos,Zpos); //– translate matrix.transform(Vm,Vw); //– transform points This series of transforms can be called the MCS to WCS transform. Since this is a tedious procedure, we will expand the generic matrix and hide these transforms in a convenient method called makeMCStoWCStransform( ). This way all the math will be hidden and make the code into a mathfree zone. After our architect discovers that he can mathematically transform vertices from MCS to WCS, he gets all carried away and wonders how his house would look if somebody took a picture of it from an arbitrary angle and position. He knows the position of the camera in WCS and also its orientation (angle). Figure 11-15 illustrates this. Figure 11-15 The camera has a position and angle in the world The View Coordinate System (VCS) Since the camera is now the center of attention, we could think of its position as the center of the universe. The direction of the principal axes depends on the angle of the camera. Suppose that the architect has all the coordinates defined in WCS. The same vertices will not have the same coordinates in the VCS. This is realized by comparing a vertex with the principal axes of WCS and VCS. What he needs to do is to somehow calculate the coordinates of the vertices with respect to the VCS as in Figure 11-16.
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services
