mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Merge pull request #421 from birarda/owner-pointers
add pointers back to owning avatar and owning agent
This commit is contained in:
commit
f0ce749877
18 changed files with 63 additions and 44 deletions
|
@ -45,9 +45,9 @@ 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->setLinkedData(new AvatarData(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void *receiveAgentData(void *args) {
|
|||
|
||||
void createAvatarDataForAgent(Agent* agent) {
|
||||
if (!agent->getLinkedData()) {
|
||||
agent->setLinkedData(new AvatarData());
|
||||
agent->setLinkedData(new AvatarData(agent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
_viewFrustumOffsetDistance(25.0),
|
||||
_viewFrustumOffsetUp(0.0),
|
||||
_audioScope(256, 200, true),
|
||||
_myAvatar(true),
|
||||
_manualFirstPerson(false),
|
||||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
|
@ -2098,9 +2097,9 @@ QAction* Application::checkedVoxelModeAction() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Application::attachNewHeadToAgent(Agent *newAgent) {
|
||||
void Application::attachNewHeadToAgent(Agent* newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new Avatar(false));
|
||||
newAgent->setLinkedData(new Avatar(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,9 @@ bool usingBigSphereCollisionTest = true;
|
|||
float chatMessageScale = 0.0015;
|
||||
float chatMessageHeight = 0.20;
|
||||
|
||||
Avatar::Avatar(bool isMine) :
|
||||
_isMine(isMine),
|
||||
Avatar::Avatar(Agent* owningAgent) :
|
||||
AvatarData(owningAgent),
|
||||
_head(this),
|
||||
_TEST_bigSphereRadius(0.4f),
|
||||
_TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f),
|
||||
_mousePressed(false),
|
||||
|
@ -229,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);
|
||||
}
|
||||
|
||||
|
@ -239,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();
|
||||
|
@ -254,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);
|
||||
|
||||
|
@ -304,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;
|
||||
|
@ -365,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 ) {
|
||||
|
@ -414,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 {
|
||||
|
@ -427,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) {
|
||||
|
@ -466,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();
|
||||
|
@ -558,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) {
|
||||
|
@ -727,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();
|
||||
|
@ -744,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());
|
||||
}
|
||||
|
||||
|
@ -999,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;
|
||||
}
|
||||
|
||||
|
@ -1135,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_TRANSLUCENT_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);
|
||||
|
|
|
@ -76,7 +76,7 @@ enum AvatarJointID
|
|||
|
||||
class Avatar : public AvatarData {
|
||||
public:
|
||||
Avatar(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;
|
||||
|
|
|
@ -31,8 +31,8 @@ unsigned int IRIS_TEXTURE_WIDTH = 768;
|
|||
unsigned int IRIS_TEXTURE_HEIGHT = 498;
|
||||
vector<unsigned char> irisTexture;
|
||||
|
||||
Head::Head() :
|
||||
|
||||
Head::Head(Avatar* owningAvatar) :
|
||||
HeadData((AvatarData*)owningAvatar),
|
||||
yawRate(0.0f),
|
||||
_returnHeadToCenter(false),
|
||||
_audioLoudness(0.0f),
|
||||
|
|
|
@ -24,9 +24,11 @@ enum eyeContactTargets
|
|||
MOUTH
|
||||
};
|
||||
|
||||
class Avatar;
|
||||
|
||||
class Head : public HeadData {
|
||||
public:
|
||||
Head();
|
||||
Head(Avatar* owningAvatar);
|
||||
|
||||
void reset();
|
||||
void simulate(float deltaTime, bool isMine);
|
||||
|
|
|
@ -44,7 +44,7 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- .
|
|||
10,11,15, 10,15,14, // Y+
|
||||
4,5,6, 4,6,7 }; // Z+ .
|
||||
|
||||
VoxelSystem::VoxelSystem() {
|
||||
VoxelSystem::VoxelSystem() : AgentData(NULL) {
|
||||
_voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0;
|
||||
_writeRenderFullVBO = true;
|
||||
_readRenderFullVBO = true;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "AudioRingBuffer.h"
|
||||
|
||||
AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
|
||||
AgentData(NULL),
|
||||
_ringBufferLengthSamples(ringSamples),
|
||||
_bufferLengthSamples(bufferSamples),
|
||||
_endOfLastWrite(NULL),
|
||||
|
@ -20,7 +21,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
|
|||
_shouldBeAddedToMix(false),
|
||||
_shouldLoopbackForAgent(false),
|
||||
_streamIdentifier()
|
||||
{
|
||||
{
|
||||
_buffer = new int16_t[_ringBufferLengthSamples];
|
||||
_nextOutput = _buffer;
|
||||
};
|
||||
|
|
|
@ -31,7 +31,8 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo
|
|||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
AvatarData::AvatarData() :
|
||||
AvatarData::AvatarData(Agent* owningAgent) :
|
||||
AgentData(owningAgent),
|
||||
_handPosition(0,0,0),
|
||||
_bodyYaw(-90.0),
|
||||
_bodyPitch(0.0),
|
||||
|
@ -67,7 +68,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
|
||||
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||
if (!_headData) {
|
||||
_headData = new HeadData();
|
||||
_headData = new HeadData(this);
|
||||
}
|
||||
|
||||
// Body world position
|
||||
|
@ -148,7 +149,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
|
||||
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||
if (!_headData) {
|
||||
_headData = new HeadData();
|
||||
_headData = new HeadData(this);
|
||||
}
|
||||
|
||||
// increment to push past the packet header
|
||||
|
|
|
@ -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();
|
||||
AvatarData(Agent* owningAgent = NULL);
|
||||
~AvatarData();
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
|
||||
#include "HeadData.h"
|
||||
|
||||
HeadData::HeadData() :
|
||||
HeadData::HeadData(AvatarData* owningAvatar) :
|
||||
_yaw(0.0f),
|
||||
_pitch(0.0f),
|
||||
_roll(0.0f),
|
||||
_lookAtPosition(0.0f, 0.0f, 0.0f),
|
||||
_leanSideways(0.0f),
|
||||
_leanForward(0.0f)
|
||||
_leanForward(0.0f),
|
||||
_owningAvatar(owningAvatar)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -20,9 +20,11 @@ const float MAX_HEAD_PITCH = 60;
|
|||
const float MIN_HEAD_ROLL = -50;
|
||||
const float MAX_HEAD_ROLL = 50;
|
||||
|
||||
class AvatarData;
|
||||
|
||||
class HeadData {
|
||||
public:
|
||||
HeadData();
|
||||
HeadData(AvatarData* owningAvatar);
|
||||
|
||||
float getLeanSideways() const { return _leanSideways; }
|
||||
void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; }
|
||||
|
@ -55,6 +57,7 @@ protected:
|
|||
glm::vec3 _lookAtPosition;
|
||||
float _leanSideways;
|
||||
float _leanForward;
|
||||
AvatarData* _owningAvatar;
|
||||
private:
|
||||
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||
HeadData(const HeadData&);
|
||||
|
|
|
@ -8,4 +8,10 @@
|
|||
|
||||
#include "AgentData.h"
|
||||
|
||||
AgentData::AgentData(Agent* owningAgent) :
|
||||
_owningAgent(owningAgent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AgentData::~AgentData() {}
|
|
@ -3,16 +3,21 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 2/19/13.
|
||||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef hifi_AgentData_h
|
||||
#define hifi_AgentData_h
|
||||
|
||||
class Agent;
|
||||
|
||||
class AgentData {
|
||||
public:
|
||||
AgentData(Agent* owningAgent);
|
||||
virtual ~AgentData() = 0;
|
||||
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
||||
protected:
|
||||
Agent* _owningAgent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
VoxelAgentData::VoxelAgentData() :
|
||||
VoxelAgentData::VoxelAgentData(Agent* owningAgent) :
|
||||
AvatarData(owningAgent),
|
||||
_viewSent(false),
|
||||
_voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE),
|
||||
_maxSearchLevel(1),
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
class VoxelAgentData : public AvatarData {
|
||||
public:
|
||||
VoxelAgentData();
|
||||
VoxelAgentData(Agent* owningAgent);
|
||||
~VoxelAgentData();
|
||||
|
||||
void resetVoxelPacket(); // resets voxel packet to after "V" header
|
||||
|
|
|
@ -450,9 +450,9 @@ void *distributeVoxelsToListeners(void *args) {
|
|||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void attachVoxelAgentDataToAgent(Agent *newAgent) {
|
||||
void attachVoxelAgentDataToAgent(Agent* newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new VoxelAgentData());
|
||||
newAgent->setLinkedData(new VoxelAgentData(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue