diff --git a/agent.cpp b/agent.cpp index f0f3fe9bc9..63aef1c6b4 100644 --- a/agent.cpp +++ b/agent.cpp @@ -18,7 +18,9 @@ struct AgentList { } agents[MAX_AGENTS]; int num_agents = 0; -// Process an incoming packet that lists the other agents in the area +// +// Process an incoming spaceserver packet telling you about other nearby agents +// void update_agents(char * data, int length) { std::string packet(data, length); //std::string packet("127.0.0.1,"); @@ -39,6 +41,9 @@ void update_agents(char * data, int length) { } } +// +// Look for an agent by it's IP number, add if it does not exist in local list +// int add_agent(std::string * IP) { in_addr_t addr = inet_addr(IP->c_str()); //std::cout << "Checking for " << IP->c_str() << " "; @@ -55,12 +60,14 @@ int add_agent(std::string * IP) { num_agents++; return 1; } else { - std::cout << "Max agents reached!\n"; + std::cout << "Max agents reached fail!\n"; return 0; } } +// // Broadcast data to all the other agents you are aware of, returns 1 for success +// int broadcast(int handle, char * data, int length) { sockaddr_in dest_address; dest_address.sin_family = AF_INET; diff --git a/agent.h b/agent.h index 896b76923f..ec3f42028b 100644 --- a/agent.h +++ b/agent.h @@ -19,5 +19,6 @@ void update_agents(char * data, int length); int add_agent(std::string * IP); +int broadcast(int handle, char * data, int length); #endif diff --git a/interface.xcodeproj/project.pbxproj b/interface.xcodeproj/project.pbxproj index 18a6cffacf..8930389ea0 100644 --- a/interface.xcodeproj/project.pbxproj +++ b/interface.xcodeproj/project.pbxproj @@ -235,6 +235,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0430; + ORGANIZATIONNAME = "Rosedale Lab"; }; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "interface" */; compatibilityVersion = "Xcode 3.2"; diff --git a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate index 13077bb321..99d39951b8 100644 Binary files a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate and b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/main.cpp b/main.cpp index 9f4d612058..016e202ab0 100644 --- a/main.cpp +++ b/main.cpp @@ -455,6 +455,10 @@ void update_pos(float frametime) // Update head and manipulator objects with object with current location myHead.setPos(glm::vec3(location[0], location[1], location[2])); balls.updateHand(myHead.getPos() + myHand.getPos(), glm::vec3(0,0,0), myHand.getRadius()); + + // Update all this stuff to any agents that are nearby and need to see it! + char test[] = "BXXX"; + broadcast(UDP_socket, test, strlen(test)); } void display(void) @@ -507,6 +511,9 @@ void display(void) // Render the world box if (!display_head) render_world_box(); + + glm::vec3 test(0.5, 0.5, 0.5); + render_vector(&test); glPopMatrix(); @@ -630,6 +637,9 @@ void key(unsigned char k, int x, int y) } } +// +// Check for and process incoming network packets +// void read_network() { // Receive packets @@ -640,19 +650,29 @@ void read_network() bytescount += bytes_recvd; // If packet is a Mouse data packet, copy it over if (incoming_packet[0] == 'M') { + // + // mouse location packet + // sscanf(incoming_packet, "M %d %d", &target_x, &target_y); target_display = 1; printf("X = %d Y = %d\n", target_x, target_y); } else if (incoming_packet[0] == 'P') { - // Ping packet - check time and record + // + // Ping packet - check time and record + // timeval check; gettimeofday(&check, NULL); ping_msecs = (float)diffclock(ping_start, check); } else if (incoming_packet[0] == 'S') { + // // Message from Spaceserver - //std::cout << "Spaceserver: "; - //outstring(incoming_packet, bytes_recvd); + // update_agents(&incoming_packet[1], bytes_recvd - 1); + } else if (incoming_packet[0] == 'B') { + // + // Broadcast packet from another agent + // + //std::cout << "Got broadcast from agent\n"; } } } diff --git a/util.cpp b/util.cpp index 1e3c786bf9..81d6bca869 100644 --- a/util.cpp +++ b/util.cpp @@ -20,6 +20,44 @@ float randFloat () { return (rand()%10000)/10000.f; } +void render_vector(glm::vec3 * vec) +{ + // Show edge of world + glDisable(GL_LIGHTING); + glColor4f(1.0, 1.0, 1.0, 1.0); + glLineWidth(1.0); + glBegin(GL_LINES); + // Draw axes + glColor3f(1,0,0); + glVertex3f(-1,0,0); + glVertex3f(1,0,0); + glColor3f(0,1,0); + glVertex3f(0,-1,0); + glVertex3f(0, 1, 0); + glColor3f(0,0,1); + glVertex3f(0,0,-1); + glVertex3f(0, 0, 1); + // Draw vector + glColor3f(1,1,1); + glVertex3f(0,0,0); + glVertex3f(vec->x, vec->y, vec->z); + // Draw marker dots for magnitude + glEnd(); + float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles + glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particle_attenuation_quadratic ); + glEnable(GL_POINT_SMOOTH); + glPointSize(10.0); + glBegin(GL_POINTS); + glColor3f(1,0,0); + glVertex3f(vec->x,0,0); + glColor3f(0,1,0); + glVertex3f(0,vec->y,0); + glColor3f(0,0,1); + glVertex3f(0,0,vec->z); + glEnd(); + +} + void render_world_box() { // Show edge of world diff --git a/util.h b/util.h index 2eac21117b..637248b761 100644 --- a/util.h +++ b/util.h @@ -13,6 +13,7 @@ void outstring(char * string, int length); float randFloat(); void render_world_box(); +void render_vector(glm::vec3 * vec); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char *string, float r=1.0, float g=1.0, float b=1.0); void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,