Merge branch 'master' of https://github.com/worklist/hifi into render_voxels_optimization

This commit is contained in:
ZappoMan 2013-05-14 12:14:53 -07:00
commit a1902e3dc9
16 changed files with 3526 additions and 2334 deletions

View file

@ -6,31 +6,31 @@
#
# LIBOVR_FOUND - system found LibOVR
# LIBOVR_INCLUDE_DIRS - the LibOVR include directory
# LIBOVR_LIBRARY - Link this to use LibOVR
# LIBOVR_LIBRARIES - Link this to use LibOVR
#
# Created on 5/9/2013 by Stephen Birarda
# Copyright (c) 2013 High Fidelity
#
if (LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIRS)
if (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS)
# in cache already
set(LIBOVR_FOUND TRUE)
else (LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIRS)
set(LIBOVR_INCLUDE_DIRS ${LIBOVR_ROOT_DIR}/Include)
else (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS)
find_path(LIBOVR_INCLUDE_DIRS OVR.h ${LIBOVR_ROOT_DIR}/Include)
if (APPLE)
set(LIBOVR_LIBRARY ${LIBOVR_ROOT_DIR}/Lib/MacOS/libovr.a)
else (WIN32)
set(LIBOVR_LIBRARY ${LIBOVR_ROOT_DIR}/Lib/Win32/libovr.lib)
find_library(LIBOVR_LIBRARIES libovr.a ${LIBOVR_ROOT_DIR}/Lib/MacOS/)
elseif (WIN32)
find_library(LIBOVR_LIBRARIES libovr.lib ${LIBOVR_ROOT_DIR}/Lib/Win32/)
endif ()
if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARY)
if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES)
set(LIBOVR_FOUND TRUE)
endif (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARY)
endif (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES)
if (LIBOVR_FOUND)
if (NOT LibOVR_FIND_QUIETLY)
message(STATUS "Found LibOVR: ${LIBOVR_LIBRARY}")
message(STATUS "Found LibOVR: ${LIBOVR_LIBRARIES}")
endif (NOT LibOVR_FIND_QUIETLY)
else (LIBOVR_FOUND)
if (LibOVR_FIND_REQUIRED)
@ -38,7 +38,7 @@ else (LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIRS)
endif (LibOVR_FIND_REQUIRED)
endif (LIBOVR_FOUND)
# show the LIBOVR_INCLUDE_DIRS and LIBOVR_LIBRARY variables only in the advanced view
mark_as_advanced(LIBOVR_INCLUDE_DIRS LIBOVR_LIBRARY)
# show the LIBOVR_INCLUDE_DIRS and LIBOVR_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBOVR_INCLUDE_DIRS LIBOVR_LIBRARIES)
endif (LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIRS)
endif (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS)

View file

