mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 06:53:01 +02:00
pushing new agents into list and changes to private properties
This commit is contained in:
parent
cb5d1b9214
commit
f3a8e363dc
2 changed files with 144 additions and 40 deletions
|
@ -31,8 +31,6 @@
|
||||||
#include <UDPSocket.h>
|
#include <UDPSocket.h>
|
||||||
#include "avatar.h"
|
#include "avatar.h"
|
||||||
|
|
||||||
const int LISTEN_PORT = 55444;
|
|
||||||
|
|
||||||
std::vector<AvatarAgent> *avatarAgentList = new std::vector<AvatarAgent>;
|
std::vector<AvatarAgent> *avatarAgentList = new std::vector<AvatarAgent>;
|
||||||
|
|
||||||
AvatarAgent *findAvatarAgentBySocket(sockaddr *activeSocket) {
|
AvatarAgent *findAvatarAgentBySocket(sockaddr *activeSocket) {
|
||||||
|
@ -52,14 +50,34 @@ AvatarAgent *findAvatarAgentBySocket(sockaddr *activeSocket) {
|
||||||
if (firstSocket->sin_addr.s_addr == secondSocket->sin_addr.s_addr &&
|
if (firstSocket->sin_addr.s_addr == secondSocket->sin_addr.s_addr &&
|
||||||
firstSocket->sin_port == secondSocket->sin_port) {
|
firstSocket->sin_port == secondSocket->sin_port) {
|
||||||
return &*avatarAgent;
|
return &*avatarAgent;
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor and Destructor
|
// Constructor and Destructor
|
||||||
AvatarAgent::AvatarAgent() {
|
AvatarAgent::AvatarAgent(sockaddr activeSocket,
|
||||||
|
float pitch,
|
||||||
|
float yaw,
|
||||||
|
float roll,
|
||||||
|
float headPositionX,
|
||||||
|
float headPositionY,
|
||||||
|
float headPositionZ,
|
||||||
|
float loudness,
|
||||||
|
float averageLoudness,
|
||||||
|
float handPositionX,
|
||||||
|
float handPositionY,
|
||||||
|
float handPositionZ) {
|
||||||
|
|
||||||
|
this->setActiveSocket(activeSocket);
|
||||||
|
this->setPitch(pitch);
|
||||||
|
this->setYaw(yaw);
|
||||||
|
this->setRoll(roll);
|
||||||
|
this->setHeadPosition(headPositionX, headPositionY, headPositionZ);
|
||||||
|
this->setLoudness(loudness);
|
||||||
|
this->setAverageLoudness(averageLoudness);
|
||||||
|
this->setHandPosition(handPositionX, handPositionY, handPositionZ);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +102,16 @@ float AvatarAgent::getRoll() {
|
||||||
return _roll;
|
return _roll;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<char, float> AvatarAgent::getHeadPosition() {
|
float AvatarAgent::getHeadPositionX() {
|
||||||
return _headPosition;
|
return _headPositionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AvatarAgent::getHeadPositionY() {
|
||||||
|
return _headPositionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AvatarAgent::getHeadPositionZ() {
|
||||||
|
return _headPositionZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
float AvatarAgent::getLoudness() {
|
float AvatarAgent::getLoudness() {
|
||||||
|
@ -96,8 +122,16 @@ float AvatarAgent::getAverageLoudness() {
|
||||||
return _averageLoudness;
|
return _averageLoudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<char, float> AvatarAgent::getHandPosition() {
|
float AvatarAgent::getHandPositionX() {
|
||||||
return _handPosition;
|
return _handPositionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AvatarAgent::getHandPositionY() {
|
||||||
|
return _handPositionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
float AvatarAgent::getHandPositionZ() {
|
||||||
|
return _handPositionZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Property setters
|
// Property setters
|
||||||
|
@ -114,9 +148,9 @@ void AvatarAgent::setRoll(float roll) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarAgent::setHeadPosition(float x, float y, float z) {
|
void AvatarAgent::setHeadPosition(float x, float y, float z) {
|
||||||
_headPosition['x'] = x;
|
_headPositionX = x;
|
||||||
_headPosition['y'] = y;
|
_headPositionY = y;
|
||||||
_headPosition['z'] = z;
|
_headPositionZ = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarAgent::setLoudness(float loudness) {
|
void AvatarAgent::setLoudness(float loudness) {
|
||||||
|
@ -128,30 +162,28 @@ void AvatarAgent::setAverageLoudness(float averageLoudness) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarAgent::setHandPosition(float x, float y, float z) {
|
void AvatarAgent::setHandPosition(float x, float y, float z) {
|
||||||
_handPosition['x'] = x;
|
_handPositionX = x;
|
||||||
_handPosition['y'] = y;
|
_handPositionY = y;
|
||||||
_handPosition['z'] = z;
|
_handPositionZ = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
|
unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, AvatarAgent *agentToAdd) {
|
||||||
unsigned char *packetData = new unsigned char();
|
unsigned char *packetData = new unsigned char();
|
||||||
AvatarAgent *thisAgent = new AvatarAgent();
|
|
||||||
|
|
||||||
*currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId());
|
|
||||||
currentPosition += packSocket(currentPosition, agentToAdd->getActiveSocket());
|
currentPosition += packSocket(currentPosition, agentToAdd->getActiveSocket());
|
||||||
|
|
||||||
sprintf((char *)packetData, packetFormat, thisAgent->getPitch(),
|
sprintf((char *)packetData, packetFormat, agentToAdd->getPitch(),
|
||||||
thisAgent->getYaw(),
|
agentToAdd->getYaw(),
|
||||||
thisAgent->getRoll(),
|
agentToAdd->getRoll(),
|
||||||
thisAgent->getHeadPosition()[0],
|
agentToAdd->getHeadPosition()['x'],
|
||||||
thisAgent->getHeadPosition()[1],
|
agentToAdd->getHeadPosition()['y'],
|
||||||
thisAgent->getHeadPosition()[2],
|
agentToAdd->getHeadPosition()['z'],
|
||||||
thisAgent->getLoudness(),
|
agentToAdd->getLoudness(),
|
||||||
thisAgent->getAverageLoudness(),
|
agentToAdd->getAverageLoudness(),
|
||||||
thisAgent->getHandPosition()[0],
|
agentToAdd->getHandPosition()['x'],
|
||||||
thisAgent->getHandPosition()[1],
|
agentToAdd->getHandPosition()['y'],
|
||||||
thisAgent->getHandPosition()[2]);
|
agentToAdd->getHandPosition()['z']);
|
||||||
|
|
||||||
memcpy(currentPosition, packetData, strlen((const char*)packetData));
|
memcpy(currentPosition, packetData, strlen((const char*)packetData));
|
||||||
currentPosition += strlen((const char*)packetData);
|
currentPosition += strlen((const char*)packetData);
|
||||||
|
@ -159,8 +191,7 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *
|
||||||
return currentPosition;
|
return currentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *sendAvatarData(void *args)
|
void *sendAvatarData(void *args) {
|
||||||
{
|
|
||||||
timeval startTime;
|
timeval startTime;
|
||||||
while (true) {
|
while (true) {
|
||||||
gettimeofday(&startTime, NULL);
|
gettimeofday(&startTime, NULL);
|
||||||
|
@ -188,10 +219,64 @@ int main(int argc, char* argv[])
|
||||||
pthread_create(&sendAvatarDataThread, NULL, sendAvatarData, NULL);
|
pthread_create(&sendAvatarDataThread, NULL, sendAvatarData, NULL);
|
||||||
|
|
||||||
sockaddr *agentAddress = new sockaddr;
|
sockaddr *agentAddress = new sockaddr;
|
||||||
unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
|
char *packetData = new char[MAX_PACKET_SIZE];
|
||||||
ssize_t receivedBytes = 0;
|
ssize_t receivedBytes = 0;
|
||||||
|
|
||||||
|
UDPSocket *avatarMixerSocket = new UDPSocket(AVATAR_LISTEN_PORT);
|
||||||
|
AvatarAgent *matchingAgent = NULL;
|
||||||
|
|
||||||
|
float *pitch;
|
||||||
|
float *yaw;
|
||||||
|
float *roll;
|
||||||
|
float *headPositionX;
|
||||||
|
float *headPositionY;
|
||||||
|
float *headPositionZ;
|
||||||
|
float *loudness;
|
||||||
|
float *averageLoudness;
|
||||||
|
float *handPositionX;
|
||||||
|
float *handPositionY;
|
||||||
|
float *handPositionZ;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (avatarMixerSocket->receive(agentAddress, packetData, &receivedBytes)) {
|
||||||
|
if (packetData[0] == PACKET_HEADER_HEAD_DATA) {
|
||||||
|
// Extract data from packet
|
||||||
|
sscanf(packetData + 1,
|
||||||
|
PACKET_FORMAT,
|
||||||
|
&pitch,
|
||||||
|
&yaw,
|
||||||
|
&roll,
|
||||||
|
&headPositionX,
|
||||||
|
&headPositionY,
|
||||||
|
&headPositionZ,
|
||||||
|
&loudness,
|
||||||
|
&averageLoudness,
|
||||||
|
&handPositionX,
|
||||||
|
&handPositionY,
|
||||||
|
&handPositionZ);
|
||||||
|
|
||||||
|
matchingAgent = findAvatarAgentBySocket(agentAddress);
|
||||||
|
|
||||||
|
if (matchingAgent) {
|
||||||
|
// We already have this agent on our list, just modify positional data
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// This is a new agent, we need to add to the list
|
||||||
|
AvatarAgent thisAgentHolder = *new AvatarAgent(*agentAddress,
|
||||||
|
*pitch,
|
||||||
|
*yaw,
|
||||||
|
*roll,
|
||||||
|
*headPositionX,
|
||||||
|
*headPositionY,
|
||||||
|
*headPositionZ,
|
||||||
|
*loudness,
|
||||||
|
*averageLoudness,
|
||||||
|
*handPositionX,
|
||||||
|
*handPositionY,
|
||||||
|
*handPositionZ);
|
||||||
|
avatarAgentList->push_back(thisAgentHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
const unsigned short AVATAR_LISTEN_PORT = 55444;
|
const int AVATAR_LISTEN_PORT = 55444;
|
||||||
const unsigned short BROADCAST_INTERVAL = 20;
|
const unsigned short BROADCAST_INTERVAL = 20;
|
||||||
const char *packetFormat = "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f";
|
const char *PACKET_FORMAT = "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f";
|
||||||
|
|
||||||
class AvatarAgent {
|
class AvatarAgent {
|
||||||
private:
|
private:
|
||||||
|
@ -36,12 +36,27 @@ private:
|
||||||
float _pitch;
|
float _pitch;
|
||||||
float _yaw;
|
float _yaw;
|
||||||
float _roll;
|
float _roll;
|
||||||
std::map<char, float> _headPosition;
|
float _headPositionX;
|
||||||
|
float _headPositionY;
|
||||||
|
float _headPositionZ;
|
||||||
float _loudness;
|
float _loudness;
|
||||||
float _averageLoudness;
|
float _averageLoudness;
|
||||||
std::map<char, float> _handPosition;
|
float _handPositionX;
|
||||||
|
float _handPositionY;
|
||||||
|
float _handPositionZ;
|
||||||
public:
|
public:
|
||||||
AvatarAgent();
|
AvatarAgent(sockaddr activeSocket,
|
||||||
|
float pitch,
|
||||||
|
float yaw,
|
||||||
|
float roll,
|
||||||
|
float headPositionX,
|
||||||
|
float headPositionY,
|
||||||
|
float headPositionZ,
|
||||||
|
float loudness,
|
||||||
|
float averageLoudness,
|
||||||
|
float handPositionX,
|
||||||
|
float handPositionY,
|
||||||
|
float handPositionZ);
|
||||||
~AvatarAgent();
|
~AvatarAgent();
|
||||||
sockaddr *getActiveSocket();
|
sockaddr *getActiveSocket();
|
||||||
void setActiveSocket(sockaddr activeSocket);
|
void setActiveSocket(sockaddr activeSocket);
|
||||||
|
@ -51,12 +66,16 @@ public:
|
||||||
void setYaw(float yaw);
|
void setYaw(float yaw);
|
||||||
float getRoll();
|
float getRoll();
|
||||||
void setRoll(float roll);
|
void setRoll(float roll);
|
||||||
std::map<char, float> getHeadPosition();
|
float getHeadPositionX();
|
||||||
|
float getHeadPositionY();
|
||||||
|
float getHeadPositionZ();
|
||||||
void setHeadPosition(float x, float y, float z);
|
void setHeadPosition(float x, float y, float z);
|
||||||
float getLoudness();
|
float getLoudness();
|
||||||
void setLoudness(float loudness);
|
void setLoudness(float loudness);
|
||||||
float getAverageLoudness();
|
float getAverageLoudness();
|
||||||
void setAverageLoudness(float averageLoudness);
|
void setAverageLoudness(float averageLoudness);
|
||||||
std::map<char, float> getHandPosition();
|
float getHandPositionX();
|
||||||
|
float getHandPositionY();
|
||||||
|
float getHandPositionZ();
|
||||||
void setHandPosition(float x, float y, float z);
|
void setHandPosition(float x, float y, float z);
|
||||||
};
|
};
|
Loading…
Reference in a new issue