[SML Overview]

class SMLVec4f

#include "smlmath.h"

Class SMLVec4f is a 4x1 vector of single precision floats. It includes data and methods, which allow forming 4-vectors, computing sum, difference, scalar product of two vectors, computing product and quotient of vector and scalar value, finding normalized vector, etc.

Public Interface

Constructors

constructors

Access the data as an array

data

Rename to XYZW

X

Y

Z

Rename to RGBA

Red

Green

Blue

Alpha

Operators

operator==

operator!=

operator<

operator+

operator-

operator+=

operator-=

operator*

operator/

operator*=

operator/=

Methods

Set

Add

Sub

Scale

ScaleAdd

Dot

Transform

Dot

Negate

Add

Sub

Scale

Length

LengthSquared

Normalize

Distance

DistanceSquared

operator=


Public Data

float x;

float y;

float z;

float w;

Defines 4 components of the vector.

[top]


SMLLIBENTRY SMLVec4f(float a, float b, float c, float d);

Discussion

SMLVec4f object constructor. This constructor sets coordinates of vector equal to a, b, c, d correspondingly.

Example:

SMLVec4f A(3.5f, 0.45f, 1.4f, -2.0f);

Parameters

a, b, c, d - coordinates of new vector. These parameters should be of float type.

[top]


SMLLIBENTRY SMLVec4f(float v[]);

Discussion

SMLVec4f object constructor. The constructor sets the coordinates of vector equal to first four elements of float-type array v.

Example:

float crd[4] = {1, 3, 2, 1}; SMLVec4f A(crd);

Parameters

v[] - float-type array with coordinates of new vector. The array must have at least four elements.

[top]


SMLLIBENTRY SMLVec4f(const SMLVec4f& v);

Discussion

SMLVec4f object constructor. The constructor sets coordinates of vector equal to those of vector v.

Example:

float crd[4] = {1, 3, 2, 1};
SMLVec4f A(crd);
SMLVec4f B(A);

Parameters

v - reference to an object of SMLVec4f type.

[top]


SMLLIBENTRY SMLVec4f();

Discussion

Default SMLVec4f object constructor. The constructor sets all coordinates of vector equal to zero.

Example:

SMLVec4f A();

Parameters

No.

[top]


SMLLIBENTRY const float* data() const;

SMLLIBENTRY float* data();

Discussion

Methods are used for access to component data of the object which are coordinates of a vector.

Example:

