Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point Class Reference

#include <IcePoint.h>

Inheritance diagram for Point:
HPoint

Public Member Functions

inline_ Point ()
 Empty constructor. More...
 
inline_ Point (float _x, float _y, float _z)
 Constructor from a single float. More...
 
inline_ Point (const float f[3])
 Constructor from array. More...
 
inline_ Point (const Point &p)
 Copy constructor. More...
 
inline_ ~Point ()
 Destructor. More...
 
inline_ PointZero ()
 Clears the vector. More...
 
inline_ PointSetPlusInfinity ()
 
inline_ PointSetMinusInfinity ()
 
PointPositiveUnitRandomVector ()
 Sets positive unit random vector. More...
 
PointUnitRandomVector ()
 Sets unit random vector. More...
 
inline_ PointSet (float _x, float _y, float _z)
 Assignment from values. More...
 
inline_ PointSet (const float f[3])
 Assignment from array. More...
 
inline_ PointSet (const Point &src)
 Assignment from another point. More...
 
inline_ PointAdd (const Point &p)
 Adds a vector. More...
 
inline_ PointAdd (float _x, float _y, float _z)
 Adds a vector. More...
 
inline_ PointAdd (const float f[3])
 Adds a vector. More...
 
inline_ PointAdd (const Point &p, const Point &q)
 Adds vectors. More...
 
inline_ PointSub (const Point &p)
 Subtracts a vector. More...
 
inline_ PointSub (float _x, float _y, float _z)
 Subtracts a vector. More...
 
inline_ PointSub (const float f[3])
 Subtracts a vector. More...
 
inline_ PointSub (const Point &p, const Point &q)
 Subtracts vectors. More...
 
inline_ PointNeg ()
 this = -this More...
 
inline_ PointNeg (const Point &a)
 this = -a More...
 
inline_ PointMult (float s)
 Multiplies by a scalar. More...
 
inline_ PointMult (const Point &a, float scalar)
 this = a * scalar More...
 
inline_ PointMac (const Point &a, const Point &b, float scalar)
 this = a + b * scalar More...
 
inline_ PointMac (const Point &a, float scalar)
 this = this + a * scalar More...
 
inline_ PointMsc (const Point &a, const Point &b, float scalar)
 this = a - b * scalar More...
 
inline_ PointMsc (const Point &a, float scalar)
 this = this - a * scalar More...
 
inline_ PointMac2 (const Point &a, const Point &b, float scalarb, const Point &c, float scalarc)
 this = a + b * scalarb + c * scalarc More...
 
inline_ PointMsc2 (const Point &a, const Point &b, float scalarb, const Point &c, float scalarc)
 this = a - b * scalarb - c * scalarc More...
 
inline_ PointMult (const Matrix3x3 &mat, const Point &a)
 this = mat * a More...
 
inline_ PointMult2 (const Matrix3x3 &mat1, const Point &a1, const Matrix3x3 &mat2, const Point &a2)
 this = mat1 * a1 + mat2 * a2 More...
 
inline_ PointMac (const Matrix3x3 &mat, const Point &a)
 this = this + mat * a More...
 
inline_ PointTransMult (const Matrix3x3 &mat, const Point &a)
 this = transpose(mat) * a More...
 
inline_ PointLerp (const Point &a, const Point &b, float t)
 Linear interpolate between two vectors: this = a + t * (b - a) More...
 
inline_ PointHerp (const Point &p0, const Point &p1, const Point &p2, const Point &p3, float t)
 
inline_ PointTransform (const Point &r, const Matrix3x3 &rotpos, const Point &linpos)
 this = rotpos * r + linpos More...
 
inline_ PointInvTransform (const Point &r, const Matrix3x3 &rotpos, const Point &linpos)
 this = trans(rotpos) * (r - linpos) More...
 
inline_ float Min () const
 Returns MIN(x, y, z);. More...
 
inline_ float Max () const
 Returns MAX(x, y, z);. More...
 
inline_ PointMin (const Point &p)
 Sets each element to be componentwise minimum. More...
 
inline_ PointMax (const Point &p)
 Sets each element to be componentwise maximum. More...
 
inline_ PointClamp (float min, float max)
 Clamps each element. More...
 
inline_ float SquareMagnitude () const
 Computes square magnitude. More...
 
inline_ float Magnitude () const
 Computes magnitude. More...
 
inline_ float Volume () const
 Computes volume. More...
 
inline_ bool ApproxZero () const
 Checks the point is near zero. More...
 
inline_ bool IsZero () const
 Tests for exact zero vector. More...
 
inline_ bool IsValid () const
 Checks point validity. More...
 
void Tweak (udword coord_mask, udword tweak_mask)
 Slighty moves the point. More...
 
inline_ void TweakBigger ()
 Slighty moves the point out. More...
 
inline_ void TweakSmaller ()
 Slighty moves the point in. More...
 
inline_ PointNormalize ()
 Normalizes the vector. More...
 
inline_ PointSetLength (float length)
 Sets vector length. More...
 
inline_ PointClampLength (float limit_length)
 Clamps vector length. More...
 
inline_ float Distance (const Point &b) const
 Computes distance to another point. More...
 
inline_ float SquareDistance (const Point &b) const
 Computes square distance to another point. More...
 
inline_ float Dot (const Point &p) const
 Dot product dp = this|a. More...
 
