remove unused mohawk and hair physics

This commit is contained in:
Philip Rosedale 2014-01-02 17:12:34 -08:00
parent 2ad3aea729
commit 3fe972791c
4 changed files with 2 additions and 311 deletions

View file

@ -1,119 +0,0 @@
//
// BendyLine.cpp
// interface
//
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
#include "BendyLine.h"
#include "Util.h"
#include "world.h"
const float DEFAULT_BENDY_LINE_SPRING_FORCE = 10.0f;
const float DEFAULT_BENDY_LINE_TORQUE_FORCE = 0.1f;
const float DEFAULT_BENDY_LINE_DRAG = 10.0f;
const float DEFAULT_BENDY_LINE_LENGTH = 0.09f;
const float DEFAULT_BENDY_LINE_THICKNESS = 0.03f;
BendyLine::BendyLine(){
_springForce = DEFAULT_BENDY_LINE_SPRING_FORCE;
_torqueForce = DEFAULT_BENDY_LINE_TORQUE_FORCE;
_drag = DEFAULT_BENDY_LINE_DRAG;
_length = DEFAULT_BENDY_LINE_LENGTH;
_thickness = DEFAULT_BENDY_LINE_THICKNESS;
_gravityForce = glm::vec3(0.0f, 0.0f, 0.0f);
_basePosition = glm::vec3(0.0f, 0.0f, 0.0f);
_baseDirection = glm::vec3(0.0f, 1.0f, 0.0f);
_midPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_endPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
_endVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
}
void BendyLine::reset() {
_midPosition = _basePosition + _baseDirection * _length * ONE_HALF;
_endPosition = _midPosition + _baseDirection * _length * ONE_HALF;
_midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
_endVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
}
void BendyLine::update(float deltaTime) {
glm::vec3 midAxis = _midPosition - _basePosition;
glm::vec3 endAxis = _endPosition - _midPosition;
float midLength = glm::length(midAxis);
float endLength = glm::length(endAxis);
glm::vec3 midDirection;
glm::vec3 endDirection;
if (midLength > 0.0f) {
midDirection = midAxis / midLength;
} else {
midDirection = _baseDirection;
}
if (endLength > 0.0f) {
endDirection = endAxis / endLength;
} else {
endDirection = _baseDirection;
}
// add spring force
float midForce = midLength - _length * ONE_HALF;
float endForce = endLength - _length * ONE_HALF;
_midVelocity -= midDirection * midForce * _springForce * deltaTime;
_endVelocity -= endDirection * endForce * _springForce * deltaTime;
// add gravity force
_midVelocity += _gravityForce;
_endVelocity += _gravityForce;
// add torque force
_midVelocity += _baseDirection * _torqueForce * deltaTime;
_endVelocity += midDirection * _torqueForce * deltaTime;
// add drag force
float momentum = 1.0f - (_drag * deltaTime);
if (momentum < 0.0f) {
_midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
_endVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
} else {
_midVelocity *= momentum;
_endVelocity *= momentum;
}
// update position by velocity
_midPosition += _midVelocity;
_endPosition += _endVelocity;
// clamp lengths
glm::vec3 newMidVector = _midPosition - _basePosition;
glm::vec3 newEndVector = _endPosition - _midPosition;
float newMidLength = glm::length(newMidVector);
float newEndLength = glm::length(newEndVector);
glm::vec3 newMidDirection;
glm::vec3 newEndDirection;
if (newMidLength > 0.0f) {
newMidDirection = newMidVector/newMidLength;
} else {
newMidDirection = _baseDirection;
}
if (newEndLength > 0.0f) {
newEndDirection = newEndVector/newEndLength;
} else {
newEndDirection = _baseDirection;
}
_endPosition = _midPosition + newEndDirection * _length * ONE_HALF;
_midPosition = _basePosition + newMidDirection * _length * ONE_HALF;
}

View file

@ -1,52 +0,0 @@
//
// BendyLine.h
// interface
//
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef hifi_bendyLine_h
#define hifi_bendyLine_h
#include <SharedUtil.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
class BendyLine {
public:
BendyLine();
void update(float deltaTime);
void reset();
void setLength (float length ) { _length = length; }
void setThickness (float thickness ) { _thickness = thickness; }
void setSpringForce (float springForce ) { _springForce = springForce; }
void setTorqueForce (float torqueForce ) { _torqueForce = torqueForce; }
void setDrag (float drag ) { _drag = drag; }
void setBasePosition (glm::vec3 basePosition ) { _basePosition = basePosition; }
void setBaseDirection(glm::vec3 baseDirection) { _baseDirection = baseDirection;}
void setGravityForce (glm::vec3 gravityForce ) { _gravityForce = gravityForce; }
glm::vec3 getBasePosition() { return _basePosition; }
glm::vec3 getMidPosition () { return _midPosition; }
glm::vec3 getEndPosition () { return _endPosition; }
float getThickness () { return _thickness; }
private:
float _springForce;
float _torqueForce;
float _drag;
float _length;
float _thickness;
glm::vec3 _gravityForce;
glm::vec3 _basePosition;
glm::vec3 _baseDirection;
glm::vec3 _midPosition;
glm::vec3 _endPosition;
glm::vec3 _midVelocity;
glm::vec3 _endVelocity;
};
#endif

