#include "smlmath.h"
Class SMLVec3f is a 3x1 vector of single precision floats. It includes data and methods, which allow forming 3-vectors, computing sum, difference, scalar and cross product of two vectors, computing product and quotient of vector and scalar value, finding normalized vector, etc.
float x;
float y;
float z;
Defines 3 components of the vector.
[top]
SMLLIBENTRY SMLVec3f(float a, float b, float c);
SMLVec3f object constructor. This constructor sets coordinates of vector equal to a, b, c correspondingly.
Example:
SMLVec3f A(3.5f, 0.45f, 1.4f);
a, b, c - coordinates of new vector. These parameters should be of float type.
[top]
SMLLIBENTRY SMLVec3f(float v[]);
SMLVec3f object constructor. The constructor sets the coordinates of vector equal to first three elements of float-type array v.
Example:
float crd[3] = {1, 3, 2}; SMLVec3f A(crd);
v[] - float-type array with coordinates of new vector. The array must have at least three elements.
[top]
SMLLIBENTRY SMLVec3f(const SMLVec3f& v);
SMLVec3f copy-constructor. The constructor sets coordinates of vector equal to those of vector v.
Example:
float crd[3] = {1, 3, 2};
SMLVec3f A(crd);
SMLVec3f B(A);
v - reference to an object of SMLVec3f type.
[top]
SMLLIBENTRY SMLVec3f();
Default SMLVec3f object constructor. The constructor sets all coordinates of vector equal to zero.
Example:
SMLVec3f A();
No.
[top]
SMLLIBENTRY const float* data() const;
SMLLIBENTRY float* data();
Methods are used for access to component data of the object, which are coordinates of a vector.
Example:
float *tmp, crd[3] = {1, 3, 2};
SMLVec3f A(crd);
tmp = A.data(); // tmp[1] = 3
No.
Methods return float-type pointer to the first element of component data of the object.
[top]
SMLLIBENTRY float X() const;
Method is used for access to variable x of component data of the object. This variable is x-coordinate of the current vector.
Example:
float tmp, crd[3] = {1, 3, 2};
SMLVec3f A(crd);
tmp = A.X(); // tmp = 1
No.
Methods returns value of variable x of component data of the object.
[top]
SMLLIBENTRY float& X();
Method is used as synonym of variable x of component data of the object.
No.
Methods returns reference to variable x of component data of the object.
[top]
SMLLIBENTRY float Y() const;
Method is used for access to variable y of component data of the object. This variable is y-coordinate of the current vector.
Example:
float tmp, crd[3] = {1, 3, 2};
SMLVec3f A(crd);
tmp = A.Y(); // tmp = 3
No.
Methods returns value of variable y of component data of the object. This variable is y-coordinate of the current vector.
[top]
SMLLIBENTRY float& Y();
Method is used as synonym of variable y of component data of the object.
No.
Methods returns reference to variable y of component data of the object.
[top]
SMLLIBENTRY float Z() const;
Method is used for access to variable z of component data of the object. This variable is z-coordinate of the current vector.
Example:
float tmp, crd[3] = {1, 3, 2};
SMLVec3f A(crd);
tmp = A.Z(); // tmp = 2
No.
Methods returns value of variable z of component data of the object.
[top]
SMLLIBENTRY float& Z();
Method is used as synonym of variable z of component data of the object.
No.
Methods returns reference to variable z of component data of the object.
[top]
SMLLIBENTRY const SMLVec3f& operator=(const SMLVec3f& v);
Method is an overloaded operator-function. It sets coordinates of this vector to those of vector v.
Example:
float crd[3] = {1, 3, 2};
SMLVec3f A(crd), B;
B = A;
v - reference to object of SMLVec3f type whose coordinates are assigned to the new vector.
Returns reference to SMLVec3f-type object.
[top]
friend SMLLIBENTRY bool operator<(const SMLVec3f& v1, const SMLVec3f& v2);
Friend of the class. Function compares length of 2 vectors and returns true, if and only if vector v1 is shorter than v2.
Example:
float crd1[3] = {1, 2, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
A = (A > B)?A:B // A = B
[top]
friend SMLLIBENTRY bool operator==(const SMLVec3f& v1, const SMLVec3f& v2);
Friend of the class. Function returns true, if components of two vectors are equal to each other.
Example:
float crd1[3] = {1, 2, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
A = (A == B)?A:B // A = B
[top]
friend SMLLIBENTRY bool operator!=(const SMLVec3f& v1, const SMLVec3f& v2);
Friend of the class. Function returns true, if components of two vectors are not equal.
Example:
float crd1[3] = {1, 2, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
A = (A != B)?A:B // A = A
[top]
SMLLIBENTRY SMLVec3f operator+(const SMLVec3f& v) const;
Method is an overloaded operator-function. It computes and returns sum of two vectors.
Example:
float crd1[3] = {1, 2, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2), C;
C = A + B // C = {3, 4, 4}
v - reference to object of SMLVec3f type.
Returns new object of SMLVec3f type, which is equal to sum of two vectors.
[top]
SMLLIBENTRY SMLVec3f operator-(const SMLVec3f& v) const;
Method is an overloaded operator-function. It computes and returns difference of two vectors.
Example:
float crd1[3] = {1, 2, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2), C;
C = A - B // C = {-1, 0, 0}
v - reference to object of SMLVec3f type.
Returns new object of SMLVec3f type, which is equal to difference of two vectors.
[top]
SMLLIBENTRY SMLVec3f operator*(float var) const;
Method is an overloaded operator-function. It computes and returns product of vector and variable var.
Example:
float crd[3] = {1, 2, 2};
SMLVec3f A(crd), C;
C = A * 2.0f // C = {2, 4, 4}
var - variable of float type.
Returns new object of SMLVec3f type, which is equal to product of vector and variable.
[top]
SMLLIBENTRY SMLVec3f operator/(float var) const;
Method is an overloaded operator-function. It computes and returns quotient of vector and variable var.
Example:
float crd[3] = {4, 2, 2};
SMLVec3f A(crd), C;
C = A / 2.0f // C = {2, 1, 1}
var - variable of float type.
Returns new object of SMLVec3f type, which is quotient of vector and variable.
[top]
SMLLIBENTRY SMLVec3f& operator+=(const SMLVec3f& v);
Method is an overloaded operator-function. It computes sum of two vectors. The result is assigned to the first vector.
Example:
float crd1[3] = {1, 3, 2}, crd2[2] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
A += B // A = {3, 5, 4}
v - reference to object of SMLVec3f type.
Returns reference to current object of SMLVec3f type, which is sum of two vectors.
[top]
SMLLIBENTRY SMLVec3f& operator-=(const SMLVec3f& v);
Method is an overloaded operator-function. It computes difference of two vectors. The result is assigned to the first vector.
Example:
float crd1[3] = {1, 3, 2}, crd2[2] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
A -= B // A = {-1, 1 ,0}
v - reference to object of SMLVec3f type.
Returns reference to current object of SMLVec3f type, which is difference of two vectors.
[top]
SMLLIBENTRY SMLVec3f& operator*=(float var);
Method is an overloaded operator-function. It computes product of vector and variable. The result is assigned to the first vector.
Example:
float crd[3] = {1, 3, 2};
SMLVec3f A(crd);
A *= 2.0f // C = {2, 6, 4}
v - reference to object of SMLVec3f type.
Returns reference to the current object of SMLVec3f type, which is product of two vectors.
[top]
SMLLIBENTRY SMLVec3f& operator/=(float var);
Method is an overloaded operator-function. It computes quotient of vector and variable. The result is assigned to the first vector.
Example:
float crd[3] = {4, 6, 2};
SMLVec3f A(crd);
A /= 2.0f // C = {2, 3, 1}
var - reference to object of SMLVec3f type.
Returns reference to the current object of SMLVec3f type, which is quotient of the vector and variable.
[top]
SMLLIBENTRY float& operator[](int index);
Method is an overloaded operator-function. It gives access to the element of component data with index index.
Example:
float tmp, crd[3] = {1, 3, 2};
SMLVec3f A(crd);
tmp = A[1]; // tmp = 3
index - index of element of component data of the object.
Returns reference to the element of component data with index index of the current object of SMLVec3f type.
[top]
SMLLIBENTRY float operator[](int index) const;
Method is an overloaded operator-function. It gives access to the element of component data with index index.
index - index of element of component data of the object.
Returns element of component data with index index of the current object of SMLVec3f type.
[top]
SMLLIBENTRY void Set(const SMLVec3f& v);
Method sets coordinates of vector equal to those of vector v.
Example:
float crd[3] = {1, 3, 2};SMLVec3f A(crd);
SMLVec3f B(A) ;
v - reference to vector whose coordinates are assigned to this vector.
[top]
SMLLIBENTRY void Set(float x, float y, float z);
Method sets coordinates of vector equal to variables x, y, z.
Example:
SMLVec3f A(); A.Set(1.0f, 2.0f, -4.3f);
x, y, z - new coordinates of the vector.
[top]
SMLLIBENTRY void Add(const SMLVec3f& vec1, const SMLVec3f& vec2);
Method sets coordinates of vector equal to sum of corresponding coordinates of two vectors vec1 and vec2.
Example:
float crd1[3] = {1, 3, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2), C;
C.Add(A, B); // C = {3, 5, 4}
vec1, vec2 - vectors to be added .
[top]
SMLLIBENTRY void Sub(const SMLVec3f& vec1, const SMLVec3f& vec2);
Method sets coordinates of vector equal to difference of corresponding coordinates of two vectors vec1 and vec2.
Example:
float crd1[3] = {1, 3, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2), C;
C.Sub(A, B); // C = {-1, 1, 0}
vec1, vec2 - vectors, difference of which is to be computed.
[top]
SMLLIBENTRY void Scale(float var, const SMLVec3f& v);
Method sets coordinates of vector equal to product of variable var and vector v.
Example:
float crd[3] = {1, 3, 2};
SMLVec3f A(crd1);
A.Scale(2.0f); // A = {2, 6, 4}
var - variable of float type (scale parameter).
v - reference to vector to be scaled.
[top]
SMLLIBENTRY void ScaleAdd(float var, const SMLVec3f& vec1, const SMLVec3f& vec2);
Method sets coordinates of vector equal to sum of scaled vector vec1 and vector vec2 with scale parameter var. this = var*vec1 + vec2.
Example:
float crd1[3] = {1, 3, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2), C;
C.ScaleAdd(2.0f, A, B); // C = {4, 8, 6}
var - variable of float type (scale parameter).
vec1 - vector to be scaled.
vec2 - vectors to be not scaled.
[top]
SMLLIBENTRY float Dot(const SMLVec3f& vec) const;
Method computes scalar product of this vector and vector vec.
Example:
float sp, crd1[3] = {1, 3, 2}, crd2[3] = {2, 2, 2};
SMLVec3f A(crd1), B(crd2);
sp = A.Dot(B); // sp = 12
vec - reference to the second vector of the scalar product.
Returns scalar product of this vector and vector vec.
[top]
SMLLIBENTRY float Dot(const float * const vec) const;
Method computes scalar product of this vector and constant vector defined with constant pointer vec.
vec - constant pointer to the second constant vector of the scalar product.
Returns scalar product of this vector and vector vec.
[top]
SMLLIBENTRY const SMLVec3f& Negate();
Method replaces this vector with vector (-x, -y -z).
Example:
SMLVec3f A(1, 3, 2); A.Negate(); // A = {-1, -3, -2}
No.
Methods returns reference to the current object.
[top]
SMLLIBENTRY float Length() const;
Method computes length of this vector.
Example:
float l;
SMLVec3f A(3,4,5); l = A.Length();
No.
Methods returns length of this vector.
[top]
SMLLIBENTRY float LengthSquared() const;
Method computes length squared of this vector.
Example:
float ls;
SMLVec3f A(3,4,5); ls = A.LengthSquared();
No.
Methods returns length squared of this vector.
[top]
SMLLIBENTRY float Distance(const SMLVec3f& vec) const;
Method computes distance between this point and vector vec.
Example:
float d;
SMLVec3f A(3,4,1), B(4,3,2);
d = A.Distance(B);
vec - radius-vector of the second point. Reference to object of SMLVec3f type.
Methods returns distance between two points.
[top]
SMLLIBENTRY float DistanceSquared(const SMLVec3f& vec) const;
Method computes distance squared between this point and vector vec.
Example:
float ds;
SMLVec3f A(2,4,1), B(4,3,2);
ds = A.Distance(B);
vec - radius-vector of the second point. Reference to object of SMLVec3f type.
Methods returns distance squared between two points.
[top]
SMLLIBENTRY void Cross(const SMLVec3f& vec);
Method computes cross product of two vectors. The first one is this vector and the second vector is defined with reference vec. Result is written into this vector.
vec - reference to SMLVec3f-type object.
[top]
SMLLIBENTRY float operator*(const SMLVec3f& vec) const;
Method is an overloaded operator-function. It computes scalar product of this vector and vector vec. Result is written into this vector.
vec - reference to object of SMLVec3f type.
Returns scalar product of the vectors.
[top]
SMLLIBENTRY float Normalize();
Method normalizes this vector. If length of the vector is smaller than 1 / FLT_EPSILON, the normalized vector is created in accordance with general rules, i. e. normalized vector is equal to this vector divided on its length. If norm of the vector is greater than 1 / FLT_EPSILON, the method forms unit vector with coordinates {0; 1; 0}.
Example:
float n;
SMLVec3f A(3,4,2);
n = A.Normalize();
No.
Methods returns value equal to the inverted length of this vector.
[top]
SMLLIBENTRY void TransformPoint(const SMLMatrix4f& matr, const SMLVec3f& vec);
Method transforms coordinates of given point in accordance with matrix matr. The main minor (submatrix 3X3) of the matrix represents the rotation transformation of coordinates of the point, while the first three elements of the last column of the matrix depicts coordinates of some vector which are to be added to coordinates of the point after their rotation transformation. Coordinates of new point are assigned to this vector.
matr - reference to SMLMatrix4f-type object which contains transformation matrix.
vec - reference to object of SMLVec3f type with coordinates of the point which are to be transformed.
[top]
SMLLIBENTRY void TransformVector(const SMLMatrix4f& matr, const SMLVec3f& vec);
Method transforms coordinates of given vector in accordance with matrix matr. The main minor of the matrix represents the rotation transformation of coordinates of the point. Coordinates of new vector are assigned to this vector.
matr - reference to SMLMatrix4f-type object which contains transformation matrix.
vec - reference to object of SMLVec3f type with coordinates of the point which are to be transformed.
[top]