#include <IcePoint.h>
Public Member Functions | |
inline_ Point & | Add (const Point &p) |
Adds a vector. | |
inline_ Point & | Add (float _x, float _y, float _z) |
Adds a vector. | |
inline_ Point & | Add (const float f[3]) |
Adds a vector. | |
inline_ Point & | Add (const Point &p, const Point &q) |
Adds vectors. | |
inline_ bool | ApproxZero () const |
Checks the point is near zero. | |
inline_ Point & | Clamp (float min, float max) |
Clamps each element. | |
inline_ Point & | ClampLength (float limit_length) |
Clamps vector length. | |
inline_ PointComponent | ClosestAxis () const |
Returns closest axis. | |
inline_ Point & | Cross (const Point &a, const Point &b) |
Cross product this = a x b. | |
inline_ float | Distance (const Point &b) const |
Computes distance to another point. | |
inline_ float | Dot (const Point &p) const |
Dot product dp = this|a. | |
inline_ udword | GetHashValue () const |
Hash function from Ville Miettinen. | |
inline_ Point & | Herp (const Point &p0, const Point &p1, const Point &p2, const Point &p3, float t) |
inline_ Point & | InvTransform (const Point &r, const Matrix3x3 &rotpos, const Point &linpos) |
this = trans(rotpos) * (r - linpos) | |
BOOL | IsNotUsed () const |
Checks the point is marked as not used. | |
inline_ BOOL | IsValid () const |
Checks point validity. | |
inline_ BOOL | IsZero () const |
Tests for exact zero vector. | |
inline_ PointComponent | LargestAxis () const |
Returns largest axis. | |
inline_ Point & | Lerp (const Point &a, const Point &b, float t) |
Linear interpolate between two vectors: this = a + t * (b - a) | |
inline_ Point & | Mac (const Point &a, const Point &b, float scalar) |
this = a + b * scalar | |
inline_ Point & | Mac (const Point &a, float scalar) |
this = this + a * scalar | |
inline_ Point & | Mac (const Matrix3x3 &mat, const Point &a) |
this = this + mat * a | |
inline_ Point & | Mac2 (const Point &a, const Point &b, float scalarb, const Point &c, float scalarc) |
this = a + b * scalarb + c * scalarc | |
inline_ float | Magnitude () const |
Computes magnitude. | |
inline_ float | Max () const |
Returns MAX(x, y, z);. | |
inline_ Point & | Max (const Point &p) |
Sets each element to be componentwise maximum. | |
inline_ float | Min () const |
Returns MIN(x, y, z);. | |
inline_ Point & | Min (const Point &p) |
Sets each element to be componentwise minimum. | |
inline_ Point & | Msc (const Point &a, const Point &b, float scalar) |
this = a - b * scalar | |
inline_ Point & | Msc (const Point &a, float scalar) |
this = this - a * scalar | |
inline_ Point & | Msc2 (const Point &a, const Point &b, float scalarb, const Point &c, float scalarc) |
this = a - b * scalarb - c * scalarc | |
inline_ Point & | Mult (float s) |
Multiplies by a scalar. | |
inline_ Point & | Mult (const Point &a, float scalar) |
this = a * scalar | |
inline_ Point & | Mult (const Matrix3x3 &mat, const Point &a) |
this = mat * a | |
inline_ Point & | Mult2 (const Matrix3x3 &mat1, const Point &a1, const Matrix3x3 &mat2, const Point &a2) |
this = mat1 * a1 + mat2 * a2 | |
inline_ Point & | Neg () |
this = -this | |
inline_ Point & | Neg (const Point &a) |
this = -a | |
inline_ Point & | Normalize () |
Normalizes the vector. | |
inline_ | operator const float * () const |
inline_ | operator float * () |
operator HPoint () const | |
Cast a Point to a HPoint. w is set to zero. | |
inline_ bool | operator!= (const Point &p) const |
Operator for "if(Point!=Point)". | |
inline_ Point | operator* (const Point &p) const |
Operator for Point Mul = Point * Point. | |
inline_ Point | operator* (float s) const |
Operator for Point Scale = Point * float. | |
inline_ Point | operator* (const Matrix3x3 &mat) const |
Operator for Point Mul = Point * Matrix3x3. | |
inline_ Point | operator* (const Matrix4x4 &mat) const |
Operator for Point Mul = Point * Matrix4x4. | |
inline_ Point & | operator*= (const Point &p) |
Operator for Point *= Point. | |
inline_ Point & | operator*= (float s) |
Operator for Point *= float. | |
inline_ Point & | operator*= (const Matrix3x3 &mat) |
Operator for Point *= Matrix3x3. | |
inline_ Point & | operator*= (const Matrix4x4 &mat) |
Operator for Point *= Matrix4x4. | |
inline_ Point | operator+ (const Point &p) const |
Operator for Point Plus = Point + Point. | |
inline_ Point & | operator+= (const Point &p) |
Operator for Point += Point. | |
inline_ Point & | operator+= (float s) |
Operator for Point += float. | |
inline_ Point | operator- () const |
Unary operator for Point Negate = - Point. | |
inline_ Point | operator- (const Point &p) const |
Operator for Point Minus = Point - Point. | |
inline_ Point & | operator-= (const Point &p) |
Operator for Point -= Point. | |
inline_ Point & | operator-= (float s) |
Operator for Point -= float. | |
inline_ Point | operator/ (const Point &p) const |
Operator for Point Div = Point / Point. | |
inline_ Point | operator/ (float s) const |
Operator for Point Scale = Point / float. | |
inline_ Point & | operator/= (const Point &p) |
Operator for Point /= Point. | |
inline_ Point & | operator/= (float s) |
Operator for Point /= float. | |
inline_ bool | operator== (const Point &p) const |
Operator for "if(Point==Point)". | |
inline_ Point | operator^ (const Point &p) const |
Operator for Point VecProd = Point ^ Point. | |
inline_ float | operator| (const Point &p) const |
Operator for float DotProd = Point | Point. | |
inline_ | Point () |
Empty constructor. | |
inline_ | Point (float _x, float _y, float _z) |
Constructor from a single float. | |
inline_ | Point (const float f[3]) |
Constructor from array. | |
inline_ | Point (const Point &p) |
Copy constructor. | |
Point & | PositiveUnitRandomVector () |
Sets positive unit random vector. | |
Point & | ProjectToPlane (const Plane &p) |
Projects the point onto a plane. | |
void | ProjectToScreen (float halfrenderwidth, float halfrenderheight, const Matrix4x4 &mat, HPoint &projected) const |
Projects the point onto the screen. | |
Point & | Refract (const Point &eye, const Point &n, float refractindex, Point &refracted) |
Refracts the point. | |
inline_ Point & | Set (float _x, float _y, float _z) |
Assignment from values. | |
inline_ Point & | Set (const float f[3]) |
Assignment from array. | |
inline_ Point & | Set (const Point &src) |
Assignment from another point. | |
inline_ Point & | SetLength (float length) |
Sets vector length. | |
inline_ Point & | SetMinusInfinity () |
void | SetNotUsed () |
Stuff magic values in the point, marking it as explicitely not used. | |
inline_ Point & | SetPlusInfinity () |
+ infinity | |
inline_ PointComponent | SmallestAxis () const |
Returns smallest axis. | |
inline_ float | SquareDistance (const Point &b) const |
Computes square distance to another point. | |
inline_ float | SquareMagnitude () const |
Computes square magnitude. | |
inline_ Point & | Sub (const Point &p) |
Subtracts a vector. | |
inline_ Point & | Sub (float _x, float _y, float _z) |
Subtracts a vector. | |
inline_ Point & | Sub (const float f[3]) |
Subtracts a vector. | |
inline_ Point & | Sub (const Point &p, const Point &q) |
Subtracts vectors. | |
inline_ Point & | Transform (const Point &r, const Matrix3x3 &rotpos, const Point &linpos) |
this = rotpos * r + linpos | |
inline_ Point & | TransMult (const Matrix3x3 &mat, const Point &a) |
this = transpose(mat) * a | |
void | Tweak (udword coord_mask, udword tweak_mask) |
Slighty moves the point. | |
inline_ void | TweakBigger () |
Slighty moves the point out. | |
inline_ void | TweakSmaller () |
Slighty moves the point in. | |
Point & | Unfold (Plane &p, Point &a, Point &b) |
Unfolds the point onto a plane according to edge(a,b) | |
Point & | UnitRandomVector () |
Sets unit random vector. | |
inline_ udword | VectorCode () const |
Vector code ( bitmask = sign(z) | sign(y) | sign(x) ) | |
inline_ float | Volume () const |
Computes volume. | |
inline_ Point & | Zero () |
Clears the vector. | |
inline_ | ~Point () |
Destructor. | |
Public Attributes | |
float | x |
float | y |
float | z |
Friends | |
inline_ friend Point | operator* (float s, const Point &p) |
Operator for Point Scale = float * Point. | |
inline_ friend Point | operator/ (float s, const Point &p) |
Operator for Point Scale = float / Point. |
3D point.
The name is "Point" instead of "Vector" since a vector is N-dimensional, whereas a point is an implicit "vector of dimension 3". So the choice was between "Point" and "Vector3", the first one looked better (IMHO).
Some people, then, use a typedef to handle both points & vectors using the same class: typedef Point Vector3; This is bad since it opens the door to a lot of confusion while reading the code. I know it may sounds weird but check this out:
This compiles fine, although you should have written:
Subtle things like this are not caught at compile-time, and when you find one in the code, you never know whether it's a mistake from the author or something you don't get.
One way to handle it at compile-time would be to use different classes for Point & Vector3, only overloading operator "-" for vectors. But then, you get a lot of redundant code in thoses classes, and basically it's really a lot of useless work.
Another way would be to use homogeneous points: w=1 for points, w=0 for vectors. That's why the HPoint class exists. Now, to store your model's vertices and in most cases, you really want to use Points to save ram.
Definition at line 25 of file IcePoint.h.
inline_ Point::Point | ( | ) | [inline] |
Empty constructor.
Definition at line 30 of file IcePoint.h.
inline_ Point::Point | ( | float | _x, |
float | _y, | ||
float | _z | ||
) | [inline] |
inline_ Point::Point | ( | const float | f[3] | ) | [inline] |
Constructor from array.
Definition at line 37 of file IcePoint.h.
inline_ Point::Point | ( | const Point & | p | ) | [inline] |
Copy constructor.
Definition at line 39 of file IcePoint.h.
inline_ Point::~Point | ( | ) | [inline] |
Destructor.
Definition at line 41 of file IcePoint.h.
inline_ Point& Point::Add | ( | const Point & | p | ) | [inline] |
Adds a vector.
Definition at line 64 of file IcePoint.h.
inline_ Point& Point::Add | ( | float | _x, |
float | _y, | ||
float | _z | ||
) | [inline] |
Adds a vector.
Definition at line 66 of file IcePoint.h.
inline_ Point& Point::Add | ( | const float | f[3] | ) | [inline] |
Adds a vector.
Definition at line 68 of file IcePoint.h.
Adds vectors.
Definition at line 70 of file IcePoint.h.
inline_ bool Point::ApproxZero | ( | ) | const [inline] |
Checks the point is near zero.
Definition at line 224 of file IcePoint.h.
inline_ Point& Point::Clamp | ( | float | min, |
float | max | ||
) | [inline] |
Clamps each element.
Definition at line 208 of file IcePoint.h.
inline_ Point& Point::ClampLength | ( | float | limit_length | ) | [inline] |
Clamps vector length.
Definition at line 293 of file IcePoint.h.
inline_ PointComponent Point::ClosestAxis | ( | ) | const [inline] |
Returns closest axis.
Definition at line 352 of file IcePoint.h.
Cross product this = a x b.
Definition at line 326 of file IcePoint.h.
inline_ float Point::Distance | ( | const Point & | b | ) | const [inline] |
Computes distance to another point.
Definition at line 311 of file IcePoint.h.
inline_ float Point::Dot | ( | const Point & | p | ) | const [inline] |
Dot product dp = this|a.
Definition at line 323 of file IcePoint.h.
inline_ udword Point::GetHashValue | ( | ) | const [inline] |
Hash function from Ville Miettinen.
Definition at line 385 of file IcePoint.h.
inline_ Point& Point::Herp | ( | const Point & | p0, |
const Point & | p1, | ||
const Point & | p2, | ||
const Point & | p3, | ||
float | t | ||
) | [inline] |
Hermite interpolate between p1 and p2. p0 and p3 are used for finding gradient at p1 and p2. this = p0 * (2t^2 - t^3 - t)/2 + p1 * (3t^3 - 5t^2 + 2)/2 + p2 * (4t^2 - 3t^3 + t)/2 + p3 * (t^3 - t^2)/2
Definition at line 178 of file IcePoint.h.
inline_ Point& Point::InvTransform | ( | const Point & | r, |
const Matrix3x3 & | rotpos, | ||
const Point & | linpos | ||
) |
this = trans(rotpos) * (r - linpos)
BOOL Point::IsNotUsed | ( | ) | const |
Checks the point is marked as not used.
inline_ BOOL Point::IsValid | ( | ) | const [inline] |
Checks point validity.
Definition at line 234 of file IcePoint.h.
inline_ BOOL Point::IsZero | ( | ) | const [inline] |
Tests for exact zero vector.
Definition at line 227 of file IcePoint.h.
inline_ PointComponent Point::LargestAxis | ( | ) | const [inline] |
Returns largest axis.
Definition at line 341 of file IcePoint.h.
Linear interpolate between two vectors: this = a + t * (b - a)
Definition at line 165 of file IcePoint.h.
this = a + b * scalar
Definition at line 99 of file IcePoint.h.
inline_ Point& Point::Mac | ( | const Point & | a, |
float | scalar | ||
) | [inline] |
this = this + a * scalar
Definition at line 108 of file IcePoint.h.
inline_ Point& Point::Mac2 | ( | const Point & | a, |
const Point & | b, | ||
float | scalarb, | ||
const Point & | c, | ||
float | scalarc | ||
) | [inline] |
this = a + b * scalarb + c * scalarc
Definition at line 135 of file IcePoint.h.
inline_ float Point::Magnitude | ( | ) | const [inline] |
inline_ float Point::Max | ( | ) | const [inline] |
inline_ Point& Point::Max | ( | const Point & | p | ) | [inline] |
Sets each element to be componentwise maximum.
Definition at line 205 of file IcePoint.h.
inline_ float Point::Min | ( | ) | const [inline] |
inline_ Point& Point::Min | ( | const Point & | p | ) | [inline] |
Sets each element to be componentwise minimum.
Definition at line 203 of file IcePoint.h.
this = a - b * scalar
Definition at line 117 of file IcePoint.h.
inline_ Point& Point::Msc | ( | const Point & | a, |
float | scalar | ||
) | [inline] |
this = this - a * scalar
Definition at line 126 of file IcePoint.h.
inline_ Point& Point::Msc2 | ( | const Point & | a, |
const Point & | b, | ||
float | scalarb, | ||
const Point & | c, | ||
float | scalarc | ||
) | [inline] |
this = a - b * scalarb - c * scalarc
Definition at line 144 of file IcePoint.h.
inline_ Point& Point::Mult | ( | float | s | ) | [inline] |
Multiplies by a scalar.
Definition at line 87 of file IcePoint.h.
inline_ Point& Point::Mult | ( | const Point & | a, |
float | scalar | ||
) | [inline] |
this = a * scalar
Definition at line 90 of file IcePoint.h.
inline_ Point& Point::Mult2 | ( | const Matrix3x3 & | mat1, |
const Point & | a1, | ||
const Matrix3x3 & | mat2, | ||
const Point & | a2 | ||
) |
this = mat1 * a1 + mat2 * a2
inline_ Point& Point::Neg | ( | ) | [inline] |
this = -this
Definition at line 82 of file IcePoint.h.
inline_ Point& Point::Neg | ( | const Point & | a | ) | [inline] |
this = -a
Definition at line 84 of file IcePoint.h.
inline_ Point& Point::Normalize | ( | ) | [inline] |
Definition at line 520 of file IcePoint.h.
inline_ Point::operator float * | ( | ) | [inline] |
Definition at line 521 of file IcePoint.h.
Operator for "if(Point!=Point)".
Definition at line 457 of file IcePoint.h.
Operator for Point Mul = Point * Point.
Definition at line 408 of file IcePoint.h.
Operator for Point Scale = Point * float.
Reimplemented in HPoint.
Definition at line 410 of file IcePoint.h.
Definition at line 443 of file IcePoint.h.
Operator for Point *= Matrix3x3.
Definition at line 486 of file IcePoint.h.
Operator for Point *= Matrix4x4.
Reimplemented in HPoint.
Definition at line 501 of file IcePoint.h.
Operator for Point Plus = Point + Point.
Definition at line 403 of file IcePoint.h.
Definition at line 433 of file IcePoint.h.
Unary operator for Point Negate = - Point.
Reimplemented in HPoint.
Definition at line 400 of file IcePoint.h.
Operator for Point Minus = Point - Point.
Definition at line 405 of file IcePoint.h.
Definition at line 438 of file IcePoint.h.
Operator for Point Div = Point / Point.
Definition at line 415 of file IcePoint.h.
Operator for Point Scale = Point / float.
Reimplemented in HPoint.
Definition at line 417 of file IcePoint.h.
Definition at line 448 of file IcePoint.h.
Operator for "if(Point==Point)".
Definition at line 455 of file IcePoint.h.
Operator for Point VecProd = Point ^ Point.
Definition at line 424 of file IcePoint.h.
Operator for float DotProd = Point | Point.
Definition at line 422 of file IcePoint.h.
Sets positive unit random vector.
Point& Point::ProjectToPlane | ( | const Plane & | p | ) |
Projects the point onto a plane.
void Point::ProjectToScreen | ( | float | halfrenderwidth, |
float | halfrenderheight, | ||
const Matrix4x4 & | mat, | ||
HPoint & | projected | ||
) | const |
Projects the point onto the screen.
Refracts the point.
inline_ Point& Point::Set | ( | float | _x, |
float | _y, | ||
float | _z | ||
) | [inline] |
Assignment from values.
Definition at line 57 of file IcePoint.h.
inline_ Point& Point::Set | ( | const float | f[3] | ) | [inline] |
Assignment from array.
Definition at line 59 of file IcePoint.h.
inline_ Point& Point::Set | ( | const Point & | src | ) | [inline] |
Assignment from another point.
Definition at line 61 of file IcePoint.h.
inline_ Point& Point::SetLength | ( | float | length | ) | [inline] |
Sets vector length.
Definition at line 283 of file IcePoint.h.
inline_ Point& Point::SetMinusInfinity | ( | ) | [inline] |
Definition at line 49 of file IcePoint.h.
Stuff magic values in the point, marking it as explicitely not used.
inline_ Point& Point::SetPlusInfinity | ( | ) | [inline] |
+ infinity
Definition at line 47 of file IcePoint.h.
inline_ PointComponent Point::SmallestAxis | ( | ) | const [inline] |
Returns smallest axis.
Definition at line 362 of file IcePoint.h.
inline_ float Point::SquareDistance | ( | const Point & | b | ) | const [inline] |
Computes square distance to another point.
Definition at line 317 of file IcePoint.h.
inline_ float Point::SquareMagnitude | ( | ) | const [inline] |
inline_ Point& Point::Sub | ( | const Point & | p | ) | [inline] |
Subtracts a vector.
Definition at line 73 of file IcePoint.h.
inline_ Point& Point::Sub | ( | float | _x, |
float | _y, | ||
float | _z | ||
) | [inline] |
Subtracts a vector.
Definition at line 75 of file IcePoint.h.
inline_ Point& Point::Sub | ( | const float | f[3] | ) | [inline] |
Subtracts a vector.
Definition at line 77 of file IcePoint.h.
Subtracts vectors.
Definition at line 79 of file IcePoint.h.
this = rotpos * r + linpos
this = transpose(mat) * a
void Point::Tweak | ( | udword | coord_mask, |
udword | tweak_mask | ||
) | [inline] |
Slighty moves the point.
Definition at line 243 of file IcePoint.h.
inline_ void Point::TweakBigger | ( | ) | [inline] |
Slighty moves the point out.
Definition at line 253 of file IcePoint.h.
inline_ void Point::TweakSmaller | ( | ) | [inline] |
Slighty moves the point in.
Definition at line 261 of file IcePoint.h.
Point& Point::Unfold | ( | Plane & | p, |
Point & | a, | ||
Point & | b | ||
) |
Unfolds the point onto a plane according to edge(a,b)
Sets unit random vector.
inline_ udword Point::VectorCode | ( | ) | const [inline] |
Vector code ( bitmask = sign(z) | sign(y) | sign(x) )
Definition at line 335 of file IcePoint.h.
inline_ float Point::Volume | ( | ) | const [inline] |
Computes volume.
Definition at line 221 of file IcePoint.h.
inline_ Point& Point::Zero | ( | ) | [inline] |
Operator for Point Scale = float * Point.
Definition at line 412 of file IcePoint.h.
Operator for Point Scale = float / Point.
Definition at line 419 of file IcePoint.h.
float Point::x |
Definition at line 524 of file IcePoint.h.
float Point::y |
Definition at line 524 of file IcePoint.h.
float Point::z |
Definition at line 524 of file IcePoint.h.