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

Last change on this file since 2877 was 2877, checked in by ldelgass, 12 years ago

Some minor refactoring, also add some more fine grained config.h defines
(e.g. replace NV40 define with feature defines). Add tests for some required
OpenGL extensions (should always check for extensions or base version before
calling entry points from the extension). Also, clamp diffuse and specular
values on input and warn when they are out of range.

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