@ -6,34 +6,26 @@
#
# LODEPNG_FOUND - system has LODEPNG_FOUND
# LODEPNG_INCLUDE_DIRS - the LodePNG include directory
# LODEPNG_LIBRARY - Link these to use LodePNG
# LODEPNG_LIBRARIES- Link these to use LodePNG
#
# Copyright (c) 2013 Stephen Birarda <birarda@coffeeandpower.com>
#
if (LODEPNG_LIBRARY AND LODEPNG_INCLUDE_DIRS)
if (LODEPNG_LIBRARIES AND LODEPNG_INCLUDE_DIRS)
# in cache already
set(LODEPNG_FOUND TRUE)
else (LODEPNG_LIBRARY AND LODEPNG_INCLUDE_DIRS)
else (LODEPNG_LIBRARIES AND LODEPNG_INCLUDE_DIRS)
FIND_PATH(LODEPNG_INCLUDE_DIR "lodepng.h"
PATHS ${LODEPNG_ROOT_DIR})
find_path(LODEPNG_INCLUDE_DIRS lodepng.h ${LODEPNG_ROOT_DIR})
find_file(LODEPNG_LIBRARIES lodepng.cpp ${LODEPNG_ROOT_DIR})
set(LODEPNG_INCLUDE_DIRS
${LODEPNG_INCLUDE_DIR}
)
set(LODEPNG_LIBRARY
${LODEPNG_ROOT_DIR}/lodepng.cpp
)
if (LODEPNG_INCLUDE_DIRS AND LODEPNG_LIBRARY)
if (LODEPNG_INCLUDE_DIRS AND LODEPNG_LIBRARIES)
set(LODEPNG_FOUND TRUE)
endif (LODEPNG_INCLUDE_DIRS AND LODEPNG_LIBRARY)
endif (LODEPNG_INCLUDE_DIRS AND LODEPNG_LIBRARIES)
if (LODEPNG_FOUND)
if (NOT LodePNG_FIND_QUIETLY)
message(STATUS "Found LodePNG: ${LODEPNG_LIBRARY}")
message(STATUS "Found LodePNG: ${LODEPNG_LIBRARIES}")
endif (NOT LodePNG_FIND_QUIETLY)
else (LODEPNG_FOUND)
if (LodePNG_FIND_REQUIRED)
@ -41,7 +33,7 @@ else (LODEPNG_LIBRARY AND LODEPNG_INCLUDE_DIRS)
endif (LodePNG_FIND_REQUIRED)
endif (LODEPNG_FOUND)
# show the LODEPNG_INCLUDE_DIRS and LODEPNG_LIBRARY variables only in the advanced view
mark_as_advanced(LODEPNG_INCLUDE_DIRS LODEPNG_LIBRARY)
# show the LODEPNG_INCLUDE_DIRS and LODEPNG_LIBRARIES variables only in the advanced view
mark_as_advanced(LODEPNG_INCLUDE_DIRS LODEPNG_LIBRARIES)
endif (LODEPNG_LIBRARY AND LODEPNG_INCLUDE_DIRS)
endif (LODEPNG_LIBRARIES AND LODEPNG_INCLUDE_DIRS)

View file

@ -0,0 +1,44 @@
# Find the static PortAudio library
#
# You must provide a PORTAUDIO_ROOT_DIR which contains lib and include directories
#
# Once done this will define
#
# PORTAUDIO_FOUND - system found PortAudio
# PORTAUDIO_INCLUDE_DIRS - the PortAudio include directory
# PORTAUDIO_LIBRARIES - Link this to use PortAudio
#
# Created on 5/14/2013 by Stephen Birarda
# Copyright (c) 2013 High Fidelity
#
if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
# in cache already
set(PORTAUDIO_FOUND TRUE)
else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
find_path(PORTAUDIO_INCLUDE_DIRS portaudio.h ${PORTAUDIO_ROOT_DIR}/include)
if (APPLE)
find_library(PORTAUDIO_LIBRARIES libportaudio.a ${PORTAUDIO_ROOT_DIR}/lib/MacOS/)
elseif (UNIX)
find_library(PORTAUDIO_LIBRARIES libportaudio.a ${PORTAUDIO_ROOT_DIR}/lib/UNIX/)
endif ()
if (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES)
set(PORTAUDIO_FOUND TRUE)
endif (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES)
if (PORTAUDIO_FOUND)
if (NOT PortAudio_FIND_QUIETLY)
message(STATUS "Found PortAudio: ${PORTAUDIO_LIBRARIES}")
endif (NOT PortAudio_FIND_QUIETLY)
else (PORTAUDIO_FOUND)
if (PortAudio_FIND_REQUIRED)
message(FATAL_ERROR "Could not find PortAudio")
endif (PortAudio_FIND_REQUIRED)
endif (PORTAUDIO_FOUND)
# show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view
mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES)
endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)

View file