inline_ PointCross (const Point &a, const Point &b)
 Cross product this = a x b. More...
 
inline_ udword VectorCode () const
 Vector code ( bitmask = sign(z) | sign(y) | sign(x) ) More...
 
inline_ PointComponent LargestAxis () const
 Returns largest axis. More...
 
inline_ PointComponent ClosestAxis () const
 Returns closest axis. More...
 
inline_ PointComponent SmallestAxis () const
 Returns smallest axis. More...
 
PointRefract (const Point &eye, const Point &n, float refractindex, Point &refracted)
 Refracts the point. More...
 
PointProjectToPlane (const Plane &p)
 Projects the point onto a plane. More...
 
void ProjectToScreen (float halfrenderwidth, float halfrenderheight, const Matrix4x4 &mat, HPoint &projected) const
 Projects the point onto the screen. More...
 
PointUnfold (Plane &p, Point &a, Point &b)
 Unfolds the point onto a plane according to edge(a,b) More...
 
inline_ udword GetHashValue () const
 Hash function from Ville Miettinen. More...
 
void SetNotUsed ()
 Stuff magic values in the point, marking it as explicitely not used. More...
 
bool IsNotUsed () const
 Checks the point is marked as not used. More...
 
inline_ Point operator- () const
 Unary operator for Point Negate = - Point. More...
 
inline_ Point operator+ (const Point &p) const
 Operator for Point Plus = Point + Point. More...
 
inline_ Point operator- (const Point &p) const
 Operator for Point Minus = Point - Point. More...
 
inline_ Point operator* (const Point &p) const
 Operator for Point Mul = Point * Point. More...
 
inline_ Point operator* (float s) const
 Operator for Point Scale = Point * float. More...
 
inline_ Point operator/ (const Point &p) const
 Operator for Point Div = Point / Point. More...
 
inline_ Point operator/ (float s) const
 Operator for Point Scale = Point / float. More...
 
inline_ float operator| (const Point &p) const
 Operator for float DotProd = Point | Point. More...
 
inline_ Point operator^ (const Point &p) const
 Operator for Point VecProd = Point ^ Point. More...
 
inline_ Pointoperator+= (const Point &p)
 Operator for Point += Point. More...
 
inline_ Pointoperator+= (float s)
 Operator for Point += float. More...
 
inline_ Pointoperator-= (const Point &p)
 Operator for Point -= Point. More...
 
inline_ Pointoperator-= (float s)
 Operator for Point -= float. More...
 
inline_ Pointoperator*= (const Point &p)
 Operator for Point *= Point. More...
 
inline_ Pointoperator*= (float s)
 Operator for Point *= float. More...
 
inline_ Pointoperator/= (const Point &p)
 Operator for Point /= Point. More...
 
inline_ Pointoperator/= (float s)
 Operator for Point /= float. More...
 
inline_ bool operator== (const Point &p) const
 Operator for "if(Point==Point)". More...
 
inline_ bool operator!= (const Point &p) const
 Operator for "if(Point!=Point)". More...
 
inline_ Point operator* (const Matrix3x3 &mat) const
 Operator for Point Mul = Point * Matrix3x3. More...
 
inline_ Point operator* (const Matrix4x4 &mat) const
 Operator for Point Mul = Point * Matrix4x4. More...
 
inline_ Pointoperator*= (const Matrix3x3 &mat)
 Operator for Point *= Matrix3x3. More...
 
inline_ Pointoperator*= (const Matrix4x4 &mat)
 Operator for Point *= Matrix4x4. More...
 
 operator HPoint () const
 Cast a Point to a HPoint. w is set to zero. More...
 
inline_ float operator[] (int n) const
 
inline_ floatoperator[] (int n)
 
bool operator== (const Point &other)
 
bool operator!= (const Point &other)
 
 Point ()
 
 Point (float cx, float cy)
 

Public Attributes

float x
 
float y
 
float z
 

Friends

inline_ friend Point operator* (float s, const Point &p)
 Operator for Point Scale = float * Point. More...
 
inline_ friend Point operator/ (float s, const Point &p)
 Operator for Point Scale = float / Point. More...
 

Detailed Description

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:

Point P0,P1 = some 3D points;
Point Delta = P1 - P0;

This compiles fine, although you should have written:

Point P0,P1 = some 3D points;
Vector3 Delta = P1 - P0;

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.

Author
Pierre Terdiman
Version
1.0

Definition at line 25 of file IcePoint.h.

Constructor & Destructor Documentation

inline_ Point::Point ( )
inline

Empty constructor.

Definition at line 30 of file IcePoint.h.

30 {}
inline_ Point::Point ( float  _x,
float  _y,
float  _z 
)
inline

Constructor from a single float.

Constructor from floats

Definition at line 35 of file IcePoint.h.

References z.

35 : x(_x), y(_y), z(_z) {}
inline_ Point::Point ( const float  f[3])
inline

Constructor from array.

Definition at line 37 of file IcePoint.h.

References z.

37 : x(f[_X]), y(f[_Y]), z(f[_Z]) {}
inline_ Point::Point ( const Point p)
inline

Copy constructor.

Definition at line 39 of file IcePoint.h.

References z.

39 : x(p.x), y(p.y), z(p.z) {}
inline_ Point::~Point ( )
inline

Destructor.

Definition at line 41 of file IcePoint.h.

