-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
274 lines (224 loc) · 5.45 KB
/
display.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include "stdafx.h"
#include <GL/glut.h>
#include "XnPoint3D.h"
#include "mode.h"
#include "picking.h"
#include "gesture.h"
#include "drawmodel.h"
#include "hand_history.h"
#include "vertex.h"
#include "vmmodel.h"
#include "display.h"
#include "paint.h"
#include "print_screen.h"
//resolution
static int g_nXRes = 640, g_nYRes = 480;
static int h=800, w= 800;
static float cursorX, cursorY;
bool stateGrabR = false; //0- not grab, 1 - already in grab
bool stateGrabL = false; //0- not grab, 1 - already in grab
bool switchHand = false; //right hand perform rotation
bool static BACK_BUFF; //display back buffer
bool shape = false;
void activate_rotate(){
switchHand = !switchHand;
}
bool isRotate(){
return switchHand;
}
/* Select from 3 available modes and process accordingly */
void mode_selection(XnPoint3D* handPointList, hand_h* rhand){
//-------------------sculpting--------------------------
if(is_mode(1)){
checkRCursor(1, rhand); //right
//if(hasTwoHands()) checkLCursor(lhand); //left
//SELECTION
if(is_state(1)){
float* cursor = getCursor();
cursorX = cursor[0];
cursorY = cursor[1];
drawPickVMModel();
processPick(cursorX, cursorY);
set_state(2);
}
//RENDER
else {
draw_hand(handPointList); //draw every hands
//show back buffer?
if(!BACK_BUFF){
drawVMModel();
}
else{
drawPickVMModel();
}
set_state(1);
glutSwapBuffers();
}
}
//-------------------paint----------------------------
else if(is_mode(2)) {
checkRCursor(2, rhand);
//SELECTION
if(is_state(1)){
//update cursor for paint effect
float* cursor = getCursor();
cursorX = cursor[0];
cursorY = cursor[1];
drawPickVMModel();
processPick(cursorX, cursorY);
set_state(2);
}
//RENDER
else {
//////////////////////////////////////////////////** in gesture////////////////
draw_hand(handPointList);
if(!BACK_BUFF)
drawVMModel();
else drawPickVMModel();
//back to select other mesh
set_state(1);
glutSwapBuffers();
}
}
//------------------ Selection ------------------------
else if(is_mode(3)) {
checkRCursor(3, rhand);
if(is_state(1)){
drawPickVMModel();
set_state(2);
}
else {
//////////////////////////////////////////////////** in gesture////////////////
draw_hand(handPointList);
if(!BACK_BUFF)
drawVMModel();
else drawPickVMModel();
drawVMModel();
glutSwapBuffers();
}
}
}
//RIGHT HAND:: treat grab as a mouse click.
void checkRCursor(int func, hand_h* rhand){
if(isGrab()) {
rhand->storeHand(getPalm()); //keep the hand movement history
//first time grab gesture occurs for right hand
if(!stateGrabR) {
//adjust with width and height of the screen
float* cursor = getCursor();
cursorX = cursor[0];
cursorY = cursor[1];
set_state(1);
stateGrabR = true;
}
//still in grab gesture
else{
//sculpt
if(func == 1) {
//select a mesh once
//we don't need this for painting
set_state(2);
if(switchHand){
commitScene(rhand->gettranslateX(), rhand->gettranslateY(), rhand->gettranslateZ());
recalNormal();
}
else{
//grab group of mesh
if(sListContain(getSelection()) >= 0 ){
shape = true;
interpolate(getsList(), rhand->gettranslateX(),
rhand->gettranslateY(), rhand->gettranslateZ(), getRotX(), getRotY());
recalNormal();
}
//grab one mesh
else if(getSelection() >= 0 && getSelection() < getFaceListSize()){
shape = true;
interpolate(getSelection(), rhand->gettranslateX(),
rhand->gettranslateY(), rhand->gettranslateZ(), getRotX(), getRotY());
recalNormal();
}
}
}
//paint
else if(func ==2){
if(switchHand){
commitScene(rhand->gettranslateX(), rhand->gettranslateY(), rhand->gettranslateZ());
recalNormal();
}else{
if(getSelection() >=0 && getSelection() < getFaceListSize()){
//printf("selection ->%d\n", getSelection());
paintMesh(getSelection(), getBrushColor());
}
}
}
//selection?
else if(func ==3){
}
}
}
else{
//just release
if(stateGrabR){
//selection list
//if(selection && getSelection() > 0 && getSelection() < getFaceListSize()){
// store_selection(getSelection());
//}
stateGrabR = false;
rhand->clearHandList();
setNullSelection(); //show no mesh response when hand released
//undo
if(func == 1 && shape) {
copy_vmmodel();
shape = false;
}
}
}
}
//LEFT HAND:: handle rotation
void checkLCursor(hand_h* lhand){
if((isLGrab() && !switchHand) || (switchHand && isGrab())) {
XnPoint3D point;
if(switchHand) point = getPalm();
else point = getLPalm();
lhand->storeHand(point); //keep the hand movement history
//first time grab gesture occurs for left hand
if(!stateGrabL) {
set_state(1);
stateGrabL = true;
}
//still in grab gesture
else{
commitScene(lhand->gettranslateX(), lhand->gettranslateY(), lhand->gettranslateZ());
recalNormal();
}
}
else{
//just release
if(stateGrabL){
stateGrabL = false;
lhand->clearHandList();
}
}
}
void preview_scene(){
commitScene(1, 0, 0);
drawVMModel();
glutSwapBuffers();
}
void set_cursor(float x, float y){
cursorX = x;
cursorY = y;
}
void switch_buffer(){
BACK_BUFF = !BACK_BUFF;
}
bool get_buffer(){
return BACK_BUFF;
}
float* getCursor(){
float* c = (float*) malloc(sizeof(float)*2);
c[0] = getPalm().X;
c[1] = getPalm().Y;
return c;
return 0;
}