mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 12:09:45 +02:00
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:
parent
1b91a8e653
commit
ca2840f905
3 changed files with 51 additions and 47 deletions
|
@ -35,9 +35,7 @@ float browThickness = 0.16;
|
||||||
|
|
||||||
bool usingBigSphereCollisionTest = true;
|
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";
|
char iris_texture_file[] = "resources/images/green_eye.png";
|
||||||
|
|
||||||
|
@ -380,7 +378,19 @@ void Head::simulate(float deltaTime) {
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
updateBigSphereCollisionTest(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
|
// update avatar skeleton
|
||||||
//------------------------
|
//------------------------
|
||||||
|
@ -460,7 +470,6 @@ void Head::simulate(float deltaTime) {
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
// decay body yaw delta
|
// decay body yaw delta
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
const float TEST_YAW_DECAY = 5.0;
|
|
||||||
_bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime);
|
_bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime);
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
@ -476,7 +485,6 @@ void Head::simulate(float deltaTime) {
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
// decay velocity
|
// decay velocity
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
const float LIN_VEL_DECAY = 5.0;
|
|
||||||
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
|
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
|
||||||
|
|
||||||
if (!_head.noise) {
|
if (!_head.noise) {
|
||||||
|
@ -585,7 +593,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
|
||||||
{
|
{
|
||||||
for (int b=0; b<NUM_AVATAR_BONES; b++)
|
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 distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter);
|
||||||
float combinedRadius = _bone[b].radius + _TEST_bigSphereRadius;
|
float combinedRadius = _bone[b].radius + _TEST_bigSphereRadius;
|
||||||
if ( distanceToBigSphereCenter < combinedRadius )
|
if ( distanceToBigSphereCenter < combinedRadius )
|
||||||
|
@ -598,9 +606,9 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
|
||||||
float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius);
|
float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius);
|
||||||
glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration;
|
glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration;
|
||||||
|
|
||||||
_bone[b].springyVelocity += collisionForce * 8.0f * deltaTime;
|
_bone[b].springyVelocity += collisionForce * 30.0f * deltaTime;
|
||||||
_velocity += collisionForce * 18.0f * deltaTime;
|
_velocity += collisionForce * 100.0f * deltaTime;
|
||||||
_bone[b].position = _TEST_bigSpherePosition + directionVector * combinedRadius;
|
_bone[b].springyPosition = _TEST_bigSpherePosition + directionVector * combinedRadius;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -609,22 +617,7 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
|
||||||
if (!_usingBodySprings) {
|
if (!_usingBodySprings) {
|
||||||
_usingBodySprings = true;
|
_usingBodySprings = true;
|
||||||
initializeBodySprings();
|
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 )
|
if ( _isMine )
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// render other avatars (DEBUG TEST)
|
// render other avatars (DEBUG TEST)
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
|
@ -687,6 +681,7 @@ void Head::render(int faceToFace) {
|
||||||
glutSolidSphere( 1, 10, 10 );
|
glutSolidSphere( 1, 10, 10 );
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (_usingBodySprings) {
|
if (_usingBodySprings) {
|
||||||
if ( _closestOtherAvatar != -1 ) {
|
if ( _closestOtherAvatar != -1 ) {
|
||||||
|
@ -1124,12 +1119,23 @@ glm::vec3 Head::getHeadLookatDirectionRight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Head::getHeadPosition() {
|
glm::vec3 Head::getHeadPosition() {
|
||||||
|
|
||||||
|
if ( _usingBodySprings ) {
|
||||||
|
return _bone[ AVATAR_BONE_HEAD ].springyPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _bone[ AVATAR_BONE_HEAD ].position;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
return glm::vec3
|
return glm::vec3
|
||||||
(
|
(
|
||||||
_bone[ AVATAR_BONE_HEAD ].position.x,
|
_bone[ AVATAR_BONE_HEAD ].position.x,
|
||||||
_bone[ AVATAR_BONE_HEAD ].position.y,
|
_bone[ AVATAR_BONE_HEAD ].position.y,
|
||||||
_bone[ AVATAR_BONE_HEAD ].position.z
|
_bone[ AVATAR_BONE_HEAD ].position.z
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,13 @@
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/gtx/quaternion.hpp> //looks like we might not need this
|
#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};
|
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
||||||
|
|
||||||
#define FWD 0
|
#define FWD 0
|
||||||
|
|
|
@ -802,18 +802,16 @@ void display(void)
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
// camera settings
|
// camera settings
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
myCamera.setTargetPosition( myAvatar.getBodyPosition() );
|
|
||||||
|
|
||||||
if ( displayHead ) {
|
if ( displayHead ) {
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// set the camera to looking at my own face
|
// 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.setYaw ( - myAvatar.getBodyYaw() );
|
||||||
myCamera.setPitch ( 0.0 );
|
myCamera.setPitch ( 0.0 );
|
||||||
myCamera.setRoll ( 0.0 );
|
myCamera.setRoll ( 0.0 );
|
||||||
myCamera.setUp ( 0.6 );
|
myCamera.setUp ( 0.0 );
|
||||||
myCamera.setDistance ( 0.3 );
|
myCamera.setDistance ( 0.2 );
|
||||||
myCamera.setTightness ( 100.0f );
|
myCamera.setTightness ( 100.0f );
|
||||||
myCamera.update ( 1.f/FPS );
|
myCamera.update ( 1.f/FPS );
|
||||||
} else {
|
} else {
|
||||||
|
@ -822,12 +820,12 @@ void display(void)
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
|
myCamera.setTargetPosition ( myAvatar.getBodyPosition() );
|
||||||
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
|
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
|
||||||
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
|
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
|
||||||
myCamera.setRoll ( 0.0 );
|
myCamera.setRoll ( 0.0 );
|
||||||
myCamera.setUp ( 0.45);
|
myCamera.setUp ( 0.45 );
|
||||||
myCamera.setDistance ( 1.0 );
|
myCamera.setDistance ( 1.0 );
|
||||||
myCamera.setTightness ( 10.0f );
|
myCamera.setTightness ( 8.0f );
|
||||||
myCamera.update ( 1.f/FPS );
|
myCamera.update ( 1.f/FPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: whichCamera is used to pick between the normal camera myCamera for our
|
// Note: whichCamera is used to pick between the normal camera myCamera for our
|
||||||
|
@ -890,14 +888,12 @@ void display(void)
|
||||||
float sphereRadius = 0.25f;
|
float sphereRadius = 0.25f;
|
||||||
glColor3f(1,0,0);
|
glColor3f(1,0,0);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
//glTranslatef( 0.0f, sphereRadius, 0.0f );
|
|
||||||
glutSolidSphere( sphereRadius, 15, 15 );
|
glutSolidSphere( sphereRadius, 15, 15 );
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
//draw a grid gound plane....
|
//draw a grid gound plane....
|
||||||
drawGroundPlaneGrid( 5.0f, 9 );
|
drawGroundPlaneGrid( 5.0f, 9 );
|
||||||
|
|
||||||
|
|
||||||
// Draw cloud of dots
|
// Draw cloud of dots
|
||||||
if (!displayHead) cloud.render();
|
if (!displayHead) cloud.render();
|
||||||
|
|
||||||
|
@ -917,12 +913,7 @@ void display(void)
|
||||||
agent++) {
|
agent++) {
|
||||||
if (agent->getLinkedData() != NULL) {
|
if (agent->getLinkedData() != NULL) {
|
||||||
Head *avatar = (Head *)agent->getLinkedData();
|
Head *avatar = (Head *)agent->getLinkedData();
|
||||||
//glPushMatrix();
|
|
||||||
|
|
||||||
//printf( "rendering remote avatar\n" );
|
|
||||||
|
|
||||||
avatar->render(0);
|
avatar->render(0);
|
||||||
//glPopMatrix();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,7 +984,7 @@ void display(void)
|
||||||
int totalAgents = AgentList::getInstance()->getAgents().size();
|
int totalAgents = AgentList::getInstance()->getAgents().size();
|
||||||
int totalAvatars = 0, totalServers = 0;
|
int totalAvatars = 0, totalServers = 0;
|
||||||
for (int i = 0; i < totalAgents; i++) {
|
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++;
|
? totalAvatars++ : totalServers++;
|
||||||
}
|
}
|
||||||
sprintf(agents, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);
|
sprintf(agents, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);
|
||||||
|
|
Loading…
Reference in a new issue