mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:28:02 +02:00
Added ability to drag hand by clicking and dragging on the screen.
This commit is contained in:
parent
888ef2249d
commit
eb37d1fbf8
3 changed files with 23 additions and 6 deletions
|
@ -57,9 +57,11 @@ void Hand::reset()
|
||||||
|
|
||||||
void Hand::simulate(float deltaTime)
|
void Hand::simulate(float deltaTime)
|
||||||
{
|
{
|
||||||
const float VNOISE = 0.1;
|
const float VNOISE = 0.01;
|
||||||
const float RSPRING = 0.01;
|
const float RSPRING = 0.01;
|
||||||
|
const float PSPRING = 0.4;
|
||||||
const float RNOISE = 0.1;
|
const float RNOISE = 0.1;
|
||||||
|
const float VDECAY = 5.0;
|
||||||
|
|
||||||
// If noise, add a bit of random velocity
|
// If noise, add a bit of random velocity
|
||||||
if (noise) {
|
if (noise) {
|
||||||
|
@ -77,11 +79,15 @@ void Hand::simulate(float deltaTime)
|
||||||
yaw += yawRate;
|
yaw += yawRate;
|
||||||
roll += rollRate;
|
roll += rollRate;
|
||||||
|
|
||||||
|
// Spring effect to return hand to target;
|
||||||
|
glm::vec3 sVel = target - position;
|
||||||
|
sVel *= PSPRING;
|
||||||
|
addVelocity(sVel);
|
||||||
// Decay position of hand toward target
|
// Decay position of hand toward target
|
||||||
position -= deltaTime*(position - target);
|
//position -= deltaTime*(position - target);
|
||||||
|
|
||||||
// Decay velocity
|
// Decay velocity
|
||||||
velocity *= 1.0 - deltaTime;
|
velocity *= 1.0 - deltaTime*VDECAY;
|
||||||
|
|
||||||
// Decay Angular Velocity
|
// Decay Angular Velocity
|
||||||
pitchRate *= 1.0 - deltaTime;
|
pitchRate *= 1.0 - deltaTime;
|
||||||
|
|
|
@ -60,6 +60,9 @@ class Head : public AgentData {
|
||||||
void SetNewHeadTarget(float, float);
|
void SetNewHeadTarget(float, float);
|
||||||
glm::vec3 getPos() { return position; };
|
glm::vec3 getPos() { return position; };
|
||||||
void setPos(glm::vec3 newpos) { position = newpos; };
|
void setPos(glm::vec3 newpos) { position = newpos; };
|
||||||
|
|
||||||
|
Hand * hand;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float noise;
|
float noise;
|
||||||
float Pitch;
|
float Pitch;
|
||||||
|
@ -99,7 +102,6 @@ class Head : public AgentData {
|
||||||
void readSensors();
|
void readSensors();
|
||||||
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
|
||||||
|
|
||||||
Hand * hand;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -144,14 +144,15 @@ int display_head_mouse = 1; // Display sample mouse pointer controlled
|
||||||
int head_mouse_x, head_mouse_y;
|
int head_mouse_x, head_mouse_y;
|
||||||
int head_lean_x, head_lean_y;
|
int head_lean_x, head_lean_y;
|
||||||
|
|
||||||
int mouse_x, mouse_y; // Where is the mouse
|
int mouse_x, mouse_y; // Where is the mouse
|
||||||
|
int mouse_start_x, mouse_start_y; // Mouse location at start of last down click
|
||||||
int mouse_pressed = 0; // true if mouse has been pressed (clear when finished)
|
int mouse_pressed = 0; // true if mouse has been pressed (clear when finished)
|
||||||
|
|
||||||
int nearbyAgents = 0; // How many other people near you is the domain server reporting?
|
int nearbyAgents = 0; // How many other people near you is the domain server reporting?
|
||||||
|
|
||||||
int speed;
|
int speed;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Serial USB Variables
|
// Serial USB Variables
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -813,6 +814,8 @@ void mouseFunc( int button, int state, int x, int y )
|
||||||
mouse_y = y;
|
mouse_y = y;
|
||||||
mouse_pressed = 1;
|
mouse_pressed = 1;
|
||||||
lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
|
lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
|
||||||
|
mouse_start_x = x;
|
||||||
|
mouse_start_y = y;
|
||||||
}
|
}
|
||||||
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
|
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
|
||||||
{
|
{
|
||||||
|
@ -833,6 +836,12 @@ void motionFunc( int x, int y)
|
||||||
char mouse_string[20];
|
char mouse_string[20];
|
||||||
sprintf(mouse_string, "M %d %d\n", mouse_x, mouse_y);
|
sprintf(mouse_string, "M %d %d\n", mouse_x, mouse_y);
|
||||||
//network_send(UDP_socket, mouse_string, strlen(mouse_string));
|
//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);
|
lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT);
|
||||||
|
|
Loading…
Reference in a new issue