41 {}
Point::Point ( )
inline

Definition at line 43 of file guidefs.h.

43  : x( 0.0 )
44  , y( 0.0 ) {}
Point::Point ( float  cx,
float  cy 
)
inline

Definition at line 45 of file guidefs.h.

45  :
46  x( cx )
47  , y( cy )
48  {}

Member Function Documentation

inline_ Point& Point::Add ( const Point p)
inline

Adds a vector.

Definition at line 64 of file IcePoint.h.

References x, x, y, y, z, and z.

64 { x += p.x; y += p.y; z += p.z; return *this; }
inline_ Point& Point::Add ( float  _x,
float  _y,
float  _z 
)
inline

Adds a vector.

Definition at line 66 of file IcePoint.h.

References x, y, and z.

66 { x += _x; y += _y; z += _z; return *this; }
inline_ Point& Point::Add ( const float  f[3])
inline

Adds a vector.

Definition at line 68 of file IcePoint.h.

References _X, _Y, _Z, x, y, and z.

68 { x += f[_X]; y += f[_Y]; z += f[_Z]; return *this; }
inline_ Point& Point::Add ( const Point p,
const Point q 
)
inline

Adds vectors.

Definition at line 70 of file IcePoint.h.

References x, x, y, y, z, and z.

70 { x = p.x+q.x; y = p.y+q.y; z = p.z+q.z; return *this; }
inline_ bool Point::ApproxZero ( ) const
inline

Checks the point is near zero.

Definition at line 224 of file IcePoint.h.

References EPSILON2.

224 { return SquareMagnitude() < EPSILON2; }
inline_ Point& Point::Clamp ( float  min,
float  max 
)
inline

Clamps each element.

Definition at line 208 of file IcePoint.h.

References max(), min(), x, y, and z.

209  {
210  if(x<min) x=min; if(x>max) x=max;
211  if(y<min) y=min; if(y>max) y=max;
212  if(z<min) z=min; if(z>max) z=max;
213  return *this;
214  }
inline_ Point& Point::ClampLength ( float  limit_length)
inline

Clamps vector length.

Definition at line 293 of file IcePoint.h.

References f, x, y, and z.

294  {
295  if(limit_length>=0.0f) // Magnitude must be positive
296  {
297  float CurrentSquareLength = SquareMagnitude();
298 
299  if(CurrentSquareLength > limit_length * limit_length)
300  {
301  float Coeff = limit_length / sqrtf(CurrentSquareLength);
302  x *= Coeff;
303  y *= Coeff;
304  z *= Coeff;
305  }
306  }
307  return *this;
308  }
inline_ PointComponent Point::ClosestAxis ( ) const
inline

Returns closest axis.

Definition at line 351 of file IcePoint.h.

References _X, _Y, _Z, AIR, and x.

352  {
353  const float* Vals = &x;
354  PointComponent m = _X;
355  if(AIR(Vals[_Y]) > AIR(Vals[m])) m = _Y;
356  if(AIR(Vals[_Z]) > AIR(Vals[m])) m = _Z;
357  return m;
358  }
inline_ Point& Point::Cross ( const Point a,
const Point b 
)
inline

Cross product this = a x b.

Definition at line 326 of file IcePoint.h.

References x, x, y, y, z, and z.

327  {
328  x = a.y * b.z - a.z * b.y;
329  y = a.z * b.x - a.x * b.z;
330  z = a.x * b.y - a.y * b.x;
331  return *this;
332  }
inline_ float Point::Distance ( const Point b) const
inline

Computes distance to another point.

Definition at line 311 of file IcePoint.h.

References x, x, y, y, z, and z.

312  {
313  return sqrtf((x - b.x)*(x - b.x) + (y - b.y)*(y - b.y) + (z - b.z)*(z - b.z));
314  }
inline_ float Point::Dot ( const Point p) const
inline

Dot product dp = this|a.

Definition at line 323 of file IcePoint.h.

References x, x, y, y, z, and z.

Referenced by OPC_SegmentSegmentSqrDist(), and OPC_SegmentTriangleSqrDist().

323 { return p.x * x + p.y * y + p.z * z; }
inline_ udword Point::GetHashValue ( ) const
inline

Hash function from Ville Miettinen.

Definition at line 383 of file IcePoint.h.

References f, and h.

384  {
385  const udword* h = (const udword*)(this);
386  udword f = (h[0]+h[1]*11-(h[2]*17)) & 0x7fffffff; // avoid problems with +-0
387  return (f>>22)^(f>>12)^(f);
388  }
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.

References f, x, x, y, y, z, and z.

179  {
180  float t2 = t * t;
181  float t3 = t2 * t;
182  float kp0 = (2.0f * t2 - t3 - t) * 0.5f;
183  float kp1 = (3.0f * t3 - 5.0f * t2 + 2.0f) * 0.5f;
184  float kp2 = (4.0f * t2 - 3.0f * t3 + t) * 0.5f;
185  float kp3 = (t3 - t2) * 0.5f;
186  x = p0.x * kp0 + p1.x * kp1 + p2.x * kp2 + p3.x * kp3;
187  y = p0.y * kp0 + p1.y * kp1 + p2.y * kp2 + p3.y * kp3;
188  z = p0.z * kp0 + p1.z * kp1 + p2.z * kp2 + p3.z * kp3;
189  return *this;
190  }
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.

