Cleaned up some const values in Head.h, implemented avatar gravity and ground collision, improved test sphere collision, added _usingBodySprings test to getHeadPosition, improved camera settings in main.cpp, cleaned up commented-out code in main.cpp

This commit is contained in:
Jeffrey Ventrella 2013-04-22 15:39:31 -07:00
parent 1b91a8e653
commit ca2840f905
3 changed files with 51 additions and 47 deletions

View file

@ -35,9 +35,7 @@ float browThickness = 0.16;
bool usingBigSphereCollisionTest = true;
const float DECAY = 0.1;
const float THRUST_MAG = 10.0;
const float YAW_MAG = 300.0;
char iris_texture_file[] = "resources/images/green_eye.png";
@ -380,7 +378,19 @@ void Head::simulate(float deltaTime) {
//--------------------------------------------------------------
updateBigSphereCollisionTest(deltaTime);
}
if ( AVATAR_GRAVITY ) {
if ( _bodyPosition.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) {
_velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime );
}
else {
if ( _bodyPosition.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) {
_bodyPosition.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius;
_velocity.y = 0.0;
}
}
}
//------------------------
// update avatar skeleton
//------------------------
@ -460,7 +470,6 @@ void Head::simulate(float deltaTime) {
//----------------------------------------------------------
// decay body yaw delta
//----------------------------------------------------------
const float TEST_YAW_DECAY = 5.0;
_bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime);
//----------------------------------------------------------
@ -476,7 +485,6 @@ void Head::simulate(float deltaTime) {
//----------------------------------------------------------
// decay velocity
//----------------------------------------------------------
const float LIN_VEL_DECAY = 5.0;
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
if (!_head.noise) {
@ -585,7 +593,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
{
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].position - _TEST_bigSpherePosition);
glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - _TEST_bigSpherePosition);
float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter);
float combinedRadius = _bone[b].radius + _TEST_bigSphereRadius;
if ( distanceToBigSphereCenter < combinedRadius )
@ -598,9 +606,9 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius);
glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration;
_bone[b].springyVelocity += collisionForce * 8.0f * deltaTime;
_velocity += collisionForce * 18.0f * deltaTime;
_bone[b].position = _TEST_bigSpherePosition + directionVector * combinedRadius;
_bone[b].springyVelocity += collisionForce * 30.0f * deltaTime;
_velocity += collisionForce * 100.0f * deltaTime;
_bone[b].springyPosition = _TEST_bigSpherePosition + directionVector * combinedRadius;
}
}
}
@ -609,22 +617,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
if (!_usingBodySprings) {
_usingBodySprings = true;
initializeBodySprings();
}
//----------------------------------------------------------
// add gravity to velocity
//----------------------------------------------------------
_velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * 0.05;
//----------------------------------------------------------
// ground collisions
//----------------------------------------------------------
if ( _bodyPosition.y < 0.0 ) {
_bodyPosition.y = 0.0;
if ( _velocity.y < 0.0 ) {
_velocity.y *= -0.7;
}
}
}
}
}
}
@ -677,6 +670,7 @@ void Head::render(int faceToFace) {
//---------------------------------------------------------------------------
if ( _isMine )
{
/*
//---------------------------------------------------
// render other avatars (DEBUG TEST)
//---------------------------------------------------
@ -687,6 +681,7 @@ void Head::render(int faceToFace) {
glutSolidSphere( 1, 10, 10 );
glPopMatrix();
}
*/
if (_usingBodySprings) {
if ( _closestOtherAvatar != -1 ) {
@ -1124,12 +1119,23 @@ glm::vec3 Head::getHeadLookatDirectionRight() {
}
glm::vec3 Head::getHeadPosition() {
if ( _usingBodySprings ) {
return _bone[ AVATAR_BONE_HEAD ].springyPosition;
}
return _bone[ AVATAR_BONE_HEAD ].position;
/*
return glm::vec3
(
_bone[ AVATAR_BONE_HEAD ].position.x,
_bone[ AVATAR_BONE_HEAD ].position.y,
_bone[ AVATAR_BONE_HEAD ].position.z
);
*/
}

View file

@ -22,6 +22,13 @@
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp> //looks like we might not need this
const bool AVATAR_GRAVITY = true;
const float DECAY = 0.1;
const float THRUST_MAG = 10.0;
const float YAW_MAG = 300.0;
const float TEST_YAW_DECAY = 5.0;
const float LIN_VEL_DECAY = 5.0;
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
#define FWD 0

View file

@ -802,18 +802,16 @@ void display(void)
//--------------------------------------------------------
// camera settings
//--------------------------------------------------------
myCamera.setTargetPosition( myAvatar.getBodyPosition() );
if ( displayHead ) {
//-----------------------------------------------
// set the camera to looking at my own face
//-----------------------------------------------
myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); // XXXBHG - Shouldn't we use Head position here?
myCamera.setTargetPosition ( myAvatar.getHeadPosition() );
myCamera.setYaw ( - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.6 );
myCamera.setDistance ( 0.3 );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.0 );
myCamera.setDistance ( 0.2 );
myCamera.setTightness ( 100.0f );
myCamera.update ( 1.f/FPS );
} else {
@ -822,12 +820,12 @@ void display(void)
//----------------------------------------------------
myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.45);
myCamera.setDistance ( 1.0 );
myCamera.setTightness ( 10.0f );
myCamera.update ( 1.f/FPS );
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.45 );
myCamera.setDistance ( 1.0 );
myCamera.setTightness ( 8.0f );
myCamera.update ( 1.f/FPS);
}
// Note: whichCamera is used to pick between the normal camera myCamera for our
@ -890,14 +888,12 @@ void display(void)
float sphereRadius = 0.25f;
glColor3f(1,0,0);
glPushMatrix();
//glTranslatef( 0.0f, sphereRadius, 0.0f );
glutSolidSphere( sphereRadius, 15, 15 );
glPopMatrix();
//draw a grid gound plane....
drawGroundPlaneGrid( 5.0f, 9 );
// Draw cloud of dots
if (!displayHead) cloud.render();
@ -917,12 +913,7 @@ void display(void)
agent++) {
if (agent->getLinkedData() != NULL) {
Head *avatar = (Head *)agent->getLinkedData();
//glPushMatrix();
//printf( "rendering remote avatar\n" );
avatar->render(0);
//glPopMatrix();
}
}
@ -993,7 +984,7 @@ void display(void)
int totalAgents = AgentList::getInstance()->getAgents().size();
int totalAvatars = 0, totalServers = 0;
for (int i = 0; i < totalAgents; i++) {
(AgentList::getInstance()->getAgents()[i].getType() == AGENT_TYPE_INTERFACE)
(AgentList::getInstance()->getAgents()[i].getType() == AGENT_TYPE_AVATAR)
? totalAvatars++ : totalServers++;
}
sprintf(agents, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);