Merge pull request #387 from Ventrella/master

fixes and cleanups in avatar lookat feature
This commit is contained in:
ZappoMan 2013-05-22 15:54:16 -07:00
commit 5a9d3a8436
11 changed files with 157 additions and 160 deletions

View file

@ -1206,12 +1206,17 @@ void Application::initMenu() {
_renderAvatarsOn->setChecked(true);
(_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true);
_renderFrameTimerOn->setChecked(false);
(_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true);
_renderLookatOn->setChecked(false);
renderMenu->addAction("First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P)->setCheckable(true);
(_oculusOn = renderMenu->addAction("Oculus", this, SLOT(setOculus(bool)), Qt::Key_O))->setCheckable(true);
QMenu* toolsMenu = menuBar->addMenu("Tools");
(_renderStatsOn = toolsMenu->addAction("Stats"))->setCheckable(true);
_renderStatsOn->setShortcut(Qt::Key_Slash);
(_logOn = toolsMenu->addAction("Log"))->setCheckable(true);
_logOn->setChecked(true);
@ -1317,6 +1322,7 @@ void Application::init() {
a.tightness = 8.0f;
_myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a);
_myAvatar.setDisplayingHead(true);
_myAvatar.setDisplayingLookatVectors(false);
QCursor::setPos(_headMouseX, _headMouseY);
@ -1695,6 +1701,8 @@ void Application::displaySide(Camera& whichCamera) {
// Render my own Avatar
_myAvatar.render(_lookingInMirror->isChecked(), _myCamera.getPosition());
_myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());
}
// Render the world box

View file

@ -78,6 +78,7 @@ private slots:
void setFullscreen(bool fullscreen);
void setRenderFirstPerson(bool firstPerson);
//void setRenderLookatVectors(bool lookatVectors);
void setOculus(bool oculus);
void setFrustumOffset(bool frustumOffset);
@ -147,6 +148,7 @@ private:
QAction* _oculusOn; // Whether to configure the display for the Oculus Rift
QAction* _renderStatsOn; // Whether to show onscreen text overlay with stats
QAction* _renderFrameTimerOn; // Whether to show onscreen text overlay with stats
QAction* _renderLookatOn; // Whether to show lookat vectors from avatar eyes if looking at something
QAction* _logOn; // Whether to show on-screen log
QActionGroup* _voxelModeActions; // The group of voxel edit mode actions
QAction* _addVoxelMode; // Whether add voxel mode is enabled

View file

@ -53,6 +53,11 @@ const float AVATAR_BRAKING_STRENGTH = 40.0f;
const float JOINT_TOUCH_RANGE = 0.0005f;
const float ANGULAR_RIGHTING_SPEED = 45.0f;
const float LEAN_SENSITIVITY = 0.15;
const float LEAN_MAX = 0.45;
const float LEAN_AVERAGING = 10.0;
const float HEAD_RATE_MAX = 50.f;
float skinColor [] = {1.0, 0.84, 0.66};
float darkSkinColor[] = {0.9, 0.78, 0.63};
float lightBlue [] = {0.7, 0.8, 1.0 };
@ -136,16 +141,12 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa
_head.addRoll (measuredRollRate * deltaTime);
// Update head lean distance based on accelerometer data
const float LEAN_SENSITIVITY = 0.15;
const float LEAN_MAX = 0.45;
const float LEAN_AVERAGING = 10.0;
glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll());
float headRateMax = 50.f;
glm::vec3 leaning = (serialInterface->getLastAcceleration() - serialInterface->getGravity())
* LEAN_SENSITIVITY
* (1.f - fminf(glm::length(headRotationRates), headRateMax) / headRateMax);
* (1.f - fminf(glm::length(headRotationRates), HEAD_RATE_MAX) / HEAD_RATE_MAX);
leaning.y = 0.f;
if (glm::length(leaning) < LEAN_MAX) {
_head.setLeanForward(_head.getLeanForward() * (1.f - LEAN_AVERAGING * deltaTime) +
@ -385,14 +386,15 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_head.setPitch(_head.getPitch() * (1.f - acceleration * ACCELERATION_PITCH_DECAY * deltaTime));
}
//apply the head lean values to the springy position...
if (fabs(_head.getLeanSideways() + _head.getLeanForward()) > 0.0f) {
glm::vec3 headLean =
_orientation.getRight() * _head.getLeanSideways() +
_orientation.getFront() * _head.getLeanForward();
// this is not a long-term solution, but it works ok for initial purposes of making the avatar lean
_joint[ AVATAR_JOINT_TORSO ].springyPosition += headLean * 0.1f;
_joint[ AVATAR_JOINT_CHEST ].springyPosition += headLean * 0.4f;
_joint[ AVATAR_JOINT_NECK_BASE ].springyPosition += headLean * 0.7f;
@ -409,19 +411,17 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_joint[ AVATAR_JOINT_RIGHT_ELBOW ].springyPosition += headLean * 0.2f;
_joint[ AVATAR_JOINT_RIGHT_WRIST ].springyPosition += headLean * 0.1f;
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition += headLean * 0.0f;
}
}
// set head lookat position
if (_interactingOther) {
_head.setLooking(true);
if (_isMine) {
_head.setLookAtPosition(_interactingOther->getSpringyHeadPosition());
}
} else {
_head.setLooking(false);
if (_isMine) {
if (_interactingOther) {
_head.setLookAtPosition(_interactingOther->caclulateAverageEyePosition());
} else {
_head.setLookAtPosition(glm::vec3(0.0f, 0.0f, 0.0f)); // 0,0,0 represents NOT looking at anything
}
}
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setPosition(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition);
_head.setScale (_joint[ AVATAR_JOINT_HEAD_BASE ].radius);
@ -598,15 +598,6 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d
}
}
}
/*
if (jointCollision) {
if (!_usingBodySprings) {
_usingBodySprings = true;
initializeBodySprings();
}
}
*/
}
}
@ -727,9 +718,6 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
otherAvatar->_velocity *= bodyMomentum;
}
void Avatar::setDisplayingHead(bool displayingHead) {
_displayingHead = displayingHead;
}
static TextRenderer* textRenderer() {
static TextRenderer* renderer = new TextRenderer(SANS_FONT_FAMILY, 24, -1, false, TextRenderer::SHADOW_EFFECT);
@ -760,7 +748,7 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
//render body
renderBody(lookingInMirror);
// if this is my avatar, then render my interactions with the other avatar
if (_isMine) {
_avatarTouch.render(_cameraPosition);
@ -1185,16 +1173,6 @@ void Avatar::renderBody(bool lookingInMirror) {
_joint[_joint[j].parent ].radius * 0.8,
_joint[j ].radius * 0.8
);
/*
// Render lines connecting the joint positions
glColor3f(0.4f, 0.5f, 0.6f);
glLineWidth(3.0);
glBegin(GL_LINE_STRIP);
glVertex3fv(&_joint[ _joint[ b ].parent ].springyPosition.x);
glVertex3fv(&_joint[ b ].springyPosition.x);
glEnd();
*/
}
}
}

