diff --git a/interface/src/Agent.cpp b/interface/src/Agent.cpp index a454b23d57..41db4fcdc9 100644 --- a/interface/src/Agent.cpp +++ b/interface/src/Agent.cpp @@ -57,13 +57,13 @@ int update_agents(char * data, int length) { } // Render the heads of the agents -void render_agents(int renderSelf) { +void render_agents(int renderSelf, float * myLocation) { for (int i = 0; i < num_agents; i++) { glm::vec3 pos = agents[i].head.getPos(); glPushMatrix(); if (!agents[i].isSelf || renderSelf) { glTranslatef(-pos.x, -pos.y, -pos.z); - agents[i].head.render(0); + agents[i].head.render(0, myLocation); } glPopMatrix(); } @@ -120,11 +120,12 @@ int broadcastToAgents(UDPSocket *handle, char * data, int length, int sendToSelf int sent_bytes; //printf("broadcasting to %d agents\n", num_agents); for (int i = 0; i < num_agents; i++) { - //std::cout << "to: Agent address " << agents[i].address << " port " << agents[i].port << "\n"; - if (sendToSelf || ((strcmp((char *)"127.0.0.1", agents[i].address) != 0) - && (agents[i].port != AGENT_UDP_PORT))) + if (sendToSelf || (((strcmp((char *)"127.0.0.1", agents[i].address) != 0) + && (agents[i].port != AGENT_UDP_PORT)))) if (agents[i].agentType != 'M') { + //std::cout << "broadcasting my agent data to: " << agents[i].address << " : " << agents[i].port << "\n"; + sent_bytes = handle->send(agents[i].address, agents[i].port, data, length); if (sent_bytes != length) { std::cout << "Broadcast to agents FAILED\n"; @@ -142,7 +143,7 @@ void pingAgents(UDPSocket *handle) { if (agents[i].agentType != 'M') { gettimeofday(&agents[i].pingStarted, NULL); handle->send(agents[i].address, agents[i].port, payload, 1); -// printf("\nSent Ping at %d usecs\n", agents[i].pingStarted.tv_usec); + //printf("\nSent Ping at %d usecs\n", agents[i].pingStarted.tv_usec); } } diff --git a/interface/src/Agent.h b/interface/src/Agent.h index e7dce9dd5f..c328a8a376 100644 --- a/interface/src/Agent.h +++ b/interface/src/Agent.h @@ -27,7 +27,7 @@ int broadcastToAgents(UDPSocket * handle, char * data, int length, int sendToSel void pingAgents(UDPSocket *handle); void setAgentPing(char * address, unsigned short port); void update_agent(char * address, unsigned short port, char * data, int length); -void render_agents(int renderSelf); +void render_agents(int renderSelf, float * myLocation); void kludgyMixerUpdate(Audio audio); #endif diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 34e1e28e9b..b8f2681244 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -206,117 +206,126 @@ void Head::simulate(float deltaTime) } -void Head::render(int faceToFace) +void Head::render(int faceToFace, float * myLocation) { - int side = 0; + int side = 0; - glEnable(GL_DEPTH_TEST); - glPushMatrix(); + glm::vec3 cameraHead(myLocation[0], myLocation[1], myLocation[2]); + float distanceToCamera = glm::distance(cameraHead, position); + + //std::cout << distanceToCamera << "\n"; + + // Don't render a head if it is really close to your location, because that is your own head! + if (distanceToCamera > 0.1) { + glEnable(GL_DEPTH_TEST); + glPushMatrix(); - glScalef(scale, scale, scale); - glTranslatef(leanSideways, 0.f, leanForward); + glScalef(scale, scale, scale); + glTranslatef(leanSideways, 0.f, leanForward); - glRotatef(Yaw/2.0, 0, 1, 0); - glRotatef(Pitch/2.0, 1, 0, 0); - glRotatef(Roll/2.0, 0, 0, 1); + glRotatef(Yaw/2.0, 0, 1, 0); + glRotatef(Pitch/2.0, 1, 0, 0); + glRotatef(Roll/2.0, 0, 0, 1); - - // Overall scale of head - if (faceToFace) glScalef(1.5, 2.0, 2.0); - glColor3fv(skinColor); - - // Head - glutSolidSphere(1, 30, 30); - - // Ears - glPushMatrix(); - glTranslatef(1, 0, 0); - for(side = 0; side < 2; side++) + + // Overall scale of head + if (faceToFace) glScalef(1.5, 2.0, 2.0); + glColor3fv(skinColor); + + // Head + glutSolidSphere(1, 30, 30); + + // Ears + glPushMatrix(); + glTranslatef(1, 0, 0); + for(side = 0; side < 2; side++) + { + glPushMatrix(); + glScalef(0.5, 0.75, 1.0); + glutSolidSphere(0.5, 30, 30); + glPopMatrix(); + glTranslatef(-2, 0, 0); + } + glPopMatrix(); + + + // Eyebrows + glPushMatrix(); + glTranslatef(-interBrowDistance/2.0,0.4,0.45); + for(side = 0; side < 2; side++) + { + glColor3fv(browColor); + glPushMatrix(); + glTranslatef(0, 0.4, 0); + glRotatef(EyebrowPitch[side]/2.0, 1, 0, 0); + glRotatef(EyebrowRoll[side]/2.0, 0, 0, 1); + glScalef(browWidth, browThickness, 1); + glutSolidCube(0.5); + glPopMatrix(); + glTranslatef(interBrowDistance, 0, 0); + } + glPopMatrix(); + + + // Mouth + + glPushMatrix(); + glTranslatef(0,-0.3,0.75); + glColor3f(loudness/1000.0,0,0); + glRotatef(MouthPitch, 1, 0, 0); + glRotatef(MouthYaw, 0, 0, 1); + glScalef(MouthWidth*(.5 + averageLoudness/3000.0), MouthHeight*(1.0 + averageLoudness/6000.0), 1); + glutSolidCube(0.5); + glPopMatrix(); + + glTranslatef(0, 1.0, 0); + + glTranslatef(-interPupilDistance/2.0,-0.68,0.7); + // Right Eye + glRotatef(-10, 1, 0, 0); + glColor3fv(eyeColor); + glPushMatrix(); { - glPushMatrix(); - glScalef(0.5, 0.75, 1.0); - glutSolidSphere(0.5, 30, 30); - glPopMatrix(); - glTranslatef(-2, 0, 0); + glTranslatef(interPupilDistance/10.0, 0, 0.05); + glRotatef(20, 0, 0, 1); + glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ); + glutSolidSphere(0.25, 30, 30); } - glPopMatrix(); - + glPopMatrix(); + // Right Pupil + glPushMatrix(); + glRotatef(EyeballPitch[1], 1, 0, 0); + glRotatef(EyeballYaw[1] + PupilConverge, 0, 1, 0); + glTranslatef(0,0,.35); + if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); + //glRotatef(90,0,1,0); + glutSolidSphere(PupilSize, 15, 15); - // Eyebrows - glPushMatrix(); - glTranslatef(-interBrowDistance/2.0,0.4,0.45); - for(side = 0; side < 2; side++) + glPopMatrix(); + // Left Eye + glColor3fv(eyeColor); + glTranslatef(interPupilDistance, 0, 0); + glPushMatrix(); { - glColor3fv(browColor); - glPushMatrix(); - glTranslatef(0, 0.4, 0); - glRotatef(EyebrowPitch[side]/2.0, 1, 0, 0); - glRotatef(EyebrowRoll[side]/2.0, 0, 0, 1); - glScalef(browWidth, browThickness, 1); - glutSolidCube(0.5); - glPopMatrix(); - glTranslatef(interBrowDistance, 0, 0); + glTranslatef(-interPupilDistance/10.0, 0, .05); + glRotatef(-20, 0, 0, 1); + glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ); + glutSolidSphere(0.25, 30, 30); } - glPopMatrix(); - - - // Mouth - - glPushMatrix(); - glTranslatef(0,-0.3,0.75); - glColor3f(loudness/1000.0,0,0); - glRotatef(MouthPitch, 1, 0, 0); - glRotatef(MouthYaw, 0, 0, 1); - glScalef(MouthWidth*(.5 + averageLoudness/3000.0), MouthHeight*(1.0 + averageLoudness/6000.0), 1); - glutSolidCube(0.5); - glPopMatrix(); - - glTranslatef(0, 1.0, 0); - - glTranslatef(-interPupilDistance/2.0,-0.68,0.7); - // Right Eye - glRotatef(-10, 1, 0, 0); - glColor3fv(eyeColor); - glPushMatrix(); - { - glTranslatef(interPupilDistance/10.0, 0, 0.05); - glRotatef(20, 0, 0, 1); - glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ); - glutSolidSphere(0.25, 30, 30); + glPopMatrix(); + // Left Pupil + glPushMatrix(); + glRotatef(EyeballPitch[0], 1, 0, 0); + glRotatef(EyeballYaw[0] - PupilConverge, 0, 1, 0); + glTranslatef(0,0,.35); + if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); + //glRotatef(90,0,1,0); + glutSolidSphere(PupilSize, 15, 15); + glPopMatrix(); + + glPopMatrix(); } - glPopMatrix(); - // Right Pupil - glPushMatrix(); - glRotatef(EyeballPitch[1], 1, 0, 0); - glRotatef(EyeballYaw[1] + PupilConverge, 0, 1, 0); - glTranslatef(0,0,.35); - if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); - //glRotatef(90,0,1,0); - glutSolidSphere(PupilSize, 15, 15); - - glPopMatrix(); - // Left Eye - glColor3fv(eyeColor); - glTranslatef(interPupilDistance, 0, 0); - glPushMatrix(); - { - glTranslatef(-interPupilDistance/10.0, 0, .05); - glRotatef(-20, 0, 0, 1); - glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ); - glutSolidSphere(0.25, 30, 30); - } - glPopMatrix(); - // Left Pupil - glPushMatrix(); - glRotatef(EyeballPitch[0], 1, 0, 0); - glRotatef(EyeballYaw[0] - PupilConverge, 0, 1, 0); - glTranslatef(0,0,.35); - if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); - //glRotatef(90,0,1,0); - glutSolidSphere(PupilSize, 15, 15); - glPopMatrix(); - glPopMatrix(); } diff --git a/interface/src/Head.h b/interface/src/Head.h index 558fb4f6db..c0a51e0bfc 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -80,7 +80,7 @@ public: float getRoll() {return Roll;} float getYaw() {return Yaw;} - void render(int faceToFace); + void render(int faceToFace, float * myLocation); void simulate(float); // Send and receive network data int getBroadcastData(char* data); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 3f1ff96f2e..fcf424cc0b 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -58,7 +58,7 @@ int simulate_on = 1; const int MAX_PACKET_SIZE = 1500; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; -char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup +char DOMAIN_IP[100] = "192.168.1.47"; // IP Address will be used first if not empty string const int DOMAINSERVER_PORT = 40102; UDPSocket agentSocket(AGENT_UDP_PORT); @@ -74,7 +74,7 @@ int bytescount = 0; int target_x, target_y; int target_display = 0; -int head_mirror = 1; // Whether to mirror own head when viewing it +int head_mirror = 1; // Whether to mirror own head when viewing it int sendToSelf = 1; int WIDTH = 1200; @@ -570,7 +570,7 @@ void display(void) if (display_field) field.render(); // Render heads of other agents - render_agents(sendToSelf); + render_agents(sendToSelf, &location[0]); if (display_hand) myHand.render(); @@ -585,7 +585,7 @@ void display(void) glPushMatrix(); glLoadIdentity(); glTranslatef(0.f, 0.f, -7.f); - myHead.render(1); + myHead.render(1, &location[0]); glPopMatrix(); } //glm::vec3 test(0.5, 0.5, 0.5); @@ -795,13 +795,14 @@ void *networkReceive(void *args) // // Message from domainserver // - // printf("agent list received!\n"); + //printf("agent list received!\n"); nearbyAgents = update_agents(&incomingPacket[1], bytesRecvd - 1); kludgyMixerUpdate(audio); } else if (incomingPacket[0] == 'H') { // // Broadcast packet from another agent // + //printf("broadcast received"); update_agent(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), &incomingPacket[1], bytesRecvd - 1); } else if (incomingPacket[0] == 'T') { // Received a self-test packet (to get one's own IP), copy it to local variable! @@ -927,18 +928,19 @@ int main(int argc, char** argv) // Create network socket and buffer incomingPacket = new char[MAX_PACKET_SIZE]; - // Lookup the IP address of things we have hostnames - printf("need to look this one up\n"); - struct hostent* pHostInfo; - if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) { - sockaddr_in tempAddress; - memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length); - strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr)); - printf("Domain server found: %s\n", DOMAIN_IP); + // Lookup the IP address of things we have hostnames + if (atoi(DOMAIN_IP) == 0) { + struct hostent* pHostInfo; + if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) { + sockaddr_in tempAddress; + memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length); + strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr)); + printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP); - } else { - printf("Failed lookup domain server\n"); - } + } else { + printf("Failed lookup domainserver\n"); + } + } else printf("Using static domainserver IP: %s\n", DOMAIN_IP); //std::cout << "Test address: " << inet_ntoa(testAddress.sin_addr) << "\n";