Merge pull request #196 from Ventrella/master

fixed physics bug and added avatar shadow
This commit is contained in:
birarda 2013-05-06 11:39:12 -07:00
commit 2076dcc67f
6 changed files with 78 additions and 46 deletions

View file

@ -10,5 +10,4 @@ add_subdirectory(interface)
add_subdirectory(injector)
add_subdirectory(pairing-server)
add_subdirectory(space-server)
add_subdirectory(voxel-server)
add_subdirectory(voxel-edit)
add_subdirectory(voxel-edit)add_subdirectory(voxel-server)

View file

@ -32,9 +32,14 @@ const float BODY_ROLL_WHILE_TURNING = 0.1;
const float LIN_VEL_DECAY = 5.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
const float BODY_SPRING_FORCE = 6.0f;
//const float BODY_SPRING_DEFAULT_TIGHTNESS = 20.0f;
//const float BODY_SPRING_FORCE = 6.0f;
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1500.0f;
const float BODY_SPRING_FORCE = 300.0f;
const float BODY_SPRING_DECAY = 16.0f;
const float BODY_SPRING_DEFAULT_TIGHTNESS = 10.0f;
const float COLLISION_RADIUS_SCALAR = 1.8;
const float COLLISION_BALL_FORCE = 1.0;
const float COLLISION_BODY_FORCE = 6.0;
@ -70,8 +75,8 @@ Avatar::Avatar(bool isMine) {
_orientation.setToIdentity();
_velocity = glm::vec3( 0.0, 0.0, 0.0 );
_thrust = glm::vec3( 0.0, 0.0, 0.0 );
_velocity = glm::vec3(0.0f, 0.0f, 0.0f);
_thrust = glm::vec3(0.0f, 0.0f, 0.0f);
_rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
_bodyYaw = -90.0;
_bodyPitch = 0.0;
@ -91,7 +96,7 @@ Avatar::Avatar(bool isMine) {
_pelvisStandingHeight = 0.0f;
_displayingHead = true;
_TEST_bigSphereRadius = 0.4f;
_TEST_bigSpherePosition = glm::vec3( 0.0f, _TEST_bigSphereRadius, 2.0f );
_TEST_bigSpherePosition = glm::vec3(5.0f, _TEST_bigSphereRadius, 5.0f);
for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false;
@ -132,13 +137,13 @@ Avatar::Avatar(bool isMine) {
_head.browAudioLift = 0.0;
_head.noise = 0;
_head.returnSpringScale = 1.0;
_movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
_movedHandOffset = glm::vec3(0.0f, 0.0f, 0.0f);
_usingBodySprings = true;
_renderYaw = 0.0;
_renderPitch = 0.0;
_sphere = NULL;
_interactingOther = NULL;
_handHoldingPosition = glm::vec3( 0.0, 0.0, 0.0 );
_handHoldingPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_distanceToNearestAvatar = std::numeric_limits<float>::max();
initializeSkeleton();
@ -330,14 +335,10 @@ void Avatar::simulate(float deltaTime) {
//update the movement of the hand and process handshaking with other avatars...
updateHandMovementAndTouching(deltaTime);
// test for avatar collision response with the big sphere
if (usingBigSphereCollisionTest) {
updateCollisionWithSphere( _TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime );
}
// apply gravity and collision wiht the ground/floor
if (AVATAR_GRAVITY) {
if ( _position.y > _pelvisStandingHeight + 0.01 ) {
if ( _position.y > _pelvisStandingHeight + 0.01f) {
_velocity += glm::dvec3(getGravity(getPosition())) * (6.0 * deltaTime );
} else if (_position.y < _pelvisStandingHeight) {
_position.y = _pelvisStandingHeight;
@ -348,10 +349,15 @@ void Avatar::simulate(float deltaTime) {
// update body springs
updateBodySprings(deltaTime);
// test for avatar collision response with the big sphere
if (usingBigSphereCollisionTest) {
updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime);
}
// driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
if (_isMine) {
_thrust = glm::vec3( 0.0, 0.0, 0.0 );
_thrust = glm::vec3(0.0f, 0.0f, 0.0f);
if (_driveKeys[FWD ]) {_thrust += THRUST_MAG * deltaTime * _orientation.getFront();}
if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG * deltaTime * _orientation.getFront();}
@ -664,8 +670,8 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float
float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius);
glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration;
_joint[b].springyVelocity += collisionForce * 30.0f * deltaTime;
_velocity += collisionForce * 100.0f * deltaTime;
_joint[b].springyVelocity += collisionForce * 0.0f * deltaTime;
_velocity += collisionForce * 40.0f * deltaTime;
_joint[b].springyPosition = position + directionVector * combinedRadius;
}
}
@ -753,8 +759,11 @@ static TextRenderer* textRenderer() {
return renderer;
}
void Avatar::render(bool lookingInMirror) {
// 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 );
/*
// show avatar position
@ -1270,7 +1279,7 @@ void Avatar::updateBodySprings( float deltaTime ) {
_joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
}
_joint[b].springyPosition += _joint[b].springyVelocity;
_joint[b].springyPosition += _joint[b].springyVelocity * deltaTime;
}
}
@ -1534,6 +1543,7 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) {
}
}
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";
void Avatar::writeAvatarDataToFile() {
@ -1562,3 +1572,4 @@ void Avatar::readAvatarDataFromFile() {
fclose(avatarFile);
}
}

View file

@ -11,13 +11,11 @@
#include "AvatarRenderer.h"
#include "InterfaceConfig.h"
AvatarRenderer::AvatarRenderer() {
}
// this method renders the avatar
void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) {
/*
// show avatar position
glColor4f( 0.5f, 0.5f, 0.5f, 0.6 );
@ -28,5 +26,3 @@ void AvatarRenderer::render(Avatar *avatar, bool lookingInMirror) {
glPopMatrix();
*/
}

View file

@ -237,6 +237,36 @@ void drawGroundPlaneGrid(float size)
}
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness) {
glColor4f( 0.0f, 0.0f, 0.0f, darkness );
int num = 20;
float y = 0.001f;
float x2 = 0.0f;
float z2 = radius;
float x1;
float z1;
glBegin(GL_TRIANGLES);
for (int i=1; i<num+1; i++) {
x1 = x2;
z1 = z2;
float r = ((float)i / (float)num) * PI * 2.0;
x2 = radius * sin(r);
z2 = radius * cos(r);
glVertex3f(position.x, y, position.z );
glVertex3f(position.x + x1, y, position.z + z1);
glVertex3f(position.x + x2, y, position.z + z2);
}
glEnd();
}
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) {
glm::vec3 pRight = position + orientation.getRight() * size;
glm::vec3 pUp = position + orientation.getUp() * size;

View file

@ -44,6 +44,8 @@ double diffclock(timeval *clock1,timeval *clock2);
void drawGroundPlaneGrid(float size);
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness);
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );

