Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philip Rosedale 2013-05-08 09:06:13 -07:00
commit 355cff21c5
19 changed files with 353 additions and 361 deletions

View file

@ -60,7 +60,7 @@ const float DISTANCE_RATIO = 3.0f / 0.3f;
const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5;
const int PHASE_DELAY_AT_90 = 20; const int PHASE_DELAY_AT_90 = 20;
const float MAX_OFF_AXIS_ATTENUATION = 0.5f; const float MAX_OFF_AXIS_ATTENUATION = 0.2f;
const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f; const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f;
void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) {
@ -111,7 +111,6 @@ void *sendBuffer(void *args) {
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData(); AudioRingBuffer* agentRingBuffer = (AudioRingBuffer*) agent->getLinkedData();
float agentBearing = agentRingBuffer->getBearing();
int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {}; int16_t clientMix[BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2] = {};
@ -120,6 +119,13 @@ void *sendBuffer(void *args) {
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData(); AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
if (otherAgentBuffer->shouldBeAddedToMix()) { if (otherAgentBuffer->shouldBeAddedToMix()) {
float bearingRelativeAngleToSource = 0.f;
float attenuationCoefficient = 1.f;
int numSamplesDelay = 0;
float weakChannelAmplitudeRatio = 1.f;
if (otherAgent != agent) {
float *agentPosition = agentRingBuffer->getPosition(); float *agentPosition = agentRingBuffer->getPosition();
float *otherAgentPosition = otherAgentBuffer->getPosition(); float *otherAgentPosition = otherAgentBuffer->getPosition();
@ -144,8 +150,7 @@ void *sendBuffer(void *args) {
float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]), float triangleAngle = atan2f(fabsf(agentPosition[2] - otherAgentPosition[2]),
fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI); fabsf(agentPosition[0] - otherAgentPosition[0])) * (180 / M_PI);
float absoluteAngleToSource = 0; float absoluteAngleToSource = 0;
float bearingRelativeAngleToSource = 0; bearingRelativeAngleToSource = 0;
// find the angle we need for calculation based on the orientation of the triangle // find the angle we need for calculation based on the orientation of the triangle
if (otherAgentPosition[0] > agentPosition[0]) { if (otherAgentPosition[0] > agentPosition[0]) {
@ -162,34 +167,38 @@ void *sendBuffer(void *args) {
} }
} }
if (absoluteAngleToSource > 180) { bearingRelativeAngleToSource = absoluteAngleToSource - agentRingBuffer->getBearing();
absoluteAngleToSource -= 360;
} else if (absoluteAngleToSource < -180) {
absoluteAngleToSource += 360;
}
bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; if (bearingRelativeAngleToSource > 180) {
bearingRelativeAngleToSource *= (M_PI / 180); bearingRelativeAngleToSource -= 360;
} else if (bearingRelativeAngleToSource < -180) {
bearingRelativeAngleToSource += 360;
}
float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing();
if (angleOfDelivery < -180) { if (angleOfDelivery > 180) {
angleOfDelivery -= 360;
} else if (angleOfDelivery < -180) {
angleOfDelivery += 360; angleOfDelivery += 360;
} }
float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
(OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f));
float attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex]
* otherAgentBuffer->getAttenuationRatio() * otherAgentBuffer->getAttenuationRatio()
* offAxisCoefficient; * offAxisCoefficient;
float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); bearingRelativeAngleToSource *= (M_PI / 180);
int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
float weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
int16_t* goodChannel = bearingRelativeAngleToSource > 0 ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix; float sinRatio = fabsf(sinf(bearingRelativeAngleToSource));
int16_t* delayedChannel = bearingRelativeAngleToSource > 0 ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
}
int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL : clientMix;
int16_t* delayedChannel = bearingRelativeAngleToSource > 0.0f ? clientMix : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer() int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer()
? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay
@ -208,8 +217,7 @@ void *sendBuffer(void *args) {
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay],
currentSample * currentSample * weakChannelAmplitudeRatio);
weakChannelAmplitudeRatio);
} }
} }
} }
@ -274,8 +282,8 @@ int main(int argc, const char* argv[]) {
if(agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if(agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) {
if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) { if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) {
if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentId())) { if (agentList->addOrUpdateAgent(agentAddress, agentAddress, packetData[0], agentList->getLastAgentID())) {
agentList->increaseAgentId(); agentList->increaseAgentID();
} }
agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); agentList->updateAgentWithData(agentAddress, packetData, receivedBytes);

View file

@ -88,15 +88,12 @@ int main(int argc, const char* argv[]) {
// send back a packet with other active agent data to this agent // send back a packet with other active agent data to this agent
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getLinkedData() != NULL if (agent->getLinkedData() && !socketMatch(agentAddress, agent->getActiveSocket())) {
&& !socketMatch(agentAddress, agent->getActiveSocket())) {
currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*agent); currentBufferPosition = addAgentToBroadcastPacket(currentBufferPosition, &*agent);
} }
} }
agentList->getAgentSocket().send(agentAddress, agentList->getAgentSocket().send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket);
broadcastPacket,
currentBufferPosition - broadcastPacket);
break; break;
case PACKET_HEADER_DOMAIN: case PACKET_HEADER_DOMAIN:

View file

@ -118,8 +118,8 @@ int main(int argc, const char * argv[])
if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress, if (agentList->addOrUpdateAgent((sockaddr*) &agentPublicAddress,
(sockaddr*) &agentLocalAddress, (sockaddr*) &agentLocalAddress,
agentType, agentType,
agentList->getLastAgentId())) { agentList->getLastAgentID())) {
agentList->increaseAgentId(); agentList->increaseAgentID();
} }
currentBufferPos = broadcastPacket + 1; currentBufferPos = broadcastPacket + 1;

View file

