GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Matrix4f.hpp
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2 ** This software is in the public domain, furnished "as is", without technical
3 ** support, and with no warranty, express or implied, as to its usefulness for
4 ** any purpose.
5 **
6 ** Matrix4f.hpp
7 ** Declares a 4x4 matrix consisting of 16 float values and its helper functions
8 **
9 ** Author: Nim
10 ** -------------------------------------------------------------------------*/
11 
12 #pragma once
13 #ifndef MATRIX4F_HPP
14 #define MATRIX4F_HPP
15 
16 #include <string>
17 
18 namespace radix {
19 
20 class Matrix3f;
21 class Vector3f;
22 class Vector4f;
23 class Quaternion;
24 
25 class Matrix4f {
26 public:
27  static const Matrix4f Identity;
28 
29  /* Core */
30  Matrix4f();
31  Matrix4f(const Vector3f&, const Quaternion&);
32  void setIdentity();
33  void translate(const Vector3f &v);
34  void rotate(float angle, float x, float y, float z);
35  void rotate(const Quaternion &quat);
36  void scale(float scale);
37  void scale(const Vector3f &scale);
38  Vector3f transform(const Vector3f &v) const;
39 
40  float* toArray();
41  std::string str() const;
42 
43  Quaternion getRotation() const;
44  Vector3f getPosition() const;
45 
46  /* Operator overloads */
47  inline float operator[](int i) const {
48  return a[i];
49  }
50  inline float& operator[](int i) {
51  return a[i];
52  }
53  bool operator==(const Matrix4f&) const;
54  bool operator!=(const Matrix4f&) const;
55  Matrix4f operator*(const Matrix4f&) const;
56  Vector4f operator*(const Vector4f&) const;
57  Vector3f operator*(const Vector3f&) const;
58 private:
59  float a[16];
60 };
61 
62 /* Utility functions */
63 Matrix4f transpose(const Matrix4f& m);
64 float determinant(const Matrix4f& m);
65 Matrix4f inverse(const Matrix4f& m);
66 Matrix3f toMatrix3f(const Matrix4f& m);
67 
68 } /* namespace radix */
69 
70 #endif /* MATRIX4F_HPP */
Definition: GameController.hpp:7
void translate(const Vector3f &v)
Definition: Matrix4f.cpp:49
Quaternion getRotation() const
Definition: Matrix4f.cpp:154
float & operator[](int i)
Definition: Matrix4f.hpp:50
Definition: Vector4f.hpp:117
Definition: Matrix3f.hpp:24
void scale(float scale)
Definition: Matrix4f.cpp:97
Matrix4f operator*(const Matrix4f &) const
Definition: Matrix4f.cpp:195
Matrix3f inverse(const Matrix3f &m)
Definition: Matrix3f.cpp:150
4-dimensional float-based vector/point storage and manipulation struct
Definition: Vector4f.hpp:22
void setIdentity()
Definition: Matrix4f.cpp:45
Matrix3f toMatrix3f(const Matrix4f &m)
Definition: Matrix4f.cpp:308
float a[16]
Definition: Matrix4f.hpp:59
float operator[](int i) const
Definition: Matrix4f.hpp:47
Matrix4f()
Definition: Matrix4f.cpp:35
std::string str() const
Definition: Matrix4f.cpp:143
bool operator!=(const Matrix4f &) const
Definition: Matrix4f.cpp:191
Vector3f getPosition() const
Definition: Matrix4f.cpp:182
static const Matrix4f Identity
Definition: Matrix4f.hpp:27
float * toArray()
Definition: Matrix4f.cpp:139
Matrix3f transpose(const Matrix3f &m)
Definition: Matrix3f.cpp:128
void rotate(float angle, float x, float y, float z)
Definition: Matrix4f.cpp:56
Definition: Matrix4f.hpp:25
Vector3f transform(const Vector3f &v) const
Definition: Matrix4f.cpp:131
float determinant(const Matrix3f &m)
Definition: Matrix3f.cpp:142
3-dimensional float-based vector/point storage and manipulation struct
Definition: Vector3f.hpp:27
bool operator==(const Matrix4f &) const
Definition: Matrix4f.cpp:187