mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
First commit to improve avatar movement
This commit is contained in:
parent
53cff16c9a
commit
642b64dfd6
3 changed files with 101 additions and 56 deletions
|
@ -212,10 +212,46 @@ void Head::setLeanSideways(float dist){
|
||||||
// Simulate the head over time
|
// Simulate the head over time
|
||||||
void Head::simulate(float deltaTime)
|
void Head::simulate(float deltaTime)
|
||||||
{
|
{
|
||||||
// Increment position as a function of velocity
|
|
||||||
position += velocity * deltaTime;
|
glm::vec3 forward(-sinf(getRenderYaw()*PI/180),
|
||||||
|
sinf(getRenderPitch()*PI/180),
|
||||||
|
cosf(getRenderYaw()*PI/180));
|
||||||
|
|
||||||
|
thrust = glm::vec3(0);
|
||||||
|
const float THRUST_MAG = 6.0;
|
||||||
|
const float THRUST_LATERAL_MAG = 6.0;
|
||||||
|
const float THRUST_VERTICAL_MAG = 6.0;
|
||||||
|
|
||||||
|
if (driveKeys[FWD]) {
|
||||||
|
thrust += THRUST_MAG*forward;
|
||||||
|
}
|
||||||
|
if (driveKeys[BACK]) {
|
||||||
|
thrust += -THRUST_MAG*forward;
|
||||||
|
}
|
||||||
|
if (driveKeys[RIGHT]) {
|
||||||
|
thrust.x += forward.z*-THRUST_LATERAL_MAG;
|
||||||
|
thrust.z += forward.x*THRUST_LATERAL_MAG;
|
||||||
|
}
|
||||||
|
if (driveKeys[LEFT]) {
|
||||||
|
thrust.x += forward.z*THRUST_LATERAL_MAG;
|
||||||
|
thrust.z += forward.x*-THRUST_LATERAL_MAG;
|
||||||
|
}
|
||||||
|
if (driveKeys[UP]) {
|
||||||
|
thrust.y += -THRUST_VERTICAL_MAG;
|
||||||
|
}
|
||||||
|
if (driveKeys[DOWN]) {
|
||||||
|
thrust.y += THRUST_VERTICAL_MAG;
|
||||||
|
}
|
||||||
|
|
||||||
// Increment velocity as time
|
// Increment velocity as time
|
||||||
velocity += thrust * deltaTime;
|
velocity += thrust * deltaTime;
|
||||||
|
|
||||||
|
// Increment position as a function of velocity
|
||||||
|
position += velocity * deltaTime;
|
||||||
|
|
||||||
|
// Decay velocity
|
||||||
|
const float LIN_VEL_DECAY = 5.0;
|
||||||
|
velocity *= (1.0 - LIN_VEL_DECAY*deltaTime);
|
||||||
|
|
||||||
if (!noise)
|
if (!noise)
|
||||||
{
|
{
|
||||||
|
@ -315,13 +351,10 @@ void Head::simulate(float deltaTime)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::render(int faceToFace, int isMine, float * myLocation)
|
void Head::render(int faceToFace, int isMine)
|
||||||
{
|
{
|
||||||
int side = 0;
|
int side = 0;
|
||||||
|
|
||||||
glm::vec3 cameraHead(myLocation[0], myLocation[1], myLocation[2]);
|
|
||||||
float distanceToCamera = glm::distance(cameraHead, position);
|
|
||||||
|
|
||||||
// Always render own hand, but don't render head unless showing face2face
|
// Always render own hand, but don't render head unless showing face2face
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -334,7 +367,7 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
|
||||||
hand->render(1);
|
hand->render(1);
|
||||||
|
|
||||||
// Don't render a head if it is really close to your location, because that is your own head!
|
// Don't render a head if it is really close to your location, because that is your own head!
|
||||||
if ((distanceToCamera > 1.0) || faceToFace) {
|
if (!isMine || faceToFace) {
|
||||||
|
|
||||||
glRotatef(Pitch, 1, 0, 0);
|
glRotatef(Pitch, 1, 0, 0);
|
||||||
glRotatef(Roll, 0, 0, 1);
|
glRotatef(Roll, 0, 0, 1);
|
||||||
|
|
|
@ -20,6 +20,13 @@
|
||||||
|
|
||||||
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
||||||
|
|
||||||
|
#define FWD 0
|
||||||
|
#define BACK 1
|
||||||
|
#define LEFT 2
|
||||||
|
#define RIGHT 3
|
||||||
|
#define UP 4
|
||||||
|
#define DOWN 5
|
||||||
|
|
||||||
class Head : public AgentData {
|
class Head : public AgentData {
|
||||||
public:
|
public:
|
||||||
Head();
|
Head();
|
||||||
|
@ -49,7 +56,7 @@ class Head : public AgentData {
|
||||||
float getYaw() {return Yaw;}
|
float getYaw() {return Yaw;}
|
||||||
float getLastMeasuredYaw() {return YawRate;}
|
float getLastMeasuredYaw() {return YawRate;}
|
||||||
|
|
||||||
void render(int faceToFace, int isMine, float * myLocation);
|
void render(int faceToFace, int isMine);
|
||||||
void simulate(float);
|
void simulate(float);
|
||||||
|
|
||||||
// Send and receive network data
|
// Send and receive network data
|
||||||
|
@ -65,7 +72,11 @@ class Head : public AgentData {
|
||||||
glm::vec3 getPos() { return position; };
|
glm::vec3 getPos() { return position; };
|
||||||
void setPos(glm::vec3 newpos) { position = newpos; };
|
void setPos(glm::vec3 newpos) { position = newpos; };
|
||||||
|
|
||||||
// Set/Get update the thrust that will move the avatar around
|
// Set what driving keys are being pressed to control thrust levels
|
||||||
|
void setDriveKeys(int key, bool val) { driveKeys[key] = val; };
|
||||||
|
bool getDriveKeys(int key) { return driveKeys[key]; };
|
||||||
|
|
||||||
|
// Set/Get update the thrust that will move the avatar around
|
||||||
void setThrust(glm::vec3 newThrust) { thrust = newThrust; };
|
void setThrust(glm::vec3 newThrust) { thrust = newThrust; };
|
||||||
void addThrust(glm::vec3 newThrust) { thrust += newThrust; };
|
void addThrust(glm::vec3 newThrust) { thrust += newThrust; };
|
||||||
glm::vec3 getThrust() { return thrust; };
|
glm::vec3 getThrust() { return thrust; };
|
||||||
|
@ -111,8 +122,8 @@ class Head : public AgentData {
|
||||||
glm::vec3 velocity;
|
glm::vec3 velocity;
|
||||||
glm::vec3 thrust;
|
glm::vec3 thrust;
|
||||||
|
|
||||||
bool fwdKey, backKey, turnLeftKey, turnRightKey, slideLeftKey, slideRightKey, upKey, downKey;
|
int driveKeys[6];
|
||||||
|
|
||||||
int eyeContact;
|
int eyeContact;
|
||||||
eyeContactTargets eyeContactTarget;
|
eyeContactTargets eyeContactTarget;
|
||||||
|
|
||||||
|
|
|
@ -121,14 +121,9 @@ float render_yaw_rate = 0.f;
|
||||||
float render_pitch_rate = 0.f;
|
float render_pitch_rate = 0.f;
|
||||||
float lateral_vel = 0.f;
|
float lateral_vel = 0.f;
|
||||||
|
|
||||||
// Manage speed and direction of motion
|
// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program)
|
||||||
GLfloat fwd_vec[] = {0.0, 0.0, 1.0};
|
glm::vec3 start_location(6.1f, 0, 1.4f);
|
||||||
//GLfloat start_location[] = { WORLD_SIZE*1.5, -WORLD_SIZE/2.0, -WORLD_SIZE/3.0};
|
|
||||||
//GLfloat start_location[] = { 0.1, -0.15, 0.1};
|
|
||||||
|
|
||||||
GLfloat start_location[] = {6.1f, 0, 1.4f};
|
|
||||||
|
|
||||||
GLfloat location[] = {start_location[0], start_location[1], start_location[2]};
|
|
||||||
float fwd_vel = 0.0f;
|
float fwd_vel = 0.0f;
|
||||||
|
|
||||||
int stats_on = 0; // Whether to show onscreen text overlay with stats
|
int stats_on = 0; // Whether to show onscreen text overlay with stats
|
||||||
|
@ -319,6 +314,7 @@ void init(void)
|
||||||
if (noise_on) {
|
if (noise_on) {
|
||||||
myHead.setNoise(noise);
|
myHead.setNoise(noise);
|
||||||
}
|
}
|
||||||
|
myHead.setPos(start_location);
|
||||||
|
|
||||||
char output[] = "I";
|
char output[] = "I";
|
||||||
char address[] = "10.0.0.10";
|
char address[] = "10.0.0.10";
|
||||||
|
@ -365,12 +361,10 @@ void reset_sensors()
|
||||||
yaw = render_yaw_rate = 0;
|
yaw = render_yaw_rate = 0;
|
||||||
pitch = render_pitch = render_pitch_rate = 0;
|
pitch = render_pitch = render_pitch_rate = 0;
|
||||||
lateral_vel = 0;
|
lateral_vel = 0;
|
||||||
location[0] = start_location[0];
|
myHead.setPos(start_location);
|
||||||
location[1] = start_location[1];
|
|
||||||
location[2] = start_location[2];
|
|
||||||
fwd_vel = 0.0;
|
fwd_vel = 0.0;
|
||||||
head_mouse_x = WIDTH/2;
|
head_mouse_x = WIDTH/2;
|
||||||
head_mouse_y = HEIGHT/2;
|
head_mouse_y = HEIGHT/2;
|
||||||
head_lean_x = WIDTH/2;
|
head_lean_x = WIDTH/2;
|
||||||
head_lean_y = HEIGHT/2;
|
head_lean_y = HEIGHT/2;
|
||||||
|
|
||||||
|
@ -483,26 +477,11 @@ void simulateHead(float frametime)
|
||||||
}*/
|
}*/
|
||||||
// Decrease forward velocity
|
// Decrease forward velocity
|
||||||
fwd_vel *= (1.f - 4.0*frametime);
|
fwd_vel *= (1.f - 4.0*frametime);
|
||||||
|
|
||||||
|
|
||||||
// Update forward vector based on pitch and yaw
|
|
||||||
fwd_vec[0] = -sinf(myHead.getRenderYaw()*PI/180);
|
|
||||||
fwd_vec[1] = sinf(render_pitch*PI/180);
|
|
||||||
fwd_vec[2] = cosf(myHead.getRenderYaw()*PI/180);
|
|
||||||
|
|
||||||
// Advance location forward
|
|
||||||
location[0] += fwd_vec[0]*fwd_vel;
|
|
||||||
location[1] += fwd_vec[1]*fwd_vel;
|
|
||||||
location[2] += fwd_vec[2]*fwd_vel;
|
|
||||||
|
|
||||||
// Slide location sideways
|
|
||||||
location[0] += fwd_vec[2]*-lateral_vel;
|
|
||||||
location[2] += fwd_vec[0]*lateral_vel;
|
|
||||||
|
|
||||||
// Update own head data
|
// Update own head data
|
||||||
myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
|
myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
|
||||||
myHead.setRenderPitch(render_pitch);
|
myHead.setRenderPitch(render_pitch);
|
||||||
myHead.setPos(glm::vec3(location[0], location[1], location[2]));
|
//myHead.setPos(glm::vec3(location[0], location[1], location[2]));
|
||||||
|
|
||||||
// Get audio loudness data from audio input device
|
// Get audio loudness data from audio input device
|
||||||
float loudness, averageLoudness;
|
float loudness, averageLoudness;
|
||||||
|
@ -552,12 +531,11 @@ void display(void)
|
||||||
// Rotate, translate to camera location
|
// Rotate, translate to camera location
|
||||||
glRotatef(myHead.getRenderPitch(), 1, 0, 0);
|
glRotatef(myHead.getRenderPitch(), 1, 0, 0);
|
||||||
glRotatef(myHead.getRenderYaw(), 0, 1, 0);
|
glRotatef(myHead.getRenderYaw(), 0, 1, 0);
|
||||||
glTranslatef(location[0], location[1], location[2]);
|
glTranslatef(myHead.getPos().x, myHead.getPos().y, myHead.getPos().z);
|
||||||
|
|
||||||
glColor3f(1,0,0);
|
glColor3f(1,0,0);
|
||||||
glutSolidSphere(0.25, 15, 15);
|
glutSolidSphere(0.25, 15, 15);
|
||||||
|
|
||||||
|
|
||||||
// Draw cloud of dots
|
// Draw cloud of dots
|
||||||
glDisable( GL_POINT_SPRITE_ARB );
|
glDisable( GL_POINT_SPRITE_ARB );
|
||||||
glDisable( GL_TEXTURE_2D );
|
glDisable( GL_TEXTURE_2D );
|
||||||
|
@ -576,7 +554,7 @@ void display(void)
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glm::vec3 pos = agentHead->getPos();
|
glm::vec3 pos = agentHead->getPos();
|
||||||
glTranslatef(-pos.x, -pos.y, -pos.z);
|
glTranslatef(-pos.x, -pos.y, -pos.z);
|
||||||
agentHead->render(0, 0, &location[0]);
|
agentHead->render(0, 0);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,12 +568,8 @@ void display(void)
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.f, 0.f, -7.f);
|
glTranslatef(0.f, 0.f, -7.f);
|
||||||
myHead.render(display_head, 1, &location[0]);
|
myHead.render(display_head, 1);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
//glm::vec3 test(0.5, 0.5, 0.5);
|
|
||||||
//render_vector(&test);
|
|
||||||
|
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
@ -715,23 +689,50 @@ const float KEYBOARD_YAW_RATE = 0.8;
|
||||||
const float KEYBOARD_STRAFE_RATE = 0.03;
|
const float KEYBOARD_STRAFE_RATE = 0.03;
|
||||||
const float KEYBOARD_FLY_RATE = 0.08;
|
const float KEYBOARD_FLY_RATE = 0.08;
|
||||||
|
|
||||||
|
void specialkeyUp(int k, int x, int y) {
|
||||||
|
if (k == GLUT_KEY_UP) {
|
||||||
|
myHead.setDriveKeys(FWD, 0);
|
||||||
|
myHead.setDriveKeys(UP, 0);
|
||||||
|
}
|
||||||
|
if (k == GLUT_KEY_DOWN) {
|
||||||
|
myHead.setDriveKeys(BACK, 0);
|
||||||
|
myHead.setDriveKeys(DOWN, 0);
|
||||||
|
}
|
||||||
|
if (k == GLUT_KEY_LEFT) myHead.setDriveKeys(LEFT, 0);
|
||||||
|
if (k == GLUT_KEY_RIGHT) myHead.setDriveKeys(RIGHT, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void specialkey(int k, int x, int y)
|
void specialkey(int k, int x, int y)
|
||||||
{
|
{
|
||||||
if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) {
|
if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) {
|
||||||
if (k == GLUT_KEY_UP) fwd_vel += KEYBOARD_FLY_RATE;
|
if (k == GLUT_KEY_UP) {
|
||||||
if (k == GLUT_KEY_DOWN) fwd_vel -= KEYBOARD_FLY_RATE;
|
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(UP, 1);
|
||||||
|
else myHead.setDriveKeys(FWD, 1);
|
||||||
|
}
|
||||||
|
if (k == GLUT_KEY_DOWN) {
|
||||||
|
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(DOWN, 1);
|
||||||
|
else myHead.setDriveKeys(BACK, 1);
|
||||||
|
}
|
||||||
if (k == GLUT_KEY_LEFT) {
|
if (k == GLUT_KEY_LEFT) {
|
||||||
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel -= KEYBOARD_STRAFE_RATE;
|
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(LEFT, 1);
|
||||||
else render_yaw_rate -= KEYBOARD_YAW_RATE;
|
else render_yaw_rate -= KEYBOARD_YAW_RATE;
|
||||||
}
|
}
|
||||||
if (k == GLUT_KEY_RIGHT) {
|
if (k == GLUT_KEY_RIGHT) {
|
||||||
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel += KEYBOARD_STRAFE_RATE;
|
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myHead.setDriveKeys(RIGHT, 1);
|
||||||
else render_yaw_rate += KEYBOARD_YAW_RATE;
|
else render_yaw_rate += KEYBOARD_YAW_RATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio.setWalkingState(true);
|
audio.setWalkingState(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void keyUp(unsigned char k, int x, int y) {
|
||||||
|
if (k == 'e') myHead.setDriveKeys(UP, 0);
|
||||||
|
if (k == 'c') myHead.setDriveKeys(DOWN, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void key(unsigned char k, int x, int y)
|
void key(unsigned char k, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -764,10 +765,8 @@ void key(unsigned char k, int x, int y)
|
||||||
|
|
||||||
if (k == 'f') display_field = !display_field;
|
if (k == 'f') display_field = !display_field;
|
||||||
if (k == 'l') display_levels = !display_levels;
|
if (k == 'l') display_levels = !display_levels;
|
||||||
|
if (k == 'e') myHead.setDriveKeys(UP, 1);
|
||||||
|
if (k == 'c') myHead.setDriveKeys(DOWN, 1);
|
||||||
if (k == 'e') location[1] -= WORLD_SIZE/100.0;
|
|
||||||
if (k == 'c') location[1] += WORLD_SIZE/100.0;
|
|
||||||
if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE;
|
if (k == 'w') fwd_vel += KEYBOARD_FLY_RATE;
|
||||||
if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE;
|
if (k == 's') fwd_vel -= KEYBOARD_FLY_RATE;
|
||||||
if (k == ' ') reset_sensors();
|
if (k == ' ') reset_sensors();
|
||||||
|
@ -960,7 +959,9 @@ int main(int argc, char** argv)
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutReshapeFunc(reshape);
|
glutReshapeFunc(reshape);
|
||||||
glutKeyboardFunc(key);
|
glutKeyboardFunc(key);
|
||||||
|
glutKeyboardUpFunc(keyUp);
|
||||||
glutSpecialFunc(specialkey);
|
glutSpecialFunc(specialkey);
|
||||||
|
glutSpecialUpFunc(specialkeyUp);
|
||||||
glutMotionFunc(motionFunc);
|
glutMotionFunc(motionFunc);
|
||||||
glutPassiveMotionFunc(mouseoverFunc);
|
glutPassiveMotionFunc(mouseoverFunc);
|
||||||
glutMouseFunc(mouseFunc);
|
glutMouseFunc(mouseFunc);
|
||||||
|
|
Loading…
Reference in a new issue