Für C++ gibts schöne Bibliotheken, GLM zum Beispiel. Und genau diese hab ich jetzt zum großen Teil für PB übersetzt:
https://github.com/GPIforGit/math/releases/
Es gibt zwei Möglichkeiten, die Sammlung zu nutzen:
1) Einfach das Verzeichnis in dein Projekt kopieren und so einbinden:
Code: Alles auswählen
XIncludeFile "math/math.pbi"
Code: Alles auswählen
XIncludeFile #PB_Compiler_Home + "Include/math/math.pbi"
Es gibt 4 Vektoren
- math::vec2
- math::vec3
- math::vec4
ein Quaternion
- math::quat
und viele Matrixen:
- math::mat2x2
- math::mat2x3
- math::mat2x4
- math::mat3x2
- math::mat3x3
- math::mat3x4
- math::mat4x2
- math::mat4x3
- math::mat4x4
einfaches Beispiel:
Code: Alles auswählen
Define.math::vec3 v1,v2,vres
math::vec3_set(v1, 1,2,3)
math::vec3_set(v2, 2,4,5)
math::vec3_add(vres, v1,v2)
Debug math::string(vres)
Code: Alles auswählen
Define.math::vec3 v1,v2,vres
math::set_float(v1, 1,2,3)
math::set_float(v2, 2,4,5)
math::add(vres, v1,v2)
Debug math::string(vres)
Code: Alles auswählen
Define.math::vec3 v
Define.math::vec3 vres
Define.math::mat3x3 m
math::set_float(m, 1) ; createas a identity matrix
math::set_float(v,2) ; set all values of the vector to 2
math::mul(vres, m, v) ; equals vres = m4*v
Debug math::string(vres) + " = " + math::string(m) + " * " + math::string(v)
Code: Alles auswählen
Define.math::vec3 v
Define.math::vec3 vres
Define.math::mat3x3 m
math::Mat3x3_set_Scalar(m, 1) ; createas a identity matrix
math::vec3_set_Scalar(v,2) ; set all values of the vector to 2
math::Mat3x3_mul_Vec3(vres, m, v) ; equals vres = m4*v
Debug math::string(vres) + " = " + math::string(m) + " * " + math::string(v)
Es gibt eine menge an Proceduren, dot, length, cross usw.
res in math:: - for example dot, length, cross and so on.
In der "test.pb" gibt es weitere Beispiele.