Subversion Repositories gelsvn

Rev

Rev 2 | Rev 12 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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