27 #if defined(HAVE_CONFIG_H)
30 #include "wx/glcanvas.h"
31 #if defined(HAVE_GL_GLU_H)
33 #elif defined(HAVE_OPENGL_GLU_H)
34 #include <OpenGL/glu.h>
57 if (!IsShownOnScreen())
66 sx = 1.0f / (GLfloat)event.GetSize().x;
67 sy = 1.0f / (GLfloat)event.GetSize().y;
72 glViewport(0, 0, event.GetSize().x, event.GetSize().y);
74 glMatrixMode(GL_PROJECTION);
77 gluPerspective(30.0, (GLfloat)event.GetSize().x / (GLfloat)event.GetSize().y, 1.0, 100.0);
80 glMatrixMode(GL_MODELVIEW);
91 static int dragging = 0;
92 static float last_x, last_y;
94 GLfloat dx, dy, a, rot0[3][3], rot1[3][3], ax, ay;
100 if (event.LeftIsDown())
111 dx = (
event.GetX() - last_x) *
sx;
112 dy = (
event.GetY() - last_y) *
sy;
116 a = sqrtf(dx * dx + dy * dy);
129 rot0[0][0] = (ax * ax + ay * ay * cosf(a)) / (ax * ax + ay * ay);
130 rot0[0][1] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
131 rot0[0][2] = ay * sinf(a) / sqrtf(ax * ax + ay * ay);
132 rot0[1][0] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
133 rot0[1][1] = (ax * ax * cosf(a) + ay * ay) / (ax * ax + ay * ay);
134 rot0[1][2] = ax * sinf(a) / sqrtf(ax * ax + ay * ay);
135 rot0[2][0] = -ay * sinf(a) / sqrtf(ax * ax + ay * ay);
136 rot0[2][1] = -ax * sinf(a) / sqrtf(ax * ax + ay * ay);
137 rot0[2][2] = cosf(a);
139 for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) rot1[i][j] =
rot[i][j];
141 for (i = 0; i < 3; i++) {
142 for (j = 0; j < 3; j++) {
143 rot[i][j] = rot0[i][0] * rot1[0][j]
144 + rot0[i][1] * rot1[1][j]
145 + rot0[i][2] * rot1[2][j];
152 if (cosf(
thetay) != 0.0) {
161 else thetaz = 6.283185307f - acosf(
rot[1][1]);
163 thetax *= 180.0f / 3.14159265f;
164 thetay *= 180.0f / 3.14159265f;
165 thetaz *= 180.0f / 3.14159265f;
188 last_x =
event.GetX();
189 last_y =
event.GetY();
196 wheel =
event.GetWheelRotation();
205 else if (wheel < 0) {
213 if (event.LeftDClick()) {
214 trans[0] = (
event.GetX() *
sx * 2.0 - 1.0) /
scl;
215 trans[1] = -(
event.GetY() *
sy * 2.0 - 1.0) /
scl;
228 switch (event.GetKeyCode())
273 glClearColor(0.0, 0.0, 0.0, 0.0);
274 glEnable(GL_DEPTH_TEST);
275 glEnable(GL_LIGHTING);
276 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
279 glEnable(GL_NORMALIZE);
280 glEnableClientState(GL_VERTEX_ARRAY);
281 glEnable(GL_COLOR_MATERIAL);
282 PostSizeEventToParent();
288 : wxGLCanvas(parent, id, gl_attrib)
291 m_glRC =
new wxGLContext(
this);