Subversion Repositories gelsvn

Rev

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

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