TrueReality  v0.1.1912
Quat.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 #pragma once
22 #include "Export.h"
23 
24 #include <trBase/Vec4f.h>
25 #include <trBase/Vec4d.h>
26 #include <trBase/Vec3f.h>
27 #include <trBase/Vec3d.h>
28 
29 #include <osg/Quat>
30 
31 #include <iostream>
32 #include <string>
33 
34 namespace trBase
35 {
36  class Matrixd;
37  class Matrixf;
38 
45  {
46  public:
47 
48  using value_type = double;
49 
53  Quat();
54 
60  Quat(const Quat& q);
61 
67  Quat(const osg::Quat& q);
68 
78 
84  Quat(const Vec4f& v);
85 
91  Quat(const Vec4d& v);
92 
99  Quat(value_type angle, const Vec3f& axis);
100 
107  Quat(value_type angle, const Vec3d& axis);
108 
120  Quat(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3);
121 
133  Quat(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3);
134 
138  osg::Quat& GetOSGQuat();
139 
143  const osg::Quat& GetOSGQuat() const;
144 
150  Vec4d AsVec4() const;
151 
157  Vec3d AsVec3() const;
158 
164  void Set(const Quat& q);
165 
171  void Set(const osg::Quat& q);
172 
181  void Set(value_type x, value_type y, value_type z, value_type w);
182 
188  void Set(const Vec4f& v);
189 
195  void Set(const Vec4d& v);
196 
200  void Set(const Matrixf& matrix);
201 
205  void Set(const Matrixd& matrix);
206 
210  void Get(Matrixf& matrix) const;
211 
215  void Get(Matrixd& matrix) const;
216 
222  void Set(const osg::Matrixf& matrix);
223 
229  void Set(const osg::Matrixd& matrix);
230 
236  void Get(osg::Matrixf& matrix) const;
237 
243  void Get(osg::Matrixd& matrix) const;
244 
251  bool IsZeroRotation() const;
252 
258  value_type Length() const;
259 
265  value_type Length2() const;
266 
272  trBase::Quat Conj() const;
273 
279  const trBase::Quat Inverse() const;
280 
290  void MakeRotate(value_type angle, value_type x, value_type y, value_type z);
291 
299  void MakeRotate(value_type angle, const Vec3f& vec);
300 
308  void MakeRotate(value_type angle, const Vec3d& vec);
309 
323  void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3);
324 
338  void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3);
339 
352  void MakeRotate(const Vec3f& vec1, const Vec3f& vec2);
353 
366  void MakeRotate(const Vec3d& vec1, const Vec3d& vec2);
367 
376  void GetRotate(value_type& angle, value_type& x, value_type& y, value_type& z) const;
377 
384  void GetRotate(value_type& angle, Vec3f& vec) const;
385 
392  void GetRotate(value_type& angle, Vec3d& vec) const;
393 
399  void Clear();
400 
409  void Slerp(value_type t, const Quat& from, const Quat& to);
410 
414  value_type& X();
415 
419  value_type& Y();
420 
424  value_type& Z();
425 
429  value_type& W();
430 
434  value_type X() const;
435 
439  value_type Y() const;
440 
444  value_type Z() const;
445 
449  value_type W() const;
450 
454  value_type & operator [] (int i);
455 
459  value_type operator [] (int i) const;
460 
464  Quat& operator = (const Quat& v);
465 
469  bool operator == (const Quat& v) const;
470 
474  bool operator != (const Quat& v) const;
475 
479  bool operator < (const Quat& v) const;
480 
484  bool operator > (const Quat& v) const;
485 
489  const Quat operator * (value_type rhs) const;
490 
494  Vec3f operator* (const Vec3f& v) const;
495 
499  Vec3d operator* (const Vec3d& v) const;
500 
504  Quat& operator *= (value_type rhs);
505 
509  const Quat operator*(const Quat& rhs) const;
510 
514  Quat& operator*=(const Quat& rhs);
515 
519  Quat operator / (value_type rhs) const;
520 
524  Quat& operator /= (value_type rhs);
525 
529  const Quat operator/(const Quat& denom) const;
530 
534  Quat& operator/=(const Quat& denom);
535 
539  const Quat operator + (const Quat& rhs) const;
540 
544  Quat& operator += (const Quat& rhs);
545 
549  const Quat operator - (const Quat& rhs) const;
550 
554  Quat& operator -= (const Quat& rhs);
555 
560  const Quat operator - () const;
561 
565  operator osg::Quat () const;
566 
570  operator osg::Quat& ();
571 
575  operator const osg::Quat& () const;
576 
580  operator osg::Quat* ();
581 
591  std::string ToString(int precision = -1);
592 
593  protected:
594 
595  osg::Quat mQuat;
596  };
597 
603  TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Quat& q);
604 }
605 
606 
607 
608 
#define TR_BASE_EXPORT
Definition: trBase/Export.h:34
std::string operator+(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:193
bool operator==(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:187
General purpose 3D float Vector.
Definition: Vec4f.h:47
bool operator!=(const std::string &s1, const RefStr &s2)
Definition: RefStr.h:199
TR_BASE_EXPORT std::ostream & operator<<(std::ostream &ios, const Matrixd &q)
Stream insertion operator.
A float Matrix class to be used for generic matrix operations.
Definition: Matrixd.h:40
General purpose 3D double Vector.
Definition: Vec3d.h:47
General purpose 3D double Vector.
Definition: Vec4d.h:47
std::string ToString(const T &t, int precision=-1)
A utility function to convert a basic type into a string.
Definition: StringUtils.h:334
Represents a quaternion, that is used for angular calculations and transformations.
Definition: Quat.h:44
A float Matrix class to be used for generic matrix operations.
Definition: Matrixf.h:41
osg::Quat mQuat
Definition: Quat.h:595
double value_type
Definition: Quat.h:48
General purpose 3D float Vector.
Definition: Vec3f.h:47