This repository was archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelerview.cpp
109 lines (97 loc) · 2.68 KB
/
modelerview.cpp
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
#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(kActionZoomTwist, eventCoordX, eventCoordY );
break;
}
// printf("push %d %d\n", eventCoordX, eventCoordY);
}
break;
case FL_DRAG:
{
m_camera->dragMouse(eventCoordX, eventCoordY);
//printf("drag %d %d\n", eventCoordX, eventCoordY);
}
break;
case FL_RELEASE:
{
switch(eventButton)
{
case kMouseRotationButton:
case kMouseTranslationButton:
case kMouseZoomButton:
m_camera->releaseMouse(eventCoordX, eventCoordY );
break;
}
// printf("release %d %d\n", eventCoordX, eventCoordY);
}
break;
default:
return 0;
}
redraw();
return 1;
}
static GLfloat lightPosition0[] = { 4, 2, -4, 0 };
static GLfloat lightDiffuse0[] = { 1,1,1,1 };
static GLfloat lightPosition1[] = { -2, 1, 5, 0 };
static GLfloat lightDiffuse1[] = { 1, 1, 1, 1 };
void ModelerView::draw()
{
if (!valid())
{
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_LIGHT1 );
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 );
}