mPoint4.h
Classes:
Public Typedefs
Vector4F
Points can be vectors!
Public Functions
Detailed Description
Public Typedefs
typedef Point4F Vector4F
Points can be vectors!
Public Functions
mDot(const Point4F & p1, const Point4F & p2)
mIsNaN(const Point4F & p)
operator*(F32 mul, const Point4F & multiplicand)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _MPOINT4_H_ 25#define _MPOINT4_H_ 26 27#ifndef _MMATHFN_H_ 28#include "math/mMathFn.h" 29#endif 30 31#ifndef _MPOINT3_H_ 32#include "math/mPoint3.h" 33#endif 34 35 36//------------------------------------------------------------------------------ 37/// 4D integer point 38/// 39/// Uses S32 internally. Currently storage only. 40class Point4I 41{ 42 public: 43 Point4I() :x(0), y(0), z(0), w(0) {} 44 Point4I(S32 _x, S32 _y, S32 _z, S32 _w); 45 46 void zero(); ///< Zero all values 47 48 S32 x; 49 S32 y; 50 S32 z; 51 S32 w; 52 53 //-------------------------------------- Public static constants 54 public: 55 const static Point4I One; 56 const static Point4I Zero; 57}; 58 59//------------------------------------------------------------------------------ 60/// 4D floating-point point. 61/// 62/// Uses F32 internally. 63/// 64/// Useful for representing quaternions and other 4d beasties. 65class Point4F 66{ 67 //-------------------------------------- Public data 68 public: 69 F32 x; ///< X co-ordinate. 70 F32 y; ///< Y co-ordinate. 71 F32 z; ///< Z co-ordinate. 72 F32 w; ///< W co-ordinate. 73 74 public: 75 Point4F(); ///< Create an uninitialized point. 76 Point4F(const Point4F&); ///< Copy constructor. 77 78 /// Create point from coordinates. 79 Point4F(F32 _x, F32 _y, F32 _z, F32 _w); 80 81 /// Set point's coordinates. 82 void set(F32 _x, F32 _y, F32 _z, F32 _w); 83 84 /// Interpolate from _pt1 to _pt2, based on _factor. 85 /// 86 /// @param _pt1 Starting point. 87 /// @param _pt2 Ending point. 88 /// @param _factor Interpolation factor (0.0 .. 1.0). 89 void interpolate(const Point4F& _pt1, const Point4F& _pt2, F32 _factor); 90 91 void zero(); 92 93 operator F32*() { return (&x); } 94 operator const F32*() const { return &x; } 95 96 F32 len() const; 97 98 Point4F operator/(F32) const; 99 100 Point4F operator*(F32) const; 101 Point4F operator+(const Point4F&) const; 102 Point4F& operator+=(const Point4F&); 103 Point4F operator-(const Point4F&) const; 104 Point4F operator*(const Point4F&) const; 105 Point4F& operator*=(const Point4F&); 106 Point4F& operator=(const Point3F&); 107 Point4F& operator=(const Point4F&); 108 109 Point3F asPoint3F() const { return Point3F(x,y,z); } 110 111 //-------------------------------------- Public static constants 112 public: 113 const static Point4F One; 114 const static Point4F Zero; 115}; 116 117typedef Point4F Vector4F; ///< Points can be vectors! 118 119//------------------------------------------------------------------------------ 120//-------------------------------------- Point4I 121 122inline void Point4I::zero() 123{ 124 x = y = z = w = 0; 125} 126 127//------------------------------------------------------------------------------ 128//-------------------------------------- Point4F 129// 130inline Point4F::Point4F() 131 :x(0.0f), y(0.0f), z(0.0f), w(0.0f) 132{ 133} 134 135inline Point4F::Point4F(const Point4F& _copy) 136 : x(_copy.x), y(_copy.y), z(_copy.z), w(_copy.w) 137{ 138} 139 140inline Point4F::Point4F(F32 _x, F32 _y, F32 _z, F32 _w) 141 : x(_x), y(_y), z(_z), w(_w) 142{ 143} 144 145inline void Point4F::set(F32 _x, F32 _y, F32 _z, F32 _w) 146{ 147 x = _x; 148 y = _y; 149 z = _z; 150 w = _w; 151} 152 153inline F32 Point4F::len() const 154{ 155 return mSqrt(x*x + y*y + z*z + w*w); 156} 157 158inline void Point4F::interpolate(const Point4F& _from, const Point4F& _to, F32 _factor) 159{ 160 x = (_from.x * (1.0f - _factor)) + (_to.x * _factor); 161 y = (_from.y * (1.0f - _factor)) + (_to.y * _factor); 162 z = (_from.z * (1.0f - _factor)) + (_to.z * _factor); 163 w = (_from.w * (1.0f - _factor)) + (_to.w * _factor); 164} 165 166inline void Point4F::zero() 167{ 168 x = y = z = w = 0.0f; 169} 170 171inline Point4F& Point4F::operator=(const Point3F &_vec) 172{ 173 x = _vec.x; 174 y = _vec.y; 175 z = _vec.z; 176 w = 1.0f; 177 return *this; 178} 179 180inline Point4F& Point4F::operator=(const Point4F &_vec) 181{ 182 x = _vec.x; 183 y = _vec.y; 184 z = _vec.z; 185 w = _vec.w; 186 187 return *this; 188} 189 190inline Point4F Point4F::operator+(const Point4F& _add) const 191{ 192 return Point4F( x + _add.x, y + _add.y, z + _add.z, w + _add.w ); 193} 194 195inline Point4F& Point4F::operator+=(const Point4F& _add) 196{ 197 x += _add.x; 198 y += _add.y; 199 z += _add.z; 200 w += _add.w; 201 202 return *this; 203} 204 205inline Point4F Point4F::operator-(const Point4F& _rSub) const 206{ 207 return Point4F( x - _rSub.x, y - _rSub.y, z - _rSub.z, w - _rSub.w ); 208} 209 210inline Point4F Point4F::operator*(const Point4F &_vec) const 211{ 212 return Point4F(x * _vec.x, y * _vec.y, z * _vec.z, w * _vec.w); 213} 214 215inline Point4F Point4F::operator*(F32 _mul) const 216{ 217 return Point4F(x * _mul, y * _mul, z * _mul, w * _mul); 218} 219 220inline Point4F Point4F::operator/(F32 t) const 221{ 222 F32 f = 1.0f / t; 223 return Point4F( x * f, y * f, z * f, w * f ); 224} 225 226inline F32 mDot(const Point4F &p1, const Point4F &p2) 227{ 228 return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z + p1.w*p2.w); 229} 230 231//------------------------------------------------------------------------------ 232//-------------------------------------- Point4F 233 234inline Point4I::Point4I(S32 _x, S32 _y, S32 _z, S32 _w) : x(_x), y(_y), z(_z), w(_w) 235{ 236} 237 238//------------------------------------------------------------------- 239// Non-Member Operators 240//------------------------------------------------------------------- 241 242inline Point4F operator*(F32 mul, const Point4F& multiplicand) 243{ 244 return multiplicand * mul; 245} 246 247inline bool mIsNaN( const Point4F &p ) 248{ 249 return mIsNaN_F( p.x ) || mIsNaN_F( p.y ) || mIsNaN_F( p.z ) || mIsNaN_F( p.w ); 250} 251 252#endif // _MPOINT4_H_ 253