mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:30:42 +02:00
Merge branch 'master' of https://github.com/worklist/hifi into view_frustum_work
Conflicts: interface/src/main.cpp
This commit is contained in:
commit
74c5916519
52 changed files with 941 additions and 241 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
Oscilloscope * scope;
|
Oscilloscope * scope;
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ int audioCallback (const void *inputBuffer,
|
||||||
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
|
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
|
||||||
// int16_t *inputRight = ((int16_t **) inputBuffer)[1];
|
// int16_t *inputRight = ((int16_t **) inputBuffer)[1];
|
||||||
|
|
||||||
//printf("Audio callback at %6.0f\n", usecTimestampNow()/1000);
|
//printLog("Audio callback at %6.0f\n", usecTimestampNow()/1000);
|
||||||
|
|
||||||
if (inputLeft != NULL) {
|
if (inputLeft != NULL) {
|
||||||
|
|
||||||
|
@ -231,21 +232,21 @@ int audioCallback (const void *inputBuffer,
|
||||||
if (ringBuffer->getEndOfLastWrite() != NULL) {
|
if (ringBuffer->getEndOfLastWrite() != NULL) {
|
||||||
|
|
||||||
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) {
|
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) {
|
||||||
//printf("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES);
|
//printLog("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES);
|
||||||
} else if (ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES) {
|
} else if (ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES) {
|
||||||
ringBuffer->setStarted(false);
|
ringBuffer->setStarted(false);
|
||||||
|
|
||||||
starve_counter++;
|
starve_counter++;
|
||||||
packetsReceivedThisPlayback = 0;
|
packetsReceivedThisPlayback = 0;
|
||||||
|
|
||||||
//printf("Starved #%d\n", starve_counter);
|
//printLog("Starved #%d\n", starve_counter);
|
||||||
data->wasStarved = 10; // Frames to render the indication that the system was starved.
|
data->wasStarved = 10; // Frames to render the indication that the system was starved.
|
||||||
} else {
|
} else {
|
||||||
if (!ringBuffer->isStarted()) {
|
if (!ringBuffer->isStarted()) {
|
||||||
ringBuffer->setStarted(true);
|
ringBuffer->setStarted(true);
|
||||||
//printf("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0);
|
//printLog("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0);
|
||||||
} else {
|
} else {
|
||||||
//printf("pushing buffer\n");
|
//printLog("pushing buffer\n");
|
||||||
}
|
}
|
||||||
// play whatever we have in the audio buffer
|
// play whatever we have in the audio buffer
|
||||||
|
|
||||||
|
@ -391,12 +392,12 @@ void *receiveAudioViaUDP(void *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double tDiff = diffclock(&previousReceiveTime, ¤tReceiveTime);
|
double tDiff = diffclock(&previousReceiveTime, ¤tReceiveTime);
|
||||||
//printf("tDiff %4.1f\n", tDiff);
|
//printLog("tDiff %4.1f\n", tDiff);
|
||||||
// Discard first few received packets for computing jitter (often they pile up on start)
|
// Discard first few received packets for computing jitter (often they pile up on start)
|
||||||
if (totalPacketsReceived > 3) stdev.addValue(tDiff);
|
if (totalPacketsReceived > 3) stdev.addValue(tDiff);
|
||||||
if (stdev.getSamples() > 500) {
|
if (stdev.getSamples() > 500) {
|
||||||
sharedAudioData->measuredJitter = stdev.getStDev();
|
sharedAudioData->measuredJitter = stdev.getStDev();
|
||||||
//printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter);
|
//printLog("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter);
|
||||||
stdev.reset();
|
stdev.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +408,7 @@ void *receiveAudioViaUDP(void *args) {
|
||||||
packetsReceivedThisPlayback++;
|
packetsReceivedThisPlayback++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//printf("Audio packet received at %6.0f\n", usecTimestampNow()/1000);
|
//printLog("Audio packet received at %6.0f\n", usecTimestampNow()/1000);
|
||||||
}
|
}
|
||||||
if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL);
|
if (packetsReceivedThisPlayback == 1) gettimeofday(&firstPlaybackTimer, NULL);
|
||||||
|
|
||||||
|
@ -494,8 +495,8 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
fprintf(stderr, "-- Failed to initialize portaudio --\n");
|
printLog("-- Failed to initialize portaudio --\n");
|
||||||
fprintf(stderr, "PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
|
printLog("PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
|
||||||
initialized = false;
|
initialized = false;
|
||||||
delete[] audioData;
|
delete[] audioData;
|
||||||
}
|
}
|
||||||
|
@ -629,8 +630,8 @@ bool Audio::terminate ()
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
fprintf(stderr, "-- portaudio termination error --\n");
|
printLog("-- portaudio termination error --\n");
|
||||||
fprintf(stderr, "PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
|
printLog("PortAudio error (%d): %s\n", paError, Pa_GetErrorText(paError));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __interface__Audio__
|
#ifndef __interface__Audio__
|
||||||
#define __interface__Audio__
|
#define __interface__Audio__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
#include "AudioData.h"
|
#include "AudioData.h"
|
||||||
#include "Oscilloscope.h"
|
#include "Oscilloscope.h"
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#ifndef __interface__AudioData__
|
#ifndef __interface__AudioData__
|
||||||
#define __interface__AudioData__
|
#define __interface__AudioData__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include "AudioRingBuffer.h"
|
#include "AudioRingBuffer.h"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
// #include "Log.h"
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
|
||||||
|
@ -67,6 +68,6 @@ void Camera::update( float deltaTime )
|
||||||
_orientation.pitch ( _pitch );
|
_orientation.pitch ( _pitch );
|
||||||
_orientation.roll ( _roll );
|
_orientation.roll ( _roll );
|
||||||
|
|
||||||
//printf( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z );
|
//printLog( "orientation.front = %f, %f, %f\n", _orientation.front.x, _orientation.front.y, _orientation.front.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#ifndef __interface__Field__
|
#ifndef __interface__Field__
|
||||||
#define __interface__Field__
|
#define __interface__Field__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
|
@ -7,14 +7,12 @@
|
||||||
// Copyright (c) 2012 Physical, Inc.. All rights reserved.
|
// Copyright (c) 2012 Physical, Inc.. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <lodepng.h>
|
#include <lodepng.h>
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include "Head.h"
|
#include "Head.h"
|
||||||
|
#include "Log.h"
|
||||||
#include <AgentList.h>
|
#include <AgentList.h>
|
||||||
#include <AgentTypes.h>
|
#include <AgentTypes.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
|
@ -38,7 +36,7 @@ float MouthWidthChoices[3] = {0.5, 0.77, 0.3};
|
||||||
float browWidth = 0.8;
|
float browWidth = 0.8;
|
||||||
float browThickness = 0.16;
|
float browThickness = 0.16;
|
||||||
|
|
||||||
bool usingBigSphereCollisionTest = false;
|
bool usingBigSphereCollisionTest = true;
|
||||||
|
|
||||||
const float DECAY = 0.1;
|
const float DECAY = 0.1;
|
||||||
const float THRUST_MAG = 10.0;
|
const float THRUST_MAG = 10.0;
|
||||||
|
@ -117,7 +115,7 @@ Head::Head(bool isMine) {
|
||||||
switchToResourcesParentIfRequired();
|
switchToResourcesParentIfRequired();
|
||||||
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
|
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl;
|
printLog("error %u: %s\n", error, lodepng_error_text(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,11 +225,11 @@ void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int h
|
||||||
PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE);
|
PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(HEAD_PITCH_RATE);
|
||||||
float measured_roll_rate = serialInterface->getRelativeValue(HEAD_ROLL_RATE);
|
float measured_roll_rate = serialInterface->getRelativeValue(HEAD_ROLL_RATE);
|
||||||
|
|
||||||
//std::cout << "Pitch Rate: " << serialInterface->getRelativeValue(PITCH_RATE) <<
|
//printLog("Pitch Rate: %d ACCEL_Z: %d\n", serialInterface->getRelativeValue(PITCH_RATE),
|
||||||
// " fwd_accel: " << serialInterface->getRelativeValue(ACCEL_Z) << "\n";
|
// serialInterface->getRelativeValue(ACCEL_Z));
|
||||||
//std::cout << "Roll Rate: " << serialInterface->getRelativeValue(ROLL_RATE) <<
|
//printLog("Pitch Rate: %d ACCEL_X: %d\n", serialInterface->getRelativeValue(PITCH_RATE),
|
||||||
//" ACCEL_X: " << serialInterface->getRelativeValue(ACCEL_X) << "\n";
|
// serialInterface->getRelativeValue(ACCEL_Z));
|
||||||
//std::cout << "Pitch: " << Pitch << "\n";
|
//printLog("Pitch: %f\n", Pitch);
|
||||||
|
|
||||||
// Update avatar head position based on measured gyro rates
|
// Update avatar head position based on measured gyro rates
|
||||||
const float HEAD_ROTATION_SCALE = 0.70;
|
const float HEAD_ROTATION_SCALE = 0.70;
|
||||||
|
@ -347,13 +345,13 @@ void Head::simulate(float deltaTime) {
|
||||||
if (! _previousHandBeingMoved ){
|
if (! _previousHandBeingMoved ){
|
||||||
initializeBodySprings();
|
initializeBodySprings();
|
||||||
_usingSprings = true;
|
_usingSprings = true;
|
||||||
//printf( "just started moving hand\n" );
|
//printLog( "just started moving hand\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( _previousHandBeingMoved ){
|
if ( _previousHandBeingMoved ){
|
||||||
_usingSprings = false;
|
_usingSprings = false;
|
||||||
//printf( "just stopped moving hand\n" );
|
//printLog( "just stopped moving hand\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __interface__head__
|
#ifndef __interface__head__
|
||||||
#define __interface__head__
|
#define __interface__head__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <AvatarData.h>
|
#include <AvatarData.h>
|
||||||
#include <Orientation.h>
|
#include <Orientation.h>
|
||||||
|
|
||||||
|
|
323
interface/src/Log.cpp
Normal file
323
interface/src/Log.cpp
Normal file
|
@ -0,0 +1,323 @@
|
||||||
|
//
|
||||||
|
// Log.cpp
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/14/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// anonymous namespace - everything in here only exists within this very .cpp file
|
||||||
|
// just as 'static' on every effective line in plain C
|
||||||
|
|
||||||
|
unsigned const CHARACTER_BUFFER_SIZE = 16384; // number of character that are buffered
|
||||||
|
unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered
|
||||||
|
unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message
|
||||||
|
|
||||||
|
bool const TEXT_MONOSPACED = true;
|
||||||
|
|
||||||
|
float const TEXT_RED = 0.7f;
|
||||||
|
float const TEXT_GREEN = 0.6f;
|
||||||
|
float const TEXT_BLUE = 1.0f;
|
||||||
|
|
||||||
|
// magic constants from the GLUT spec
|
||||||
|
// http://www.opengl.org/resources/libraries/glut/spec3/node78.html
|
||||||
|
// ultimately this stuff should be in Util.h??
|
||||||
|
float const CHAR_UP = 119.05f;
|
||||||
|
float const CHAR_DOWN = 33.33f;
|
||||||
|
float const CHAR_WIDTH = 104.76f;
|
||||||
|
// derived values
|
||||||
|
float const CHAR_HEIGHT = CHAR_UP + CHAR_DOWN;
|
||||||
|
float const CHAR_FRACT_BASELINE = CHAR_DOWN / CHAR_HEIGHT;
|
||||||
|
|
||||||
|
// unsigned integer division rounded towards infinity
|
||||||
|
unsigned divRoundUp(unsigned l, unsigned r) { return (l + r - 1) / r; }
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::Log(FILE* tPipeTo, unsigned bufferedLines,
|
||||||
|
unsigned defaultLogWidth, unsigned defaultCharWidth, unsigned defaultCharHeight) :
|
||||||
|
|
||||||
|
_ptrStream(tPipeTo),
|
||||||
|
_arrChars(0l),
|
||||||
|
_arrLines(0l),
|
||||||
|
_valLogWidth(defaultLogWidth) {
|
||||||
|
|
||||||
|
pthread_mutex_init(& _mtx, 0l);
|
||||||
|
|
||||||
|
// allocate twice as much (so we have spare space for a copy not to block
|
||||||
|
// logging from other threads during 'render')
|
||||||
|
_arrChars = new char[CHARACTER_BUFFER_SIZE * 2];
|
||||||
|
_ptrCharsEnd = _arrChars + CHARACTER_BUFFER_SIZE;
|
||||||
|
_arrLines = new char*[LINE_BUFFER_SIZE * 2];
|
||||||
|
_ptrLinesEnd = _arrLines + LINE_BUFFER_SIZE;
|
||||||
|
|
||||||
|
// initialize the log to all empty lines
|
||||||
|
_arrChars[0] = '\0';
|
||||||
|
_itrWritePos = _arrChars;
|
||||||
|
_itrWriteLineStart = _arrChars;
|
||||||
|
_itrLastLine = _arrLines;
|
||||||
|
_valWrittenInLine = 0;
|
||||||
|
memset(_arrLines, 0, LINE_BUFFER_SIZE * sizeof(char*));
|
||||||
|
|
||||||
|
setCharacterSize(defaultCharWidth, defaultCharHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log::~Log() {
|
||||||
|
|
||||||
|
delete[] _arrChars;
|
||||||
|
delete[] _arrLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Log::addMessage(char const* ptr) {
|
||||||
|
|
||||||
|
// precondition: mutex is locked so noone gets in our way
|
||||||
|
|
||||||
|
// T-pipe, if requested
|
||||||
|
if (_ptrStream != 0l) {
|
||||||
|
fprintf(_ptrStream, "%s", ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*ptr != '\0') {
|
||||||
|
// process the characters
|
||||||
|
char c = *ptr++;
|
||||||
|
|
||||||
|
if (c == '\t') {
|
||||||
|
|
||||||
|
// found TAB -> write SPACE
|
||||||
|
c = ' ';
|
||||||
|
|
||||||
|
} else if (c == '\n') {
|
||||||
|
|
||||||
|
// found LF -> write NUL (c == '\0' tells us to wrap, below)
|
||||||
|
c = '\0';
|
||||||
|
}
|
||||||
|
*_itrWritePos++ = c;
|
||||||
|
|
||||||
|
if (_itrWritePos == _ptrCharsEnd) {
|
||||||
|
// reached the end of the circular character buffer? -> start over
|
||||||
|
_itrWritePos = _arrChars;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++_valWrittenInLine >= _valLineLength || c == '\0') {
|
||||||
|
|
||||||
|
// new line? store its start to the line buffer and mark next line as empty
|
||||||
|
++_itrLastLine;
|
||||||
|
|
||||||
|
if (_itrLastLine == _ptrLinesEnd) {
|
||||||
|
_itrLastLine = _arrLines;
|
||||||
|
_itrLastLine[1] = 0l;
|
||||||
|
} else if (_itrLastLine + 1 != _ptrLinesEnd) {
|
||||||
|
_itrLastLine[1] = 0l;
|
||||||
|
} else {
|
||||||
|
_arrLines[0] = 0l;
|
||||||
|
}
|
||||||
|
*_itrLastLine = _itrWriteLineStart;
|
||||||
|
|
||||||
|
// debug mode: make sure all line pointers we write here are valid
|
||||||
|
assert(! (_itrLastLine < _arrLines || _itrLastLine >= _ptrLinesEnd));
|
||||||
|
assert(! (*_itrLastLine < _arrChars || *_itrLastLine >= _ptrCharsEnd));
|
||||||
|
|
||||||
|
// terminate line, unless done already
|
||||||
|
if (c != '\0') {
|
||||||
|
*_itrWritePos++ = '\0';
|
||||||
|
|
||||||
|
if (_itrWritePos == _ptrCharsEnd) {
|
||||||
|
_itrWritePos = _arrChars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember start position in character buffer for next line and reset character count
|
||||||
|
_itrWriteLineStart = _itrWritePos;
|
||||||
|
_valWrittenInLine = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int Log::vprint(char const* fmt, va_list args) {
|
||||||
|
pthread_mutex_lock(& _mtx);
|
||||||
|
|
||||||
|
// print to buffer
|
||||||
|
char buf[MAX_MESSAGE_LENGTH];
|
||||||
|
int n = vsnprintf(buf, MAX_MESSAGE_LENGTH, fmt, args);
|
||||||
|
if (n > 0) {
|
||||||
|
|
||||||
|
// all fine? log the message
|
||||||
|
addMessage(buf);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// error? -> mutter on stream or stderr
|
||||||
|
fprintf(_ptrStream != 0l ? _ptrStream : stderr,
|
||||||
|
"Log: Failed to log message with format string = \"%s\".\n", fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(& _mtx);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::operator()(char const* fmt, ...) {
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args,fmt);
|
||||||
|
vprint(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::setLogWidth(unsigned pixels) {
|
||||||
|
|
||||||
|
pthread_mutex_lock(& _mtx);
|
||||||
|
_valLogWidth = pixels;
|
||||||
|
_valLineLength = _valLogWidth / _valCharWidth;
|
||||||
|
pthread_mutex_unlock(& _mtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::setCharacterSize(unsigned width, unsigned height) {
|
||||||
|
|
||||||
|
pthread_mutex_lock(& _mtx);
|
||||||
|
_valCharWidth = width;
|
||||||
|
_valCharHeight = height;
|
||||||
|
_valCharYoffset = height * CHAR_FRACT_BASELINE;
|
||||||
|
_valCharScale = float(width) / CHAR_WIDTH;
|
||||||
|
_valCharAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT);
|
||||||
|
_valLineLength = _valLogWidth / _valCharWidth;
|
||||||
|
pthread_mutex_unlock(& _mtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log::render(unsigned screenWidth, unsigned screenHeight) {
|
||||||
|
|
||||||
|
// rendering might take some time, so create a local copy of the portion we need
|
||||||
|
// instead of having to hold the mutex all the time
|
||||||
|
pthread_mutex_lock(& _mtx);
|
||||||
|
|
||||||
|
// determine number of visible lines
|
||||||
|
unsigned showLines = divRoundUp(screenHeight, _valCharHeight);
|
||||||
|
|
||||||
|
char** lastLine = _itrLastLine;
|
||||||
|
char** firstLine = _itrLastLine;
|
||||||
|
|
||||||
|
if (! *lastLine) {
|
||||||
|
// empty log
|
||||||
|
pthread_mutex_unlock(& _mtx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// scan for first line
|
||||||
|
for (int n = 2; n <= showLines; ++n) {
|
||||||
|
|
||||||
|
char** prevFirstLine = firstLine;
|
||||||
|
--firstLine;
|
||||||
|
if (firstLine < _arrLines) {
|
||||||
|
firstLine = _ptrLinesEnd - 1;
|
||||||
|
}
|
||||||
|
if (! *firstLine) {
|
||||||
|
firstLine = prevFirstLine;
|
||||||
|
showLines = n - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug mode: make sure all line pointers we find here are valid
|
||||||
|
assert(! (firstLine < _arrLines || firstLine >= _ptrLinesEnd));
|
||||||
|
assert(! (*firstLine < _arrChars || *firstLine >= _ptrCharsEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the line buffer portion into a contiguous region at _ptrLinesEnd
|
||||||
|
if (firstLine <= lastLine) {
|
||||||
|
|
||||||
|
memcpy(_ptrLinesEnd, firstLine, showLines * sizeof(char*));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
unsigned atEnd = _ptrLinesEnd - firstLine;
|
||||||
|
memcpy(_ptrLinesEnd, firstLine, atEnd * sizeof(char*));
|
||||||
|
memcpy(_ptrLinesEnd + atEnd, _arrLines, (showLines - atEnd) * sizeof(char*));
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy relevant char buffer portion and determine information to remap the pointers
|
||||||
|
char* firstChar = *firstLine;
|
||||||
|
char* lastChar = *lastLine + strlen(*lastLine) + 1;
|
||||||
|
ptrdiff_t charOffset = _ptrCharsEnd - firstChar, charOffsetBeforeFirst = 0;
|
||||||
|
if (firstChar <= lastChar) {
|
||||||
|
|
||||||
|
memcpy(_ptrCharsEnd, firstChar, lastChar - firstChar + 1);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
unsigned atEnd = _ptrCharsEnd - firstChar;
|
||||||
|
memcpy(_ptrCharsEnd, firstChar, atEnd);
|
||||||
|
memcpy(_ptrCharsEnd + atEnd, _arrChars, lastChar + 1 - _arrChars);
|
||||||
|
|
||||||
|
charOffsetBeforeFirst = _ptrCharsEnd + atEnd - _arrChars;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get values for rendering
|
||||||
|
float scaleFactor = _valCharScale;
|
||||||
|
int yStart = int((screenHeight - _valCharYoffset) / _valCharAspect);
|
||||||
|
int yStep = int(_valCharHeight / _valCharAspect);
|
||||||
|
float yScale = _valCharAspect;
|
||||||
|
|
||||||
|
// render text
|
||||||
|
char** line = _ptrLinesEnd + showLines;
|
||||||
|
int x = screenWidth - _valLogWidth;
|
||||||
|
|
||||||
|
pthread_mutex_unlock(& _mtx);
|
||||||
|
// ok, we got all we need
|
||||||
|
|
||||||
|
GLint matrixMode;
|
||||||
|
glGetIntegerv(GL_MATRIX_MODE, & matrixMode);
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(1.0f, yScale, 1.0f);
|
||||||
|
|
||||||
|
for (int y = yStart; y > 0; y -= yStep) {
|
||||||
|
|
||||||
|
// debug mode: check line pointer is valid
|
||||||
|
assert(! (line < _ptrLinesEnd || line >= _ptrLinesEnd + (_ptrLinesEnd - _arrLines)));
|
||||||
|
|
||||||
|
// get character pointer
|
||||||
|
if (--line < _ptrLinesEnd) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
char* chars = *line;
|
||||||
|
|
||||||
|
// debug mode: check char pointer we find is valid
|
||||||
|
assert(! (chars < _arrChars || chars >= _ptrCharsEnd));
|
||||||
|
|
||||||
|
// remap character pointer it to copied buffer
|
||||||
|
chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst;
|
||||||
|
|
||||||
|
// debug mode: check char pointer is still valid (in new range)
|
||||||
|
assert(! (chars < _ptrCharsEnd || chars >= _ptrCharsEnd + (_ptrCharsEnd - _arrChars)));
|
||||||
|
|
||||||
|
// render the string
|
||||||
|
drawtext(x, y, scaleFactor, 0.0f, 1.0f, int(TEXT_MONOSPACED),
|
||||||
|
chars, TEXT_RED, TEXT_GREEN, TEXT_BLUE);
|
||||||
|
|
||||||
|
//fprintf(stderr, "Log::render, message = \"%s\"\n", chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
glMatrixMode(matrixMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log logger;
|
||||||
|
|
||||||
|
int printLog(char const* fmt, ...) {
|
||||||
|
|
||||||
|
int result;
|
||||||
|
va_list args;
|
||||||
|
va_start(args,fmt);
|
||||||
|
result = logger.vprint(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
80
interface/src/Log.h
Normal file
80
interface/src/Log.h
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
//
|
||||||
|
// Log.h
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/14/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __interface__Log__
|
||||||
|
#define __interface__Log__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
class Log;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call it as you would call 'printf'.
|
||||||
|
//
|
||||||
|
int printLog(char const* fmt, ...);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Global instance.
|
||||||
|
//
|
||||||
|
extern Log logger;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Logging subsystem.
|
||||||
|
//
|
||||||
|
class Log {
|
||||||
|
FILE* _ptrStream;
|
||||||
|
char* _arrChars;
|
||||||
|
char* _ptrCharsEnd;
|
||||||
|
char** _arrLines;
|
||||||
|
char** _ptrLinesEnd;
|
||||||
|
|
||||||
|
char* _itrWritePos; // character position to write to
|
||||||
|
char* _itrWriteLineStart; // character position where line being written starts
|
||||||
|
char** _itrLastLine; // last line in the log
|
||||||
|
unsigned _valWrittenInLine; // character counter for line wrapping
|
||||||
|
unsigned _valLineLength; // number of characters before line wrap
|
||||||
|
|
||||||
|
unsigned _valLogWidth; // width of the log in pixels
|
||||||
|
unsigned _valCharWidth; // width of a character in pixels
|
||||||
|
unsigned _valCharHeight; // height of a character in pixels
|
||||||
|
unsigned _valCharYoffset; // baseline offset in pixels
|
||||||
|
float _valCharScale; // scale factor
|
||||||
|
float _valCharAspect; // aspect (h/w)
|
||||||
|
|
||||||
|
pthread_mutex_t _mtx;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit Log(FILE* tPipeTo = stdout, unsigned bufferedLines = 1024,
|
||||||
|
unsigned defaultLogWidth = 240, unsigned defaultCharWidth = 6, unsigned defaultCharHeight = 20);
|
||||||
|
~Log();
|
||||||
|
|
||||||
|
void setLogWidth(unsigned pixels);
|
||||||
|
void setCharacterSize(unsigned width, unsigned height);
|
||||||
|
|
||||||
|
void render(unsigned screenWidth, unsigned screenHeight);
|
||||||
|
|
||||||
|
void operator()(char const* fmt, ...);
|
||||||
|
int vprint(char const* fmt, va_list);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// don't copy/assign
|
||||||
|
Log(Log const&); // = delete;
|
||||||
|
Log& operator=(Log const&); // = delete;
|
||||||
|
|
||||||
|
inline void addMessage(char const*);
|
||||||
|
|
||||||
|
friend class LogStream; // for optional iostream-style interface that has to be #included separately
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
106
interface/src/LogStream.h
Normal file
106
interface/src/LogStream.h
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
//
|
||||||
|
// LogStream.h
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __interface__LogStream__
|
||||||
|
#define __interface__LogStream__
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Makes the logging facility accessible as a C++ stream.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// // somewhere central - ideally one per thread (else pass 'true' as
|
||||||
|
// // second constructor argument and compromise some efficiency)
|
||||||
|
// LogStream lOut(printLog);
|
||||||
|
//
|
||||||
|
// // elsewhere:
|
||||||
|
// lOut << "Hello there!" << std::endl;
|
||||||
|
//
|
||||||
|
class LogStream {
|
||||||
|
std::ostringstream _objOutStream;
|
||||||
|
Log& _refLog;
|
||||||
|
bool _flgThreadSafe;
|
||||||
|
public:
|
||||||
|
inline LogStream(Log& log, bool threadSafe = false);
|
||||||
|
|
||||||
|
class StreamRef; friend class StreamRef;
|
||||||
|
|
||||||
|
template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// don't
|
||||||
|
LogStream(LogStream const&); // = delete;
|
||||||
|
LogStream& operator=(LogStream const&); // = delete;
|
||||||
|
|
||||||
|
inline void ostreamBegin();
|
||||||
|
inline void ostreamEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
inline LogStream::LogStream(Log& log, bool threadSafe) :
|
||||||
|
_objOutStream(std::ios_base::out), _refLog(log), _flgThreadSafe(threadSafe) { }
|
||||||
|
|
||||||
|
inline void LogStream::ostreamBegin() {
|
||||||
|
|
||||||
|
if (_flgThreadSafe) {
|
||||||
|
// the user wants to share this LogStream among threads,
|
||||||
|
// so lock the global log here, already
|
||||||
|
pthread_mutex_lock(& _refLog._mtx);
|
||||||
|
}
|
||||||
|
_objOutStream.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void LogStream::ostreamEnd() {
|
||||||
|
|
||||||
|
if (! _flgThreadSafe) {
|
||||||
|
// haven't locked, so far (we have memory for each thread)
|
||||||
|
pthread_mutex_lock(& _refLog._mtx);
|
||||||
|
}
|
||||||
|
_refLog.addMessage(_objOutStream.str().c_str());
|
||||||
|
pthread_mutex_unlock(& _refLog._mtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// The Log::StreamRef class makes operator<< work. It...
|
||||||
|
//
|
||||||
|
class LogStream::StreamRef {
|
||||||
|
mutable LogStream* _ptrLogStream;
|
||||||
|
typedef std::ostream& (*manipulator)(std::ostream&);
|
||||||
|
|
||||||
|
friend class LogStream;
|
||||||
|
|
||||||
|
template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&);
|
||||||
|
StreamRef(LogStream* log) : _ptrLogStream(log) { }
|
||||||
|
public:
|
||||||
|
// ...forwards << operator calls to stringstream...
|
||||||
|
template< typename T > StreamRef const operator<<(T const& x) const { _ptrLogStream->_objOutStream << x; return *this; }
|
||||||
|
// ...has to dance around to make manipulators (such as std::hex, std::endl) work...
|
||||||
|
StreamRef const operator<<(manipulator x) const { _ptrLogStream->_objOutStream << x; return *this; }
|
||||||
|
// ...informs the logger that a stream has ended when it has the responsibility...
|
||||||
|
~StreamRef() { if (_ptrLogStream != 0l) { _ptrLogStream->ostreamEnd(); } }
|
||||||
|
// ...which is passed on upon copy.
|
||||||
|
StreamRef(StreamRef const& other) : _ptrLogStream(other._ptrLogStream) { other._ptrLogStream = 0l; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// don't
|
||||||
|
StreamRef& operator=(StreamRef const&); // = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
template< typename T > inline LogStream::StreamRef const operator<<(LogStream& s, T const& x) {
|
||||||
|
|
||||||
|
s.ostreamBegin();
|
||||||
|
s._objOutStream << x;
|
||||||
|
return LogStream::StreamRef(& s); // calls streamEnd at the end of the stream expression
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,17 +2,18 @@
|
||||||
#define __interface__OpenGlSupport__
|
#define __interface__OpenGlSupport__
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Macro to log OpenGl errors to stderr.
|
// Macro to log OpenGl errors.
|
||||||
* Example: oglLog( glPushMatrix() );
|
// Example: oglLog( glPushMatrix() );
|
||||||
*/
|
//
|
||||||
#define oGlLog(stmt) \
|
#define oGlLog(stmt) \
|
||||||
stmt; \
|
stmt; \
|
||||||
{ \
|
{ \
|
||||||
GLenum e = glGetError(); \
|
GLenum e = glGetError(); \
|
||||||
if (e != GL_NO_ERROR) { \
|
if (e != GL_NO_ERROR) { \
|
||||||
fprintf(stderr, __FILE__ ":" oGlLog_stringize(__LINE__) \
|
printLog(__FILE__ ":" oGlLog_stringize(__LINE__) \
|
||||||
" [OpenGL] %s\n", gluErrorString(e)); \
|
" [OpenGL] %s\n", gluErrorString(e)); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
@ -21,10 +22,10 @@
|
||||||
#define oGlLog_stringize(x) oGlLog_stringize_i(x)
|
#define oGlLog_stringize(x) oGlLog_stringize_i(x)
|
||||||
#define oGlLog_stringize_i(x) # x
|
#define oGlLog_stringize_i(x) # x
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Encapsulation of the otherwise lengthy call sequence to compile
|
// Encapsulation of the otherwise lengthy call sequence to compile
|
||||||
* and link shading pipelines.
|
// and link shading pipelines.
|
||||||
*/
|
//
|
||||||
class OGlProgram {
|
class OGlProgram {
|
||||||
|
|
||||||
GLuint _hndProg;
|
GLuint _hndProg;
|
||||||
|
@ -54,10 +55,10 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Activates the executable for rendering.
|
// Activates the executable for rendering.
|
||||||
* Shaders must be added and linked before this will work.
|
// Shaders must be added and linked before this will work.
|
||||||
*/
|
//
|
||||||
void activate() const {
|
void activate() const {
|
||||||
|
|
||||||
if (_hndProg != 0u) {
|
if (_hndProg != 0u) {
|
||||||
|
@ -66,17 +67,17 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Adds a shader to the program.
|
// Adds a shader to the program.
|
||||||
*/
|
//
|
||||||
bool addShader(GLenum type, GLchar const* cString) {
|
bool addShader(GLenum type, GLchar const* cString) {
|
||||||
|
|
||||||
return addShader(type, 1, & cString);
|
return addShader(type, 1, & cString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Adds a shader to the program and logs to stderr.
|
// Adds a shader to the program and logs to stderr.
|
||||||
*/
|
//
|
||||||
bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) {
|
bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) {
|
||||||
|
|
||||||
if (! _hndProg && !! glCreateProgram) {
|
if (! _hndProg && !! glCreateProgram) {
|
||||||
|
@ -100,9 +101,9 @@ public:
|
||||||
return !! status;
|
return !! status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Links the program and logs to stderr.
|
// Links the program and logs to stderr.
|
||||||
*/
|
//
|
||||||
bool link() {
|
bool link() {
|
||||||
|
|
||||||
if (! _hndProg) { return false; }
|
if (! _hndProg) { return false; }
|
||||||
|
@ -136,7 +137,7 @@ private:
|
||||||
if (!! logLength) {
|
if (!! logLength) {
|
||||||
GLchar* message = new GLchar[logLength];
|
GLchar* message = new GLchar[logLength];
|
||||||
getLog(handle, logLength, 0l, message);
|
getLog(handle, logLength, 0l, message);
|
||||||
fprintf(stderr, "%s\n", message);
|
printLog("%s\n", message);
|
||||||
delete[] message;
|
delete[] message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class Oscilloscope {
|
class Oscilloscope {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <string>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int serialFd;
|
int serialFd;
|
||||||
|
@ -67,10 +68,10 @@ int SerialInterface::initializePort(char* portname, int baud)
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
serialFd = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
|
|
||||||
printf("Opening SerialUSB %s: ", portname);
|
printLog("Opening SerialUSB %s: ", portname);
|
||||||
|
|
||||||
if (serialFd == -1) {
|
if (serialFd == -1) {
|
||||||
printf("Failed.\n");
|
printLog("Failed.\n");
|
||||||
return -1; // Failed to open port
|
return -1; // Failed to open port
|
||||||
}
|
}
|
||||||
struct termios options;
|
struct termios options;
|
||||||
|
@ -101,7 +102,7 @@ int SerialInterface::initializePort(char* portname, int baud)
|
||||||
tcsetattr(serialFd,TCSANOW,&options);
|
tcsetattr(serialFd,TCSANOW,&options);
|
||||||
|
|
||||||
|
|
||||||
printf("Connected.\n");
|
printLog("Connected.\n");
|
||||||
resetSerial();
|
resetSerial();
|
||||||
active = true;
|
active = true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -168,13 +169,13 @@ void SerialInterface::readData() {
|
||||||
int initialSamples = totalSamples;
|
int initialSamples = totalSamples;
|
||||||
|
|
||||||
while (read(serialFd, &bufchar, 1) > 0) {
|
while (read(serialFd, &bufchar, 1) > 0) {
|
||||||
//std::cout << bufchar[0];
|
//printLof("%c", bufchar[0]);
|
||||||
serialBuffer[serialBufferPos] = bufchar[0];
|
serialBuffer[serialBufferPos] = bufchar[0];
|
||||||
serialBufferPos++;
|
serialBufferPos++;
|
||||||
// Have we reached end of a line of input?
|
// Have we reached end of a line of input?
|
||||||
if ((bufchar[0] == '\n') || (serialBufferPos >= MAX_BUFFER)) {
|
if ((bufchar[0] == '\n') || (serialBufferPos >= MAX_BUFFER)) {
|
||||||
std::string serialLine(serialBuffer, serialBufferPos-1);
|
std::string serialLine(serialBuffer, serialBufferPos-1);
|
||||||
//std::cout << serialLine << "\n";
|
//printLog("%s\n", serialLine.c_str());
|
||||||
int spot;
|
int spot;
|
||||||
//int channel = 0;
|
//int channel = 0;
|
||||||
std::string val;
|
std::string val;
|
||||||
|
@ -182,7 +183,7 @@ void SerialInterface::readData() {
|
||||||
spot = serialLine.find_first_of(" ", 0);
|
spot = serialLine.find_first_of(" ", 0);
|
||||||
if (spot != std::string::npos) {
|
if (spot != std::string::npos) {
|
||||||
val = serialLine.substr(0,spot);
|
val = serialLine.substr(0,spot);
|
||||||
//std::cout << val << "\n";
|
//printLog("%s\n", val.c_str());
|
||||||
if (i < NUM_CHANNELS) lastMeasured[i] = atoi(val.c_str());
|
if (i < NUM_CHANNELS) lastMeasured[i] = atoi(val.c_str());
|
||||||
else samplesAveraged = atoi(val.c_str());
|
else samplesAveraged = atoi(val.c_str());
|
||||||
} else LED = atoi(serialLine.c_str());
|
} else LED = atoi(serialLine.c_str());
|
||||||
|
@ -208,8 +209,7 @@ void SerialInterface::readData() {
|
||||||
}
|
}
|
||||||
if (totalSamples == GRAVITY_SAMPLES) {
|
if (totalSamples == GRAVITY_SAMPLES) {
|
||||||
gravity = glm::normalize(gravity);
|
gravity = glm::normalize(gravity);
|
||||||
std::cout << "gravity: " << gravity.x << "," <<
|
//printLof("gravity: %f,%f,%f\n", gravity.x, gravity.y, gravity.z);
|
||||||
gravity.y << "," << gravity.z << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
totalSamples++;
|
totalSamples++;
|
||||||
|
@ -222,7 +222,7 @@ void SerialInterface::readData() {
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) {
|
if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) {
|
||||||
std::cout << "No data - Shutting down SerialInterface.\n";
|
printLog("No data - Shutting down SerialInterface.\n");
|
||||||
resetSerial();
|
resetSerial();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include <iostream>
|
#include "Log.h"
|
||||||
|
|
||||||
// These includes are for serial port reading/writing
|
// These includes are for serial port reading/writing
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
#include <lodepng.h>
|
#include <lodepng.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -30,7 +32,7 @@ int load_png_as_texture(char* filename)
|
||||||
unsigned int width = 1, height = 1;
|
unsigned int width = 1, height = 1;
|
||||||
unsigned error = lodepng::decode(image, width, height, filename);
|
unsigned error = lodepng::decode(image, width, height, filename);
|
||||||
if (error) {
|
if (error) {
|
||||||
std::cout << "Error loading texture" << std::endl;
|
printLog("Error loading texture\n");
|
||||||
return (int) error;
|
return (int) error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +45,7 @@ int load_png_as_texture(char* filename)
|
||||||
|
|
||||||
if(glGetError() != GL_NO_ERROR)
|
if(glGetError() != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
std::cout << "Error initing GL" << std::endl;
|
printLog("Error initing GL\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#ifndef __interface__Texture__
|
#ifndef __interface__Texture__
|
||||||
#define __interface__Texture__
|
#define __interface__Texture__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
|
||||||
int load_png_as_texture(char* filename);
|
int load_png_as_texture(char* filename);
|
||||||
|
|
|
@ -14,9 +14,16 @@
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
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) {
|
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * front, glm::vec3 * right, glm::vec3 * up) {
|
||||||
|
@ -143,12 +150,17 @@ double diffclock(timeval *clock1,timeval *clock2)
|
||||||
return diffms;
|
return diffms;
|
||||||
}
|
}
|
||||||
|
|
||||||
int widthText(float scale, int mono, char *string) {
|
int widthText(float scale, int mono, char const* string) {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
if (!mono) {
|
if (!mono) {
|
||||||
width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
||||||
} else {
|
} else {
|
||||||
|
#ifndef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
||||||
|
#else
|
||||||
|
// return value is unreliable, so just calculate it
|
||||||
|
width = scale * float(strlen(string)) * MONO_STROKE_WIDTH_GLUT;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +182,27 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
len = (int) strlen(string);
|
len = (int) strlen(string);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
if (!mono) {
|
||||||
else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i]));
|
glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
||||||
|
} else {
|
||||||
|
#ifdef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
|
if (string[i] != 'm') {
|
||||||
|
#endif
|
||||||
|
glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i]));
|
||||||
|
#ifdef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
|
} else {
|
||||||
|
// some glut implementations have a broken 'm'...
|
||||||
|
unsigned char tmpStr[2];
|
||||||
|
tmpStr[0] = string[i];
|
||||||
|
tmpStr[1] = '\0';
|
||||||
|
float scale = MONO_STROKE_WIDTH_GLUT / glutStrokeLength(GLUT_STROKE_ROMAN, tmpStr);
|
||||||
|
glScalef(scale, 1.0f, 1.0f);
|
||||||
|
glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
||||||
|
// staying humble on the stack - might be in projection mode
|
||||||
|
glScalef(1.0f / scale, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
@ -211,7 +242,7 @@ void drawGroundPlaneGrid( float size, int resolution )
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
|
|
||||||
float gridSize = 10.0;
|
float gridSize = 10.0;
|
||||||
int gridResolution = 10;
|
int gridResolution = 20;
|
||||||
|
|
||||||
for (int g=0; g<gridResolution; g++)
|
for (int g=0; g<gridResolution; g++)
|
||||||
{
|
{
|
||||||
|
@ -232,6 +263,15 @@ void drawGroundPlaneGrid( float size, int resolution )
|
||||||
glVertex3f( gridSize * ONE_HALF, 0.0f, inc );
|
glVertex3f( gridSize * ONE_HALF, 0.0f, inc );
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw a translucent quad just underneath the grid.
|
||||||
|
glColor4f(0.5, 0.5, 0.5, 0.4);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex3f(-gridSize * ONE_HALF, 0, -gridSize * ONE_HALF);
|
||||||
|
glVertex3f(gridSize * ONE_HALF, 0, -gridSize * ONE_HALF);
|
||||||
|
glVertex3f(gridSize * ONE_HALF, 0, gridSize * ONE_HALF);
|
||||||
|
glVertex3f(-gridSize * ONE_HALF, 0, gridSize * ONE_HALF);
|
||||||
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,13 +301,13 @@ void renderOrientationDirections( glm::vec3 position, Orientation orientation, f
|
||||||
|
|
||||||
bool closeEnoughForGovernmentWork(float a, float b) {
|
bool closeEnoughForGovernmentWork(float a, float b) {
|
||||||
float distance = std::abs(a-b);
|
float distance = std::abs(a-b);
|
||||||
//printf("closeEnoughForGovernmentWork() a=%1.10f b=%1.10f distance=%1.10f\n",a,b,distance);
|
//printLog("closeEnoughForGovernmentWork() a=%1.10f b=%1.10f distance=%1.10f\n",a,b,distance);
|
||||||
return (distance < 0.00001f);
|
return (distance < 0.00001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void testOrientationClass() {
|
void testOrientationClass() {
|
||||||
printf("\n----------\ntestOrientationClass()\n----------\n\n");
|
printLog("\n----------\ntestOrientationClass()\n----------\n\n");
|
||||||
|
|
||||||
oTestCase tests[] = {
|
oTestCase tests[] = {
|
||||||
// - inputs ------------, outputs -------------------- ------------------- ----------------------------
|
// - inputs ------------, outputs -------------------- ------------------- ----------------------------
|
||||||
|
@ -337,53 +377,53 @@ void testOrientationClass() {
|
||||||
glm::vec3 up = o1.getUp();
|
glm::vec3 up = o1.getUp();
|
||||||
glm::vec3 right = o1.getRight();
|
glm::vec3 right = o1.getRight();
|
||||||
|
|
||||||
printf("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n",i+1,yaw,pitch,roll);
|
printLog("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n",i+1,yaw,pitch,roll);
|
||||||
|
|
||||||
printf("\nFRONT\n");
|
printLog("\nFRONT\n");
|
||||||
printf(" + received: front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
|
printLog(" + received: front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
|
||||||
|
|
||||||
if (closeEnoughForGovernmentWork(front.x, tests[i].frontX)
|
if (closeEnoughForGovernmentWork(front.x, tests[i].frontX)
|
||||||
&& closeEnoughForGovernmentWork(front.y, tests[i].frontY)
|
&& closeEnoughForGovernmentWork(front.y, tests[i].frontY)
|
||||||
&& closeEnoughForGovernmentWork(front.z, tests[i].frontZ)) {
|
&& closeEnoughForGovernmentWork(front.z, tests[i].frontZ)) {
|
||||||
printf(" front vector PASSES!\n");
|
printLog(" front vector PASSES!\n");
|
||||||
} else {
|
} else {
|
||||||
printf(" expected: front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
|
printLog(" expected: front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
|
||||||
printf(" front vector FAILED! \n");
|
printLog(" front vector FAILED! \n");
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nUP\n");
|
printLog("\nUP\n");
|
||||||
printf(" + received: up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
|
printLog(" + received: up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
|
||||||
if (closeEnoughForGovernmentWork(up.x, tests[i].upX)
|
if (closeEnoughForGovernmentWork(up.x, tests[i].upX)
|
||||||
&& closeEnoughForGovernmentWork(up.y, tests[i].upY)
|
&& closeEnoughForGovernmentWork(up.y, tests[i].upY)
|
||||||
&& closeEnoughForGovernmentWork(up.z, tests[i].upZ)) {
|
&& closeEnoughForGovernmentWork(up.z, tests[i].upZ)) {
|
||||||
printf(" up vector PASSES!\n");
|
printLog(" up vector PASSES!\n");
|
||||||
} else {
|
} else {
|
||||||
printf(" expected: up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
|
printLog(" expected: up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
|
||||||
printf(" up vector FAILED!\n");
|
printLog(" up vector FAILED!\n");
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("\nRIGHT\n");
|
printLog("\nRIGHT\n");
|
||||||
printf(" + received: right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
|
printLog(" + received: right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
|
||||||
if (closeEnoughForGovernmentWork(right.x, tests[i].rightX)
|
if (closeEnoughForGovernmentWork(right.x, tests[i].rightX)
|
||||||
&& closeEnoughForGovernmentWork(right.y, tests[i].rightY)
|
&& closeEnoughForGovernmentWork(right.y, tests[i].rightY)
|
||||||
&& closeEnoughForGovernmentWork(right.z, tests[i].rightZ)) {
|
&& closeEnoughForGovernmentWork(right.z, tests[i].rightZ)) {
|
||||||
printf(" right vector PASSES!\n");
|
printLog(" right vector PASSES!\n");
|
||||||
} else {
|
} else {
|
||||||
printf(" expected: right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
|
printLog(" expected: right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
|
||||||
printf(" right vector FAILED!\n");
|
printLog(" right vector FAILED!\n");
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
printf("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
|
printLog("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
|
||||||
failedCount++;
|
failedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
|
printLog("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
|
||||||
printf("\n----------DONE----------\n\n");
|
printLog("\n----------DONE----------\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float
|
||||||
float randFloat();
|
float randFloat();
|
||||||
void render_world_box();
|
void render_world_box();
|
||||||
void render_vector(glm::vec3 * vec);
|
void render_vector(glm::vec3 * vec);
|
||||||
int widthText(float scale, int mono, char *string);
|
int widthText(float scale, int mono, char const* string);
|
||||||
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
char const* string, float r=1.0, float g=1.0, float b=1.0);
|
char const* 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,
|
void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, glm::vec3 vec,
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include <OctalCode.h>
|
#include <OctalCode.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
#include "VoxelSystem.h"
|
#include "VoxelSystem.h"
|
||||||
|
|
||||||
const int MAX_VOXELS_PER_SYSTEM = 250000;
|
const int MAX_VOXELS_PER_SYSTEM = 250000;
|
||||||
|
@ -136,15 +138,15 @@ void VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
int commandLength = strlen(command); // commands are null terminated strings
|
int commandLength = strlen(command); // commands are null terminated strings
|
||||||
int totalLength = 1+commandLength+1;
|
int totalLength = 1+commandLength+1;
|
||||||
|
|
||||||
printf("got Z message len(%d)= %s\n", numBytes, command);
|
printLog("got Z message len(%d)= %s\n", numBytes, command);
|
||||||
|
|
||||||
while (totalLength <= numBytes) {
|
while (totalLength <= numBytes) {
|
||||||
if (0==strcmp(command,(char*)"erase all")) {
|
if (0==strcmp(command,(char*)"erase all")) {
|
||||||
printf("got Z message == erase all\n");
|
printLog("got Z message == erase all\n");
|
||||||
tree->eraseAllVoxels();
|
tree->eraseAllVoxels();
|
||||||
}
|
}
|
||||||
if (0==strcmp(command,(char*)"add scene")) {
|
if (0==strcmp(command,(char*)"add scene")) {
|
||||||
printf("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
|
printLog("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
|
||||||
}
|
}
|
||||||
totalLength += commandLength+1;
|
totalLength += commandLength+1;
|
||||||
}
|
}
|
||||||
|
@ -194,13 +196,13 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
|
||||||
float viewerZ = swapXandZ ? viewerPosition[0] : viewerPosition[2];
|
float viewerZ = swapXandZ ? viewerPosition[0] : viewerPosition[2];
|
||||||
|
|
||||||
// debugging code.
|
// debugging code.
|
||||||
//printf("treeToArrays() halfUnitForVoxel=%f\n",halfUnitForVoxel);
|
//printLog("treeToArrays() halfUnitForVoxel=%f\n",halfUnitForVoxel);
|
||||||
//printf("treeToArrays() viewerPosition {x,y,z or [0],[1],[2]} ={%f,%f,%f}\n",
|
//printLog("treeToArrays() viewerPosition {x,y,z or [0],[1],[2]} ={%f,%f,%f}\n",
|
||||||
// viewerPosition[0],viewerPosition[1],viewerPosition[2]);
|
// viewerPosition[0],viewerPosition[1],viewerPosition[2]);
|
||||||
//printf("treeToArrays() nodePosition {x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
|
//printLog("treeToArrays() nodePosition {x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
|
||||||
// nodePosition[0],nodePosition[1],nodePosition[2]);
|
// nodePosition[0],nodePosition[1],nodePosition[2]);
|
||||||
//float* vertices = firstVertexForCode(currentNode->octalCode);
|
//float* vertices = firstVertexForCode(currentNode->octalCode);
|
||||||
//printf("treeToArrays() firstVerticesForCode(currentNode->octalCode)={x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
|
//printLog("treeToArrays() firstVerticesForCode(currentNode->octalCode)={x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
|
||||||
// vertices[0],vertices[1],vertices[2]);
|
// vertices[0],vertices[1],vertices[2]);
|
||||||
//delete []vertices;
|
//delete []vertices;
|
||||||
|
|
||||||
|
@ -209,7 +211,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) {
|
||||||
powf(viewerZ - nodePosition[2] - halfUnitForVoxel, 2));
|
powf(viewerZ - nodePosition[2] - halfUnitForVoxel, 2));
|
||||||
|
|
||||||
int boundaryPosition = boundaryDistanceForRenderLevel(*currentNode->octalCode + 1);
|
int boundaryPosition = boundaryDistanceForRenderLevel(*currentNode->octalCode + 1);
|
||||||
//printf("treeToArrays() distanceToVoxelCenter=%f boundaryPosition=%d\n",distanceToVoxelCenter,boundaryPosition);
|
//printLog("treeToArrays() distanceToVoxelCenter=%f boundaryPosition=%d\n",distanceToVoxelCenter,boundaryPosition);
|
||||||
|
|
||||||
bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring
|
bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <iostream>
|
|
||||||
#include <UDPSocket.h>
|
#include <UDPSocket.h>
|
||||||
#include <AgentData.h>
|
#include <AgentData.h>
|
||||||
#include <VoxelTree.h>
|
#include <VoxelTree.h>
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -47,6 +45,11 @@
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
#include "shared_Log.h"
|
||||||
|
#include "voxels_Log.h"
|
||||||
|
#include "avatars_Log.h"
|
||||||
|
|
||||||
#include "Field.h"
|
#include "Field.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
@ -147,7 +150,7 @@ float renderPitchRate = 0.f;
|
||||||
// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program)
|
// Where one's own agent begins in the world (needs to become a dynamic thing passed to the program)
|
||||||
glm::vec3 start_location(6.1f, 0, 1.4f);
|
glm::vec3 start_location(6.1f, 0, 1.4f);
|
||||||
|
|
||||||
int statsOn = 0; // Whether to show onscreen text overlay with stats
|
bool statsOn = false; // Whether to show onscreen text overlay with stats
|
||||||
bool starsOn = false; // Whether to display the stars
|
bool starsOn = false; // Whether to display the stars
|
||||||
bool paintOn = false; // Whether to paint voxels as you fly around
|
bool paintOn = false; // Whether to paint voxels as you fly around
|
||||||
VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
|
VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
|
||||||
|
@ -316,9 +319,9 @@ void init(void)
|
||||||
marker_capturer.position_updated(&position_updated);
|
marker_capturer.position_updated(&position_updated);
|
||||||
marker_capturer.frame_updated(&marker_frame_available);
|
marker_capturer.frame_updated(&marker_frame_available);
|
||||||
if(!marker_capturer.init_capture()){
|
if(!marker_capturer.init_capture()){
|
||||||
printf("Camera-based marker capture initialized.\n");
|
printLog("Camera-based marker capture initialized.\n");
|
||||||
}else{
|
}else{
|
||||||
printf("Error initializing camera-based marker capture.\n");
|
printLog("Error initializing camera-based marker capture.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -884,6 +887,7 @@ void display(void)
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
glPointSize(1.0f);
|
glPointSize(1.0f);
|
||||||
displayStats();
|
displayStats();
|
||||||
|
logger.render(WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show menu
|
// Show menu
|
||||||
|
@ -1083,7 +1087,7 @@ void testPointToVoxel()
|
||||||
float s=0.1;
|
float s=0.1;
|
||||||
for (float x=0; x<=1; x+= 0.05)
|
for (float x=0; x<=1; x+= 0.05)
|
||||||
{
|
{
|
||||||
std::cout << " x=" << x << " ";
|
printLog(" x=%f");
|
||||||
|
|
||||||
unsigned char red = 200; //randomColorValue(65);
|
unsigned char red = 200; //randomColorValue(65);
|
||||||
unsigned char green = 200; //randomColorValue(65);
|
unsigned char green = 200; //randomColorValue(65);
|
||||||
|
@ -1092,7 +1096,7 @@ void testPointToVoxel()
|
||||||
unsigned char* voxelCode = pointToVoxel(x, y, z, s,red,green,blue);
|
unsigned char* voxelCode = pointToVoxel(x, y, z, s,red,green,blue);
|
||||||
printVoxelCode(voxelCode);
|
printVoxelCode(voxelCode);
|
||||||
delete voxelCode;
|
delete voxelCode;
|
||||||
std::cout << std::endl;
|
printLog("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1101,7 +1105,7 @@ void sendVoxelServerEraseAll() {
|
||||||
sprintf(message,"%c%s",'Z',"erase all");
|
sprintf(message,"%c%s",'Z',"erase all");
|
||||||
int messageSize = strlen(message) + 1;
|
int messageSize = strlen(message) + 1;
|
||||||
AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
|
AgentList::getInstance()->broadcastToAgents((unsigned char*) message, messageSize, &AGENT_TYPE_VOXEL, 1);
|
||||||
}\
|
}
|
||||||
|
|
||||||
void sendVoxelServerAddScene() {
|
void sendVoxelServerAddScene() {
|
||||||
char message[100];
|
char message[100];
|
||||||
|
@ -1139,11 +1143,11 @@ void addRandomSphere(bool wantColorRandomizer)
|
||||||
float s = 0.001; // size of voxels to make up surface of sphere
|
float s = 0.001; // size of voxels to make up surface of sphere
|
||||||
bool solid = false;
|
bool solid = false;
|
||||||
|
|
||||||
printf("random sphere\n");
|
printLog("random sphere\n");
|
||||||
printf("radius=%f\n",r);
|
printLog("radius=%f\n",r);
|
||||||
printf("xc=%f\n",xc);
|
printLog("xc=%f\n",xc);
|
||||||
printf("yc=%f\n",yc);
|
printLog("yc=%f\n",yc);
|
||||||
printf("zc=%f\n",zc);
|
printLog("zc=%f\n",zc);
|
||||||
|
|
||||||
voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
|
voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
|
||||||
}
|
}
|
||||||
|
@ -1411,7 +1415,7 @@ void reshape(int width, int height)
|
||||||
farClip = ::myCamera.getFarClip();
|
farClip = ::myCamera.getFarClip();
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n",
|
//printLog("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n",
|
||||||
// width,height,aspectRatio,fov,nearClip,farClip);
|
// width,height,aspectRatio,fov,nearClip,farClip);
|
||||||
|
|
||||||
// Tell our viewFrustum about this change
|
// Tell our viewFrustum about this change
|
||||||
|
@ -1491,6 +1495,10 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
|
shared_lib::printLog = & ::printLog;
|
||||||
|
voxels_lib::printLog = & ::printLog;
|
||||||
|
avatars_lib::printLog = & ::printLog;
|
||||||
|
|
||||||
// Quick test of the Orientation class on startup!
|
// Quick test of the Orientation class on startup!
|
||||||
if (cmdOptionExists(argc, argv, "--testOrientation")) {
|
if (cmdOptionExists(argc, argv, "--testOrientation")) {
|
||||||
testOrientationClass();
|
testOrientationClass();
|
||||||
|
@ -1507,7 +1515,7 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
// Handle Local Domain testing with the --local command line
|
// Handle Local Domain testing with the --local command line
|
||||||
if (cmdOptionExists(argc, argv, "--local")) {
|
if (cmdOptionExists(argc, argv, "--local")) {
|
||||||
printf("Local Domain MODE!\n");
|
printLog("Local Domain MODE!\n");
|
||||||
int ip = getLocalAddress();
|
int ip = getLocalAddress();
|
||||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||||
}
|
}
|
||||||
|
@ -1547,11 +1555,11 @@ int main(int argc, const char * argv[])
|
||||||
viewFrustumOffsetCamera.setNearClip(0.1);
|
viewFrustumOffsetCamera.setNearClip(0.1);
|
||||||
viewFrustumOffsetCamera.setFarClip(500.0);
|
viewFrustumOffsetCamera.setFarClip(500.0);
|
||||||
|
|
||||||
printf( "Created Display Window.\n" );
|
printLog( "Created Display Window.\n" );
|
||||||
|
|
||||||
initMenu();
|
initMenu();
|
||||||
initDisplay();
|
initDisplay();
|
||||||
printf( "Initialized Display.\n" );
|
printLog( "Initialized Display.\n" );
|
||||||
|
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutReshapeFunc(reshape);
|
glutReshapeFunc(reshape);
|
||||||
|
@ -1565,7 +1573,7 @@ int main(int argc, const char * argv[])
|
||||||
glutIdleFunc(idle);
|
glutIdleFunc(idle);
|
||||||
|
|
||||||
init();
|
init();
|
||||||
printf( "Init() complete.\n" );
|
printLog( "Init() complete.\n" );
|
||||||
|
|
||||||
// Check to see if the user passed in a command line option for randomizing colors
|
// Check to see if the user passed in a command line option for randomizing colors
|
||||||
if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
|
if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
|
||||||
|
@ -1577,17 +1585,17 @@ int main(int argc, const char * argv[])
|
||||||
const char* voxelsFilename = getCmdOption(argc, argv, "-i");
|
const char* voxelsFilename = getCmdOption(argc, argv, "-i");
|
||||||
if (voxelsFilename) {
|
if (voxelsFilename) {
|
||||||
voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
|
voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
|
||||||
printf("Local Voxel File loaded.\n");
|
printLog("Local Voxel File loaded.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create thread for receipt of data via UDP
|
// create thread for receipt of data via UDP
|
||||||
pthread_create(&networkReceiveThread, NULL, networkReceive, NULL);
|
pthread_create(&networkReceiveThread, NULL, networkReceive, NULL);
|
||||||
printf("Network receive thread created.\n");
|
printLog("Network receive thread created.\n");
|
||||||
|
|
||||||
glutTimerFunc(1000, Timer, 0);
|
glutTimerFunc(1000, Timer, 0);
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
printf("Normal exit.\n");
|
printLog("Normal exit.\n");
|
||||||
::terminate();
|
::terminate();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include "OGlProgram.h"
|
#include "OGlProgram.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
|
@ -211,7 +211,7 @@ namespace starfield {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: setResolution(%d)\n", k);
|
// printLog("Stars.cpp: setResolution(%d)\n", k);
|
||||||
|
|
||||||
#if STARFIELD_MULTITHREADING
|
#if STARFIELD_MULTITHREADING
|
||||||
if (k != _valTileResolution.load(memory_order_relaxed))
|
if (k != _valTileResolution.load(memory_order_relaxed))
|
||||||
|
@ -251,7 +251,7 @@ namespace starfield {
|
||||||
VertexOrder scanner(tiling);
|
VertexOrder scanner(tiling);
|
||||||
radix2InplaceSort(_seqInput.begin(), _seqInput.end(), scanner);
|
radix2InplaceSort(_seqInput.begin(), _seqInput.end(), scanner);
|
||||||
|
|
||||||
// fprintf(stderr,
|
// printLog(
|
||||||
// "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin);
|
// "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin);
|
||||||
|
|
||||||
recreateRenderer(n, k, b, bMin);
|
recreateRenderer(n, k, b, bMin);
|
||||||
|
@ -266,7 +266,7 @@ namespace starfield {
|
||||||
assert(overalloc >= realloc && realloc >= 0.0);
|
assert(overalloc >= realloc && realloc >= 0.0);
|
||||||
assert(overalloc <= 1.0 && realloc <= 1.0);
|
assert(overalloc <= 1.0 && realloc <= 1.0);
|
||||||
|
|
||||||
// fprintf(stderr,
|
// printLog(
|
||||||
// "Stars.cpp: changeLOD(%lf, %lf, %lf)\n", factor, overalloc, realloc);
|
// "Stars.cpp: changeLOD(%lf, %lf, %lf)\n", factor, overalloc, realloc);
|
||||||
|
|
||||||
size_t n, nRender;
|
size_t n, nRender;
|
||||||
|
@ -307,7 +307,7 @@ namespace starfield {
|
||||||
_valLodBrightness = b;
|
_valLodBrightness = b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: "
|
// printLog("Stars.cpp: "
|
||||||
// "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n",
|
// "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n",
|
||||||
// fraction, oaFract, toBufSize(oaFract * last)), n, bMin, b);
|
// fraction, oaFract, toBufSize(oaFract * last)), n, bMin, b);
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ namespace starfield {
|
||||||
|
|
||||||
recreateRenderer(n, _valTileResolution, b, bMin);
|
recreateRenderer(n, _valTileResolution, b, bMin);
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: LOD reallocation\n");
|
// printLog("Stars.cpp: LOD reallocation\n");
|
||||||
|
|
||||||
// publish new lod state
|
// publish new lod state
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,12 @@ namespace starfield {
|
||||||
|
|
||||||
if (! UrlReader::readUrl(url, *this, cacheFile))
|
if (! UrlReader::readUrl(url, *this, cacheFile))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s:%d: %s\n",
|
printLog("%s:%d: %s\n",
|
||||||
_strUrl, _valLineNo, getError());
|
_strUrl, _valLineNo, getError());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Stars.cpp: read %u vertices, using %lu\n",
|
printLog("Stars.cpp: read %u vertices, using %lu\n", _valRecordsRead, _ptrVertices->size());
|
||||||
_valRecordsRead, _ptrVertices->size());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +71,7 @@ namespace starfield {
|
||||||
|
|
||||||
_ptrVertices->clear();
|
_ptrVertices->clear();
|
||||||
_ptrVertices->reserve(_valLimit);
|
_ptrVertices->reserve(_valLimit);
|
||||||
// fprintf(stderr, "Stars.cpp: loader begin %s\n", url);
|
// printLog("Stars.cpp: loader begin %s\n", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t transfer(char* input, size_t bytes) {
|
size_t transfer(char* input, size_t bytes) {
|
||||||
|
@ -111,7 +110,7 @@ namespace starfield {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
fprintf(stderr, "Stars.cpp:%d: Bad input from %s\n",
|
printLog("Stars.cpp:%d: Bad input from %s\n",
|
||||||
_valLineNo, _strUrl);
|
_valLineNo, _strUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +135,7 @@ namespace starfield {
|
||||||
// remember the brightness at its top
|
// remember the brightness at its top
|
||||||
if (_valRecordsRead == _valLimit) {
|
if (_valRecordsRead == _valLimit) {
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: vertex limit reached -> heap mode\n");
|
// printLog("Stars.cpp: vertex limit reached -> heap mode\n");
|
||||||
|
|
||||||
make_heap(
|
make_heap(
|
||||||
_ptrVertices->begin(), _ptrVertices->end(),
|
_ptrVertices->begin(), _ptrVertices->end(),
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace starfield {
|
||||||
mat4 const& orientation,
|
mat4 const& orientation,
|
||||||
BrightnessLevel minBright) {
|
BrightnessLevel minBright) {
|
||||||
|
|
||||||
// fprintf(stderr, "
|
// printLog("
|
||||||
// Stars.cpp: rendering at minimal brightness %d\n", minBright);
|
// Stars.cpp: rendering at minimal brightness %d\n", minBright);
|
||||||
|
|
||||||
float halfPersp = perspective * 0.5f;
|
float halfPersp = perspective * 0.5f;
|
||||||
|
@ -160,7 +160,7 @@ namespace starfield {
|
||||||
unsigned tileIndex =
|
unsigned tileIndex =
|
||||||
_objTiling.getTileIndex(azimuth, altitude);
|
_objTiling.getTileIndex(azimuth, altitude);
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: starting on tile #%d\n", tileIndex);
|
// printLog("Stars.cpp: starting on tile #%d\n", tileIndex);
|
||||||
|
|
||||||
|
|
||||||
#if STARFIELD_DEBUG_CULLING
|
#if STARFIELD_DEBUG_CULLING
|
||||||
|
@ -245,7 +245,7 @@ namespace starfield {
|
||||||
if (bv >= b)
|
if (bv >= b)
|
||||||
++count_active;
|
++count_active;
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex);
|
// printLog("Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex);
|
||||||
|
|
||||||
// write converted vertex
|
// write converted vertex
|
||||||
_arrData[vertexIndex++] = *i;
|
_arrData[vertexIndex++] = *i;
|
||||||
|
@ -376,7 +376,7 @@ namespace starfield {
|
||||||
float dal = halfSlice;
|
float dal = halfSlice;
|
||||||
float adjustedNear = cos(_valHalfPersp + sqrt(daz * daz + dal * dal));
|
float adjustedNear = cos(_valHalfPersp + sqrt(daz * daz + dal * dal));
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip);
|
// printLog("Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip);
|
||||||
|
|
||||||
return w > adjustedNear;
|
return w > adjustedNear;
|
||||||
}
|
}
|
||||||
|
@ -486,10 +486,10 @@ namespace starfield {
|
||||||
|
|
||||||
void glBatch(GLfloat const* matrix, GLsizei n_ranges) {
|
void glBatch(GLfloat const* matrix, GLsizei n_ranges) {
|
||||||
|
|
||||||
// fprintf(stderr, "Stars.cpp: rendering %d-multibatch\n", n_ranges);
|
// printLog("Stars.cpp: rendering %d-multibatch\n", n_ranges);
|
||||||
|
|
||||||
// for (int i = 0; i < n_ranges; ++i)
|
// for (int i = 0; i < n_ranges; ++i)
|
||||||
// fprintf(stderr, "Stars.cpp: Batch #%d - %d stars @ %d\n", i,
|
// printLog("Stars.cpp: Batch #%d - %d stars @ %d\n", i,
|
||||||
// _arrBatchOffs[i], _arrBatchCount[i]);
|
// _arrBatchOffs[i], _arrBatchCount[i]);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
|
|
||||||
#include "AvatarData.h"
|
#include "AvatarData.h"
|
||||||
|
#include "avatars_Log.h"
|
||||||
|
|
||||||
|
using avatars_lib::printLog;
|
||||||
|
|
||||||
|
|
||||||
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
|
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
|
||||||
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
|
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
|
||||||
|
@ -58,13 +62,9 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
||||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
|
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
|
||||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
|
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
|
||||||
|
|
||||||
//printf( "_bodyYaw = %f", _bodyYaw );
|
|
||||||
|
|
||||||
memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3);
|
memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3);
|
||||||
destinationBuffer += sizeof(float) * 3;
|
destinationBuffer += sizeof(float) * 3;
|
||||||
|
|
||||||
std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n";
|
|
||||||
|
|
||||||
return destinationBuffer - bufferStart;
|
return destinationBuffer - bufferStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +83,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3);
|
memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3);
|
||||||
sourceBuffer += sizeof(float) * 3;
|
sourceBuffer += sizeof(float) * 3;
|
||||||
|
|
||||||
//printf( "_bodyYaw = %f", _bodyYaw );
|
//printLog( "_bodyYaw = %f", _bodyYaw );
|
||||||
|
|
||||||
//std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n";
|
|
||||||
//std::cout << _bodyPosition.x << ", " << _bodyPosition.y << ", " << _bodyPosition.z << "\n";
|
|
||||||
|
|
||||||
|
|
||||||
|
//printLog("%f, %f, %f\n", _handPosition.x, _handPosition.y, _handPosition.z);
|
||||||
|
//printLog("%f, %f, %f\n", _bodyPosition.x, _bodyPosition.y, _bodyPosition.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 AvatarData::getBodyPosition() {
|
glm::vec3 AvatarData::getBodyPosition() {
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __hifi__AvatarData__
|
#ifndef __hifi__AvatarData__
|
||||||
#define __hifi__AvatarData__
|
#define __hifi__AvatarData__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <AgentData.h>
|
#include <AgentData.h>
|
||||||
|
|
|
@ -7,13 +7,19 @@
|
||||||
|
|
||||||
#include "Orientation.h"
|
#include "Orientation.h"
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
#include "avatars_Log.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
//#include "Util.h"
|
//#include "Util.h"
|
||||||
|
|
||||||
|
using avatars_lib::printLog;
|
||||||
|
|
||||||
// XXXBHG - this test has not yet been reworked to match the correct vector orientation
|
// XXXBHG - this test has not yet been reworked to match the correct vector orientation
|
||||||
// of the coordinate system, so don't use it for now.
|
// of the coordinate system, so don't use it for now.
|
||||||
|
//
|
||||||
|
// tosh - yep, I noticed... :-)
|
||||||
|
//
|
||||||
static bool testingForNormalizationAndOrthogonality = false;
|
static bool testingForNormalizationAndOrthogonality = false;
|
||||||
|
|
||||||
Orientation::Orientation() {
|
Orientation::Orientation() {
|
||||||
|
@ -110,7 +116,7 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
|
||||||
|
|
||||||
if (( rightLength > 1.0f + epsilon )
|
if (( rightLength > 1.0f + epsilon )
|
||||||
|| ( rightLength < 1.0f - epsilon )) {
|
|| ( rightLength < 1.0f - epsilon )) {
|
||||||
printf( "Error in Orientation class: right direction length is %f \n", rightLength );
|
printLog( "Error in Orientation class: right direction length is %f \n", rightLength );
|
||||||
}
|
}
|
||||||
assert ( rightLength > 1.0f - epsilon );
|
assert ( rightLength > 1.0f - epsilon );
|
||||||
assert ( rightLength < 1.0f + epsilon );
|
assert ( rightLength < 1.0f + epsilon );
|
||||||
|
@ -118,7 +124,7 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
|
||||||
|
|
||||||
if (( upLength > 1.0f + epsilon )
|
if (( upLength > 1.0f + epsilon )
|
||||||
|| ( upLength < 1.0f - epsilon )) {
|
|| ( upLength < 1.0f - epsilon )) {
|
||||||
printf( "Error in Orientation class: up direction length is %f \n", upLength );
|
printLog( "Error in Orientation class: up direction length is %f \n", upLength );
|
||||||
}
|
}
|
||||||
assert ( upLength > 1.0f - epsilon );
|
assert ( upLength > 1.0f - epsilon );
|
||||||
assert ( upLength < 1.0f + epsilon );
|
assert ( upLength < 1.0f + epsilon );
|
||||||
|
@ -126,7 +132,7 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
|
||||||
|
|
||||||
if (( frontLength > 1.0f + epsilon )
|
if (( frontLength > 1.0f + epsilon )
|
||||||
|| ( frontLength < 1.0f - epsilon )) {
|
|| ( frontLength < 1.0f - epsilon )) {
|
||||||
printf( "Error in Orientation class: front direction length is %f \n", frontLength );
|
printLog( "Error in Orientation class: front direction length is %f \n", frontLength );
|
||||||
}
|
}
|
||||||
assert ( frontLength > 1.0f - epsilon );
|
assert ( frontLength > 1.0f - epsilon );
|
||||||
assert ( frontLength < 1.0f + epsilon );
|
assert ( frontLength < 1.0f + epsilon );
|
||||||
|
@ -143,22 +149,22 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) {
|
||||||
|
|
||||||
|
|
||||||
if ( rightDiff > epsilon ) {
|
if ( rightDiff > epsilon ) {
|
||||||
printf( "Error in Orientation class: right direction not orthogonal to up and/or front. " );
|
printLog( "Error in Orientation class: right direction not orthogonal to up and/or front. " );
|
||||||
printf( "The tested cross of up and front is off by %f \n", rightDiff );
|
printLog( "The tested cross of up and front is off by %f \n", rightDiff );
|
||||||
}
|
}
|
||||||
assert ( rightDiff < epsilon );
|
assert ( rightDiff < epsilon );
|
||||||
|
|
||||||
|
|
||||||
if ( upDiff > epsilon ) {
|
if ( upDiff > epsilon ) {
|
||||||
printf( "Error in Orientation class: up direction not orthogonal to front and/or right. " );
|
printLog( "Error in Orientation class: up direction not orthogonal to front and/or right. " );
|
||||||
printf( "The tested cross of front and right is off by %f \n", upDiff );
|
printLog( "The tested cross of front and right is off by %f \n", upDiff );
|
||||||
}
|
}
|
||||||
assert ( upDiff < epsilon );
|
assert ( upDiff < epsilon );
|
||||||
|
|
||||||
|
|
||||||
if ( frontDiff > epsilon ) {
|
if ( frontDiff > epsilon ) {
|
||||||
printf( "Error in Orientation class: front direction not orthogonal to right and/or up. " );
|
printLog( "Error in Orientation class: front direction not orthogonal to right and/or up. " );
|
||||||
printf( "The tested cross of right and up is off by %f \n", frontDiff );
|
printLog( "The tested cross of right and up is off by %f \n", frontDiff );
|
||||||
}
|
}
|
||||||
assert ( frontDiff < epsilon );
|
assert ( frontDiff < epsilon );
|
||||||
}
|
}
|
||||||
|
|
17
libraries/avatars/src/avatars_Log.cpp
Normal file
17
libraries/avatars/src/avatars_Log.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// avatars_Log.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
namespace avatars_lib {
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int (* printLog)(char const*, ...) = & printf;
|
||||||
|
}
|
20
libraries/avatars/src/avatars_Log.h
Normal file
20
libraries/avatars/src/avatars_Log.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// avatars_Log.h
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __hifi__avatars_Log__
|
||||||
|
#define __hifi__avatars_Log__
|
||||||
|
|
||||||
|
namespace avatars_lib {
|
||||||
|
|
||||||
|
// variable that can be set from outside to redirect the log output
|
||||||
|
// of this library
|
||||||
|
extern int (* printLog)(char const*, ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__avatars_Log__) */
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Agent.h"
|
#include "Agent.h"
|
||||||
#include "AgentTypes.h"
|
#include "AgentTypes.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include "shared_Log.h"
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using shared_lib::printLog;
|
||||||
|
|
||||||
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) {
|
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) {
|
||||||
publicSocket = new sockaddr;
|
publicSocket = new sockaddr;
|
||||||
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
|
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
|
||||||
|
@ -208,6 +211,16 @@ bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, cha
|
||||||
&& socketMatch(localSocket, otherLocalSocket);
|
&& socketMatch(localSocket, otherLocalSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Agent::printLog(Agent const& agent) {
|
||||||
|
|
||||||
|
sockaddr_in *agentPublicSocket = (sockaddr_in *) agent.publicSocket;
|
||||||
|
sockaddr_in *agentLocalSocket = (sockaddr_in *) agent.localSocket;
|
||||||
|
|
||||||
|
::printLog("T: %s (%c) PA: %s:%d LA: %s:%d\n", agent.getTypeName(), agent.type,
|
||||||
|
inet_ntoa(agentPublicSocket->sin_addr), ntohs(agentPublicSocket->sin_port),
|
||||||
|
inet_ntoa(agentLocalSocket->sin_addr), ntohs(agentLocalSocket->sin_port));
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Agent* agent) {
|
std::ostream& operator<<(std::ostream& os, const Agent* agent) {
|
||||||
sockaddr_in *agentPublicSocket = (sockaddr_in *)agent->publicSocket;
|
sockaddr_in *agentPublicSocket = (sockaddr_in *)agent->publicSocket;
|
||||||
sockaddr_in *agentLocalSocket = (sockaddr_in *)agent->localSocket;
|
sockaddr_in *agentLocalSocket = (sockaddr_in *)agent->localSocket;
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#ifndef __hifi__Agent__
|
#ifndef __hifi__Agent__
|
||||||
#define __hifi__Agent__
|
#define __hifi__Agent__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <ostream>
|
||||||
#include "AgentData.h"
|
#include "AgentData.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -50,6 +50,7 @@ public:
|
||||||
AgentData* getLinkedData();
|
AgentData* getLinkedData();
|
||||||
void setLinkedData(AgentData *newData);
|
void setLinkedData(AgentData *newData);
|
||||||
|
|
||||||
|
static void printLog(Agent const&);
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Agent* agent);
|
friend std::ostream& operator<<(std::ostream& os, const Agent* agent);
|
||||||
private:
|
private:
|
||||||
void swap(Agent &first, Agent &second);
|
void swap(Agent &first, Agent &second);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "AgentTypes.h"
|
#include "AgentTypes.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "Syssocket.h"
|
#include "Syssocket.h"
|
||||||
|
@ -21,6 +22,8 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using shared_lib::printLog;
|
||||||
|
|
||||||
const char * SOLO_AGENT_TYPES_STRING = "MV";
|
const char * SOLO_AGENT_TYPES_STRING = "MV";
|
||||||
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
|
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
|
||||||
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
|
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
|
||||||
|
@ -37,7 +40,7 @@ AgentList* AgentList::createInstance(char ownerType, unsigned int socketListenPo
|
||||||
if (_sharedInstance == NULL) {
|
if (_sharedInstance == NULL) {
|
||||||
_sharedInstance = new AgentList(ownerType, socketListenPort);
|
_sharedInstance = new AgentList(ownerType, socketListenPort);
|
||||||
} else {
|
} else {
|
||||||
printf("AgentList createInstance called with existing instance.\n");
|
printLog("AgentList createInstance called with existing instance.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sharedInstance;
|
return _sharedInstance;
|
||||||
|
@ -45,7 +48,7 @@ AgentList* AgentList::createInstance(char ownerType, unsigned int socketListenPo
|
||||||
|
|
||||||
AgentList* AgentList::getInstance() {
|
AgentList* AgentList::getInstance() {
|
||||||
if (_sharedInstance == NULL) {
|
if (_sharedInstance == NULL) {
|
||||||
printf("AgentList getInstance called before call to createInstance. Returning NULL pointer.\n");
|
printLog("AgentList getInstance called before call to createInstance. Returning NULL pointer.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sharedInstance;
|
return _sharedInstance;
|
||||||
|
@ -237,7 +240,8 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
newAgent.activatePublicSocket();
|
newAgent.activatePublicSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Added agent - " << &newAgent << "\n";
|
printLog("Added agent - ");
|
||||||
|
Agent::printLog(newAgent);
|
||||||
|
|
||||||
pthread_mutex_lock(&vectorChangeMutex);
|
pthread_mutex_lock(&vectorChangeMutex);
|
||||||
agents.push_back(newAgent);
|
agents.push_back(newAgent);
|
||||||
|
@ -336,7 +340,8 @@ void *removeSilentAgents(void *args) {
|
||||||
&& agent->getType() != AGENT_TYPE_VOXEL
|
&& agent->getType() != AGENT_TYPE_VOXEL
|
||||||
&& pthread_mutex_trylock(agentDeleteMutex) == 0) {
|
&& pthread_mutex_trylock(agentDeleteMutex) == 0) {
|
||||||
|
|
||||||
std::cout << "Killing agent " << &(*agent) << "\n";
|
printLog("Killing agent - ");
|
||||||
|
Agent::printLog(*agent);
|
||||||
|
|
||||||
// make sure the vector isn't currently adding an agent
|
// make sure the vector isn't currently adding an agent
|
||||||
pthread_mutex_lock(&vectorChangeMutex);
|
pthread_mutex_lock(&vectorChangeMutex);
|
||||||
|
@ -390,12 +395,12 @@ void *checkInWithDomainServer(void *args) {
|
||||||
sockaddr_in tempAddress;
|
sockaddr_in tempAddress;
|
||||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
||||||
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
|
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
|
||||||
printf("Domain server: %s \n", DOMAIN_HOSTNAME);
|
printLog("Domain server: %s \n", DOMAIN_HOSTNAME);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failed lookup domainserver\n");
|
printLog("Failed lookup domainserver\n");
|
||||||
}
|
}
|
||||||
} else printf("Using static domainserver IP: %s\n", DOMAIN_IP);
|
} else printLog("Using static domainserver IP: %s\n", DOMAIN_IP);
|
||||||
|
|
||||||
|
|
||||||
while (!domainServerCheckinStopFlag) {
|
while (!domainServerCheckinStopFlag) {
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
#ifndef __hifi__AgentList__
|
#ifndef __hifi__AgentList__
|
||||||
#define __hifi__AgentList__
|
#define __hifi__AgentList__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "Agent.h"
|
#include "Agent.h"
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#ifndef __interface__AudioRingBuffer__
|
#ifndef __interface__AudioRingBuffer__
|
||||||
#define __interface__AudioRingBuffer__
|
#define __interface__AudioRingBuffer__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "AgentData.h"
|
#include "AgentData.h"
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
//private:
|
//private:
|
||||||
// long int currentCount;
|
// long int currentCount;
|
||||||
|
@ -98,7 +98,7 @@ void CounterStatHistory::recordSample(double thisTime, long thisCount) {
|
||||||
this->currentTime = thisTime;
|
this->currentTime = thisTime;
|
||||||
this->currentDelta = thisDelta;
|
this->currentDelta = thisDelta;
|
||||||
|
|
||||||
//printf("CounterStatHistory[%s]::recordSample(thisTime %lf, thisCount= %ld)\n",this->name.c_str(),thisTime,thisCount);
|
//printLog("CounterStatHistory[%s]::recordSample(thisTime %lf, thisCount= %ld)\n",this->name.c_str(),thisTime,thisCount);
|
||||||
|
|
||||||
// if more than 1/10th of a second has passed, then record
|
// if more than 1/10th of a second has passed, then record
|
||||||
// things in our rolling history
|
// things in our rolling history
|
||||||
|
@ -115,7 +115,7 @@ void CounterStatHistory::recordSample(double thisTime, long thisCount) {
|
||||||
this->timeSamples[this->sampleAt]=thisTime;
|
this->timeSamples[this->sampleAt]=thisTime;
|
||||||
this->deltaSamples[this->sampleAt]=thisDelta;
|
this->deltaSamples[this->sampleAt]=thisDelta;
|
||||||
|
|
||||||
//printf("CounterStatHistory[%s]::recordSample() ACTUALLY RECORDING IT sampleAt=%d thisTime %lf, thisCount= %ld)\n",this->name.c_str(),this->sampleAt,thisTime,thisCount);
|
//printLog("CounterStatHistory[%s]::recordSample() ACTUALLY RECORDING IT sampleAt=%d thisTime %lf, thisCount= %ld)\n",this->name.c_str(),this->sampleAt,thisTime,thisCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
|
using shared_lib::printLog;
|
||||||
|
|
||||||
// Static class members initialization here!
|
// Static class members initialization here!
|
||||||
std::map<std::string,PerfStatHistory,std::less<std::string> > PerfStat::groupHistoryMap;
|
std::map<std::string,PerfStatHistory,std::less<std::string> > PerfStat::groupHistoryMap;
|
||||||
bool PerfStat::wantDebugOut = false;
|
bool PerfStat::wantDebugOut = false;
|
||||||
|
@ -55,7 +59,7 @@ PerfStat::~PerfStat() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantDebugOut) {
|
if (wantDebugOut) {
|
||||||
printf("PerfStats: %s elapsed:%f average:%lf count:%ld total:%lf ut:%d us:%d ue:%d t:%ld s:%ld e:%ld\n",
|
printLog("PerfStats: %s elapsed:%f average:%lf count:%ld total:%lf ut:%d us:%d ue:%d t:%ld s:%ld e:%ld\n",
|
||||||
this->group.c_str(),elapsed,average,count,totalTime,
|
this->group.c_str(),elapsed,average,count,totalTime,
|
||||||
(end.tv_usec-start.tv_usec),start.tv_usec,end.tv_usec,
|
(end.tv_usec-start.tv_usec),start.tv_usec,end.tv_usec,
|
||||||
(end.tv_sec-start.tv_sec),start.tv_sec,end.tv_sec
|
(end.tv_sec-start.tv_sec),start.tv_sec,end.tv_sec
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "Syssocket.h"
|
#include "Syssocket.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "shared_Log.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
#include "OctalCode.h"
|
#include "OctalCode.h"
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using shared_lib::printLog;
|
||||||
|
|
||||||
double usecTimestamp(timeval *time) {
|
double usecTimestamp(timeval *time) {
|
||||||
return (time->tv_sec * 1000000.0 + time->tv_usec);
|
return (time->tv_sec * 1000000.0 + time->tv_usec);
|
||||||
}
|
}
|
||||||
|
@ -50,13 +53,13 @@ bool randomBoolean() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void outputBits(unsigned char byte) {
|
void outputBits(unsigned char byte) {
|
||||||
printf("%d: ", byte);
|
printLog("%d: ", byte);
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
printf("%d", byte >> (7 - i) & 1);
|
printLog("%d", byte >> (7 - i) & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printLog("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int numberOfOnes(unsigned char byte) {
|
int numberOfOnes(unsigned char byte) {
|
||||||
|
@ -329,14 +332,14 @@ void printVoxelCode(unsigned char* voxelCode) {
|
||||||
unsigned int voxelSizeInOctets = (voxelSizeInBits/3);
|
unsigned int voxelSizeInOctets = (voxelSizeInBits/3);
|
||||||
unsigned int voxelBufferSize = voxelSizeInBytes+1+3; // 1 for size, 3 for color
|
unsigned int voxelBufferSize = voxelSizeInBytes+1+3; // 1 for size, 3 for color
|
||||||
|
|
||||||
printf("octets=%d\n",octets);
|
printLog("octets=%d\n",octets);
|
||||||
printf("voxelSizeInBits=%d\n",voxelSizeInBits);
|
printLog("voxelSizeInBits=%d\n",voxelSizeInBits);
|
||||||
printf("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
printLog("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
||||||
printf("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
printLog("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
||||||
printf("voxelBufferSize=%d\n",voxelBufferSize);
|
printLog("voxelBufferSize=%d\n",voxelBufferSize);
|
||||||
|
|
||||||
for(int i=0;i<voxelBufferSize;i++) {
|
for(int i=0;i<voxelBufferSize;i++) {
|
||||||
printf("i=%d ",i);
|
printLog("i=%d ",i);
|
||||||
outputBits(voxelCode[i]);
|
outputBits(voxelCode[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __hifi__StdDev__
|
#ifndef __hifi__StdDev__
|
||||||
#define __hifi__StdDev__
|
#define __hifi__StdDev__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class StDev {
|
class StDev {
|
||||||
public:
|
public:
|
||||||
StDev();
|
StDev();
|
||||||
|
|
|
@ -18,8 +18,13 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
|
using shared_lib::printLog;
|
||||||
|
|
||||||
sockaddr_in destSockaddr, senderAddress;
|
sockaddr_in destSockaddr, senderAddress;
|
||||||
|
|
||||||
bool socketMatch(sockaddr *first, sockaddr *second) {
|
bool socketMatch(sockaddr *first, sockaddr *second) {
|
||||||
|
@ -104,7 +109,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
||||||
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
if (handle <= 0) {
|
if (handle <= 0) {
|
||||||
printf("Failed to create socket.\n");
|
printLog("Failed to create socket.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +122,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
||||||
bind_address.sin_port = htons((uint16_t) listeningPort);
|
bind_address.sin_port = htons((uint16_t) listeningPort);
|
||||||
|
|
||||||
if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) {
|
if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) {
|
||||||
printf("Failed to bind socket to port %d.\n", listeningPort);
|
printLog("Failed to bind socket to port %d.\n", listeningPort);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +132,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
||||||
tv.tv_usec = 500000;
|
tv.tv_usec = 500000;
|
||||||
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
||||||
|
|
||||||
printf("Created UDP socket listening on port %d.\n", listeningPort);
|
printLog("Created UDP socket listening on port %d.\n", listeningPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPSocket::~UDPSocket() {
|
UDPSocket::~UDPSocket() {
|
||||||
|
@ -196,7 +201,7 @@ int UDPSocket::send(sockaddr *destAddress, const void *data, size_t byteLength)
|
||||||
0, (sockaddr *) destAddress, sizeof(sockaddr_in));
|
0, (sockaddr *) destAddress, sizeof(sockaddr_in));
|
||||||
|
|
||||||
if (sent_bytes != byteLength) {
|
if (sent_bytes != byteLength) {
|
||||||
printf("Failed to send packet: %s\n", strerror(errno));
|
printLog("Failed to send packet: %s\n", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __interface__UDPSocket__
|
#ifndef __interface__UDPSocket__
|
||||||
#define __interface__UDPSocket__
|
#define __interface__UDPSocket__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "Syssocket.h"
|
#include "Syssocket.h"
|
||||||
#else
|
#else
|
||||||
|
|
17
libraries/shared/src/shared_Log.cpp
Normal file
17
libraries/shared/src/shared_Log.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// shared_Log.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "shared_Log.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
namespace shared_lib {
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int (* printLog)(char const*, ...) = & printf;
|
||||||
|
}
|
20
libraries/shared/src/shared_Log.h
Normal file
20
libraries/shared/src/shared_Log.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// shared_Log.h
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __hifi__shared_Log__
|
||||||
|
#define __hifi__shared_Log__
|
||||||
|
|
||||||
|
namespace shared_lib {
|
||||||
|
|
||||||
|
// variable that can be set from outside to redirect the log output
|
||||||
|
// of this library
|
||||||
|
extern int (* printLog)(char const*, ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__shared_Log__) */
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "MarkerNode.h"
|
#include "MarkerNode.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
MarkerNode::MarkerNode() {
|
MarkerNode::MarkerNode() {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __hifi__MarkerNode__
|
#ifndef __hifi__MarkerNode__
|
||||||
#define __hifi__MarkerNode__
|
#define __hifi__MarkerNode__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class MarkerNode {
|
class MarkerNode {
|
||||||
public:
|
public:
|
||||||
MarkerNode();
|
MarkerNode();
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include "Plane.h"
|
#include "Plane.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "voxels_Log.h"
|
||||||
|
|
||||||
|
using voxels_lib::printLog;
|
||||||
|
|
||||||
// These are some useful utilities that vec3 is missing
|
// These are some useful utilities that vec3 is missing
|
||||||
float vec3_length(const glm::vec3& v) {
|
float vec3_length(const glm::vec3& v) {
|
||||||
return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
|
return((float)sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
|
||||||
|
@ -79,5 +83,5 @@ float Plane::distance(const glm::vec3 &p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plane::print() {
|
void Plane::print() {
|
||||||
//printf("Plane(");normal.print();printf("# %f)",d);
|
//printLog("Plane(");normal.print();printLog("# %f)",d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "ViewFrustum.h"
|
#include "ViewFrustum.h"
|
||||||
|
#include "voxels_Log.h"
|
||||||
|
|
||||||
|
using voxels_lib::printLog;
|
||||||
|
|
||||||
ViewFrustum::ViewFrustum() :
|
ViewFrustum::ViewFrustum() :
|
||||||
_position(glm::vec3(0,0,0)),
|
_position(glm::vec3(0,0,0)),
|
||||||
|
@ -95,39 +98,39 @@ void ViewFrustum::calculate() {
|
||||||
|
|
||||||
void ViewFrustum::dump() {
|
void ViewFrustum::dump() {
|
||||||
|
|
||||||
printf("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z);
|
printLog("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z);
|
||||||
printf("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z);
|
printLog("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z);
|
||||||
printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z);
|
printLog("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z);
|
||||||
printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z);
|
printLog("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z);
|
||||||
|
|
||||||
printf("farDist=%f\n", this->_farClip);
|
printLog("farDist=%f\n", this->_farClip);
|
||||||
printf("farHeight=%f\n", this->_farHeight);
|
printLog("farHeight=%f\n", this->_farHeight);
|
||||||
printf("farWidth=%f\n", this->_farWidth);
|
printLog("farWidth=%f\n", this->_farWidth);
|
||||||
|
|
||||||
printf("nearDist=%f\n", this->_nearClip);
|
printLog("nearDist=%f\n", this->_nearClip);
|
||||||
printf("nearHeight=%f\n", this->_nearHeight);
|
printLog("nearHeight=%f\n", this->_nearHeight);
|
||||||
printf("nearWidth=%f\n", this->_nearWidth);
|
printLog("nearWidth=%f\n", this->_nearWidth);
|
||||||
|
|
||||||
printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",
|
printLog("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n",
|
||||||
this->_farCenter.x, this->_farCenter.y, this->_farCenter.z);
|
this->_farCenter.x, this->_farCenter.y, this->_farCenter.z);
|
||||||
printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",
|
printLog("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n",
|
||||||
this->_farTopLeft.x, this->_farTopLeft.y, this->_farTopLeft.z);
|
this->_farTopLeft.x, this->_farTopLeft.y, this->_farTopLeft.z);
|
||||||
printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",
|
printLog("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n",
|
||||||
this->_farTopRight.x, this->_farTopRight.y, this->_farTopRight.z);
|
this->_farTopRight.x, this->_farTopRight.y, this->_farTopRight.z);
|
||||||
printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",
|
printLog("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n",
|
||||||
this->_farBottomLeft.x, this->_farBottomLeft.y, this->_farBottomLeft.z);
|
this->_farBottomLeft.x, this->_farBottomLeft.y, this->_farBottomLeft.z);
|
||||||
printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",
|
printLog("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n",
|
||||||
this->_farBottomRight.x, this->_farBottomRight.y, this->_farBottomRight.z);
|
this->_farBottomRight.x, this->_farBottomRight.y, this->_farBottomRight.z);
|
||||||
|
|
||||||
printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",
|
printLog("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n",
|
||||||
this->_nearCenter.x, this->_nearCenter.y, this->_nearCenter.z);
|
this->_nearCenter.x, this->_nearCenter.y, this->_nearCenter.z);
|
||||||
printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",
|
printLog("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n",
|
||||||
this->_nearTopLeft.x, this->_nearTopLeft.y, this->_nearTopLeft.z);
|
this->_nearTopLeft.x, this->_nearTopLeft.y, this->_nearTopLeft.z);
|
||||||
printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",
|
printLog("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n",
|
||||||
this->_nearTopRight.x, this->_nearTopRight.y, this->_nearTopRight.z);
|
this->_nearTopRight.x, this->_nearTopRight.y, this->_nearTopRight.z);
|
||||||
printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",
|
printLog("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n",
|
||||||
this->_nearBottomLeft.x, this->_nearBottomLeft.y, this->_nearBottomLeft.z);
|
this->_nearBottomLeft.x, this->_nearBottomLeft.y, this->_nearBottomLeft.z);
|
||||||
printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",
|
printLog("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n",
|
||||||
this->_nearBottomRight.x, this->_nearBottomRight.y, this->_nearBottomRight.z);
|
this->_nearBottomRight.x, this->_nearBottomRight.y, this->_nearBottomRight.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,12 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
//#include "voxels_Log.h"
|
||||||
#include "VoxelNode.h"
|
#include "VoxelNode.h"
|
||||||
#include "OctalCode.h"
|
#include "OctalCode.h"
|
||||||
|
|
||||||
|
// using voxels_lib::printLog;
|
||||||
|
|
||||||
VoxelNode::VoxelNode() {
|
VoxelNode::VoxelNode() {
|
||||||
octalCode = NULL;
|
octalCode = NULL;
|
||||||
|
|
||||||
|
@ -76,7 +79,7 @@ bool VoxelNode::collapseIdenticalLeaves() {
|
||||||
// if no child, or child doesn't have a color
|
// if no child, or child doesn't have a color
|
||||||
if (children[i] == NULL || children[i]->color[3] != 1) {
|
if (children[i] == NULL || children[i]->color[3] != 1) {
|
||||||
allChildrenMatch=false;
|
allChildrenMatch=false;
|
||||||
//printf("SADNESS child missing or not colored! i=%d\n",i);
|
//printLog("SADNESS child missing or not colored! i=%d\n",i);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
|
@ -92,7 +95,7 @@ bool VoxelNode::collapseIdenticalLeaves() {
|
||||||
|
|
||||||
|
|
||||||
if (allChildrenMatch) {
|
if (allChildrenMatch) {
|
||||||
//printf("allChildrenMatch: pruning tree\n");
|
//printLog("allChildrenMatch: pruning tree\n");
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
delete children[i]; // delete all the child nodes
|
delete children[i]; // delete all the child nodes
|
||||||
children[i]=NULL; // set it to NULL
|
children[i]=NULL; // set it to NULL
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#ifndef __hifi__VoxelNode__
|
#ifndef __hifi__VoxelNode__
|
||||||
#define __hifi__VoxelNode__
|
#define __hifi__VoxelNode__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class VoxelNode {
|
class VoxelNode {
|
||||||
public:
|
public:
|
||||||
VoxelNode();
|
VoxelNode();
|
||||||
|
|
|
@ -13,13 +13,14 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
#include "voxels_Log.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
#include "CounterStats.h"
|
#include "CounterStats.h"
|
||||||
#include "OctalCode.h"
|
#include "OctalCode.h"
|
||||||
#include "VoxelTree.h"
|
#include "VoxelTree.h"
|
||||||
#include <iostream> // to load voxels from file
|
|
||||||
#include <fstream> // to load voxels from file
|
#include <fstream> // to load voxels from file
|
||||||
|
|
||||||
|
using voxels_lib::printLog;
|
||||||
|
|
||||||
int boundaryDistanceForRenderLevel(unsigned int renderLevel) {
|
int boundaryDistanceForRenderLevel(unsigned int renderLevel) {
|
||||||
switch (renderLevel) {
|
switch (renderLevel) {
|
||||||
|
@ -416,7 +417,7 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer,
|
||||||
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
|
||||||
// XXXBHG: validate buffer is at least 4 bytes long? other guards??
|
// XXXBHG: validate buffer is at least 4 bytes long? other guards??
|
||||||
unsigned short int itemNumber = (*((unsigned short int*)&bitstream[1]));
|
unsigned short int itemNumber = (*((unsigned short int*)&bitstream[1]));
|
||||||
printf("processRemoveVoxelBitstream() receivedBytes=%d itemNumber=%d\n",bufferSizeBytes,itemNumber);
|
printLog("processRemoveVoxelBitstream() receivedBytes=%d itemNumber=%d\n",bufferSizeBytes,itemNumber);
|
||||||
int atByte = 3;
|
int atByte = 3;
|
||||||
unsigned char* pVoxelData = (unsigned char*)&bitstream[3];
|
unsigned char* pVoxelData = (unsigned char*)&bitstream[3];
|
||||||
while (atByte < bufferSizeBytes) {
|
while (atByte < bufferSizeBytes) {
|
||||||
|
@ -424,7 +425,7 @@ void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int buffe
|
||||||
int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color!
|
int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color!
|
||||||
|
|
||||||
float* vertices = firstVertexForCode(pVoxelData);
|
float* vertices = firstVertexForCode(pVoxelData);
|
||||||
printf("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
printLog("deleting voxel at: %f,%f,%f\n",vertices[0],vertices[1],vertices[2]);
|
||||||
delete []vertices;
|
delete []vertices;
|
||||||
|
|
||||||
deleteVoxelCodeFromTree(pVoxelData);
|
deleteVoxelCodeFromTree(pVoxelData);
|
||||||
|
@ -510,11 +511,11 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
|
||||||
|
|
||||||
int totalBytesRead = 0;
|
int totalBytesRead = 0;
|
||||||
if(file.is_open()) {
|
if(file.is_open()) {
|
||||||
printf("loading file...\n");
|
printLog("loading file...\n");
|
||||||
bool bail = false;
|
bool bail = false;
|
||||||
while (!file.eof() && !bail) {
|
while (!file.eof() && !bail) {
|
||||||
file.get(octets);
|
file.get(octets);
|
||||||
//printf("octets=%d...\n",octets);
|
//printLog("octets=%d...\n",octets);
|
||||||
totalBytesRead++;
|
totalBytesRead++;
|
||||||
lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1;
|
lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1;
|
||||||
unsigned char * voxelData = new unsigned char[lengthInBytes+1+3];
|
unsigned char * voxelData = new unsigned char[lengthInBytes+1+3];
|
||||||
|
@ -536,14 +537,14 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
|
||||||
file.get(colorRead);
|
file.get(colorRead);
|
||||||
blue = (unsigned char)colorRead;
|
blue = (unsigned char)colorRead;
|
||||||
|
|
||||||
printf("voxel color from file red:%d, green:%d, blue:%d \n",red,green,blue);
|
printLog("voxel color from file red:%d, green:%d, blue:%d \n",red,green,blue);
|
||||||
vCount++;
|
vCount++;
|
||||||
|
|
||||||
int colorRandomizer = wantColorRandomizer ? randIntInRange (-5, 5) : 0;
|
int colorRandomizer = wantColorRandomizer ? randIntInRange (-5, 5) : 0;
|
||||||
voxelData[lengthInBytes+1] = std::max(0,std::min(255,red + colorRandomizer));
|
voxelData[lengthInBytes+1] = std::max(0,std::min(255,red + colorRandomizer));
|
||||||
voxelData[lengthInBytes+2] = std::max(0,std::min(255,green + colorRandomizer));
|
voxelData[lengthInBytes+2] = std::max(0,std::min(255,green + colorRandomizer));
|
||||||
voxelData[lengthInBytes+3] = std::max(0,std::min(255,blue + colorRandomizer));
|
voxelData[lengthInBytes+3] = std::max(0,std::min(255,blue + colorRandomizer));
|
||||||
printf("voxel color after rand red:%d, green:%d, blue:%d\n",
|
printLog("voxel color after rand red:%d, green:%d, blue:%d\n",
|
||||||
voxelData[lengthInBytes+1], voxelData[lengthInBytes+2], voxelData[lengthInBytes+3]);
|
voxelData[lengthInBytes+1], voxelData[lengthInBytes+2], voxelData[lengthInBytes+3]);
|
||||||
|
|
||||||
//printVoxelCode(voxelData);
|
//printVoxelCode(voxelData);
|
||||||
|
@ -608,7 +609,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
|
||||||
// If you also iterate form the interior of the sphere to the radius, makeing
|
// If you also iterate form the interior of the sphere to the radius, makeing
|
||||||
// larger and larger sphere's you'd end up with a solid sphere. And lots of voxels!
|
// larger and larger sphere's you'd end up with a solid sphere. And lots of voxels!
|
||||||
for (; ri <= (r+(s/2.0)); ri+=s) {
|
for (; ri <= (r+(s/2.0)); ri+=s) {
|
||||||
//printf("radius: ri=%f ri+s=%f (r+(s/2.0))=%f\n",ri,ri+s,(r+(s/2.0)));
|
//printLog("radius: ri=%f ri+s=%f (r+(s/2.0))=%f\n",ri,ri+s,(r+(s/2.0)));
|
||||||
for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) {
|
for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) {
|
||||||
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
|
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
|
||||||
t++; // total voxels
|
t++; // total voxels
|
||||||
|
@ -622,7 +623,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
|
||||||
// only use our actual desired color on the outer edge, otherwise
|
// only use our actual desired color on the outer edge, otherwise
|
||||||
// use our "average" color
|
// use our "average" color
|
||||||
if (ri+(s*2.0)>=r) {
|
if (ri+(s*2.0)>=r) {
|
||||||
//printf("painting candy shell radius: ri=%f r=%f\n",ri,r);
|
//printLog("painting candy shell radius: ri=%f r=%f\n",ri,r);
|
||||||
red = wantColorRandomizer ? randomColorValue(165) : r1+((r2-r1)*gradient);
|
red = wantColorRandomizer ? randomColorValue(165) : r1+((r2-r1)*gradient);
|
||||||
green = wantColorRandomizer ? randomColorValue(165) : g1+((g2-g1)*gradient);
|
green = wantColorRandomizer ? randomColorValue(165) : g1+((g2-g1)*gradient);
|
||||||
blue = wantColorRandomizer ? randomColorValue(165) : b1+((b2-b1)*gradient);
|
blue = wantColorRandomizer ? randomColorValue(165) : b1+((b2-b1)*gradient);
|
||||||
|
@ -630,7 +631,7 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
|
||||||
|
|
||||||
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
||||||
this->readCodeColorBufferToTree(voxelData);
|
this->readCodeColorBufferToTree(voxelData);
|
||||||
//printf("voxel data for x:%f y:%f z:%f s:%f\n",x,y,z,s);
|
//printLog("voxel data for x:%f y:%f z:%f s:%f\n",x,y,z,s);
|
||||||
//printVoxelCode(voxelData);
|
//printVoxelCode(voxelData);
|
||||||
delete voxelData;
|
delete voxelData;
|
||||||
}
|
}
|
||||||
|
|
17
libraries/voxels/src/voxels_Log.cpp
Normal file
17
libraries/voxels/src/voxels_Log.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// voxels_Log.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "voxels_Log.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
namespace voxels_lib {
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int (* printLog)(char const*, ...) = & printf;
|
||||||
|
}
|
20
libraries/voxels/src/voxels_Log.h
Normal file
20
libraries/voxels/src/voxels_Log.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// voxels_Log.h
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Tobias Schwinger on 4/17/13.
|
||||||
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __hifi__voxels_Log__
|
||||||
|
#define __hifi__voxels_Log__
|
||||||
|
|
||||||
|
namespace voxels_lib {
|
||||||
|
|
||||||
|
// variable that can be set from outside to redirect the log output
|
||||||
|
// of this library
|
||||||
|
extern int (* printLog)(char const*, ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__voxels_Log__) */
|
||||||
|
|
Loading…
Reference in a new issue