Merge remote-tracking branch 'upstream/master' into agentlist-array

This commit is contained in:
Stephen Birarda 2013-04-25 17:01:17 -07:00
commit e6d278ea12
6 changed files with 211 additions and 112 deletions

View file

@ -113,9 +113,8 @@ int main(int argc, const char* argv[]) {
// move eve away from the origin
// pick a random point inside a 10x10 grid
eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION),
0,
randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION)));
eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), 0.4,
randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION)));
// face any instance of eve down the z-axis
eve.setBodyYaw(0);

View file

@ -117,6 +117,8 @@ Avatar::Avatar(bool isMine) {
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
_handHolding.force = 10.0f;
initializeSkeleton();
if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
@ -127,7 +129,6 @@ Avatar::Avatar(bool isMine) {
}
Avatar::Avatar(const Avatar &otherAvatar) {
_velocity = otherAvatar._velocity;
@ -198,6 +199,9 @@ Avatar::Avatar(const Avatar &otherAvatar) {
_head.browAudioLift = otherAvatar._head.browAudioLift;
_head.noise = otherAvatar._head.noise;
initializeSkeleton();
if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
@ -297,7 +301,7 @@ void Avatar::simulate(float deltaTime) {
}
_interactingOtherIsNearby = false;
// if the avatar being simulated is mine, then loop through
// all the other avatars for potential interactions...
if ( _isMine )
@ -366,6 +370,19 @@ void Avatar::simulate(float deltaTime) {
deltaTime);
}
if ( AVATAR_GRAVITY ) {
if ( _position.y > _pelvisStandingHeight + 0.01 ) {
_velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime );
}
else {
if ( _position.y < _pelvisStandingHeight ) {
_position.y = _pelvisStandingHeight;
_velocity.y = 0.0;
}
}
}
/*
if ( AVATAR_GRAVITY ) {
if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) {
_velocity += glm::dvec3(getGravity(getPosition())) * ( 6.0 * deltaTime );
@ -374,6 +391,8 @@ void Avatar::simulate(float deltaTime) {
_velocity.y = 0.0;
}
}
*/
// update body springs
updateBodySprings( deltaTime );
@ -533,6 +552,22 @@ void Avatar::simulate(float deltaTime) {
const float AUDIO_AVERAGING_SECS = 0.05;
_head.averageLoudness = (1.f - deltaTime / AUDIO_AVERAGING_SECS) * _head.averageLoudness +
(deltaTime / AUDIO_AVERAGING_SECS) * _audioLoudness;
_speed = glm::length( _velocity );
float rotationalSpeed = fabs( _bodyYawDelta );
if ( _speed + rotationalSpeed > 0.2 )
{
_mode = AVATAR_MODE_WALKING;
}
else
{
_mode = AVATAR_MODE_INTERACTING;
}
}
float Avatar::getSpeed() {
return _speed;
}
@ -595,6 +630,7 @@ void Avatar::render(bool lookingInMirror) {
glScalef( 0.03, 0.03, 0.03 );
glutSolidSphere( 1, 10, 10 );
glPopMatrix();
*/
if ( usingBigSphereCollisionTest ) {
@ -860,7 +896,7 @@ void Avatar::initializeSkeleton() {
_bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
// specify the default pose position
_bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 );
_bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 );
_bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
_bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
_bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
@ -1218,4 +1254,4 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) {
// If flying in space, turn gravity OFF
return glm::vec3(0.f, 0.f, 0.f);
}
}
}

View file

@ -25,7 +25,7 @@
const bool AVATAR_GRAVITY = true;
const float DECAY = 0.1;
const float THRUST_MAG = 10.0;
const float YAW_MAG = 300.0;
const float YAW_MAG = 500.0; //JJV - changed from 300.0;
const float TEST_YAW_DECAY = 5.0;
const float LIN_VEL_DECAY = 5.0;

View file