References FALSE, IsValidFloat(), TRUE, x, y, and z.

235  {
236  if(!IsValidFloat(x)) return FALSE;
237  if(!IsValidFloat(y)) return FALSE;
238  if(!IsValidFloat(z)) return FALSE;
239  return TRUE;
240  }
inline_ bool Point::IsZero ( ) const
inline

Tests for exact zero vector.

Definition at line 227 of file IcePoint.h.

References FALSE, IR, TRUE, x, y, and z.

228  {
229  if(IR(x) || IR(y) || IR(z)) return FALSE;
230  return TRUE;
231  }
inline_ PointComponent Point::LargestAxis ( ) const
inline

Returns largest axis.

Definition at line 341 of file IcePoint.h.

References _X, _Y, _Z, and x.

342  {
343  const float* Vals = &x;
344  PointComponent m = _X;
345  if(Vals[_Y] > Vals[m]) m = _Y;
346  if(Vals[_Z] > Vals[m]) m = _Z;
347  return m;
348  }
inline_ Point& Point::Lerp ( const Point a,
const Point b,
float  t 
)
inline

Linear interpolate between two vectors: this = a + t * (b - a)

Definition at line 165 of file IcePoint.h.

References x, x, y, y, z, and z.

166  {
167  x = a.x + t * (b.x - a.x);
168  y = a.y + t * (b.y - a.y);
169  z = a.z + t * (b.z - a.z);
170  return *this;
171  }
inline_ Point& Point::Mac ( const Point a,
const Point b,
float  scalar 
)
inline

this = a + b * scalar

Definition at line 99 of file IcePoint.h.

References x, x, y, y, z, and z.

100  {
101  x = a.x + b.x * scalar;
102  y = a.y + b.y * scalar;
103  z = a.z + b.z * scalar;
104  return *this;
105  }
inline_ Point& Point::Mac ( const Point a,
float  scalar 
)
inline

this = this + a * scalar

Definition at line 108 of file IcePoint.h.

References x, x, y, y, z, and z.

109  {
110  x += a.x * scalar;
111  y += a.y * scalar;
112  z += a.z * scalar;
113  return *this;
114  }
inline_ Point& Point::Mac ( const Matrix3x3 mat,
const Point a 
)

this = this + mat * a

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.

References x, x, y, y, z, and z.

136  {
137  x = a.x + b.x * scalarb + c.x * scalarc;
138  y = a.y + b.y * scalarb + c.y * scalarc;
139  z = a.z + b.z * scalarb + c.z * scalarc;
140  return *this;
141  }
inline_ float Point::Magnitude ( ) const
inline

Computes magnitude.

Definition at line 219 of file IcePoint.h.

References x, y, and z.

Referenced by HPoint::Normalize().

219 { return sqrtf(x*x + y*y + z*z); }
inline_ float Point::Max ( ) const
inline

Returns MAX(x, y, z);.

Definition at line 201 of file IcePoint.h.

References MAX, x, y, and z.

201 { return MAX(x, MAX(y, z)); }
inline_ Point& Point::Max ( const Point p)
inline

Sets each element to be componentwise maximum.

Definition at line 205 of file IcePoint.h.

References MAX, x, x, y, y, z, and z.

205 { x = MAX(x, p.x); y = MAX(y, p.y); z = MAX(z, p.z); return *this; }
inline_ float Point::Min ( ) const
inline

Returns MIN(x, y, z);.

Definition at line 199 of file IcePoint.h.

References MIN, x, y, and z.

199 { return MIN(x, MIN(y, z)); }
inline_ Point& Point::Min ( const Point p)
inline

Sets each element to be componentwise minimum.

Definition at line 203 of file IcePoint.h.

References MIN, x, x, y, y, z, and z.

203 { x = MIN(x, p.x); y = MIN(y, p.y); z = MIN(z, p.z); return *this; }
inline_ Point& Point::Msc ( const Point a,
const Point b,
float  scalar 
)
inline

this = a - b * scalar

Definition at line 117 of file IcePoint.h.

References x, x, y, y, z, and z.

118  {
119  x = a.x - b.x * scalar;
120  y = a.y - b.y * scalar;
121  z = a.z - b.z * scalar;
122  return *this;
123  }
inline_ Point& Point::Msc ( const Point a,
float  scalar 
)
inline

this = this - a * scalar

Definition at line 126 of file IcePoint.h.

References x, x, y, y, z, and z.

127  {
128  x -= a.x * scalar;
129  y -= a.y * scalar;
130  z -= a.z * scalar;
131  return *this;
132  }
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.

References x, x, y, y, z, and z.

145  {
146  x = a.x - b.x * scalarb - c.x * scalarc;
147  y = a.y - b.y * scalarb - c.y * scalarc;
148  z = a.z - b.z * scalarb - c.z * scalarc;
149  return *this;
150  }
inline_ Point& Point::Mult ( float  s)
inline

Multiplies by a scalar.

Definition at line 87 of file IcePoint.h.

References x, y, and z.

87 { x *= s; y *= s; z *= s; return *this; }
inline_ Point& Point::Mult ( const Point a,
float  scalar 
)
inline

this = a * scalar

Definition at line 90 of file IcePoint.h.

References x, x, y, y, z, and z.

91  {
92  x = a.x * scalar;
93  y = a.y * scalar;
94  z = a.z * scalar;
95  return *this;
96  }
inline_ Point& Point::Mult ( const Matrix3x3 mat,
const Point a 
)

