From 2ec3f6b21092c1c62adf563ce2c505a8db939265 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 10:37:07 -0700 Subject: [PATCH 1/9] Adding new AgentTypes.h and moving over to new constants --- domain/src/main.cpp | 6 ++++-- interface/src/main.cpp | 3 ++- mixer/src/main.cpp | 3 ++- shared/src/AgentList.cpp | 13 ++++++++----- shared/src/AgentTypes.h | 21 +++++++++++++++++++++ voxel/src/main.cpp | 3 ++- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 shared/src/AgentTypes.h diff --git a/domain/src/main.cpp b/domain/src/main.cpp index 7ef0967e1b..9235091660 100644 --- a/domain/src/main.cpp +++ b/domain/src/main.cpp @@ -25,6 +25,8 @@ #include #include #include "AgentList.h" +#include "AgentTypes.h" +#include #include "SharedUtil.h" #ifdef _WIN32 @@ -46,7 +48,7 @@ const int LOGOFF_CHECK_INTERVAL = 5000; #define DEBUG_TO_SELF 0 int lastActiveCount = 0; -AgentList agentList('D', DOMAIN_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_DOMAIN, DOMAIN_LISTEN_PORT); unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { *currentPosition++ = agentToAdd->getType(); @@ -82,7 +84,7 @@ int main(int argc, const char * argv[]) char agentType; unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; - *broadcastPacket = 'D'; + *broadcastPacket = PACKET_HEADER_DOMAIN; unsigned char *currentBufferPos; unsigned char *startPointer; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index cb3341c9d9..b8e2c190e7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -55,6 +55,7 @@ #include "Texture.h" #include "Cloud.h" #include +#include #include "VoxelSystem.h" #include "Lattice.h" #include "Finger.h" @@ -70,7 +71,7 @@ using namespace std; int audio_on = 1; // Whether to turn on the audio support int simulate_on = 1; -AgentList agentList('I'); +AgentList agentList(AGENT_TYPE_INTERFACE); pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 7a8705b645..10040a05a9 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "AudioRingBuffer.h" @@ -60,7 +61,7 @@ const int AGENT_LOOPBACK_MODIFIER = 307; const int LOOPBACK_SANITY_CHECK = 0; -AgentList agentList('M', MIXER_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_MIXER, MIXER_LISTEN_PORT); StDev stdev; void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 1e01487348..aa04d99c9a 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -11,6 +11,7 @@ #include #include #include "AgentList.h" +#include "AgentTypes.h" #include "PacketHeaders.h" #include "SharedUtil.h" @@ -180,13 +181,13 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, newAgent.activatePublicSocket(); } - if (newAgent.getType() == 'M' && audioMixerSocketUpdate != NULL) { + if (newAgent.getType() == AGENT_TYPE_MIXER && audioMixerSocketUpdate != NULL) { // this is an audio mixer // for now that means we need to tell the audio class // to use the local socket information the domain server gave us sockaddr_in *publicSocketIn = (sockaddr_in *)publicSocket; audioMixerSocketUpdate(publicSocketIn->sin_addr.s_addr, publicSocketIn->sin_port); - } else if (newAgent.getType() == 'V') { + } else if (newAgent.getType() == AGENT_TYPE_VOXEL) { newAgent.activatePublicSocket(); } @@ -199,7 +200,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, return true; } else { - if (agent->getType() == 'M' || agent->getType() == 'V') { + if (agent->getType() == AGENT_TYPE_MIXER || agent->getType() == AGENT_TYPE_VOXEL) { // until the Audio class also uses our agentList, we need to update // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously agent->setLastRecvTimeUsecs(usecTimestampNow()); @@ -210,6 +211,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } } +// XXXBHG - do we want to move these? const char* AgentList::AGENTS_OF_TYPE_HEAD = "H"; const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V"; @@ -229,7 +231,7 @@ void AgentList::pingAgents() { *payload = PACKET_HEADER_PING; for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->getType() == 'I') { + if (agent->getType() == AGENT_TYPE_INTERFACE) { if (agent->getActiveSocket() != NULL) { // we know which socket is good for this agent, send there agentSocket.send(agent->getActiveSocket(), payload, 1); @@ -268,7 +270,8 @@ void *removeSilentAgents(void *args) { pthread_mutex_t * agentDeleteMutex = &agent->deleteMutex; - if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != 'V' + if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS + && agent->getType() != AGENT_TYPE_VOXEL && pthread_mutex_trylock(agentDeleteMutex) == 0) { std::cout << "Killing agent " << &(*agent) << "\n"; diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h new file mode 100644 index 0000000000..1d91f8cb65 --- /dev/null +++ b/shared/src/AgentTypes.h @@ -0,0 +1,21 @@ +// +// AgentTypes.h +// hifi +// +// Created by Brad Hefta-Gaub on 2013/04/09 +// +// +// Single byte/character Agent Types used to identify various agents in the system. +// For example, an agent whose is 'V' is always a voxel server. +// + +#ifndef hifi_AgentTypes_h +#define hifi_AgentTypes_h + +const char AGENT_TYPE_DOMAIN = 'D'; +const char AGENT_TYPE_VOXEL = 'V'; +const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? +const char AGENT_TYPE_HEAD = 'H'; // Is this needed??? +const char AGENT_TYPE_MIXER = 'M'; + +#endif diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 09834a2d3e..3990a82eac 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "VoxelAgentData.h" #include @@ -45,7 +46,7 @@ const int PACKETS_PER_CLIENT_PER_INTERVAL = 2; const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; -AgentList agentList('V', VOXEL_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_VOXEL, VOXEL_LISTEN_PORT); VoxelTree randomTree; bool wantColorRandomizer = false; From 87c26a39fb1c4eaf1d9cf9a471d973553159ae3a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 12:54:59 -0700 Subject: [PATCH 2/9] adding more changes and small improvements to camera, and head... --- interface/src/Camera.cpp | 6 +++ interface/src/Head.cpp | 80 ++++++++++------------------------------ interface/src/main.cpp | 31 ++++++++++++---- 3 files changed, 50 insertions(+), 67 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index e7bf3d751b..1481456361 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -33,5 +33,11 @@ void Camera::update() position = glm::dvec3( targetPosition ); position += glm::dvec3( x, y, z ); + + //geterate the ortho-normals for the orientation based on the Euler angles + orientation.setToIdentity(); + orientation.yaw ( yaw ); + orientation.pitch ( pitch ); + orientation.roll ( roll ); } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2b1222c09d..c6df7de2e9 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -190,7 +190,7 @@ void Head::reset() - +//this pertains to moving the head with the glasses //--------------------------------------------------- void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles @@ -285,10 +285,7 @@ void Head::simulate(float deltaTime) sin( avatar.pitch * PI_OVER_180 ), cos( avatar.roll * PI_OVER_180 ) ); - */ - - - /* + glm::vec3 forward(-sinf(getRenderYaw()*PI/180), sinf(getRenderPitch()*PI/180), cosf(getRenderYaw()*PI/180)); @@ -296,93 +293,54 @@ void Head::simulate(float deltaTime) thrust = glm::vec3(0); */ - const float THRUST_MAG = 10.0; - - /* - const float THRUST_LATERAL_MAG = 10.0; - const float THRUST_VERTICAL_MAG = 10.0; - */ - + const float THRUST_MAG = 10.0; + const float THRUST_LATERAL_MAG = 10.0; + const float THRUST_VERTICAL_MAG = 10.0; avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 ); if (driveKeys[FWD]) { - //position.x += avatar.orientation.getFront().getX() * 0.01; - //position.y += avatar.orientation.getFront().getY() * 0.01; - //position.z -= avatar.orientation.getFront().getZ() * 0.01; - avatar.thrust.x += avatar.orientation.getFront().getX() * THRUST_MAG; avatar.thrust.y += avatar.orientation.getFront().getY() * THRUST_MAG; avatar.thrust.z -= avatar.orientation.getFront().getZ() * THRUST_MAG; - //thrust += THRUST_MAG*forward; } - if (driveKeys[BACK]) { - //position.x -= avatar.orientation.getFront().getX() * 0.01; - //position.y -= avatar.orientation.getFront().getY() * 0.01; - //position.z += avatar.orientation.getFront().getZ() * 0.01; - avatar.thrust.x -= avatar.orientation.getFront().getX() * THRUST_MAG; avatar.thrust.y -= avatar.orientation.getFront().getY() * THRUST_MAG; avatar.thrust.z += avatar.orientation.getFront().getZ() * THRUST_MAG; - //thrust += -THRUST_MAG*forward; } - - if (driveKeys[RIGHT]) { - //position.x += avatar.orientation.getRight().getX() * 0.01; - //position.y += avatar.orientation.getRight().getY() * 0.01; - //position.z -= avatar.orientation.getRight().getZ() * 0.01; - - avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_MAG; - avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_MAG; - avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_MAG; - + avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; + avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; + avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; //thrust.x += forward.z*-THRUST_LATERAL_MAG; //thrust.z += forward.x*THRUST_LATERAL_MAG; } if (driveKeys[LEFT]) { - //position.x -= avatar.orientation.getRight().getX() * 0.01; - //position.y -= avatar.orientation.getRight().getY() * 0.01; - //position.z += avatar.orientation.getRight().getZ() * 0.01; - - avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_MAG; - avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_MAG; - avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_MAG; - + avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; + avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; + avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; //thrust.x += forward.z*THRUST_LATERAL_MAG; //thrust.z += forward.x*-THRUST_LATERAL_MAG; } - - if (driveKeys[UP]) { - //position.x -= avatar.orientation.getUp().getX() * 0.01; - //position.y -= avatar.orientation.getUp().getY() * 0.01; - //position.z += avatar.orientation.getUp().getZ() * 0.01; - - avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_MAG; - avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_MAG; - avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_MAG; - + avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; + avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; + avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; //thrust.y += -THRUST_VERTICAL_MAG; } if (driveKeys[DOWN]) { - //position.x += avatar.orientation.getUp().getX() * 0.01; - //position.y += avatar.orientation.getUp().getY() * 0.01; - //position.z -= avatar.orientation.getUp().getZ() * 0.01; - - avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_MAG; - avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_MAG; - avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_MAG; - + avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; + avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; + avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; //thrust.y += THRUST_VERTICAL_MAG; } @@ -1055,7 +1013,9 @@ void Head::parseData(void *data, int size) &Pitch, &Yaw, &Roll, &position.x, &position.y, &position.z, &loudness, &averageLoudness, - &handPos.x, &handPos.y, &handPos.z + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z ); if (glm::length(handPos) > 0.0) hand->setPos(handPos); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 64d4e774c5..edaee1095a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -608,7 +608,7 @@ void display(void) { myCamera.setYaw ( - myHead.getAvatarYaw() ); myCamera.setUp ( 0.4 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 0.5 ); myCamera.update(); } else @@ -618,7 +618,7 @@ void display(void) { myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); myCamera.setUp ( 0.15 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 1.0 ); myCamera.update(); } @@ -653,14 +653,16 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels - voxels.render(); +//voxels.render(); // Draw field vectors if (display_field) field.render(); // Render heads of other agents - for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) { - if (agent->getLinkedData() != NULL) { + for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) + { + if (agent->getLinkedData() != NULL) + { Head *agentHead = (Head *)agent->getLinkedData(); glPushMatrix(); glm::vec3 pos = agentHead->getPos(); @@ -670,7 +672,7 @@ void display(void) } } - if (!display_head) balls.render(); + if ( !display_head ) balls.render(); // Render the world box if (!display_head && stats_on) render_world_box(); @@ -1046,6 +1048,21 @@ void idle(void) // Simulation simulateHead(1.f/FPS); + + + //test + /* + // simulate the other agents + for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) + { + if (agent->getLinkedData() != NULL) + { + Head *agentHead = (Head *)agent->getLinkedData(); + agentHead->simulate(1.f/FPS); + } + } + */ + simulateHand(1.f/FPS); if (simulate_on) { @@ -1078,7 +1095,7 @@ void reshape(int width, int height) glMatrixMode(GL_PROJECTION); //hello fov.setResolution(width, height) .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) - .setPerspective(0.7854f); + .setPerspective(0.7854f); glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); glMatrixMode(GL_MODELVIEW); From 712997451bda7398730660279dfa6ac76c5a1936 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 13:00:20 -0700 Subject: [PATCH 3/9] Adding friendly names to AgentType display. --- shared/src/Agent.cpp | 35 +++++++++++++++++++++++++++++++++-- shared/src/Agent.h | 3 ++- shared/src/AgentTypes.h | 6 ++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/shared/src/Agent.cpp b/shared/src/Agent.cpp index 677b4884fe..e9e62f3c66 100644 --- a/shared/src/Agent.cpp +++ b/shared/src/Agent.cpp @@ -7,6 +7,7 @@ // #include "Agent.h" +#include "AgentTypes.h" #include #include "UDPSocket.h" #include "SharedUtil.h" @@ -90,10 +91,40 @@ Agent::~Agent() { delete linkedData; } -char Agent::getType() { +char Agent::getType() const { return type; } +// Names of Agent Types +const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; +const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; +const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface"; +const char* AGENT_TYPE_NAME_HEAD = "Avatar Head"; // Is this needed??? +const char* AGENT_TYPE_NAME_MIXER = "Audio Mixer"; +const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; + +const char* Agent::getTypeName() const { + const char* name = AGENT_TYPE_NAME_UNKNOWN; + switch (this->type) { + case AGENT_TYPE_DOMAIN: + name = AGENT_TYPE_NAME_DOMAIN; + break; + case AGENT_TYPE_VOXEL: + name = AGENT_TYPE_NAME_VOXEL; + break; + case AGENT_TYPE_INTERFACE: + name = AGENT_TYPE_NAME_INTERFACE; + break; + case AGENT_TYPE_HEAD: + name = AGENT_TYPE_NAME_HEAD; + break; + case AGENT_TYPE_MIXER: + name = AGENT_TYPE_NAME_MIXER; + break; + } + return name; +} + void Agent::setType(char newType) { type = newType; } @@ -174,7 +205,7 @@ std::ostream& operator<<(std::ostream& os, const Agent* agent) { sockaddr_in *agentPublicSocket = (sockaddr_in *)agent->publicSocket; sockaddr_in *agentLocalSocket = (sockaddr_in *)agent->localSocket; - os << "T: " << agent->type << " PA: " << inet_ntoa(agentPublicSocket->sin_addr) << + os << "T: " << agent->getTypeName() << " (" << agent->type << ") PA: " << inet_ntoa(agentPublicSocket->sin_addr) << ":" << ntohs(agentPublicSocket->sin_port) << " LA: " << inet_ntoa(agentLocalSocket->sin_addr) << ":" << ntohs(agentLocalSocket->sin_port); return os; diff --git a/shared/src/Agent.h b/shared/src/Agent.h index 1b86e95e9b..bc6a6eb714 100644 --- a/shared/src/Agent.h +++ b/shared/src/Agent.h @@ -40,7 +40,8 @@ public: pthread_mutex_t deleteMutex; - char getType(); + char getType() const; + const char* getTypeName() const; void setType(char newType); uint16_t getAgentId(); void setAgentId(uint16_t thisAgentId); diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h index 1d91f8cb65..fdfce9af8b 100644 --- a/shared/src/AgentTypes.h +++ b/shared/src/AgentTypes.h @@ -12,6 +12,12 @@ #ifndef hifi_AgentTypes_h #define hifi_AgentTypes_h +// NOTE: If you add a new AGENT_TYPE_XXX then you also should add a new AGENT_TYPE_NAME_XXX and a new "case" to the +// switch statement in Agent.cpp specifically Agent::getTypeName(). +// If you don't then it will make things harder on your co-developers in debugging because the Agent +// class won't know the name and will report it as "Unknown". + +// Agent Type Codes const char AGENT_TYPE_DOMAIN = 'D'; const char AGENT_TYPE_VOXEL = 'V'; const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? From f5634a66aae1c7a0fffe99184236ebb868e1c785 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 13:27:15 -0700 Subject: [PATCH 4/9] Got rid of AGENT_TYPE_HEAD and fixed voxel server to use AGENT_TYPE_INTERFACE --- shared/src/Agent.cpp | 4 ---- shared/src/AgentList.cpp | 4 ++-- shared/src/AgentList.h | 5 ++--- shared/src/AgentTypes.h | 1 - voxel/src/main.cpp | 8 +++++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/shared/src/Agent.cpp b/shared/src/Agent.cpp index e9e62f3c66..0e8a98efc1 100644 --- a/shared/src/Agent.cpp +++ b/shared/src/Agent.cpp @@ -99,7 +99,6 @@ char Agent::getType() const { const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface"; -const char* AGENT_TYPE_NAME_HEAD = "Avatar Head"; // Is this needed??? const char* AGENT_TYPE_NAME_MIXER = "Audio Mixer"; const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; @@ -115,9 +114,6 @@ const char* Agent::getTypeName() const { case AGENT_TYPE_INTERFACE: name = AGENT_TYPE_NAME_INTERFACE; break; - case AGENT_TYPE_HEAD: - name = AGENT_TYPE_NAME_HEAD; - break; case AGENT_TYPE_MIXER: name = AGENT_TYPE_NAME_MIXER; break; diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index aa04d99c9a..1add03d6ff 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -212,9 +212,9 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } // XXXBHG - do we want to move these? -const char* AgentList::AGENTS_OF_TYPE_HEAD = "H"; -const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V"; +const char* AgentList::AGENTS_OF_TYPE_INTERFACE = "I"; +const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes,const char* agentTypes) { for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { diff --git a/shared/src/AgentList.h b/shared/src/AgentList.h index ca6d844b48..e3de23154f 100644 --- a/shared/src/AgentList.h +++ b/shared/src/AgentList.h @@ -67,10 +67,9 @@ public: void startDomainServerCheckInThread(); void stopDomainServerCheckInThread(); - static const char* AGENTS_OF_TYPE_HEAD; - static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE; static const char* AGENTS_OF_TYPE_VOXEL; - + static const char* AGENTS_OF_TYPE_INTERFACE; + static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE; }; int unpackAgentId(unsigned char *packedData, uint16_t *agentId); diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h index fdfce9af8b..43c1239912 100644 --- a/shared/src/AgentTypes.h +++ b/shared/src/AgentTypes.h @@ -21,7 +21,6 @@ const char AGENT_TYPE_DOMAIN = 'D'; const char AGENT_TYPE_VOXEL = 'V'; const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? -const char AGENT_TYPE_HEAD = 'H'; // Is this needed??? const char AGENT_TYPE_MIXER = 'M'; #endif diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 3990a82eac..01b63d63b6 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -345,7 +345,7 @@ int main(int argc, const char * argv[]) // Now send this to the connected agents so they know to delete printf("rebroadcasting delete voxel message to connected agents... agentList.broadcastToAgents()\n"); - agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); + agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_INTERFACE); } if (packetData[0] == PACKET_HEADER_Z_COMMAND) { @@ -373,12 +373,14 @@ int main(int argc, const char * argv[]) // Now send this to the connected agents so they can also process these messages printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n"); - agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); + agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_INTERFACE); } + // If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_INTERFACE, and we + // need to make sure we have it in our agentList. if (packetData[0] == PACKET_HEADER_HEAD_DATA) { if (agentList.addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, - packetData[0], + AGENT_TYPE_INTERFACE, agentList.getLastAgentId())) { agentList.increaseAgentId(); } From 42e1355f1eccaf06dd1819029a753be3731d240c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 14:11:55 -0700 Subject: [PATCH 5/9] add back voxels.render() call --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2458318812..83a07bb32e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -657,7 +657,7 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels -//voxels.render(); + voxels.render(); // Draw field vectors if (display_field) field.render(); From ff53b1573c93cb9b6047c9068604c12a4f566096 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 14:35:29 -0700 Subject: [PATCH 6/9] fixed bug in avatar arm IK prototype --- interface/src/Head.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 84c7232fed..de2b1410a5 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -927,7 +927,6 @@ void Head::updateHandMovement() //------------------------------------------------------------------------------- float distance = glm::length( armVector ); - //------------------------------------------------------------------------------- // if right hand is being dragged beyond maximum arm length... //------------------------------------------------------------------------------- @@ -952,7 +951,16 @@ void Head::updateHandMovement() newElbowPosition += armVector * (float)ONE_HALF; glm::dvec3 perpendicular = glm::dvec3( -armVector.y, armVector.x, armVector.z ); newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF; - avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newElbowPosition; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition = newElbowPosition; + + //----------------------------------------------------------------------------- + // set wrist position + //----------------------------------------------------------------------------- + glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); + vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + newWristPosition += vv * 0.7f; + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newWristPosition; } From 7d42b93489b893013d92ed4bdf4f8951f5c34fb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 14:45:19 -0700 Subject: [PATCH 7/9] condensed avatar bone line code --- interface/src/Head.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index de2b1410a5..309a192512 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -736,7 +736,7 @@ void Head::initializeAvatar() //---------------------------------------------------------------------------- // left pelvis and leg //---------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_NULL; + avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; avatar.bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS; avatar.bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH; avatar.bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN; @@ -744,7 +744,7 @@ void Head::initializeAvatar() //---------------------------------------------------------------------------- // right pelvis and leg //---------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_NULL; + avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS; avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH; avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN; @@ -971,7 +971,9 @@ void Head::renderBody() { glColor3fv(skinColor); + //----------------------------------------- // Render bones as spheres + //----------------------------------------- for (int b=0; b Date: Tue, 9 Apr 2013 15:05:37 -0700 Subject: [PATCH 8/9] added camera modes and also set initial avatar yaw to 90 --- interface/src/Camera.cpp | 5 +++++ interface/src/Camera.h | 14 +++++++++++++ interface/src/Head.cpp | 6 +++--- interface/src/main.cpp | 44 ++++++++++++++++++---------------------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1481456361..4eb0101eda 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,6 +11,8 @@ //------------------------ Camera::Camera() { + mode = CAMERA_MODE_THIRD_PERSON; + fieldOfView = 60.0; // default yaw = 0.0; pitch = 0.0; roll = 0.0; @@ -22,6 +24,7 @@ Camera::Camera() } + //------------------------ void Camera::update() { @@ -34,7 +37,9 @@ void Camera::update() position = glm::dvec3( targetPosition ); position += glm::dvec3( x, y, z ); + //------------------------------------------------------------------------ //geterate the ortho-normals for the orientation based on the Euler angles + //------------------------------------------------------------------------ orientation.setToIdentity(); orientation.yaw ( yaw ); orientation.pitch ( pitch ); diff --git a/interface/src/Camera.h b/interface/src/Camera.h index eed70c1c92..bee20829eb 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -12,6 +12,16 @@ #include "Orientation.h" #include +enum CameraMode +{ + CAMERA_MODE_NULL = -1, + CAMERA_MODE_FIRST_PERSON, + CAMERA_MODE_THIRD_PERSON, + CAMERA_MODE_MY_OWN_FACE, + NUM_CAMERA_MODES +}; + + class Camera { public: @@ -19,6 +29,7 @@ public: void update(); + void setMode ( CameraMode m ) { mode = m; } void setYaw ( double y ) { yaw = y; } void setPitch ( double p ) { pitch = p; } void setRoll ( double r ) { roll = r; } @@ -33,11 +44,14 @@ public: double getRoll () { return roll; } glm::dvec3 getPosition () { return position; } Orientation getOrientation () { return orientation; } + CameraMode getMode () { return mode; } private: + CameraMode mode; glm::dvec3 position; glm::dvec3 targetPosition; + double fieldOfView; double yaw; double pitch; double roll; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 309a192512..8167e80e89 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -688,9 +688,9 @@ void Head::initializeAvatar() avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); - avatar.yaw = 0.0; - avatar.pitch = 0.0; - avatar.roll = 0.0; + avatar.yaw = 90.0; + avatar.pitch = 0.0; + avatar.roll = 0.0; avatar.yawDelta = 0.0; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 83a07bb32e..9618f2c020 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -596,49 +596,45 @@ void display(void) glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - //------------------------------------------------------------------------------------- - // set the camera to third-person view - //------------------------------------------------------------------------------------- + //-------------------------------------------------------- + // camera settings + //-------------------------------------------------------- myCamera.setTargetPosition( (glm::dvec3)myHead.getPos() ); - myCamera.setPitch ( 0.0 ); - myCamera.setRoll ( 0.0 ); if ( display_head ) - //------------------------------------------------------------------------------------- - // set the camera to looking at my face - //------------------------------------------------------------------------------------- { + //----------------------------------------------- + // set the camera to looking at my own face + //----------------------------------------------- myCamera.setYaw ( - myHead.getAvatarYaw() ); + myCamera.setPitch ( 0.0 ); + myCamera.setRoll ( 0.0 ); myCamera.setUp ( 0.4 ); - myCamera.setDistance( 0.5 ); + myCamera.setDistance( 0.5 ); myCamera.setDistance( 0.08 ); myCamera.update(); } else - //------------------------------------------------------------------------------------- - // set the camera to third-person view - //------------------------------------------------------------------------------------- { + //---------------------------------------------------- + // set the camera to third-person view behind my av + //---------------------------------------------------- myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); - myCamera.setUp ( 0.15 ); - myCamera.setDistance( 1.0 ); - myCamera.setDistance( 0.08 ); + myCamera.setPitch ( 10.0 ); + myCamera.setRoll ( 0.0 ); + myCamera.setUp ( 0.2 ); + myCamera.setDistance( 1.6 ); + myCamera.setDistance( 0.5 ); myCamera.update(); } - //------------------------------------------------------------------------------------- - // transform to camera view - //------------------------------------------------------------------------------------- + //--------------------------------------------- + // transform view according to myCamera + //--------------------------------------------- glRotatef ( myCamera.getPitch(), 1, 0, 0 ); glRotatef ( myCamera.getYaw(), 0, 1, 0 ); glRotatef ( myCamera.getRoll(), 0, 0, 1 ); - - //printf( "myCamera position = %f, %f, %f\n", myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z ); - glTranslatef( myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z ); - - // fixed view - //glTranslatef( 6.18, -0.15, 1.4 ); if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting From 3dae70e665f1940a463c6f701fa62825d65f01f3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 15:23:59 -0700 Subject: [PATCH 9/9] removed glm::dvec3 and replaced with glm::vec3 in most of avatar code, except for velocity --- interface/src/Camera.h | 38 ++++++++--------- interface/src/Head.cpp | 97 +++++++++++++++++++++--------------------- interface/src/Head.h | 32 +++++++------- interface/src/main.cpp | 16 +++---- 4 files changed, 91 insertions(+), 92 deletions(-) diff --git a/interface/src/Camera.h b/interface/src/Camera.h index bee20829eb..02c063c42e 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -30,33 +30,33 @@ public: void update(); void setMode ( CameraMode m ) { mode = m; } - void setYaw ( double y ) { yaw = y; } - void setPitch ( double p ) { pitch = p; } - void setRoll ( double r ) { roll = r; } - void setUp ( double u ) { up = u; } - void setDistance ( double d ) { distance = d; } - void setTargetPosition ( glm::dvec3 t ) { targetPosition = t; }; - void setPosition ( glm::dvec3 p ) { position = p; }; + void setYaw ( float y ) { yaw = 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); } - double getYaw () { return yaw; } - double getPitch () { return pitch; } - double getRoll () { return roll; } - glm::dvec3 getPosition () { return position; } + 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; } private: CameraMode mode; - glm::dvec3 position; - glm::dvec3 targetPosition; - double fieldOfView; - double yaw; - double pitch; - double roll; - double up; - double distance; + glm::vec3 position; + glm::vec3 targetPosition; + float fieldOfView; + float yaw; + float pitch; + float roll; + float up; + float distance; Orientation orientation; }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 8167e80e89..3e7512a8b7 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -239,9 +239,9 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea //--------------------------------------------------- -void Head::setAvatarPosition( double x, double y, double z ) +void Head::setAvatarPosition( float x, float y, float z ) { - avatar.position = glm::dvec3( x, y, z ); + avatar.position = glm::vec3( x, y, z ); } @@ -297,7 +297,7 @@ void Head::simulate(float deltaTime) const float THRUST_LATERAL_MAG = 10.0; const float THRUST_VERTICAL_MAG = 10.0; - avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (driveKeys[FWD]) { @@ -362,9 +362,9 @@ void Head::simulate(float deltaTime) //avatar.yawDelta *= 0.99; - avatar.velocity += avatar.thrust * (double)deltaTime; + avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); - position += avatar.velocity * (double)deltaTime; + position += (glm::vec3)avatar.velocity * deltaTime; //avatar.velocity *= 0.9; @@ -673,9 +673,9 @@ void Head::renderHead( int faceToFace, int isMine ) //--------------------------------------------------------- -void Head::setHandMovement( glm::dvec3 movement ) +void Head::setHandMovement( glm::vec3 movement ) { - handOffset = glm::dvec3( movement.x, -movement.y, movement.z ); + handOffset = glm::vec3( movement.x, -movement.y, movement.z ); } @@ -683,9 +683,9 @@ void Head::setHandMovement( glm::dvec3 movement ) //----------------------------------------- void Head::initializeAvatar() { - avatar.position = glm::dvec3( 0.0, 0.0, 0.0 ); - avatar.velocity = glm::dvec3( 0.0, 0.0, 0.0 ); - avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 ); + avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); avatar.yaw = 90.0; @@ -696,9 +696,8 @@ void Head::initializeAvatar() for (int b=0; b