View file

@ -94,7 +94,7 @@ public:
float getAbsoluteHeadYaw() const;
float getAbsoluteHeadPitch() const;
glm::vec3 getApproximateEyePosition();
glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat)
const glm::vec3& getHeadPosition() const ; // get the position of the avatar's rigid body head
const glm::vec3& getSpringyHeadPosition() const ; // get the springy position of the avatar's head
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].springyPosition; };
@ -113,8 +113,9 @@ public:
void simulate(float deltaTime, Transmitter* transmitter);
void setMovedHandOffset(glm::vec3 movedHandOffset) { _movedHandOffset = movedHandOffset; }
void updateArmIKAndConstraints( float deltaTime );
void setDisplayingHead( bool displayingHead );
void setDisplayingHead( bool displayingHead ) { _displayingHead = displayingHead; }
void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors); }
// 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]; };

View file

@ -37,18 +37,25 @@ Camera::Camera() {
_idealPosition = glm::vec3(0.0, 0.0, 0.0);
_orientation.setToIdentity();
for (int m = 0; m < NUM_CAMERA_MODES; m ++) {
_attributes[m].upShift = 0.0f;
_attributes[m].distance = 0.0f;
_attributes[m].tightness = 0.0f;
_attributes[CAMERA_MODE_FIRST_PERSON].upShift = CAMERA_DEFAULT_FIRST_PERSON_MODE_UP_SHIFT;
_attributes[CAMERA_MODE_FIRST_PERSON].distance = CAMERA_DEFAULT_FIRST_PERSON_MODE_DISTANCE;
_attributes[CAMERA_MODE_FIRST_PERSON].tightness = CAMERA_DEFAULT_FIRST_PERSON_MODE_TIGHTNESS;
_attributes[CAMERA_MODE_THIRD_PERSON].upShift = CAMERA_DEFAULT_THIRD_PERSON_MODE_UP_SHIFT;
_attributes[CAMERA_MODE_THIRD_PERSON].distance = CAMERA_DEFAULT_THIRD_PERSON_MODE_DISTANCE;
_attributes[CAMERA_MODE_THIRD_PERSON].tightness = CAMERA_DEFAULT_THIRD_PERSON_MODE_TIGHTNESS;
_attributes[CAMERA_MODE_MIRROR ].upShift = CAMERA_DEFAULT_MIRROR_MODE_UP_SHIFT;
_attributes[CAMERA_MODE_MIRROR ].distance = CAMERA_DEFAULT_MIRROR_MODE_DISTANCE;
_attributes[CAMERA_MODE_MIRROR ].tightness = CAMERA_DEFAULT_MIRROR_MODE_TIGHTNESS;
for (int m = 0; m < NUM_CAMERA_MODES; m ++) {
_previousAttributes[m].upShift = 0.0f;
_previousAttributes[m].distance = 0.0f;
_previousAttributes[m].tightness = 0.0f;
}
}
void Camera::update(float deltaTime) {
if (_mode != CAMERA_MODE_NULL) {

View file

@ -21,6 +21,19 @@ enum CameraMode
NUM_CAMERA_MODES
};
const float CAMERA_DEFAULT_FIRST_PERSON_MODE_UP_SHIFT = 0.0f;
const float CAMERA_DEFAULT_FIRST_PERSON_MODE_DISTANCE = 0.0f;
const float CAMERA_DEFAULT_FIRST_PERSON_MODE_TIGHTNESS = 100.0f;
const float CAMERA_DEFAULT_THIRD_PERSON_MODE_UP_SHIFT = -0.2f;
const float CAMERA_DEFAULT_THIRD_PERSON_MODE_DISTANCE = 1.5f;
const float CAMERA_DEFAULT_THIRD_PERSON_MODE_TIGHTNESS = 8.0f;
const float CAMERA_DEFAULT_MIRROR_MODE_UP_SHIFT = 0.0f;
const float CAMERA_DEFAULT_MIRROR_MODE_DISTANCE = 0.2f;
const float CAMERA_DEFAULT_MIRROR_MODE_TIGHTNESS = 100.0f;
class Camera
{
public:

View file

@ -7,44 +7,54 @@
#include "Head.h"
#include "Util.h"
#include <vector>
#include <SharedUtil.h>
#include <lodepng.h>
using namespace std;
const float EYE_RIGHT_OFFSET = 0.27f;
const float EYE_UP_OFFSET = 0.38f;
const float EYE_FRONT_OFFSET = 0.8f;
const float EAR_RIGHT_OFFSET = 1.0;
const float MOUTH_FRONT_OFFSET = 1.0f;
const float MOUTH_UP_OFFSET = -0.3f;
const float MINIMUM_EYE_ROTATION = 0.7f; // based on a dot product: 1.0 is straight ahead, 0.0 is 90 degrees off
const float EYEBALL_RADIUS = 0.02;
const float EYEBALL_COLOR[3] = { 0.9f, 0.9f, 0.8f };
const float IRIS_RADIUS = 0.007;
const float IRIS_PROTRUSION = 0.018f;
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
const float EYE_RIGHT_OFFSET = 0.27f;
const float EYE_UP_OFFSET = 0.36f;
const float EYE_FRONT_OFFSET = 0.8f;
const float EAR_RIGHT_OFFSET = 1.0;
const float MOUTH_FRONT_OFFSET = 1.0f;
const float MOUTH_UP_OFFSET = -0.3f;
const float HEAD_MOTION_DECAY = 0.1;
const float MINIMUM_EYE_ROTATION_DOT = 0.5f; // based on a dot product: 1.0 is straight ahead, 0.0 is 90 degrees off
const float EYEBALL_RADIUS = 0.017;
const float EYEBALL_COLOR[3] = { 0.9f, 0.9f, 0.8f };
const float IRIS_RADIUS = 0.007;
const float IRIS_PROTRUSION = 0.0145f;
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
unsigned int IRIS_TEXTURE_WIDTH = 768;
unsigned int IRIS_TEXTURE_HEIGHT = 498;
vector<unsigned char> irisTexture;
Head::Head() :
yawRate(0.0f),
_returnHeadToCenter(false),
_audioLoudness(0.0f),
_skinColor(0.0f, 0.0f, 0.0f),
_position(0.0f, 0.0f, 0.0f),
_rotation(0.0f, 0.0f, 0.0f),
_leftEyePosition(0.0f, 0.0f, 0.0f),
_rightEyePosition(0.0f, 0.0f, 0.0f),
_leftEyeBrowPosition(0.0f, 0.0f, 0.0f),
_rightEyeBrowPosition(0.0f, 0.0f, 0.0f),
_leftEarPosition(0.0f, 0.0f, 0.0f),
_rightEarPosition(0.0f, 0.0f, 0.0f),
_mouthPosition(0.0f, 0.0f, 0.0f),
_scale(1.0f),
_browAudioLift(0.0f),
_lookingAtSomething(false),
_gravity(0.0f, -1.0f, 0.0f),
_lastLoudness(0.0f),
_averageLoudness(0.0f),
_audioAttack(0.0f),
_returnSpringScale(1.0f),
_bodyRotation(0.0f, 0.0f, 0.0f),
_headRotation(0.0f, 0.0f, 0.0f) {
_headRotation(0.0f, 0.0f, 0.0f),
_renderLookatVectors(false) {
}
void Head::reset() {
@ -96,26 +106,27 @@ void Head::simulate(float deltaTime, bool isMine) {
float clamp = 0.01;
if (_browAudioLift > clamp) { _browAudioLift = clamp; }
_browAudioLift *= 0.7f;
_browAudioLift *= 0.7f;
// based on the nature of the lookat position, determine if the eyes can look / are looking at it.
determineIfLookingAtSomething();
}
void Head::determineIfLookingAtSomething() {
void Head::setLooking(bool looking) {
_lookingAtSomething = looking;
glm::vec3 averageEyePosition = _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF;
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - averageEyePosition);
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
if (dot < MINIMUM_EYE_ROTATION) {
if ( fabs(_lookAtPosition.x + _lookAtPosition.y + _lookAtPosition.z) == 0.0 ) { // a lookatPosition of 0,0,0 signifies NOT looking
_lookingAtSomething = false;
} else {
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - caclulateAverageEyePosition());
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
if (dot < MINIMUM_EYE_ROTATION_DOT) { // too far off from center for the eyes to rotate
_lookingAtSomething = false;
} else {
_lookingAtSomething = true;
}
}
}
void Head::calculateGeometry(bool lookingInMirror) {
//generate orientation directions based on Euler angles...
@ -145,6 +156,10 @@ void Head::calculateGeometry(bool lookingInMirror) {
+ _orientation.getUp () * _scale * EYE_UP_OFFSET
+ _orientation.getFront() * _scale * EYE_FRONT_OFFSET;
//calculate the eyebrow positions
_leftEyeBrowPosition = _leftEyePosition;
_rightEyeBrowPosition = _rightEyePosition;
//calculate the ear positions
_leftEarPosition = _position - _orientation.getRight() * _scale * EAR_RIGHT_OFFSET;
_rightEarPosition = _position + _orientation.getRight() * _scale * EAR_RIGHT_OFFSET;
@ -168,12 +183,9 @@ void Head::render(bool lookingInMirror) {
renderMouth();
renderEyeBrows();
/*
if (_lookingAtSomething) {
// Render lines originating from the eyes and converging on the lookatPosition
debugRenderLookatVectors(_leftEyePosition, _rightEyePosition, _lookatPosition);
if (_renderLookatVectors && _lookingAtSomething) {
renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition);
}
*/
}
void Head::renderHeadSphere() {
@ -205,53 +217,33 @@ void Head::renderEars() {
void Head::renderMouth() {
float s = sqrt(_averageLoudness);
float height = _scale * (0.05f + s * 0.0040f );
float width = _scale * (0.30f + s * 0.0014f );
glm::vec3 leftCorner = _mouthPosition;
glm::vec3 rightCorner = _mouthPosition;
glm::vec3 leftTop = _mouthPosition;
glm::vec3 rightTop = _mouthPosition;
glm::vec3 leftBottom = _mouthPosition;
glm::vec3 rightBottom = _mouthPosition;
leftCorner -= _orientation.getRight() * width;
rightCorner += _orientation.getRight() * width;
leftTop -= _orientation.getRight() * width * 0.4f;
rightTop += _orientation.getRight() * width * 0.4f;
leftBottom -= _orientation.getRight() * width * 0.4f;
rightBottom += _orientation.getRight() * width * 0.4f;
leftTop += _orientation.getUp() * height * 0.7f;
rightTop += _orientation.getUp() * height * 0.7f;
leftBottom -= _orientation.getUp() * height;
rightBottom -= _orientation.getUp() * height;
leftTop += _orientation.getFront() * _scale * 0.1f;
rightTop += _orientation.getFront() * _scale * 0.1f;
leftBottom += _orientation.getFront() * _scale * 0.1f;
rightBottom += _orientation.getFront() * _scale * 0.1f;
glm::vec3 r = _orientation.getRight() * _scale * (0.30f + s * 0.0014f );
glm::vec3 u = _orientation.getUp () * _scale * (0.05f + s * 0.0040f );
glm::vec3 f = _orientation.getFront() * _scale * 0.1f;
glm::vec3 leftCorner = _mouthPosition - r * 1.0f;
glm::vec3 rightCorner = _mouthPosition + r * 1.0f;
glm::vec3 leftTop = _mouthPosition - r * 0.4f + u * 0.7f + f;
glm::vec3 rightTop = _mouthPosition + r * 0.4f + u * 0.7f + f;
glm::vec3 leftBottom = _mouthPosition - r * 0.4f - u * 1.0f + f;
glm::vec3 rightBottom = _mouthPosition + r * 0.4f - u * 1.0f + f;
glColor3f(0.2f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(leftCorner.x, leftCorner.y, leftCorner.z);
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z);
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z);
glVertex3f(leftCorner.x, leftCorner.y, leftCorner.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(rightBottom.x, rightBottom.y, rightBottom.z);
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(rightBottom.x, rightBottom.y, rightBottom.z);
glVertex3f(rightCorner.x, rightCorner.y, rightCorner.z);
glEnd();
}
@ -272,48 +264,42 @@ void Head::renderEyeBrows() {
glm::vec3 leftBottom = _leftEyePosition;
glm::vec3 rightBottom = _leftEyePosition;
glm::vec3 r = _orientation.getRight() * length;
glm::vec3 u = _orientation.getUp() * height;
glm::vec3 t = _orientation.getUp() * (height + width);
glm::vec3 f = _orientation.getFront() * _scale * -0.1f;
for (int i = 0; i < 2; i++) {
if ( i == 1 ) {
leftCorner = rightCorner = leftTop = rightTop = leftBottom = rightBottom = _rightEyePosition;
}
leftCorner -= _orientation.getRight() * length;
rightCorner += _orientation.getRight() * length;
leftTop -= _orientation.getRight() * length * 0.4f;
rightTop += _orientation.getRight() * length * 0.4f;
leftBottom -= _orientation.getRight() * length * 0.4f;
rightBottom += _orientation.getRight() * length * 0.4f;
leftCorner -= r * 1.0f;
rightCorner += r * 1.0f;
leftTop -= r * 0.4f;
rightTop += r * 0.4f;
leftBottom -= r * 0.4f;
rightBottom += r * 0.4f;
leftCorner += _orientation.getUp() * height;
rightCorner += _orientation.getUp() * height;
leftTop += _orientation.getUp() * (height + width);
rightTop += _orientation.getUp() * (height + width);
leftBottom += _orientation.getUp() * height;
rightBottom += _orientation.getUp() * height;
leftCorner += _orientation.getFront() * _scale * -0.1f;
rightCorner += _orientation.getFront() * _scale * -0.1f;
leftTop += _orientation.getFront() * _scale * -0.1f;
rightTop += _orientation.getFront() * _scale * -0.1f;
leftBottom += _orientation.getFront() * _scale * -0.1f;
rightBottom += _orientation.getFront() * _scale * -0.1f;
leftCorner += u + f;
rightCorner += u + f;
leftTop += t + f;
rightTop += t + f;
leftBottom += u + f;
rightBottom += u + f;
glBegin(GL_TRIANGLES);
glVertex3f(leftCorner.x, leftCorner.y, leftCorner.z);
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z);
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z);
glVertex3f(leftCorner.x, leftCorner.y, leftCorner.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(leftTop.x, leftTop.y, leftTop.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(leftBottom.x, leftBottom.y, leftBottom.z );
glVertex3f(rightBottom.x, rightBottom.y, rightBottom.z);
glVertex3f(rightTop.x, rightTop.y, rightTop.z );
glVertex3f(rightBottom.x, rightBottom.y, rightBottom.z);
glVertex3f(rightCorner.x, rightCorner.y, rightCorner.z);
@ -356,7 +342,7 @@ void Head::renderEyeBalls() {
glPushMatrix();
//if (_lookingAtSomething) {
if (_lookingAtSomething) {
//rotate the eyeball to aim towards the lookat position
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _leftEyePosition); // the lookat direction
@ -364,7 +350,6 @@ void Head::renderEyeBalls() {
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
glRotatef(180.0, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
/*
} else {
//rotate the eyeball to aim straight ahead
@ -378,7 +363,6 @@ void Head::renderEyeBalls() {
if ( dot < 0.0f ) { rollRotation = -rollRotation; }
glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector
}
*/
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!)
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
@ -402,7 +386,7 @@ void Head::renderEyeBalls() {
glPushMatrix();
//if (_lookingAtSomething) {
if (_lookingAtSomething) {
//rotate the eyeball to aim towards the lookat position
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _rightEyePosition);
@ -410,7 +394,7 @@ void Head::renderEyeBalls() {
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
/*
} else {
//rotate the eyeball to aim straight ahead
@ -424,7 +408,6 @@ void Head::renderEyeBalls() {
if ( dot < 0.0f ) { rollRotation = -rollRotation; }
glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector
}
*/
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!)
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
@ -439,10 +422,10 @@ void Head::renderEyeBalls() {
glPopMatrix();
}
void Head::debugRenderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
glColor3f(0.0f, 0.0f, 0.0f);
glLineWidth(3.0);
glLineWidth(2.0);
glBegin(GL_LINE_STRIP);
glVertex3f(leftEyePosition.x, leftEyePosition.y, leftEyePosition.z);
glVertex3f(lookatPosition.x, lookatPosition.y, lookatPosition.z);

View file

@ -15,6 +15,7 @@
#include "InterfaceConfig.h"
#include "SerialInterface.h"
#include "Orientation.h"
#include <SharedUtil.h>
enum eyeContactTargets
{
@ -31,8 +32,6 @@ public:
void simulate(float deltaTime, bool isMine);
void render(bool lookingInMirror);
void setLooking(bool looking);
void setScale (float scale ) { _scale = scale; }
void setPosition (glm::vec3 position ) { _position = position; }
void setBodyRotation (glm::vec3 bodyRotation ) { _bodyRotation = bodyRotation; }
@ -43,9 +42,11 @@ public:
void setAverageLoudness(float averageLoudness ) { _averageLoudness = averageLoudness; }
void setAudioLoudness (float audioLoudness ) { _audioLoudness = audioLoudness; }
void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; }
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
float getAverageLoudness() {return _averageLoudness;};
glm::vec3 caclulateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; }
float yawRate;
float noise;
@ -59,6 +60,8 @@ private:
glm::vec3 _rotation;
glm::vec3 _leftEyePosition;
glm::vec3 _rightEyePosition;
glm::vec3 _leftEyeBrowPosition;
glm::vec3 _rightEyeBrowPosition;
glm::vec3 _leftEarPosition;
glm::vec3 _rightEarPosition;
glm::vec3 _mouthPosition;
@ -73,6 +76,7 @@ private:
Orientation _orientation;
glm::vec3 _bodyRotation;
glm::vec3 _headRotation;
bool _renderLookatVectors;
// private methods
void renderHeadSphere();
@ -80,9 +84,9 @@ private:
void renderEyeBrows();
void renderEars();
void renderMouth();
void debugRenderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition);
void updateEyePositions();
void renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition);
void calculateGeometry( bool lookingInMirror);
void determineIfLookingAtSomething();
};
#endif

View file

@ -97,7 +97,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
// Lookat Position
memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition));
destinationBuffer += sizeof(_headData->_lookAtPosition);
// Hand State (0 = not grabbing, 1 = grabbing)
memcpy(destinationBuffer, &_handState, sizeof(char));
destinationBuffer += sizeof(char);
@ -191,7 +191,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
// Lookat Position
memcpy(&_headData->_lookAtPosition, sourceBuffer, sizeof(_headData->_lookAtPosition));
sourceBuffer += sizeof(_headData->_lookAtPosition);
// Hand State
memcpy(&_handState, sourceBuffer, sizeof(char));
sourceBuffer += sizeof(char);

View file

@ -31,6 +31,7 @@ void HeadData::addRoll(float roll) {
setRoll(_roll + roll);
}
void HeadData::addLean(float sideways, float forwards) {
// Add lean as impulse
_leanSideways += sideways;

0
libraries/avatars/src/Orientation.h Executable file → Normal file
View file