this = mat * a

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.

References x, y, and z.

82 { x = -x; y = -y; z = -z; return *this; }
inline_ Point& Point::Neg ( const Point a)
inline

this = -a

Definition at line 84 of file IcePoint.h.

References x, x, y, y, z, and z.

84 { x = -a.x; y = -a.y; z = -a.z; return *this; }
inline_ Point& Point::Normalize ( )
inline

Normalizes the vector.

Definition at line 269 of file IcePoint.h.

References M, x, y, and z.

270  {
271  float M = x*x + y*y + z*z;
272  if(M)
273  {
274  M = 1.0f / sqrtf(M);
275  x *= M;
276  y *= M;
277  z *= M;
278  }
279  return *this;
280  }
Point::operator HPoint ( ) const

Cast a Point to a HPoint. w is set to zero.

bool Point::operator!= ( const Point other)
inline

Definition at line 37 of file guidefs.h.

38  {
39  return !(*this == other);
40  }
inline_ bool Point::operator!= ( const Point p) const
inline

Operator for "if(Point!=Point)".

Definition at line 455 of file IcePoint.h.

References IR, x, x, y, y, z, and z.

455 { return ( (IR(x)!=IR(p.x))||(IR(y)!=IR(p.y))||(IR(z)!=IR(p.z))); }
inline_ Point Point::operator* ( const Point p) const
inline

Operator for Point Mul = Point * Point.

Definition at line 406 of file IcePoint.h.

References x, x, y, y, z, and z.

406 { return Point(x * p.x, y * p.y, z * p.z); }
inline_ Point Point::operator* ( float  s) const
inline

Operator for Point Scale = Point * float.

Definition at line 408 of file IcePoint.h.

References x, y, and z.

408 { return Point(x * s, y * s, z * s ); }
inline_ Point Point::operator* ( const Matrix3x3 mat) const
inline

Operator for Point Mul = Point * Matrix3x3.

Definition at line 460 of file IcePoint.h.

References x, y, and z.

461  {
462  class ShadowMatrix3x3{ public: float m[3][3]; }; // To allow inlining
463  const ShadowMatrix3x3* Mat = (const ShadowMatrix3x3*)&mat;
464 
465  return Point(
466  x * Mat->m[0][0] + y * Mat->m[1][0] + z * Mat->m[2][0],
467  x * Mat->m[0][1] + y * Mat->m[1][1] + z * Mat->m[2][1],
468  x * Mat->m[0][2] + y * Mat->m[1][2] + z * Mat->m[2][2] );
469  }
inline_ Point Point::operator* ( const Matrix4x4 mat) const
inline

Operator for Point Mul = Point * Matrix4x4.

Definition at line 472 of file IcePoint.h.

References x, y, and z.

473  {
474  class ShadowMatrix4x4{ public: float m[4][4]; }; // To allow inlining
475  const ShadowMatrix4x4* Mat = (const ShadowMatrix4x4*)&mat;
476 
477  return Point(
478  x * Mat->m[0][0] + y * Mat->m[1][0] + z * Mat->m[2][0] + Mat->m[3][0],
479  x * Mat->m[0][1] + y * Mat->m[1][1] + z * Mat->m[2][1] + Mat->m[3][1],
480  x * Mat->m[0][2] + y * Mat->m[1][2] + z * Mat->m[2][2] + Mat->m[3][2]);
481  }
inline_ Point& Point::operator*= ( const Point p)
inline

Operator for Point *= Point.

Definition at line 441 of file IcePoint.h.

References x, x, y, y, z, and z.

441 { x *= p.x; y *= p.y; z *= p.z; return *this; }
inline_ Point& Point::operator*= ( float  s)
inline

Operator for Point *= float.

Definition at line 443 of file IcePoint.h.

References x, y, and z.

443 { x *= s; y *= s; z *= s; return *this; }
inline_ Point& Point::operator*= ( const Matrix3x3 mat)
inline

Operator for Point *= Matrix3x3.

Definition at line 484 of file IcePoint.h.

References x, y, and z.

485  {
486  class ShadowMatrix3x3{ public: float m[3][3]; }; // To allow inlining
487  const ShadowMatrix3x3* Mat = (const ShadowMatrix3x3*)&mat;
488 
489  float xp = x * Mat->m[0][0] + y * Mat->m[1][0] + z * Mat->m[2][0];
490  float yp = x * Mat->m[0][1] + y * Mat->m[1][1] + z * Mat->m[2][1];
491  float zp = x * Mat->m[0][2] + y * Mat->m[1][2] + z * Mat->m[2][2];
492 
493  x = xp; y = yp; z = zp;
494 
495  return *this;
496  }
inline_ Point& Point::operator*= ( const Matrix4x4 mat)
inline

Operator for Point *= Matrix4x4.

Definition at line 499 of file IcePoint.h.

References x, y, and z.

500  {
501  class ShadowMatrix4x4{ public: float m[4][4]; }; // To allow inlining
502  const ShadowMatrix4x4* Mat = (const ShadowMatrix4x4*)&mat;
503 
504  float xp = x * Mat->m[0][0] + y * Mat->m[1][0] + z * Mat->m[2][0] + Mat->m[3][0];
505  float yp = x * Mat->m[0][1] + y * Mat->m[1][1] + z * Mat->m[2][1] + Mat->m[3][1];
506  float zp = x * Mat->m[0][2] + y * Mat->m[1][2] + z * Mat->m[2][2] + Mat->m[3][2];
507 
508  x = xp; y = yp; z = zp;
509 
510  return *this;
511  }
inline_ Point Point::operator+ ( const Point p) const
inline

