mirror of
https://github.com/lubosz/overte.git
synced 2025-08-16 17:58:40 +02:00
First commit to re-enable gyros, removed various old head_mirror variables, now use 'lookingInMirror', etc. Local gyros now correctly drive own head.
This commit is contained in:
parent
e00a387020
commit
9760b7d410
4 changed files with 55 additions and 50 deletions
|
@ -250,8 +250,16 @@ int audioCallback (const void *inputBuffer,
|
||||||
}
|
}
|
||||||
// play whatever we have in the audio buffer
|
// play whatever we have in the audio buffer
|
||||||
|
|
||||||
|
//
|
||||||
// if we haven't fired off the flange effect, check if we should
|
// if we haven't fired off the flange effect, check if we should
|
||||||
int lastYawMeasured = fabsf(data->linkedHead->getLastMeasuredYaw());
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// NOTE: PER - LastMeasuredHeadYaw is now relative to body position, represents the local
|
||||||
|
// rotation of the head relative to body, this may effect flange effect!
|
||||||
|
//
|
||||||
|
//
|
||||||
|
int lastYawMeasured = fabsf(data->linkedHead->getLastMeasuredHeadYaw());
|
||||||
|
|
||||||
if (!samplesLeftForFlange && lastYawMeasured > MIN_FLANGE_EFFECT_THRESHOLD) {
|
if (!samplesLeftForFlange && lastYawMeasured > MIN_FLANGE_EFFECT_THRESHOLD) {
|
||||||
// we should flange for one second
|
// we should flange for one second
|
||||||
|
|
|
@ -241,7 +241,7 @@ void Head::reset() {
|
||||||
|
|
||||||
//this pertains to moving the head with the glasses
|
//this pertains to moving the head with the glasses
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity)
|
void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity)
|
||||||
// Using serial data, update avatar/render position and angles
|
// Using serial data, update avatar/render position and angles
|
||||||
{
|
{
|
||||||
const float PITCH_ACCEL_COUPLING = 0.5;
|
const float PITCH_ACCEL_COUPLING = 0.5;
|
||||||
|
@ -270,19 +270,14 @@ void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int h
|
||||||
const float MIN_YAW = -85;
|
const float MIN_YAW = -85;
|
||||||
|
|
||||||
if ((_head.pitch < MAX_PITCH) && (_head.pitch > MIN_PITCH))
|
if ((_head.pitch < MAX_PITCH) && (_head.pitch > MIN_PITCH))
|
||||||
addPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime);
|
addHeadPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime);
|
||||||
|
|
||||||
addRoll(-measured_roll_rate * HEAD_ROLL_SCALE * frametime);
|
addHeadRoll(measured_roll_rate * HEAD_ROLL_SCALE * frametime);
|
||||||
|
|
||||||
if (head_mirror) {
|
if ((_head.yaw < MAX_YAW) && (_head.yaw > MIN_YAW))
|
||||||
if ((_head.yaw < MAX_YAW) && (_head.yaw > MIN_YAW))
|
addHeadYaw(_head.yawRate * HEAD_ROTATION_SCALE * frametime);
|
||||||
addYaw(-_head.yawRate * HEAD_ROTATION_SCALE * frametime);
|
|
||||||
addLean(-measured_lateral_accel * frametime * HEAD_LEAN_SCALE, -measured_fwd_accel*frametime * HEAD_LEAN_SCALE);
|
addLean(-measured_lateral_accel * frametime * HEAD_LEAN_SCALE, -measured_fwd_accel*frametime * HEAD_LEAN_SCALE);
|
||||||
} else {
|
|
||||||
if ((_head.yaw < MAX_YAW) && (_head.yaw > MIN_YAW))
|
|
||||||
addYaw(_head.yawRate * -HEAD_ROTATION_SCALE * frametime);
|
|
||||||
addLean(measured_lateral_accel * frametime * -HEAD_LEAN_SCALE, measured_fwd_accel*frametime * HEAD_LEAN_SCALE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::addLean(float x, float z) {
|
void Head::addLean(float x, float z) {
|
||||||
|
@ -462,10 +457,6 @@ void Head::simulate(float deltaTime) {
|
||||||
_bodyYaw += _bodyYawDelta * deltaTime;
|
_bodyYaw += _bodyYawDelta * deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we will be eventually getting head rotation from elsewhere. For now, just setting it to body rotation
|
|
||||||
_head.yaw = _bodyYaw;
|
|
||||||
_head.pitch = _bodyPitch;
|
|
||||||
_head.roll = _bodyRoll;
|
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
// decay body yaw delta
|
// decay body yaw delta
|
||||||
|
@ -487,6 +478,15 @@ void Head::simulate(float deltaTime) {
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
|
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Head information
|
||||||
|
//
|
||||||
|
|
||||||
|
// we will be eventually getting head rotation from elsewhere. For now, just setting it to body rotation
|
||||||
|
//_head.yaw = _bodyYaw;
|
||||||
|
//_head.pitch = _bodyPitch;
|
||||||
|
//_head.roll = _bodyRoll;
|
||||||
|
|
||||||
if (!_head.noise) {
|
if (!_head.noise) {
|
||||||
// Decay back toward center
|
// Decay back toward center
|
||||||
_head.pitch *= (1.0f - DECAY*2*deltaTime);
|
_head.pitch *= (1.0f - DECAY*2*deltaTime);
|
||||||
|
@ -625,7 +625,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Head::render(int faceToFace) {
|
void Head::render(int lookingInMirror) {
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// show avatar position
|
// show avatar position
|
||||||
|
@ -658,7 +658,7 @@ void Head::render(int faceToFace) {
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// render head
|
// render head
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
renderHead(faceToFace);
|
renderHead(lookingInMirror);
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// if this is my avatar, then render my interactions with the other avatars
|
// if this is my avatar, then render my interactions with the other avatars
|
||||||
|
@ -695,9 +695,9 @@ void Head::render(int faceToFace) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Head::renderHead(int faceToFace) {
|
void Head::renderHead(int lookingInMirror) {
|
||||||
int side = 0;
|
int side = 0;
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
@ -723,9 +723,13 @@ void Head::renderHead(int faceToFace) {
|
||||||
|
|
||||||
glScalef( 0.03, 0.03, 0.03 );
|
glScalef( 0.03, 0.03, 0.03 );
|
||||||
|
|
||||||
glRotatef(_head.yaw, 0, 1, 0);
|
if (lookingInMirror) {
|
||||||
glRotatef(_head.pitch, 1, 0, 0);
|
glRotatef(_bodyYaw - _head.yaw, 0, 1, 0);
|
||||||
glRotatef(_head.roll, 0, 0, 1);
|
} else {
|
||||||
|
glRotatef(_bodyYaw + _head.yaw, 0, 1, 0);
|
||||||
|
}
|
||||||
|
glRotatef(_bodyPitch + _head.pitch, 1, 0, 0);
|
||||||
|
glRotatef(_bodyRoll + _head.roll, 0, 0, 1);
|
||||||
|
|
||||||
glScalef(2.0, 2.0, 2.0);
|
glScalef(2.0, 2.0, 2.0);
|
||||||
glColor3fv(skinColor);
|
glColor3fv(skinColor);
|
||||||
|
|
|
@ -148,7 +148,7 @@ class Head : public AvatarData {
|
||||||
Head* clone() const;
|
Head* clone() const;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
|
void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
|
||||||
void setNoise (float mag) { _head.noise = mag; }
|
void setNoise (float mag) { _head.noise = mag; }
|
||||||
void setPitch(float p) {_head.pitch = p; }
|
void setPitch(float p) {_head.pitch = p; }
|
||||||
void setYaw(float y) {_head.yaw = y; }
|
void setYaw(float y) {_head.yaw = y; }
|
||||||
|
@ -160,14 +160,14 @@ class Head : public AvatarData {
|
||||||
float getRenderPitch() {return _renderPitch;}
|
float getRenderPitch() {return _renderPitch;}
|
||||||
void setLeanForward(float dist);
|
void setLeanForward(float dist);
|
||||||
void setLeanSideways(float dist);
|
void setLeanSideways(float dist);
|
||||||
void addPitch(float p) {_head.pitch -= p; }
|
void addHeadPitch(float p) {_head.pitch -= p; }
|
||||||
void addYaw(float y){_head.yaw -= y; }
|
void addHeadYaw(float y){_head.yaw -= y; }
|
||||||
void addRoll(float r){_head.roll += r; }
|
void addHeadRoll(float r){_head.roll += r; }
|
||||||
void addLean(float x, float z);
|
void addLean(float x, float z);
|
||||||
float getPitch() {return _head.pitch;}
|
float getHeadPitch() {return _head.pitch;}
|
||||||
float getRoll() {return _head.roll;}
|
float getHeadRoll() {return _head.roll;}
|
||||||
float getYaw() {return _head.yaw;}
|
float getHeadYaw() {return _head.yaw;}
|
||||||
float getLastMeasuredYaw() {return _head.yawRate;}
|
float getLastMeasuredHeadYaw() {return _head.yawRate;}
|
||||||
float getBodyYaw() {return _bodyYaw;};
|
float getBodyYaw() {return _bodyYaw;};
|
||||||
void addBodyYaw(float y) {_bodyYaw += y;};
|
void addBodyYaw(float y) {_bodyYaw += y;};
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,6 @@ int packetsPerSecond = 0;
|
||||||
int bytesPerSecond = 0;
|
int bytesPerSecond = 0;
|
||||||
int bytesCount = 0;
|
int bytesCount = 0;
|
||||||
|
|
||||||
int headMirror = 1; // Whether to mirror own head when viewing it
|
|
||||||
|
|
||||||
int WIDTH = 1200; // Window size
|
int WIDTH = 1200; // Window size
|
||||||
int HEIGHT = 800;
|
int HEIGHT = 800;
|
||||||
int fullscreen = 0;
|
int fullscreen = 0;
|
||||||
|
@ -163,7 +161,7 @@ int noiseOn = 0; // Whether to add random noise
|
||||||
float noise = 1.0; // Overall magnitude scaling for random noise levels
|
float noise = 1.0; // Overall magnitude scaling for random noise levels
|
||||||
|
|
||||||
int displayLevels = 0;
|
int displayLevels = 0;
|
||||||
int displayHead = 0;
|
int lookingInMirror = 0; // Are we currently rendering one's own head as if in mirror?
|
||||||
int displayField = 0;
|
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
|
||||||
|
@ -459,7 +457,7 @@ void updateAvatar(float frametime)
|
||||||
float gyroPitchRate = serialPort.getRelativeValue(HEAD_PITCH_RATE);
|
float gyroPitchRate = serialPort.getRelativeValue(HEAD_PITCH_RATE);
|
||||||
float gyroYawRate = serialPort.getRelativeValue(HEAD_YAW_RATE );
|
float gyroYawRate = serialPort.getRelativeValue(HEAD_YAW_RATE );
|
||||||
|
|
||||||
myAvatar.UpdateGyros(frametime, &serialPort, headMirror, &gravity);
|
myAvatar.UpdateGyros(frametime, &serialPort, &gravity);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update gyro-based mouse (X,Y on screen)
|
// Update gyro-based mouse (X,Y on screen)
|
||||||
|
@ -819,7 +817,7 @@ void display(void)
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
// camera settings
|
// camera settings
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
if ( displayHead ) {
|
if ( lookingInMirror ) {
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// set the camera to looking at my own face
|
// set the camera to looking at my own face
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
@ -912,7 +910,7 @@ void display(void)
|
||||||
drawGroundPlaneGrid( 5.0f, 9 );
|
drawGroundPlaneGrid( 5.0f, 9 );
|
||||||
|
|
||||||
// Draw cloud of dots
|
// Draw cloud of dots
|
||||||
if (!displayHead) cloud.render();
|
if (!lookingInMirror) cloud.render();
|
||||||
|
|
||||||
// Draw voxels
|
// Draw voxels
|
||||||
if ( showingVoxels )
|
if ( showingVoxels )
|
||||||
|
@ -934,16 +932,16 @@ void display(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !displayHead ) balls.render();
|
if ( !lookingInMirror ) balls.render();
|
||||||
|
|
||||||
// Render the world box
|
// Render the world box
|
||||||
if (!displayHead && statsOn) render_world_box();
|
if (!lookingInMirror && statsOn) render_world_box();
|
||||||
|
|
||||||
// brad's frustum for debugging
|
// brad's frustum for debugging
|
||||||
if (::frustumOn) renderViewFrustum(::viewFrustum);
|
if (::frustumOn) renderViewFrustum(::viewFrustum);
|
||||||
|
|
||||||
//Render my own avatar
|
//Render my own avatar
|
||||||
myAvatar.render(true);
|
myAvatar.render(lookingInMirror);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
@ -961,7 +959,7 @@ void display(void)
|
||||||
if (audioScope.getState()) audioScope.render();
|
if (audioScope.getState()) audioScope.render();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (displayHeadMouse && !displayHead && statsOn) {
|
if (displayHeadMouse && !lookingInMirror && statsOn) {
|
||||||
// Display small target box at center or head mouse target that can also be used to measure LOD
|
// Display small target box at center or head mouse target that can also be used to measure LOD
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
|
@ -1057,7 +1055,7 @@ int setValue(int state, bool *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int setHead(int state) {
|
int setHead(int state) {
|
||||||
return setValue(state, &displayHead);
|
return setValue(state, &lookingInMirror);
|
||||||
}
|
}
|
||||||
|
|
||||||
int setField(int state) {
|
int setField(int state) {
|
||||||
|
@ -1090,10 +1088,6 @@ int setMenu(int state) {
|
||||||
return setValue(state, &::menuOn);
|
return setValue(state, &::menuOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int setMirror(int state) {
|
|
||||||
return setValue(state, &headMirror);
|
|
||||||
}
|
|
||||||
|
|
||||||
int setDisplayFrustum(int state) {
|
int setDisplayFrustum(int state) {
|
||||||
return setValue(state, &::frustumOn);
|
return setValue(state, &::frustumOn);
|
||||||
}
|
}
|
||||||
|
@ -1202,7 +1196,6 @@ void initMenu() {
|
||||||
menuColumnOptions->addRow("(H)ead", setHead);
|
menuColumnOptions->addRow("(H)ead", setHead);
|
||||||
menuColumnOptions->addRow("Field (f)", setField);
|
menuColumnOptions->addRow("Field (f)", setField);
|
||||||
menuColumnOptions->addRow("(N)oise", setNoise);
|
menuColumnOptions->addRow("(N)oise", setNoise);
|
||||||
menuColumnOptions->addRow("Mirror", setMirror);
|
|
||||||
menuColumnOptions->addRow("(V)oxels", setVoxels);
|
menuColumnOptions->addRow("(V)oxels", setVoxels);
|
||||||
menuColumnOptions->addRow("Stars (*)", setStars);
|
menuColumnOptions->addRow("Stars (*)", setStars);
|
||||||
menuColumnOptions->addRow("(Q)uit", quitApp);
|
menuColumnOptions->addRow("(Q)uit", quitApp);
|
||||||
|
@ -1411,9 +1404,9 @@ void key(unsigned char k, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k == 'h') {
|
if (k == 'h') {
|
||||||
displayHead = !displayHead;
|
lookingInMirror = !lookingInMirror;
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
audio.setMixerLoopbackFlag(displayHead);
|
audio.setMixerLoopbackFlag(lookingInMirror);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue