Hi All…
I am new to Xojo, but have experience in Visual Basic. My forte is C++.
I took my Matrix and Vector classes I use for my OpenGL programs and ported them to be used in Xojo. I have tested them somewhat by creating an STL Viewer program.
The classes included are:
Vector2 (2D Vector Class)
Vector3 (3D Vector Class)
Vector4 (4D Vector Class)
Matrix2 (2x2 Matrix Class)
Matrix3 (3x3 Matrix Class)
Matrix4 (4x4 Matrix Class)
All matrices are row major. (OpenGL uses column-major matrix)
| 0 1 | | 0 1 2 | | 0 1 2 3 |
| 2 3 | | 3 4 5 | | 4 5 6 7 |
| 6 7 8 | | 8 9 10 11 |
| 12 13 14 15 |
Here is an example on how to use them with OpenGL.
Dim cX as Single, cY as Single, cZ as Single
Self.StlObj.ModelCenter(cX,cY,cZ)
Dim v As New Vector3(cX,cY,cZ)
Dim matView As New Matrix4
matView.translate(-v.x,-v.y,Self.Zoom)
Dim matModel As New Matrix4
matModel.rotateAt(Self.RotateModel,0,1,0,v.opNegate())
OpenGL.glLoadMatrixf(matView.opMultiply(matModel).getTranspose())
Matrix4::getTranspose() converts the matrix to Column-Major and places its contents into a MemoryBlock so it can be used in such OpenGL functions as glLoadMatrixf, glMultMatrixf, etc.
They work pretty much how you’d expect them to. They could probably be optimized a bit by the Xojo pros who understand the language better than I do.
Here is a screen cap of my program using them:
Here is a link to the classes if you are interested.
I am open for critiques or optimizations that could make it even better.
Thanks!
-andy.