View file

@ -69,7 +69,6 @@
#include "Camera.h"
#include "Avatar.h"
#include "AvatarRenderer.h"
#include "Texture.h"
#include <AgentList.h>
#include <AgentTypes.h>
@ -120,9 +119,6 @@ Avatar myAvatar(true); // The rendered avatar of oneself
Camera myCamera; // My view onto the world (sometimes on myself :)
Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode
AvatarRenderer avatarRenderer;
// Starfield information
char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
char starCacheFile[] = "cachedStars.txt";
@ -714,7 +710,6 @@ void displaySide(Camera& whichCamera) {
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
Avatar *avatar = (Avatar *)agent->getLinkedData();
avatar->render(0);
//avatarRenderer.render(avatar, 0); // this will replace the above call
}
}
agentList->unlock();
@ -727,7 +722,6 @@ void displaySide(Camera& whichCamera) {
//Render my own avatar
myAvatar.render(::lookingInMirror);
//avatarRenderer.render(&myAvatar, lookingInMirror); // this will replace the above call
glPopMatrix();
}
@ -1011,7 +1005,7 @@ void display(void)
float firstPersonTightness = 100.0f;
float thirdPersonPitch = 0.0f;
float thirdPersonUpShift = -0.1f;
float thirdPersonUpShift = -0.2f;
float thirdPersonDistance = 1.2f;
float thirdPersonTightness = 8.0f;