@ -10,7 +10,7 @@ project(${TARGET_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
set(LODEPNG_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/LodePNG)
set(LIBOVR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/LibOVR)
set(PORTAUDIO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
set(PORTAUDIO_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/portaudio)
if (APPLE)
set(GL_HEADERS "#include <GLUT/glut.h>\n#include <OpenGL/glext.h>")
@ -55,7 +55,7 @@ if (APPLE)
SET(INTERFACE_SRCS ${INTERFACE_SRCS} ${INTERFACE_RSRCS})
endif (APPLE)
find_package(Qt4 REQUIRED QtCore QtGui)
find_package(Qt4 REQUIRED QtCore QtGui QtOpenGL)
include(${QT_USE_FILE})
# run qt moc on qt-enabled headers
@ -109,7 +109,7 @@ if (APPLE)
${GLUT}
${OpenGL}
${IOKit}
${LIBOVR_LIBRARY}
${LIBOVR_LIBRARIES}
)
else (APPLE)
find_package(OpenGL REQUIRED)
@ -129,30 +129,12 @@ if (WIN32)
wsock32.lib
)
else (WIN32)
target_link_libraries(${TARGET_NAME} ${LODEPNG_LIBRARY})
# include PortAudio as external project
include(ExternalProject)
set(PORTAUDIO_PROJ_DIR external/portaudio)
ExternalProject_Add(
portaudio
PREFIX ${PORTAUDIO_PROJ_DIR}
BINARY_DIR ${PORTAUDIO_PROJ_DIR}/src/portaudio
URL ${PORTAUDIO_DIR}/pa_snapshot_020813.tgz
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix "${PROJECT_BINARY_DIR}/${PORTAUDIO_PROJ_DIR}"
BUILD_COMMAND make
)
# make PortAudio a dependency of the interface executable
add_dependencies(${TARGET_NAME} portaudio)
# include the PortAudio headers
ExternalProject_Get_Property(portaudio source_dir)
include_directories(${source_dir}/include)
target_link_libraries(${TARGET_NAME} ${LODEPNG_LIBRARIES})
# link the PortAudio library
ExternalProject_Get_Property(portaudio binary_dir)
target_link_libraries(${TARGET_NAME} ${binary_dir}/lib/.libs/libportaudio.a)
find_package(PortAudio REQUIRED)
include_directories(${PORTAUDIO_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${PORTAUDIO_LIBRARIES})
# link required libraries on UNIX
if (UNIX AND NOT APPLE)

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -9,16 +9,223 @@
#ifndef __interface__Application__
#define __interface__Application__
#include <pthread.h>
#include <time.h>
#include <QApplication>
#include <AgentList.h>
#ifndef _WIN32
#include "Audio.h"
#endif
#include "Camera.h"
#include "Environment.h"
#include "HandControl.h"
#include "SerialInterface.h"
#include "Stars.h"
#include "ViewFrustum.h"
#include "VoxelSystem.h"
#include "ui/ChatEntry.h"
class QAction;
class QGLWidget;
class QKeyEvent;
class QMainWindow;
class QMouseEvent;
class QWheelEvent;
class Agent;
class ProgramObject;
class Application : public QApplication {
Q_OBJECT
public:
Application(int& argc, char** argv);
public slots:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
private slots:
void timer();
void idle();
void terminate();
void pair();
void setHead(bool head);
void setNoise(bool noise);
void setFullscreen(bool fullscreen);
void setRenderFirstPerson(bool firstPerson);
void setOculus(bool oculus);
void setFrustumOffset(bool frustumOffset);
void cycleFrustumRenderMode();
void setRenderWarnings(bool renderWarnings);
void doKillLocalVoxels();
void doRandomizeVoxelColors();
void doFalseRandomizeVoxelColors();
void doFalseRandomizeEveryOtherVoxelColors();
void doFalseColorizeByDistance();
void doFalseColorizeInView();
void doTrueVoxelColors();
void doTreeStats();
void setWantsMonochrome(bool wantsMonochrome);
void setWantsResIn(bool wantsResIn);
private:
void initMenu();
void updateFrustumRenderModeAction();
void initDisplay();
void init();
void updateAvatar(float deltaTime);
void loadViewFrustum(ViewFrustum& viewFrustum);
void displayOculus(Camera& whichCamera);
void displaySide(Camera& whichCamera);
void displayOverlay();
void displayStats();
void renderViewFrustum(ViewFrustum& viewFrustum);
void setupPaintingVoxel();
void shiftPaintingColor();
void addVoxelInFrontOfAvatar();
void addVoxelUnderCursor();
void deleteVoxelUnderCursor();
void resetSensors();
void setMenuShortcutsEnabled(bool enabled);
static void attachNewHeadToAgent(Agent *newAgent);
#ifndef _WIN32
static void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort);
#endif
static void* networkReceive(void* args);
QMainWindow* _window;
QGLWidget* _glWidget;
QAction* _lookingInMirror; // Are we currently rendering one's own head as if in mirror?
QAction* _gyroLook; // Whether to allow the gyro data from head to move your view
QAction* _renderVoxels; // Whether to render voxels
QAction* _renderStarsOn; // Whether to display the stars
QAction* _renderAtmosphereOn; // Whether to display the atmosphere
QAction* _renderAvatarsOn; // Whether to render avatars
QAction* _oculusOn; // Whether to configure the display for the Oculus Rift
QAction* _renderStatsOn; // Whether to show onscreen text overlay with stats
QAction* _logOn; // Whether to show on-screen log
QAction* _frustumOn; // Whether or not to display the debug view frustum
QAction* _viewFrustumFromOffset; // Whether or not to offset the view of the frustum
QAction* _cameraFrustum; // which frustum to look at
QAction* _frustumRenderModeAction;
SerialInterface _serialPort;
bool _displayLevels;
glm::vec3 _gravity;
// Frame Rate Measurement
int _frameCount;
float _fps;
timeval _applicationStartupTime;
timeval _timerStart, _timerEnd;
timeval _lastTimeIdle;
bool _justStarted;
Stars _stars;
VoxelSystem _voxels;
QByteArray _voxelsFilename;
bool _wantToKillLocalVoxels;
ViewFrustum _viewFrustum; // current state of view frustum, perspective, orientation, etc.
enum FrustumDrawMode { FRUSTUM_DRAW_MODE_ALL, FRUSTUM_DRAW_MODE_VECTORS, FRUSTUM_DRAW_MODE_PLANES,
FRUSTUM_DRAW_MODE_NEAR_PLANE, FRUSTUM_DRAW_MODE_FAR_PLANE, FRUSTUM_DRAW_MODE_COUNT };
FrustumDrawMode _frustumDrawingMode;
float _viewFrustumOffsetYaw; // the following variables control yaw, pitch, roll and distance form regular
float _viewFrustumOffsetPitch; // camera to the offset camera
float _viewFrustumOffsetRoll;
float _viewFrustumOffsetDistance;
float _viewFrustumOffsetUp;
float _mouseViewShiftYaw;
float _mouseViewShiftPitch;
Oscilloscope _audioScope;
Avatar _myAvatar; // The rendered avatar of oneself
Camera _myCamera; // My view onto the world
Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode
Environment _environment;
int _headMouseX, _headMouseY;
HandControl _handControl;
int _mouseX;
int _mouseY;
bool _mousePressed; // true if mouse has been pressed (clear when finished)
// The current mode for mouse interaction
enum MouseMode { NO_EDIT_MODE, ADD_VOXEL_MODE, DELETE_VOXEL_MODE, COLOR_VOXEL_MODE };
MouseMode _mouseMode;
VoxelDetail _mouseVoxel; // details of the voxel under the mouse cursor
float _mouseVoxelScale; // the scale for adding/removing voxels
bool _paintOn; // Whether to paint voxels as you fly around
unsigned char _dominantColor; // The dominant color of the voxel we're painting
VoxelDetail _paintingVoxel; // The voxel we're painting if we're painting
bool _perfStatsOn; // Do we want to display perfStats?
ChatEntry _chatEntry; // chat entry field
bool _chatEntryOn; // Whether to show the chat entry
GLuint _oculusTextureID; // The texture to which we render for Oculus distortion
ProgramObject* _oculusProgram; // The GLSL program containing the distortion shader
float _oculusDistortionScale; // Controls the Oculus field of view
int _textureLocation;
int _lensCenterLocation;
int _screenCenterLocation;
int _scaleLocation;
int _scaleInLocation;
int _hmdWarpParamLocation;
#ifndef _WIN32
Audio _audio;
#endif
bool _enableNetworkThread;
pthread_t _networkReceiveThread;
bool _stopNetworkReceiveThread;
unsigned char _incomingPacket[MAX_PACKET_SIZE];
int _packetCount;
int _packetsPerSecond;
int _bytesPerSecond;
int _bytesCount;
};
#endif /* defined(__interface__Application__) */

View file

@ -2,16 +2,7 @@
// SerialInterface.cpp
// 2012 by Philip Rosedale for High Fidelity Inc.
//
// Read interface data from the gyros/accelerometer board using SerialUSB
//
// Channels are received in the following order (integer 0-4096 based on voltage 0-3.3v)
//
// 0 - AIN 15: Pitch Gyro (nodding your head 'yes')
// 1 - AIN 16: Yaw Gyro (shaking your head 'no')
// 2 - AIN 17: Roll Gyro (looking quizzical, tilting your head)
// 3 - AIN 18: Lateral acceleration (moving from side-to-side in front of your monitor)
// 4 - AIN 19: Up/Down acceleration (sitting up/ducking in front of your monitor)
// 5 - AIN 20: Forward/Back acceleration (Toward or away from your monitor)
// Read interface data from the gyros/accelerometer Invensense board using the SerialUSB
//
#include "SerialInterface.h"
@ -22,14 +13,8 @@
#include <string>
#endif
const int MAX_BUFFER = 255;
char serialBuffer[MAX_BUFFER];
int serialBufferPos = 0;
const int ZERO_OFFSET = 2048;
const short NO_READ_MAXIMUM_MSECS = 3000;
const short SAMPLES_TO_DISCARD = 100; // Throw out the first few samples
const int GRAVITY_SAMPLES = 60; // Use the first samples to compute gravity vector
const int GRAVITY_SAMPLES = 60; // Use the first few samples to baseline values
const bool USING_INVENSENSE_MPU9150 = 1;
@ -51,7 +36,7 @@ void SerialInterface::pair() {
char *serialPortname = new char[100];
sprintf(serialPortname, "/dev/%s", entry->d_name);
initializePort(serialPortname, 115200);
initializePort(serialPortname);
delete [] serialPortname;
}
@ -63,7 +48,7 @@ void SerialInterface::pair() {
}
// connect to the serial port
void SerialInterface::initializePort(char* portname, int baud) {
void SerialInterface::initializePort(char* portname) {
#ifdef __APPLE__
_serialDescriptor = open(portname, O_RDWR | O_NOCTTY | O_NDELAY);
@ -72,35 +57,20 @@ void SerialInterface::initializePort(char* portname, int baud) {
if (_serialDescriptor == -1) {
printLog("Failed.\n");
return;
}
struct termios options;
tcgetattr(_serialDescriptor, &options);
switch(baud) {
case 9600: cfsetispeed(&options,B9600);
cfsetospeed(&options,B9600);
break;
case 19200: cfsetispeed(&options,B19200);
cfsetospeed(&options,B19200);
break;
case 38400: cfsetispeed(&options,B38400);
cfsetospeed(&options,B38400);
break;
case 115200: cfsetispeed(&options,B115200);
cfsetospeed(&options,B115200);
break;
default:cfsetispeed(&options,B9600);
cfsetospeed(&options,B9600);
break;
}
options.c_cflag |= (CLOCAL | CREAD);
struct termios options;
tcgetattr(_serialDescriptor, &options);
options.c_cflag |= (CLOCAL | CREAD | CS8);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
tcsetattr(_serialDescriptor, TCSANOW, &options);
cfsetispeed(&options,B115200);
cfsetospeed(&options,B115200);
if (USING_INVENSENSE_MPU9150) {
// block on invensense reads until there is data to read
int currentFlags = fcntl(_serialDescriptor, F_GETFL);
@ -140,11 +110,11 @@ void SerialInterface::renderLevels(int width, int height) {
const int LEVEL_CORNER_Y = 200;
// Draw the numeric degree/sec values from the gyros
sprintf(val, "Yaw %4.1f", _lastYawRate);
sprintf(val, "Yaw %4.1f", getLastYawRate());
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y, 0.10, 0, 1.0, 1, val, 0, 1, 0);
sprintf(val, "Pitch %4.1f", _lastPitchRate);
sprintf(val, "Pitch %4.1f", getLastPitchRate());
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 15, 0.10, 0, 1.0, 1, val, 0, 1, 0);
sprintf(val, "Roll %4.1f", _lastRollRate);
sprintf(val, "Roll %4.1f", getLastRollRate());
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 30, 0.10, 0, 1.0, 1, val, 0, 1, 0);
sprintf(val, "X %4.3f", _lastAccelX);
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 45, 0.10, 0, 1.0, 1, val, 0, 1, 0);
@ -161,11 +131,11 @@ void SerialInterface::renderLevels(int width, int height) {
glBegin(GL_LINES);
// Gyro rates
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 3);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastYawRate, LEVEL_CORNER_Y - 3);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastYawRate(), LEVEL_CORNER_Y - 3);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 12);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastPitchRate, LEVEL_CORNER_Y + 12);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastPitchRate(), LEVEL_CORNER_Y + 12);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 27);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRollRate, LEVEL_CORNER_Y + 27);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastRollRate(), LEVEL_CORNER_Y + 27);
// Acceleration
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 42);
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)((_lastAccelX - _gravity.x)* ACCEL_VIEW_SCALING),
@ -232,26 +202,33 @@ void SerialInterface::readData() {
convertHexToInt(sensorBuffer + 30, pitchRate);
// Convert the integer rates to floats
const float LSB_TO_DEGREES_PER_SECOND = 1.f / 16.4f; // From MPU-9150 register map, 2000 deg/sec.
const float PITCH_BIAS = 2.0; // Strangely, there is a small DC bias in the
// invensense pitch reading. Gravity?
const float LSB_TO_DEGREES_PER_SECOND = 1.f / 16.4f; // From MPU-9150 register map, 2000 deg/sec.
_lastRollRate = ((float) rollRate) * LSB_TO_DEGREES_PER_SECOND;
_lastYawRate = ((float) yawRate) * LSB_TO_DEGREES_PER_SECOND;
_lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND + PITCH_BIAS;
_lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND;
// Accumulate an initial reading for gravity
// Use a set of initial samples to compute gravity
if (totalSamples < GRAVITY_SAMPLES) {
_gravity.x += _lastAccelX;
_gravity.y += _lastAccelY;
_gravity.z += _lastAccelZ;
}
if (totalSamples == GRAVITY_SAMPLES) {
_gravity /= (float) totalSamples;
printLog("Gravity: %f\n", glm::length(_gravity));
}
// Accumulate a set of initial baseline readings for setting gravity
if (totalSamples == 0) {
_averageGyroRates[0] = _lastRollRate;
_averageGyroRates[1] = _lastYawRate;
_averageGyroRates[2] = _lastPitchRate;
_gravity.x = _lastAccelX;
_gravity.y = _lastAccelY;
_gravity.z = _lastAccelZ;
}
else if (totalSamples < GRAVITY_SAMPLES) {
_gravity = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _gravity +
1.f/(float)GRAVITY_SAMPLES * glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ);
_averageGyroRates[0] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[0] +
1.f/(float)GRAVITY_SAMPLES * _lastRollRate;
_averageGyroRates[1] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[1] +
1.f/(float)GRAVITY_SAMPLES * _lastYawRate;
_averageGyroRates[2] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[2] +
1.f/(float)GRAVITY_SAMPLES * _lastPitchRate;
}
totalSamples++;
}
@ -269,14 +246,17 @@ void SerialInterface::readData() {
#endif
}
void SerialInterface::resetSerial() {
#ifdef __APPLE__
active = false;
void SerialInterface::resetAverages() {
totalSamples = 0;
_gravity = glm::vec3(0, 0, 0);
_averageGyroRates = glm::vec3(0, 0, 0);
}
void SerialInterface::resetSerial() {
#ifdef __APPLE__
resetAverages();
active = false;
gettimeofday(&lastGoodRead, NULL);
#endif
}

View file

@ -37,6 +37,8 @@ extern const bool USING_INVENSENSE_MPU9150;
class SerialInterface {
public:
SerialInterface() : active(false),
_gravity(0,0,0),
_averageGyroRates(0,0,0),
_lastAccelX(0),
_lastAccelY(0),
_lastAccelZ(0),
@ -47,23 +49,25 @@ public:
void pair();
void readData();
float getLastYawRate() const { return _lastYawRate; }
float getLastPitchRate() const { return _lastPitchRate; }
float getLastRollRate() const { return _lastRollRate; }
float getLastYawRate() const { return _lastYawRate - _averageGyroRates[1]; }
float getLastPitchRate() const { return _lastPitchRate - _averageGyroRates[2]; }
float getLastRollRate() const { return _lastRollRate - _averageGyroRates[0]; }
glm::vec3 getLastAcceleration() { return glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ); };
glm::vec3 getGravity() {return _gravity;};
void renderLevels(int width, int height);
void resetAverages();
bool active;
private:
void initializePort(char* portname, int baud);
void initializePort(char* portname);
void resetSerial();
int _serialDescriptor;
int totalSamples;
timeval lastGoodRead;
glm::vec3 _gravity;
glm::vec3 _averageGyroRates;
float _lastAccelX;
float _lastAccelY;
float _lastAccelZ;

File diff suppressed because it is too large Load diff

View file

@ -5,60 +5,71 @@
// Created by Andrzej Kapolka on 4/24/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
#include "InterfaceConfig.h"
#include <QKeyEvent>
#include "ChatEntry.h"
#include "InterfaceConfig.h"
#include "Util.h"
using namespace std;
const int MAX_CONTENT_LENGTH = 140;
ChatEntry::ChatEntry() : _cursorPos(0) {
}
void ChatEntry::clear() {
_contents.clear();
_cursorPos = 0;
}
bool ChatEntry::key(unsigned char k) {
switch (k) {
case '\r':
bool ChatEntry::keyPressEvent(QKeyEvent* event) {
event->accept();
switch (event->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
return false;
case '\b':
case Qt::Key_Escape:
clear();
return false;
case Qt::Key_Backspace:
if (_cursorPos != 0) {
_contents.erase(_cursorPos - 1, 1);
_cursorPos--;
}
return true;
case 127: // delete
case Qt::Key_Delete:
if (_cursorPos < _contents.size()) {
_contents.erase(_cursorPos, 1);
}
return true;
default:
if (_contents.size() != MAX_CONTENT_LENGTH) {
_contents.insert(_cursorPos, 1, k);
_cursorPos++;
}
return true;
}
}
void ChatEntry::specialKey(unsigned char k) {
switch (k) {
case GLUT_KEY_LEFT:
case Qt::Key_Left:
if (_cursorPos != 0) {
_cursorPos--;
}
break;
return true;
case GLUT_KEY_RIGHT:
case Qt::Key_Right:
if (_cursorPos != _contents.size()) {
_cursorPos++;
}
break;
return true;
default:
QString text = event->text();
if (text.isEmpty()) {
event->ignore();
return true;
}
if (_contents.size() != MAX_CONTENT_LENGTH) {
_contents.insert(_cursorPos, 1, text.at(0).toAscii());
_cursorPos++;
}
return true;
}
}
@ -74,5 +85,4 @@ void ChatEntry::render(int screenWidth, int screenHeight) {
glVertex2f(20 + width, screenHeight - 165);
glVertex2f(20 + width, screenHeight - 150);
glEnd();
glEnable(GL_LINE_SMOOTH);
}

View file

@ -11,15 +11,18 @@
#include <string>
class QKeyEvent;
class ChatEntry {
public:
ChatEntry();
const std::string& getContents() const { return _contents; }
void clear();
bool key(unsigned char k);
void specialKey(unsigned char k);
bool keyPressEvent(QKeyEvent* event);
void render(int screenWidth, int screenHeight);

View file

@ -38,6 +38,7 @@ public:
_headRoll(0),
_headLeanSideways(0),
_headLeanForward(0),
_audioLoudness(0),
_handState(0),
_cameraPosition(0,0,0),
_cameraDirection(0,0,0),