mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:03:35 +02:00
added more robust avatar hand movement algorithm in main.cpp
This commit is contained in:
parent
2b5d23de5d
commit
298bc7eee9
1 changed files with 79 additions and 44 deletions
|
@ -167,16 +167,73 @@ int displayField = 0;
|
||||||
int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement
|
int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement
|
||||||
int headMouseX, headMouseY;
|
int headMouseX, headMouseY;
|
||||||
|
|
||||||
int mouseX, mouseY; // Where is the mouse
|
int mouseX = 0;
|
||||||
|
int mouseY = 0;
|
||||||
|
|
||||||
// Mouse location at start of last down click
|
// Mouse location at start of last down click
|
||||||
int mouseStartX = WIDTH / 2;
|
|
||||||
int mouseStartY = HEIGHT / 2;
|
|
||||||
int mousePressed = 0; // true if mouse has been pressed (clear when finished)
|
int mousePressed = 0; // true if mouse has been pressed (clear when finished)
|
||||||
|
|
||||||
Menu menu; // main menu
|
Menu menu; // main menu
|
||||||
int menuOn = 1; // Whether to show onscreen menu
|
int menuOn = 1; // Whether to show onscreen menu
|
||||||
|
|
||||||
|
struct HandMovement
|
||||||
|
{
|
||||||
|
bool enabled = false;
|
||||||
|
int startX = WIDTH / 2;
|
||||||
|
int startY = HEIGHT / 2;
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
int lastX = 0;
|
||||||
|
int lastY = 0;
|
||||||
|
int velocityX = 0;
|
||||||
|
int velocityY = 0;
|
||||||
|
float rampUpRate = 0.05;
|
||||||
|
float rampDownRate = 0.02;
|
||||||
|
float envelope = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
HandMovement handMovement;
|
||||||
|
|
||||||
|
void updateHandMovement( int x, int y ) {
|
||||||
|
handMovement.lastX = handMovement.x;
|
||||||
|
handMovement.lastY = handMovement.y;
|
||||||
|
handMovement.x = x;
|
||||||
|
handMovement.y = y;
|
||||||
|
handMovement.velocityX = handMovement.x - handMovement.lastX;
|
||||||
|
handMovement.velocityY = handMovement.y - handMovement.lastY;
|
||||||
|
|
||||||
|
if (( handMovement.velocityX != 0 )
|
||||||
|
|| ( handMovement.velocityY != 0 )) {
|
||||||
|
handMovement.enabled = true;
|
||||||
|
if ( handMovement.envelope < 1.0 ) {
|
||||||
|
handMovement.envelope += handMovement.rampUpRate;
|
||||||
|
if ( handMovement.envelope >= 1.0 ) {
|
||||||
|
handMovement.envelope = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! handMovement.enabled ) {
|
||||||
|
if ( handMovement.envelope > 0.0 ) {
|
||||||
|
handMovement.envelope -= handMovement.rampDownRate;
|
||||||
|
if ( handMovement.envelope <= 0.0 ) {
|
||||||
|
handMovement.startX = WIDTH / 2;
|
||||||
|
handMovement.startY = HEIGHT / 2;
|
||||||
|
handMovement.envelope = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( handMovement.envelope > 0.0 ) {
|
||||||
|
float leftRight = ( ( handMovement.x - handMovement.startX ) / (float)WIDTH ) * handMovement.envelope;
|
||||||
|
float downUp = ( ( handMovement.y - handMovement.startY ) / (float)HEIGHT ) * handMovement.envelope;
|
||||||
|
float backFront = 0.0;
|
||||||
|
myAvatar.setHandMovement( glm::vec3( leftRight, downUp, backFront ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Serial USB Variables
|
// Serial USB Variables
|
||||||
//
|
//
|
||||||
|
@ -363,22 +420,6 @@ void reset_sensors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void updateAvatarHand(float deltaTime) {
|
|
||||||
// If mouse is being dragged, send current force to the hand controller
|
|
||||||
if (mousePressed == 1)
|
|
||||||
{
|
|
||||||
// NOTE--PER: Need to re-implement when ready for new avatar hand movements
|
|
||||||
|
|
||||||
const float MOUSE_HAND_FORCE = 1.5;
|
|
||||||
float dx = mouseX - mouseStartX;
|
|
||||||
float dy = mouseY - mouseStartY;
|
|
||||||
glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0);
|
|
||||||
//myAvatar.hand->addVelocity(vel*deltaTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Using gyro data, update both view frustum and avatar head position
|
// Using gyro data, update both view frustum and avatar head position
|
||||||
//
|
//
|
||||||
|
@ -830,10 +871,10 @@ void display(void)
|
||||||
agent != agentList->getAgents().end();
|
agent != agentList->getAgents().end();
|
||||||
agent++) {
|
agent++) {
|
||||||
if (agent->getLinkedData() != NULL) {
|
if (agent->getLinkedData() != NULL) {
|
||||||
Head *agentHead = (Head *)agent->getLinkedData();
|
Head *avatar = (Head *)agent->getLinkedData();
|
||||||
glPushMatrix();
|
//glPushMatrix();
|
||||||
agentHead->render(0);
|
avatar->render(0);
|
||||||
glPopMatrix();
|
//glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1332,25 +1373,13 @@ void idle(void) {
|
||||||
|
|
||||||
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
|
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
|
||||||
|
|
||||||
//if ( myAvatar.getMode() == AVATAR_MODE_COMMUNICATING ) {
|
float deltaTime = 1.f/FPS;
|
||||||
float leftRight = ( mouseX - mouseStartX ) / (float)WIDTH;
|
|
||||||
float downUp = ( mouseY - mouseStartY ) / (float)HEIGHT;
|
// update behaviors for avatar hand movement
|
||||||
float backFront = 0.0;
|
updateHandMovement( mouseX, mouseY );
|
||||||
glm::vec3 handMovement( leftRight, downUp, backFront );
|
|
||||||
myAvatar.setHandMovement( handMovement );
|
|
||||||
/*}
|
|
||||||
else {
|
|
||||||
mouseStartX = mouseX;
|
|
||||||
mouseStartY = mouseY;
|
|
||||||
//mouseStartX = (float)WIDTH / 2.0f;
|
|
||||||
//mouseStartY = (float)HEIGHT / 2.0f;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//--------------------------------------------------------
|
|
||||||
// when the mouse is being pressed, an 'action' is being
|
// when the mouse is being pressed, an 'action' is being
|
||||||
// triggered in the avatar. The action is context-based.
|
// triggered in the avatar. The action is context-based.
|
||||||
//--------------------------------------------------------
|
|
||||||
if ( mousePressed == 1 ) {
|
if ( mousePressed == 1 ) {
|
||||||
myAvatar.setTriggeringAction( true );
|
myAvatar.setTriggeringAction( true );
|
||||||
}
|
}
|
||||||
|
@ -1358,8 +1387,11 @@ void idle(void) {
|
||||||
myAvatar.setTriggeringAction( false );
|
myAvatar.setTriggeringAction( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
float deltaTime = 1.f/FPS;
|
// walking triggers the handMovement to stop
|
||||||
|
if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) {
|
||||||
|
handMovement.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
|
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
|
||||||
//
|
//
|
||||||
|
@ -1457,8 +1489,6 @@ void mouseFunc( int button, int state, int x, int y )
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
mousePressed = 1;
|
mousePressed = 1;
|
||||||
//mouseStartX = x;
|
|
||||||
//mouseStartY = y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
|
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
|
||||||
|
@ -1478,12 +1508,17 @@ void motionFunc( int x, int y)
|
||||||
void mouseoverFunc( int x, int y)
|
void mouseoverFunc( int x, int y)
|
||||||
{
|
{
|
||||||
menu.mouseOver(x, y);
|
menu.mouseOver(x, y);
|
||||||
|
|
||||||
mouseX = x;
|
mouseX = x;
|
||||||
mouseY = y;
|
mouseY = y;
|
||||||
if (mousePressed == 0)
|
if (mousePressed == 0)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void attachNewHeadToAgent(Agent *newAgent) {
|
void attachNewHeadToAgent(Agent *newAgent) {
|
||||||
if (newAgent->getLinkedData() == NULL) {
|
if (newAgent->getLinkedData() == NULL) {
|
||||||
newAgent->setLinkedData(new Head(false));
|
newAgent->setLinkedData(new Head(false));
|
||||||
|
|
Loading…
Reference in a new issue