Commit b606443d606db241843737b395376574fab89259
1 parent
003327a2
Implemented small spider, with rotation and correctional translation, using the shift key
Showing
2 changed files
with
51 additions
and
12 deletions
Show diff stats
TextureTest.cu
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | #define VERTICAL 1 |
14 | 14 | #define HORIZONTAL 1 |
15 | 15 | stim::camera cam; |
16 | + stim::camera Parker; | |
16 | 17 | GLuint texID; |
17 | 18 | float a = -1.0; |
18 | 19 | float b = 1.0; |
... | ... | @@ -39,6 +40,7 @@ |
39 | 40 | stim::vec<float> up; |
40 | 41 | stim::vec<float> d; |
41 | 42 | static bool button1 = FALSE; |
43 | + static bool button_shift = FALSE; | |
42 | 44 | static float degtorad = 360/(2*M_PI); |
43 | 45 | static GLfloat adjustTex = 1.0/426.0; |
44 | 46 | static GLfloat adjustDrw = 2.0/426.0; |
... | ... | @@ -76,7 +78,7 @@ glInit() |
76 | 78 | glLoadIdentity(); |
77 | 79 | glOrtho(-5.0, 2.0,-5.0, 2.0, -0.0, 1000.0); |
78 | 80 | glMatrixMode(GL_MODELVIEW); |
79 | - spidey = stim::gl_spider<float>(0.5, 0.5, 0.5, -0.1, -0.1, -0.1, 0.5, 0.5); | |
81 | + spidey = stim::gl_spider<float>(0.5, 0.5, 0.5, -0.1, -0.1, -0.1, 0.1, 0.1); | |
80 | 82 | CHECK_OPENGL_ERROR |
81 | 83 | } |
82 | 84 | |
... | ... | @@ -303,29 +305,24 @@ renderScene() |
303 | 305 | void |
304 | 306 | MouseButton(int button, int state, int x, int y) |
305 | 307 | { |
308 | + | |
306 | 309 | if (button == GLUT_LEFT_BUTTON) |
307 | 310 | { |
308 | 311 | button1 = (state == GLUT_DOWN) ? TRUE : FALSE; |
312 | + button_shift = glutGetModifiers(); | |
309 | 313 | prevmousePos[0] = (float)x; |
310 | 314 | prevmousePos[1] = (float)y; |
311 | 315 | } |
312 | 316 | if (button == GLUT_RIGHT_BUTTON) |
313 | 317 | { |
314 | - float clicked[2] = {(float) x*1.0/ (float) size[0], | |
315 | - (float) y*1.0/ (float) size[1]}; | |
316 | - std::cout << "clicked at " << clicked[0] << ":" << clicked[1] << std::endl; | |
317 | - if (clicked[0] > vertexDrw[0][0] && clicked[1] > vertexDrw[0][1]) | |
318 | - if(clicked[0] < vertexDrw[2][0] && clicked[1] < vertexDrw[2][1]) | |
319 | - { | |
320 | - std::cout << (float)x/(float)size[0]*3 << " " | |
321 | - << (float)y/(float)size[1]*3 << std::endl; | |
322 | - } | |
318 | + std::cout << spidey.getPosition() << std::endl | |
319 | + << spidey.getDirection() << std::endl; | |
323 | 320 | } |
324 | 321 | } |
325 | 322 | |
326 | 323 | void MouseMotion(int x, int y) |
327 | 324 | { |
328 | - if(button1) | |
325 | + if(button1 && !button_shift) | |
329 | 326 | { |
330 | 327 | mousePos[0] = (prevmousePos[0] - (float) x)*0.0005; |
331 | 328 | mousePos[1] = ((float)y - prevmousePos[1])*0.0005; |
... | ... | @@ -333,6 +330,20 @@ void MouseMotion(int x, int y) |
333 | 330 | prevmousePos[1] = (float)y; |
334 | 331 | cam.OrbitFocus(mousePos[0]*degtorad, mousePos[1]*degtorad); |
335 | 332 | } |
333 | + if(button1 && button_shift) | |
334 | + { | |
335 | + mousePos[0] = (prevmousePos[0] - (float) x)*0.00001; | |
336 | + mousePos[1] = ((float)y - prevmousePos[1])*0.00001; | |
337 | + prevmousePos[0] = (float)x; | |
338 | + prevmousePos[1] = (float)y; | |
339 | + Parker.setPosition(spidey.getPosition()); | |
340 | + Parker.LookAt(spidey.getDirection()); | |
341 | + Parker.Pan(mousePos[0]*degtorad); | |
342 | + Parker.Tilt(mousePos[1]*degtorad); | |
343 | + spidey.setDirection(Parker.getLookAt()); | |
344 | + spidey.Update(); | |
345 | + std::cout << Parker.getLookAt() << std::endl; | |
346 | + } | |
336 | 347 | } |
337 | 348 | |
338 | 349 | void |
... | ... | @@ -354,6 +365,13 @@ switch(key) { |
354 | 365 | else{ |
355 | 366 | oriDrw[2] = oriDrw[2] + adjustDrw; |
356 | 367 | } |
368 | + if (glutGetModifiers() == 1) | |
369 | + { | |
370 | + stim::vec<float> temp = spidey.getPosition(); | |
371 | + temp[1] += 0.0001; | |
372 | + spidey.setPosition(temp); | |
373 | + spidey.Update(); | |
374 | + } | |
357 | 375 | break; |
358 | 376 | case GLUT_KEY_DOWN: |
359 | 377 | oriTex[2] = oriTex[2]-adjustTex; |
... | ... | @@ -363,6 +381,13 @@ switch(key) { |
363 | 381 | else{ |
364 | 382 | oriDrw[2] = oriDrw[2] - adjustDrw; |
365 | 383 | } |
384 | + if (glutGetModifiers() == 1) | |
385 | + { | |
386 | + stim::vec<float> temp = spidey.getPosition(); | |
387 | + temp[1] -= 0.0001; | |
388 | + spidey.setPosition(temp); | |
389 | + spidey.Update(); | |
390 | + } | |
366 | 391 | break; |
367 | 392 | case GLUT_KEY_LEFT: |
368 | 393 | oriTex[1] = oriTex[1]+adjustTex; |
... | ... | @@ -372,6 +397,13 @@ switch(key) { |
372 | 397 | else{ |
373 | 398 | oriDrw[1] = oriDrw[1] + adjustDrw; |
374 | 399 | } |
400 | + if (glutGetModifiers() == 1) | |
401 | + { | |
402 | + stim::vec<float> temp = spidey.getPosition(); | |
403 | + temp[0] += 0.0001; | |
404 | + spidey.setPosition(temp); | |
405 | + spidey.Update(); | |
406 | + } | |
375 | 407 | break; |
376 | 408 | case GLUT_KEY_RIGHT: |
377 | 409 | oriTex[1] = oriTex[1]-adjustTex; |
... | ... | @@ -382,6 +414,13 @@ switch(key) { |
382 | 414 | oriDrw[1] = oriDrw[1] - adjustDrw; |
383 | 415 | } |
384 | 416 | break; |
417 | + if (glutGetModifiers() == 1) | |
418 | + { | |
419 | + stim::vec<float> temp = spidey.getPosition(); | |
420 | + temp[0] -= 0.0001; | |
421 | + spidey.setPosition(temp); | |
422 | + spidey.Update(); | |
423 | + } | |
385 | 424 | } |
386 | 425 | glutPostRedisplay(); |
387 | 426 | } | ... | ... |