Don't render head if you are inside it (it's your own)

This commit is contained in:
Philip Rosedale 2013-02-14 13:14:01 -08:00
parent 864bcb0a03
commit 10ff074e38
5 changed files with 125 additions and 112 deletions

View file

@ -57,7 +57,7 @@ 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();
@ -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";

View file

@ -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

View file

@ -206,10 +206,17 @@ void Head::simulate(float deltaTime)
}
void Head::render(int faceToFace)
void Head::render(int faceToFace, float * myLocation)
{
int side = 0;
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();
@ -319,6 +326,8 @@ void Head::render(int faceToFace)
glPopMatrix();
}
}
// Transmit data to agents requesting it

View file

@ -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);

View file

@ -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 re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102;
UDPSocket agentSocket(AGENT_UDP_PORT);
@ -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);
@ -802,6 +802,7 @@ void *networkReceive(void *args)
//
// 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!
@ -928,6 +929,7 @@ int main(int argc, char** argv)
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) {
@ -939,6 +941,7 @@ int main(int argc, char** argv)
} else {
printf("Failed lookup domain server\n");
}
*/
//std::cout << "Test address: " << inet_ntoa(testAddress.sin_addr) << "\n";