Vector4.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 #ifndef base_vecmath_Vector4_hpp
00018 #define base_vecmath_Vector4_hpp
00019 
00020 #include "Tuple4.hpp"
00021 #include "Tuple3.hpp"
00022 
00023 namespace se_core {
00024 
00030     class _SeCoreExport Vector4 : public Tuple4 {
00031     public:
00039         Vector4(coor_t x, coor_t y, coor_t z, coor_t w): Tuple4(x, y, z, w) { }
00040 
00045         Vector4(const coor_t v[]): Tuple4(v) { }
00046 
00051         Vector4(const Tuple4& t1): Tuple4(t1) { }
00052 
00056         Vector4(): Tuple4() { }
00057 
00067         Vector4(const Tuple3& t1): Tuple4(t1.x_, t1.y_, t1.z_, 0) { }
00068 
00081         void set3(const Tuple3& t1) {
00082             x_ = t1.x_;
00083             y_ = t1.y_;
00084             z_ = t1.z_;
00085             w_ = 0;
00086         }
00087 
00092         coor_double_t lengthSquared() const {
00093             return static_cast<coor_double_t>(x_)*x_
00094                 + static_cast<coor_double_t>(y_)*y_
00095                 + static_cast<coor_double_t>(z_)*z_
00096                 + static_cast<coor_double_t>(w_)*w_;
00097         }
00098 
00103         coor_t length() const;
00104 
00105 
00111         coor_t dot(const Vector4& v1) const {
00112             return CoorT::fromd
00113                 ((static_cast<coor_double_t>(x_) * v1.x_)
00114                 + (static_cast<coor_double_t>(y_) * v1.y_)
00115                 + (static_cast<coor_double_t>(z_) * v1.z_)
00116                 + (static_cast<coor_double_t>(w_) * v1.w_));
00117         }
00118 
00123         void normalize(const Vector4& v1) {
00124             Tuple4::set(v1);
00125             normalize();
00126         }
00127 
00131         void normalize() {
00132             coor_t d = length();
00133 
00134             // zero-div may occur.
00135             x_ = CoorT::fromd(static_cast<coor_double_t>(x_)) / d;
00136             y_ = CoorT::fromd(static_cast<coor_double_t>(y_)) / d;
00137             z_ = CoorT::fromd(static_cast<coor_double_t>(z_)) / d;
00138             w_ = CoorT::fromd(static_cast<coor_double_t>(w_)) / d;
00139         }
00140 
00148         bray_t angle(const Vector4& v1) const {
00149             LogFatal("Not implmented");
00150             /*
00151             // zero div may occur.
00152             coor_t d = dot(v1);
00153             coor_t v1_length = v1.length();
00154             coor_t v_length = length();
00155 
00156             // numerically, domain error may occur
00157             return T(acos(d/v1_length/v_length));
00158             */
00159             return 0;
00160         }
00161 
00162         // copy constructor and operator = is made by complier
00163 
00164         Vector4& operator=(const Tuple4& t) {
00165             Tuple4::operator=(t);
00166             return *this;
00167         }
00168     };
00169 
00170 } // Namespace
00171 
00172 template <class T>
00173 inline
00174 se_core::Vector4 operator*(scale_t s, const se_core::Vector4& t1) {
00175     return operator*(s, (const se_core::Tuple4&)t1);
00176 }
00177 
00178 #endif /* VECTOR4_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