mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 07:10:06 +02:00
Merge pull request #297 from Ventrella/master
added code to allow mouse hover over avatar to be used for touch effects
This commit is contained in:
commit
d386221620
5 changed files with 187 additions and 307 deletions
|
@ -49,36 +49,17 @@ const float HEAD_MAX_YAW = 85;
|
||||||
const float HEAD_MIN_YAW = -85;
|
const float HEAD_MIN_YAW = -85;
|
||||||
const float AVATAR_BRAKING_RANGE = 1.6f;
|
const float AVATAR_BRAKING_RANGE = 1.6f;
|
||||||
const float AVATAR_BRAKING_STRENGTH = 30.0f;
|
const float AVATAR_BRAKING_STRENGTH = 30.0f;
|
||||||
|
//const float MAX_JOINT_TOUCH_DOT = 0.995f;
|
||||||
|
const float JOINT_TOUCH_RANGE = 0.0005f;
|
||||||
|
|
||||||
float skinColor [] = {1.0, 0.84, 0.66};
|
float skinColor [] = {1.0, 0.84, 0.66};
|
||||||
float lightBlue [] = {0.7, 0.8, 1.0};
|
float lightBlue [] = {0.7, 0.8, 1.0};
|
||||||
|
|
||||||
/*
|
|
||||||
float browColor [] = {210.0/255.0, 105.0/255.0, 30.0/255.0};
|
|
||||||
float mouthColor[] = {1, 0, 0};
|
|
||||||
|
|
||||||
float BrowRollAngle [5] = {0, 15, 30, -30, -15};
|
|
||||||
float BrowPitchAngle[3] = {-70, -60, -50};
|
|
||||||
float eyeColor [3] = {1,1,1};
|
|
||||||
|
|
||||||
float MouthWidthChoices[3] = {0.5, 0.77, 0.3};
|
|
||||||
|
|
||||||
float browWidth = 0.8;
|
|
||||||
float browThickness = 0.16;
|
|
||||||
|
|
||||||
|
|
||||||
//char iris_texture_file[] = "resources/images/green_eye.png";
|
|
||||||
*/
|
|
||||||
bool usingBigSphereCollisionTest = true;
|
bool usingBigSphereCollisionTest = true;
|
||||||
|
|
||||||
float chatMessageScale = 0.0015;
|
float chatMessageScale = 0.0015;
|
||||||
float chatMessageHeight = 0.45;
|
float chatMessageHeight = 0.45;
|
||||||
|
|
||||||
/*
|
|
||||||
vector<unsigned char> iris_texture;
|
|
||||||
unsigned int iris_texture_width = 512;
|
|
||||||
unsigned int iris_texture_height = 256;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Avatar::Avatar(bool isMine) {
|
Avatar::Avatar(bool isMine) {
|
||||||
|
|
||||||
|
@ -106,6 +87,9 @@ Avatar::Avatar(bool isMine) {
|
||||||
_displayingHead = true;
|
_displayingHead = true;
|
||||||
_TEST_bigSphereRadius = 0.4f;
|
_TEST_bigSphereRadius = 0.4f;
|
||||||
_TEST_bigSpherePosition = glm::vec3(5.0f, _TEST_bigSphereRadius, 5.0f);
|
_TEST_bigSpherePosition = glm::vec3(5.0f, _TEST_bigSphereRadius, 5.0f);
|
||||||
|
_mouseRayOrigin = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
_mouseRayDirection = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
_cameraPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false;
|
for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false;
|
||||||
|
|
||||||
|
@ -123,16 +107,6 @@ Avatar::Avatar(bool isMine) {
|
||||||
|
|
||||||
_avatarTouch.setReachableRadius(0.6);
|
_avatarTouch.setReachableRadius(0.6);
|
||||||
|
|
||||||
/*
|
|
||||||
if (iris_texture.size() == 0) {
|
|
||||||
switchToResourcesParentIfRequired();
|
|
||||||
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
|
|
||||||
if (error != 0) {
|
|
||||||
printLog("error %u: %s\n", error, lodepng_error_text(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (BALLS_ON) { _balls = new Balls(100); }
|
if (BALLS_ON) { _balls = new Balls(100); }
|
||||||
else { _balls = NULL; }
|
else { _balls = NULL; }
|
||||||
}
|
}
|
||||||
|
@ -319,6 +293,9 @@ bool Avatar::getIsNearInteractingOther() {
|
||||||
|
|
||||||
void Avatar::simulate(float deltaTime) {
|
void Avatar::simulate(float deltaTime) {
|
||||||
|
|
||||||
|
//figure out if the mouse cursor is over any body spheres...
|
||||||
|
checkForMouseRayTouching();
|
||||||
|
|
||||||
// update balls
|
// update balls
|
||||||
if (_balls) { _balls->simulate(deltaTime); }
|
if (_balls) { _balls->simulate(deltaTime); }
|
||||||
|
|
||||||
|
@ -481,6 +458,30 @@ void Avatar::simulate(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Avatar::checkForMouseRayTouching() {
|
||||||
|
|
||||||
|
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||||
|
|
||||||
|
glm::vec3 directionToBodySphere = glm::normalize(_joint[b].springyPosition - _mouseRayOrigin);
|
||||||
|
float dot = glm::dot(directionToBodySphere, _mouseRayDirection);
|
||||||
|
|
||||||
|
if (dot > (1.0f - JOINT_TOUCH_RANGE)) {
|
||||||
|
_joint[b].touchForce = (dot - (1.0f - JOINT_TOUCH_RANGE)) / JOINT_TOUCH_RANGE;
|
||||||
|
} else {
|
||||||
|
_joint[b].touchForce = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction ) {
|
||||||
|
_mouseRayOrigin = origin; _mouseRayDirection = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
||||||
|
|
||||||
// reset hand and arm positions according to hand movement
|
// reset hand and arm positions according to hand movement
|
||||||
|
@ -491,8 +492,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
||||||
|
|
||||||
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
|
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
|
||||||
|
|
||||||
if (_isMine)
|
if (_isMine) {
|
||||||
{
|
|
||||||
_avatarTouch.setMyBodyPosition(_position);
|
_avatarTouch.setMyBodyPosition(_position);
|
||||||
|
|
||||||
Avatar * _interactingOther = NULL;
|
Avatar * _interactingOther = NULL;
|
||||||
|
@ -853,6 +853,8 @@ void Avatar::setGravity(glm::vec3 gravity) {
|
||||||
|
|
||||||
void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
|
void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
|
||||||
|
|
||||||
|
_cameraPosition = cameraPosition; // store this for use in various parts of the code
|
||||||
|
|
||||||
// render a simple round on the ground projected down from the avatar's position
|
// render a simple round on the ground projected down from the avatar's position
|
||||||
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f);
|
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f);
|
||||||
|
|
||||||
|
@ -877,16 +879,18 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//render body
|
//render body
|
||||||
renderBody();
|
renderBody(lookingInMirror);
|
||||||
|
|
||||||
|
/*
|
||||||
// render head
|
// render head
|
||||||
if (_displayingHead) {
|
if (_displayingHead) {
|
||||||
_head.render(lookingInMirror, _bodyYaw);
|
_head.render(lookingInMirror, _bodyYaw);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// if this is my avatar, then render my interactions with the other avatar
|
// if this is my avatar, then render my interactions with the other avatar
|
||||||
if (_isMine) {
|
if (_isMine) {
|
||||||
_avatarTouch.render(cameraPosition);
|
_avatarTouch.render(_cameraPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the balls
|
// Render the balls
|
||||||
|
@ -941,180 +945,6 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Avatar::renderHead(bool lookingInMirror) {
|
|
||||||
/*
|
|
||||||
int side = 0;
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_RESCALE_NORMAL);
|
|
||||||
|
|
||||||
// show head orientation
|
|
||||||
//renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f);
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
glTranslatef(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.x,
|
|
||||||
_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.y,
|
|
||||||
_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition.z);
|
|
||||||
|
|
||||||
glScalef
|
|
||||||
(
|
|
||||||
_joint[ AVATAR_JOINT_HEAD_BASE ].radius,
|
|
||||||
_joint[ AVATAR_JOINT_HEAD_BASE ].radius,
|
|
||||||
_joint[ AVATAR_JOINT_HEAD_BASE ].radius
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if (lookingInMirror) {
|
|
||||||
glRotatef(_bodyYaw - _headYaw, 0, 1, 0);
|
|
||||||
//glRotatef(_bodyPitch + _headPitch, 1, 0, 0);
|
|
||||||
//glRotatef(_bodyRoll - _headRoll, 0, 0, 1);
|
|
||||||
// don't let body pitch and roll affect the head..
|
|
||||||
glRotatef(_headPitch, 1, 0, 0);
|
|
||||||
glRotatef(-_headRoll, 0, 0, 1);
|
|
||||||
} else {
|
|
||||||
glRotatef(_bodyYaw + _headYaw, 0, 1, 0);
|
|
||||||
//glRotatef(_bodyPitch + _headPitch, 1, 0, 0);
|
|
||||||
//glRotatef(_bodyRoll + _headRoll, 0, 0, 1);
|
|
||||||
// don't let body pitch and roll affect the head..
|
|
||||||
glRotatef(_headPitch, 1, 0, 0);
|
|
||||||
glRotatef(_headRoll, 0, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//glScalef(2.0, 2.0, 2.0);
|
|
||||||
glColor3fv(skinColor);
|
|
||||||
|
|
||||||
glutSolidSphere(1, 30, 30);
|
|
||||||
|
|
||||||
// Ears
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(1.0, 0, 0);
|
|
||||||
for(side = 0; side < 2; side++) {
|
|
||||||
glPushMatrix();
|
|
||||||
glScalef(0.3, 0.65, .65);
|
|
||||||
glutSolidSphere(0.5, 30, 30);
|
|
||||||
glPopMatrix();
|
|
||||||
glTranslatef(-2.0, 0, 0);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
|
|
||||||
// Update audio attack data for facial animation (eyebrows and mouth)
|
|
||||||
_head.audioAttack = 0.9 * _head.audioAttack + 0.1 * fabs(_audioLoudness - _head.lastLoudness);
|
|
||||||
_head.lastLoudness = _audioLoudness;
|
|
||||||
|
|
||||||
|
|
||||||
const float BROW_LIFT_THRESHOLD = 100;
|
|
||||||
if (_head.audioAttack > BROW_LIFT_THRESHOLD)
|
|
||||||
_head.browAudioLift += sqrt(_head.audioAttack) / 1000.0;
|
|
||||||
|
|
||||||
_head.browAudioLift *= .90;
|
|
||||||
|
|
||||||
|
|
||||||
// Render Eyebrows
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(-_head.interBrowDistance / 2.0,0.4,0.45);
|
|
||||||
for(side = 0; side < 2; side++) {
|
|
||||||
glColor3fv(browColor);
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(0, 0.35 + _head.browAudioLift, 0);
|
|
||||||
glRotatef(_head.eyebrowPitch[side]/2.0, 1, 0, 0);
|
|
||||||
glRotatef(_head.eyebrowRoll[side]/2.0, 0, 0, 1);
|
|
||||||
glScalef(browWidth, browThickness, 1);
|
|
||||||
glutSolidCube(0.5);
|
|
||||||
glPopMatrix();
|
|
||||||
glTranslatef(_head.interBrowDistance, 0, 0);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
// Mouth
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(0,-0.35,0.75);
|
|
||||||
glColor3f(0,0,0);
|
|
||||||
glRotatef(_head.mouthPitch, 1, 0, 0);
|
|
||||||
glRotatef(_head.mouthYaw, 0, 0, 1);
|
|
||||||
if (_head.averageLoudness > 1.f) {
|
|
||||||
glScalef(_head.mouthWidth * (.7f + sqrt(_head.averageLoudness) /60.f),
|
|
||||||
_head.mouthHeight * (1.f + sqrt(_head.averageLoudness) /30.f), 1);
|
|
||||||
} else {
|
|
||||||
glScalef(_head.mouthWidth, _head.mouthHeight, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
glutSolidCube(0.5);
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
glTranslatef(0, 1.0, 0);
|
|
||||||
|
|
||||||
glTranslatef(-_head.interPupilDistance/2.0,-0.68,0.7);
|
|
||||||
// Right Eye
|
|
||||||
glRotatef(-10, 1, 0, 0);
|
|
||||||
glColor3fv(eyeColor);
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glTranslatef(_head.interPupilDistance/10.0, 0, 0.05);
|
|
||||||
glRotatef(20, 0, 0, 1);
|
|
||||||
glScalef(_head.eyeballScaleX, _head.eyeballScaleY, _head.eyeballScaleZ);
|
|
||||||
glutSolidSphere(0.25, 30, 30);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
// Right Pupil
|
|
||||||
if (_sphere == NULL) {
|
|
||||||
_sphere = gluNewQuadric();
|
|
||||||
gluQuadricTexture(_sphere, GL_TRUE);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
gluQuadricOrientation(_sphere, GLU_OUTSIDE);
|
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iris_texture_width, iris_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &iris_texture[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glRotatef(_head.eyeballPitch[1], 1, 0, 0);
|
|
||||||
glRotatef(_head.eyeballYaw[1] + _headYaw + _head.pupilConverge, 0, 1, 0);
|
|
||||||
glTranslatef(0,0,.35);
|
|
||||||
glRotatef(-75,1,0,0);
|
|
||||||
glScalef(1.0, 0.4, 1.0);
|
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
gluSphere(_sphere, _head.pupilSize, 15, 15);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
// Left Eye
|
|
||||||
glColor3fv(eyeColor);
|
|
||||||
glTranslatef(_head.interPupilDistance, 0, 0);
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glTranslatef(-_head.interPupilDistance/10.0, 0, .05);
|
|
||||||
glRotatef(-20, 0, 0, 1);
|
|
||||||
glScalef(_head.eyeballScaleX, _head.eyeballScaleY, _head.eyeballScaleZ);
|
|
||||||
glutSolidSphere(0.25, 30, 30);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
// Left Pupil
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glRotatef(_head.eyeballPitch[0], 1, 0, 0);
|
|
||||||
glRotatef(_head.eyeballYaw[0] + _headYaw - _head.pupilConverge, 0, 1, 0);
|
|
||||||
glTranslatef(0, 0, .35);
|
|
||||||
glRotatef(-75, 1, 0, 0);
|
|
||||||
glScalef(1.0, 0.4, 1.0);
|
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
gluSphere(_sphere, _head.pupilSize, 15, 15);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Avatar::setHandMovementValues(glm::vec3 handOffset) {
|
void Avatar::setHandMovementValues(glm::vec3 handOffset) {
|
||||||
_movedHandOffset = handOffset;
|
_movedHandOffset = handOffset;
|
||||||
}
|
}
|
||||||
|
@ -1138,6 +968,7 @@ void Avatar::initializeSkeleton() {
|
||||||
_joint[b].roll = 0.0;
|
_joint[b].roll = 0.0;
|
||||||
_joint[b].length = 0.0;
|
_joint[b].length = 0.0;
|
||||||
_joint[b].radius = 0.0;
|
_joint[b].radius = 0.0;
|
||||||
|
_joint[b].touchForce = 0.0;
|
||||||
_joint[b].springBodyTightness = BODY_SPRING_DEFAULT_TIGHTNESS;
|
_joint[b].springBodyTightness = BODY_SPRING_DEFAULT_TIGHTNESS;
|
||||||
_joint[b].orientation.setToIdentity();
|
_joint[b].orientation.setToIdentity();
|
||||||
}
|
}
|
||||||
|
@ -1373,10 +1204,11 @@ void Avatar::updateBodySprings(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply tightness force - (causing springy position to be close to rigid body position)
|
||||||
_joint[b].springyVelocity += (_joint[b].position - _joint[b].springyPosition) * _joint[b].springBodyTightness * deltaTime;
|
_joint[b].springyVelocity += (_joint[b].position - _joint[b].springyPosition) * _joint[b].springBodyTightness * deltaTime;
|
||||||
|
|
||||||
|
// apply decay
|
||||||
float decay = 1.0 - BODY_SPRING_DECAY * deltaTime;
|
float decay = 1.0 - BODY_SPRING_DECAY * deltaTime;
|
||||||
|
|
||||||
if (decay > 0.0) {
|
if (decay > 0.0) {
|
||||||
_joint[b].springyVelocity *= decay;
|
_joint[b].springyVelocity *= decay;
|
||||||
}
|
}
|
||||||
|
@ -1384,20 +1216,25 @@ void Avatar::updateBodySprings(float deltaTime) {
|
||||||
_joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
_joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//apply forces from touch...
|
||||||
|
if (_joint[b].touchForce > 0.0) {
|
||||||
|
_joint[b].springyVelocity += _mouseRayDirection * _joint[b].touchForce * 0.7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update position by velocity...
|
||||||
_joint[b].springyPosition += _joint[b].springyVelocity * deltaTime;
|
_joint[b].springyPosition += _joint[b].springyVelocity * deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3& Avatar::getHeadPosition() const {
|
|
||||||
|
|
||||||
|
|
||||||
//if (_usingBodySprings) {
|
|
||||||
// return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
const glm::vec3& Avatar::getSpringyHeadPosition() const {
|
||||||
return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;
|
return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const glm::vec3& Avatar::getHeadPosition() const {
|
||||||
|
return _joint[ AVATAR_JOINT_HEAD_BASE ].position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Avatar::updateArmIKAndConstraints(float deltaTime) {
|
void Avatar::updateArmIKAndConstraints(float deltaTime) {
|
||||||
|
@ -1438,12 +1275,16 @@ void Avatar::updateArmIKAndConstraints(float deltaTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Avatar::renderBody() {
|
void Avatar::renderBody(bool lookingInMirror) {
|
||||||
|
|
||||||
// Render joint positions as spheres
|
// Render joint positions as spheres
|
||||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||||
|
|
||||||
if (b != AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case in "renderHead"
|
if (b == AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case
|
||||||
|
if (_displayingHead) {
|
||||||
|
_head.render(lookingInMirror, _bodyYaw);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
//show direction vectors of the bone orientation
|
//show direction vectors of the bone orientation
|
||||||
//renderOrientationDirections(_joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0);
|
//renderOrientationDirections(_joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0);
|
||||||
|
@ -1454,6 +1295,18 @@ void Avatar::renderBody() {
|
||||||
glutSolidSphere(_joint[b].radius, 20.0f, 20.0f);
|
glutSolidSphere(_joint[b].radius, 20.0f, 20.0f);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_joint[b].touchForce > 0.0f) {
|
||||||
|
|
||||||
|
float alpha = _joint[b].touchForce * 0.2;
|
||||||
|
float r = _joint[b].radius * 1.1f + 0.005f;
|
||||||
|
glColor4f(0.5f, 0.2f, 0.2f, alpha);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z);
|
||||||
|
glScalef(r, r, r);
|
||||||
|
glutSolidSphere(1, 20, 20);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render lines connecting the joint positions
|
// Render lines connecting the joint positions
|
||||||
|
|
|
@ -92,6 +92,7 @@ public:
|
||||||
void addBodyYaw(float y) {_bodyYaw += y;};
|
void addBodyYaw(float y) {_bodyYaw += y;};
|
||||||
void setGravity(glm::vec3 gravity);
|
void setGravity(glm::vec3 gravity);
|
||||||
|
|
||||||
|
void setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction );
|
||||||
bool getIsNearInteractingOther();
|
bool getIsNearInteractingOther();
|
||||||
|
|
||||||
float getAbsoluteHeadYaw() const;
|
float getAbsoluteHeadYaw() const;
|
||||||
|
@ -99,11 +100,9 @@ public:
|
||||||
void setLeanForward(float dist);
|
void setLeanForward(float dist);
|
||||||
void setLeanSideways(float dist);
|
void setLeanSideways(float dist);
|
||||||
void addLean(float x, float z);
|
void addLean(float x, float z);
|
||||||
const glm::vec3& getHeadPosition() const ;
|
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].position; };
|
|
||||||
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].springyPosition; };
|
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].springyPosition; };
|
||||||
|
|
||||||
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
|
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
|
||||||
float getSpeed() const { return _speed; };
|
float getSpeed() const { return _speed; };
|
||||||
const glm::vec3& getVelocity() const { return _velocity; };
|
const glm::vec3& getVelocity() const { return _velocity; };
|
||||||
|
@ -113,9 +112,8 @@ public:
|
||||||
AvatarMode getMode();
|
AvatarMode getMode();
|
||||||
|
|
||||||
void setMousePressed(bool pressed);
|
void setMousePressed(bool pressed);
|
||||||
void render(bool lookingInMirrorm, glm::vec3 cameraPosition);
|
void render(bool lookingInMirror, glm::vec3 cameraPosition);
|
||||||
void renderBody();
|
void renderBody(bool lookingInMirror);
|
||||||
void renderHead(bool lookingInMirror);
|
|
||||||
void simulate(float);
|
void simulate(float);
|
||||||
void setHandMovementValues( glm::vec3 movement );
|
void setHandMovementValues( glm::vec3 movement );
|
||||||
void updateArmIKAndConstraints( float deltaTime );
|
void updateArmIKAndConstraints( float deltaTime );
|
||||||
|
@ -155,6 +153,7 @@ private:
|
||||||
float length; // the length of vector connecting the joint and its parent
|
float length; // the length of vector connecting the joint and its parent
|
||||||
float radius; // used for detecting collisions for certain physical effects
|
float radius; // used for detecting collisions for certain physical effects
|
||||||
bool isCollidable; // when false, the joint position will not register a collision
|
bool isCollidable; // when false, the joint position will not register a collision
|
||||||
|
float touchForce; // if being touched, what's the degree of influence? (0 to 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
Head _head;
|
Head _head;
|
||||||
|
@ -192,6 +191,12 @@ private:
|
||||||
bool _displayingHead; // should be false if in first-person view
|
bool _displayingHead; // should be false if in first-person view
|
||||||
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
||||||
glm::vec3 _gravity;
|
glm::vec3 _gravity;
|
||||||
|
glm::vec3 _mouseRayOrigin;
|
||||||
|
glm::vec3 _mouseRayDirection;
|
||||||
|
glm::vec3 _cameraPosition;
|
||||||
|
|
||||||
|
//AvatarJointID _jointTouched;
|
||||||
|
|
||||||
|
|
||||||
// private methods...
|
// private methods...
|
||||||
void initializeSkeleton();
|
void initializeSkeleton();
|
||||||
|
@ -206,6 +211,7 @@ private:
|
||||||
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
|
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
|
||||||
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
||||||
void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime);
|
void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime);
|
||||||
|
void checkForMouseRayTouching();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
|
||||||
|
const float MODE_SHIFT_RATE = 5.0f;
|
||||||
|
|
||||||
Camera::Camera() {
|
Camera::Camera() {
|
||||||
|
|
||||||
_needsToInitialize = true;
|
_needsToInitialize = true;
|
||||||
|
@ -22,12 +24,10 @@ Camera::Camera() {
|
||||||
_fieldOfView = 60.0; // default
|
_fieldOfView = 60.0; // default
|
||||||
_nearClip = 0.08; // default
|
_nearClip = 0.08; // default
|
||||||
_farClip = 50.0 * TREE_SCALE; // default
|
_farClip = 50.0 * TREE_SCALE; // default
|
||||||
_modeShift = 0.0;
|
|
||||||
_yaw = 0.0;
|
_yaw = 0.0;
|
||||||
_pitch = 0.0;
|
_pitch = 0.0;
|
||||||
_roll = 0.0;
|
_roll = 0.0;
|
||||||
_upShift = 0.0;
|
_upShift = 0.0;
|
||||||
_rightShift = 0.0;
|
|
||||||
_distance = 0.0;
|
_distance = 0.0;
|
||||||
_idealYaw = 0.0;
|
_idealYaw = 0.0;
|
||||||
_idealPitch = 0.0;
|
_idealPitch = 0.0;
|
||||||
|
@ -36,28 +36,27 @@ Camera::Camera() {
|
||||||
_position = glm::vec3(0.0, 0.0, 0.0);
|
_position = glm::vec3(0.0, 0.0, 0.0);
|
||||||
_idealPosition = glm::vec3(0.0, 0.0, 0.0);
|
_idealPosition = glm::vec3(0.0, 0.0, 0.0);
|
||||||
_orientation.setToIdentity();
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::update(float deltaTime) {
|
void Camera::update(float deltaTime) {
|
||||||
|
|
||||||
if (_mode == CAMERA_MODE_NULL) {
|
if (_mode != CAMERA_MODE_NULL) {
|
||||||
_modeShift = 0.0;
|
// use iterative forces to push the camera towards the target position and angle
|
||||||
} else {
|
|
||||||
// use iterative forces to push the camera towards the desired position and angle
|
|
||||||
updateFollowMode(deltaTime);
|
updateFollowMode(deltaTime);
|
||||||
|
|
||||||
if (_modeShift < 1.0f) {
|
|
||||||
_modeShift += MODE_SHIFT_RATE * deltaTime;
|
|
||||||
if (_modeShift > 1.0f) {
|
|
||||||
_modeShift = 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do this AFTER making any changes to yaw pitch and roll....
|
// do this AFTER making any changes to yaw pitch and roll....
|
||||||
generateOrientation();
|
generateOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// generate the ortho-normals for the orientation based on the three Euler angles
|
// generate the ortho-normals for the orientation based on the three Euler angles
|
||||||
void Camera::generateOrientation() {
|
void Camera::generateOrientation() {
|
||||||
_orientation.setToIdentity();
|
_orientation.setToIdentity();
|
||||||
|
@ -104,15 +103,27 @@ void Camera::updateFollowMode(float deltaTime) {
|
||||||
_position = _idealPosition;
|
_position = _idealPosition;
|
||||||
_needsToInitialize = false;
|
_needsToInitialize = false;
|
||||||
} else {
|
} else {
|
||||||
// pull position towards ideal position
|
// force position towards ideal position
|
||||||
_position += (_idealPosition - _position) * t;
|
_position += (_idealPosition - _position) * t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//transition to the attributes of the current mode
|
||||||
|
_upShift += (_attributes[_mode].upShift - _upShift ) * deltaTime * MODE_SHIFT_RATE;
|
||||||
|
_distance += (_attributes[_mode].distance - _distance ) * deltaTime * MODE_SHIFT_RATE;
|
||||||
|
_tightness += (_attributes[_mode].tightness - _tightness) * deltaTime * MODE_SHIFT_RATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::setMode(CameraMode m, CameraFollowingAttributes a) {
|
||||||
|
|
||||||
|
_attributes[m].upShift = a.upShift;
|
||||||
|
_attributes[m].distance = a.distance;
|
||||||
|
_attributes[m].tightness = a.tightness;
|
||||||
|
|
||||||
|
setMode(m);
|
||||||
|
}
|
||||||
|
|
||||||
void Camera::setMode(CameraMode m) {
|
void Camera::setMode(CameraMode m) {
|
||||||
_mode = m;
|
_mode = m;
|
||||||
_modeShift = 0.0f;
|
|
||||||
_needsToInitialize = true;
|
_needsToInitialize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,18 @@ enum CameraMode
|
||||||
NUM_CAMERA_MODES
|
NUM_CAMERA_MODES
|
||||||
};
|
};
|
||||||
|
|
||||||
const float MODE_SHIFT_RATE = 2.0f;
|
|
||||||
|
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Camera();
|
Camera();
|
||||||
|
|
||||||
|
struct CameraFollowingAttributes
|
||||||
|
{
|
||||||
|
float upShift;
|
||||||
|
float distance;
|
||||||
|
float tightness;
|
||||||
|
};
|
||||||
|
|
||||||
void initialize(); // instantly put the camera at the ideal position and rotation.
|
void initialize(); // instantly put the camera at the ideal position and rotation.
|
||||||
|
|
||||||
void update( float deltaTime );
|
void update( float deltaTime );
|
||||||
|
@ -35,7 +40,6 @@ public:
|
||||||
void setPitch ( float p ) { _pitch = p; }
|
void setPitch ( float p ) { _pitch = p; }
|
||||||
void setRoll ( float r ) { _roll = r; }
|
void setRoll ( float r ) { _roll = r; }
|
||||||
void setUpShift ( float u ) { _upShift = u; }
|
void setUpShift ( float u ) { _upShift = u; }
|
||||||
void setRightShift ( float r ) { _rightShift = r; }
|
|
||||||
void setDistance ( float d ) { _distance = d; }
|
void setDistance ( float d ) { _distance = d; }
|
||||||
void setTargetPosition( glm::vec3 t ) { _targetPosition = t; }
|
void setTargetPosition( glm::vec3 t ) { _targetPosition = t; }
|
||||||
void setTargetYaw ( float y ) { _idealYaw = y; }
|
void setTargetYaw ( float y ) { _idealYaw = y; }
|
||||||
|
@ -43,8 +47,8 @@ public:
|
||||||
void setTightness ( float t ) { _tightness = t; }
|
void setTightness ( float t ) { _tightness = t; }
|
||||||
void setTargetRotation( float yaw, float pitch, float roll );
|
void setTargetRotation( float yaw, float pitch, float roll );
|
||||||
|
|
||||||
|
|
||||||
void setMode ( CameraMode m );
|
void setMode ( CameraMode m );
|
||||||
|
void setMode ( CameraMode m, CameraFollowingAttributes attributes );
|
||||||
void setFieldOfView ( float f );
|
void setFieldOfView ( float f );
|
||||||
void setAspectRatio ( float a );
|
void setAspectRatio ( float a );
|
||||||
void setNearClip ( float n );
|
void setNearClip ( float n );
|
||||||
|
@ -56,7 +60,6 @@ public:
|
||||||
glm::vec3 getPosition () { return _position; }
|
glm::vec3 getPosition () { return _position; }
|
||||||
Orientation getOrientation() { return _orientation; }
|
Orientation getOrientation() { return _orientation; }
|
||||||
CameraMode getMode () { return _mode; }
|
CameraMode getMode () { return _mode; }
|
||||||
float getModeShift () { return _modeShift; }
|
|
||||||
float getFieldOfView() { return _fieldOfView; }
|
float getFieldOfView() { return _fieldOfView; }
|
||||||
float getAspectRatio() { return _aspectRatio; }
|
float getAspectRatio() { return _aspectRatio; }
|
||||||
float getNearClip () { return _nearClip; }
|
float getNearClip () { return _nearClip; }
|
||||||
|
@ -68,7 +71,6 @@ private:
|
||||||
|
|
||||||
bool _needsToInitialize;
|
bool _needsToInitialize;
|
||||||
CameraMode _mode;
|
CameraMode _mode;
|
||||||
float _modeShift; // 0.0 to 1.0
|
|
||||||
bool _frustumNeedsReshape;
|
bool _frustumNeedsReshape;
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::vec3 _idealPosition;
|
glm::vec3 _idealPosition;
|
||||||
|
@ -81,7 +83,6 @@ private:
|
||||||
float _pitch;
|
float _pitch;
|
||||||
float _roll;
|
float _roll;
|
||||||
float _upShift;
|
float _upShift;
|
||||||
float _rightShift;
|
|
||||||
float _idealYaw;
|
float _idealYaw;
|
||||||
float _idealPitch;
|
float _idealPitch;
|
||||||
float _idealRoll;
|
float _idealRoll;
|
||||||
|
@ -89,6 +90,8 @@ private:
|
||||||
float _tightness;
|
float _tightness;
|
||||||
Orientation _orientation;
|
Orientation _orientation;
|
||||||
|
|
||||||
|
CameraFollowingAttributes _attributes[NUM_CAMERA_MODES];
|
||||||
|
|
||||||
void generateOrientation();
|
void generateOrientation();
|
||||||
void updateFollowMode( float deltaTime );
|
void updateFollowMode( float deltaTime );
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,9 +114,6 @@ float MOUSE_VIEW_SHIFT_PITCH_MARGIN = (float)(::screenHeight * 0.2f);
|
||||||
float MOUSE_VIEW_SHIFT_YAW_LIMIT = 45.0;
|
float MOUSE_VIEW_SHIFT_YAW_LIMIT = 45.0;
|
||||||
float MOUSE_VIEW_SHIFT_PITCH_LIMIT = 30.0;
|
float MOUSE_VIEW_SHIFT_PITCH_LIMIT = 30.0;
|
||||||
|
|
||||||
//CameraMode defaultCameraMode = CAMERA_MODE_FIRST_PERSON;
|
|
||||||
CameraMode defaultCameraMode = CAMERA_MODE_THIRD_PERSON;
|
|
||||||
|
|
||||||
bool wantColorRandomizer = true; // for addSphere and load file
|
bool wantColorRandomizer = true; // for addSphere and load file
|
||||||
|
|
||||||
Oscilloscope audioScope(256,200,true);
|
Oscilloscope audioScope(256,200,true);
|
||||||
|
@ -337,7 +334,12 @@ void init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
myAvatar.setPosition(start_location);
|
myAvatar.setPosition(start_location);
|
||||||
myCamera.setMode(defaultCameraMode);
|
Camera::CameraFollowingAttributes a;
|
||||||
|
a.upShift = -0.2f;
|
||||||
|
a.distance = 1.5f;
|
||||||
|
a.tightness = 8.0f;
|
||||||
|
myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a);
|
||||||
|
myAvatar.setDisplayingHead(true);
|
||||||
|
|
||||||
OculusManager::connect();
|
OculusManager::connect();
|
||||||
|
|
||||||
|
@ -1046,36 +1048,27 @@ void display(void)
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// camera settings
|
// camera settings
|
||||||
if (myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
if (OculusManager::isConnected()) {
|
||||||
myAvatar.setDisplayingHead(true);
|
|
||||||
myCamera.setUpShift (0.0);
|
|
||||||
myCamera.setDistance (0.2);
|
|
||||||
myCamera.setTightness (100.0f);
|
|
||||||
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
|
||||||
myCamera.setTargetRotation(myAvatar.getBodyYaw() - 180.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
} else if (myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || OculusManager::isConnected()) {
|
|
||||||
myAvatar.setDisplayingHead(false);
|
myAvatar.setDisplayingHead(false);
|
||||||
myCamera.setUpShift (0.0f);
|
myCamera.setUpShift (0.0f);
|
||||||
myCamera.setDistance (0.0f);
|
myCamera.setDistance (0.0f);
|
||||||
myCamera.setTightness (100.0f);
|
myCamera.setTightness (100.0f);
|
||||||
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
||||||
|
myCamera.setTargetRotation(myAvatar.getBodyYaw() + myAvatar.getHeadYaw(), -myAvatar.getHeadPitch(), myAvatar.getHeadRoll());
|
||||||
|
|
||||||
|
} else if (myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||||
|
myCamera.setTargetPosition(myAvatar.getSpringyHeadPosition());
|
||||||
|
myCamera.setTargetRotation(myAvatar.getBodyYaw() - 180.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
if (OculusManager::isConnected()) {
|
|
||||||
myCamera.setTargetRotation(myAvatar.getBodyYaw() + myAvatar.getHeadYaw(),
|
|
||||||
-myAvatar.getHeadPitch(),
|
|
||||||
myAvatar.getHeadRoll());
|
|
||||||
} else {
|
} else {
|
||||||
myCamera.setTargetRotation(myAvatar.getAbsoluteHeadYaw()- mouseViewShiftYaw, myAvatar.getAbsoluteHeadPitch() + myAvatar.getRenderPitch() + mouseViewShiftPitch, 0.0f);
|
if (myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
|
||||||
}
|
myCamera.setTargetPosition(myAvatar.getSpringyHeadPosition());
|
||||||
|
myCamera.setTargetRotation(myAvatar.getAbsoluteHeadYaw()- mouseViewShiftYaw, myAvatar.getRenderPitch() + mouseViewShiftPitch, 0.0f);
|
||||||
} else if (myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
} else if (myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
||||||
myAvatar.setDisplayingHead(true);
|
|
||||||
myCamera.setUpShift (-0.2f);
|
|
||||||
myCamera.setDistance (1.5f);
|
|
||||||
myCamera.setTightness (8.0f);
|
|
||||||
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
myCamera.setTargetPosition(myAvatar.getHeadPosition());
|
||||||
myCamera.setTargetRotation(myAvatar.getBodyYaw() - mouseViewShiftYaw, mouseViewShiftPitch, 0.0f);
|
myCamera.setTargetRotation(myAvatar.getBodyYaw() - mouseViewShiftYaw, mouseViewShiftPitch, 0.0f);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// important...
|
// important...
|
||||||
myCamera.update( 1.f/FPS );
|
myCamera.update( 1.f/FPS );
|
||||||
|
@ -1247,9 +1240,19 @@ int setRenderFirstPerson(int state) {
|
||||||
bool value = setValue(state, &::renderFirstPersonOn);
|
bool value = setValue(state, &::renderFirstPersonOn);
|
||||||
if (state == MENU_ROW_PICKED) {
|
if (state == MENU_ROW_PICKED) {
|
||||||
if (::renderFirstPersonOn) {
|
if (::renderFirstPersonOn) {
|
||||||
myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
|
Camera::CameraFollowingAttributes a;
|
||||||
|
a.upShift = 0.0f;
|
||||||
|
a.distance = 0.0f;
|
||||||
|
a.tightness = 100.0f;
|
||||||
|
myCamera.setMode(CAMERA_MODE_FIRST_PERSON, a);
|
||||||
|
myAvatar.setDisplayingHead(false);
|
||||||
} else {
|
} else {
|
||||||
myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
|
Camera::CameraFollowingAttributes a;
|
||||||
|
a.upShift = -0.2f;
|
||||||
|
a.distance = 1.5f;
|
||||||
|
a.tightness = 8.0f;
|
||||||
|
myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a);
|
||||||
|
myAvatar.setDisplayingHead(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -1703,9 +1706,19 @@ void key(unsigned char k, int x, int y) {
|
||||||
audio.setMixerLoopbackFlag(::lookingInMirror);
|
audio.setMixerLoopbackFlag(::lookingInMirror);
|
||||||
|
|
||||||
if (::lookingInMirror) {
|
if (::lookingInMirror) {
|
||||||
myCamera.setMode(CAMERA_MODE_MIRROR);
|
Camera::CameraFollowingAttributes a;
|
||||||
|
a.upShift = 0.0f;
|
||||||
|
a.distance = 0.2f;
|
||||||
|
a.tightness = 100.0f;
|
||||||
|
myCamera.setMode(CAMERA_MODE_MIRROR, a);
|
||||||
|
myAvatar.setDisplayingHead(true);
|
||||||
} else {
|
} else {
|
||||||
myCamera.setMode(defaultCameraMode);
|
Camera::CameraFollowingAttributes a;
|
||||||
|
a.upShift = -0.2f;
|
||||||
|
a.distance = 1.5f;
|
||||||
|
a.tightness = 8.0f;
|
||||||
|
myCamera.setMode(CAMERA_MODE_THIRD_PERSON, a);
|
||||||
|
myAvatar.setDisplayingHead(true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1819,13 +1832,16 @@ void idle(void) {
|
||||||
myAvatar.setMousePressed(mousePressed);
|
myAvatar.setMousePressed(mousePressed);
|
||||||
|
|
||||||
// check what's under the mouse and update the mouse voxel
|
// check what's under the mouse and update the mouse voxel
|
||||||
glm::vec3 origin, direction;
|
glm::vec3 mouseRayOrigin, mouseRayDirection;
|
||||||
viewFrustum.computePickRay(mouseX / (float)::screenWidth, mouseY / (float)::screenHeight, origin, direction);
|
viewFrustum.computePickRay(mouseX / (float)::screenWidth, mouseY / (float)::screenHeight, mouseRayOrigin, mouseRayDirection);
|
||||||
|
|
||||||
|
// tell my avatar the posiion and direction of the ray projected ino the world based on the mouse position
|
||||||
|
myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection);
|
||||||
|
|
||||||
float distance;
|
float distance;
|
||||||
BoxFace face;
|
BoxFace face;
|
||||||
::mouseVoxel.s = 0.0f;
|
::mouseVoxel.s = 0.0f;
|
||||||
if (::mouseMode != NO_EDIT_MODE && voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) {
|
if (voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, ::mouseVoxel, distance, face)) {
|
||||||
// find the nearest voxel with the desired scale
|
// find the nearest voxel with the desired scale
|
||||||
if (::mouseVoxelScale > ::mouseVoxel.s) {
|
if (::mouseVoxelScale > ::mouseVoxel.s) {
|
||||||
// choose the larger voxel that encompasses the one selected
|
// choose the larger voxel that encompasses the one selected
|
||||||
|
@ -1834,24 +1850,14 @@ void idle(void) {
|
||||||
::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale);
|
::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale);
|
||||||
::mouseVoxel.s = ::mouseVoxelScale;
|
::mouseVoxel.s = ::mouseVoxelScale;
|
||||||
|
|
||||||
} else {
|
} else if (::mouseVoxelScale < ::mouseVoxel.s) {
|
||||||
glm::vec3 faceVector = getFaceVector(face);
|
glm::vec3 pt = (mouseRayOrigin + mouseRayDirection * distance) / (float)TREE_SCALE -
|
||||||
if (::mouseVoxelScale < ::mouseVoxel.s) {
|
getFaceVector(face) * (::mouseVoxelScale * 0.5f);
|
||||||
// find the closest contained voxel
|
|
||||||
glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE -
|
|
||||||
faceVector * (::mouseVoxelScale * 0.5f);
|
|
||||||
::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale);
|
::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale);
|
||||||
::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale);
|
::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale);
|
||||||
::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale);
|
::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale);
|
||||||
::mouseVoxel.s = ::mouseVoxelScale;
|
::mouseVoxel.s = ::mouseVoxelScale;
|
||||||
}
|
}
|
||||||
if (::mouseMode == ADD_VOXEL_MODE) {
|
|
||||||
// use the face to determine the side on which to create a neighbor
|
|
||||||
::mouseVoxel.x += faceVector.x * ::mouseVoxel.s;
|
|
||||||
::mouseVoxel.y += faceVector.y * ::mouseVoxel.s;
|
|
||||||
::mouseVoxel.z += faceVector.z * ::mouseVoxel.s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (::mouseMode == COLOR_VOXEL_MODE) {
|
if (::mouseMode == COLOR_VOXEL_MODE) {
|
||||||
::mouseVoxel.red = 0;
|
::mouseVoxel.red = 0;
|
||||||
|
@ -1892,6 +1898,7 @@ void idle(void) {
|
||||||
if (agent->getLinkedData() != NULL) {
|
if (agent->getLinkedData() != NULL) {
|
||||||
Avatar *avatar = (Avatar *)agent->getLinkedData();
|
Avatar *avatar = (Avatar *)agent->getLinkedData();
|
||||||
avatar->simulate(deltaTime);
|
avatar->simulate(deltaTime);
|
||||||
|
avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
agentList->unlock();
|
agentList->unlock();
|
||||||
|
|
Loading…
Reference in a new issue