Subversion Repositories gelsvn

Rev

Rev 10 | Rev 43 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 12
Line 3... Line 3...
3
 
3
 
4
#include "ArithVec.h"
4
#include "ArithVec.h"
5
 
5
 
6
namespace CGLA {
6
namespace CGLA {
7
 
7
 
8
	template<class T, class V, int N>
8
  template<class T, class V, int N>
9
	class ArithVecFloat: public ArithVec<T,V,N>
9
    class ArithVecFloat: public ArithVec<T,V,N>
10
	{
10
    {
11
#define for_all_i(expr) for(int i=0;i<N;i++) {expr;}
11
#define for_all_i(expr) for(int i=0;i<N;i++) {expr;}
12
 
12
 
13
	public:
13
    public:
14
 
14
	  
15
		ArithVecFloat() 
15
      ArithVecFloat() 
16
			{
16
	{
17
#ifndef NDEBUG
17
#ifndef NDEBUG
18
			for_all_i(data[i]=CGLA_INIT_VALUE);
18
	  for_all_i(data[i]=CGLA_INIT_VALUE);
19
#endif
19
#endif
20
			}
20
	}
21
 
21
	  
22
		ArithVecFloat(T a): 
22
      ArithVecFloat(T a): 
23
			ArithVec<T,V,N>(a) {}
23
	ArithVec<T,V,N>(a) {}
24
 
24
 
25
		ArithVecFloat(T a, T b): 
25
      ArithVecFloat(T a, T b): 
26
			ArithVec<T,V,N>(a,b) {}
26
	ArithVec<T,V,N>(a,b) {}
27
 
27
 
28
		ArithVecFloat(T a, T b, T c): 
28
      ArithVecFloat(T a, T b, T c): 
29
			ArithVec<T,V,N>(a,b,c) {}
29
	ArithVec<T,V,N>(a,b,c) {}
30
 
30
 
31
		ArithVecFloat(T a, T b, T c, T d): 
31
      ArithVecFloat(T a, T b, T c, T d): 
32
			ArithVec<T,V,N>(a,b,c,d) {}
32
	ArithVec<T,V,N>(a,b,c,d) {}
33
 
33
 
34
		/// Compute Euclidean length.
34
      /// Compute Euclidean length.
35
		T length() const 
35
      T length() const 
36
    {
36
	{
37
      return sqrt(sqr_length(*this));
37
	  return sqrt(sqr_length(*this));
38
    }
38
	}
39
    
39
    
40
		/// Normalize vector.
40
      /// Normalize vector.
41
		void normalize() 
41
      void normalize() 
42
    {
-
 
43
      (*this) /= length();
-
 
44
    }
-
 
45
		
-
 
46
	};
-
 
47
 
-
 
48
	/// Returns normalized vector
-
 
49
	template<class T, class V, int N>
-
 
50
	inline T length(const ArithVecFloat<T,V,N>& v) 
-
 
51
	{
42
	{
52
		return v.length();
43
	  (*this) /= length();
53
	}
44
	}
-
 
45
		
-
 
46
    };
-
 
47
 
-
 
48
  /// Returns normalized vector
-
 
49
  template<class T, class V, int N>
-
 
50
    inline T length(const ArithVecFloat<T,V,N>& v) 
-
 
51
    {
-
 
52
      return v.length();
-
 
53
    }
54
	
54
	
55
	
55
	
56
	/// Returns normalized vector
56
  /// Returns normalized vector
57
	template<class T, class V, int N>
57
  template<class T, class V, int N>
58
	inline V normalize(const ArithVecFloat<T,V,N>& v) 
58
    inline V normalize(const ArithVecFloat<T,V,N>& v) 
59
	{
59
    {
60
		return v/v.length();
60
      return v/v.length();
61
	}
61
    }
62
#undef for_all_i
62
#undef for_all_i
63
}
63
}
64
 
64
 
65
#endif
65
#endif
66
 
66