Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/extensions/authoring/source/VHACD/inc/vhacdVector.h

Go to the documentation of this file.
00001 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
00002  All rights reserved.
00003  
00004  
00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00006  
00007  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00008  
00009  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00010  
00011  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
00012  
00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00014  */
00015 #pragma once
00016 #ifndef VHACD_VECTOR_H
00017 #define VHACD_VECTOR_H
00018 #include <iostream>
00019 #include <math.h>
00020 
00021 namespace VHACD {
00023 template <typename T>
00024 class Vec3 {
00025 public:
00026     T& operator[](size_t i) { return m_data[i]; }
00027     const T& operator[](size_t i) const { return m_data[i]; }
00028     T& X();
00029     T& Y();
00030     T& Z();
00031     const T& X() const;
00032     const T& Y() const;
00033     const T& Z() const;
00034     void Normalize();
00035     T GetNorm() const;
00036     void operator=(const Vec3& rhs);
00037     void operator+=(const Vec3& rhs);
00038     void operator-=(const Vec3& rhs);
00039     void operator-=(T a);
00040     void operator+=(T a);
00041     void operator/=(T a);
00042     void operator*=(T a);
00043     Vec3 operator^(const Vec3& rhs) const;
00044     T operator*(const Vec3& rhs) const;
00045     Vec3 operator+(const Vec3& rhs) const;
00046     Vec3 operator-(const Vec3& rhs) const;
00047     Vec3 operator-() const;
00048     Vec3 operator*(T rhs) const;
00049     Vec3 operator/(T rhs) const;
00050     bool operator<(const Vec3& rhs) const;
00051     bool operator>(const Vec3& rhs) const;
00052     Vec3();
00053     Vec3(T a);
00054     Vec3(T x, T y, T z);
00055     Vec3(const Vec3& rhs);
00056     /*virtual*/ ~Vec3(void);
00057 
00058     // Compute the center of this bounding box and return the diagonal length
00059     T GetCenter(const Vec3 &bmin, const Vec3 &bmax)
00060     {
00061         X() = (bmin.X() + bmax.X())*0.5;
00062         Y() = (bmin.Y() + bmax.Y())*0.5;
00063         Z() = (bmin.Z() + bmax.Z())*0.5;
00064         T dx = bmax.X() - bmin.X();
00065         T dy = bmax.Y() - bmin.Y();
00066         T dz = bmax.Z() - bmin.Z();
00067         T diagonal = T(sqrt(dx*dx + dy*dy + dz*dz));
00068         return diagonal;
00069     }
00070 
00071     // Update the min/max values relative to this point
00072     void UpdateMinMax(Vec3 &bmin,Vec3 &bmax) const
00073     {
00074         if (X() < bmin.X())
00075         {
00076             bmin.X() = X();
00077         }
00078         if (Y() < bmin.Y())
00079         {
00080             bmin.Y() = Y();
00081         }
00082         if (Z() < bmin.Z())
00083         {
00084             bmin.Z() = Z();
00085         }
00086         if (X() > bmax.X())
00087         {
00088             bmax.X() = X();
00089         }
00090         if (X() > bmax.X())
00091         {
00092             bmax.X() = X();
00093         }
00094         if (Y() > bmax.Y())
00095         {
00096             bmax.Y() = Y();
00097         }
00098         if (Z() > bmax.Z())
00099         {
00100             bmax.Z() = Z();
00101         }
00102     }
00103 
00104     // Returns the squared distance between these two points
00105     T GetDistanceSquared(const Vec3 &p) const
00106     {
00107         T dx = X() - p.X();
00108         T dy = Y() - p.Y();
00109         T dz = Z() - p.Z();
00110         return dx*dx + dy*dy + dz*dz;
00111     }
00112 
00113     T GetDistance(const Vec3 &p) const
00114     {
00115         return sqrt(GetDistanceSquared(p));
00116     }
00117 
00118     // Returns the raw vector data as a pointer
00119     T* GetData(void) 
00120     {
00121         return m_data;
00122     }
00123 private:
00124     T m_data[3];
00125 };
00127 template <typename T>
00128 class Vec2 {
00129 public:
00130     T& operator[](size_t i) { return m_data[i]; }
00131     const T& operator[](size_t i) const { return m_data[i]; }
00132     T& X();
00133     T& Y();
00134     const T& X() const;
00135     const T& Y() const;
00136     void Normalize();
00137     T GetNorm() const;
00138     void operator=(const Vec2& rhs);
00139     void operator+=(const Vec2& rhs);
00140     void operator-=(const Vec2& rhs);
00141     void operator-=(T a);
00142     void operator+=(T a);
00143     void operator/=(T a);
00144     void operator*=(T a);
00145     T operator^(const Vec2& rhs) const;
00146     T operator*(const Vec2& rhs) const;
00147     Vec2 operator+(const Vec2& rhs) const;
00148     Vec2 operator-(const Vec2& rhs) const;
00149     Vec2 operator-() const;
00150     Vec2 operator*(T rhs) const;
00151     Vec2 operator/(T rhs) const;
00152     Vec2();
00153     Vec2(T a);
00154     Vec2(T x, T y);
00155     Vec2(const Vec2& rhs);
00156     /*virtual*/ ~Vec2(void);
00157 
00158 private:
00159     T m_data[2];
00160 };
00161 
00162 template <typename T>
00163 const bool Colinear(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& c);
00164 template <typename T>
00165 const T ComputeVolume4(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& c, const Vec3<T>& d);
00166 }
00167 #include "vhacdVector.inl" // template implementation
00168 #endif
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com