|
yage.core.math.vector
Authors:
Eric Poggel
License:
LGPL v3
- struct
Vec
(int S,T : real,int D = 0);
- This is a template to create a vector of any type with any number of elements.
Use
Vec
.v[0..n] to access the vector's elements directly, or x,y,z,w to access
elements of vector's of size less than or equal to four.
Example:
Vec!(4, real) a; // a is a four-component real vector.
TODO:
Convert looping code to static if's to improve performance.
- T[S]
v
;
- Allow acessiong the vector as an array of values through field
v
, or via .x, .y, .z, etc. up to the number of components.
- T
x
;
- Allow acessiong the vector as an array of values through field v, or via .
x
, .y, .z, etc. up to the number of components.
- T
r
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
y
;
- Allow acessiong the vector as an array of values through field v, or via .x, .
y
, .z, etc. up to the number of components.
- T
g
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
z
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .
z
, etc. up to the number of components.
- T
b
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
w
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
a
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
width
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
height
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
top
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
right
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
bottom
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- T
left
;
- Allow acessiong the vector as an array of values through field v, or via .x, .y, .z, etc. up to the number of components.
- VST
opCall
();
- Create a zero vector
- VST
opCall
(T s);
- Create a vector with all values as s.
- VST
opCall
(T[S] s...);
- Create a new vector with the values s0, s1, s2, ...
- VST
opCall
(T[] s);
- Create a new vector with the values of s; If s is less than the size of the vector, remaining values are set to 0.
- float
angle
(VST s);
- The
angle
between this vector and s, in radians.
- VST
clamp
(T min, T max);
VST
clamp
(VST min, VST max);
- Clamp all values between min and max.
- float
dot
(VST s);
- Return the dot product of this vector and s.
- bool
inside
(VST topLeft, VST bottomRight, bool inclusive = true);
- Is this Vector (as a point)
inside
a box/cube/etc. defined by topLeft and bottomRight
- bool
inside
(VST[] polygon);
- Is this Vector (as a point)
inside
a polygon defined by an array of Points?
See Also:
http:
//www.visibone.com/inpoly
- float
length
();
- Return the length of the vector (the magnitude).
- float
length2
();
- Return the length of the vector squared. This is faster than length().
- VST
opAdd
(VST s);
void
opAddAssign
(VST s);
VST
opSub
(VST s);
void
opSubAssign
(VST s);
VST
opMul
(VST s);
void
opMulAssign
(VST s);
VST
opDiv
(VST s);
void
opDivAssign
(VST s);
- Allow for linear additions, subtractions, multiplcations, and divisions among Vectors of the same size and type.
- void
opMulAssign
(float s);
void
opDivAssign
(float s);
- Allow for additions, subtractions, multiplcations, and divisions where a scalar is applied to each vector component.
- float
opIndex
(size_t i);
- Get the element at i
- float
opIndexAssign
(T value, size_t i);
- Assign value to the element at i
- VST
projection
(VST s);
- Create a new vector with the values of s
- T*
ptr
();
- VST
scale
(float s);
VST
scale
(VST s);
- Scale (multiply) this vector.
- void
set
(T s);
void
set
(VST s);
void
set
(T[S] s...);
- Set the values of the Vector.
- VST
transform
(Matrix m);
- Transform this vector by a Matrix.
- char[]
toString
();
- Return a string representation of this vector for human reading.
- template
toVec
(int S2,T2 : real)
- Convert to one type of Vec to another.
Params:
S2 |
Size (number of components) of new Vec. |
T2 |
type of new Vec. |
- Vec!(S2,T2)
toVec
();
- Convert to one type of Vec to another.
Params:
S2 |
Size (number of components) of new Vec. |
T2 |
type of new Vec. |
- alias
vec2f
;
alias
vec3f
;
alias
vec4f
;
alias
vec2i
;
alias
vec3i
;
alias
vec4i
;
- Convert to these types of vectors
- alias
Vec2i
;
- A two-component int Vec
- alias
Vec3i
;
- A three-component int Vec
- alias
Vec4i
;
- A four-component int Vec
- alias
Vec2f
;
- A two-component float Vec
- alias
Vec4f
;
- A four-component float Vec
- struct
Vec3f
;
- A 3D vector class.
This can be merged with the templated version above when D fixed the forward template declaration bugs.
- static Vec3f
opCall
();
- Create a zero vector
- static Vec3f
opCall
(float s);
- Create a Vec3f with all values as s.
- static Vec3f
opCall
(float x, float y, float z);
- Create a new Vec3f with the values x, y, and z
- static Vec3f
opCall
(float angle, float x, float y, float z);
- Create a new axis-angle Vec3f from rotation angle angle and the values x, y, and z
- static Vec3f
opCall
(float[] s);
- Return a vector with the values of s.
- Vec3f
abs
();
- Return a vector containing the absolute value of each component
- Vec3f
add
(Vec3f s);
- Add another vector into this vector
- bool
almostEqual
(Vec3f s, float fudge = 0.0001F);
- Is this vector equal to vector s, discarding relative error fudge.
- Vec3f
lookAt
(Vec3f direction, Vec3f up);
- float
average
();
- Return the
average
of the x, y, and z components.
- Vec3f
clamp
(float l, float u);
- Vec3f
clamp
(Vec3f l, Vec3f u);
- Vec3f
cross
(Vec3f s);
- Return the
cross
product of this vector with another vector.
- float
dot
(Vec3f s);
- Return the
dot
product of this vector and another.
- float
distance
(Vec3f s);
- Return the
distance
from this vector to another, interpreting each as 3D coordinates.
- float
distance2
(Vec3f s);
- Return the square of the distance from this Vec3f to another, interpreting each as 3D coordinates.
- bool
inside
(Vec3f topLeft, Vec3f bottomRight, bool inclusive = true);
- Is this Vector
inside
a box/cube/etc. defined by topLeft and bottomRight
- Vec3f
inverse
();
- Vec3f
inverseTransform
(Matrix m);
- Unlike a transformation, we first apply the translation and then the rotation.
- Vec3f
inverseRotate
(Matrix m);
- Vec3f
inverseTranslate
(Matrix m);
- float
length
();
- Return the
length
of the vector (the magnitude).
- float
length2
();
- Return the length of the vector squared. This is faster than length().
- Vec3f
length
(float l);
- Return a copy of this vector scaled to
length
l.
- float
max
();
- Return the maximum value of the vector components
- Vec3f
negate
();
- Return a vector with every value of this Vec3f negated.
- Vec3f
normalize
();
- Return a normalized copy of this vector.
- Vec3f
opAdd
(Vec3f s);
- Return the sum of this vector and another.
- Vec3f
opAddAssign
(Vec3f s);
- Add the values of another Vec3f into this one.
- Vec3f
opDiv
(float s);
- Return a copy of this vector with every value divided by s.
- Vec3f
opDivAssign
(float s);
- Divide every value of this vector by s.
- float
opIndex
(ubyte i);
- Get the element at i
- float
opIndexAssign
(float value, ubyte i);
- Assign value to the element at i
- Vec3f
opMul
(float s);
- Return a copy of this vector with every value multiplied by s.
- Vec3f
opMulAssign
(float s);
- Multiply every value of this vector by s.
- Vec3f
opNeg
();
- Return a vector with every value of this vector negated.
- Vec3f
opSub
(Vec3f s);
- Return the difference between this vector and another.
- Vec3f
opSubAssign
(Vec3f s);
- Subtract the values of another vector from this one.
- float*
ptr
();
- Vec3f
projection
(Vec3f s);
- Create a new vector with the values of s
- static Vec3f
random
(float r = cast(float)1);
- Return a vector in a
random
direction between length -r and r.
- Vec3f
rotate
(Vec3f axis);
- Return a copy of this vector rotated by axis, where both are interpreted
as axis-angle vectors.
- Vec3f
rotate
(Quatrn q);
- Return a copy of this Vec3f rotated by the Quatrn q.
Note that this is curently slower than
rotate
(Matrix m).
- Vec3f
rotate
(Matrix m);
- Return a copy of this vector rotated by the rotation values of Matrix m.
- Vec3f
scale
(float s);
- Return a copy of this vector with each component scaled by s.
- Vec3f
scale
(Vec3f v);
- Return a copy of this vector scaled by the values of another vector.
- void
setAxis
(Matrix m);
- Set to a rotation axis from the rotation values of Matrix m.
- void
setAxis
(Quatrn q);
- Set to a rotation axis from the rotation values of Quatrn q.
- Vec3f
subtract
(Vec3f s);
- Return the difference between this vector and another.
- Quatrn
toQuatrn
();
- Interpret the values of this vector as a rotation axis/angle and convert to a Quatrn.
- Quatrn
toQuatrnEuler
();
- Interpret the values of this vector as Euler angles and convert to a Quatrn.
- Matrix
toMatrix
();
- Interpret the values of this vector as a rotation axis and convert to a rotation Matrix.
- char[]
toString
();
- Return a string representation of this vector for human reading.
- Vec3f
translate
(Matrix m);
- Return a copy of this Vecotr translated by the translation component of Matrix m.
- Vec3f
transform
(Matrix m);
- Return a copy of this vector transformed by Matrix m.
- Vec!(2,float)
vec2f
();
- Vec!(4,float)
vec4f
();
|
|