mirror of
https://github.com/overte-org/overte.git
synced 2025-06-21 22:20:26 +02:00
cleaned up avatar slow-down upon nearness; fixed mouse pressed bug;
This commit is contained in:
parent
7cfc9844a3
commit
17c61c88c7
4 changed files with 28 additions and 26 deletions
|
@ -47,6 +47,8 @@ const float HEAD_MAX_PITCH = 45;
|
||||||
const float HEAD_MIN_PITCH = -45;
|
const float HEAD_MIN_PITCH = -45;
|
||||||
const float HEAD_MAX_YAW = 85;
|
const float HEAD_MAX_YAW = 85;
|
||||||
const float HEAD_MIN_YAW = -85;
|
const float HEAD_MIN_YAW = -85;
|
||||||
|
const float AVATAR_BRAKING_RANGE = 1.6f;
|
||||||
|
const float AVATAR_BRAKING_STRENGTH = 30.0f;
|
||||||
|
|
||||||
float skinColor [] = {1.0, 0.84, 0.66};
|
float skinColor [] = {1.0, 0.84, 0.66};
|
||||||
float lightBlue [] = {0.7, 0.8, 1.0};
|
float lightBlue [] = {0.7, 0.8, 1.0};
|
||||||
|
@ -404,8 +406,8 @@ void Avatar::simulate(float deltaTime) {
|
||||||
_bodyPitch *= tiltDecay;
|
_bodyPitch *= tiltDecay;
|
||||||
_bodyRoll *= tiltDecay;
|
_bodyRoll *= tiltDecay;
|
||||||
|
|
||||||
//wtf? - why won't this compile?
|
//the following will be used to make the avatar upright no matter what gravity is
|
||||||
//angleBetween(&_orientation.getUp(), &_gravity);
|
//float f = angleBetween(_orientation.getUp(), _gravity);
|
||||||
|
|
||||||
// update position by velocity
|
// update position by velocity
|
||||||
_position += _velocity * deltaTime;
|
_position += _velocity * deltaTime;
|
||||||
|
@ -418,15 +420,17 @@ void Avatar::simulate(float deltaTime) {
|
||||||
_velocity *= decay;
|
_velocity *= decay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If someone is near, damp velocity as a function of closeness
|
// If another avatar is near, dampen velocity as a function of closeness
|
||||||
const float AVATAR_BRAKING_RANGE = 1.6f;
|
if (_isMine && (_distanceToNearestAvatar < AVATAR_BRAKING_RANGE)) {
|
||||||
const float AVATAR_BRAKING_STRENGTH = 35.f;
|
float closeness = 1.0f - (_distanceToNearestAvatar / AVATAR_BRAKING_RANGE);
|
||||||
if (_isMine && (_distanceToNearestAvatar < AVATAR_BRAKING_RANGE)) {
|
float drag = 1.0f - closeness * AVATAR_BRAKING_STRENGTH * deltaTime;
|
||||||
_velocity *=
|
if ( drag > 0.0f ) {
|
||||||
(1.f - deltaTime * AVATAR_BRAKING_STRENGTH *
|
_velocity *= drag;
|
||||||
(AVATAR_BRAKING_RANGE - _distanceToNearestAvatar));
|
} else {
|
||||||
|
_velocity = glm::vec3( 0.0f, 0.0f, 0.0f );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update head state
|
// update head state
|
||||||
updateHead(deltaTime);
|
updateHead(deltaTime);
|
||||||
|
|
||||||
|
@ -466,8 +470,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
||||||
// Test: Show angle between your fwd vector and nearest avatar
|
// Test: Show angle between your fwd vector and nearest avatar
|
||||||
glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) -
|
glm::vec3 vectorBetweenUs = otherAvatar->getJointPosition(AVATAR_JOINT_PELVIS) -
|
||||||
getJointPosition(AVATAR_JOINT_PELVIS);
|
getJointPosition(AVATAR_JOINT_PELVIS);
|
||||||
glm::vec3 myForwardVector = _orientation.getFront();
|
printLog("Angle between: %f\n", angleBetween(vectorBetweenUs, _orientation.getFront()));
|
||||||
printLog("Angle between: %f\n", angleBetween(&vectorBetweenUs, &myForwardVector));
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// test whether shoulders are close enough to allow for reaching to touch hands
|
// test whether shoulders are close enough to allow for reaching to touch hands
|
||||||
|
|
|
@ -67,8 +67,8 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function returns the positive angle in degrees between two 3D vectors
|
// Helper function returns the positive angle in degrees between two 3D vectors
|
||||||
float angleBetween(glm::vec3 * v1, glm::vec3 * v2) {
|
float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
||||||
return acos((glm::dot(*v1, *v2)) / (glm::length(*v1) * glm::length(*v2))) * 180.f / PI;
|
return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a 3D vector floating in space
|
// Draw a 3D vector floating in space
|
||||||
|
|
|
@ -44,7 +44,7 @@ void noiseTest(int w, int h);
|
||||||
|
|
||||||
void drawVector(glm::vec3* vector);
|
void drawVector(glm::vec3* vector);
|
||||||
|
|
||||||
float angleBetween(glm::vec3 * v1, glm::vec3 * v2);
|
float angleBetween(const glm::vec3& v1, const glm::vec3& v2);
|
||||||
|
|
||||||
double diffclock(timeval *clock1,timeval *clock2);
|
double diffclock(timeval *clock1,timeval *clock2);
|
||||||
|
|
||||||
|
|
|
@ -1767,9 +1767,7 @@ void idle(void) {
|
||||||
myAvatar.setHandMovementValues(handControl.getValues());
|
myAvatar.setHandMovementValues(handControl.getValues());
|
||||||
|
|
||||||
// tell my avatar if the mouse is being pressed...
|
// tell my avatar if the mouse is being pressed...
|
||||||
if (mousePressed) {
|
myAvatar.setMousePressed(mousePressed);
|
||||||
myAvatar.setMousePressed(mousePressed);
|
|
||||||
}
|
|
||||||
|
|
||||||
// walking triggers the handControl to stop
|
// walking triggers the handControl to stop
|
||||||
if (myAvatar.getMode() == AVATAR_MODE_WALKING) {
|
if (myAvatar.getMode() == AVATAR_MODE_WALKING) {
|
||||||
|
@ -1889,19 +1887,20 @@ glm::vec3 getGravity(glm::vec3 pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseFunc(int button, int state, int x, int y) {
|
void mouseFunc(int button, int state, int x, int y) {
|
||||||
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
|
if ( !menu.mouseClick(x, y)) { // if a menu item was not clicked or unclicked...
|
||||||
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
|
if ( button == GLUT_LEFT_BUTTON ) {
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
mousePressed = 1;
|
if (state == GLUT_DOWN ) {
|
||||||
} else if (state == GLUT_UP) {
|
mousePressed = 1;
|
||||||
mouseX = x;
|
} else if (state == GLUT_UP ) {
|
||||||
mouseY = y;
|
mousePressed = 0;
|
||||||
mousePressed = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void motionFunc(int x, int y) {
|
void motionFunc(int x, int y) {
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
|
|
Loading…
Reference in a new issue