mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
Merge branch 'master' of github.com:worklist/hifi
This commit is contained in:
commit
f371b5e21c
14 changed files with 150 additions and 136 deletions
|
@ -5,6 +5,8 @@
|
||||||
// Created by Philip Rosedale on 11/20/12.
|
// Created by Philip Rosedale on 11/20/12.
|
||||||
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
|
// The Domain Server
|
||||||
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -33,12 +35,13 @@ const int MAX_AGENTS = 1000;
|
||||||
const int LOGOFF_CHECK_INTERVAL = 2000;
|
const int LOGOFF_CHECK_INTERVAL = 2000;
|
||||||
|
|
||||||
struct AgentList {
|
struct AgentList {
|
||||||
|
char agentType;
|
||||||
uint32_t ip;
|
uint32_t ip;
|
||||||
in_addr sin_addr;
|
in_addr sin_addr;
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
bool active;
|
bool active;
|
||||||
timeval time;
|
timeval time, connectTime;
|
||||||
} agents[MAX_AGENTS];
|
} agents[MAX_AGENTS];
|
||||||
|
|
||||||
int num_agents = 0;
|
int num_agents = 0;
|
||||||
|
@ -89,7 +92,7 @@ int network_init()
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addAgent(uint32_t ip, in_port_t port, float x, float y, float z) {
|
int addAgent(uint32_t ip, in_port_t port, char agentType, float x, float y, float z) {
|
||||||
// Search for agent in list and add if needed
|
// Search for agent in list and add if needed
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int is_new = 0;
|
int is_new = 0;
|
||||||
|
@ -104,7 +107,9 @@ int addAgent(uint32_t ip, in_port_t port, float x, float y, float z) {
|
||||||
agents[i].active = true;
|
agents[i].active = true;
|
||||||
agents[i].sin_addr.s_addr = ip;
|
agents[i].sin_addr.s_addr = ip;
|
||||||
agents[i].port = port;
|
agents[i].port = port;
|
||||||
|
agents[i].agentType = agentType;
|
||||||
gettimeofday(&agents[i].time, NULL);
|
gettimeofday(&agents[i].time, NULL);
|
||||||
|
if (is_new) gettimeofday(&agents[i].connectTime, NULL);
|
||||||
if (i == num_agents) {
|
if (i == num_agents) {
|
||||||
num_agents++;
|
num_agents++;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +122,7 @@ void update_agent_list(timeval now) {
|
||||||
for (i = 0; i < num_agents; i++) {
|
for (i = 0; i < num_agents; i++) {
|
||||||
if ((diffclock(agents[i].time, now) > LOGOFF_CHECK_INTERVAL) &&
|
if ((diffclock(agents[i].time, now) > LOGOFF_CHECK_INTERVAL) &&
|
||||||
agents[i].active) {
|
agents[i].active) {
|
||||||
std::cout << "Expired Agent from " <<
|
std::cout << "Expired Agent type " << agents[i].agentType << " from " <<
|
||||||
inet_ntoa(agents[i].sin_addr) << ":" << agents[i].port << "\n";
|
inet_ntoa(agents[i].sin_addr) << ":" << agents[i].port << "\n";
|
||||||
agents[i].active = false;
|
agents[i].active = false;
|
||||||
}
|
}
|
||||||
|
@ -135,12 +140,14 @@ void send_agent_list(int handle, sockaddr_in * dest_address) {
|
||||||
//std::cout << "send list to: " << inet_ntoa(dest_address->sin_addr) << "\n";
|
//std::cout << "send list to: " << inet_ntoa(dest_address->sin_addr) << "\n";
|
||||||
for (i = 0; i < num_agents; i++) {
|
for (i = 0; i < num_agents; i++) {
|
||||||
if (agents[i].active) {
|
if (agents[i].active) {
|
||||||
|
// Write the type of the agent
|
||||||
|
buffer[length++] = agents[i].agentType;
|
||||||
// Write agent's IP address
|
// Write agent's IP address
|
||||||
address = inet_ntoa(agents[i].sin_addr);
|
address = inet_ntoa(agents[i].sin_addr);
|
||||||
memcpy(&buffer[length], address, strlen(address));
|
memcpy(&buffer[length], address, strlen(address));
|
||||||
length += strlen(address);
|
length += strlen(address);
|
||||||
// Add port number
|
// Add port number
|
||||||
buffer[length++] = ':';
|
buffer[length++] = ' ';
|
||||||
sprintf(portstring, "%d\n", agents[i].port);
|
sprintf(portstring, "%d\n", agents[i].port);
|
||||||
memcpy(&buffer[length], portstring, strlen(portstring));
|
memcpy(&buffer[length], portstring, strlen(portstring));
|
||||||
length += strlen(portstring);
|
length += strlen(portstring);
|
||||||
|
@ -185,9 +192,10 @@ int main(int argc, const char * argv[])
|
||||||
//std::cout << "Packet from: " << inet_ntoa(dest_address.sin_addr)
|
//std::cout << "Packet from: " << inet_ntoa(dest_address.sin_addr)
|
||||||
//<< " " << packet_data << "\n";
|
//<< " " << packet_data << "\n";
|
||||||
float x,y,z;
|
float x,y,z;
|
||||||
sscanf(packet_data, "%f,%f,%f", &x, &y, &z);
|
char agentType;
|
||||||
if (addAgent(dest_address.sin_addr.s_addr, ntohs(dest_address.sin_port), x, y, z)) {
|
sscanf(packet_data, "%c %f,%f,%f", &agentType, &x, &y, &z);
|
||||||
std::cout << "Added Agent from " <<
|
if (addAgent(dest_address.sin_addr.s_addr, ntohs(dest_address.sin_port), agentType, x, y, z)) {
|
||||||
|
std::cout << "Added Agent, type " << agentType << " from " <<
|
||||||
inet_ntoa(dest_address.sin_addr) << ":" << ntohs(dest_address.sin_port) << "\n";
|
inet_ntoa(dest_address.sin_addr) << ":" << ntohs(dest_address.sin_port) << "\n";
|
||||||
}
|
}
|
||||||
// Reply with packet listing nearby active agents
|
// Reply with packet listing nearby active agents
|
||||||
|
|
|
@ -20,6 +20,8 @@ struct AgentList {
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
timeval pingStarted;
|
timeval pingStarted;
|
||||||
int pingMsecs;
|
int pingMsecs;
|
||||||
|
char agentType;
|
||||||
|
bool isSelf;
|
||||||
Head head;
|
Head head;
|
||||||
} agents[MAX_AGENTS];
|
} agents[MAX_AGENTS];
|
||||||
|
|
||||||
|
@ -35,18 +37,16 @@ int update_agents(char * data, int length) {
|
||||||
size_t spot;
|
size_t spot;
|
||||||
size_t start_spot = 0;
|
size_t start_spot = 0;
|
||||||
std::string address, port;
|
std::string address, port;
|
||||||
|
char agentType;
|
||||||
unsigned short nPort = 0;
|
unsigned short nPort = 0;
|
||||||
|
unsigned int iPort = 0;
|
||||||
spot = packet.find_first_of (",", 0);
|
spot = packet.find_first_of (",", 0);
|
||||||
while (spot != std::string::npos) {
|
while (spot != std::string::npos) {
|
||||||
std::string thisAgent = packet.substr(start_spot, spot-start_spot);
|
std::string thisAgent = packet.substr(start_spot, spot-start_spot);
|
||||||
if (thisAgent.find_first_of(":", 0) != std::string::npos) {
|
//std::cout << "raw string: " << thisAgent << "\n";
|
||||||
address = thisAgent.substr(0, thisAgent.find_first_of(":", 0));
|
sscanf(thisAgent.c_str(), "%c %s %u", &agentType, address.c_str(), &iPort);
|
||||||
port = thisAgent.substr(thisAgent.find_first_of(":", 0) + 1,
|
nPort = (unsigned short) iPort;
|
||||||
thisAgent.length() - thisAgent.find_first_of(":", 0));
|
add_agent((char *)address.c_str(), nPort, agentType);
|
||||||
nPort = atoi(port.c_str());
|
|
||||||
}
|
|
||||||
//std::cout << "IP: " << address << ", port: " << nPort << "\n";
|
|
||||||
add_agent((char *)address.c_str(), nPort);
|
|
||||||
numAgents++;
|
numAgents++;
|
||||||
start_spot = spot + 1;
|
start_spot = spot + 1;
|
||||||
if (start_spot < packet.length())
|
if (start_spot < packet.length())
|
||||||
|
@ -56,12 +56,15 @@ int update_agents(char * data, int length) {
|
||||||
return numAgents;
|
return numAgents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_agents() {
|
// Render the heads of the agents
|
||||||
|
void render_agents(int renderSelf) {
|
||||||
for (int i = 0; i < num_agents; i++) {
|
for (int i = 0; i < num_agents; i++) {
|
||||||
glm::vec3 pos = agents[i].head.getPos();
|
glm::vec3 pos = agents[i].head.getPos();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(pos.x, pos.y, pos.z);
|
if (!agents[i].isSelf || renderSelf) {
|
||||||
agents[i].head.render(0);
|
glTranslatef(-pos.x, -pos.y, -pos.z);
|
||||||
|
agents[i].head.render(0);
|
||||||
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +79,9 @@ void update_agent(char * address, unsigned short port, char * data, int length)
|
||||||
if ((strcmp(address, agents[i].address) == 0) && (agents[i].port == port)) {
|
if ((strcmp(address, agents[i].address) == 0) && (agents[i].port == port)) {
|
||||||
// Update the agent
|
// Update the agent
|
||||||
agents[i].head.recvBroadcastData(data, length);
|
agents[i].head.recvBroadcastData(data, length);
|
||||||
|
if ((strcmp(address, "127.0.0.1") == 0) && (port == AGENT_UDP_PORT)) {
|
||||||
|
agents[i].isSelf = true;
|
||||||
|
} else agents[i].isSelf = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +89,7 @@ void update_agent(char * address, unsigned short port, char * data, int length)
|
||||||
//
|
//
|
||||||
// Look for an agent by it's IP number, add if it does not exist in local list
|
// Look for an agent by it's IP number, add if it does not exist in local list
|
||||||
//
|
//
|
||||||
int add_agent(char * address, unsigned short port) {
|
int add_agent(char * address, unsigned short port, char agentType) {
|
||||||
//std::cout << "Checking for " << IP->c_str() << " ";
|
//std::cout << "Checking for " << IP->c_str() << " ";
|
||||||
for (int i = 0; i < num_agents; i++) {
|
for (int i = 0; i < num_agents; i++) {
|
||||||
if ((strcmp(address, agents[i].address) == 0) && (agents[i].port == port)) {
|
if ((strcmp(address, agents[i].address) == 0) && (agents[i].port == port)) {
|
||||||
|
@ -94,6 +100,7 @@ int add_agent(char * address, unsigned short port) {
|
||||||
if (num_agents < MAX_AGENTS) {
|
if (num_agents < MAX_AGENTS) {
|
||||||
strcpy(agents[num_agents].address, address);
|
strcpy(agents[num_agents].address, address);
|
||||||
agents[num_agents].port = port;
|
agents[num_agents].port = port;
|
||||||
|
agents[num_agents].agentType = agentType;
|
||||||
std::cout << "Added Agent # " << num_agents << " with Address " <<
|
std::cout << "Added Agent # " << num_agents << " with Address " <<
|
||||||
agents[num_agents].address << ":" << agents[num_agents].port << "\n";
|
agents[num_agents].address << ":" << agents[num_agents].port << "\n";
|
||||||
num_agents++;
|
num_agents++;
|
||||||
|
@ -107,22 +114,16 @@ int add_agent(char * address, unsigned short port) {
|
||||||
//
|
//
|
||||||
// Broadcast data to all the other agents you are aware of, returns 1 if success
|
// Broadcast data to all the other agents you are aware of, returns 1 if success
|
||||||
//
|
//
|
||||||
int broadcastToAgents(UDPSocket *handle, char * data, int length) {
|
int broadcastToAgents(UDPSocket *handle, char * data, int length, int sendToSelf) {
|
||||||
int sent_bytes;
|
int sent_bytes;
|
||||||
//printf("broadcasting to %d agents\n", num_agents);
|
//printf("broadcasting to %d agents\n", num_agents);
|
||||||
for (int i = 0; i < num_agents; i++) {
|
for (int i = 0; i < num_agents; i++) {
|
||||||
//printf("bcast to %s\n", agents[i].address);
|
//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)
|
||||||
// STUPID HACK: For some reason on OSX with NAT translation packets sent to localhost are
|
&& (agents[i].port != AGENT_UDP_PORT)))
|
||||||
// received as from the NAT translated port but have to be sent to the local port number.
|
|
||||||
//
|
|
||||||
//if (1) //(strcmp("192.168.1.53",agents[i].address) == 0)
|
|
||||||
// sent_bytes = handle->send(agents[i].address, 40103, data, length);
|
|
||||||
//else
|
|
||||||
sent_bytes = handle->send(agents[i].address, agents[i].port, data, length);
|
sent_bytes = handle->send(agents[i].address, agents[i].port, data, length);
|
||||||
|
|
||||||
if (sent_bytes != length) {
|
if (sent_bytes != length) {
|
||||||
std::cout << "Broadcast packet fail!\n";
|
std::cout << "Broadcast to agents FAILED\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +136,7 @@ void pingAgents(UDPSocket *handle) {
|
||||||
for (int i = 0; i < num_agents; i++) {
|
for (int i = 0; i < num_agents; i++) {
|
||||||
gettimeofday(&agents[i].pingStarted, NULL);
|
gettimeofday(&agents[i].pingStarted, NULL);
|
||||||
handle->send(agents[i].address, agents[i].port, payload, 1);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ void setAgentPing(char * address, unsigned short port) {
|
||||||
timeval pingReceived;
|
timeval pingReceived;
|
||||||
gettimeofday(&pingReceived, NULL);
|
gettimeofday(&pingReceived, NULL);
|
||||||
float pingMsecs = diffclock(&agents[i].pingStarted, &pingReceived);
|
float pingMsecs = diffclock(&agents[i].pingStarted, &pingReceived);
|
||||||
printf("Received ping at %d usecs, Agent ping = %3.1f\n", pingReceived.tv_usec, pingMsecs);
|
//printf("Received ping at %d usecs, Agent ping = %3.1f\n", pingReceived.tv_usec, pingMsecs);
|
||||||
agents[i].pingMsecs = pingMsecs;
|
agents[i].pingMsecs = pingMsecs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
|
const int AGENT_UDP_PORT = 40103;
|
||||||
|
|
||||||
int update_agents(char * data, int length);
|
int update_agents(char * data, int length);
|
||||||
int add_agent(char * address, unsigned short port);
|
int add_agent(char * address, unsigned short port, char agentType);
|
||||||
int broadcastToAgents(UDPSocket * handle, char * data, int length);
|
int broadcastToAgents(UDPSocket * handle, char * data, int length, int sendToSelf);
|
||||||
void pingAgents(UDPSocket *handle);
|
void pingAgents(UDPSocket *handle);
|
||||||
void setAgentPing(char * address, unsigned short port);
|
void setAgentPing(char * address, unsigned short port);
|
||||||
void update_agent(char * address, unsigned short port, char * data, int length);
|
void update_agent(char * address, unsigned short port, char * data, int length);
|
||||||
void render_agents();
|
void render_agents(int renderSelf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include "AudioSource.h"
|
#include "AudioSource.h"
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
|
Oscilloscope * scope;
|
||||||
|
|
||||||
const short BUFFER_LENGTH_BYTES = 1024;
|
const short BUFFER_LENGTH_BYTES = 1024;
|
||||||
const short BUFFER_LENGTH_SAMPLES = BUFFER_LENGTH_BYTES / sizeof(int16_t);
|
const short BUFFER_LENGTH_SAMPLES = BUFFER_LENGTH_BYTES / sizeof(int16_t);
|
||||||
|
|
||||||
|
@ -97,6 +99,14 @@ int audioCallback (const void *inputBuffer,
|
||||||
loudness /= BUFFER_LENGTH_SAMPLES;
|
loudness /= BUFFER_LENGTH_SAMPLES;
|
||||||
data->lastInputLoudness = loudness;
|
data->lastInputLoudness = loudness;
|
||||||
data->averagedInputLoudness = 0.66*data->averagedInputLoudness + 0.33*loudness;
|
data->averagedInputLoudness = 0.66*data->averagedInputLoudness + 0.33*loudness;
|
||||||
|
//
|
||||||
|
// If scope is turned on, copy input buffer to scope
|
||||||
|
//
|
||||||
|
if (scope->getState()) {
|
||||||
|
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
|
||||||
|
scope->addData((float)inputLeft[i]/32767.0, 1, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t *outputLeft = ((int16_t **) outputBuffer)[0];
|
int16_t *outputLeft = ((int16_t **) outputBuffer)[0];
|
||||||
|
@ -105,6 +115,14 @@ int audioCallback (const void *inputBuffer,
|
||||||
memset(outputLeft, 0, BUFFER_LENGTH_BYTES);
|
memset(outputLeft, 0, BUFFER_LENGTH_BYTES);
|
||||||
memset(outputRight, 0, BUFFER_LENGTH_BYTES);
|
memset(outputRight, 0, BUFFER_LENGTH_BYTES);
|
||||||
|
|
||||||
|
// Copy output data to oscilloscope
|
||||||
|
if (scope->getState()) {
|
||||||
|
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
|
||||||
|
scope->addData((float)outputRight[i]/32767.0, 2, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ECHO_SERVER_TEST) {
|
if (ECHO_SERVER_TEST) {
|
||||||
AudioRingBuffer *ringBuffer = data->ringBuffer;
|
AudioRingBuffer *ringBuffer = data->ringBuffer;
|
||||||
|
|
||||||
|
@ -299,17 +317,19 @@ void *receiveAudioViaUDP(void *args) {
|
||||||
* @return Returns true if successful or false if an error occurred.
|
* @return Returns true if successful or false if an error occurred.
|
||||||
Use Audio::getError() to retrieve the error code.
|
Use Audio::getError() to retrieve the error code.
|
||||||
*/
|
*/
|
||||||
bool Audio::init()
|
bool Audio::init(Oscilloscope * s)
|
||||||
{
|
{
|
||||||
Head *deadHead = new Head();
|
Head *deadHead = new Head();
|
||||||
return Audio::init(deadHead);
|
return Audio::init(deadHead, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Audio::init(Head *mainHead)
|
bool Audio::init(Head *mainHead, Oscilloscope * s)
|
||||||
{
|
{
|
||||||
err = Pa_Initialize();
|
err = Pa_Initialize();
|
||||||
if (err != paNoError) goto error;
|
if (err != paNoError) goto error;
|
||||||
|
|
||||||
|
scope = s;
|
||||||
|
|
||||||
if (ECHO_SERVER_TEST) {
|
if (ECHO_SERVER_TEST) {
|
||||||
data = new AudioData(BUFFER_LENGTH_BYTES);
|
data = new AudioData(BUFFER_LENGTH_BYTES);
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
#include "Head.h"
|
#include "Head.h"
|
||||||
#include "AudioData.h"
|
#include "AudioData.h"
|
||||||
|
#include "Oscilloscope.h"
|
||||||
|
|
||||||
class Audio {
|
class Audio {
|
||||||
public:
|
public:
|
||||||
// initializes audio I/O
|
// initializes audio I/O
|
||||||
static bool init();
|
static bool init(Oscilloscope * s);
|
||||||
static bool init(Head* mainHead);
|
static bool init(Head* mainHead, Oscilloscope * s);
|
||||||
|
|
||||||
static void render();
|
static void render();
|
||||||
static void render(int screenWidth, int screenHeight);
|
static void render(int screenWidth, int screenHeight);
|
||||||
|
@ -32,6 +33,7 @@ private:
|
||||||
|
|
||||||
static AudioData *data;
|
static AudioData *data;
|
||||||
|
|
||||||
|
|
||||||
// protects constructor so that public init method is used
|
// protects constructor so that public init method is used
|
||||||
Audio();
|
Audio();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@ AudioData::AudioData(int bufferLength) {
|
||||||
sources = NULL;
|
sources = NULL;
|
||||||
|
|
||||||
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
||||||
|
averagedLatency = 0.0;
|
||||||
|
lastCallback.tv_usec = 0;
|
||||||
|
wasStarved = 0;
|
||||||
|
measuredJitter = 0;
|
||||||
|
jitterBuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioData::AudioData(int numberOfSources, int bufferLength) {
|
AudioData::AudioData(int numberOfSources, int bufferLength) {
|
||||||
|
|
|
@ -59,7 +59,6 @@ VoxelSystem::VoxelSystem(int num,
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::render() {
|
void VoxelSystem::render() {
|
||||||
glPushMatrix();
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < cube_count) {
|
while (i < cube_count) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -69,7 +68,6 @@ void VoxelSystem::render() {
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::simulate(float deltaTime) {
|
void VoxelSystem::simulate(float deltaTime) {
|
||||||
|
|
|
@ -214,22 +214,7 @@ void Head::render(int faceToFace)
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glScalef(scale, scale, scale);
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
glTranslatef(leanSideways, 0.f, leanForward);
|
glTranslatef(leanSideways, 0.f, leanForward);
|
||||||
|
|
||||||
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(Yaw/2.0, 0, 1, 0);
|
||||||
glRotatef(Pitch/2.0, 1, 0, 0);
|
glRotatef(Pitch/2.0, 1, 0, 0);
|
||||||
|
@ -237,7 +222,7 @@ void Head::render(int faceToFace)
|
||||||
|
|
||||||
|
|
||||||
// Overall scale of head
|
// Overall scale of head
|
||||||
glScalef(1.5, 2.0, 2.0);
|
if (faceToFace) glScalef(1.5, 2.0, 2.0);
|
||||||
glColor3fv(skinColor);
|
glColor3fv(skinColor);
|
||||||
|
|
||||||
// Head
|
// Head
|
||||||
|
|
|
@ -88,8 +88,8 @@ public:
|
||||||
|
|
||||||
float getLoudness() {return loudness;};
|
float getLoudness() {return loudness;};
|
||||||
float getAverageLoudness() {return averageLoudness;};
|
float getAverageLoudness() {return averageLoudness;};
|
||||||
float setAverageLoudness(float al) {averageLoudness = al;};
|
void setAverageLoudness(float al) {averageLoudness = al;};
|
||||||
float setLoudness(float l) {loudness = l;};
|
void setLoudness(float l) {loudness = l;};
|
||||||
|
|
||||||
void SetNewHeadTarget(float, float);
|
void SetNewHeadTarget(float, float);
|
||||||
glm::vec3 getPos() { return position; };
|
glm::vec3 getPos() { return position; };
|
||||||
|
|
|
@ -9,22 +9,37 @@
|
||||||
#include "Oscilloscope.h"
|
#include "Oscilloscope.h"
|
||||||
|
|
||||||
Oscilloscope::Oscilloscope(int w,
|
Oscilloscope::Oscilloscope(int w,
|
||||||
int h) {
|
int h, bool isOn) {
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
data = new float[width];
|
data1 = new float[width];
|
||||||
|
data2 = new float[width];
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
data[i] = 0.0;
|
data1[i] = 0.0;
|
||||||
|
data2[i] = 0.0;
|
||||||
}
|
}
|
||||||
|
state = isOn;
|
||||||
current_sample = 0;
|
current_sample = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Oscilloscope::addData(float d) {
|
void Oscilloscope::addData(float d, int channel, int position) {
|
||||||
data[current_sample++] = d;
|
if (channel == 1) data1[position] = d;
|
||||||
|
else data2[position] = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Oscilloscope::render() {
|
void Oscilloscope::render() {
|
||||||
|
glColor3f(1,1,1);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
//glVertex2f(
|
for (int i = 0; i < width; i++) {
|
||||||
|
glVertex2f((float)i, height/2 + data1[i]*(float)height);
|
||||||
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
glColor3f(0,1,1);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
glVertex2f((float)i, height/2 + data2[i]*(float)height);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,13 +18,16 @@
|
||||||
class Oscilloscope {
|
class Oscilloscope {
|
||||||
public:
|
public:
|
||||||
Oscilloscope(int width,
|
Oscilloscope(int width,
|
||||||
int height);
|
int height, bool isOn);
|
||||||
void addData(float data);
|
void addData(float d, int channel, int position);
|
||||||
void render();
|
void render();
|
||||||
|
void setState(bool s) {state = s;};
|
||||||
|
bool getState() {return state;};
|
||||||
private:
|
private:
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
float * data;
|
float *data1, *data2;
|
||||||
int current_sample;
|
int current_sample;
|
||||||
|
bool state;
|
||||||
};
|
};
|
||||||
#endif /* defined(__interface__oscilloscope__) */
|
#endif /* defined(__interface__oscilloscope__) */
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "Cube.h"
|
#include "Cube.h"
|
||||||
#include "Lattice.h"
|
#include "Lattice.h"
|
||||||
#include "Finger.h"
|
#include "Finger.h"
|
||||||
|
#include "Oscilloscope.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -55,8 +56,7 @@ int simulate_on = 1;
|
||||||
//
|
//
|
||||||
|
|
||||||
const int MAX_PACKET_SIZE = 1500;
|
const int MAX_PACKET_SIZE = 1500;
|
||||||
const int AGENT_UDP_PORT = 40103;
|
char DOMAINSERVER_IP[] = "127.0.0.1";
|
||||||
char DOMAINSERVER_IP[] = "192.168.1.53";
|
|
||||||
const int DOMAINSERVER_PORT = 40102;
|
const int DOMAINSERVER_PORT = 40102;
|
||||||
UDPSocket agentSocket(AGENT_UDP_PORT);
|
UDPSocket agentSocket(AGENT_UDP_PORT);
|
||||||
|
|
||||||
|
@ -73,15 +73,16 @@ int target_x, target_y;
|
||||||
int target_display = 0;
|
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 = 0;
|
||||||
|
|
||||||
int WIDTH = 1200;
|
int WIDTH = 1200;
|
||||||
int HEIGHT = 800;
|
int HEIGHT = 800;
|
||||||
int fullscreen = 0;
|
int fullscreen = 0;
|
||||||
|
|
||||||
|
Oscilloscope audioScope(512,200,true);
|
||||||
|
|
||||||
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
|
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
|
||||||
Head myHead; // The rendered head of oneself or others
|
Head myHead; // The rendered head of oneself
|
||||||
Head dummyHead; // Test Head to render
|
|
||||||
int showDummyHead = 0;
|
|
||||||
|
|
||||||
Hand myHand(HAND_RADIUS,
|
Hand myHand(HAND_RADIUS,
|
||||||
glm::vec3(0,1,1)); // My hand (used to manipulate things in world)
|
glm::vec3(0,1,1)); // My hand (used to manipulate things in world)
|
||||||
|
@ -224,9 +225,11 @@ void Timer(int extra)
|
||||||
glutTimerFunc(1000,Timer,0);
|
glutTimerFunc(1000,Timer,0);
|
||||||
gettimeofday(&timer_start, NULL);
|
gettimeofday(&timer_start, NULL);
|
||||||
|
|
||||||
|
//
|
||||||
// Send a message to the domainserver telling it we are ALIVE
|
// Send a message to the domainserver telling it we are ALIVE
|
||||||
|
//
|
||||||
char output[100];
|
char output[100];
|
||||||
sprintf(output, "%f,%f,%f", location[0], location[1], location[2]);
|
sprintf(output, "%c %f,%f,%f", 'I', location[0], location[1], location[2]);
|
||||||
int packet_size = strlen(output);
|
int packet_size = strlen(output);
|
||||||
agentSocket.send(DOMAINSERVER_IP, DOMAINSERVER_PORT, output, packet_size);
|
agentSocket.send(DOMAINSERVER_IP, DOMAINSERVER_PORT, output, packet_size);
|
||||||
|
|
||||||
|
@ -239,9 +242,9 @@ void Timer(int extra)
|
||||||
gettimeofday(&starttest, NULL);
|
gettimeofday(&starttest, NULL);
|
||||||
char junk[1000];
|
char junk[1000];
|
||||||
junk[0] = 'J';
|
junk[0] = 'J';
|
||||||
for (int i = 0; i < 3000; i++)
|
for (int i = 0; i < 10000; i++)
|
||||||
{
|
{
|
||||||
agentSocket.send("192.168.1.38", AGENT_UDP_PORT, junk, 1000);
|
agentSocket.send((char *)"192.168.1.38", AGENT_UDP_PORT, junk, 1000);
|
||||||
}
|
}
|
||||||
gettimeofday(&endtest, NULL);
|
gettimeofday(&endtest, NULL);
|
||||||
float sendTime = diffclock(&starttest, &endtest);
|
float sendTime = diffclock(&starttest, &endtest);
|
||||||
|
@ -299,18 +302,11 @@ void init(void)
|
||||||
{
|
{
|
||||||
myHead.setRenderYaw(start_yaw);
|
myHead.setRenderYaw(start_yaw);
|
||||||
|
|
||||||
dummyHead.setPitch(0);
|
|
||||||
dummyHead.setRoll(0);
|
|
||||||
dummyHead.setYaw(0);
|
|
||||||
dummyHead.setScale(0.25);
|
|
||||||
|
|
||||||
dummyHead.setPos(glm::vec3(0,0,0));
|
|
||||||
|
|
||||||
if (audio_on) {
|
if (audio_on) {
|
||||||
if (serial_on) {
|
if (serial_on) {
|
||||||
Audio::init(&myHead);
|
Audio::init(&myHead, &audioScope);
|
||||||
} else {
|
} else {
|
||||||
Audio::init();
|
Audio::init(&audioScope);
|
||||||
}
|
}
|
||||||
printf( "Audio started.\n" );
|
printf( "Audio started.\n" );
|
||||||
}
|
}
|
||||||
|
@ -328,7 +324,6 @@ void init(void)
|
||||||
{
|
{
|
||||||
myHand.setNoise(noise);
|
myHand.setNoise(noise);
|
||||||
myHead.setNoise(noise);
|
myHead.setNoise(noise);
|
||||||
dummyHead.setNoise(noise);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serial_on)
|
if (serial_on)
|
||||||
|
@ -385,8 +380,6 @@ void reset_sensors()
|
||||||
// Reset serial I/O sensors
|
// Reset serial I/O sensors
|
||||||
//
|
//
|
||||||
myHead.setRenderYaw(start_yaw);
|
myHead.setRenderYaw(start_yaw);
|
||||||
dummyHead.setRenderPitch(0);
|
|
||||||
dummyHead.setRenderYaw(0);
|
|
||||||
|
|
||||||
yaw = render_yaw_rate = 0;
|
yaw = render_yaw_rate = 0;
|
||||||
pitch = render_pitch = render_pitch_rate = 0;
|
pitch = render_pitch = render_pitch_rate = 0;
|
||||||
|
@ -535,16 +528,10 @@ void update_pos(float frametime)
|
||||||
myHead.setAverageLoudness(averageLoudness);
|
myHead.setAverageLoudness(averageLoudness);
|
||||||
|
|
||||||
// Send my streaming head data to agents that are nearby and need to see it!
|
// Send my streaming head data to agents that are nearby and need to see it!
|
||||||
|
|
||||||
const int MAX_BROADCAST_STRING = 200;
|
const int MAX_BROADCAST_STRING = 200;
|
||||||
char broadcast_string[MAX_BROADCAST_STRING];
|
char broadcast_string[MAX_BROADCAST_STRING];
|
||||||
int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
|
int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
|
||||||
broadcastToAgents(&agentSocket, broadcast_string, broadcast_bytes);
|
broadcastToAgents(&agentSocket, broadcast_string, broadcast_bytes, sendToSelf);
|
||||||
|
|
||||||
//printf("-> %s\n", broadcast_string);
|
|
||||||
//dummyHead.recvBroadcastData(broadcast_string, broadcast_bytes);
|
|
||||||
//printf("head bytes: %d\n", broadcast_bytes);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_test_spot = WIDTH/2;
|
int render_test_spot = WIDTH/2;
|
||||||
|
@ -559,6 +546,8 @@ void display(void)
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// Setup 3D lights
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
|
|
||||||
|
@ -589,21 +578,9 @@ void display(void)
|
||||||
|
|
||||||
// Draw field vectors
|
// Draw field vectors
|
||||||
if (display_field) field.render();
|
if (display_field) field.render();
|
||||||
|
|
||||||
// Render my own head
|
|
||||||
if (display_head) {
|
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
glTranslatef(0.f, 0.f, -7.f);
|
|
||||||
myHead.render(1);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render dummy head
|
|
||||||
if (showDummyHead) dummyHead.render(0);
|
|
||||||
|
|
||||||
// Render heads of other agents
|
// Render heads of other agents
|
||||||
if (!display_head) render_agents();
|
render_agents(sendToSelf);
|
||||||
|
|
||||||
if (display_hand) myHand.render();
|
if (display_hand) myHand.render();
|
||||||
|
|
||||||
|
@ -612,11 +589,22 @@ void display(void)
|
||||||
// Render the world box
|
// Render the world box
|
||||||
if (!display_head && stats_on) render_world_box();
|
if (!display_head && stats_on) render_world_box();
|
||||||
|
|
||||||
|
// Render my own head
|
||||||
|
|
||||||
|
if (display_head) {
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.f, 0.f, -7.f);
|
||||||
|
myHead.render(1);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
// render audio sources and start them
|
// render audio sources and start them
|
||||||
if (audio_on) {
|
if (audio_on) {
|
||||||
Audio::render();
|
Audio::render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//glm::vec3 test(0.5, 0.5, 0.5);
|
//glm::vec3 test(0.5, 0.5, 0.5);
|
||||||
//render_vector(&test);
|
//render_vector(&test);
|
||||||
|
|
||||||
|
@ -633,6 +621,8 @@ void display(void)
|
||||||
// lattice.render(WIDTH, HEIGHT);
|
// lattice.render(WIDTH, HEIGHT);
|
||||||
// myFinger.render();
|
// myFinger.render();
|
||||||
Audio::render(WIDTH, HEIGHT);
|
Audio::render(WIDTH, HEIGHT);
|
||||||
|
if (audioScope.getState()) audioScope.render();
|
||||||
|
|
||||||
|
|
||||||
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
|
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);
|
||||||
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic );
|
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic );
|
||||||
|
@ -801,7 +791,7 @@ void read_network()
|
||||||
//
|
//
|
||||||
// Got Ping, reply immediately!
|
// Got Ping, reply immediately!
|
||||||
//
|
//
|
||||||
printf("Replying to ping!\n");
|
//printf("Replying to ping!\n");
|
||||||
char reply[] = "R";
|
char reply[] = "R";
|
||||||
agentSocket.send(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), reply, 1);
|
agentSocket.send(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), reply, 1);
|
||||||
} else if (incoming_packet[0] == 'R') {
|
} else if (incoming_packet[0] == 'R') {
|
||||||
|
@ -829,7 +819,10 @@ void read_network()
|
||||||
//
|
//
|
||||||
update_agent(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), &incoming_packet[1], bytes_recvd - 1);
|
update_agent(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), &incoming_packet[1], bytes_recvd - 1);
|
||||||
} else if (incoming_packet[0] == 'T') {
|
} else if (incoming_packet[0] == 'T') {
|
||||||
printf("Got test! From port %d\n", senderAddress.sin_port);
|
// Received a self-test packet (to get one's own IP), copy it to local variable!
|
||||||
|
printf("My Address: %s:%u\n",
|
||||||
|
inet_ntoa(senderAddress.sin_addr),
|
||||||
|
senderAddress.sin_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -948,7 +941,10 @@ int main(int argc, char** argv)
|
||||||
// Create network socket and buffer
|
// Create network socket and buffer
|
||||||
incoming_packet = new char[MAX_PACKET_SIZE];
|
incoming_packet = new char[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
//
|
// Send one test packet to detect own IP, port:
|
||||||
|
char selfTest[] = "T";
|
||||||
|
agentSocket.send((char *)"127.0.0.1", AGENT_UDP_PORT, selfTest, 1);
|
||||||
|
|
||||||
printf("Testing stats math... ");
|
printf("Testing stats math... ");
|
||||||
StDev stdevtest;
|
StDev stdevtest;
|
||||||
stdevtest.reset();
|
stdevtest.reset();
|
||||||
|
|
|
@ -27,24 +27,3 @@ void getVoxel(float * pos, int scale, float * vpos) {
|
||||||
vpos[Z] = floor(pos[Z]*vscale)/vscale;
|
vpos[Z] = floor(pos[Z]*vscale)/vscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Given a pointer to an octal code and some domain owner data, iterate the tree and add the node(s) as needed.
|
|
||||||
//
|
|
||||||
domainNode* createNode(int lengthInBits, char * octalData,
|
|
||||||
char * hostname, char * nickname, int domain_id) {
|
|
||||||
domainNode * currentNode = &rootNode;
|
|
||||||
for (int i = 0; i < lengthInBits; i+=3) {
|
|
||||||
char octet = 0;
|
|
||||||
if (i%8 < 6) octet = octalData[i/8] << (i%8);
|
|
||||||
else {
|
|
||||||
octet = octalData[i/8] << (i%8) && ((octalData[i/8 + 1] >> (i%8)) << (8 - i%8));
|
|
||||||
}
|
|
||||||
if (currentNode->child[octet] == NULL) currentNode->child[octet] = new domainNode;
|
|
||||||
currentNode = currentNode->child[octet];
|
|
||||||
}
|
|
||||||
// Copy in the new node info...
|
|
||||||
strcpy(currentNode->hostname, hostname);
|
|
||||||
strcpy(currentNode->nickname, nickname);
|
|
||||||
currentNode->domain_id = domain_id;
|
|
||||||
return currentNode;
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#ifndef __interface__world__
|
#ifndef __interface__world__
|
||||||
#define __interface__world__
|
#define __interface__world__
|
||||||
|
|
||||||
|
|
||||||
const float WORLD_SIZE = 10.0;
|
const float WORLD_SIZE = 10.0;
|
||||||
#define PI 3.14159265
|
#define PI 3.14159265
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue