History

First commit to improve avatar movement

Philip Rosedale committed 13 years ago

Commit 642b64d1 parent 53cff163 files · +101 −56Browse files

Showing the changes to interface/src/main.cpp (1 of 3 files). Show all

Unified · Split

interface/src/main.cpp+45−44
@@ -121,14 +121,9 @@ float render_yaw_rate = 0.f; · 120 unmodified lines
121121 float render_pitch_rate = 0.f;
122122 float lateral_vel = 0.f;
123123
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);
128126
129−GLfloat start_location[] = {6.1f, 0, 1.4f};
130−
131−GLfloat location[] = {start_location[0], start_location[1], start_location[2]};
132127 float fwd_vel = 0.0f;
133128
134129 int stats_on = 0; // Whether to show onscreen text overlay with stats
@@ -319,6 +314,7 @@ void init(void) · 184 unmodified lines
319314 if (noise_on) {
320315 myHead.setNoise(noise);
321316 }
317+ myHead.setPos(start_location);
322318
323319 char output[] = "I";
324320 char address[] = "10.0.0.10";
@@ -365,12 +361,10 @@ void reset_sensors() · 40 unmodified lines
365361 yaw = render_yaw_rate = 0;
366362 pitch = render_pitch = render_pitch_rate = 0;
367363 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);
371365 fwd_vel = 0.0;
372366 head_mouse_x = WIDTH/2;
373− head_mouse_y = HEIGHT/2;
367+ head_mouse_y = HEIGHT/2;
374368 head_lean_x = WIDTH/2;
375369 head_lean_y = HEIGHT/2;
376370
@@ -483,26 +477,11 @@ void simulateHead(float frametime) · 106 unmodified lines
483477 }*/
484478 // Decrease forward velocity
485479 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+
502481 // Update own head data
503482 myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
504483 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]));
506485
507486 // Get audio loudness data from audio input device
508487 float loudness, averageLoudness;
@@ -552,12 +531,11 @@ void display(void) · 43 unmodified lines
552531 // Rotate, translate to camera location
553532 glRotatef(myHead.getRenderPitch(), 1, 0, 0);
554533 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);
556535
557536 glColor3f(1,0,0);
558537 glutSolidSphere(0.25, 15, 15);
559538
560−
561539 // Draw cloud of dots
562540 glDisable( GL_POINT_SPRITE_ARB );
563541 glDisable( GL_TEXTURE_2D );
@@ -576,7 +554,7 @@ void display(void) · 12 unmodified lines
576554 glPushMatrix();
577555 glm::vec3 pos = agentHead->getPos();
578556 glTranslatef(-pos.x, -pos.y, -pos.z);
579− agentHead->render(0, 0, &location[0]);
557+ agentHead->render(0, 0);
580558 glPopMatrix();
581559 }
582560 }
@@ -590,12 +568,8 @@ void display(void) · 7 unmodified lines
590568 glPushMatrix();
591569 glLoadIdentity();
592570 glTranslatef(0.f, 0.f, -7.f);
593− myHead.render(display_head, 1, &location[0]);
571+ myHead.render(display_head, 1);
594572 glPopMatrix();
595−
596− //glm::vec3 test(0.5, 0.5, 0.5);
597− //render_vector(&test);
598−
599573
600574 glPopMatrix();
601575
@@ -715,23 +689,50 @@ const float KEYBOARD_YAW_RATE = 0.8; · 113 unmodified lines
715689 const float KEYBOARD_STRAFE_RATE = 0.03;
716690 const float KEYBOARD_FLY_RATE = 0.08;
717691
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+
718706 void specialkey(int k, int x, int y)
719707 {
720708 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+ }
723717 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);
725719 else render_yaw_rate -= KEYBOARD_YAW_RATE;
726720 }
727721 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);
729723 else render_yaw_rate += KEYBOARD_YAW_RATE;
730724 }
731725
732726 audio.setWalkingState(true);
733727 }
734728 }
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+
735736 void key(unsigned char k, int x, int y)
736737 {
737738
@@ -764,10 +765,8 @@ void key(unsigned char k, int x, int y) · 26 unmodified lines
764765
765766 if (k == 'f') display_field = !display_field;
766767 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);
771770 if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE;
772771 if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE;
773772 if (k == ' ') reset_sensors();
@@ -960,7 +959,9 @@ int main(int argc, char** argv) · 186 unmodified lines
960959 glutDisplayFunc(display);
961960 glutReshapeFunc(reshape);
962961 glutKeyboardFunc(key);
962+ glutKeyboardUpFunc(keyUp);
963963 glutSpecialFunc(specialkey);
964+ glutSpecialUpFunc(specialkeyUp);
964965 glutMotionFunc(motionFunc);
965966 glutPassiveMotionFunc(mouseoverFunc);
966967 glutMouseFunc(mouseFunc);