Operator for Point Plus = Point + Point.

Definition at line 401 of file IcePoint.h.

References x, x, y, y, z, and z.

401 { return Point(x + p.x, y + p.y, z + p.z); }
inline_ Point& Point::operator+= ( const Point p)
inline

Operator for Point += Point.

Definition at line 431 of file IcePoint.h.

References x, x, y, y, z, and z.

431 { x += p.x; y += p.y; z += p.z; return *this; }
inline_ Point& Point::operator+= ( float  s)
inline

Operator for Point += float.

Definition at line 433 of file IcePoint.h.

References x, y, and z.

433 { x += s; y += s; z += s; return *this; }
inline_ Point Point::operator- ( ) const
inline

Unary operator for Point Negate = - Point.

Definition at line 398 of file IcePoint.h.

References x, y, and z.

398 { return Point(-x, -y, -z); }
inline_ Point Point::operator- ( const Point p) const
inline

Operator for Point Minus = Point - Point.

Definition at line 403 of file IcePoint.h.

References x, x, y, y, z, and z.

403 { return Point(x - p.x, y - p.y, z - p.z); }
inline_ Point& Point::operator-= ( const Point p)
inline

Operator for Point -= Point.

Definition at line 436 of file IcePoint.h.

References x, x, y, y, z, and z.

436 { x -= p.x; y -= p.y; z -= p.z; return *this; }
inline_ Point& Point::operator-= ( float  s)
inline

Operator for Point -= float.

Definition at line 438 of file IcePoint.h.

References x, y, and z.

438 { x -= s; y -= s; z -= s; return *this; }
inline_ Point Point::operator/ ( const Point p) const
inline

Operator for Point Div = Point / Point.

Definition at line 413 of file IcePoint.h.

References x, x, y, y, z, and z.

413 { return Point(x / p.x, y / p.y, z / p.z); }
inline_ Point Point::operator/ ( float  s) const
inline

Operator for Point Scale = Point / float.

Definition at line 415 of file IcePoint.h.

References x, y, and z.

415 { s = 1.0f / s; return Point(x * s, y * s, z * s); }
inline_ Point& Point::operator/= ( const Point p)
inline

Operator for Point /= Point.

Definition at line 446 of file IcePoint.h.

References x, x, y, y, z, and z.

446 { x /= p.x; y /= p.y; z /= p.z; return *this; }
inline_ Point& Point::operator/= ( float  s)
inline

Operator for Point /= float.

Definition at line 448 of file IcePoint.h.

References x, y, and z.

448 { s = 1.0f/s; x *= s; y *= s; z *= s; return *this; }
bool Point::operator== ( const Point other)
inline

Definition at line 33 of file guidefs.h.

References x, and y.

34  {
35  return x == other.x && y == other.y;
36  }
inline_ bool Point::operator== ( const Point p) const
inline

Operator for "if(Point==Point)".

Definition at line 453 of file IcePoint.h.

References IR, x, x, y, y, z, and z.

453 { return ( (IR(x)==IR(p.x))&&(IR(y)==IR(p.y))&&(IR(z)==IR(p.z))); }
inline_ float Point::operator[] ( int  n) const
inline

Definition at line 518 of file IcePoint.h.

References x.

518 { return *(&x + n); }
inline_ float& Point::operator[] ( int  n)
inline

Definition at line 519 of file IcePoint.h.

References x.

519 { return *(&x + n); }
inline_ Point Point::operator^ ( const Point p) const
inline

Operator for Point VecProd = Point ^ Point.

Definition at line 422 of file IcePoint.h.

References x, x, y, y, z, and z.

423  {
424  return Point(
425  y * p.z - z * p.y,
426  z * p.x - x * p.z,
427  x * p.y - y * p.x );
428  }
inline_ float Point::operator| ( const Point p) const
inline

Operator for float DotProd = Point | Point.

Definition at line 420 of file IcePoint.h.

References x, x, y, y, z, and z.

420 { return x*p.x + y*p.y + z*p.z; }
Point& Point::PositiveUnitRandomVector ( )

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.

Point& Point::Refract ( const Point eye,
const Point n,
float  refractindex,
Point refracted 
)

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.

References x, y, and z.

57 { x = _x; y = _y; z = _z; return *this; }
inline_ Point& Point::Set ( const float  f[3])
inline

Assignment from array.

Definition at line 59 of file IcePoint.h.

References _X, _Y, _Z, x, y, and z.

59 { x = f[_X]; y = f[_Y]; z = f[_Z]; return *this; }
inline_ Point& Point::Set ( const Point src)
inline

Assignment from another point.

Definition at line 61 of file IcePoint.h.

References x, x, y, y, z, and z.

61 { x = src.x; y = src.y; z = src.z; return *this; }
inline_ Point& Point::SetLength ( float  length)
inline

Sets vector length.

Definition at line 283 of file IcePoint.h.

References Magnitude(), x, y, and z.

