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 | 121 | float render_pitch_rate = 0.f; |
| 122 | 122 | float lateral_vel = 0.f; |
| 123 | 123 | |
| 124 | −// Manage speed and direction of motion | |
| 125 | −GLfloat fwd_vec[] = {0.0, 0.0, 1.0}; | |
| 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}; | |
| 124 | +// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program) | |
| 125 | +glm::vec3 start_location(6.1f, 0, 1.4f); | |
| 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 | 127 | float fwd_vel = 0.0f; |
| 133 | 128 | |
| 134 | 129 | int stats_on = 0; // Whether to show onscreen text overlay with stats |
| @@ -319,6 +314,7 @@ void init(void) · 184 unmodified lines | ||
| 319 | 314 | if (noise_on) { |
| 320 | 315 | myHead.setNoise(noise); |
| 321 | 316 | } |
| 317 | + myHead.setPos(start_location); | |
| 322 | 318 | |
| 323 | 319 | char output[] = "I"; |
| 324 | 320 | char address[] = "10.0.0.10"; |
| @@ -365,12 +361,10 @@ void reset_sensors() · 40 unmodified lines | ||
| 365 | 361 | yaw = render_yaw_rate = 0; |
| 366 | 362 | pitch = render_pitch = render_pitch_rate = 0; |
| 367 | 363 | lateral_vel = 0; |
| 368 | − location[0] = start_location[0]; | |
| 369 | − location[1] = start_location[1]; | |
| 370 | − location[2] = start_location[2]; | |
| 364 | + myHead.setPos(start_location); | |
| 371 | 365 | fwd_vel = 0.0; |
| 372 | 366 | head_mouse_x = WIDTH/2; |
| 373 | − head_mouse_y = HEIGHT/2; | |
| 367 | + head_mouse_y = HEIGHT/2; | |
| 374 | 368 | head_lean_x = WIDTH/2; |
| 375 | 369 | head_lean_y = HEIGHT/2; |
| 376 | 370 | |
| @@ -483,26 +477,11 @@ void simulateHead(float frametime) · 106 unmodified lines | ||
| 483 | 477 | }*/ |
| 484 | 478 | // Decrease forward velocity |
| 485 | 479 | fwd_vel *= (1.f - 4.0*frametime); |
| 486 | − | |
| 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 | − | |
| 480 | + | |
| 502 | 481 | // Update own head data |
| 503 | 482 | myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate); |
| 504 | 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 | 486 | // Get audio loudness data from audio input device |
| 508 | 487 | float loudness, averageLoudness; |
| @@ -552,12 +531,11 @@ void display(void) · 43 unmodified lines | ||
| 552 | 531 | // Rotate, translate to camera location |
| 553 | 532 | glRotatef(myHead.getRenderPitch(), 1, 0, 0); |
| 554 | 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 | 536 | glColor3f(1,0,0); |
| 558 | 537 | glutSolidSphere(0.25, 15, 15); |
| 559 | 538 | |
| 560 | − | |
| 561 | 539 | // Draw cloud of dots |
| 562 | 540 | glDisable( GL_POINT_SPRITE_ARB ); |
| 563 | 541 | glDisable( GL_TEXTURE_2D ); |
| @@ -576,7 +554,7 @@ void display(void) · 12 unmodified lines | ||
| 576 | 554 | glPushMatrix(); |
| 577 | 555 | glm::vec3 pos = agentHead->getPos(); |
| 578 | 556 | glTranslatef(-pos.x, -pos.y, -pos.z); |
| 579 | − agentHead->render(0, 0, &location[0]); | |
| 557 | + agentHead->render(0, 0); | |
| 580 | 558 | glPopMatrix(); |
| 581 | 559 | } |
| 582 | 560 | } |
| @@ -590,12 +568,8 @@ void display(void) · 7 unmodified lines | ||
| 590 | 568 | glPushMatrix(); |
| 591 | 569 | glLoadIdentity(); |
| 592 | 570 | glTranslatef(0.f, 0.f, -7.f); |
| 593 | − myHead.render(display_head, 1, &location[0]); | |
| 571 | + myHead.render(display_head, 1); | |
| 594 | 572 | glPopMatrix(); |
| 595 | − | |
| 596 | − //glm::vec3 test(0.5, 0.5, 0.5); | |
| 597 | − //render_vector(&test); | |
| 598 | − | |
| 599 | 573 | |
| 600 | 574 | glPopMatrix(); |
| 601 | 575 | |
| @@ -715,23 +689,50 @@ const float KEYBOARD_YAW_RATE = 0.8; · 113 unmodified lines | ||
| 715 | 689 | const float KEYBOARD_STRAFE_RATE = 0.03; |
| 716 | 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 | 706 | void specialkey(int k, int x, int y) |
| 719 | 707 | { |
| 720 | 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; | |
| 722 | − if (k == GLUT_KEY_DOWN) fwd_vel -= KEYBOARD_FLY_RATE; | |
| 709 | + if (k == GLUT_KEY_UP) { | |
| 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 | 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 | 719 | else render_yaw_rate -= KEYBOARD_YAW_RATE; |
| 726 | 720 | } |
| 727 | 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 | 723 | else render_yaw_rate += KEYBOARD_YAW_RATE; |
| 730 | 724 | } |
| 731 | 725 | |
| 732 | 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 | 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 | 766 | if (k == 'f') display_field = !display_field; |
| 766 | 767 | if (k == 'l') display_levels = !display_levels; |
| 767 | − | |
| 768 | − | |
| 769 | − if (k == 'e') location[1] -= WORLD_SIZE/100.0; | |
| 770 | − if (k == 'c') location[1] += WORLD_SIZE/100.0; | |
| 768 | + if (k == 'e') myHead.setDriveKeys(UP, 1); | |
| 769 | + if (k == 'c') myHead.setDriveKeys(DOWN, 1); | |
| 771 | 770 | if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE; |
| 772 | 771 | if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE; |
| 773 | 772 | if (k == ' ') reset_sensors(); |
| @@ -960,7 +959,9 @@ int main(int argc, char** argv) · 186 unmodified lines | ||
| 960 | 959 | glutDisplayFunc(display); |
| 961 | 960 | glutReshapeFunc(reshape); |
| 962 | 961 | glutKeyboardFunc(key); |
| 962 | + glutKeyboardUpFunc(keyUp); | |
| 963 | 963 | glutSpecialFunc(specialkey); |
| 964 | + glutSpecialUpFunc(specialkeyUp); | |
| 964 | 965 | glutMotionFunc(motionFunc); |
| 965 | 966 | glutPassiveMotionFunc(mouseoverFunc); |
| 966 | 967 | glutMouseFunc(mouseFunc); |