Showing the changes to interface/src/main.cpp (1 of 2 files). Show all
Unified · Split
| @@ -391,7 +391,20 @@ void reset_sensors() · 390 unmodified lines | ||
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | −void update_pos(float frametime) | |
| 394 | +void simulateHand(float deltaTime) { | |
| 395 | + // If mouse is being dragged, send current force to the hand controller | |
| 396 | + if (mouse_pressed == 1) | |
| 397 | + { | |
| 398 | + // Add a velocity to the hand corresponding to the detected size of the drag vector | |
| 399 | + const float MOUSE_HAND_FORCE = 3.0; | |
| 400 | + float dx = mouse_x - mouse_start_x; | |
| 401 | + float dy = mouse_y - mouse_start_y; | |
| 402 | + glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); | |
| 403 | + myHead.hand->addVelocity(vel*deltaTime); | |
| 404 | + } | |
| 405 | +} | |
| 406 | + | |
| 407 | +void simulateHead(float frametime) | |
| 395 | 408 | // Using serial data, update avatar/render position and angles |
| 396 | 409 | { |
| 397 | 410 | // float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE); |
| @@ -766,7 +779,9 @@ void idle(void) · 368 unmodified lines | ||
| 766 | 779 | { |
| 767 | 780 | steps_per_frame++; |
| 768 | 781 | // Simulation |
| 769 | − update_pos(1.f/FPS); | |
| 782 | + simulateHead(1.f/FPS); | |
| 783 | + simulateHand(1.f/FPS); | |
| 784 | + | |
| 770 | 785 | if (simulate_on) { |
| 771 | 786 | field.simulate(1.f/FPS); |
| 772 | 787 | myHead.simulate(1.f/FPS); |
| @@ -830,22 +845,8 @@ void motionFunc( int x, int y) · 57 unmodified lines | ||
| 830 | 845 | { |
| 831 | 846 | mouse_x = x; |
| 832 | 847 | mouse_y = y; |
| 833 | − if (mouse_pressed == 1) | |
| 834 | − { | |
| 835 | − // Send network packet containing mouse location | |
| 836 | − char mouse_string[20]; | |
| 837 | − sprintf(mouse_string, "M %d %d\n", mouse_x, mouse_y); | |
| 838 | − //network_send(UDP_socket, mouse_string, strlen(mouse_string)); | |
| 839 | − | |
| 840 | − // Send dragged mouse vector to the hand; | |
| 841 | − float dx = mouse_x - mouse_start_x; | |
| 842 | − float dy = mouse_y - mouse_start_y; | |
| 843 | − glm::vec3 vel(dx*0.003, -dy*0.003, 0); | |
| 844 | − myHead.hand->addVelocity(vel); | |
| 845 | − } | |
| 846 | 848 | |
| 847 | 849 | lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); |
| 848 | − | |
| 849 | 850 | } |
| 850 | 851 | |
| 851 | 852 | void mouseoverFunc( int x, int y) |