use a NULL default for owningAvatar to simplify constructors

This commit is contained in:
Stephen Birarda 2013-05-24 11:49:22 -07:00
parent eb25fd3b46
commit 59a6016f4b
7 changed files with 24 additions and 27 deletions

View file

@ -45,7 +45,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *
return currentPosition;
}
void attachAvatarDataToAgent(Agent *newAgent) {
void attachAvatarDataToAgent(Agent* newAgent) {
if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new AvatarData(newAgent));
}

View file

@ -95,7 +95,7 @@ int main(int argc, const char* argv[]) {
pthread_create(&receiveAgentDataThread, NULL, receiveAgentData, NULL);
// create an AvatarData object, "eve"
AvatarData eve(NULL);
AvatarData eve;
// move eve away from the origin
// pick a random point inside a 10x10 grid

View file

@ -128,7 +128,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_viewFrustumOffsetDistance(25.0),
_viewFrustumOffsetUp(0.0),
_audioScope(256, 200, true),
_myAvatar(NULL, true),
_manualFirstPerson(false),
_mouseX(0),
_mouseY(0),
@ -2100,7 +2099,7 @@ QAction* Application::checkedVoxelModeAction() const {
void Application::attachNewHeadToAgent(Agent* newAgent) {
if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Avatar(newAgent, false));
newAgent->setLinkedData(new Avatar(newAgent));
}
}

View file

@ -69,10 +69,9 @@ bool usingBigSphereCollisionTest = true;
float chatMessageScale = 0.0015;
float chatMessageHeight = 0.10;
Avatar::Avatar(Agent* owningAgent, bool isMine) :
Avatar::Avatar(Agent* owningAgent) :
AvatarData(owningAgent),
_head(this),
_isMine(isMine),
_TEST_bigSphereRadius(0.4f),
_TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f),
_mousePressed(false),
@ -231,7 +230,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
updateSkeleton();
//detect and respond to collisions with other avatars...
if (_isMine) {
if (!_owningAgent) {
updateAvatarCollisions(deltaTime);
}
@ -241,7 +240,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_avatarTouch.simulate(deltaTime);
// apply gravity and collision with the ground/floor
if (_isMine && USING_AVATAR_GRAVITY) {
if (!_owningAgent && USING_AVATAR_GRAVITY) {
_velocity += _gravity * (GRAVITY_SCALE * deltaTime);
updateCollisionWithEnvironment();
@ -256,12 +255,12 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
}
// collision response with voxels
if (_isMine) {
if (!_owningAgent) {
updateCollisionWithVoxels();
}
// driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
if (_isMine) {
if (!_owningAgent) {
_thrust = glm::vec3(0.0f, 0.0f, 0.0f);
@ -306,7 +305,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
}
// update body yaw by body yaw delta
if (_isMine) {
if (!_owningAgent) {
_bodyPitch += _bodyPitchDelta * deltaTime;
_bodyYaw += _bodyYawDelta * deltaTime;
_bodyRoll += _bodyRollDelta * deltaTime;
@ -367,7 +366,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
}
// If another avatar is near, dampen velocity as a function of closeness
if (_isMine && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) {
if (!_owningAgent && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) {
float closeness = 1.0f - (_distanceToNearestAvatar / PERIPERSONAL_RADIUS);
float drag = 1.0f - closeness * AVATAR_BRAKING_STRENGTH * deltaTime;
if ( drag > 0.0f ) {
@ -416,7 +415,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
}
// set head lookat position
if (_isMine) {
if (!_owningAgent) {
if (_interactingOther) {
_head.setLookAtPosition(_interactingOther->caclulateAverageEyePosition());
} else {
@ -429,7 +428,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_head.setScale (_joint[ AVATAR_JOINT_HEAD_BASE ].radius);
_head.setAudioLoudness(_audioLoudness);
_head.setSkinColor(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
_head.simulate(deltaTime, _isMine);
_head.simulate(deltaTime, !_owningAgent);
// use speed and angular velocity to determine walking vs. standing
if (_speed + fabs(_bodyYawDelta) > 0.2) {
@ -468,7 +467,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
if (_isMine) {
if (!_owningAgent) {
_avatarTouch.setMyBodyPosition(_position);
float closestDistance = std::numeric_limits<float>::max();
@ -560,7 +559,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
updateArmIKAndConstraints(deltaTime);
//Set right hand position and state to be transmitted, and also tell AvatarTouch about it
if (_isMine) {
if (!_owningAgent) {
setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position);
if (_mousePressed) {
@ -729,7 +728,7 @@ void Avatar::setGravity(glm::vec3 gravity) {
void Avatar::render(bool lookingInMirror) {
if (_isMine && usingBigSphereCollisionTest) {
if (!_owningAgent && usingBigSphereCollisionTest) {
// show TEST big sphere
glColor4f(0.5f, 0.6f, 0.8f, 0.7);
glPushMatrix();
@ -746,7 +745,7 @@ void Avatar::render(bool lookingInMirror) {
renderBody(lookingInMirror);
// if this is my avatar, then render my interactions with the other avatar
if (_isMine) {
if (!_owningAgent) {
_avatarTouch.render(getCameraPosition());
}
@ -1001,7 +1000,7 @@ void Avatar::updateSkeleton() {
}
// if this is not my avatar, then hand position comes from transmitted data
if (! _isMine) {
if (_owningAgent) {
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
}
@ -1137,12 +1136,12 @@ void Avatar::renderBody(bool lookingInMirror) {
float distanceToCamera = glm::length(getCameraPosition() - _joint[b].position);
// Always render other people, and render myself when beyond threshold distance
if (b == AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case
if (lookingInMirror || !_isMine || distanceToCamera > RENDER_OPAQUE_BEYOND) {
if (lookingInMirror || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND) {
_head.render(lookingInMirror);
}
} else if (!_isMine || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) {
} else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) {
// Render the sphere at the joint
if (!_isMine) {
if (_owningAgent) {
glColor3f(skinColor[0] + _joint[b].touchForce * 0.3f,
skinColor[1] - _joint[b].touchForce * 0.2f,
skinColor[2] - _joint[b].touchForce * 0.1f);

View file

@ -76,7 +76,7 @@ enum AvatarJointID
class Avatar : public AvatarData {
public:
Avatar(Agent* owningAgent, bool isMine);
Avatar(Agent* owningAgent = NULL);
~Avatar();
void reset();
@ -151,7 +151,6 @@ private:
};
Head _head;
bool _isMine;
float _TEST_bigSphereRadius;
glm::vec3 _TEST_bigSpherePosition;
bool _mousePressed;

View file

@ -22,14 +22,14 @@ const int WANT_DELTA_AT_BIT = 2;
enum KeyState
{
NO_KEY_DOWN,
NO_KEY_DOWN,
INSERT_KEY_DOWN,
DELETE_KEY_DOWN
};
class AvatarData : public AgentData {
public:
AvatarData(Agent* owningAgent);
AvatarData(Agent* owningAgent = NULL);
~AvatarData();
const glm::vec3& getPosition() const { return _position; }

View file

@ -16,7 +16,7 @@ public:
AgentData(Agent* owningAgent);
virtual ~AgentData() = 0;
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
private:
protected:
Agent* _owningAgent;
};