mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 23:16:20 +02:00
312 lines
11 KiB
C++
312 lines
11 KiB
C++
//
|
|
// Application.h
|
|
// interface
|
|
//
|
|
// Created by Andrzej Kapolka on 5/10/13.
|
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#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 QActionGroup;
|
|
class QGLWidget;
|
|
class QKeyEvent;
|
|
class QMainWindow;
|
|
class QMouseEvent;
|
|
class QWheelEvent;
|
|
|
|
class Agent;
|
|
class ProgramObject;
|
|
|
|
class Application : public QApplication {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
|
|
|
Application(int& argc, char** argv, timeval &startup_time);
|
|
|
|
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);
|
|
|
|
Avatar* getAvatar() { return &_myAvatar; }
|
|
VoxelSystem* getVoxels() { return &_voxels; }
|
|
Environment* getEnvironment() { return &_environment; }
|
|
|
|
/*!
|
|
@fn getSettingBool
|
|
@brief A function for getting boolean settings from the settings file.
|
|
@param settingName The desired setting to get the value for.
|
|
@param boolSetting The referenced variable where the setting will be stored.
|
|
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to false.
|
|
*/
|
|
bool getSettingBool(const char* settingName, bool &boolSetting, bool defaultSetting = false);
|
|
|
|
/*!
|
|
@fn getSettingFloat
|
|
@brief A function for getting float settings from the settings file.
|
|
@param settingName The desired setting to get the value for.
|
|
@param floatSetting The referenced variable where the setting will be stored.
|
|
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to 0.0f.
|
|
*/
|
|
bool getSettingFloat(const char* settingName, float &floatSetting, float defaultSetting = 0.0f);
|
|
|
|
/*!
|
|
@fn getSettingVec3
|
|
@brief A function for getting boolean settings from the settings file.
|
|
@param settingName The desired setting to get the value for.
|
|
@param vecSetting The referenced variable where the setting will be stored.
|
|
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to <0.0f, 0.0f, 0.0f>
|
|
*/
|
|
bool getSettingVec3(const char* settingName, glm::vec3 &vecSetting, glm::vec3 defaultSetting = glm::vec3(0.0f, 0.0f, 0.0f));
|
|
|
|
/*!
|
|
@fn setSettingBool
|
|
@brief A function for setting boolean setting values when saving the settings file.
|
|
@param settingName The desired setting to populate a value for.
|
|
@param boolSetting The value to set.
|
|
*/
|
|
void setSettingBool(const char* settingName, bool boolSetting);
|
|
|
|
/*!
|
|
@fn setSettingFloat
|
|
@brief A function for setting boolean setting values when saving the settings file.
|
|
@param settingName The desired setting to populate a value for.
|
|
@param floatSetting The value to set.
|
|
*/
|
|
void setSettingFloat(const char* settingName, float floatSetting);
|
|
|
|
/*!
|
|
@fn setSettingVec3
|
|
@brief A function for setting boolean setting values when saving the settings file.
|
|
@param settingName The desired setting to populate a value for.
|
|
@param vecSetting The value to set.
|
|
*/
|
|
void setSettingVec3(const char* settingName, glm::vec3 vecSetting);
|
|
|
|
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);
|
|
void setWantsDelta(bool wantsDelta);
|
|
void updateVoxelModeActions();
|
|
void addVoxelInFrontOfAvatar();
|
|
void decreaseVoxelSize();
|
|
void increaseVoxelSize();
|
|
void chooseVoxelPaintColor();
|
|
|
|
private:
|
|
|
|
void initMenu();
|
|
void updateFrustumRenderModeAction();
|
|
void initDisplay();
|
|
void init();
|
|
|
|
void updateAvatar(float deltaTime);
|
|
void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum);
|
|
|
|
void displayOculus(Camera& whichCamera);
|
|
void displaySide(Camera& whichCamera);
|
|
void displayOverlay();
|
|
void displayStats();
|
|
|
|
void renderViewFrustum(ViewFrustum& viewFrustum);
|
|
|
|
void setupPaintingVoxel();
|
|
void shiftPaintingColor();
|
|
void maybeEditVoxelUnderCursor();
|
|
void deleteVoxelUnderCursor();
|
|
|
|
void resetSensors();
|
|
|
|
void setMenuShortcutsEnabled(bool enabled);
|
|
|
|
QAction* checkedVoxelModeAction() const;
|
|
|
|
static void attachNewHeadToAgent(Agent *newAgent);
|
|
static void* networkReceive(void* args);
|
|
|
|
bool openSettingsFile(const char* mode);
|
|
void closeSettingsFile();
|
|
|
|
void saveSettings();
|
|
void readSettings();
|
|
|
|
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* _mouseLook; // Whether the have the mouse near edge of screen move your view
|
|
QAction* _transmitterDrives; // Whether to have Transmitter data move/steer the Avatar
|
|
QAction* _renderVoxels; // Whether to render voxels
|
|
QAction* _renderVoxelTextures; // Whether to render noise textures on 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* _renderFrameTimerOn; // Whether to show onscreen text overlay with stats
|
|
QAction* _renderLookatOn; // Whether to show lookat vectors from avatar eyes if looking at something
|
|
QAction* _logOn; // Whether to show on-screen log
|
|
QActionGroup* _voxelModeActions; // The group of voxel edit mode actions
|
|
QAction* _addVoxelMode; // Whether add voxel mode is enabled
|
|
QAction* _deleteVoxelMode; // Whether delete voxel mode is enabled
|
|
QAction* _colorVoxelMode; // Whether color voxel mode is enabled
|
|
QAction* _voxelPaintColor; // The color with which to paint voxels
|
|
QAction* _destructiveAddVoxel; // when doing voxel editing do we want them to be destructive
|
|
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;
|
|
|
|
Oscilloscope _audioScope;
|
|
|
|
Avatar _myAvatar; // The rendered avatar of oneself
|
|
|
|
Transmitter _myTransmitter; // Gets UDP data from transmitter app used to animate the avatar
|
|
|
|
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;
|
|
bool _manualFirstPerson;
|
|
|
|
HandControl _handControl;
|
|
|
|
int _mouseX;
|
|
int _mouseY;
|
|
bool _mousePressed; // true if mouse has been pressed (clear when finished)
|
|
|
|
VoxelDetail _mouseVoxel; // details of the voxel under the mouse cursor
|
|
float _mouseVoxelScale; // the scale for adding/removing voxels
|
|
glm::vec3 _lastMouseVoxelPos; // the position of the last mouse voxel edit
|
|
bool _justEditedVoxel; // set when we've just added/deleted/colored a voxel
|
|
|
|
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;
|
|
|
|
FILE* _settingsFile;
|
|
};
|
|
|
|
#endif /* defined(__interface__Application__) */
|