3D Transformations?
Blitz3D Forums/Blitz3D Programming/3D Transformations?
| ||
I wrote a working Quaternion lib, and I have some matrix commands written in Blitz. I want to do 3D transformations like Blitz3D does for child-parent relationships (but in BlitzPlus). Given 3 float values for x,y, and z position of a point, say a vertex in a mesh, and an x,y,z,w quaternion rotation, what is the adjusted point position. In other words, what would it's position be in world coordinates? Function Tranform(x#,y#,z#,qx#,qy#,qz#,qw#) End Function If you want the quat lib it's at www.leadwerks.com/code/userlibs/maths3d |
| ||
This SHOULD work, according to the book I am using, but doesn't, which is not all that surprising: Ax,y,z is the 3D point and x,y,z,w is the quat rotation. Should I be storing full 4x4 matrices, or just a quat and a position for each entity? Any words of wisdom from THE MAN? Function TransformPoint(Ax#,Ay#,Az#,x#,y#,z#,w#) ;Create a temporary 3x3 matrix mat11#=1-2*y^2-2*z^2 mat12#=2*x*y+2*w*z mat13#=2*x*z-2*w*y mat21#=2*x*y-2*w*z mat22#=1-2*x^2-2*z^2 mat23#=2*y*z+2*w*x mat31#=2*x*z+2*w*y mat32#=2*y*z-2*w*x mat33#=1-2*x^2-2*y^2 ;Multiple the position and temp matrices as if they were two complete matrices newx#=Ax*mat11+Ay*mat21+Az*mat31 newy#=Ax*mat12+Ay*mat22+Az*mat32 newz#=Ax*mat13+Ay*mat23+Az*mat33 ;Store values for retrieval FillVector newx,newy,newz,0 End Function |
| ||
Sorry man my linear algebra is a little rusty at the moment :) |
| ||
Got the conversions for Quaternions to matrices in B3D. I guess my question now is should I store a full 4x4 matrix, a 4x3 matrix, or just a 3-value position and 4-value quaternion? Function QuatAsMatrix#(x,y,z,w) mat00#=1-2*x^2-2*z^2 mat01#=-(2*z*y+2*w*x) mat02#=2*w*z-2*x*y mat10#=-(2*z*y-2*w*x) mat11#=1-2*y^2-2*x^2 mat12#=2*x*z+2*w*y mat20#=-(2*x*y+2*w*z) mat21#=-(2*w*y-2*x*z) mat22#=1-2*z^2-2*y^2 End Function |