00001 #ifndef __VECMATH_VECTOR4_HPP
00002 #define __VECMATH_VECTOR4_HPP
00003
00004 #ifndef __VECMATH_TUPLE4_HPP
00005 #include <vecmath/_Tuple4.h>
00006 #endif
00007
00008 #ifndef __VECMATH_POINT3_HPP
00009 #include <vecmath/_Point3.h>
00010 #endif
00011
00012
00013 #define DEBUGVECTOR4(d)
00014
00015 template <class Type>
00016 class VECMATH_EXPORT _Vector4 : public _Tuple4<Type> {
00017 public:
00018
00019 _Vector4<Type>() : _Tuple4<Type>() {}
00020
00021 explicit _Vector4<Type>(Type x, Type y = 0, Type z = 0, Type w = 0) : _Tuple4<Type>(x, y, z, w) {
00022 DEBUGVECTOR4(cout << "_Vector4 explicit constructor x,y,z,w " << *this << endl);
00023 }
00024
00025 _Vector4<Type>(const _Tuple4<double>& t) : _Tuple4<Type>(t) {
00026 DEBUGVECTOR4(cout << "_Vector4 constructor &double " << *this << endl);
00027 }
00028
00029 _Vector4<Type>(const _Tuple4<float>& t) : _Tuple4<Type>(t) {
00030 DEBUGVECTOR4(cout << "_Vector4 constructor &float " << *this << endl);
00031 }
00032
00033 _Vector4<Type>(const _Tuple3<double>& t) : _Tuple4<Type>(t) {
00034 DEBUGVECTOR4(cout << "_Vector4 constructor &double3 " << *this << endl);
00035 }
00036
00037 _Vector4<Type>(const _Tuple3<float>& t) : _Tuple4<Type>(t) {
00038 DEBUGVECTOR4(cout << "_Vector4 constructor &float3 " << *this << endl);
00039 }
00040
00041 _Vector4<Type>(const Type t[4]) : _Tuple4<Type>(t) {
00042 DEBUGVECTOR4(cout << "_Vector4 constructor t[4] " << *this << endl);
00043 }
00044
00045 Type angle(const _Vector4<Type>& v) const {
00046 double d = dot(v) / (length() * v.lentgh());
00047 if (d < -1)
00048 d = -1;
00049 else if (d > 1)
00050 d = 1;
00051 return (Type) acos(d);
00052 }
00053
00054 Type dot(const _Vector4<Type>& v) const {
00055 return _Tuple4<Type>::x * v.x + _Tuple4<Type>::y * v.y + _Tuple4<Type>::z * v.z + _Tuple4<Type>::w * v.w;
00056 }
00057
00058
00059 Type dot(const _Point3<Type>& v) const {
00060 return _Tuple4<Type>::x * v.x + _Tuple4<Type>::y * v.y + _Tuple4<Type>::z * v.z + _Tuple4<Type>::w;
00061 }
00062
00063 Type lengthSquared() const {
00064 return _Tuple4<Type>::normSquared();
00065 }
00066
00067 Type length() const {
00068 return _Tuple4<Type>::norm();
00069 }
00070
00071 void normalize() {
00072 normalize(*this);
00073 }
00074
00075 void normalize(const _Vector4<Type> &v) {
00076 Type l = v.length();
00077 this->set(v.x / l, v.y / l, v.z / l, v.w / l);
00078 }
00079 };
00080
00081 #endif