284  {
285  float NewLength = length / Magnitude();
286  x *= NewLength;
287  y *= NewLength;
288  z *= NewLength;
289  return *this;
290  }
inline_ Point& Point::SetMinusInfinity ( )
inline
  • infinity

Definition at line 49 of file IcePoint.h.

References MIN_FLOAT, x, y, and z.

49 { x = y = z = MIN_FLOAT; return *this; }
void Point::SetNotUsed ( )

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.

References MAX_FLOAT, x, y, and z.

47 { x = y = z = MAX_FLOAT; return *this; }
inline_ PointComponent Point::SmallestAxis ( ) const
inline

Returns smallest axis.

Definition at line 361 of file IcePoint.h.

References _X, _Y, _Z, and x.

362  {
363  const float* Vals = &x;
364  PointComponent m = _X;
365  if(Vals[_Y] < Vals[m]) m = _Y;
366  if(Vals[_Z] < Vals[m]) m = _Z;
367  return m;
368  }
inline_ float Point::SquareDistance ( const Point b) const
inline

Computes square distance to another point.

Definition at line 317 of file IcePoint.h.

References x, x, y, y, z, and z.

318  {
319  return ((x - b.x)*(x - b.x) + (y - b.y)*(y - b.y) + (z - b.z)*(z - b.z));
320  }
inline_ float Point::SquareMagnitude ( ) const
inline

Computes square magnitude.

Definition at line 217 of file IcePoint.h.

References x, y, and z.

Referenced by OPC_PointTriangleSqrDist(), OPC_SegmentSegmentSqrDist(), OPC_SegmentTriangleSqrDist(), and SphereCollider::SphereTriOverlap().

217 { return x*x + y*y + z*z; }
inline_ Point& Point::Sub ( const Point p)
inline

Subtracts a vector.

Definition at line 73 of file IcePoint.h.

References x, x, y, y, z, and z.

73 { x -= p.x; y -= p.y; z -= p.z; return *this; }
inline_ Point& Point::Sub ( float  _x,
float  _y,
float  _z 
)
inline

Subtracts a vector.

Definition at line 75 of file IcePoint.h.

References x, y, and z.

75 { x -= _x; y -= _y; z -= _z; return *this; }
inline_ Point& Point::Sub ( const float  f[3])
inline

Subtracts a vector.

Definition at line 77 of file IcePoint.h.

References _X, _Y, _Z, x, y, and z.

77 { x -= f[_X]; y -= f[_Y]; z -= f[_Z]; return *this; }
inline_ Point& Point::Sub ( const Point p,
const Point q 
)
inline

Subtracts vectors.

Definition at line 79 of file IcePoint.h.

References x, x, y, y, z, and z.

79 { x = p.x-q.x; y = p.y-q.y; z = p.z-q.z; return *this; }
inline_ Point& Point::Transform ( const Point r,
const Matrix3x3 rotpos,
const Point linpos 
)

this = rotpos * r + linpos

inline_ Point& Point::TransMult ( const Matrix3x3 mat,
const Point a 
)

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.

References FR, IR, x, y, and z.

244  {
245  if(coord_mask&1) { udword Dummy = IR(x); Dummy^=tweak_mask; x = FR(Dummy); }
246  if(coord_mask&2) { udword Dummy = IR(y); Dummy^=tweak_mask; y = FR(Dummy); }
247  if(coord_mask&4) { udword Dummy = IR(z); Dummy^=tweak_mask; z = FR(Dummy); }
248  }
inline_ void Point::TweakBigger ( )
inline

Slighty moves the point out.

Definition at line 253 of file IcePoint.h.

254  {
255  udword Dummy = (IR(x)&TWEAKNOTMASK); if(x >= 0.0f) Dummy+=TWEAKMASK+1; x = FR(Dummy);
256  Dummy = (IR(y)&TWEAKNOTMASK); if(y >= 0.0f) Dummy+=TWEAKMASK+1; y = FR(Dummy);
257  Dummy = (IR(z)&TWEAKNOTMASK); if(z >= 0.0f) Dummy+=TWEAKMASK+1; z = FR(Dummy);
258  }
inline_ void Point::TweakSmaller ( )
inline

Slighty moves the point in.

Definition at line 261 of file IcePoint.h.

References f, FR, IR, TWEAKMASK, TWEAKNOTMASK, x, y, and z.

262  {
263  udword Dummy = (IR(x)&TWEAKNOTMASK); if(x < 0.0f) Dummy+=TWEAKMASK+1; x = FR(Dummy);
264  Dummy = (IR(y)&TWEAKNOTMASK); if(y < 0.0f) Dummy+=TWEAKMASK+1; y = FR(Dummy);
265  Dummy = (IR(z)&TWEAKNOTMASK); if(z < 0.0f) Dummy+=TWEAKMASK+1; z = FR(Dummy);
266  }
Point& Point::Unfold ( Plane p,
Point a,
Point b 
)

Unfolds the point onto a plane according to edge(a,b)

Point& Point::UnitRandomVector ( )

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.

References IR, SIGN_BITMASK, x, y, and z.

336  {
337  return (IR(x)>>31) | ((IR(y)&SIGN_BITMASK)>>30) | ((IR(z)&SIGN_BITMASK)>>29);
338  }
inline_ float Point::Volume ( ) const
inline

Computes volume.

Definition at line 221 of file IcePoint.h.

References x, y, and z.

