mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Added vector renderer util, broadcast packets now reaching agents
This commit is contained in:
parent
5daf15ac2d
commit
2b62adce6c
7 changed files with 73 additions and 5 deletions
11
agent.cpp
11
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;
|
||||
|
|
1
agent.h
1
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
|
||||
|
|
|
@ -235,6 +235,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0430;
|
||||
ORGANIZATIONNAME = "Rosedale Lab";
|
||||
};
|
||||
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "interface" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
|
|
Binary file not shown.
26
main.cpp
26
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
util.cpp
38
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
|
||||
|
|
1
util.h
1
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,
|
||||
|
|
Loading…
Reference in a new issue