mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-14 11:46:34 +02:00
Added critically damped spring behavior to hand, and added simulateHand() routine to main.cpp that uses mouse to correctly move hand controller.
This commit is contained in:
parent
f7b20a7c9c
commit
26a87b3b43
2 changed files with 27 additions and 25 deletions
|
@ -59,7 +59,8 @@ void Hand::simulate(float deltaTime)
|
|||
{
|
||||
const float VNOISE = 0.01;
|
||||
const float RSPRING = 0.01;
|
||||
const float PSPRING = 0.4;
|
||||
const float LINEAR_SPRING_CONSTANT = 500;
|
||||
const float LINEAR_DAMPING_COEFFICIENT = 2.0*powf(LINEAR_SPRING_CONSTANT,0.5);
|
||||
const float RNOISE = 0.1;
|
||||
const float VDECAY = 5.0;
|
||||
|
||||
|
@ -79,15 +80,15 @@ void Hand::simulate(float deltaTime)
|
|||
yaw += yawRate;
|
||||
roll += rollRate;
|
||||
|
||||
// Spring effect to return hand to target;
|
||||
glm::vec3 sVel = target - position;
|
||||
sVel *= PSPRING;
|
||||
addVelocity(sVel);
|
||||
// Decay position of hand toward target
|
||||
//position -= deltaTime*(position - target);
|
||||
// Use a spring to attempt to return the hand to the target position
|
||||
glm::vec3 springForce = target - position;
|
||||
springForce *= LINEAR_SPRING_CONSTANT;
|
||||
addVelocity(springForce * deltaTime);
|
||||
|
||||
// Decay velocity
|
||||
velocity *= 1.0 - deltaTime*VDECAY;
|
||||
// Critically damp the spring
|
||||
glm::vec3 dampingForce(velocity);
|
||||
dampingForce *= LINEAR_DAMPING_COEFFICIENT;
|
||||
addVelocity(-dampingForce * deltaTime);
|
||||
|
||||
// Decay Angular Velocity
|
||||
pitchRate *= 1.0 - deltaTime;
|
||||
|
|
|
@ -391,7 +391,20 @@ void reset_sensors()
|
|||
}
|
||||
}
|
||||
|
||||
void update_pos(float frametime)
|
||||
void simulateHand(float deltaTime) {
|
||||
// If mouse is being dragged, send current force to the hand controller
|
||||
if (mouse_pressed == 1)
|
||||
{
|
||||
// Add a velocity to the hand corresponding to the detected size of the drag vector
|
||||
const float MOUSE_HAND_FORCE = 3.0;
|
||||
float dx = mouse_x - mouse_start_x;
|
||||
float dy = mouse_y - mouse_start_y;
|
||||
glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0);
|
||||
myHead.hand->addVelocity(vel*deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void simulateHead(float frametime)
|
||||
// Using serial data, update avatar/render position and angles
|
||||
{
|
||||
// float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE);
|
||||
|
@ -766,7 +779,9 @@ void idle(void)
|
|||
{
|
||||
steps_per_frame++;
|
||||
// Simulation
|
||||
update_pos(1.f/FPS);
|
||||
simulateHead(1.f/FPS);
|
||||
simulateHand(1.f/FPS);
|
||||
|
||||
if (simulate_on) {
|
||||
field.simulate(1.f/FPS);
|
||||
myHead.simulate(1.f/FPS);
|
||||
|
@ -830,22 +845,8 @@ void motionFunc( int x, int y)
|
|||
{
|
||||
mouse_x = x;
|
||||
mouse_y = y;
|
||||
if (mouse_pressed == 1)
|
||||
{
|
||||
// Send network packet containing mouse location
|
||||
char mouse_string[20];
|
||||
sprintf(mouse_string, "M %d %d\n", mouse_x, mouse_y);
|
||||
//network_send(UDP_socket, mouse_string, strlen(mouse_string));
|
||||
|
||||
// Send dragged mouse vector to the hand;
|
||||
float dx = mouse_x - mouse_start_x;
|
||||
float dy = mouse_y - mouse_start_y;
|
||||
glm::vec3 vel(dx*0.003, -dy*0.003, 0);
|
||||
myHead.hand->addVelocity(vel);
|
||||
}
|
||||
|
||||
lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
|
||||
|
||||
}
|
||||
|
||||
void mouseoverFunc( int x, int y)
|
||||
|
|
Loading…
Reference in a new issue