Showing the changes to interface/src/main.cpp (1 of 3 files). Show all
Unified · Split
| @@ -121,14 +121,9 @@ float render_yaw_rate = 0.f; · 120 unmodified lines | |||
| 121 | float render_pitch_rate = 0.f; | 121 | float render_pitch_rate = 0.f; |
| 122 | float lateral_vel = 0.f; | 122 | float lateral_vel = 0.f; |
| 123 | 123 | ||
| 124 | // Manage speed and direction of motion | 124 | // Where one's own agent begins in the world (needs to become a dynamic thing passed to the program) |
| 125 | GLfloat fwd_vec[] = {0.0, 0.0, 1.0}; | 125 | glm::vec3 start_location(6.1f, 0, 1.4f); |
| 126 | //GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0}; | ||
| 127 | //GLfloat start_location[] = { 0.1, -0.15, 0.1}; | ||
| 128 | 126 | ||
| 129 | GLfloat start_location[] = {6.1f, 0, 1.4f}; | ||
| 130 | |||
| 131 | GLfloat location[] = {start_location[0], start_location[1], start_location[2]}; | ||
| 132 | float fwd_vel = 0.0f; | 127 | float fwd_vel = 0.0f; |
| 133 | 128 | ||
| 134 | int stats_on = 0; // Whether to show onscreen text overlay with stats | 129 | int stats_on = 0; // Whether to show onscreen text overlay with stats |
| @@ -319,6 +314,7 @@ void init(void) · 184 unmodified lines | |||
| 319 | if (noise_on) { | 314 | if (noise_on) { |
| 320 | myHead.setNoise(noise); | 315 | myHead.setNoise(noise); |
| 321 | } | 316 | } |
| 317 | myHead.setPos(start_location); | ||
| 322 | 318 | ||
| 323 | char output[] = "I"; | 319 | char output[] = "I"; |
| 324 | char address[] = "10.0.0.10"; | 320 | char address[] = "10.0.0.10"; |
| @@ -365,12 +361,10 @@ void reset_sensors() · 40 unmodified lines | |||
| 365 | yaw = render_yaw_rate = 0; | 361 | yaw = render_yaw_rate = 0; |
| 366 | pitch = render_pitch = render_pitch_rate = 0; | 362 | pitch = render_pitch = render_pitch_rate = 0; |
| 367 | lateral_vel = 0; | 363 | lateral_vel = 0; |
| 368 | location[0] = start_location[0]; | 364 | myHead.setPos(start_location); |
| 369 | location[1] = start_location[1]; | ||
| 370 | location[2] = start_location[2]; | ||
| 371 | fwd_vel = 0.0; | 365 | fwd_vel = 0.0; |
| 372 | head_mouse_x = WIDTH/2; | 366 | head_mouse_x = WIDTH/2; |
| 373 | head_mouse_y = HEIGHT/2; | 367 | head_mouse_y = HEIGHT/2; |
| 374 | head_lean_x = WIDTH/2; | 368 | head_lean_x = WIDTH/2; |
| 375 | head_lean_y = HEIGHT/2; | 369 | head_lean_y = HEIGHT/2; |
| 376 | 370 | ||
| @@ -483,26 +477,11 @@ void simulateHead(float frametime) · 106 unmodified lines | |||
| 483 | }*/ | 477 | }*/ |
| 484 | // Decrease forward velocity | 478 | // Decrease forward velocity |
| 485 | fwd_vel *= (1.f - 4.0*frametime); | 479 | fwd_vel *= (1.f - 4.0*frametime); |
| 486 | 480 | ||
| 487 | |||
| 488 | // Update forward vector based on pitch and yaw | ||
| 489 | fwd_vec[0] = -sinf(myHead.getRenderYaw()*PI/180); | ||
| 490 | fwd_vec[1] = sinf(render_pitch*PI/180); | ||
| 491 | fwd_vec[2] = cosf(myHead.getRenderYaw()*PI/180); | ||
| 492 | |||
| 493 | // Advance location forward | ||
| 494 | location[0] += fwd_vec[0]*fwd_vel; | ||
| 495 | location[1] += fwd_vec[1]*fwd_vel; | ||
| 496 | location[2] += fwd_vec[2]*fwd_vel; | ||
| 497 | |||
| 498 | // Slide location sideways | ||
| 499 | location[0] += fwd_vec[2]*-lateral_vel; | ||
| 500 | location[2] += fwd_vec[0]*lateral_vel; | ||
| 501 | |||
| 502 | // Update own head data | 481 | // Update own head data |
| 503 | myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate); | 482 | myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate); |
| 504 | myHead.setRenderPitch(render_pitch); | 483 | myHead.setRenderPitch(render_pitch); |
| 505 | myHead.setPos(glm::vec3(location[0], location[1], location[2])); | 484 | //myHead.setPos(glm::vec3(location[0], location[1], location[2])); |
| 506 | 485 | ||
| 507 | // Get audio loudness data from audio input device | 486 | // Get audio loudness data from audio input device |
| 508 | float loudness, averageLoudness; | 487 | float loudness, averageLoudness; |
| @@ -552,12 +531,11 @@ void display(void) · 43 unmodified lines | |||
| 552 | // Rotate, translate to camera location | 531 | // Rotate, translate to camera location |
| 553 | glRotatef(myHead.getRenderPitch(), 1, 0, 0); | 532 | glRotatef(myHead.getRenderPitch(), 1, 0, 0); |
| 554 | glRotatef(myHead.getRenderYaw(), 0, 1, 0); | 533 | glRotatef(myHead.getRenderYaw(), 0, 1, 0); |
| 555 | glTranslatef(location[0], location[1], location[2]); | 534 | glTranslatef(myHead.getPos().x, myHead.getPos().y, myHead.getPos().z); |
| 556 | 535 | ||
| 557 | glColor3f(1,0,0); | 536 | glColor3f(1,0,0); |
| 558 | glutSolidSphere(0.25, 15, 15); | 537 | glutSolidSphere(0.25, 15, 15); |
| 559 | 538 | ||
| 560 | |||
| 561 | // Draw cloud of dots | 539 | // Draw cloud of dots |
| 562 | glDisable( GL_POINT_SPRITE_ARB ); | 540 | glDisable( GL_POINT_SPRITE_ARB ); |
| 563 | glDisable( GL_TEXTURE_2D ); | 541 | glDisable( GL_TEXTURE_2D ); |
| @@ -576,7 +554,7 @@ void display(void) · 12 unmodified lines | |||
| 576 | glPushMatrix(); | 554 | glPushMatrix(); |
| 577 | glm::vec3 pos = agentHead->getPos(); | 555 | glm::vec3 pos = agentHead->getPos(); |
| 578 | glTranslatef(-pos.x, -pos.y, -pos.z); | 556 | glTranslatef(-pos.x, -pos.y, -pos.z); |
| 579 | agentHead->render(0, 0, &location[0]); | 557 | agentHead->render(0, 0); |
| 580 | glPopMatrix(); | 558 | glPopMatrix(); |
| 581 | } | 559 | } |
| 582 | } | 560 | } |
| @@ -590,12 +568,8 @@ void display(void) · 7 unmodified lines | |||
| 590 | glPushMatrix(); | 568 | glPushMatrix(); |
| 591 | glLoadIdentity(); | 569 | glLoadIdentity(); |
| 592 | glTranslatef(0.f, 0.f, -7.f); | 570 | glTranslatef(0.f, 0.f, -7.f); |
| 593 | myHead.render(display_head, 1, &location[0]); | 571 | myHead.render(display_head, 1); |
| 594 | glPopMatrix(); | 572 | glPopMatrix(); |
| 595 | |||
| 596 | //glm::vec3 test(0.5, 0.5, 0.5); | ||
| 597 | //render_vector(&test); | ||
| 598 | |||
| 599 | 573 | ||
| 600 | glPopMatrix(); | 574 | glPopMatrix(); |
| 601 | 575 | ||
| @@ -715,23 +689,50 @@ const float KEYBOARD_YAW_RATE = 0.8; · 113 unmodified lines | |||
| 715 | const float KEYBOARD_STRAFE_RATE = 0.03; | 689 | const float KEYBOARD_STRAFE_RATE = 0.03; |
| 716 | const float KEYBOARD_FLY_RATE = 0.08; | 690 | const float KEYBOARD_FLY_RATE = 0.08; |
| 717 | 691 | ||
| 692 | void specialkeyUp(int k, int x, int y) { | ||
| 693 | if (k == GLUT_KEY_UP) { | ||
| 694 | myHead.setDriveKeys(FWD, 0); | ||
| 695 | myHead.setDriveKeys(UP, 0); | ||
| 696 | } | ||
| 697 | if (k == GLUT_KEY_DOWN) { | ||
| 698 | myHead.setDriveKeys(BACK, 0); | ||
| 699 | myHead.setDriveKeys(DOWN, 0); | ||
| 700 | } | ||
| 701 | if (k == GLUT_KEY_LEFT) myHead.setDriveKeys(LEFT, 0); | ||
| 702 | if (k == GLUT_KEY_RIGHT) myHead.setDriveKeys(RIGHT, 0); | ||
| 703 | |||
| 704 | } | ||
| 705 | |||
| 718 | void specialkey(int k, int x, int y) | 706 | void specialkey(int k, int x, int y) |
| 719 | { | 707 | { |
| 720 | if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) { | 708 | if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) { |
| 721 | if (k == GLUT_KEY_UP) fwd_vel += KEYBOARD_FLY_RATE; | 709 | if (k == GLUT_KEY_UP) { |
| 722 | if (k == GLUT_KEY_DOWN) fwd_vel -= KEYBOARD_FLY_RATE; | 710 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(UP, 1); |
| 711 | else myHead.setDriveKeys(FWD, 1); | ||
| 712 | } | ||
| 713 | if (k == GLUT_KEY_DOWN) { | ||
| 714 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(DOWN, 1); | ||
| 715 | else myHead.setDriveKeys(BACK, 1); | ||
| 716 | } | ||
| 723 | if (k == GLUT_KEY_LEFT) { | 717 | if (k == GLUT_KEY_LEFT) { |
| 724 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel -= KEYBOARD_STRAFE_RATE; | 718 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(LEFT, 1); |
| 725 | else render_yaw_rate -= KEYBOARD_YAW_RATE; | 719 | else render_yaw_rate -= KEYBOARD_YAW_RATE; |
| 726 | } | 720 | } |
| 727 | if (k == GLUT_KEY_RIGHT) { | 721 | if (k == GLUT_KEY_RIGHT) { |
| 728 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel += KEYBOARD_STRAFE_RATE; | 722 | if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(RIGHT, 1); |
| 729 | else render_yaw_rate += KEYBOARD_YAW_RATE; | 723 | else render_yaw_rate += KEYBOARD_YAW_RATE; |
| 730 | } | 724 | } |
| 731 | 725 | ||
| 732 | audio.setWalkingState(true); | 726 | audio.setWalkingState(true); |
| 733 | } | 727 | } |
| 734 | } | 728 | } |
| 729 | |||
| 730 | |||
| 731 | void keyUp(unsigned char k, int x, int y) { | ||
| 732 | if (k == 'e') myHead.setDriveKeys(UP, 0); | ||
| 733 | if (k == 'c') myHead.setDriveKeys(DOWN, 0); | ||
| 734 | } | ||
| 735 | |||
| 735 | void key(unsigned char k, int x, int y) | 736 | void key(unsigned char k, int x, int y) |
| 736 | { | 737 | { |
| 737 | 738 | ||
| @@ -764,10 +765,8 @@ void key(unsigned char k, int x, int y) · 26 unmodified lines | |||
| 764 | 765 | ||
| 765 | if (k == 'f') display_field = !display_field; | 766 | if (k == 'f') display_field = !display_field; |
| 766 | if (k == 'l') display_levels = !display_levels; | 767 | if (k == 'l') display_levels = !display_levels; |
| 767 | 768 | if (k == 'e') myHead.setDriveKeys(UP, 1); | |
| 768 | 769 | if (k == 'c') myHead.setDriveKeys(DOWN, 1); | |
| 769 | if (k == 'e') location[1] -= WORLD_SIZE/100.0; | ||
| 770 | if (k == 'c') location[1] += WORLD_SIZE/100.0; | ||
| 771 | if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE; | 770 | if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE; |
| 772 | if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE; | 771 | if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE; |
| 773 | if (k == ' ') reset_sensors(); | 772 | if (k == ' ') reset_sensors(); |
| @@ -960,7 +959,9 @@ int main(int argc, char** argv) · 186 unmodified lines | |||
| 960 | glutDisplayFunc(display); | 959 | glutDisplayFunc(display); |
| 961 | glutReshapeFunc(reshape); | 960 | glutReshapeFunc(reshape); |
| 962 | glutKeyboardFunc(key); | 961 | glutKeyboardFunc(key); |
| 962 | glutKeyboardUpFunc(keyUp); | ||
| 963 | glutSpecialFunc(specialkey); | 963 | glutSpecialFunc(specialkey); |
| 964 | glutSpecialUpFunc(specialkeyUp); | ||
| 964 | glutMotionFunc(motionFunc); | 965 | glutMotionFunc(motionFunc); |
| 965 | glutPassiveMotionFunc(mouseoverFunc); | 966 | glutPassiveMotionFunc(mouseoverFunc); |
| 966 | glutMouseFunc(mouseFunc); | 967 | glutMouseFunc(mouseFunc); |