-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsglmatrixobj.cpp
More file actions
130 lines (116 loc) · 2.63 KB
/
Copy pathsglmatrixobj.cpp
File metadata and controls
130 lines (116 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// C++ Implementation: sglmatrixobj
//
// Description:
//
//
// Author: Enrico Reimer,,, <enni@Akira>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "sglmatrixobj.h"
#include "sglmisc.h"
#include <string.h>
#ifdef __APPLE__
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
SGLMatrixObj::SGLMatrixObj(GLenum type)
{
MatrMode= type;
}
void SGLMatrixObj::SetPosAndScale(GLdouble x, GLdouble y, GLdouble z, GLdouble fact)
{
ResetTransformMatrix(NULL);
MyTransformMatrix[12]=x;
MyTransformMatrix[13]=y;
MyTransformMatrix[14]=z;
MyTransformMatrix[0]=MyTransformMatrix[5]=MyTransformMatrix[10]=fact;
}
void SGLMatrixObj::Move(SGLVektor to){Move(to.SGLV_X,to.SGLV_Y,to.SGLV_Z);}
void SGLMatrixObj::Move(GLdouble x,GLdouble y, GLdouble z)
{
loadMatrix();
glTranslated(x,y,z);
saveMatrix(MatrMode);
unloadMatrix();
}
void SGLMatrixObj::Scale(GLdouble xfact,GLdouble yfact, GLdouble zfact)
{
loadMatrix();
glScaled(xfact,yfact,zfact);
saveMatrix(MatrMode);
unloadMatrix();
}
void SGLMatrixObj::Rotate(GLdouble xfact,GLdouble yfact, GLdouble zfact, GLdouble amount)
{
loadMatrix();
glRotated(amount,xfact,yfact,zfact);
saveMatrix(MatrMode);
unloadMatrix();
}
void SGLMatrixObj::ResetTransformMatrix(const GLdouble *newMatrix)
{
if(newMatrix)memcpy(MyTransformMatrix,newMatrix,sizeof(GLdouble)*16);
else for(int i=0;i<16;i++)
{
if(i%5)MyTransformMatrix[i]=0;
else MyTransformMatrix[i]=1;
}
}
const GLdouble* SGLMatrixObj::getTransformMatrix() const{
return MyTransformMatrix;
}
void SGLMatrixObj::Scale(GLdouble fact){Scale(fact,fact,fact);}
/*!
\fn SGLMatrixObj::loadMatrix()
*/
void SGLMatrixObj::loadMatrix()
{
glMatrixMode(MatrMode);
glPushMatrix();
glMultMatrixd(MyTransformMatrix);
}
/*!
\fn SGLMatrixObj::unloadMatrix()
*/
void SGLMatrixObj::unloadMatrix()
{
glMatrixMode(MatrMode);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
/*!
\fn SGLMatrixObj::saveAktMatrix()
*/
void SGLMatrixObj::saveAktMatrix(GLdouble dst[16])
{
if(dst==0)dst=MyTransformMatrix;
saveMatrix(sglGeti(GL_MATRIX_MODE),dst);
}
void SGLMatrixObj::saveMatrix(GLenum mode,GLdouble dst[16])
{
#define CASE_SET(CASE) case CASE:type=CASE ## _MATRIX
GLenum type;
if(dst==0)dst=MyTransformMatrix;
switch(mode)
{
CASE_SET(GL_MODELVIEW);break;
CASE_SET(GL_PROJECTION);break;
CASE_SET(GL_TEXTURE);break;
// CASE_SET(GL_COLOR);break; @todo fixme
default:SGLprintError("Unbekannter MatrixMode");type=0;break;
}
if(type)glGetDoublev(type,dst);
#undef CASE_SET
}
/*!
\fn SGLObjBase::guesType()
*/
const char* SGLMatrixObj::guesType()
{
return typeid(*this).name();
}
SGLMatrixObj::~SGLMatrixObj(){}