@ -17,7 +17,7 @@
const int EVE_AGENT_LISTEN_PORT = 55441; const int EVE_AGENT_LISTEN_PORT = 55441;
const float RANDOM_POSITION_MAX_DIMENSION = 5.0f; const float RANDOM_POSITION_MAX_DIMENSION = 10.0f;
const float DATA_SEND_INTERVAL_MSECS = 15; const float DATA_SEND_INTERVAL_MSECS = 15;
const float MIN_AUDIO_SEND_INTERVAL_SECS = 10; const float MIN_AUDIO_SEND_INTERVAL_SECS = 10;
@ -25,6 +25,12 @@ const int MIN_ITERATIONS_BETWEEN_AUDIO_SENDS = (MIN_AUDIO_SEND_INTERVAL_SECS * 1
const int MAX_AUDIO_SEND_INTERVAL_SECS = 15; const int MAX_AUDIO_SEND_INTERVAL_SECS = 15;
const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS; const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * 1000) / DATA_SEND_INTERVAL_MSECS;
const int ITERATIONS_BEFORE_HAND_GRAB = 100;
const int HAND_GRAB_DURATION_ITERATIONS = 50;
const int HAND_TIMER_SLEEP_ITERATIONS = 50;
const float EVE_PELVIS_HEIGHT = 0.5f;
bool stopReceiveAgentDataThread; bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false; bool injectAudioThreadRunning = false;
@ -48,7 +54,7 @@ void *receiveAgentData(void *args) {
// avatar mixer - this makes sure it won't be killed during silent agent removal // avatar mixer - this makes sure it won't be killed during silent agent removal
avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
if (avatarMixer != NULL) { if (avatarMixer) {
avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); avatarMixer->setLastHeardMicrostamp(usecTimestampNow());
} }
@ -73,9 +79,9 @@ void *injectAudio(void *args) {
// look for an audio mixer in our agent list // look for an audio mixer in our agent list
Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER); Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
if (audioMixer != NULL) { if (audioMixer) {
// until the audio mixer is setup for ping-reply, activate the public socket if it's not active // until the audio mixer is setup for ping-reply, activate the public socket if it's not active
if (audioMixer->getActiveSocket() == NULL) { if (!audioMixer->getActiveSocket()) {
audioMixer->activatePublicSocket(); audioMixer->activatePublicSocket();
} }
@ -113,9 +119,9 @@ int main(int argc, const char* argv[]) {
// move eve away from the origin // move eve away from the origin
// pick a random point inside a 10x10 grid // pick a random point inside a 10x10 grid
eve.setPosition(glm::vec3(randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION), eve.setPosition(glm::vec3(randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION),
1.33, // this should be the same as the avatar's pelvis standing height EVE_PELVIS_HEIGHT, // this should be the same as the avatar's pelvis standing height
randFloatInRange(-RANDOM_POSITION_MAX_DIMENSION, RANDOM_POSITION_MAX_DIMENSION))); randFloatInRange(0, RANDOM_POSITION_MAX_DIMENSION)));
// face any instance of eve down the z-axis // face any instance of eve down the z-axis
eve.setBodyYaw(0); eve.setBodyYaw(0);
@ -130,8 +136,6 @@ int main(int argc, const char* argv[]) {
unsigned char broadcastPacket[MAX_PACKET_SIZE]; unsigned char broadcastPacket[MAX_PACKET_SIZE];
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA; broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
int numBytesToSend = 0;
timeval thisSend; timeval thisSend;
double numMicrosecondsSleep = 0; double numMicrosecondsSleep = 0;
@ -145,15 +149,18 @@ int main(int argc, const char* argv[]) {
gettimeofday(&thisSend, NULL); gettimeofday(&thisSend, NULL);
// find the current avatar mixer // find the current avatar mixer
Agent *avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER); Agent* avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
// make sure we actually have an avatar mixer with an active socket // make sure we actually have an avatar mixer with an active socket
if (avatarMixer != NULL && avatarMixer->getActiveSocket() != NULL) { if (agentList->getOwnerID() != UNKNOWN_AGENT_ID && avatarMixer && avatarMixer->getActiveSocket() != NULL) {
unsigned char* packetPosition = broadcastPacket + sizeof(PACKET_HEADER);
packetPosition += packAgentId(packetPosition, agentList->getOwnerID());
// use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer // use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer
numBytesToSend = eve.getBroadcastData((broadcastPacket + 1)); packetPosition += eve.getBroadcastData(packetPosition);
// use the UDPSocket instance attached to our agent list to send avatar data to mixer // use the UDPSocket instance attached to our agent list to send avatar data to mixer
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, numBytesToSend); agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket);
} }
// temporarily disable Eve's audio sending until the file is actually available on EC2 box // temporarily disable Eve's audio sending until the file is actually available on EC2 box
@ -175,13 +182,12 @@ int main(int argc, const char* argv[]) {
// simulate the effect of pressing and un-pressing the mouse button/pad // simulate the effect of pressing and un-pressing the mouse button/pad
handStateTimer++; handStateTimer++;
if ( handStateTimer == 100 ) {
if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB) {
eve.setHandState(1); eve.setHandState(1);
} } else if (handStateTimer == ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS) {
if ( handStateTimer == 150 ) {
eve.setHandState(0); eve.setHandState(0);
} } else if (handStateTimer >= ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS + HAND_TIMER_SLEEP_ITERATIONS) {
if ( handStateTimer >= 200 ) {
handStateTimer = 0; handStateTimer = 0;
} }
} }

View file

