Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
optransfrm.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1998-2001 by Jorrit Tyberghein
3  Largely rewritten by Ivan Avramovic <ivan@avramovic.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 #ifndef __CS_TRANSFORM_H__
21 #define __CS_TRANSFORM_H__
22 
23 #include "opmatrix3.h"
24 
26 
34 {
35 protected:
40 
41 public:
45  csTransform () : m_o2t (), v_o2t (0, 0, 0) {}
46 
54  csTransform (const csMatrix3& other2this, const csVector3& origin_pos) :
55  m_o2t (other2this), v_o2t (origin_pos) {}
56 
61  inline const csMatrix3& GetO2T () const { return m_o2t; }
62 
67  inline const csVector3& GetO2TTranslation () const { return v_o2t; }
68 
72  inline const csVector3& GetOrigin () const { return v_o2t; }
73 
78  virtual void SetO2T (const csMatrix3& m) { m_o2t = m; }
79 
84  virtual void SetO2TTranslation (const csVector3& v) { v_o2t = v; }
85 
89  inline void SetOrigin (const csVector3& v) { SetO2TTranslation (v); }
90 
94  inline void Translate (const csVector3& v) { SetO2TTranslation (v_o2t + v); }
95 
100  inline csVector3 Other2This (const csVector3& v) const
101  {
102  return m_o2t * (v - v_o2t);
103  }
104 
110  { return m_o2t * v; }
111 
115 // csPlane3 Other2This (const csPlane3& p) const;
116 
121 // csPlane3 Other2ThisRelative (const csPlane3& p) const;
122 
128 // void Other2This (const csPlane3& p, const csVector3& point,
129 // csPlane3& result) const;
130 
134  friend csVector3 operator* (const csVector3& v, const csTransform& t);
135 
137  friend csVector3 operator* (const csTransform& t, const csVector3& v);
139  friend csVector3& operator*= (csVector3& v, const csTransform& t);
141 // friend csPlane3 operator* (const csPlane3& p, const csTransform& t);
143 // friend csPlane3 operator* (const csTransform& t, const csPlane3& p);
145 // friend csPlane3& operator*= (csPlane3& p, const csTransform& t);
146 
148  friend csMatrix3 operator* (const csMatrix3& m, const csTransform& t);
150  friend csMatrix3 operator* (const csTransform& t, const csMatrix3& m);
152  friend csMatrix3& operator*= (csMatrix3& m, const csTransform& t);
154  friend csTransform operator* (const csTransform& t1,
155  const csReversibleTransform& t2);
156 
162 // static csTransform GetReflect (const csPlane3& pl);
163 };
164 
173 {
174 protected:
177 
181  csReversibleTransform (const csMatrix3& o2t, const csMatrix3& t2o,
182  const csVector3& pos) : csTransform (o2t,pos), m_t2o (t2o) {}
183 
184 public:
189 
194  csTransform (
195  csMatrix3 (m.r[0],m.r[3],m.r[6],
196  m.r[1],m.r[4],m.r[7],
197  m.r[2],m.r[5],m.r[8]).GetInverse(),
198  csVector3 (m.p.i,m.p.j,m.p.k)),
199  m_t2o(m.r[0],m.r[3],m.r[6],
200  m.r[1],m.r[4],m.r[7],
201  m.r[2],m.r[5],m.r[8]) {
202  }
210  csReversibleTransform (const csMatrix3& o2t, const csVector3& pos) :
211  csTransform (o2t,pos) { m_t2o = m_o2t.GetInverse (); }
212 
217  csTransform (t) { m_t2o = m_o2t.GetInverse (); }
218 
220  csTransform (t) { m_t2o = t.m_t2o; }
221 
225  inline const csMatrix3& GetT2O () const { return m_t2o; }
226 
230  inline csVector3 GetT2OTranslation () const { return -m_o2t*v_o2t; }
231 
236  { return csReversibleTransform (m_t2o, m_o2t, -m_o2t*v_o2t); }
237 
241  virtual void SetO2T (const csMatrix3& m)
242  { m_o2t = m; m_t2o = m_o2t.GetInverse (); }
243 
247  virtual void SetT2O (const csMatrix3& m)
248  { m_t2o = m; m_o2t = m_t2o.GetInverse (); }
249 
255  { return v_o2t + m_t2o * v; }
256 
261  inline csVector3 This2OtherRelative (const csVector3& v) const
262  { return m_t2o * v; }
263 
267 // csPlane3 This2Other (const csPlane3& p) const;
268 
273 // csPlane3 This2OtherRelative (const csPlane3& p) const;
274 
280 // void This2Other (const csPlane3& p, const csVector3& point,
281 // csPlane3& result) const;
282 
283 
289  void RotateOther (const csVector3& v, float angle);
290 
296  void RotateThis (const csVector3& v, float angle);
297 
303  void RotateOther (const csMatrix3& m) { SetT2O (m * m_t2o); }
304 
310  void RotateThis (const csMatrix3& m) { SetT2O (m_t2o * m); }
311 
317  void LookAt (const csVector3& v, const csVector3& up);
318 
320  friend csVector3 operator/ (const csVector3& v, const csReversibleTransform& t);
324 // friend csPlane3 operator/ (const csPlane3& p, const csReversibleTransform& t);
326 // friend csPlane3& operator/= (csPlane3& p, const csReversibleTransform& t);
329  const csReversibleTransform& t2)
330  {
331  t1.v_o2t = t2.m_t2o*t1.v_o2t;
332  t1.v_o2t += t2.v_o2t;
333  t1.m_o2t *= t2.m_o2t;
334  t1.m_t2o *= t1.m_t2o;
335  return t1;
336  }
339  const csReversibleTransform& t2)
340  {
341  return csReversibleTransform (t1.m_o2t*t2.m_o2t, t2.m_t2o*t1.m_t2o,
342  t2.v_o2t + t2.m_t2o*t1.v_o2t);
343  }
345  friend csTransform operator* (const csTransform& t1,
346  const csReversibleTransform& t2);
349  const csReversibleTransform& t2);
352  const csReversibleTransform& t2);
353 };
354 
362 {
363 public:
368 
372  csOrthoTransform (const csMatrix3& o2t, const csVector3& pos) :
373  csReversibleTransform (o2t, o2t.GetTranspose (), pos) { }
374 
379  csReversibleTransform (t.GetO2T (), t.GetO2T ().GetTranspose (), t.GetO2TTranslation ()) { }
380 
384  virtual void SetO2T (const csMatrix3& m)
385  { m_o2t = m; m_t2o = m_o2t.GetTranspose (); }
386 
390  virtual void SetT2O (const csMatrix3& m)
391  { m_t2o = m; m_o2t = m_t2o.GetTranspose (); }
392 };
393 
394 #endif // __CS_TRANSFORM_H__