~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/MathConverter.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-10-22 23:21:17 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091022232117-isr8u3402qmu7ilo
Tags: 0.5.7-1
* New upstream release.
  - Compile against current ogre (Closes: #551431)
  - Removed debian/patches/ember-gcc4.4.patch. Merged upstream.
  - Updated Depends on ember-media.
* Add libboost-thread-dev tp Build-Depends.
* Make debian/rules independent from upstream version.
* Updated watch file to allow automatic download of new upstream
  tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
-----------------------------------------------------------------------------
3
 
MathConverter.h by Miguel Guzman Miranda (Aglanor)
4
 
Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
5
 
 
6
 
Copyright � 2003 The Worldforge Project (http://www.worldforge.org)
7
 
This file is part of Ember client (http://www.worldforge.org/dev/eng/clients/Ember)
8
 
 
9
 
This code is distributed under the GNU GPL (General Public License).
10
 
See file COPYING for details.
11
 
 
12
 
-----------------------------------------------------------------------------
13
 
 
14
 
-----------------------------------------------------------------------------
15
 
Filename:    MathConverter.h
16
 
Description:    Point, Vector and Quaternion converter
17
 
        for world-centric coordinates (Atlas-wfmath like)
18
 
        to/from screen-centric coordinates (Ogre like).
19
 
 
20
 
        Atlas is World-centric (picture a map):
21
 
                x is east
22
 
                y is north
23
 
                z is up
24
 
 
25
 
        Ogre is screen-centric (picture your monitor screen):
26
 
                x is right
27
 
                y is up
28
 
                z is depth (negative towards the screen,
29
 
                        positive is towards you,
30
 
                        so the coord system is also dextrogyrous)
31
 
 
32
 
        --------------------------------------------------------
33
 
        Example of Atlas --> Ogre conversion
34
 
 
35
 
        Picture this is the world map, in both cases:
36
 
        ^ North
37
 
        |
38
 
        |     East
39
 
        (Up)--->
40
 
 
41
 
 
42
 
        Atlas                   Ogre
43
 
 
44
 
        ^ a.y                   ^ -o.z
45
 
        |                       |
46
 
        |     a.x               |   o.x
47
 
        (a.z)--->               (o.y)--->
48
 
 
49
 
        --------------------------------------------------------
50
 
        Example of Ogre --> Atlas conversion
51
 
 
52
 
        Picture this is your computer screen, in both cases:
53
 
        ^ Up
54
 
        |
55
 
        |      Left
56
 
        (You)--->
57
 
 
58
 
        Ogre                    Atlas
59
 
 
60
 
        ^ o.y                   ^ a.z
61
 
        |                       |
62
 
        |     o.x               |      a.x
63
 
        (o.z)--->               (-a.y)--->http://mandriva.com/en/community/start
64
 
 
65
 
        The math is:
66
 
 
67
 
        Atlas.x = Ogre.x
68
 
        Atlas.y = -Ogre.z
69
 
        Atlas.z = Ogre.y
70
 
 
71
 
        Ogre.x = Atlas.x
72
 
        Ogre.y = Atlas.z
73
 
        Ogre.z = -Atlas.y
74
 
 
75
 
-----------------------------------------------------------------------------
76
 
*/
77
 
 
78
 
#ifndef __MATH_CONVERTER_H__
79
 
#define __MATH_CONVERTER_H__
80
 
 
81
 
// ------------------------------
82
 
// Include WFmath header files
83
 
// ------------------------------
84
 
#include <wfmath/point.h>
85
 
#include <wfmath/vector.h>
86
 
#include <wfmath/axisbox.h>
87
 
#include <wfmath/quaternion.h>
88
 
#include <wfmath/const.h>
89
 
 
90
 
namespace EmberOgre {
91
 
 
92
 
/**
93
 
 * @brief Converts a 2d WFMath::Point<2> into a 3d Ogre vector.
94
 
 * The vertical position of the resulting vector will be zero.
95
 
 * @param p A 2d Worldforge position.
96
 
 * @return A 3d Ogre vector.
97
 
 */
98
 
Ogre::Vector3 Atlas2Ogre(const WFMath::Point<2>& p);
99
 
 
100
 
/**
101
 
 * @brief Converts a 2d WFMath::Point<2> into a 2d Ogre vector.
102
 
 * @param p A 2d Worldforge position.
103
 
 * @return A 2d Ogre vector.
104
 
 */
105
 
Ogre::Vector2 Atlas2Ogre_Vector2(const WFMath::Point<2>& p);
106
 
 
107
 
/**
108
 
 * @brief Converts a 2d vector into a 2d Ogre vector.
109
 
 * @param p A 2d Worldforge vector.
110
 
 * @return A 2d Ogre vector.
111
 
 */
112
 
Ogre::Vector2 Atlas2Ogre(const WFMath::Vector<2>& p);
113
 
 
114
 
/**
115
 
 * @brief Converts an Ogre 3d vector into a Worldforge 3d point.
116
 
 * @param p A 3d Ogre vector.
117
 
 * @return A 3d Worldforge point.
118
 
 */
119
 
WFMath::Point<3> Ogre2Atlas(const Ogre::Vector3& p);
120
 
 
121
 
/**
122
 
 * @brief Converts an Ogre 2d vector into a Worldforge 2d point.
123
 
 * @param p A 2d Ogre vector.
124
 
 * @return A 2d Worldforge point.
125
 
 */
126
 
WFMath::Point<2> Ogre2Atlas(const Ogre::Vector2& p);
127
 
 
128
 
/**
129
 
 * @brief Converts an Ogre 3d vector into a Worldforge 2d point.
130
 
 * @param p A 3d Ogre vector.
131
 
 * @return A 2d Worldforge point.
132
 
 */
133
 
WFMath::Point<2> Ogre2Atlas_TerrainPosition(const Ogre::Vector3& p);
134
 
 
135
 
/**
136
 
 * @brief Converts an Ogre 3d vector into a Worldforge 3d vector.
137
 
 * @param p A 3d Ogre vector.
138
 
 * @return A 3d Worldforge vector.
139
 
 */
140
 
WFMath::Vector<3> Ogre2Atlas_Vector3(const Ogre::Vector3& p);
141
 
 
142
 
/**
143
 
 * @brief Converts a Worldforge 3d point into an Ogre 3d vector.
144
 
 * @param p A 3d Worldforge point.
145
 
 * @return A 3d Ogre vector.
146
 
 */
147
 
Ogre::Vector3 Atlas2Ogre(const WFMath::Point<3>& p);
148
 
 
149
 
/**
150
 
 * @brief Converts a Worldforge 3d vector into an Ogre 3d vector.
151
 
 * @param v A 3d Worldforge vector.
152
 
 * @return A 3d Ogre vector.
153
 
 */
154
 
Ogre::Vector3 Atlas2Ogre(const WFMath::Vector<3>& v);
155
 
 
156
 
/**
157
 
 * @brief Converts a Worldforge quaternion into an Ogre quaternion.
158
 
 * @param aq A Worldforge quaternion.
159
 
 * @return An Ogre quaternion.
160
 
 */
161
 
Ogre::Quaternion Atlas2Ogre(const WFMath::Quaternion& aq);
162
 
 
163
 
/**
164
 
 * @brief Converts an Ogre quaternion into a Worldforge quaternion.
165
 
 * @param aq An Ogre quaternion.
166
 
 * @return A Worldforge quaternion.
167
 
 */
168
 
WFMath::Quaternion Ogre2Atlas(const Ogre::Quaternion& aq);
169
 
 
170
 
/**
171
 
 * @brief Converts a Worldforge 3d axisbox into an Ogre 3d axisbox.
172
 
 * @param axisBox A Worldforge 3d axisbox.
173
 
 * @return An Ogre 3d axisbox.
174
 
 */
175
 
Ogre::AxisAlignedBox Atlas2Ogre(const WFMath::AxisBox<3>& axisBox);
176
 
 
177
 
/**
178
 
 * @brief Converts a Worldforge 2d axisbox into an Ogre TRect.
179
 
 * @param atlasBox A Worldforge 2d axisbox.
180
 
 * @return An Ogre TRect.
181
 
 */
182
 
Ogre::TRect<Ogre::Real> Atlas2Ogre(const WFMath::AxisBox<2>& atlasBox);
183
 
 
184
 
 
185
 
/**
186
 
 * @brief Converts an Ogre 3d axisbox into a Worldforge 3d axisbox.
187
 
 * @param axisBox An Ogre 3d axisbox.
188
 
 * @return A Worldforge 3d axisbox.
189
 
 */
190
 
WFMath::AxisBox<3> Ogre2Atlas(const Ogre::AxisAlignedBox& axisBox);
191
 
 
192
 
/**
193
 
 * @brief Converts an Ogre TRect into a Worldforge 2d axisbox.
194
 
 * @param bounds An Ogre TRect instance.
195
 
 * @return A Worldforge 2d axisbox.
196
 
 */
197
 
WFMath::AxisBox<2> Ogre2Atlas(const Ogre::TRect<Ogre::Real>& bounds);
198
 
 
199
 
 
200
 
///Implementations
201
 
 
202
 
inline Ogre::Vector3 Atlas2Ogre(const WFMath::Point<2>& p) {
203
 
        return Ogre::Vector3(p.x(),0,-p.y());
204
 
}
205
 
 
206
 
inline Ogre::Vector2 Atlas2Ogre(const WFMath::Vector<2>& p) {
207
 
        return Ogre::Vector2(p.x(),-p.y());
208
 
}
209
 
 
210
 
inline Ogre::Vector2 Atlas2Ogre_Vector2(const WFMath::Point<2>& p) {
211
 
        return Ogre::Vector2(p.x(),-p.y());
212
 
}
213
 
 
214
 
inline WFMath::Point<3> Ogre2Atlas(const Ogre::Vector3& p) {
215
 
        return WFMath::Point<3>(p.x,-p.z,p.y);
216
 
}
217
 
 
218
 
inline WFMath::Point<2> Ogre2Atlas(const Ogre::Vector2& p) {
219
 
        return WFMath::Point<2>(p.x,-p.y);
220
 
}
221
 
 
222
 
inline WFMath::Point<2> Ogre2Atlas_TerrainPosition(const Ogre::Vector3& p) {
223
 
        return WFMath::Point<2>(p.x,-p.z);
224
 
}
225
 
 
226
 
inline WFMath::Vector<3> Ogre2Atlas_Vector3(const Ogre::Vector3& p) {
227
 
        return WFMath::Vector<3>(p.x,-p.z,p.y);
228
 
}
229
 
 
230
 
inline Ogre::Vector3 Atlas2Ogre(const WFMath::Point<3>& p){
231
 
        return Ogre::Vector3(p.x(),p.z(),-p.y());
232
 
}
233
 
 
234
 
inline Ogre::Vector3 Atlas2Ogre(const WFMath::Vector<3>& v){
235
 
        return Ogre::Vector3(v.x(),v.z(),-v.y());
236
 
}
237
 
 
238
 
inline Ogre::Quaternion Atlas2Ogre(const WFMath::Quaternion& aq){
239
 
        if (!aq.isValid()) {
240
 
                return Ogre::Quaternion::IDENTITY;
241
 
        }
242
 
        return Ogre::Quaternion(aq.scalar(),aq.vector().x(),aq.vector().z(),-aq.vector().y());
243
 
}
244
 
 
245
 
inline WFMath::Quaternion Ogre2Atlas(const Ogre::Quaternion& aq){
246
 
        return WFMath::Quaternion(aq.w,aq.x,-aq.z,aq.y);
247
 
}
248
 
 
249
 
inline Ogre::AxisAlignedBox Atlas2Ogre(const WFMath::AxisBox<3>& axisBox){
250
 
        if (!axisBox.isValid()) {
251
 
                return Ogre::AxisAlignedBox();
252
 
        }
253
 
        return Ogre::AxisAlignedBox(axisBox.lowCorner().x(), axisBox.lowCorner().z(), -axisBox.highCorner().y(), axisBox.highCorner().x(), axisBox.highCorner().z(), -axisBox.lowCorner().y());
254
 
}
255
 
 
256
 
inline Ogre::TRect<Ogre::Real> Atlas2Ogre(const WFMath::AxisBox<2>& atlasBox) {
257
 
        if (!atlasBox.isValid()) {
258
 
                return Ogre::TRect<Ogre::Real>();
259
 
        }
260
 
        return Ogre::TRect<Ogre::Real>(atlasBox.lowCorner().x(), -atlasBox.highCorner().y(), atlasBox.highCorner().x(), -atlasBox.lowCorner().y());
261
 
}
262
 
 
263
 
inline WFMath::AxisBox<3> Ogre2Atlas(const Ogre::AxisAlignedBox& axisBox){
264
 
        if (axisBox.isNull() || axisBox.isInfinite()) {
265
 
                return WFMath::AxisBox<3>();
266
 
        }
267
 
        return WFMath::AxisBox<3>(WFMath::Point<3>(axisBox.getMinimum().x, -axisBox.getMaximum().z, axisBox.getMinimum().y), WFMath::Point<3>(axisBox.getMaximum().x, -axisBox.getMinimum().z, axisBox.getMaximum().y));
268
 
}
269
 
 
270
 
inline WFMath::AxisBox<2> Ogre2Atlas(const Ogre::TRect<Ogre::Real>& bounds){
271
 
        return WFMath::AxisBox<2>(WFMath::Point<2>(bounds.left, -bounds.top), WFMath::Point<2>(bounds.right, -bounds.bottom));
272
 
}
273
 
 
274
 
}
275
 
 
276
 
#endif