mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Massive migration from GLUT/globals to Qt/class members. Mostly there.
This commit is contained in:
parent
121a819bda
commit
e0388515a4
6 changed files with 2108 additions and 48 deletions
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,8 +9,35 @@
|
|||
#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 Agent;
|
||||
class ProgramObject;
|
||||
|
||||
class Application : public QApplication {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -18,9 +45,185 @@ public:
|
|||
|
||||
Application(int& argc, char** argv);
|
||||
|
||||
public slots:
|
||||
#ifndef _WIN32
|
||||
Audio& getAudio() { return _audio; }
|
||||
#endif
|
||||
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
void resizeGL(int width, int height);
|
||||
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void keyReleaseEvent(QKeyEvent* event);
|
||||
|
||||
void testSlot();
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
private slots:
|
||||
|
||||
void timer();
|
||||
void idle();
|
||||
void terminate();
|
||||
|
||||
void setHead(bool head);
|
||||
void setNoise(bool noise);
|
||||
void setFullscreen(bool fullscreen);
|
||||
|
||||
void setRenderFirstPerson(bool firstPerson);
|
||||
void setOculus(bool oculus);
|
||||
|
||||
void setMenu(bool menu);
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
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;
|
||||
QAction* _gyroLook;
|
||||
QAction* _renderVoxels;
|
||||
QAction* _renderStarsOn;
|
||||
QAction* _renderAtmosphereOn;
|
||||
QAction* _renderAvatarsOn;
|
||||
QAction* _oculusOn;
|
||||
QAction* _renderStatsOn;
|
||||
QAction* _logOn;
|
||||
QAction* _frustumOn;
|
||||
QAction* _viewFrustumFromOffset;
|
||||
QAction* _cameraFrustum;
|
||||
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;
|
||||
|
||||
// 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;
|
||||
unsigned char _dominantColor;
|
||||
VoxelDetail _paintingVoxel;
|
||||
|
||||
bool _perfStatsOn;
|
||||
|
||||
ChatEntry _chatEntry;
|
||||
bool _chatEntryOn;
|
||||
|
||||
GLuint _oculusTextureID;
|
||||
ProgramObject* _oculusProgram;
|
||||
float _oculusDistortionScale;
|
||||
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__) */
|
||||
|
|
|
@ -1559,7 +1559,7 @@ void specialkeyUp(int k, int x, int y) {
|
|||
|
||||
void specialkey(int k, int x, int y) {
|
||||
if (::chatEntryOn) {
|
||||
chatEntry.specialKey(k);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1603,16 +1603,7 @@ void toggleMouseMode(MouseMode mode) {
|
|||
|
||||
void key(unsigned char k, int x, int y) {
|
||||
if (::chatEntryOn) {
|
||||
if (chatEntry.key(k)) {
|
||||
myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete
|
||||
DELETE_KEY_DOWN : INSERT_KEY_DOWN);
|
||||
myAvatar.setChatMessage(string(chatEntry.getContents().size(), SOLID_BLOCK_CHAR));
|
||||
|
||||
} else {
|
||||
myAvatar.setChatMessage(chatEntry.getContents());
|
||||
chatEntry.clear();
|
||||
::chatEntryOn = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1777,10 +1768,14 @@ glm::vec3 getFaceVector(BoxFace face) {
|
|||
}
|
||||
}
|
||||
|
||||
Application* app;
|
||||
|
||||
void idle(void) {
|
||||
timeval check;
|
||||
gettimeofday(&check, NULL);
|
||||
|
||||
app->processEvents();
|
||||
|
||||
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time
|
||||
|
||||
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
|
||||
|
@ -2034,6 +2029,14 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
|||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
Application app(argc, const_cast<char**>(argv));
|
||||
printLog( "Created QT Application.\n" );
|
||||
int exitCode = app.exec();
|
||||
printLog("Normal exit.\n");
|
||||
return exitCode;
|
||||
|
||||
|
||||
|
||||
gettimeofday(&applicationStartupTime, NULL);
|
||||
printLog("Interface Startup:\n");
|
||||
|
||||
|
@ -2098,10 +2101,6 @@ int main(int argc, const char * argv[]) {
|
|||
|
||||
#endif
|
||||
|
||||
// we need to create a QApplication instance in order to use Qt's font rendering
|
||||
Application app(argc, const_cast<char**>(argv));
|
||||
printLog( "Created QT Application.\n" );
|
||||
|
||||
// Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large
|
||||
// field of view and near and far clip to make it interesting.
|
||||
//viewFrustumOffsetCamera.setFieldOfView(90.0);
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
// 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;
|
||||
|
@ -19,46 +20,47 @@ void ChatEntry::clear() {
|
|||
_cursorPos = 0;
|
||||
}
|
||||
|
||||
bool ChatEntry::key(unsigned char k) {
|
||||
switch (k) {
|
||||
case '\r':
|
||||
bool ChatEntry::keyPressEvent(QKeyEvent* event) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Enter:
|
||||
return false;
|
||||
|
||||
case '\b':
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
class QKeyEvent;
|
||||
|
||||
class ChatEntry {
|
||||
public:
|
||||
|
||||
|
@ -18,8 +20,7 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
bool key(unsigned char k);
|
||||
void specialKey(unsigned char k);
|
||||
bool keyPressEvent(QKeyEvent* event);
|
||||
|
||||
void render(int screenWidth, int screenHeight);
|
||||
|
||||
|
|
Loading…
Reference in a new issue