Vector3.hpp

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 1997,1998,1999
00003    Kenji Hiranabe, Eiwa System Management, Inc.
00004 
00005    This program is free software.
00006    Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
00007    conforming to the Java(TM) 3D API specification by Sun Microsystems.
00008 
00009    Permission to use, copy, modify, distribute and sell this software
00010    and its documentation for any purpose is hereby granted without fee,
00011    provided that the above copyright notice appear in all copies and
00012    that both that copyright notice and this permission notice appear
00013    in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
00014    makes no representations about the suitability of this software for any
00015    purpose.  It is provided "AS IS" with NO WARRANTY.
00016 
00017    Copyright (C) 2004
00018    Rune Myrland, Skalden Studio AS
00019    SagaEngine adaptions, involving conversion from floating point values to fixed point values.
00020    Kenji Hiranabe's license apply.
00021 */
00022 #ifndef base_vecmath_Vector3_hpp
00023 #define base_vecmath_Vector3_hpp
00024 
00025 #include "util_vecmath.hpp"
00026 #include "Tuple3.hpp"
00027 
00028 namespace se_core {
00035     class _SeCoreExport Vector3 : public Tuple3 {
00036     public:
00043         Vector3(coor_t x, coor_t y, coor_t z): Tuple3(x, y, z) { }
00044 
00049         Vector3(const coor_t v[]): Tuple3(v) {  }
00050 
00055         Vector3(const Tuple3& t1): Tuple3(t1) { }
00056 
00060         Vector3(): Tuple3() { }
00061 
00067         void cross(const Vector3& v1, const Vector3& v2) {
00068             // store on stack once for aliasing-safty
00069             // i.e. safe when a.cross(a, b)
00070             set(
00071                 CoorT::fromd(static_cast<coor_double_t>(v1.y_)*v2.z_ - static_cast<coor_double_t>(v1.z_)*v2.y_),
00072                 CoorT::fromd(static_cast<coor_double_t>(v1.z_)*v2.x_ - static_cast<coor_double_t>(v1.x_)*v2.z_),
00073                 CoorT::fromd(static_cast<coor_double_t>(v1.x_)*v2.y_ - static_cast<coor_double_t>(v1.y_)*v2.x_)
00074                 );
00075         }
00076 
00081         void normalize(const Vector3& v1) {
00082             set(v1);
00083             normalize();
00084         }
00085 
00089         void normalize() {
00090             coor_t d = length();
00091 
00092             // zero-div may occur.
00093             x_ = CoorT::fromd(static_cast<coor_double_t>(x_)) / d;
00094             y_ = CoorT::fromd(static_cast<coor_double_t>(y_)) / d;
00095             z_ = CoorT::fromd(static_cast<coor_double_t>(z_)) / d;
00096         }
00097 
00102         coor_t dot(const Vector3& v1) const {
00103             return
00104                 CoorT::fromd((static_cast<coor_double_t>(x_)*v1.x_)
00105                 + (static_cast<coor_double_t>(y_)*v1.y_)
00106                 + (static_cast<coor_double_t>(z_)*v1.z_));
00107         }
00108 
00113         coor_double_t lengthSquared() const {
00114             return
00115                 (static_cast<coor_double_t>(x_)*x_)
00116                 + (static_cast<coor_double_t>(y_)*y_)
00117                 + (static_cast<coor_double_t>(z_)*z_);
00118         }
00119 
00124         coor_double_t xzLengthSquared() const {
00125             return
00126                 (static_cast<coor_double_t>(x_)*x_)
00127                 + (static_cast<coor_double_t>(z_)*z_);
00128         }
00129 
00130 
00131         coor_t xzLength() const;
00132 
00137         coor_t length() const;
00138 
00139 
00147         bray_t angle(const Vector3& v1) const;
00148 
00149         bray_t yaw() const;
00150 
00151         void rotate(const Quat4& q);
00152         void rotate(const Vector3& v, const Quat4& q);
00153         void rotateInverse(const Quat4& q);
00154 
00155         void rotate(const Euler3& a);
00156         void rotate(const Vector3& v, const Euler3& a);
00157         void rotateInverse(const Euler3& a);
00158 
00159         void setForward(const coor_t len, const bray_t yaw);
00160         void setForward(const coor_t len, const bray_t yaw, const bray_t pitch);
00161         void setForward(const coor_t len, const Euler3& a1);
00162 
00163 
00164         // copy constructor and operator = is made by complier
00165 
00166         Vector3& operator=(const Tuple3& t) {
00167             Tuple3::operator=(t);
00168             return *this;
00169         }
00170 
00171         static const Vector3 ZERO;
00172         static const Vector3 UNIT_FORWARD;
00173 
00174     };
00175 
00176 } // Namespace
00177 
00178 
00179 inline
00180 se_core::Vector3 operator*(scale_t s, const se_core::Vector3& t1) {
00181     return operator*(s, (const se_core::Tuple3&)t1);
00182 }
00183 
00184 #endif /* VECTOR3_H */

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:13 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo