Subversion Repositories gelsvn

Rev

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

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