@ -322,7 +322,6 @@ bool Avatar::getIsNearInteractingOther() {
void Avatar::simulate(float deltaTime) { void Avatar::simulate(float deltaTime) {
// update balls // update balls
if (_balls) { _balls->simulate(deltaTime); } if (_balls) { _balls->simulate(deltaTime); }
@ -504,7 +503,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
void Avatar::updateHead(float deltaTime) { void Avatar::updateHead(float deltaTime) {
//apply the head lean values to the springy position... //apply the head lean values to the springy position...
if (fabs( _head.leanSideways + _head.leanForward ) > 0.0f) { if (fabs(_head.leanSideways + _head.leanForward) > 0.0f) {
glm::vec3 headLean = glm::vec3 headLean =
_orientation.getRight() * _head.leanSideways + _orientation.getRight() * _head.leanSideways +
_orientation.getFront() * _head.leanForward; _orientation.getFront() * _head.leanForward;
@ -669,7 +668,7 @@ void Avatar::updateAvatarCollisions(float deltaTime) {
glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position); glm::vec3 vectorBetweenBoundingSpheres(_position - otherAvatar->_position);
if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) { if (glm::length(vectorBetweenBoundingSpheres) < _height * ONE_HALF + otherAvatar->_height * ONE_HALF) {
//apply forces from collision //apply forces from collision
applyCollisionWithOtherAvatar(otherAvatar, deltaTime ); applyCollisionWithOtherAvatar(otherAvatar, deltaTime);
} }
// test other avatar hand position for proximity // test other avatar hand position for proximity
@ -703,7 +702,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition); glm::vec3 vectorBetweenJoints(_joint[b].springyPosition - otherAvatar->_joint[o].springyPosition);
float distanceBetweenJoints = glm::length(vectorBetweenJoints); float distanceBetweenJoints = glm::length(vectorBetweenJoints);
if (distanceBetweenJoints > 0.0 ) { // to avoid divide by zero if (distanceBetweenJoints > 0.0) { // to avoid divide by zero
float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius; float combinedRadius = _joint[b].radius + otherAvatar->_joint[o].radius;
// check for collision // check for collision
@ -714,7 +713,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime; glm::vec3 ballPushForce = directionVector * COLLISION_BALL_FORCE * deltaTime;
float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime; float ballMomentum = 1.0 - COLLISION_BALL_FRICTION * deltaTime;
if (ballMomentum < 0.0 ) { ballMomentum = 0.0;} if (ballMomentum < 0.0) { ballMomentum = 0.0;}
_joint[b].springyVelocity += ballPushForce; _joint[b].springyVelocity += ballPushForce;
otherAvatar->_joint[o].springyVelocity -= ballPushForce; otherAvatar->_joint[o].springyVelocity -= ballPushForce;
@ -725,7 +724,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
// accumulate forces and frictions to apply to the velocities of avatar bodies // accumulate forces and frictions to apply to the velocities of avatar bodies
bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime; bodyPushForce += directionVector * COLLISION_BODY_FORCE * deltaTime;
bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime; bodyMomentum -= COLLISION_BODY_FRICTION * deltaTime;
if (bodyMomentum < 0.0 ) { bodyMomentum = 0.0;} if (bodyMomentum < 0.0) { bodyMomentum = 0.0;}
}// check for collision }// check for collision
} // to avoid divide by zero } // to avoid divide by zero
@ -744,7 +743,7 @@ void Avatar::applyCollisionWithOtherAvatar(Avatar * otherAvatar, float deltaTime
void Avatar::setDisplayingHead(bool displayingHead ) { void Avatar::setDisplayingHead(bool displayingHead) {
_displayingHead = displayingHead; _displayingHead = displayingHead;
} }
@ -763,25 +762,25 @@ void Avatar::setGravity(glm::vec3 gravity) {
void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) { void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
// render a simple round on the ground projected down from the avatar's position // 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 ); renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f);
/* /*
// show avatar position // show avatar position
glColor4f(0.5f, 0.5f, 0.5f, 0.6 ); glColor4f(0.5f, 0.5f, 0.5f, 0.6);
glPushMatrix(); glPushMatrix();
glTranslatef(_position.x, _position.y, _position.z); glTranslatef(_position.x, _position.y, _position.z);
glScalef(0.03, 0.03, 0.03 ); glScalef(0.03, 0.03, 0.03);
glutSolidSphere(1, 10, 10 ); glutSolidSphere(1, 10, 10);
glPopMatrix(); glPopMatrix();
*/ */
if (usingBigSphereCollisionTest ) { if (usingBigSphereCollisionTest) {
// show TEST big sphere // show TEST big sphere
glColor4f(0.5f, 0.6f, 0.8f, 0.7 ); glColor4f(0.5f, 0.6f, 0.8f, 0.7);
glPushMatrix(); glPushMatrix();
glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z);
glScalef(_TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius ); glScalef(_TEST_bigSphereRadius, _TEST_bigSphereRadius, _TEST_bigSphereRadius);
glutSolidSphere(1, 20, 20 ); glutSolidSphere(1, 20, 20);
glPopMatrix(); glPopMatrix();
} }
@ -794,7 +793,7 @@ void Avatar::render(bool lookingInMirror, glm::vec3 cameraPosition) {
} }
// if this is my avatar, then render my interactions with the other avatar // if this is my avatar, then render my interactions with the other avatar
if (_isMine ) { if (_isMine) {
_avatarTouch.render(cameraPosition); _avatarTouch.render(cameraPosition);
} }
@ -855,7 +854,7 @@ void Avatar::renderHead(bool lookingInMirror) {
glEnable(GL_RESCALE_NORMAL); glEnable(GL_RESCALE_NORMAL);
// show head orientation // show head orientation
//renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f ); //renderOrientationDirections(_joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition, _joint[ AVATAR_JOINT_HEAD_BASE ].orientation, 0.2f);
glPushMatrix(); glPushMatrix();
@ -883,7 +882,7 @@ void Avatar::renderHead(bool lookingInMirror) {
//glRotatef(_bodyPitch + _headPitch, 1, 0, 0); //glRotatef(_bodyPitch + _headPitch, 1, 0, 0);
//glRotatef(_bodyRoll - _headRoll, 0, 0, 1); //glRotatef(_bodyRoll - _headRoll, 0, 0, 1);
// don't let body pitch and roll affect the head.. // don't let body pitch and roll affect the head..
glRotatef( _headPitch, 1, 0, 0); glRotatef(_headPitch, 1, 0, 0);
glRotatef(-_headRoll, 0, 0, 1); glRotatef(-_headRoll, 0, 0, 1);
} else { } else {
glRotatef(_bodyYaw + _headYaw, 0, 1, 0); glRotatef(_bodyYaw + _headYaw, 0, 1, 0);
@ -1020,7 +1019,7 @@ void Avatar::renderHead(bool lookingInMirror) {
glPopMatrix(); glPopMatrix();
} }
void Avatar::setHandMovementValues(glm::vec3 handOffset ) { void Avatar::setHandMovementValues(glm::vec3 handOffset) {
_movedHandOffset = handOffset; _movedHandOffset = handOffset;
} }
@ -1033,11 +1032,11 @@ void Avatar::initializeSkeleton() {
for (int b=0; b<NUM_AVATAR_JOINTS; b++) { for (int b=0; b<NUM_AVATAR_JOINTS; b++) {
_joint[b].isCollidable = true; _joint[b].isCollidable = true;
_joint[b].parent = AVATAR_JOINT_NULL; _joint[b].parent = AVATAR_JOINT_NULL;
_joint[b].position = glm::vec3(0.0, 0.0, 0.0 ); _joint[b].position = glm::vec3(0.0, 0.0, 0.0);
_joint[b].defaultPosePosition = glm::vec3(0.0, 0.0, 0.0 ); _joint[b].defaultPosePosition = glm::vec3(0.0, 0.0, 0.0);
_joint[b].springyPosition = glm::vec3(0.0, 0.0, 0.0 ); _joint[b].springyPosition = glm::vec3(0.0, 0.0, 0.0);
_joint[b].springyVelocity = glm::vec3(0.0, 0.0, 0.0 ); _joint[b].springyVelocity = glm::vec3(0.0, 0.0, 0.0);
_joint[b].rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f ); _joint[b].rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
_joint[b].yaw = 0.0; _joint[b].yaw = 0.0;
_joint[b].pitch = 0.0; _joint[b].pitch = 0.0;
_joint[b].roll = 0.0; _joint[b].roll = 0.0;
@ -1079,8 +1078,8 @@ void Avatar::initializeSkeleton() {
_joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.09, 0.0 ); _joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.09, 0.0 );
_joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, -0.01 ); _joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.1, -0.01 );
_joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.01 ); _joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.08, 0.01 );
_joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3(-0.06, 0.04, -0.01 ); _joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.06, 0.04, -0.01 );
_joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3(-0.03, 0.0, -0.01 ); _joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.03, 0.0, -0.01 );
_joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 ); _joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.13, 0.0 );
_joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 ); _joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.11, 0.0 );
_joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 ); _joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.07, 0.0 );
@ -1181,7 +1180,7 @@ void Avatar::initializeSkeleton() {
_joint[ AVATAR_JOINT_HEAD_BASE ].length + _joint[ AVATAR_JOINT_HEAD_BASE ].length +
_joint[ AVATAR_JOINT_HEAD_BASE ].radius _joint[ AVATAR_JOINT_HEAD_BASE ].radius
); );
//printf( "_height = %f\n", _height ); //printf("_height = %f\n", _height);
// generate world positions // generate world positions
updateSkeleton(); updateSkeleton();
@ -1192,7 +1191,7 @@ void Avatar::initializeSkeleton() {
void Avatar::calculateBoneLengths() { void Avatar::calculateBoneLengths() {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
_joint[b].length = glm::length( _joint[b].defaultPosePosition ); _joint[b].length = glm::length(_joint[b].defaultPosePosition);
} }
_maxArmLength _maxArmLength
@ -1205,35 +1204,35 @@ void Avatar::updateSkeleton() {
// rotate body... // rotate body...
_orientation.setToIdentity(); _orientation.setToIdentity();
_orientation.yaw ( _bodyYaw ); _orientation.yaw (_bodyYaw );
_orientation.pitch( _bodyPitch ); _orientation.pitch(_bodyPitch);
_orientation.roll ( _bodyRoll ); _orientation.roll (_bodyRoll );
// calculate positions of all bones by traversing the skeleton tree: // calculate positions of all bones by traversing the skeleton tree:
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
if ( _joint[b].parent == AVATAR_JOINT_NULL ) { if (_joint[b].parent == AVATAR_JOINT_NULL) {
_joint[b].orientation.set( _orientation ); _joint[b].orientation.set(_orientation);
_joint[b].position = _position; _joint[b].position = _position;
} }
else { else {
_joint[b].orientation.set( _joint[ _joint[b].parent ].orientation ); _joint[b].orientation.set(_joint[ _joint[b].parent ].orientation);
_joint[b].position = _joint[ _joint[b].parent ].position; _joint[b].position = _joint[ _joint[b].parent ].position;
} }
// if this is not my avatar, then hand position comes from transmitted data // if this is not my avatar, then hand position comes from transmitted data
if ( ! _isMine ) { if (! _isMine) {
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition; _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
} }
// the following will be replaced by a proper rotation...close // the following will be replaced by a proper rotation...close
float xx = glm::dot( _joint[b].defaultPosePosition, _joint[b].orientation.getRight() ); float xx = glm::dot(_joint[b].defaultPosePosition, _joint[b].orientation.getRight());
float yy = glm::dot( _joint[b].defaultPosePosition, _joint[b].orientation.getUp () ); float yy = glm::dot(_joint[b].defaultPosePosition, _joint[b].orientation.getUp ());
float zz = glm::dot( _joint[b].defaultPosePosition, _joint[b].orientation.getFront() ); float zz = glm::dot(_joint[b].defaultPosePosition, _joint[b].orientation.getFront());
glm::vec3 rotatedJointVector( xx, yy, zz ); glm::vec3 rotatedJointVector(xx, yy, zz);
//glm::vec3 myEuler ( 0.0f, 0.0f, 0.0f ); //glm::vec3 myEuler (0.0f, 0.0f, 0.0f);
//glm::quat myQuat ( myEuler ); //glm::quat myQuat (myEuler);
_joint[b].position += rotatedJointVector; _joint[b].position += rotatedJointVector;
} }
@ -1242,31 +1241,31 @@ void Avatar::updateSkeleton() {
void Avatar::initializeBodySprings() { void Avatar::initializeBodySprings() {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
_joint[b].springyPosition = _joint[b].position; _joint[b].springyPosition = _joint[b].position;
_joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); _joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
} }
} }
void Avatar::updateBodySprings( float deltaTime ) { void Avatar::updateBodySprings(float deltaTime) {
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
glm::vec3 springVector( _joint[b].springyPosition ); glm::vec3 springVector(_joint[b].springyPosition);
if ( _joint[b].parent == AVATAR_JOINT_NULL ) { if (_joint[b].parent == AVATAR_JOINT_NULL) {
springVector -= _position; springVector -= _position;
} }
else { else {
springVector -= _joint[ _joint[b].parent ].springyPosition; springVector -= _joint[ _joint[b].parent ].springyPosition;
} }
float length = glm::length( springVector ); float length = glm::length(springVector);
if ( length > 0.0f ) { if (length > 0.0f) {
glm::vec3 springDirection = springVector / length; glm::vec3 springDirection = springVector / length;
float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime; float force = (length - _joint[b].length) * BODY_SPRING_FORCE * deltaTime;
_joint[b].springyVelocity -= springDirection * force; _joint[b].springyVelocity -= springDirection * force;
if ( _joint[b].parent != AVATAR_JOINT_NULL ) { if (_joint[b].parent != AVATAR_JOINT_NULL) {
_joint[_joint[b].parent].springyVelocity += springDirection * force; _joint[_joint[b].parent].springyVelocity += springDirection * force;
} }
} }
@ -1279,7 +1278,7 @@ void Avatar::updateBodySprings( float deltaTime ) {
_joint[b].springyVelocity *= decay; _joint[b].springyVelocity *= decay;
} }
else { else {
_joint[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); _joint[b].springyVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
} }
_joint[b].springyPosition += _joint[b].springyVelocity * deltaTime; _joint[b].springyPosition += _joint[b].springyVelocity * deltaTime;
@ -1298,17 +1297,17 @@ const glm::vec3& Avatar::getHeadPosition() const {
void Avatar::updateArmIKAndConstraints( float deltaTime ) { void Avatar::updateArmIKAndConstraints(float deltaTime) {
// determine the arm vector // determine the arm vector
glm::vec3 armVector = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; glm::vec3 armVector = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position;
armVector -= _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; armVector -= _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position;
// test to see if right hand is being dragged beyond maximum arm length // test to see if right hand is being dragged beyond maximum arm length
float distance = glm::length( armVector ); float distance = glm::length(armVector);
// don't let right hand get dragged beyond maximum arm length... // don't let right hand get dragged beyond maximum arm length...
if ( distance > _maxArmLength ) { if (distance > _maxArmLength) {
// reset right hand to be constrained to maximum arm length // reset right hand to be constrained to maximum arm length
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position;
glm::vec3 armNormal = armVector / distance; glm::vec3 armNormal = armVector / distance;
@ -1323,13 +1322,13 @@ void Avatar::updateArmIKAndConstraints( float deltaTime ) {
glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position; glm::vec3 newElbowPosition = _joint[ AVATAR_JOINT_RIGHT_SHOULDER ].position;
newElbowPosition += armVector * ONE_HALF; newElbowPosition += armVector * ONE_HALF;
glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); glm::vec3 perpendicular = glm::cross(_orientation.getFront(), armVector);
newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; newElbowPosition += perpendicular * (1.0f - (_maxArmLength / distance)) * ONE_HALF;
_joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition; _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position = newElbowPosition;
// set wrist position // set wrist position
glm::vec3 vv( _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); glm::vec3 vv(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position);
vv -= _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position; vv -= _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position;
glm::vec3 newWristPosition = _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f; glm::vec3 newWristPosition = _joint[ AVATAR_JOINT_RIGHT_ELBOW ].position + vv * 0.7f;
_joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition; _joint[ AVATAR_JOINT_RIGHT_WRIST ].position = newWristPosition;
@ -1341,53 +1340,53 @@ void Avatar::renderBody() {
// Render joint positions as spheres // Render joint positions as spheres
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) { for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
if ( b != AVATAR_JOINT_HEAD_BASE ) { // the head is rendered as a special case in "renderHead" if (b != AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case in "renderHead"
//render bone orientation //render bone orientation
//renderOrientationDirections( _joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0 ); //renderOrientationDirections(_joint[b].springyPosition, _joint[b].orientation, _joint[b].radius * 2.0);
if ( _usingBodySprings ) { if (_usingBodySprings) {
glColor3fv( skinColor ); glColor3fv(skinColor);
glPushMatrix(); glPushMatrix();
glTranslatef( _joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z ); glTranslatef(_joint[b].springyPosition.x, _joint[b].springyPosition.y, _joint[b].springyPosition.z);
glutSolidSphere( _joint[b].radius, 20.0f, 20.0f ); glutSolidSphere(_joint[b].radius, 20.0f, 20.0f);
glPopMatrix(); glPopMatrix();
} }
else { else {
glColor3fv( skinColor ); glColor3fv(skinColor);
glPushMatrix(); glPushMatrix();
glTranslatef( _joint[b].position.x, _joint[b].position.y, _joint[b].position.z ); glTranslatef(_joint[b].position.x, _joint[b].position.y, _joint[b].position.z);
glutSolidSphere( _joint[b].radius, 20.0f, 20.0f ); glutSolidSphere(_joint[b].radius, 20.0f, 20.0f);
glPopMatrix(); glPopMatrix();
} }
} }
} }
// Render lines connecting the joint positions // Render lines connecting the joint positions
if ( _usingBodySprings ) { if (_usingBodySprings) {
glColor3f( 0.4f, 0.5f, 0.6f ); glColor3f(0.4f, 0.5f, 0.6f);
glLineWidth(3.0); glLineWidth(3.0);
for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { for (int b = 1; b < NUM_AVATAR_JOINTS; b++) {
if ( _joint[b].parent != AVATAR_JOINT_NULL ) if (_joint[b].parent != AVATAR_JOINT_NULL)
if ( b != AVATAR_JOINT_HEAD_TOP ) { if (b != AVATAR_JOINT_HEAD_TOP) {
glBegin( GL_LINE_STRIP ); glBegin(GL_LINE_STRIP);
glVertex3fv( &_joint[ _joint[ b ].parent ].springyPosition.x ); glVertex3fv(&_joint[ _joint[ b ].parent ].springyPosition.x);
glVertex3fv( &_joint[ b ].springyPosition.x ); glVertex3fv(&_joint[ b ].springyPosition.x);
glEnd(); glEnd();
} }
} }
} }
/* /*
else { else {
glColor3fv( skinColor ); glColor3fv(skinColor);
glLineWidth(3.0); glLineWidth(3.0);
for (int b = 1; b < NUM_AVATAR_JOINTS; b++) { for (int b = 1; b < NUM_AVATAR_JOINTS; b++) {
if ( _joint[b].parent != AVATAR_JOINT_NULL ) { if (_joint[b].parent != AVATAR_JOINT_NULL) {
glBegin( GL_LINE_STRIP ); glBegin(GL_LINE_STRIP);
glVertex3fv( &_joint[ _joint[ b ].parent ].position.x ); glVertex3fv(&_joint[ _joint[ b ].parent ].position.x);
glVertex3fv( &_joint[ b ].position.x); glVertex3fv(&_joint[ b ].position.x);
glEnd(); glEnd();
} }
} }
@ -1450,9 +1449,7 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) {
//printLog("Packet: [%s]\n", packetData); //printLog("Packet: [%s]\n", packetData);
//printLog("Version: %s\n", device); //printLog("Version: %s\n", device);
_transmitterInitialReading = glm::vec3( rot3, _transmitterInitialReading = glm::vec3(rot3, rot2, rot1);
rot2,
rot1 );
} }
const int TRANSMITTER_COUNT = 100; const int TRANSMITTER_COUNT = 100;
if (_transmitterPackets % TRANSMITTER_COUNT == 0) { if (_transmitterPackets % TRANSMITTER_COUNT == 0) {
@ -1460,7 +1457,7 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) {
timeval now; timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
double msecsElapsed = diffclock(&_transmitterTimer, &now); double msecsElapsed = diffclock(&_transmitterTimer, &now);
_transmitterHz = static_cast<float>( (double)TRANSMITTER_COUNT / (msecsElapsed / 1000.0) ); _transmitterHz = static_cast<float>((double)TRANSMITTER_COUNT / (msecsElapsed / 1000.0));
_transmitterTimer = now; _transmitterTimer = now;
printLog("Transmitter Hz: %3.1f\n", _transmitterHz); printLog("Transmitter Hz: %3.1f\n", _transmitterHz);
} }
@ -1477,12 +1474,12 @@ void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) {
glm::vec3 angularVelocity; glm::vec3 angularVelocity;
if (deviceType != DEVICE_GLASS) { if (deviceType != DEVICE_GLASS) {
angularVelocity = glm::vec3(glm::degrees(gyrZ), glm::degrees(-gyrX), glm::degrees(gyrY)); angularVelocity = glm::vec3(glm::degrees(gyrZ), glm::degrees(-gyrX), glm::degrees(gyrY));
setHeadFromGyros( &eulerAngles, &angularVelocity, setHeadFromGyros(&eulerAngles, &angularVelocity,
(_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1.0); (_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1.0);
} else { } else {
angularVelocity = glm::vec3(glm::degrees(gyrY), glm::degrees(-gyrX), glm::degrees(-gyrZ)); angularVelocity = glm::vec3(glm::degrees(gyrY), glm::degrees(-gyrX), glm::degrees(-gyrZ));
setHeadFromGyros( &eulerAngles, &angularVelocity, setHeadFromGyros(&eulerAngles, &angularVelocity,
(_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1000.0); (_transmitterHz == 0.f) ? 0.f : 1.f / _transmitterHz, 1000.0);
} }

View file

@ -16,10 +16,10 @@ const float THREAD_RADIUS = 0.012;
AvatarTouch::AvatarTouch() { AvatarTouch::AvatarTouch() {
_myHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_yourHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_myBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_yourBodyPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f);
_myHandState = 0; _myHandState = 0;
_yourHandState = 0; _yourHandState = 0;
_reachableRadius = 0.0f; _reachableRadius = 0.0f;
@ -28,7 +28,7 @@ AvatarTouch::AvatarTouch() {
_handsCloseEnoughToGrasp = false; _handsCloseEnoughToGrasp = false;
for (int p=0; p<NUM_POINTS; p++) { for (int p=0; p<NUM_POINTS; p++) {
_point[p] = glm::vec3( 0.0, 0.0, 0.0 ); _point[p] = glm::vec3(0.0, 0.0, 0.0);
} }
} }
@ -65,7 +65,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_canReachToOtherAvatar) { if (_canReachToOtherAvatar) {
glColor4f( 0.3, 0.4, 0.5, 0.5 ); glColor4f(0.3, 0.4, 0.5, 0.5);
glm::vec3 p(_yourBodyPosition); glm::vec3 p(_yourBodyPosition);
p.y = 0.0005f; p.y = 0.0005f;
renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30);
@ -74,9 +74,9 @@ void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_yourHandState == 1) { if (_yourHandState == 1) {
glPushMatrix(); glPushMatrix();
glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z);
glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.8, 0.3); glutSolidSphere(0.020f, 10.0f, 10.0f);
glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.4, 0.2); glutSolidSphere(0.025f, 10.0f, 10.0f);
glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f);
glPopMatrix(); glPopMatrix();
} }
@ -86,13 +86,13 @@ void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_handsCloseEnoughToGrasp) { if (_handsCloseEnoughToGrasp) {
glLineWidth(2.0); glLineWidth(2.0);
glColor4f( 0.7f, 0.4f, 0.1f, 0.3 ); glColor4f(0.7f, 0.4f, 0.1f, 0.3);
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glVertex3f( v1.x, v1.y, v1.z ); glVertex3f(v1.x, v1.y, v1.z);
glVertex3f( v2.x, v2.y, v2.z ); glVertex3f(v2.x, v2.y, v2.z);
glEnd(); glEnd();
glColor4f( 1.0f, 1.0f, 0.0f, 0.8 ); glColor4f(1.0f, 1.0f, 0.0f, 0.8);
for (int p=0; p<NUM_POINTS; p++) { for (int p=0; p<NUM_POINTS; p++) {
glBegin(GL_POINTS); glBegin(GL_POINTS);
@ -106,9 +106,9 @@ void AvatarTouch::render(glm::vec3 cameraPosition) {
if (_myHandState == 1) { if (_myHandState == 1) {
glPushMatrix(); glPushMatrix();
glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z);
glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.8, 0.3); glutSolidSphere(0.020f, 10.0f, 10.0f);
glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.4, 0.2); glutSolidSphere(0.025f, 10.0f, 10.0f);
glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f ); glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f);
glPopMatrix(); glPopMatrix();
} }
} }
@ -120,7 +120,7 @@ void AvatarTouch::simulate (float deltaTime) {
float distance = glm::length(v); float distance = glm::length(v);
if (distance < _reachableRadius ) { if (distance < _reachableRadius) {
_canReachToOtherAvatar = true; _canReachToOtherAvatar = true;
} else { } else {
_canReachToOtherAvatar = false; _canReachToOtherAvatar = false;
@ -129,10 +129,10 @@ void AvatarTouch::simulate (float deltaTime) {
/* /*
for (int p=0; p<NUM_POINTS; p++) { for (int p=0; p<NUM_POINTS; p++) {
_point[p] = _myHandPosition + v * ( (float)p / (float)NUM_POINTS ); _point[p] = _myHandPosition + v * ((float)p / (float)NUM_POINTS);
_point[p].x += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS ); _point[p].x += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
_point[p].y += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS ); _point[p].y += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
_point[p].z += randFloatInRange( -THREAD_RADIUS, THREAD_RADIUS ); _point[p].z += randFloatInRange(-THREAD_RADIUS, THREAD_RADIUS);
} }
*/ */

View file

@ -26,24 +26,24 @@ Camera::Camera() {
_rightShift = 0.0; _rightShift = 0.0;
_distance = 0.0; _distance = 0.0;
_idealYaw = 0.0; _idealYaw = 0.0;
_targetPosition = glm::vec3( 0.0, 0.0, 0.0 ); _targetPosition = glm::vec3(0.0, 0.0, 0.0);
_position = 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 ); _idealPosition = glm::vec3(0.0, 0.0, 0.0);
_orientation.setToIdentity(); _orientation.setToIdentity();
} }
void Camera::update( float deltaTime ) { void Camera::update(float deltaTime) {
if ( _mode == CAMERA_MODE_NULL ) { if (_mode == CAMERA_MODE_NULL) {
_modeShift = 0.0; _modeShift = 0.0;
} else { } else {
// use iterative forces to keep the camera at the desired position and angle // use iterative forces to keep the camera at the desired position and angle
updateFollowMode( deltaTime ); updateFollowMode(deltaTime);
if ( _modeShift < 1.0f ) { if (_modeShift < 1.0f) {
_modeShift += MODE_SHIFT_RATE * deltaTime; _modeShift += MODE_SHIFT_RATE * deltaTime;
if ( _modeShift > 1.0f ) { if (_modeShift > 1.0f) {
_modeShift = 1.0f; _modeShift = 1.0f;
} }
} }
@ -53,22 +53,19 @@ void Camera::update( float deltaTime ) {
generateOrientation(); generateOrientation();
} }
// generate the ortho-normals for the orientation based on the three Euler angles // generate the ortho-normals for the orientation based on the three Euler angles
void Camera::generateOrientation() { void Camera::generateOrientation() {
_orientation.setToIdentity(); _orientation.setToIdentity();
_orientation.pitch( _pitch ); _orientation.pitch(_pitch);
_orientation.yaw ( _yaw ); _orientation.yaw (_yaw );
_orientation.roll ( _roll ); _orientation.roll (_roll );
} }
// use iterative forces to keep the camera at the desired position and angle // use iterative forces to keep the camera at the desired position and angle
void Camera::updateFollowMode( float deltaTime ) { void Camera::updateFollowMode(float deltaTime) {
// derive t from tightness // derive t from tightness
float t = _tightness * deltaTime; float t = _tightness * deltaTime;
if ( t > 1.0 ) { if (t > 1.0) {
t = 1.0; t = 1.0;
} }
@ -114,8 +111,6 @@ void Camera::setFarClip (float f) {
_frustumNeedsReshape = true; _frustumNeedsReshape = true;
} }
// call to find out if the view frustum needs to be reshaped // call to find out if the view frustum needs to be reshaped
bool Camera::getFrustumNeedsReshape() { bool Camera::getFrustumNeedsReshape() {
return _frustumNeedsReshape; return _frustumNeedsReshape;

View file

@ -33,14 +33,14 @@ HandControl::HandControl() {
_envelope = 0.0f; _envelope = 0.0f;
} }
void HandControl::setScreenDimensions( int width, int height ) { void HandControl::setScreenDimensions(int width, int height) {
_width = width; _width = width;
_height = height; _height = height;
_startX = _width / 2; _startX = _width / 2;
_startY = _height / 2; _startY = _height / 2;
} }
void HandControl::update( int x, int y ) { void HandControl::update(int x, int y) {
_lastX = _x; _lastX = _x;
_lastY = _y; _lastY = _y;
_x = x; _x = x;
@ -49,22 +49,22 @@ void HandControl::update( int x, int y ) {
_velocityY = _y - _lastY; _velocityY = _y - _lastY;
// if the mouse is moving, ramp up the envelope to increase amplitude of hand movement... // if the mouse is moving, ramp up the envelope to increase amplitude of hand movement...
if (( _velocityX != 0 ) if ((_velocityX != 0)
|| ( _velocityY != 0 )) { || (_velocityY != 0)) {
_enabled = true; _enabled = true;
if ( _envelope < 1.0 ) { if (_envelope < 1.0) {
_envelope += _rampUpRate; _envelope += _rampUpRate;
if ( _envelope >= 1.0 ) { if (_envelope >= 1.0) {
_envelope = 1.0; _envelope = 1.0;
} }
} }
} }
// if not enabled ramp down the envelope to decrease amplitude of hand movement... // if not enabled ramp down the envelope to decrease amplitude of hand movement...
if ( ! _enabled ) { if (! _enabled) {
if ( _envelope > 0.0 ) { if (_envelope > 0.0) {
_envelope -= _rampDownRate; _envelope -= _rampDownRate;
if ( _envelope <= 0.0 ) { if (_envelope <= 0.0) {
_startX = _width / 2; _startX = _width / 2;
_startY = _height / 2; _startY = _height / 2;
_envelope = 0.0; _envelope = 0.0;
@ -77,14 +77,14 @@ void HandControl::update( int x, int y ) {
_backFront = 0.0; _backFront = 0.0;
// if envelope is greater than zero, apply mouse movement to values to be output // if envelope is greater than zero, apply mouse movement to values to be output
if ( _envelope > 0.0 ) { if (_envelope > 0.0) {
_leftRight += ( ( _x - _startX ) / (float)_width ) * _envelope; _leftRight += ((_x - _startX) / (float)_width ) * _envelope;
_downUp += ( ( _y - _startY ) / (float)_height ) * _envelope; _downUp += ((_y - _startY) / (float)_height) * _envelope;
} }
} }
glm::vec3 HandControl::getValues() { glm::vec3 HandControl::getValues() {
return glm::vec3( _leftRight, _downUp, _backFront ); return glm::vec3(_leftRight, _downUp, _backFront);
} }
void HandControl::stop() { void HandControl::stop() {

View file

@ -33,12 +33,6 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to
const bool USING_INVENSENSE_MPU9150 = 1; const bool USING_INVENSENSE_MPU9150 = 1;
SerialInterface::~SerialInterface() {
#ifdef __APPLE__
close(_serialDescriptor);
#endif
}
void SerialInterface::pair() { void SerialInterface::pair() {
#ifdef __APPLE__ #ifdef __APPLE__

View file

@ -38,7 +38,6 @@ class SerialInterface {
public: public:
SerialInterface() : active(false), SerialInterface() : active(false),
_failedOpenAttempts(0) {} _failedOpenAttempts(0) {}
~SerialInterface();
void pair(); void pair();
void readData(); void readData();

View file

@ -199,7 +199,7 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
// Draws text on screen as stroked so it can be resized // Draws text on screen as stroked so it can be resized
// //
glPushMatrix(); glPushMatrix();
glTranslatef( static_cast<float>(x), static_cast<float>(y), 0.0f); glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
glColor3f(r,g,b); glColor3f(r,g,b);
glRotated(rotate,0,0,1); glRotated(rotate,0,0,1);
// glLineWidth(thick); // glLineWidth(thick);
@ -235,7 +235,7 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
void drawGroundPlaneGrid(float size) { void drawGroundPlaneGrid(float size) {
glColor3f( 0.4f, 0.5f, 0.3f ); glColor3f(0.4f, 0.5f, 0.3f);
glLineWidth(2.0); glLineWidth(2.0);
for (float x = 0; x <= size; x++) { for (float x = 0; x <= size; x++) {
@ -261,7 +261,7 @@ void drawGroundPlaneGrid(float size) {
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness) { void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness) {
glColor4f( 0.0f, 0.0f, 0.0f, darkness ); glColor4f(0.0f, 0.0f, 0.0f, darkness);
int num = 20; int num = 20;
float y = 0.001f; float y = 0.001f;
@ -291,7 +291,7 @@ void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, f
void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition) { void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition) {
glm::vec3 vectorToPosition(glm::normalize(position - cameraPosition)); glm::vec3 vectorToPosition(glm::normalize(position - cameraPosition));
glm::vec3 right = glm::cross(vectorToPosition, glm::vec3( 0.0f, 1.0f, 0.0f)); glm::vec3 right = glm::cross(vectorToPosition, glm::vec3(0.0f, 1.0f, 0.0f));
glm::vec3 up = glm::cross(right, vectorToPosition); glm::vec3 up = glm::cross(right, vectorToPosition);
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
@ -312,7 +312,7 @@ void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::ve
} }
void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ) { void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides) {
glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x); glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x);
glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y); glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y);
@ -333,27 +333,27 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int
} }
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ) { void renderOrientationDirections(glm::vec3 position, Orientation orientation, float size) {
glm::vec3 pRight = position + orientation.getRight() * size; glm::vec3 pRight = position + orientation.getRight() * size;
glm::vec3 pUp = position + orientation.getUp() * size; glm::vec3 pUp = position + orientation.getUp () * size;
glm::vec3 pFront = position + orientation.getFront() * size; glm::vec3 pFront = position + orientation.getFront() * size;
glColor3f( 1.0f, 0.0f, 0.0f ); glColor3f(1.0f, 0.0f, 0.0f);
glBegin( GL_LINE_STRIP ); glBegin(GL_LINE_STRIP);
glVertex3f( position.x, position.y, position.z ); glVertex3f(position.x, position.y, position.z);
glVertex3f( pRight.x, pRight.y, pRight.z ); glVertex3f(pRight.x, pRight.y, pRight.z);
glEnd(); glEnd();
glColor3f( 0.0f, 1.0f, 0.0f ); glColor3f(0.0f, 1.0f, 0.0f);
glBegin( GL_LINE_STRIP ); glBegin(GL_LINE_STRIP);
glVertex3f( position.x, position.y, position.z ); glVertex3f(position.x, position.y, position.z);
glVertex3f( pUp.x, pUp.y, pUp.z ); glVertex3f(pUp.x, pUp.y, pUp.z);
glEnd(); glEnd();
glColor3f( 0.0f, 0.0f, 1.0f ); glColor3f(0.0f, 0.0f, 1.0f);
glBegin( GL_LINE_STRIP ); glBegin(GL_LINE_STRIP);
glVertex3f( position.x, position.y, position.z ); glVertex3f(position.x, position.y, position.z);
glVertex3f( pFront.x, pFront.y, pFront.z ); glVertex3f(pFront.x, pFront.y, pFront.z);
glEnd(); glEnd();
} }

View file

@ -429,7 +429,7 @@ void updateAvatar(float frametime) {
myAvatar.setCameraNearClip(::viewFrustum.getNearClip()); myAvatar.setCameraNearClip(::viewFrustum.getNearClip());
myAvatar.setCameraFarClip(::viewFrustum.getFarClip()); myAvatar.setCameraFarClip(::viewFrustum.getFarClip());
AgentList *agentList = AgentList::getInstance(); AgentList* agentList = AgentList::getInstance();
if (agentList->getOwnerID() != UNKNOWN_AGENT_ID) { if (agentList->getOwnerID() != UNKNOWN_AGENT_ID) {
// if I know my ID, send head/hand data to the avatar mixer and voxel server // if I know my ID, send head/hand data to the avatar mixer and voxel server
@ -451,9 +451,9 @@ void updateAvatar(float frametime) {
glm::vec3 avatarPos = myAvatar.getPosition(); glm::vec3 avatarPos = myAvatar.getPosition();
// For some reason, we don't want to flip X and Z here. // For some reason, we don't want to flip X and Z here.
::paintingVoxel.x = avatarPos.x/10.0; ::paintingVoxel.x = avatarPos.x / 10.0;
::paintingVoxel.y = avatarPos.y/10.0; ::paintingVoxel.y = avatarPos.y / 10.0;
::paintingVoxel.z = avatarPos.z/10.0; ::paintingVoxel.z = avatarPos.z / 10.0;
unsigned char* bufferOut; unsigned char* bufferOut;
int sizeOut; int sizeOut;
@ -696,8 +696,7 @@ void displaySide(Camera& whichCamera) {
drawGroundPlaneGrid(10.f); drawGroundPlaneGrid(10.f);
// Draw voxels // Draw voxels
if (showingVoxels) if (showingVoxels) {
{
voxels.render(); voxels.render();
} }
@ -1029,27 +1028,27 @@ void display(void)
// this version uses a ramp-up/ramp-down timer in the camera to determine shift between first and thirs-person view // this version uses a ramp-up/ramp-down timer in the camera to determine shift between first and thirs-person view
/* /*
if ( myAvatar.getSpeed() < 0.02 ) { if (myAvatar.getSpeed() < 0.02) {
if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON) {
myCamera.setMode(CAMERA_MODE_FIRST_PERSON); myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
} }
//printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); //printf("myCamera.getModeShift() = %f\n", myCamera.getModeShift());
myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); myCamera.setPitch (thirdPersonPitch + myCamera.getModeShift() * (firstPersonPitch - thirdPersonPitch ));
myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); myCamera.setUpShift (thirdPersonUpShift + myCamera.getModeShift() * (firstPersonUpShift - thirdPersonUpShift ));
myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); myCamera.setDistance (thirdPersonDistance + myCamera.getModeShift() * (firstPersonDistance - thirdPersonDistance ));
myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); myCamera.setTightness (thirdPersonTightness + myCamera.getModeShift() * (firstPersonTightness - thirdPersonTightness));
} else { } else {
if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {
myCamera.setMode(CAMERA_MODE_THIRD_PERSON); myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
} }
//printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); //printf("myCamera.getModeShift() = %f\n", myCamera.getModeShift());
myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); myCamera.setPitch (firstPersonPitch + myCamera.getModeShift() * (thirdPersonPitch - firstPersonPitch ));
myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); myCamera.setUpShift (firstPersonUpShift + myCamera.getModeShift() * (thirdPersonUpShift - firstPersonUpShift ));
myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); myCamera.setDistance (firstPersonDistance + myCamera.getModeShift() * (thirdPersonDistance - firstPersonDistance ));
myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); myCamera.setTightness (firstPersonTightness + myCamera.getModeShift() * (thirdPersonTightness - firstPersonTightness));
} }
*/ */
@ -1092,7 +1091,7 @@ void display(void)
if (::viewFrustumFromOffset && ::frustumOn) { if (::viewFrustumFromOffset && ::frustumOn) {
// set the camera to third-person view but offset so we can see the frustum // set the camera to third-person view but offset so we can see the frustum
viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw() ); viewFrustumOffsetCamera.setTargetYaw(::viewFrustumOffsetYaw + myAvatar.getBodyYaw());
viewFrustumOffsetCamera.setPitch (::viewFrustumOffsetPitch ); viewFrustumOffsetCamera.setPitch (::viewFrustumOffsetPitch );
viewFrustumOffsetCamera.setRoll (::viewFrustumOffsetRoll ); viewFrustumOffsetCamera.setRoll (::viewFrustumOffsetRoll );
viewFrustumOffsetCamera.setUpShift (::viewFrustumOffsetUp ); viewFrustumOffsetCamera.setUpShift (::viewFrustumOffsetUp );
@ -1783,7 +1782,7 @@ glm::vec3 getGravity(glm::vec3 pos) {
} }
void mouseFunc(int button, int state, int x, int y) { void mouseFunc(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
mouseX = x; mouseX = x;
mouseY = y; mouseY = y;

View file

@ -128,11 +128,14 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
// called on the other agents - assigns it to my views of the others // called on the other agents - assigns it to my views of the others
int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
// increment to push past the packet header and agent ID // increment to push past the packet header
sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA) + sizeof(uint16_t); sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA);
unsigned char* startPosition = sourceBuffer; unsigned char* startPosition = sourceBuffer;
// push past the agent ID
sourceBuffer += + sizeof(uint16_t);
// Body world position // Body world position
memcpy(&_position, sourceBuffer, sizeof(float) * 3); memcpy(&_position, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3; sourceBuffer += sizeof(float) * 3;

View file

@ -20,12 +20,12 @@ Orientation::Orientation() {
void Orientation::setToIdentity() { void Orientation::setToIdentity() {
quat = glm::quat(); quat = glm::quat();
right = glm::vec3( IDENTITY_RIGHT ); right = glm::vec3(IDENTITY_RIGHT);
up = glm::vec3( IDENTITY_UP ); up = glm::vec3(IDENTITY_UP );
front = glm::vec3( IDENTITY_FRONT ); front = glm::vec3(IDENTITY_FRONT);
} }
void Orientation::set( Orientation o ) { void Orientation::set(Orientation o) {
quat = o.quat; quat = o.quat;
right = o.right; right = o.right;
@ -33,12 +33,12 @@ void Orientation::set( Orientation o ) {
front = o.front; front = o.front;
} }
void Orientation::yaw( float angle ) { void Orientation::yaw(float angle) {
float radian = angle * PI_OVER_180; float radian = angle * PI_OVER_180;
if ( USING_QUATERNIONS ) { if (USING_QUATERNIONS) {
rotateAndGenerateDirections( glm::quat( glm::vec3( 0.0f, -radian, 0.0f )) ); rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, -radian, 0.0f)));
} else { } else {
float s = sin(radian); float s = sin(radian);
float c = cos(radian); float c = cos(radian);
@ -53,12 +53,12 @@ void Orientation::yaw( float angle ) {
} }
} }
void Orientation::pitch( float angle ) { void Orientation::pitch(float angle) {
float radian = angle * PI_OVER_180; float radian = angle * PI_OVER_180;
if ( USING_QUATERNIONS ) { if (USING_QUATERNIONS) {
rotateAndGenerateDirections( glm::quat( glm::vec3( radian, 0.0f, 0.0f ) ) ); rotateAndGenerateDirections(glm::quat(glm::vec3(radian, 0.0f, 0.0f)));
} else { } else {
float s = sin(radian); float s = sin(radian);
float c = cos(radian); float c = cos(radian);
@ -73,12 +73,12 @@ void Orientation::pitch( float angle ) {
} }
} }
void Orientation::roll( float angle ) { void Orientation::roll(float angle) {
float radian = angle * PI_OVER_180; float radian = angle * PI_OVER_180;
if ( USING_QUATERNIONS ) { if (USING_QUATERNIONS) {
rotateAndGenerateDirections( glm::quat( glm::vec3( 0.0f, 0.0f, radian )) ); rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, 0.0f, radian)));
} else { } else {
float s = sin(radian); float s = sin(radian);
float c = cos(radian); float c = cos(radian);
@ -93,13 +93,13 @@ void Orientation::roll( float angle ) {
} }
} }
void Orientation::rotate( float p, float y, float r ) { void Orientation::rotate(float p, float y, float r) {
pitch(p); pitch(p);
yaw (y); yaw (y);
roll (r); roll (r);
} }
void Orientation::rotate( glm::vec3 eulerAngles ) { void Orientation::rotate(glm::vec3 eulerAngles) {
//this needs to be optimized! //this needs to be optimized!
pitch(eulerAngles.x); pitch(eulerAngles.x);
@ -112,13 +112,13 @@ void Orientation::rotate( glm::quat rotation ) {
} }
void Orientation::rotateAndGenerateDirections( glm::quat rotation ) { void Orientation::rotateAndGenerateDirections(glm::quat rotation) {
quat = quat * rotation; quat = quat * rotation;
glm::mat4 rotationMatrix = glm::mat4_cast(quat); glm::mat4 rotationMatrix = glm::mat4_cast(quat);
right = glm::vec3( glm::vec4( IDENTITY_RIGHT, 0.0f ) * rotationMatrix ); right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix);
up = glm::vec3( glm::vec4( IDENTITY_UP, 0.0f ) * rotationMatrix ); up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix);
front = glm::vec3( glm::vec4( IDENTITY_FRONT, 0.0f ) * rotationMatrix ); front = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix);
} }

View file

@ -12,33 +12,33 @@
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
// this is where the coordinate system is represented // this is where the coordinate system is represented
const glm::vec3 IDENTITY_RIGHT = glm::vec3( -1.0f, 0.0f, 0.0f ); const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f);
const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f ); const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f);
const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f ); const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f);
class Orientation class Orientation
{ {
public: public:
Orientation(); Orientation();
void set( Orientation ); void set(Orientation);
void setToIdentity(); void setToIdentity();
void pitch( float p ); void pitch(float p);
void yaw ( float y ); void yaw (float y);
void roll ( float r ); void roll (float r);
void rotate( float pitch, float yaw, float roll ); void rotate(float pitch, float yaw, float roll);
void rotate( glm::vec3 EulerAngles ); void rotate(glm::vec3 EulerAngles);
void rotate( glm::quat quaternion ); void rotate(glm::quat quaternion);
const glm::vec3 & getRight() const { return right; } const glm::vec3 & getRight() const {return right;}
const glm::vec3 & getUp () const { return up; } const glm::vec3 & getUp () const {return up; }
const glm::vec3 & getFront() const { return front; } const glm::vec3 & getFront() const {return front;}
const glm::vec3 & getIdentityRight() const { return IDENTITY_RIGHT; } const glm::vec3 & getIdentityRight() const {return IDENTITY_RIGHT;}
const glm::vec3 & getIdentityUp () const { return IDENTITY_UP; } const glm::vec3 & getIdentityUp () const {return IDENTITY_UP;}
const glm::vec3 & getIdentityFront() const { return IDENTITY_FRONT; } const glm::vec3 & getIdentityFront() const {return IDENTITY_FRONT;}
private: private:
@ -47,7 +47,7 @@ private:
glm::vec3 up; glm::vec3 up;
glm::vec3 front; glm::vec3 front;
void rotateAndGenerateDirections( glm::quat rotation ); void rotateAndGenerateDirections(glm::quat rotation);
}; };
#endif #endif

View file

@ -65,7 +65,7 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) :
_ownerType(newOwnerType), _ownerType(newOwnerType),
socketListenPort(newSocketListenPort), socketListenPort(newSocketListenPort),
_ownerID(UNKNOWN_AGENT_ID), _ownerID(UNKNOWN_AGENT_ID),
lastAgentId(0) { _lastAgentID(0) {
pthread_mutex_init(&mutex, 0); pthread_mutex_init(&mutex, 0);
} }
@ -123,7 +123,7 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
uint16_t agentID = -1; uint16_t agentID = -1;
while ((currentPosition - startPosition) < numTotalBytes) { while ((currentPosition - startPosition) < numTotalBytes) {
currentPosition += unpackAgentId(currentPosition, &agentID); unpackAgentId(currentPosition, &agentID);
memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition)); memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition));
Agent* matchingAgent = agentWithID(agentID); Agent* matchingAgent = agentWithID(agentID);
@ -192,14 +192,6 @@ Agent* AgentList::agentWithID(uint16_t agentID) {
return NULL; return NULL;
} }
uint16_t AgentList::getLastAgentId() {
return lastAgentId;
}
void AgentList::increaseAgentId() {
++lastAgentId;
}
int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) { int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) {
int readAgents = 0; int readAgents = 0;

View file

@ -52,9 +52,6 @@ public:
UDPSocket& getAgentSocket(); UDPSocket& getAgentSocket();
uint16_t getLastAgentId();
void increaseAgentId();
void lock() { pthread_mutex_lock(&mutex); } void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); }
@ -76,6 +73,9 @@ public:
char getOwnerType() const { return _ownerType; } char getOwnerType() const { return _ownerType; }
uint16_t getLastAgentID() const { return _lastAgentID; }
void increaseAgentID() { ++_lastAgentID; }
uint16_t getOwnerID() const { return _ownerID; } uint16_t getOwnerID() const { return _ownerID; }
void setOwnerID(uint16_t ownerID) { _ownerID = ownerID; } void setOwnerID(uint16_t ownerID) { _ownerID = ownerID; }
@ -105,7 +105,7 @@ private:
char _ownerType; char _ownerType;
unsigned int socketListenPort; unsigned int socketListenPort;
uint16_t _ownerID; uint16_t _ownerID;
uint16_t lastAgentId; uint16_t _lastAgentID;
pthread_t removeSilentAgentsThread; pthread_t removeSilentAgentsThread;
pthread_t checkInWithDomainServerThread; pthread_t checkInWithDomainServerThread;
pthread_t pingUnknownAgentsThread; pthread_t pingUnknownAgentsThread;

View file

@ -113,6 +113,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
attenuationRatio = attenuationByte / 255.0f; attenuationRatio = attenuationByte / 255.0f;
memcpy(&bearing, dataPtr, sizeof(float)); memcpy(&bearing, dataPtr, sizeof(float));
dataPtr += sizeof(bearing);
if (bearing > 180 || bearing < -180) { if (bearing > 180 || bearing < -180) {
// we were passed an invalid bearing because this agent wants loopback (pressed the H key) // we were passed an invalid bearing because this agent wants loopback (pressed the H key)
@ -122,10 +123,10 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
bearing = bearing > 0 bearing = bearing > 0
? bearing - AGENT_LOOPBACK_MODIFIER ? bearing - AGENT_LOOPBACK_MODIFIER
: bearing + AGENT_LOOPBACK_MODIFIER; : bearing + AGENT_LOOPBACK_MODIFIER;
} else {
_shouldLoopbackForAgent = false;
} }
dataPtr += sizeof(float);
sourceBuffer = dataPtr; sourceBuffer = dataPtr;
} }

View file

@ -13,18 +13,19 @@
#ifndef hifi_PacketHeaders_h #ifndef hifi_PacketHeaders_h
#define hifi_PacketHeaders_h #define hifi_PacketHeaders_h
const char PACKET_HEADER_DOMAIN = 'D'; typedef char PACKET_HEADER;
const char PACKET_HEADER_PING = 'P'; const PACKET_HEADER PACKET_HEADER_DOMAIN = 'D';
const char PACKET_HEADER_PING_REPLY = 'R'; const PACKET_HEADER PACKET_HEADER_PING = 'P';
const char PACKET_HEADER_HEAD_DATA = 'H'; const PACKET_HEADER PACKET_HEADER_PING_REPLY = 'R';
const char PACKET_HEADER_Z_COMMAND = 'Z'; const PACKET_HEADER PACKET_HEADER_HEAD_DATA = 'H';
const char PACKET_HEADER_INJECT_AUDIO = 'I'; const PACKET_HEADER PACKET_HEADER_Z_COMMAND = 'Z';
const char PACKET_HEADER_SET_VOXEL = 'S'; const PACKET_HEADER PACKET_HEADER_INJECT_AUDIO = 'I';
const char PACKET_HEADER_ERASE_VOXEL = 'E'; const PACKET_HEADER PACKET_HEADER_SET_VOXEL = 'S';
const char PACKET_HEADER_VOXEL_DATA = 'V'; const PACKET_HEADER PACKET_HEADER_ERASE_VOXEL = 'E';
const char PACKET_HEADER_BULK_AVATAR_DATA = 'X'; const PACKET_HEADER PACKET_HEADER_VOXEL_DATA = 'V';
const char PACKET_HEADER_TRANSMITTER_DATA = 't'; const PACKET_HEADER PACKET_HEADER_BULK_AVATAR_DATA = 'X';
const char PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L'; const PACKET_HEADER PACKET_HEADER_TRANSMITTER_DATA = 't';
const char PACKET_HEADER_DOMAIN_RFD = 'C'; const PACKET_HEADER PACKET_HEADER_DOMAIN_LIST_REQUEST = 'L';
const PACKET_HEADER PACKET_HEADER_DOMAIN_RFD = 'C';
#endif #endif