source: trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h @ 2844

Last change on this file since 2844 was 2844, checked in by ldelgass, 8 years ago

Cleanups, no functional changes

File size: 3.6 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2#ifndef VRMATRIX4X4_H
3#define VRMATRIX4X4_H
4
5#include <memory.h>
6
7#include <vrmath/vrLinmath.h>
8#include <vrmath/vrVector3f.h>
9#include <vrmath/vrRotation.h>
10
11class vrMatrix4x4f
12{
13public:
14    vrMatrix4x4f()
15    {
16        makeIdentity();
17    }
18
19    /**
20     * @brief make a identity matrix
21     */
22    void makeIdentity();
23
24    /**
25     * @brief make a translation matrix
26     * @param translation translation
27     */
28    void makeTranslation(const vrVector3f& translation);
29
30    /**
31     * @brief make a translation matrix
32     * @param x x position
33     */
34    void makeTranslation(float x, float y, float z);
35
36    /**
37     * @brief make a rotation matrix
38     * @param rotation rotation
39     */
40    void makeRotation(const vrRotation& rotation);
41
42    /**
43     * @brief Make a rotation matrix
44     * @param rotation rotation
45     */
46    void makeRotation(float x, float y, float z, float angle);
47
48    void makeVecRotVec(const vrVector3f& vec1, const vrVector3f& vec2);
49
50    /**
51     * @brief make a scale matrix
52     * @param scale scale
53     */
54    void makeScale(const vrVector3f& scale);
55    void makeTR(const vrVector3f& translation, const vrRotation& rotation);
56    void makeTRS(const vrVector3f& translation, const vrRotation& rotation, const vrVector3f& scale);
57
58    void multiply(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2);
59
60    void multiply(const vrMatrix4x4f& mat1, const vrVector3f& position);
61    void multiplyScale(const vrMatrix4x4f& mat, const vrVector3f& scale);
62    void multiply(const vrMatrix4x4f& mat1, const vrRotation& rotation);
63    void multiply(const vrVector3f& position, const vrMatrix4x4f& mat1);
64    void multiply(const vrRotation& rotation, const vrMatrix4x4f& mat1);
65    void multiplyScale(const vrVector3f& scale, const vrMatrix4x4f& mat);
66
67    void multiply(const vrMatrix4x4f& mat1);
68    void multiplyFast(const vrMatrix4x4f& mat1, const vrMatrix4x4f& mat2);
69
70    void invert();
71    void invert(const vrMatrix4x4f& mat);
72    void invertFast(const vrMatrix4x4f& mat);
73
74    void transpose();
75    void transpose(const vrMatrix4x4f& mat);
76    void transposeFast(const vrMatrix4x4f& mat);
77       
78    void getTranslation(vrVector3f& vector);
79    void getRotation(vrRotation& rotation);
80
81    /**
82     * @brief return data pointer of the matrix
83     * @return float array of the matrix
84     */
85    const float *get() const;
86
87    /**
88     * @brief return data pointer of the matrix
89     * @return float array of the matrix
90     */
91    float *get();
92
93    /**
94     * @brief set float arrary to this
95     * @param m float matrix values
96     */
97    void set(float *m);
98
99    /**
100     * @brief set double arrary to this
101     * @param m float matrix values
102     */
103    void set(double *m);
104
105private:
106    float _data[16];
107};
108
109inline const float *vrMatrix4x4f::get() const
110{
111    return _data;
112}
113
114inline float *vrMatrix4x4f::get()
115{
116    return _data;
117}
118
119inline void vrMatrix4x4f::set(float *m)
120{
121    memcpy(_data, m, sizeof(float) * 16);
122}
123
124inline void vrMatrix4x4f::getTranslation(vrVector3f& translation)
125{
126    translation.set(_data[12], _data[13], _data[14]);
127}
128
129inline void vrMatrix4x4f::makeTRS(const vrVector3f& translation,
130                                  const vrRotation& rotation,
131                                  const vrVector3f& scale)
132{
133    vrMatrix4x4f mat;
134    mat.makeTR(translation, rotation);
135       
136    makeScale(scale);
137       
138    multiply(mat, *this);
139}
140
141inline void vrMatrix4x4f::makeTR(const vrVector3f& translation,
142                                 const vrRotation& rotation)
143{
144    makeRotation(rotation);
145       
146    _data[12] = translation.x;
147    _data[13] = translation.y;
148    _data[14] = translation.z;
149}
150
151#endif
Note: See TracBrowser for help on using the repository browser.