Subversion Repositories gelsvn

Rev

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

Rev 2 Rev 595
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * @brief Abstract 2D floating point vector class
-
 
6
 * ----------------------------------------------------------------------- */
-
 
7
 
-
 
8
/** @file ArithVec2Float.h
-
 
9
 * @brief Abstract 2D floating point vector class
-
 
10
 */
-
 
11
 
1
#ifndef __CGLA__ARITHVEC2FLOAT_H__
12
#ifndef __CGLA__ARITHVEC2FLOAT_H__
2
#define __CGLA__ARITHVEC2FLOAT_H__
13
#define __CGLA__ARITHVEC2FLOAT_H__
3
 
14
 
4
#include "ArithVecFloat.h"
15
#include "ArithVecFloat.h"
5
 
16
 
6
namespace CGLA {
17
namespace CGLA {
7
 
18
 
8
	template<class T, class V>
19
	template<class T, class V>
9
	class ArithVec2Float: public ArithVecFloat<T,V,2>
20
	class ArithVec2Float: public ArithVecFloat<T,V,2>
10
	{
21
	{
11
	public:
22
	public:
12
 
23
 
13
		/// Construct a 2D float vector.
24
		/// Construct a 2D float vector.
14
		ArithVec2Float(T a, T b): ArithVecFloat<T,V,2>(a,b) {}
25
		ArithVec2Float(T a, T b): ArithVecFloat<T,V,2>(a,b) {}
15
 
26
 
16
		/// Construct a 2D float vector.
27
		/// Construct a 2D float vector.
17
		ArithVec2Float() {}		
28
		ArithVec2Float() {}		
18
	};
29
	};
19
 
30
 
20
	/// Returns normalized vector
31
	/// Returns normalized vector
21
	template<class T, class V>
32
	template<class T, class V>
22
	inline V normalize(const ArithVec2Float<T,V>& v) 
33
	inline V normalize(const ArithVec2Float<T,V>& v) 
23
	{
34
	{
24
		return v/v.length();
35
		return v/v.length();
25
	}
36
	}
26
 
37
 
27
	/// Rotates vector 90 degrees to obtain orthogonal vector
38
	/// Rotates vector 90 degrees to obtain orthogonal vector
28
	template<class T, class V>
39
	template<class T, class V>
29
	inline V orthogonal(const ArithVec2Float<T,V>& v) 
40
	inline V orthogonal(const ArithVec2Float<T,V>& v) 
30
	{
41
	{
31
		return V(-v[1],v[0]);
42
		return V(-v[1],v[0]);
32
	}
43
	}
33
 
44
 
34
	// Computes (scalar) cross product from two vectors	
45
	// Computes (scalar) cross product from two vectors	
35
	template<class T, class V>
46
	template<class T, class V>
36
	inline T cross(const ArithVec2Float<T,V>& a, 
47
	inline T cross(const ArithVec2Float<T,V>& a, 
37
								 const ArithVec2Float<T,V>& b)
48
								 const ArithVec2Float<T,V>& b)
38
	{
49
	{
39
		return a[0]*b[1]-a[1]*b[0];
50
		return a[0]*b[1]-a[1]*b[0];
40
	}
51
	}
41
 
52
 
42
	/** The two last (scalar) arguments are the linear combination of 
53
	/** The two last (scalar) arguments are the linear combination of 
43
			the two first arguments (vectors) which produces the third argument.
54
			the two first arguments (vectors) which produces the third argument.
44
			*/
55
			*/
45
	template<class T, class V>
56
	template<class T, class V>
46
	bool linear_combine(const ArithVec2Float<T,V>& a,
57
	bool linear_combine(const ArithVec2Float<T,V>& a,
47
											const ArithVec2Float<T,V>& b,
58
											const ArithVec2Float<T,V>& b,
48
											const ArithVec2Float<T,V>& c,
59
											const ArithVec2Float<T,V>& c,
49
											T&,
60
											T&,
50
											T&);
61
											T&);
51
 
62
 
52
 
63
 
53
}
64
}
54
 
65
 
55
#endif
66
#endif
56
 
67
 
57
 
68