221 { return x * y * z; }
inline_ Point& Point::Zero ( )
inline

Clears the vector.

Definition at line 44 of file IcePoint.h.

References x, y, and z.

44 { x = y = z = 0.0f; return *this; }

Friends And Related Function Documentation

inline_ friend Point operator* ( float  s,
const Point p 
)
friend

Operator for Point Scale = float * Point.

Definition at line 410 of file IcePoint.h.

410 { return Point(s * p.x, s * p.y, s * p.z); }
inline_ friend Point operator/ ( float  s,
const Point p 
)
friend

Operator for Point Scale = float / Point.

Definition at line 417 of file IcePoint.h.

417 { return Point(s / p.x, s / p.y, s / p.z); }

Member Data Documentation

float Point::x

Definition at line 522 of file IcePoint.h.

Referenced by AABBCollider::AABBAABBOverlap(), Add(), TriList::AddTri(), OBBCollider::BoxBoxOverlap(), Scroller::calcLayout(), Case000(), CaseNoZeros(), Rect::center(), ComputeMinMax(), BaseComputer::createModeButtons(), Cross(), Distance(), Dot(), Slider::draw(), Picker::draw(), ScrollerButton::draw(), WindowManager::draw(), PaintText::drawLines(), drawLowRightShadow(), drawUpLeftShadow(), Matrix3x3::GetCol(), Matrix4x4::GetCol(), Matrix3x3::GetRow(), Matrix4x4::GetRow(), Matrix4x4::GetTrans(), Herp(), Control::hitTest(), Rect::inset(), Rect::inside(), Rect::left(), Lerp(), Mac(), Mac2(), HPoint::Max(), Max(), HPoint::Min(), Min(), Msc(), Msc2(), Mult(), Neg(), OPC_PointAABBSqrDist(), HPoint::operator!=(), operator!=(), HPoint::operator*(), Matrix4x4::operator*(), operator*(), HPoint::operator*=(), Matrix4x4::operator*=(), Matrix3x3::operator*=(), operator*=(), HPoint::operator+(), operator+(), HPoint::operator+=(), operator+=(), HPoint::operator-(), operator-(), HPoint::operator-=(), operator-=(), HPoint::operator/(), operator/(), HPoint::operator/=(), operator/=(), HPoint::operator==(), operator==(), operator^(), HPoint::operator|(), operator|(), Slider::processMouseDown(), Slider::processMouseDrag(), Rect::right(), Matrix3x3::Scale(), Matrix4x4::Scale(), HPoint::Set(), Set(), Matrix3x3::SetCol(), Matrix4x4::SetCol(), Matrix3x3::SetRow(), Matrix4x4::SetRow(), Matrix3x3::SetScale(), Matrix4x4::SetScale(), Matrix4x4::SetTrans(), Matrix3x3::SkewSymmetric(), SqrDistance(), SquareDistance(), Sub(), TransformPoint(), TransformPoint3x3(), TransformPoint4x3(), AABBCollider::TriBoxOverlap(), and OBBCollider::TriBoxOverlap().

float Point::y

Definition at line 522 of file IcePoint.h.

Referenced by AABBCollider::AABBAABBOverlap(), Add(), TriList::AddTri(), Rect::bottom(), OBBCollider::BoxBoxOverlap(), Scroller::calcLayout(), Case000(), CaseNoZeros(), Picker::cellForMouse(), Rect::center(), ComputeMinMax(), Cross(), Distance(), Dot(), Slider::draw(), Picker::draw(), ScrollerButton::draw(), WindowManager::draw(), PaintText::drawLines(), drawLowRightShadow(), drawUpLeftShadow(), Matrix3x3::GetCol(), Matrix4x4::GetCol(), Matrix3x3::GetRow(), Matrix4x4::GetRow(), Matrix4x4::GetTrans(), Herp(), Control::hitTest(), Rect::inset(), Rect::inside(), Lerp(), Mac(), Mac2(), HPoint::Max(), Max(), HPoint::Min(), Min(), Msc(), Msc2(), Mult(), Neg(), OPC_PointAABBSqrDist(), HPoint::operator!=(), operator!=(), HPoint::operator*(), Matrix4x4::operator*(), operator*(), HPoint::operator*=(), Matrix4x4::operator*=(), Matrix3x3::operator*=(), operator*=(), HPoint::operator+(), operator+(), HPoint::operator+=(), operator+=(), HPoint::operator-(), operator-(), HPoint::operator-=(), operator-=(), HPoint::operator/(), operator/(), HPoint::operator/=(), operator/=(), HPoint::operator==(), operator==(), operator^(), HPoint::operator|(), operator|(), Slider::processMouseDown(), Slider::processMouseDrag(), Matrix3x3::Scale(), Matrix4x4::Scale(), HPoint::Set(), Set(), Matrix3x3::SetCol(), Matrix4x4::SetCol(), Matrix3x3::SetRow(), Matrix4x4::SetRow(), Matrix3x3::SetScale(), Matrix4x4::SetScale(), Matrix4x4::SetTrans(), Matrix3x3::SkewSymmetric(), SqrDistance(), SquareDistance(), Sub(), Rect::top(), TransformPoint(), TransformPoint3x3(), TransformPoint4x3(), AABBCollider::TriBoxOverlap(), and OBBCollider::TriBoxOverlap().


The documentation for this class was generated from the following files: