From 5417df84f77d914e1941f82cc00b99e8024ede89 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 7 Feb 2013 15:08:50 -0800 Subject: [PATCH] Changing port names and fixing head rendering --- Source/Agent.cpp | 4 ++-- Source/Finger.cpp | 2 +- Source/Head.cpp | 28 ++++++++++++++++++++-------- Source/Head.h | 2 +- Source/Lattice.cpp | 2 +- Source/Network.cpp | 10 +++++----- Source/Network.h | 8 ++++++-- Source/main.cpp | 12 ++++++------ 8 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Source/Agent.cpp b/Source/Agent.cpp index a91d4ef6ad..9632c4a442 100644 --- a/Source/Agent.cpp +++ b/Source/Agent.cpp @@ -47,7 +47,7 @@ void render_agents() { glm::vec3 pos = agents[i].head.getPos(); glPushMatrix(); glTranslatef(pos.x, pos.y, pos.z); - agents[i].head.render(); + agents[i].head.render(0); glPopMatrix(); } } @@ -96,7 +96,7 @@ int add_agent(std::string * IP) { int broadcast_to_agents(int handle, char * data, int length) { sockaddr_in dest_address; dest_address.sin_family = AF_INET; - dest_address.sin_port = htons( (unsigned short) UDP_PORT ); + dest_address.sin_port = htons( (unsigned short) AGENT_UDP_PORT ); int sent_bytes; for (int i = 0; i < num_agents; i++) { diff --git a/Source/Finger.cpp b/Source/Finger.cpp index bdb2aa749c..840915a6fb 100644 --- a/Source/Finger.cpp +++ b/Source/Finger.cpp @@ -104,7 +104,7 @@ void Finger::simulate(float deltaTime) { // Move the finger float distance = glm::distance(pos, target); - float spring_length = 0; + //float spring_length = 0; const float SPRING_FORCE = 1000.0; if (distance > 0.1) { diff --git a/Source/Head.cpp b/Source/Head.cpp index 208dec75d3..c26a33c336 100644 --- a/Source/Head.cpp +++ b/Source/Head.cpp @@ -76,7 +76,7 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea // Update avatar head position based on measured gyro rates const float HEAD_ROTATION_SCALE = 0.80; const float HEAD_ROLL_SCALE = 0.80; - const float HEAD_LEAN_SCALE = 0.01; + const float HEAD_LEAN_SCALE = 0.05; if (head_mirror) { addYaw(-measured_yaw_rate * HEAD_ROTATION_SCALE * frametime); addPitch(measured_pitch_rate * -HEAD_ROTATION_SCALE * frametime); @@ -204,18 +204,30 @@ void Head::simulate(float deltaTime) } -void Head::render() +void Head::render(int faceToFace) { int side = 0; glEnable(GL_DEPTH_TEST); glPushMatrix(); + + glScalef(scale, scale, scale); - glScalef(scale, scale, scale); glTranslatef(leanSideways, 0.f, leanForward); - //printf("x: %3.1f\n", position.x); - glTranslatef(3,3,2); - //glTranslatef(position.x, position.y, position.z); + + if (!faceToFace) + { + //printf("x: %3.1f\n", position.x); + //glTranslatef(3,3,2); + //printf("head: %3.1f, %3.1f, %3.1f\n", position.x, position.y, position.z); + float x = position.x; + float y = position.y; + float z = position.z; + + //glTranslatef(6.1, 0, 1.4); + glTranslatef(x,y,z); + //glTranslatef(position.x, position.y, position.z); + } glRotatef(Yaw/2.0, 0, 1, 0); glRotatef(Pitch/2.0, 1, 0, 0); @@ -290,7 +302,7 @@ void Head::render() 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.1,0.1,1.0); + if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); //glRotatef(90,0,1,0); glutSolidSphere(PupilSize, 15, 15); @@ -311,7 +323,7 @@ void Head::render() 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.1,0.1,1.0); + if (!eyeContact) glColor3f(0,0,0); else glColor3f(0.3,0.3,0.3); //glRotatef(90,0,1,0); glutSolidSphere(PupilSize, 15, 15); glPopMatrix(); diff --git a/Source/Head.h b/Source/Head.h index 71387eef7c..ec4a78e4f4 100644 --- a/Source/Head.h +++ b/Source/Head.h @@ -75,7 +75,7 @@ public: float getRoll() {return Roll;} float getYaw() {return Yaw;} - void render(); + void render(int faceToFace); void simulate(float); // Send and receive network data int getBroadcastData(char* data); diff --git a/Source/Lattice.cpp b/Source/Lattice.cpp index 443d3fe51d..bb3bc08818 100644 --- a/Source/Lattice.cpp +++ b/Source/Lattice.cpp @@ -64,7 +64,7 @@ void Lattice::mouseOver(float x, float y) { // Update lattice based on mouse location, where x and y are floats between 0 and 1 corresponding to screen location clicked // Excite the hovered cell a bit toward firing //printf("X = %3.1f Y = %3.1f\n", x, y); - if ((width + height) > 0) { + if (0) { int index = int(x*(float)width) + int(y*(float)height)*width; if (tiles[index].type > 0) tiles[index].excited += 0.05; //printf("excited = %3.1f, inhibited = %3.1f\n", tiles[index].excited, tiles[index].inhibited); diff --git a/Source/Network.cpp b/Source/Network.cpp index 561e786375..5cc116f7fd 100644 --- a/Source/Network.cpp +++ b/Source/Network.cpp @@ -36,7 +36,7 @@ int network_init() // Bind socket to port address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = htons( (unsigned short) UDP_PORT ); + address.sin_port = htons( (unsigned short) SENDING_UDP_PORT ); if ( bind( handle, (const sockaddr*) &address, sizeof(sockaddr_in) ) < 0 ) { @@ -63,7 +63,7 @@ int network_init() dest_address.sin_family = AF_INET; dest_address.sin_addr.s_addr = inet_addr(DESTINATION_IP); - dest_address.sin_port = htons( (unsigned short) UDP_PORT ); + //dest_address.sin_port = htons( (unsigned short) UDP_PORT ); domainserver_address.sin_family = AF_INET; domainserver_address.sin_addr.s_addr = inet_addr(DOMAINSERVER_IP); @@ -71,7 +71,7 @@ int network_init() from.sin_family = AF_INET; //from.sin_addr.s_addr = htonl(ip_address); - from.sin_port = htons( (unsigned short) UDP_PORT ); + //from.sin_port = htons( (unsigned short) UDP_PORT ); return handle; } @@ -89,8 +89,8 @@ timeval network_send_ping(int handle) { int notify_domainserver(int handle, float x, float y, float z) { char data[100]; sprintf(data, "%f,%f,%f", x, y, z); - //std::cout << "sending: " << data << "\n"; int packet_size = strlen(data); + //std::cout << "sending: " << data << " of size: " << packet_size << "\n"; int sent_bytes = sendto( handle, (const char*)data, packet_size, 0, (sockaddr*)&domainserver_address, sizeof(sockaddr_in) ); if ( sent_bytes != packet_size ) @@ -110,7 +110,7 @@ int network_send(int handle, char * packet_data, int packet_size) if ( sent_bytes != packet_size ) { - printf( "failed to send packet: return value = %d\n", sent_bytes ); + printf( "failed to send packet to address, port: %s, %d, returned = %d\n", inet_ntoa(dest_address.sin_addr), dest_address.sin_port, sent_bytes ); return false; } return sent_bytes; diff --git a/Source/Network.h b/Source/Network.h index 189f32c168..59c823cabd 100644 --- a/Source/Network.h +++ b/Source/Network.h @@ -18,12 +18,16 @@ // Port to use for communicating UDP with other nearby agents const int MAX_PACKET_SIZE = 1500; -const int UDP_PORT = 30001; +const int SENDING_UDP_PORT = 40100; + +const int AGENT_UDP_PORT = 40103; + const char DESTINATION_IP[] = "127.0.0.1"; // Address and port of domainserver process to advertise other agents const char DOMAINSERVER_IP[] = "127.0.0.1"; -const int DOMAINSERVER_PORT = 40000; + +const int DOMAINSERVER_PORT = 40102; // Randomly send a ping packet every N packets sent const int PING_PACKET_COUNT = 20; diff --git a/Source/main.cpp b/Source/main.cpp index ce4cebc25d..d25ab9d9e7 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -392,8 +392,8 @@ void update_pos(float frametime) { float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE); float measured_yaw_rate = serialPort.getRelativeValue(YAW_RATE); - float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X); - float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z); + //float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X); + //float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z); myHead.UpdatePos(frametime, &serialPort, head_mirror, &gravity); @@ -569,15 +569,15 @@ void display(void) glPushMatrix(); glLoadIdentity(); glTranslatef(0.f, 0.f, -7.f); - myHead.render(); + myHead.render(1); glPopMatrix(); } // Render dummy head - if (showDummyHead) dummyHead.render(); + if (showDummyHead) dummyHead.render(0); // Render heads of other agents - if (!display_head) render_agents(); + if (!display_head) render_agents(); if (display_hand) myHand.render(); @@ -790,7 +790,7 @@ void read_network() // // Broadcast packet from another agent // - //update_agent(from_addr, &incoming_packet[1], bytes_recvd - 1); + update_agent(from_addr, &incoming_packet[1], bytes_recvd - 1); } } }