Code archives/3D Graphics - Maths/Blitz3D Maths Library
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
(full code probably too long, so it's split in 4 parts) All the maths involved to rebuild a blitz3d like entity system Originally done for a blitzmax 3d engine, all behaviors reproduice perfectly the Turn/Rotate/Move etc ... of the blitz3d entity Here is a Blitz3d version of the library. It also include some color templates to be used as vector. Note : The Vector type use a 4 th component "W" originally used for alignement, It's also usefull to store an extra value, like a radius, so a vector can define a sphere. All class are designed for OOP usage, so they all returns the object passed in the argument of the function. It allows to imbricate function calls in a single line. Also, the functions with "Self" in the name happens the transformation on the first object passed in the argument -> it does not create a new object. Local a.Vector = NewVector() Local b.Vector = NewVector() Local c.Vector = VecSub(a,b) -> create a new vector Local d.Vector = VecSelfSub(a,b) -> this will store the result of a-b in a and will return a, so "d" is "a" As it's Blitz3D (and not blitzmax), take care of memory leak ! If you create an instance of a maths object, don't forget to release it -> Vector quand Quaternion can be freed using "Delete" as they don't store internal objects -> Matrix3 and Matrix4 MUST be freed using Mat3Free(m3) and Mat4Free(m4) (because they store vectors as axis [and position for the matrix4 object]) ; Worklog : V1.001 - Fix an error in VecSub (y was added instead of substract) | |||||
; -------------------------------------------------------------------- ; - Maths Library - ; -------------------------------------------------------------------- ; - Author : Bobysait 2016 ; - About : Full compatible with the Blitz3D Entity stuff. ; the library is a portage of the Bigbang Maths module. ; whatever, see license aggreement below. ; - license : no restrictions. ; Feel free to use for any purpose ; After all, it's just a maths lib. ; -------------------------------------------------------------------- |
Comments
| ||
The Vector part : |
| ||
The Quaternion part : |
| ||
The Matrix3 part : |
| ||
The Matrix4 part : |
| ||
nice work Bobysait! perhaps some sample demos to compare with b3d builtin equivalent? |
| ||
I'll see if I can make this tomorrow, it's 0h47 here, I'm going to sleep ;) ps : I didn't mention it, but the vector part also contains some kind of GLSL portability with conversion -> v.xy() v.zx() etc ... There is no documention, but it's a maths library, everything is self-explained |
| ||
I might actually have a use for some of this in my ongoing Newton/OpenB3D fumbling, thanks for posting it! |
| ||
So, here is a small demo of transformation it shows how to reproduice the blitz-entities transformations using this maths library. Also a bench test in the end for creating 10000 pivots and rotate them compared to creating 10000 transforms and rotate them /!\ just one note, math stuff in blitz code is slower than anything writen in c/c++ as the internal blitz maths are, so keep in mind a pivot rotation, for example, will still be faster than a rotation of a transform like I did, but, the creation time is a lot faster, so what we loose somewhere is gained somewhere else. Then, this stuff is just for purpose, maths transformation does not require a full "transform" object, most of the time, we just need a vector or a rotation, not a full stuff to rebuild a 4*4 matrix. ps : (a ps before the code ... whatever) the sample below also provides working PointEntity and AlignToVector replicants. Hope it helps. [edit] TForm functions added to the sample. |
Code Archives Forum