View file

@ -17,7 +17,6 @@
using namespace std;
const bool USING_PHYSICAL_MOHAWK = true;
const float EYE_RIGHT_OFFSET = 0.27f;
const float EYE_UP_OFFSET = 0.36f;
const float EYE_FRONT_OFFSET = 0.8f;
@ -73,7 +72,6 @@ Head::Head(Avatar* owningAvatar) :
_bodyRotation(0.0f, 0.0f, 0.0f),
_angularVelocity(0,0,0),
_renderLookatVectors(false),
_mohawkInitialized(false),
_saccade(0.0f, 0.0f, 0.0f),
_saccadeTarget(0.0f, 0.0f, 0.0f),
_leftEyeBlinkVelocity(0.0f),
@ -86,9 +84,7 @@ Head::Head(Avatar* owningAvatar) :
_videoFace(this),
_faceModel(this)
{
if (USING_PHYSICAL_MOHAWK) {
resetHairPhysics();
}
}
void Head::init() {
@ -111,29 +107,10 @@ void Head::reset() {
_yaw = _pitch = _roll = 0.0f;
_mousePitch = 0.0f;
_leanForward = _leanSideways = 0.0f;
if (USING_PHYSICAL_MOHAWK) {
resetHairPhysics();
}
_faceModel.reset();
}
void Head::resetHairPhysics() {
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
_hairTuft[t].setSpringForce (HAIR_SPRING_FORCE);
_hairTuft[t].setTorqueForce (HAIR_TORQUE_FORCE);
_hairTuft[t].setGravityForce (HAIR_GRAVITY_FORCE * _gravity);
_hairTuft[t].setDrag (HAIR_DRAG);
_hairTuft[t].setLength (_scale * HAIR_LENGTH );
_hairTuft[t].setThickness (_scale * HAIR_THICKNESS);
_hairTuft[t].setBaseDirection(getUpDirection());
_hairTuft[t].reset();
}
}
}
void Head::simulate(float deltaTime, bool isMine) {
@ -240,11 +217,6 @@ void Head::simulate(float deltaTime, bool isMine) {
glm::clamp(sqrt(_averageLoudness * JAW_OPEN_SCALE) - JAW_OPEN_DEAD_ZONE, 0.0f, 1.0f), _blendshapeCoefficients);
}
// based on the nature of the lookat position, determine if the eyes can look / are looking at it.
if (USING_PHYSICAL_MOHAWK) {
updateHairPhysics(deltaTime);
}
_faceModel.simulate(deltaTime);
calculateGeometry();
@ -304,7 +276,6 @@ void Head::render(float alpha, bool renderAvatarBalls) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_RESCALE_NORMAL);
renderMohawk();
renderHeadSphere();
renderEyeBalls();
renderEars();
@ -326,16 +297,6 @@ void Head::setScale (float scale) {
return;
}
_scale = scale;
createMohawk();
if (USING_PHYSICAL_MOHAWK) {
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
_hairTuft[t].setLength (_scale * HAIR_LENGTH );
_hairTuft[t].setThickness(_scale * HAIR_THICKNESS);
}
}
}
void Head::setMousePitch(float mousePitch) {
@ -343,79 +304,7 @@ void Head::setMousePitch(float mousePitch) {
_mousePitch = glm::clamp(mousePitch, -MAX_PITCH, MAX_PITCH);
}
void Head::createMohawk() {
srand(time(NULL));
float height = _scale * (0.08f + randFloat() * 0.05f);
float variance = 0.03 + randFloat() * 0.03f;
const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES;
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
_mohawkColors[0] = basicColor;
for (int i = 1; i < MOHAWK_TRIANGLES; i++) {
_mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance,
height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f)
+ (randFloat() - 0.5f) * variance,
height * sinf(i * RAD_PER_TRIANGLE - PIf / 2.f)
+ (randFloat() - 0.5f) * variance);
_mohawkColors[i] = randFloat() * basicColor;
}
}
void Head::renderMohawk() {
if (!_mohawkInitialized) {
createMohawk();
_mohawkInitialized = true;
}
if (USING_PHYSICAL_MOHAWK) {
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
glm::vec3 baseAxis = _hairTuft[t].getMidPosition() - _hairTuft[t].getBasePosition();
glm::vec3 midAxis = _hairTuft[t].getEndPosition() - _hairTuft[t].getMidPosition();
glm::vec3 viewVector = _hairTuft[t].getBasePosition() - Application::getInstance()->getCamera()->getPosition();
glm::vec3 basePerpendicular = glm::normalize(glm::cross(baseAxis, viewVector));
glm::vec3 midPerpendicular = glm::normalize(glm::cross(midAxis, viewVector));
glm::vec3 base1 = _hairTuft[t].getBasePosition() - basePerpendicular * _hairTuft[t].getThickness() * ONE_HALF;
glm::vec3 base2 = _hairTuft[t].getBasePosition() + basePerpendicular * _hairTuft[t].getThickness() * ONE_HALF;
glm::vec3 mid1 = _hairTuft[t].getMidPosition() - midPerpendicular * _hairTuft[t].getThickness() * ONE_HALF * ONE_HALF;
glm::vec3 mid2 = _hairTuft[t].getMidPosition() + midPerpendicular * _hairTuft[t].getThickness() * ONE_HALF * ONE_HALF;
glColor3f(_mohawkColors[t].x, _mohawkColors[t].y, _mohawkColors[t].z);
glBegin(GL_TRIANGLES);
glVertex3f(base1.x, base1.y, base1.z );
glVertex3f(base2.x, base2.y, base2.z );
glVertex3f(mid1.x, mid1.y, mid1.z );
glVertex3f(base2.x, base2.y, base2.z );
glVertex3f(mid1.x, mid1.y, mid1.z );
glVertex3f(mid2.x, mid2.y, mid2.z );
glVertex3f(mid1.x, mid1.y, mid1.z );
glVertex3f(mid2.x, mid2.y, mid2.z );
glVertex3f(_hairTuft[t].getEndPosition().x, _hairTuft[t].getEndPosition().y, _hairTuft[t].getEndPosition().z );
glEnd();
}
} else {
glPushMatrix();
glTranslatef(_position.x, _position.y, _position.z);
glRotatef(_bodyRotation.y + _yaw, 0, 1, 0);
glRotatef(-_roll, 0, 0, 1);
glRotatef(-_pitch - _bodyRotation.x, 1, 0, 0);
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < MOHAWK_TRIANGLES; i++) {
glColor3f(_mohawkColors[i].x, _mohawkColors[i].y, _mohawkColors[i].z);
glVertex3fv(&_mohawkTriangleFan[i].x);
glNormal3fv(&_mohawkColors[i].x);
}
glEnd();
glPopMatrix();
}
}
glm::quat Head::getOrientation() const {
return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(glm::vec3(_pitch, _yaw, _roll)));
@ -750,19 +639,4 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi
Application::getInstance()->getGlowEffect()->end();
}
void Head::updateHairPhysics(float deltaTime) {
glm::quat orientation = getOrientation();
glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 front = orientation * IDENTITY_FRONT;
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
float fraction = (float)t / (float)(NUM_HAIR_TUFTS - 1);
float angle = -20.0f + 40.0f * fraction;
float radian = angle * PI_OVER_180;
glm::vec3 baseDirection = front * sinf(radian) + up * cosf(radian);
_hairTuft[t].setBasePosition (_position + _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f * baseDirection);
_hairTuft[t].setBaseDirection(baseDirection);
_hairTuft[t].update(deltaTime);
}
}