float *tmp, crd[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.data(); // tmp[1] = 3

Parameters

No.

Return Value

Methods return float-type pointer to the first element of component data of the object.

[top]


SMLLIBENTRY float X() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.X(); // tmp = 1

Parameters

No.

Return Value

Methods returns value of variable x of component data of the object.

[top]


SMLLIBENTRY float& X();

Discussion

Method is used as synonym of variable x of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable x of component data of the object.

[top]


SMLLIBENTRY float Y() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Y(); // tmp = 3

Parameters

No.

Return Value

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();

Discussion

Method is used as synonym of variable y of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable y of component data of the object.

[top]


SMLLIBENTRY float Z() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Z(); // tmp = 2

Parameters

No.

Return Value

Methods returns value of variable z of component data of the object.

[top]


SMLLIBENTRY float& Z();

Discussion

Method is used as synonym of variable z of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable z of component data of the object.

[top]


SMLLIBENTRY float W() const;

Discussion

Method is used for access to variable w of component data of the object. This variable is w-coordinate of the current vector.

Example:

float tmp, crd[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.W(); // tmp = 4

Parameters

No.

Return Value

Methods returns value of variable w of component data of the object.

[top]


SMLLIBENTRY float& W();

Discussion

Method is used as synonym of variable w of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable w of component data of the object.

[top]


SMLLIBENTRY float Red() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Red(); // tmp = 1

Parameters

No.

Return Value

Methods returns value of variable x of component data of the object.

[top]


SMLLIBENTRY float& Red();

Discussion

Method is used as synonym of variable x of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable x of component data of the object.

[top]


SMLLIBENTRY float Green() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Green(); // tmp = 3

Parameters

No.

Return Value

Methods returns value of variable y of component data of the object.

[top]


SMLLIBENTRY float& Green();

Discussion

Method is used as synonym of variable y of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable y of component data of the object.

[top]


SMLLIBENTRY float Blue() const;

Discussion

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[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Blue(); // tmp = 2

Parameters

No.

Return Value

Methods returns value of variable y of component data of the object.

[top]


SMLLIBENTRY float& Blue();

Discussion

Method is used as synonym of variable z of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable z of component data of the object.

[top]


SMLLIBENTRY float Alpha() const;

Discussion

Method is used for access to variable w of component data of the object. This variable is w-coordinate of the current vector.

Example:

float tmp, crd[4] = {1, 3, 2, 4};
SMLVec4f A(crd);
tmp = A.Alpha(); // tmp = 4

Parameters

No.

Return Value

Methods returns value of variable w of component data of the object

[top]


SMLLIBENTRY float& Alpha();

Discussion

Method is used as synonym of variable w of component data of the object.

Parameters

No.

Return Value

Methods returns reference to variable w of component data of the object.

[top]


SMLLIBENTRY const SMLVec4f& operator=(const SMLVec4f& v);

Discussion

Method is an overloaded operator-function. It sets coordinates of this vector to those of vector v.

Example:

float crd[4] = {1, 3, 2, 4};
SMLVec4f A(crd), B;
B = A;

Parameters

v - reference to object of SMLVec4f type whose coordinates are assigned to the new vector.

Return Value

Returns reference to SMLVec4f-type object.

[top]


friend SMLLIBENTRY bool operator<(const SMLVec4f& src, const SMLVec4f& v);

Discussion

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[4] = {1, 2, 2, 2}, crd2[3] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
A = (A > B)?A:B // A = B

[top]


friend SMLLIBENTRY bool operator==(const SMLVec4f& src, const SMLVec4f& v);

Discussion

Friend of the class. Function returns true, if components of two vectors are equal to each other.

Example:

float crd1[4] = {1, 2, 2, 2}, crd2[3] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
A = (A == B)?A:B // A = B

[top]


friend SMLLIBENTRY bool operator!=(const SMLVec4f& src, const SMLVec4f& v);

Discussion

Friend of the class. Function returns true, if components of two vectors are not equal.

Example:

float crd1[4] = {1, 2, 2, 2}, crd2[3] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
A = (A != B)?A:B // A = B

[top]


SMLLIBENTRY SMLVec4f operator+(const SMLVec4f& v) const;

Discussion

Method is an overloaded operator-function. It computes and returns sum of two vectors.

Example:

float crd1[4] = {1, 2, 2, 3}, crd2[4] = {2, 2, 2, 3};
SMLVec3f A(crd1), B(crd2), C;
C = A + B // C = {3, 4, 4, 6}

Parameters

v - reference to object of SMLVec4f type.

Return Value

Returns new object of SMLVec4f type, which is equal to sum of two vectors.

[top]


SMLLIBENTRY SMLVec4f operator-(const SMLVec4f& v) const;

Discussion

Method is an overloaded operator-function. It computes and returns difference of two vectors.

Example:

float crd1[4] = {1, 2, 2, 3}, crd2[4] = {2, 2, 2, 3};
SMLVec3f A(crd1), B(crd2), C;
C = A - B // C = {-1, 0, 0, 0}

Parameters

v - reference to object of SMLVec4f type.

Return Value

Returns new object of SMLVec4f type, which is equal to difference of two vectors.

[top]


SMLLIBENTRY SMLVec3f operator*(float var) const;

Discussion

Method is an overloaded operator-function. It computes and returns product of vector and variable var.

Example:

float crd[4] = {1, 2, 2, 3};
SMLVec4f A(crd), C;
C = A * 2.0f // C = {2, 4, 4, 6}

Parameters

var - variable of float type.

Return Value

Returns new object of SMLVec4f type, which is equal to product of vector and variable.

[top]


SMLLIBENTRY SMLVec4f operator/(float var) const;

Discussion

Method is an overloaded operator-function. It computes and returns quotient of vector and variable var.

Example:

float crd[4] = {1, 2, 2, 3};
SMLVec4f A(crd), C;
C = A / 2.0f // C = {0.5, 2, 2, 1.5}

Parameters

var - variable of float type.

Return Value

Returns new object of SMLVec4f type, which is quotient of vector and variable.

[top]


SMLLIBENTRY SMLVec3f& operator+=(const SMLVec4f& v);

Discussion

Method is an overloaded operator-function. It computes sum of two vectors. The result is assigned to the first vector.

Example:

float crd1[4] = {1, 3, 2, 1}, crd2[2] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
A += B // A = {3, 5, 4, 3}

Parameters

v - reference to object of SMLVec4f type.

Return Value

Returns reference to current object of SMLVec4f type, which is sum of two vectors.

[top]


SMLLIBENTRY SMLVec4f& operator-=(const SMLVec4f& v);

Discussion

Method is an overloaded operator-function. It computes difference of two vectors. The result is assigned to the first vector.

Example:

float crd1[4] = {1, 3, 2, 1}, crd2[2] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
A -= B // A = {-1, 1, 0, -1}

Parameters

v - reference to object of SMLVec4f type.

Return Value

Returns reference to current object of SMLVec4f type, which is difference of two vectors.

[top]


SMLLIBENTRY SMLVec4f& operator*=(float var);

Discussion

Method is an overloaded operator-function. It computes product of vector and variable var. The result is assigned to this vector.

Example:

float crd[4] = {1, 3, 2, 1};
SMLVec4f A(crd);
A *= 2.0f // C = {2, 6, 4, 2}

Parameters

v - reference to object of SMLVec4f type.

Return Value

Returns reference to the current object of SMLVec4f type, which is product of vector and variable var now.

[top]


SMLLIBENTRY SMLVec3f& operator/=(float var);

Discussion

Method is an overloaded operator-function. It computes quotient of vector and variable. The result is assigned to this vector.

Example:

float crd[4] = {1, 3, 2, 1};
SMLVec4f A(crd);
A /= 2.0f // C = {0.5, 1.5, 1, 0.5}

Parameters

var - reference to object of SMLVec3f type.

Return Value

Returns reference to the current object of SMLVec3f type, which is quotient of the vector and variable.

[top]


SMLLIBENTRY void Set(float x, float y, float z, float w);

Discussion

Method sets coordinates of vector equal to variables x, y, z, w.

Parameters

x, y, z, w - new coordinates of the vector.

[top]


SMLLIBENTRY void Add(const SMLVec4f& vec1, const SMLVec4f& vec2);

Discussion

Method sets coordinates of vector equal to sum of corresponding coordinates of two vectors vec1 and vec2.

Example:

float crd1[4] = {1, 3, 2, 1}, crd2[3] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2), C;
C.Add(A, B); // C = {3, 5, 4, 3}

Parameters

vec1, vec2 - vectors to be added .

[top]


SMLLIBENTRY void Sub(const SMLVec4f& vec1, const SMLVec4f& vec2);

Discussion

Method sets coordinates of vector equal to difference of corresponding coordinates of two vectors vec1 and vec2.

Example:

float crd1[4] = {1, 3, 2, 1}, crd2[3] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2), C;
C.Sub(A, B); // C = {-1, 1, 0, -1}

Parameters

vec1, vec2 - vectors, difference of which is to be computed.

[top]


SMLLIBENTRY void Scale(float var, const SMLVec4f& v);

Discussion

Method sets coordinates of vector equal to product of variable var and vector v.

Example:

float crd[4] = {1, 3, 2, 1};
SMLVec4f A(crd1);
A.Scale(2.0f); // A = {2, 6, 4, 2}

Parameters

var - variable of float type (scale parameter).

v - reference to vector to be scaled.

[top]


SMLLIBENTRY void Transform(const SMLMatrix4f& matr, const SMLVec4f& vec);

Discussion

Method transforms coordinates of vector vec in accordance with matrix of SMLMatrix4f object matr. It computes product of the matrix and the vector. The transformed vector is a vector of component data of current object.

Parameters

matr - reference to object of SMLMatrix4f type, which defines transformation matrix.

vec - reference to vector to be transformed. Object of SMLVec4f type.

[top]


SMLLIBENTRY void Transform(const SMLMatrix4f& matr, const SMLVec3f& vec);

Discussion

Method transforms coordinates of given vector vec in accordance with component matrix of SMLMatrix4f object matr. Method computes product of three first columns of the matrix and the vector then to obtained vector it adds the last column of the matrix. Coordinates of new vector are assigned to component vector of SMLVec4f-type object for which this method is called, i.e. the transformed vector is component data of current object.

Parameters

matr - reference to object of SMLMatrix4f type, which defines transformation matrix.

vec - reference to vector to be transformed. Object of SMLVec3f type.

[top]


SMLLIBENTRY float Dot(const SMLVec4f& vec) const;

Discussion

Method computes scalar product of this vector and vector vec.

Parameters

vec - reference to the second vector of the scalar product.

Example:

float sp, crd1[4] = {1, 3, 2, 1}, crd2[2] = {2, 2, 2, 2};
SMLVec4f A(crd1), B(crd2);
sp = A.Dot(B); // sp = 14

Return Value

Returns scalar product of this vector and vector vec.

[top]


SMLLIBENTRY const SMLVec4f& Negate();

Discussion

Method replaces this vector with vector (-x, -y, -z, -w).

Example:

SMLVec4f A(1, 3, 2, 1); A.Negate(); // A = {-1, -3, -2, -1}

Parameters

No.

Return Value

Methods returns reference to this vector.

[top]


SMLLIBENTRY float Length() const;

Discussion

Method computes length of this vector.

Example:

float l;
SMLVec4f A(3,4,5,8); l = A.Length();

Parameters

No.

Return Value

Methods returns length of this vector.

[top]


SMLLIBENTRY float LengthSquared() const;

Discussion

Method computes length squared of this vector.

Example:

float ls;
SMLVec4f A(3,4,5,8); ls = A.LengthSquared();

Parameters

No.

Return Value

Methods returns length squared of this vector.

[top]


SMLLIBENTRY float Distance(const SMLVec4f& vec) const;

Discussion

Method computes distance between two points. The first point is defined by this vector, the second vector is defined by reference vec.

Example:

float d;
SMLVec4f A(3,4,1,2), B(4,3,2,5);
d = A.Distance(B);

Parameters

vec - radius-vector of the second point. Reference to object of SMLVec4f type.

Return Value

Methods returns distance between two points.

[top]


SMLLIBENTRY float DistanceSquared(const SMLVec4f& vec) const;

Discussion

Method computes distance squared between two points. The first point is defined by this vector, the second vector is defined by reference vec.

Example:

float ds;
SMLVec4f A(2,4,2,1), B(4,3,1,1);
ds = A.Distance(B);

Parameters

vec - radius-vector of the second point. Reference to object of SMLVec4f type.

Return Value

Methods returns distance squared between two points.

[top]


SMLLIBENTRY float Normalize();

Discussion

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; 0}.

Example:

float n;
SMLVec4f A(3,4,2,1);
n = A.Normalize();

Parameters

No.

Return Value

Methods returns value equal to the inverted length of this vector.

[top]