-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelerview.cpp
More file actions
122 lines (104 loc) · 3 KB
/
modelerview.cpp
File metadata and controls
122 lines (104 loc) · 3 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
#include "modelerview.h"
#include "camera.h"
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.h>
#include <FL/gl.h>
#include <GL/glu.h>
#include <cstdio>
static const int kMouseRotationButton = FL_LEFT_MOUSE;
static const int kMouseTranslationButton = FL_MIDDLE_MOUSE;
static const int kMouseZoomButton = FL_RIGHT_MOUSE;
ModelerView::ModelerView(int x, int y, int w, int h, char *label)
: Fl_Gl_Window(x,y,w,h,label)
{
m_camera = new Camera();
}
ModelerView::~ModelerView()
{
delete m_camera;
}
int ModelerView::handle(int event)
{
unsigned eventCoordX = Fl::event_x();
unsigned eventCoordY = Fl::event_y();
unsigned eventButton = Fl::event_button();
unsigned eventState = Fl::event_state();
switch(event)
{
case FL_PUSH:
{
switch(eventButton)
{
case kMouseRotationButton:
m_camera->clickMouse(kActionRotate, eventCoordX, eventCoordY );
break;
case kMouseTranslationButton:
m_camera->clickMouse(kActionTranslate, eventCoordX, eventCoordY );
break;
case kMouseZoomButton:
m_camera->clickMouse(kActionZoom, eventCoordX, eventCoordY );
break;
}
}
break;
case FL_DRAG:
{
m_camera->dragMouse(eventCoordX, eventCoordY);
}
break;
case FL_RELEASE:
{
switch(eventButton)
{
case kMouseRotationButton:
case kMouseTranslationButton:
case kMouseZoomButton:
m_camera->releaseMouse(eventCoordX, eventCoordY );
break;
}
}
break;
default:
return 0;
}
redraw();
return 1;
}
static GLfloat lightPosition0[] = { 4, 2, -4, 0 };
static GLfloat lightDiffuse0[] = {1,1,1,0.5f };
static GLfloat lightPosition1[] = { 0, 2, 5, 0 };
static GLfloat lightDiffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
static GLfloat lightPosition2[] = { -14, 2, -2, 0 };
static GLfloat lightDiffuse2[] = { 0.7, 0.7, 0.7, 0.7 };
static GLfloat lightPosition3[] = { 4, 2, 4, 0 };
static GLfloat lightDiffuse3[] = { 0.5, 0.5, 0.5, 0.3 };
void ModelerView::draw()
{
if (!valid())
{
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_LIGHT1 );
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable( GL_NORMALIZE );
}
glViewport( 0, 0, w(), h() );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0,float(w())/float(h()),1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_camera->applyViewingTransform();
glLightfv( GL_LIGHT0, GL_POSITION, lightPosition0 );
glLightfv( GL_LIGHT0, GL_DIFFUSE, lightDiffuse0 );
glLightfv( GL_LIGHT1, GL_POSITION, lightPosition1 );
glLightfv( GL_LIGHT1, GL_DIFFUSE, lightDiffuse1 );
glLightfv(GL_LIGHT2, GL_POSITION, lightPosition2);
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightDiffuse2);
glLightfv(GL_LIGHT3, GL_POSITION, lightPosition3);
glLightfv(GL_LIGHT3, GL_DIFFUSE, lightDiffuse3);
}