vector3.h

Go to the documentation of this file.
00001 /*
00002 This program is distributed under the terms of the 'MIT license'. The text
00003 of this licence follows...
00004 
00005 Copyright (c) 2005 J.D.Medhurst (a.k.a. Tixy)
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 THE SOFTWARE.
00024 */
00025 
00032 #ifndef VECTOR_H
00033 #define VECTOR_H
00034 
00045 #include "fix.h"
00046 
00047 
00048 
00069 class Vector3
00070     {
00071 public:
00075     inline Vector3()
00076         {}
00077 
00085     inline Vector3(fix x,fix y,fix z)
00086         : X(x), Y(y), Z(z) {}
00087 
00094     Vector3 operator - () const;
00095 
00106     Vector3 operator + (const Vector3& vector) const;
00107 
00118     Vector3 operator - (const Vector3& vector) const;
00119 
00131     Vector3 operator * (fix scalar) const;
00132 
00144     Vector3 operator / (fix scalar) const;
00145 
00158     Vector3& operator += (const Vector3& vector);
00159 
00172     Vector3& operator -= (const Vector3& vector);
00173 
00186     Vector3& operator *= (fix scalar);
00187 
00200     Vector3& operator /= (fix scalar);
00201 
00210     bool operator == (const Vector3& vector) const;
00211 
00220     inline bool operator != (const Vector3& vector) const
00221         { return !(*this==vector); }
00222 
00234     fix DotProduct(const Vector3& vector) const;
00235 
00247     Vector3 CrossProduct(const Vector3& vector) const;
00248 
00255     ufix Length() const;
00256 
00274     int CompareLength(ufix length) const;
00275 
00293     int CompareLengths(const Vector3& vector) const;
00294 
00306     uint32_t LengthSquared(uint32_t& fraction) const;
00307 
00317     Vector3 UnitVector() const;
00318 
00331     Vector3 Normal(const Vector3& vector) const;
00332 
00342     fixangle Angle(const Vector3& vector) const;
00343 
00358     Vector3 Normal(const Vector3& point1,const Vector3& point2) const;
00359 
00371     fixangle Angle(const Vector3& point1,const Vector3& point2) const;
00372 
00381     static void Translate(Vector3* outVectors,unsigned vectorCount,const Vector3* inVectors,const Vector3& offset);
00382 
00391     static void Scale(Vector3* outVectors,unsigned vectorCount,const Vector3* inVectors,fix scale);
00392 
00393 private:
00394 
00401     void NormaliseComponents(unsigned bits);
00402 
00403 public:
00404     fix X; 
00405     fix Y; 
00406     fix Z; 
00407     };
00408 
00409 
00413 typedef Vector3 Point3;
00414 
00415 
00416 
00420 class Matrix3
00421     {
00422 public:
00426     inline Matrix3()
00427         {}
00428 
00436     inline Matrix3(const Vector3 row1,const Vector3 row2,const Vector3 row3)
00437         : Row1(row1), Row2(row2), Row3(row3) {}
00438 
00446     Vector3 operator * (const Vector3& vector) const;
00447 
00453     Matrix3 Transposition() const;
00454 
00463     void Transform(Vector3* outVectors,unsigned vectorCount,const Vector3* inVectors);
00464 public:
00465     Vector3 Row1; 
00466     Vector3 Row2; 
00467     Vector3 Row3; 
00468 };
00469 
00470  // End of group
00472 
00473 #endif

Generated by  doxygen 1.6.1