PositionEntity and the object's matrix
BlitzMax Forums/MiniB3D Module/PositionEntity and the object's matrix
| ||
I've noticed that if I use PositionEntity on a TMesh and then check it's matrix translation values, the z coordinate(grid[3,2]) has the opposite sign. Is that a bug or is there a good reason for it? |
| ||
Hi, Probably due to the fact that GL uses a right handed coord system while b3d uses a left handed one (or vice versa...). In other words, in GL z's <0 are in front of eye and >0 are behind - the opposite of b3d. Looks like Si has dealt with this by negating z somewhere along the way, but another approach is to use a D3D-like projection matrix instead of the standard glFrustum/gluPerspective ones. Here's what I use: Type TMat4 Field ix#,iy#,iz#,iw# Field jx#,jy#,jz#,jw# Field kx#,ky#,kz#,kw# Field tx#,ty#,tz#,tw# Method glLoadMatrix() glLoadMatrixf Varptr ix End Method Function FromFrustum:TMat4( near_left#,near_right#,near_bottom#,near_top#,near#,far# ) Local t:TMat4=New TMat4 Local near2#=near*2 Local w#=near_right-near_left Local h#=near_top-near_bottom Local d#=far-near t.ix=near2/w t.jy=near2/h t.kx=(near_right+near_left)/w t.ky=(near_top+near_bottom)/h t.kz=(far+near)/d t.kw=1 t.tz=-(far*near2)/d Return t End Function End Type This allows you to use b3d style 'z's everywhere without having to negate anything. Only slightly tricky bit is glFrontFace CW/CCW test flags get reversed. The above is actually the same as the standard glFrustum matrix except for a '1' instead of a '-1'. |
| ||
That makes sense, but I guess I just expected that functions like PositionEntity would be adapted to whatever coordinate system was being used for matrices. Anyway, I have managed to adapt by negating the z at appropriate times. Exporting animations from 3dsMax has proven tricky, but doable. I'm thrilled to have BMax and MiniB3D and Klepto's revisions available. Oh, and I appreciate you taking the time to post. Thanks! :) |