2013年10月27日 星期日

ODE教學<四>矩陣資料

The Matrix Details



The ODE library uses a 3x3 matrix in mathematical notation, i.e. row first, column second. However, internally ODE stores
its matrices as a 4x4 ordered matrix, padded with 0's. The good news is that the dBodyGetRotation function we used to 
retrieve the rotation matrix in DrawGeom above returns a 4x3 rotation matrix. So the ODEtoOGL function transposes the
elements over to the OpenGL order (column first, row second) and plugs in the position vector into the 12th, 13th and
14th elements. 



        | 0  1  2  3  |            | 0  4  8  12 |
        |             |            |             |
    R = | 4  5  6  7  |            | 1  5  9  13 |
        |             |        M = |             |
        | 8  9  10 11 |            | 2  6  10 14 |
                                   |             |
    p = | 0  1  2 |                | 3  7  11 15 |





And you're done!



You deserve a cuppa and a pat on the back if you were able to get most of that. We've come a long way from the days of 
manually rendering a polygon pixel by pixel along a scanline, now we can also add realistic rigid body physics to our programs. 



You may have noticed that the gravity and density values being used in this example are a little strange. Higher values
caused the box to penetrate too far into the ground surface or to fall right through the ground. I believe this is due to
the slow message loop or other timing issues as it isn't as noticeable when using a separate rendering thread.




沒有留言:

張貼留言