Subversion Repositories gelsvn

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 119
1
#ifndef __CGLA__ARITHVEC2FLOAT_H__
1
#ifndef __CGLA__ARITHVEC2FLOAT_H__
2
#define __CGLA__ARITHVEC2FLOAT_H__
2
#define __CGLA__ARITHVEC2FLOAT_H__
3
 
3
 
4
#include "ArithVecFloat.h"
4
#include "ArithVecFloat.h"
5
 
5
 
6
namespace CGLA {
6
namespace CGLA {
7
 
7
 
8
	template<class T, class V>
8
	template<class T, class V>
9
	class ArithVec2Float: public ArithVecFloat<T,V,2>
9
	class ArithVec2Float: public ArithVecFloat<T,V,2>
10
	{
10
	{
11
	public:
11
	public:
12
 
12
 
13
		/// Construct a 2D float vector.
13
		/// Construct a 2D float vector.
14
		ArithVec2Float(T a, T b): ArithVecFloat<T,V,2>(a,b) {}
14
		ArithVec2Float(T a, T b): ArithVecFloat<T,V,2>(a,b) {}
15
 
15
 
16
		/// Construct a 2D float vector.
16
		/// Construct a 2D float vector.
17
		ArithVec2Float() {}		
17
		ArithVec2Float() {}		
18
	};
18
	};
19
 
19
 
20
	/// Returns normalized vector
20
	/// Returns normalized vector
21
	template<class T, class V>
21
	template<class T, class V>
22
	inline V normalize(const ArithVec2Float<T,V>& v) 
22
	inline V normalize(const ArithVec2Float<T,V>& v) 
23
	{
23
	{
24
		return v/v.length();
24
		return v/v.length();
25
	}
25
	}
26
 
26
 
27
	/// Rotates vector 90 degrees to obtain orthogonal vector
27
	/// Rotates vector 90 degrees to obtain orthogonal vector
28
	template<class T, class V>
28
	template<class T, class V>
29
	inline V orthogonal(const ArithVec2Float<T,V>& v) 
29
	inline V orthogonal(const ArithVec2Float<T,V>& v) 
30
	{
30
	{
31
		return V(-v[1],v[0]);
31
		return V(-v[1],v[0]);
32
	}
32
	}
33
 
33
 
34
	// Computes (scalar) cross product from two vectors	
34
	// Computes (scalar) cross product from two vectors	
35
	template<class T, class V>
35
	template<class T, class V>
36
	inline T cross(const ArithVec2Float<T,V>& a, 
36
	inline T cross(const ArithVec2Float<T,V>& a, 
37
								 const ArithVec2Float<T,V>& b)
37
								 const ArithVec2Float<T,V>& b)
38
	{
38
	{
39
		return a[0]*b[1]-a[1]*b[0];
39
		return a[0]*b[1]-a[1]*b[0];
40
	}
40
	}
41
 
41
 
42
	/** The two last (scalar) arguments are the linear combination of 
42
	/** The two last (scalar) arguments are the linear combination of 
43
			the two first arguments (vectors) which produces the third argument.
43
			the two first arguments (vectors) which produces the third argument.
44
			*/
44
			*/
45
	template<class T, class V>
45
	template<class T, class V>
46
	bool linear_combine(const ArithVec2Float<T,V>& a,
46
	bool linear_combine(const ArithVec2Float<T,V>& a,
47
											const ArithVec2Float<T,V>& b,
47
											const ArithVec2Float<T,V>& b,
48
											const ArithVec2Float<T,V>& c,
48
											const ArithVec2Float<T,V>& c,
49
											T&,
49
											T&,
50
											T&);
50
											T&);
51
 
51
 
52
 
52
 
53
}
53
}
54
 
54
 
55
#endif
55
#endif
56
 
56
 
57
 
57