Merge pull request #193 from birarda/avatar-file

store avatar position and yaw in a local file
This commit is contained in:
Philip Rosedale 2013-05-03 15:13:45 -07:00
commit a31098ac3c
5 changed files with 44 additions and 73 deletions

View file

@ -80,10 +80,6 @@ timeval firstPlaybackTimer;
int packetsReceivedThisPlayback = 0;
float usecsAtStartup = 0;
#define LOG_SAMPLE_DELAY 0
std::ofstream logFile;
/**
* Audio callback used by portaudio.
* Communicates with Audio via a shared pointer to Audio::data.
@ -315,34 +311,12 @@ void *receiveAudioViaUDP(void *args) {
stdev.reset();
if (LOG_SAMPLE_DELAY) {
char *directory = new char[50];
char *filename = new char[50];
sprintf(directory, "%s/Desktop/echo_tests", getenv("HOME"));
mkdir(directory, S_IRWXU | S_IRWXG | S_IRWXO);
sprintf(filename, "%s/%ld.csv", directory, previousReceiveTime.tv_sec);
logFile.open(filename, std::ios::out);
delete[] directory;
delete[] filename;
}
while (!stopAudioReceiveThread) {
if (sharedAudioData->audioSocket->receive((void *)receivedData, &receivedBytes)) {
gettimeofday(&currentReceiveTime, NULL);
totalPacketsReceived++;
if (LOG_SAMPLE_DELAY) {
// write time difference (in microseconds) between packet receipts to file
double timeDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
logFile << timeDiff << std::endl;
}
double tDiff = diffclock(&previousReceiveTime, &currentReceiveTime);
//printLog("tDiff %4.1f\n", tDiff);
@ -562,8 +536,7 @@ void Audio::render(int screenWidth, int screenHeight)
* @return Returns true if the initialization was successful, or false if an error occured.
The error code may be retrieved by Audio::getError().
*/
bool Audio::terminate ()
{
bool Audio::terminate() {
stopAudioReceiveThread = true;
pthread_join(audioReceiveThread, NULL);
@ -577,7 +550,6 @@ bool Audio::terminate ()
if (paError != paNoError) goto error;
}
logFile.close();
delete audioData;
return true;

View file

@ -1539,3 +1539,23 @@ glm::vec3 Avatar::getGravity(glm::vec3 pos) {
return glm::vec3(0.f, 0.f, 0.f);
}
}
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";
void Avatar::writeAvatarDataToFile() {
// write the avatar position and yaw to a local file
FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "w");
if (avatarFile) {
fprintf(avatarFile, "%f,%f,%f %f", _position.x, _position.y, _position.z, _bodyYaw);
fclose(avatarFile);
}
}
void Avatar::readAvatarDataFromFile() {
FILE* avatarFile = fopen(AVATAR_DATA_FILENAME, "r");
if (avatarFile) {
fscanf(avatarFile, "%f,%f,%f %f", &_position.x, &_position.y, &_position.z, &_bodyYaw);
}
}

View file

@ -145,6 +145,9 @@ public:
// Find out what the local gravity vector is at this location
glm::vec3 getGravity(glm::vec3 pos);
void writeAvatarDataToFile();
void readAvatarDataFromFile();
private:

View file