View file

@ -17,7 +17,6 @@
#include <VoxelConstants.h>
#include "BendyLine.h"
#include "FaceModel.h"
#include "InterfaceConfig.h"
#include "VideoFace.h"
@ -31,9 +30,6 @@ enum eyeContactTargets {
MOUTH
};
const int MOHAWK_TRIANGLES = 50;
const int NUM_HAIR_TUFTS = 4;
class Avatar;
class ProgramObject;
@ -45,8 +41,6 @@ public:
void reset();
void simulate(float deltaTime, bool isMine);
void render(float alpha, bool renderAvatarBalls);
void renderMohawk();
void setScale(float scale);
void setPosition(glm::vec3 position) { _position = position; }
void setBodyRotation(glm::vec3 bodyRotation) { _bodyRotation = bodyRotation; }
@ -122,10 +116,7 @@ private:
glm::vec3 _bodyRotation;
glm::vec3 _angularVelocity;
bool _renderLookatVectors;
BendyLine _hairTuft[NUM_HAIR_TUFTS];
bool _mohawkInitialized;
glm::vec3 _mohawkTriangleFan[MOHAWK_TRIANGLES];
glm::vec3 _mohawkColors[MOHAWK_TRIANGLES];
//BendyLine _hairTuft[NUM_HAIR_TUFTS];
glm::vec3 _saccade;
glm::vec3 _saccadeTarget;
float _leftEyeBlinkVelocity;
@ -145,7 +136,6 @@ private:
static int _eyePositionLocation;
// private methods
void createMohawk();
void renderHeadSphere();
void renderEyeBalls();
void renderEyeBrows();
@ -154,8 +144,6 @@ private:
void renderMouth();
void renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition);
void calculateGeometry();
void resetHairPhysics();
void updateHairPhysics(float deltaTime);
friend class FaceModel;
};