@ -11,63 +11,89 @@
#include "Camera.h"
Camera::Camera() {
_mode = CAMERA_MODE_THIRD_PERSON;
_tightness = DEFAULT_CAMERA_TIGHTNESS;
_fieldOfView = 60.0; // default
_nearClip = 0.08; // default
_farClip = 50.0; // default
_yaw = 0.0;
_pitch = 0.0;
_roll = 0.0;
_up = 0.0;
_distance = 0.0;
_idealYaw = 0.0;
_targetPosition = 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 );
_frustumNeedsReshape = false;
_mode = CAMERA_MODE_THIRD_PERSON;
_tightness = 10.0; // default
_fieldOfView = 60.0; // default
_nearClip = 0.08; // default
_farClip = 50.0; // default
_modeShift = 0.0;
_yaw = 0.0;
_pitch = 0.0;
_roll = 0.0;
_upShift = 0.0;
_rightShift = 0.0;
_distance = 0.0;
_idealYaw = 0.0;
_targetPosition = 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 );
_orientation.setToIdentity();
}
void Camera::update( float deltaTime ) {
void Camera::update( float deltaTime )
{
//----------------------------------------
// derive t from tightness
//----------------------------------------
float t = _tightness * deltaTime;
if ( t > 1.0 ){
t = 1.0;
}
//----------------------------------------
// update _yaw (before position!)
//----------------------------------------
_yaw += ( _idealYaw - _yaw ) * t;
float radian = ( _yaw / 180.0 ) * PIE;
//----------------------------------------
// update _position
//----------------------------------------
//these need to be checked to make sure they correspond to the coordinate system.
double x = _distance * -sin( radian );
double z = _distance * cos( radian );
double y = _up;
_idealPosition = _targetPosition + glm::vec3( x, y, z );
_position += ( _idealPosition - _position ) * t;
//------------------------------------------------------------------------------
// generate the ortho-normals for the orientation based on the Euler angles
//------------------------------------------------------------------------------
_orientation.setToIdentity();
// generate the ortho-normals for the orientation based on the Euler angles
_orientation.setToIdentity();
_orientation.yaw ( _yaw );
_orientation.pitch( _pitch );
_orientation.roll ( _roll );
_orientation.yaw ( _yaw );
_orientation.pitch ( _pitch );
_orientation.roll ( _roll );
//printLog( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z );
if ( _mode == CAMERA_MODE_NULL ) {
_modeShift = 0.0;
} else {
// use iterative forces to keep the camera at the desired position and angle
updateFollowMode( deltaTime );
if ( _modeShift < 1.0f ) {
_modeShift += MODE_SHIFT_RATE * deltaTime;
if ( _modeShift > 1.0f ) {
_modeShift = 1.0f;
}
}
}
}
// use iterative forces to keep the camera at the desired position and angle
void Camera::updateFollowMode( float deltaTime ) {
// derive t from tightness
float t = _tightness * deltaTime;
if ( t > 1.0 ) {
t = 1.0;
}
// update _yaw (before position!)
_yaw += ( _idealYaw - _yaw ) * t;
_orientation.yaw ( _yaw );
float radian = ( _yaw / 180.0 ) * PIE;
// update _position
//these need to be checked to make sure they correspond to the correct coordinate system.
double x = _distance * -sin( radian );
double z = _distance * cos( radian );
double y = _upShift;
_idealPosition = _targetPosition + glm::vec3( x, y, z );
//_idealPosition += _orientation.getRight() * _rightShift;
//_idealPosition += _orientation.getUp () * _upShift;
// pull position towards ideal position
_position += ( _idealPosition - _position ) * t;
}
// call to find out if the view frustum needs to be reshaped
bool Camera::getFrustumNeedsReshape() {
return _frustumNeedsReshape;
}
// call this after reshaping the view frustum
void Camera::setFrustumWasReshaped() {
_frustumNeedsReshape = false;
}

View file

@ -14,13 +14,13 @@
enum CameraMode
{
CAMERA_MODE_NULL = -1,
CAMERA_MODE_FIRST_PERSON,
CAMERA_MODE_THIRD_PERSON,
CAMERA_MODE_FIRST_PERSON,
CAMERA_MODE_MY_OWN_FACE,
NUM_CAMERA_MODES
};
static const float DEFAULT_CAMERA_TIGHTNESS = 10.0f;
const float MODE_SHIFT_RATE = 2.0f;
class Camera
{
@ -29,35 +29,42 @@ public:
void update( float deltaTime );
void setMode ( CameraMode m ) { _mode = m; }
void setYaw ( float y ) { _idealYaw = y; }
void setPitch ( float p ) { _pitch = p; }
void setRoll ( float r ) { _roll = r; }
void setUp ( float u ) { _up = u; }
void setDistance ( float d ) { _distance = d; }
void setTargetPosition ( glm::vec3 t ) { _targetPosition = t; };
void setPosition ( glm::vec3 p ) { _position = p; };
void setOrientation ( Orientation o ) { _orientation.set(o); }
void setTightness ( float t ) { _tightness = t; }
void setFieldOfView ( float f ) { _fieldOfView = f; }
void setAspectRatio ( float a ) { _aspectRatio = a; }
void setNearClip ( float n ) { _nearClip = n; }
void setFarClip ( float f ) { _farClip = f; }
void setMode ( CameraMode m ) { _mode = m; _modeShift = 0.0f; }
void setYaw ( float y ) { _yaw = y; }
void setPitch ( float p ) { _pitch = p; }
void setRoll ( float r ) { _roll = r; }
void setUpShift ( float u ) { _upShift = u; }
void setRightShift ( float r ) { _rightShift = r; }
void setDistance ( float d ) { _distance = d; }
void setTargetPosition( glm::vec3 t ) { _targetPosition = t; }
void setTargetYaw ( float y ) { _idealYaw = y; }
void setPosition ( glm::vec3 p ) { _position = p; }
void setOrientation ( Orientation o ) { _orientation.set(o); }
void setTightness ( float t ) { _tightness = t; }
void setFieldOfView ( float f ) { _fieldOfView = f; _frustumNeedsReshape = true; }
void setAspectRatio ( float a ) { _aspectRatio = a; _frustumNeedsReshape = true; }
void setNearClip ( float n ) { _nearClip = n; _frustumNeedsReshape = true; }
void setFarClip ( float f ) { _farClip = f; _frustumNeedsReshape = true; }
float getYaw () { return _yaw; }
float getPitch () { return _pitch; }
float getRoll () { return _roll; }
glm::vec3 getPosition () { return _position; }
Orientation getOrientation () { return _orientation; }
CameraMode getMode () { return _mode; }
float getFieldOfView () { return _fieldOfView; }
float getAspectRatio () { return _aspectRatio; }
float getNearClip () { return _nearClip; }
float getFarClip () { return _farClip; }
float getYaw () { return _yaw; }
float getPitch () { return _pitch; }
float getRoll () { return _roll; }
glm::vec3 getPosition () { return _position; }
Orientation getOrientation() { return _orientation; }
CameraMode getMode () { return _mode; }
float getModeShift () { return _modeShift; }
float getFieldOfView() { return _fieldOfView; }
float getAspectRatio() { return _aspectRatio; }
float getNearClip () { return _nearClip; }
float getFarClip () { return _farClip; }
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
private:
CameraMode _mode;
CameraMode _mode;
float _modeShift; // 0.0 to 1.0
bool _frustumNeedsReshape;
glm::vec3 _position;
glm::vec3 _idealPosition;
glm::vec3 _targetPosition;
@ -68,11 +75,14 @@ private:
float _yaw;
float _pitch;
float _roll;
float _up;
float _upShift;
float _rightShift;
float _idealYaw;
float _distance;
float _tightness;
Orientation _orientation;
void updateFollowMode( float deltaTime );
};
#endif

View file

@ -240,8 +240,6 @@ void updateHandController( int x, int y ) {
handController.startX = WIDTH / 2;
handController.startY = HEIGHT / 2;
handController.envelope = 0.0;
//prototype
//myAvatar.stopHandMovement();
}
}
}
@ -800,34 +798,66 @@ void display(void)
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
glMateriali(GL_FRONT, GL_SHININESS, 96);
//--------------------------------------------------------
// camera settings
//--------------------------------------------------------
if ( ::lookingInMirror ) {
//-----------------------------------------------
// set the camera to looking at my own face
//-----------------------------------------------
myCamera.setTargetPosition ( myAvatar.getHeadPosition() );
myCamera.setYaw ( - myAvatar.getBodyYaw() );
myCamera.setTargetYaw ( - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
myCamera.setUp ( 0.0 );
myCamera.setUpShift ( 0.0 );
myCamera.setDistance ( 0.2 );
myCamera.setTightness ( 100.0f );
myCamera.update ( 1.f/FPS );
} else {
//----------------------------------------------------
// set the camera to third-person view behind my av
//----------------------------------------------------
myCamera.setTargetPosition ( myAvatar.getPosition() );
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 ( 8.0f );
myCamera.update ( 1.f/FPS);
float firstPersonPitch = 20.0f;
float firstPersonUpShift = 0.1f;
float firstPersonDistance = 0.0f;
float firstPersonTightness = 100.0f;
float thirdPersonPitch = 0.0f;
float thirdPersonUpShift = -0.1f;
float thirdPersonDistance = 1.f;
float thirdPersonTightness = 8.0f;
myCamera.setPitch (thirdPersonPitch );
myCamera.setUpShift (thirdPersonUpShift );
myCamera.setDistance (thirdPersonDistance );
myCamera.setTightness(thirdPersonTightness);
/*
if ( myAvatar.getSpeed() < 0.02 ) {
if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) {
myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
}
printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch ));
myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift ));
myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance ));
myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness ));
} else {
if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) {
myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
}
printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift());
myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch ));
myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift ));
myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance ));
myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness ));
}
*/
myCamera.setTargetPosition( myAvatar.getHeadPosition() );
myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setRoll ( 0.0 );
}
// important...
myCamera.update( 1.f/FPS );
// Note: whichCamera is used to pick between the normal camera myCamera for our
// main camera, vs, an alternate camera. The alternate camera we support right now
@ -843,10 +873,10 @@ void display(void)
if (::viewFrustumFromOffset && ::frustumOn) {
// set the camera to third-person view but offset so we can see the frustum
viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw );
viewFrustumOffsetCamera.setTargetYaw( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw );
viewFrustumOffsetCamera.setPitch ( ::viewFrustumOffsetPitch );
viewFrustumOffsetCamera.setRoll ( ::viewFrustumOffsetRoll );
viewFrustumOffsetCamera.setUp ( ::viewFrustumOffsetUp );
viewFrustumOffsetCamera.setUpShift ( ::viewFrustumOffsetUp );
viewFrustumOffsetCamera.setDistance ( ::viewFrustumOffsetDistance );
viewFrustumOffsetCamera.update(1.f/FPS);
whichCamera = viewFrustumOffsetCamera;
@ -864,10 +894,8 @@ void display(void)
if (::starsOn) {
// should be the first rendering pass - w/o depth buffer / lighting
// finally render the starfield
stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip());
}
glEnable(GL_LIGHTING);