@ -24,7 +24,6 @@ using namespace std;
// no clue which versions are affected...
#define WORKAROUND_BROKEN_GLUT_STROKES
// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html
static float MONO_STROKE_WIDTH_GLUT = 104.76;
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * right, glm::vec3 * up) {
//
@ -172,7 +171,6 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
//
// Draws text on screen as stroked so it can be resized
//
int len, i;
glPushMatrix();
glTranslatef( static_cast<float>(x), static_cast<float>(y), 0.0f);
glColor3f(r,g,b);

View file

@ -344,7 +344,9 @@ void init(void)
void terminate () {
// Close serial port
//close(serial_fd);
// close(serial_fd);
myAvatar.writeAvatarDataToFile();
#ifndef _WIN32
audio.terminate();
@ -1290,7 +1292,6 @@ int doRandomizeVoxelColors(int state) {
return state;
}
int doFalseRandomizeVoxelColors(int state) {
if (state == MENU_ROW_PICKED) {
::voxels.falseColorizeRandom();
@ -1322,7 +1323,6 @@ int doFalseColorizeInView(int state) {
return state;
}
const char* modeAll = " - All ";
const char* modeVectors = " - Vectors ";
const char* modePlanes = " - Planes ";
@ -1396,8 +1396,7 @@ void testPointToVoxel()
float y=0;
float z=0;
float s=0.1;
for (float x=0; x<=1; x+= 0.05)
{
for (float x=0; x<=1; x+= 0.05) {
printLog(" x=%f");
unsigned char red = 200; //randomColorValue(65);
@ -1486,11 +1485,9 @@ void specialkeyUp(int k, int x, int y) {
myAvatar.setDriveKeys(RIGHT, 0);
myAvatar.setDriveKeys(ROT_RIGHT, 0);
}
}
void specialkey(int k, int x, int y)
{
void specialkey(int k, int x, int y) {
if (::chatEntryOn) {
chatEntry.specialKey(k);
return;
@ -1532,7 +1529,6 @@ void keyUp(unsigned char k, int x, int y) {
if (k == 's') myAvatar.setDriveKeys(BACK, 0);
if (k == 'a') myAvatar.setDriveKeys(ROT_LEFT, 0);
if (k == 'd') myAvatar.setDriveKeys(ROT_RIGHT, 0);
}
void key(unsigned char k, int x, int y)
@ -1624,8 +1620,7 @@ void key(unsigned char k, int x, int y)
}
// Receive packets from other agents/servers and decide what to do with them!
void* networkReceive(void* args)
{
void* networkReceive(void* args) {
sockaddr senderAddress;
ssize_t bytesReceived;
@ -1697,9 +1692,7 @@ void idle(void) {
handControl.stop();
}
//
// Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents
//
updateAvatar(deltaTime);
// read incoming packets from network
@ -1730,9 +1723,7 @@ void idle(void) {
}
}
void reshape(int width, int height)
{
void reshape(int width, int height) {
WIDTH = width;
HEIGHT = height;
aspectRatio = ((float)width/(float)height); // based on screen resize
@ -1758,17 +1749,12 @@ void reshape(int width, int height)
camera.setFieldOfView(fov = 60);
}
//printLog("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n",
// width,height,aspectRatio,fov,nearClip,farClip);
// Tell our viewFrustum about this change
::viewFrustum.setAspectRatio(aspectRatio);
glViewport(0, 0, width, height); // shouldn't this account for the menu???
glMatrixMode(GL_PROJECTION); //hello
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that
@ -1785,42 +1771,32 @@ void reshape(int width, int height)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouseFunc( int button, int state, int x, int y )
{
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
{
if (!menu.mouseClick(x, y)) {
void mouseFunc(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
if (state == GLUT_DOWN && !menu.mouseClick(x, y)) {
mouseX = x;
mouseY = y;
mousePressed = 1;
} else if (state == GLUT_UP) {
mouseX = x;
mouseY = y;
mousePressed = 0;
}
}
if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
mouseX = x;
mouseY = y;
mousePressed = 0;
}
}
}
void motionFunc( int x, int y)
{
void motionFunc(int x, int y) {
mouseX = x;
mouseY = y;
}
void mouseoverFunc( int x, int y)
{
void mouseoverFunc(int x, int y){
menu.mouseOver(x, y);
mouseX = x;
mouseY = y;
if (mousePressed == 0)
{}
}
void attachNewHeadToAgent(Agent *newAgent) {
@ -1944,6 +1920,8 @@ int main(int argc, const char * argv[])
printLog("Network receive thread created.\n");
}
myAvatar.readAvatarDataFromFile();
glutTimerFunc(1000, Timer, 0);
glutMainLoop();