12 #ifndef __ICEPOINT_H__ 13 #define __ICEPOINT_H__ 21 #define CROSS2D(a, b) (a.x*b.y - b.x*a.y) 52 Point& PositiveUnitRandomVector();
54 Point& UnitRandomVector();
66 inline_ Point&
Add(
float _x,
float _y,
float _z) {
x += _x;
y += _y; z += _z;
return *
this; }
75 inline_ Point&
Sub(
float _x,
float _y,
float _z) {
x -= _x;
y -= _y; z -= _z;
return *
this; }
101 x = a.
x + b.
x * scalar;
102 y = a.
y + b.
y * scalar;
103 z = a.
z + b.
z * scalar;
119 x = a.
x - b.
x * scalar;
120 y = a.
y - b.
y * scalar;
121 z = a.
z - b.
z * scalar;
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;
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;
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);
182 float kp0 = (2.0f * t2 - t3 - t) * 0.5
f;
183 float kp1 = (3.0f * t3 - 5.0f * t2 + 2.0f) * 0.5
f;
184 float kp2 = (4.0f * t2 - 3.0f * t3 + t) * 0.5
f;
185 float kp3 = (t3 - t2) * 0.5
f;
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;
212 if(z<min) z=
min;
if(z>max) z=
max;
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); }
250 #define TWEAKMASK 0x3fffff 251 #define TWEAKNOTMASK ~TWEAKMASK 271 float M =
x*
x +
y*
y + z*z;
285 float NewLength = length / Magnitude();
295 if(limit_length>=0.0
f)
297 float CurrentSquareLength = SquareMagnitude();
299 if(CurrentSquareLength > limit_length * limit_length)
301 float Coeff = limit_length / sqrtf(CurrentSquareLength);
313 return sqrtf((
x - b.
x)*(
x - b.
x) + (
y - b.
y)*(
y - b.
y) + (z - b.
z)*(z - b.
z));
319 return ((
x - b.
x)*(
x - b.
x) + (
y - b.
y)*(
y - b.
y) + (z - b.
z)*(z - b.
z));
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;
347 y >
x ? (z >
y ? m =
_Z : m =
_Y) : (z >
x ? m =
_Z : m =
_X);
354 const float* Vals = &
x;
368 y <
x ? (z <
y ? m =
_Z : m =
_Y) : (z <
x ? m =
_Z : m =
_X);
379 void ProjectToScreen(
float halfrenderwidth,
float halfrenderheight,
const Matrix4x4& mat,
HPoint& projected)
const;
388 udword f = (h[0]+h[1]*11-(h[2]*17)) & 0x7fffffff;
389 return (f>>22)^(f>>12)^(f);
395 BOOL IsNotUsed()
const;
464 class ShadowMatrix3x3{
public:
float m[3][3]; };
465 const ShadowMatrix3x3* Mat = (
const ShadowMatrix3x3*)&mat;
468 x * Mat->m[0][0] +
y * Mat->m[1][0] + z * Mat->m[2][0],
469 x * Mat->m[0][1] +
y * Mat->m[1][1] + z * Mat->m[2][1],
470 x * Mat->m[0][2] +
y * Mat->m[1][2] + z * Mat->m[2][2] );
476 class ShadowMatrix4x4{
public:
float m[4][4]; };
477 const ShadowMatrix4x4* Mat = (
const ShadowMatrix4x4*)&mat;
480 x * Mat->m[0][0] +
y * Mat->m[1][0] + z * Mat->m[2][0] + Mat->m[3][0],
481 x * Mat->m[0][1] +
y * Mat->m[1][1] + z * Mat->m[2][1] + Mat->m[3][1],
482 x * Mat->m[0][2] +
y * Mat->m[1][2] + z * Mat->m[2][2] + Mat->m[3][2]);
488 class ShadowMatrix3x3{
public:
float m[3][3]; };
489 const ShadowMatrix3x3* Mat = (
const ShadowMatrix3x3*)&mat;
491 float xp =
x * Mat->m[0][0] +
y * Mat->m[1][0] + z * Mat->m[2][0];
492 float yp =
x * Mat->m[0][1] +
y * Mat->m[1][1] + z * Mat->m[2][1];
493 float zp =
x * Mat->m[0][2] +
y * Mat->m[1][2] + z * Mat->m[2][2];
495 x = xp;
y = yp; z = zp;
503 class ShadowMatrix4x4{
public:
float m[4][4]; };
504 const ShadowMatrix4x4* Mat = (
const ShadowMatrix4x4*)&mat;
506 float xp =
x * Mat->m[0][0] +
y * Mat->m[1][0] + z * Mat->m[2][0] + Mat->m[3][0];
507 float yp =
x * Mat->m[0][1] +
y * Mat->m[1][1] + z * Mat->m[2][1] + Mat->m[3][1];
508 float zp =
x * Mat->m[0][2] +
y * Mat->m[1][2] + z * Mat->m[2][2] + Mat->m[3][2];
510 x = xp;
y = yp; z = zp;
520 inline_ operator const float*()
const {
return &
x; }
530 #endif //__ICEPOINT_H__ inline_ Point operator*(const Point &p) const
Operator for Point Mul = Point * Point.
#define IR(x)
Integer representation of a floating-point value.
inline_ Point & SetMinusInfinity()
inline_ Point & operator*=(const Matrix3x3 &mat)
Operator for Point *= Matrix3x3.
#define MAX(a, b)
Returns the max value between a and b.
inline_ bool operator!=(const Point &p) const
Operator for "if(Point!=Point)".
inline_ float SquareMagnitude() const
Computes square magnitude.
inline_ Point operator+(const Point &p) const
Operator for Point Plus = Point + Point.
inline_ Point & Herp(const Point &p0, const Point &p1, const Point &p2, const Point &p3, float t)
inline_ Point & Add(const float f[3])
Adds a vector.
inline_ Point & Mac(const Point &a, float scalar)
this = this + a * scalar
FUNCTION ICEMATHS_API void Normalize2(Point &a)
inline_ Point & Set(const float f[3])
Assignment from array.
inline_ Point & Sub(const Point &p)
Subtracts a vector.
#define IS_NEGATIVE_FLOAT(x)
inline_ Point & ClampLength(float limit_length)
Clamps vector length.
inline_ float Volume() const
Computes volume.
#define FR(x)
Floating-point representation of an integer value.
inline_ Point & operator*=(float s)
Operator for Point *= float.
inline_ Point & Mac2(const Point &a, const Point &b, float scalarb, const Point &c, float scalarc)
this = a + b * scalarb + c * scalarc
static int min(int a, int b)
#define MIN(a, b)
Returns the min value between a and b.
inline_ BOOL IsZero() const
Tests for exact zero vector.
inline_ Point & Lerp(const Point &a, const Point &b, float t)
Linear interpolate between two vectors: this = a + t * (b - a)
inline_ float SquareDistance(const Point &b) const
Computes square distance to another point.
inline_ float Distance(const Point &b) const
Computes distance to another point.
inline_ Point(const float f[3])
Constructor from array.
png_bytep png_bytep png_size_t length
inline_ Point operator/(const Point &p) const
Operator for Point Div = Point / Point.
inline_ ~Point()
Destructor.
inline_ Point operator-() const
Unary operator for Point Negate = - Point.
inline_ udword GetHashValue() const
Hash function from Ville Miettinen.
int BOOL
Another boolean type.
inline_ friend Point operator/(float s, const Point &p)
Operator for Point Scale = float / Point.
unsigned int udword
sizeof(udword) must be 4
inline_ Point & Set(const Point &src)
Assignment from another point.
inline_ Point & Sub(const float f[3])
Subtracts a vector.
inline_ Point & Add(const Point &p)
Adds a vector.
inline_ Point & operator*=(const Point &p)
Operator for Point *= Point.
inline_ Point & SetPlusInfinity()
inline_ Point & operator*=(const Matrix4x4 &mat)
Operator for Point *= Matrix4x4.
inline_ udword VectorCode() const
Vector code ( bitmask = sign(z) | sign(y) | sign(x) )
inline_ Point & operator+=(float s)
Operator for Point += float.
inline_ float Magnitude() const
Computes magnitude.
inline_ Point operator^(const Point &p) const
Operator for Point VecProd = Point ^ Point.
inline_ Point & operator-=(const Point &p)
Operator for Point -= Point.
inline_ Point & Mac(const Point &a, const Point &b, float scalar)
this = a + b * scalar
inline_ Point & Neg()
this = -this
inline_ BOOL IsValid() const
Checks point validity.
inline_ Point operator*(float s) const
Operator for Point Scale = Point * float.
#define MAX_FLOAT
max possible float value
inline_ Point & Mult(float s)
Multiplies by a scalar.
inline_ Point & Msc(const Point &a, const Point &b, float scalar)
this = a - b * scalar
inline_ Point & Mult(const Point &a, float scalar)
this = a * scalar
inline_ PointComponent LargestAxis() const
Returns largest axis.
inline_ bool IsValidFloat(float value)
inline_ Point & Set(float _x, float _y, float _z)
Assignment from values.
inline_ bool operator==(const Point &p) const
Operator for "if(Point==Point)".
inline_ Point & Add(float _x, float _y, float _z)
Adds a vector.
inline_ float Max() const
Returns MAX(x, y, z);.
inline_ Point & SetLength(float length)
Sets vector length.
void Tweak(udword coord_mask, udword tweak_mask)
Slighty moves the point.
inline_ Point & Add(const Point &p, const Point &q)
Adds vectors.
inline_ Point(const Point &p)
Copy constructor.
inline_ Point(float _x, float _y, float _z)
Constructor from a single float.
inline_ float Dot(const Point &p) const
Dot product dp = this|a.
inline_ PointComponent SmallestAxis() const
Returns smallest axis.
inline_ Point & Zero()
Clears the vector.
inline_ float Min() const
Returns MIN(x, y, z);.
inline_ Point operator-(const Point &p) const
Operator for Point Minus = Point - Point.
inline_ Point & Sub(float _x, float _y, float _z)
Subtracts a vector.
inline_ PointComponent ClosestAxis() const
Returns closest axis.
FUNCTION ICEMATHS_API void Normalize1(Point &a)
inline_ Point & Max(const Point &p)
Sets each element to be componentwise maximum.
inline_ Point & Clamp(float min, float max)
Clamps each element.
inline_ Point & Min(const Point &p)
Sets each element to be componentwise minimum.
inline_ float operator|(const Point &p) const
Operator for float DotProd = Point | Point.
inline_ Point & operator-=(float s)
Operator for Point -= float.
#define AIR(x)
Absolute integer representation of a floating-point value.
inline_ Point & Neg(const Point &a)
this = -a
inline_ Point & operator/=(float s)
Operator for Point /= float.
inline_ Point operator/(float s) const
Operator for Point Scale = Point / float.
inline_ Point()
Empty constructor.
inline_ Point & Sub(const Point &p, const Point &q)
Subtracts vectors.
inline_ Point & operator+=(const Point &p)
Operator for Point += Point.
inline_ Point & Cross(const Point &a, const Point &b)
Cross product this = a x b.
inline_ bool ApproxZero() const
Checks the point is near zero.
inline_ Point operator*(const Matrix3x3 &mat) const
Operator for Point Mul = Point * Matrix3x3.
inline_ Point & Msc2(const Point &a, const Point &b, float scalarb, const Point &c, float scalarc)
this = a - b * scalarb - c * scalarc
#define MIN_FLOAT
min possible loat value
static int max(int a, int b)
inline_ friend Point operator*(float s, const Point &p)
Operator for Point Scale = float * Point.
inline_ Point & operator/=(const Point &p)
Operator for Point /= Point.
inline_ Point operator*(const Matrix4x4 &mat) const
Operator for Point Mul = Point * Matrix4x4.
inline_ void TweakSmaller()
Slighty moves the point in.
inline_ Point & Normalize()
Normalizes the vector.
inline_ Point & Msc(const Point &a, float scalar)
this = this - a * scalar