Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ef906540db5344cf47e70b763adba1eaa2e74422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
   math/axis.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_MATH_AXIS_H__
#define __INCLUDED_MATH_AXIS_H__

#include <iostream>

#include "math/vector3f.h"
#include "LinearMath/btMatrix3x3.h"
namespace math
{

/// a local coordinates system
class Axis
{
public:
	Axis();
	Axis(const Axis & other);

	void clear();

	void assign(const Axis & other);
	
	void assign(const btMatrix3x3 & other);
	
	/**
	 * @brief assign radiant yaw, pitch and roll angles.
	 * This method changes the sign of the pitch and roll angles
	 * before applying them
	 */
	void assign(const float yaw, const float pitch, const float roll);

	/// global coordinates of the X-axis in the local coordinates system
	inline const Vector3f & forward() const {
		return axis_vector[0];
	}

	/// global coordinates of the Y-axis in the local coordinates system
	inline const Vector3f & left() const {
		return axis_vector[1];
	}

	/// global coordinates of the Z-axis in the local coordinates system
	inline const Vector3f & up() const {
		return axis_vector[2];
	}

	inline Vector3f & operator[](size_t index) {
		return axis_vector[index];
	}

	inline const Vector3f & operator[](size_t index) const {
		return axis_vector[index];
	}

	Axis & operator=(const Axis & other);

	const Axis operator*(const Axis &other) const;

	/**
	 * @brief change axis direction angle
	 * rotate around axis up vector (positive is left)
	 * @param angle angle in degrees
	 **/
	void change_direction(const float angle);

	/**
	 * @brief change axis pitch angle
	 * rotate around left vector (positive is up)
	 * @param angle angle in degrees
	 **/
	void change_pitch(const float angle);

	/**
	 * @brief change axis roll angle
	 * rotate around forward vector (positive is left)
	 * @param angle angle in degrees
	 **/
	void change_roll(const float angle);

	/**
	 * @brief rotation about an arbitrary vector
	 * @param rad angle in radians
	 **/
	void rotate(Vector3f const &normal, float cosa, float sina);
	
	void rotate(const Vector3f & normal, const float rad);

	/// return the transpose of this matrix
	const Axis transpose() const;

private:
	Vector3f		axis_vector[3];
};

/// helper function to conver math::Axis to btMatrix3x3
inline btMatrix3x3 to_btMatrix3x3(const math::Axis &a)
{
	return btMatrix3x3(a[0][0], a[1][0], a[2][0],
			   a[0][1], a[1][1], a[2][1],
			   a[0][2], a[1][2], a[2][2]);
}

/// write an axis to a std::ostream
std::ostream &operator<<(std::ostream & os, const Axis & axis);

/// read an axis from a std::istream
std::istream &operator>>(std::istream & is, Axis & axis);

/// local-to-global coordinates
Vector3f operator*(const Axis &axis, const Vector3f &vector);

}

#endif // __INCLUDED_MATH_AXIS_H__