History

Added critically damped spring behavior to hand, and added simulateHand() routine to main.cpp that uses mouse to correctly move hand controller.

Philip Rosedale committed 13 years ago

Commit 26a87b31 parent f7b20a72 files · +27 −25Browse files

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

Unified · Split

interface/src/main.cpp+17−16
@@ -391,7 +391,20 @@ void reset_sensors() · 390 unmodified lines
391391 }
392392 }
393393
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)
395408 // Using serial data, update avatar/render position and angles
396409 {
397410 // float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE);
@@ -766,7 +779,9 @@ void idle(void) · 368 unmodified lines
766779 {
767780 steps_per_frame++;
768781 // Simulation
769− update_pos(1.f/FPS);
782+ simulateHead(1.f/FPS);
783+ simulateHand(1.f/FPS);
784+
770785 if (simulate_on) {
771786 field.simulate(1.f/FPS);
772787 myHead.simulate(1.f/FPS);
@@ -830,22 +845,8 @@ void motionFunc( int x, int y) · 57 unmodified lines
830845 {
831846 mouse_x = x;
832847 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− }
846848
847849 lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
848−
849850 }
850851
851852 void mouseoverFunc( int x, int y)