mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-12 01:22:41 +02:00
merge upstream/master into andrew/ragdoll
Conflicts: libraries/shared/src/Shape.h libraries/shared/src/ShapeCollider.h
This commit is contained in:
commit
b9d4545aef
88 changed files with 5631 additions and 1908 deletions
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <AccountManager.h>
|
||||
#include <Assignment.h>
|
||||
#include <HifiConfigVariantMap.h>
|
||||
#include <Logging.h>
|
||||
#include <NodeList.h>
|
||||
#include <PacketHeaders.h>
|
||||
|
@ -41,73 +42,65 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
|||
setOrganizationDomain("highfidelity.io");
|
||||
setApplicationName("assignment-client");
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
|
||||
QStringList argumentList = arguments();
|
||||
|
||||
// register meta type is required for queued invoke method on Assignment subclasses
|
||||
|
||||
|
||||
// set the logging target to the the CHILD_TARGET_NAME
|
||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||
|
||||
const QString ASSIGNMENT_TYPE_OVVERIDE_OPTION = "-t";
|
||||
int argumentIndex = argumentList.indexOf(ASSIGNMENT_TYPE_OVVERIDE_OPTION);
|
||||
|
||||
|
||||
const QVariantMap argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments());
|
||||
|
||||
const QString ASSIGNMENT_TYPE_OVERRIDE_OPTION = "t";
|
||||
const QString ASSIGNMENT_POOL_OPTION = "pool";
|
||||
const QString ASSIGNMENT_WALLET_DESTINATION_ID_OPTION = "wallet";
|
||||
const QString CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION = "a";
|
||||
|
||||
Assignment::Type requestAssignmentType = Assignment::AllTypes;
|
||||
|
||||
if (argumentIndex != -1) {
|
||||
requestAssignmentType = (Assignment::Type) argumentList[argumentIndex + 1].toInt();
|
||||
|
||||
// check for an assignment type passed on the command line or in the config
|
||||
if (argumentVariantMap.contains(ASSIGNMENT_TYPE_OVERRIDE_OPTION)) {
|
||||
requestAssignmentType = (Assignment::Type) argumentVariantMap.value(ASSIGNMENT_TYPE_OVERRIDE_OPTION).toInt();
|
||||
}
|
||||
|
||||
const QString ASSIGNMENT_POOL_OPTION = "--pool";
|
||||
|
||||
argumentIndex = argumentList.indexOf(ASSIGNMENT_POOL_OPTION);
|
||||
|
||||
|
||||
QString assignmentPool;
|
||||
|
||||
if (argumentIndex != -1) {
|
||||
assignmentPool = argumentList[argumentIndex + 1];
|
||||
|
||||
// check for an assignment pool passed on the command line or in the config
|
||||
if (argumentVariantMap.contains(ASSIGNMENT_POOL_OPTION)) {
|
||||
assignmentPool = argumentVariantMap.value(ASSIGNMENT_POOL_OPTION).toString();
|
||||
}
|
||||
|
||||
|
||||
// setup our _requestAssignment member variable from the passed arguments
|
||||
_requestAssignment = Assignment(Assignment::RequestCommand, requestAssignmentType, assignmentPool);
|
||||
|
||||
// check if we were passed a wallet UUID on the command line
|
||||
|
||||
// check for a wallet UUID on the command line or in the config
|
||||
// this would represent where the user running AC wants funds sent to
|
||||
|
||||
const QString ASSIGNMENT_WALLET_DESTINATION_ID_OPTION = "--wallet";
|
||||
if ((argumentIndex = argumentList.indexOf(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION)) != -1) {
|
||||
QUuid walletUUID = QString(argumentList[argumentIndex + 1]);
|
||||
if (argumentVariantMap.contains(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION)) {
|
||||
QUuid walletUUID = argumentVariantMap.value(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION).toString();
|
||||
qDebug() << "The destination wallet UUID for credits is" << uuidStringWithoutCurlyBraces(walletUUID);
|
||||
_requestAssignment.setWalletUUID(walletUUID);
|
||||
}
|
||||
|
||||
|
||||
// create a NodeList as an unassigned client
|
||||
NodeList* nodeList = NodeList::createInstance(NodeType::Unassigned);
|
||||
|
||||
|
||||
// check for an overriden assignment server hostname
|
||||
const QString CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION = "-a";
|
||||
|
||||
argumentIndex = argumentList.indexOf(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION);
|
||||
|
||||
if (argumentIndex != -1) {
|
||||
_assignmentServerHostname = argumentList[argumentIndex + 1];
|
||||
|
||||
if (argumentVariantMap.contains(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION)) {
|
||||
_assignmentServerHostname = argumentVariantMap.value(CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION).toString();
|
||||
|
||||
// set the custom assignment socket on our NodeList
|
||||
HifiSockAddr customAssignmentSocket = HifiSockAddr(_assignmentServerHostname, DEFAULT_DOMAIN_SERVER_PORT);
|
||||
|
||||
|
||||
nodeList->setAssignmentServerSocket(customAssignmentSocket);
|
||||
}
|
||||
|
||||
|
||||
// call a timer function every ASSIGNMENT_REQUEST_INTERVAL_MSECS to ask for assignment, if required
|
||||
qDebug() << "Waiting for assignment -" << _requestAssignment;
|
||||
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), SLOT(sendAssignmentRequest()));
|
||||
timer->start(ASSIGNMENT_REQUEST_INTERVAL_MSECS);
|
||||
|
||||
|
||||
// connect our readPendingDatagrams method to the readyRead() signal of the socket
|
||||
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams);
|
||||
|
||||
|
||||
// connections to AccountManager for authentication
|
||||
connect(&AccountManager::getInstance(), &AccountManager::authRequired,
|
||||
this, &AssignmentClient::handleAuthenticationRequest);
|
||||
|
@ -121,49 +114,49 @@ void AssignmentClient::sendAssignmentRequest() {
|
|||
|
||||
void AssignmentClient::readPendingDatagrams() {
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
|
||||
|
||||
QByteArray receivedPacket;
|
||||
HifiSockAddr senderSockAddr;
|
||||
|
||||
|
||||
while (nodeList->getNodeSocket().hasPendingDatagrams()) {
|
||||
receivedPacket.resize(nodeList->getNodeSocket().pendingDatagramSize());
|
||||
nodeList->getNodeSocket().readDatagram(receivedPacket.data(), receivedPacket.size(),
|
||||
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
|
||||
|
||||
|
||||
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
|
||||
if (packetTypeForPacket(receivedPacket) == PacketTypeCreateAssignment) {
|
||||
// construct the deployed assignment from the packet data
|
||||
_currentAssignment = SharedAssignmentPointer(AssignmentFactory::unpackAssignment(receivedPacket));
|
||||
|
||||
|
||||
if (_currentAssignment) {
|
||||
qDebug() << "Received an assignment -" << *_currentAssignment;
|
||||
|
||||
|
||||
// switch our DomainHandler hostname and port to whoever sent us the assignment
|
||||
|
||||
|
||||
nodeList->getDomainHandler().setSockAddr(senderSockAddr, _assignmentServerHostname);
|
||||
nodeList->getDomainHandler().setAssignmentUUID(_currentAssignment->getUUID());
|
||||
|
||||
|
||||
qDebug() << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
|
||||
|
||||
|
||||
// start the deployed assignment
|
||||
AssignmentThread* workerThread = new AssignmentThread(_currentAssignment, this);
|
||||
|
||||
|
||||
connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run);
|
||||
connect(_currentAssignment.data(), &ThreadedAssignment::finished, workerThread, &QThread::quit);
|
||||
connect(_currentAssignment.data(), &ThreadedAssignment::finished,
|
||||
this, &AssignmentClient::assignmentCompleted);
|
||||
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
|
||||
|
||||
|
||||
_currentAssignment->moveToThread(workerThread);
|
||||
|
||||
|
||||
// move the NodeList to the thread used for the _current assignment
|
||||
nodeList->moveToThread(workerThread);
|
||||
|
||||
|
||||
// let the assignment handle the incoming datagrams for its duration
|
||||
disconnect(&nodeList->getNodeSocket(), 0, this, 0);
|
||||
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _currentAssignment.data(),
|
||||
&ThreadedAssignment::readPendingDatagrams);
|
||||
|
||||
|
||||
// Starts an event loop, and emits workerThread->started()
|
||||
workerThread->start();
|
||||
} else {
|
||||
|
@ -180,15 +173,15 @@ void AssignmentClient::readPendingDatagrams() {
|
|||
void AssignmentClient::handleAuthenticationRequest() {
|
||||
const QString DATA_SERVER_USERNAME_ENV = "HIFI_AC_USERNAME";
|
||||
const QString DATA_SERVER_PASSWORD_ENV = "HIFI_AC_PASSWORD";
|
||||
|
||||
|
||||
// this node will be using an authentication server, let's make sure we have a username/password
|
||||
QProcessEnvironment sysEnvironment = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
|
||||
QString username = sysEnvironment.value(DATA_SERVER_USERNAME_ENV);
|
||||
QString password = sysEnvironment.value(DATA_SERVER_PASSWORD_ENV);
|
||||
|
||||
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
// ask the account manager to log us in from the env variables
|
||||
accountManager.requestAccessToken(username, password);
|
||||
|
@ -196,7 +189,7 @@ void AssignmentClient::handleAuthenticationRequest() {
|
|||
qDebug() << "Authentication was requested against" << qPrintable(accountManager.getAuthURL().toString())
|
||||
<< "but both or one of" << qPrintable(DATA_SERVER_USERNAME_ENV)
|
||||
<< "/" << qPrintable(DATA_SERVER_PASSWORD_ENV) << "are not set. Unable to authenticate.";
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -204,15 +197,15 @@ void AssignmentClient::handleAuthenticationRequest() {
|
|||
void AssignmentClient::assignmentCompleted() {
|
||||
// reset the logging target to the the CHILD_TARGET_NAME
|
||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||
|
||||
|
||||
qDebug("Assignment finished or never started - waiting for new assignment.");
|
||||
|
||||
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
|
||||
// have us handle incoming NodeList datagrams again
|
||||
disconnect(&nodeList->getNodeSocket(), 0, _currentAssignment.data(), 0);
|
||||
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams);
|
||||
|
||||
|
||||
// clear our current assignment shared pointer now that we're done with it
|
||||
// if the assignment thread is still around it has its own shared pointer to the assignment
|
||||
_currentAssignment.clear();
|
||||
|
|
|
@ -335,7 +335,7 @@ void AudioMixer::prepareMixForListeningNode(Node* node) {
|
|||
AudioMixerClientData* otherNodeClientData = (AudioMixerClientData*) otherNode->getLinkedData();
|
||||
|
||||
// enumerate the ARBs attached to the otherNode and add all that should be added to mix
|
||||
for (unsigned int i = 0; i < otherNodeClientData->getRingBuffers().size(); i++) {
|
||||
for (int i = 0; i < otherNodeClientData->getRingBuffers().size(); i++) {
|
||||
PositionalAudioRingBuffer* otherNodeBuffer = otherNodeClientData->getRingBuffers()[i];
|
||||
|
||||
if ((*otherNode != *node
|
||||
|
|
|
@ -25,14 +25,14 @@ AudioMixerClientData::AudioMixerClientData() :
|
|||
}
|
||||
|
||||
AudioMixerClientData::~AudioMixerClientData() {
|
||||
for (unsigned int i = 0; i < _ringBuffers.size(); i++) {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
// delete this attached PositionalAudioRingBuffer
|
||||
delete _ringBuffers[i];
|
||||
}
|
||||
}
|
||||
|
||||
AvatarAudioRingBuffer* AudioMixerClientData::getAvatarAudioRingBuffer() const {
|
||||
for (unsigned int i = 0; i < _ringBuffers.size(); i++) {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
if (_ringBuffers[i]->getType() == PositionalAudioRingBuffer::Microphone) {
|
||||
return (AvatarAudioRingBuffer*) _ringBuffers[i];
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ int AudioMixerClientData::parseData(const QByteArray& packet) {
|
|||
|
||||
InjectedAudioRingBuffer* matchingInjectedRingBuffer = NULL;
|
||||
|
||||
for (unsigned int i = 0; i < _ringBuffers.size(); i++) {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
if (_ringBuffers[i]->getType() == PositionalAudioRingBuffer::Injector
|
||||
&& ((InjectedAudioRingBuffer*) _ringBuffers[i])->getStreamIdentifier() == streamIdentifier) {
|
||||
matchingInjectedRingBuffer = (InjectedAudioRingBuffer*) _ringBuffers[i];
|
||||
|
@ -99,7 +99,7 @@ int AudioMixerClientData::parseData(const QByteArray& packet) {
|
|||
}
|
||||
|
||||
void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSamples) {
|
||||
for (unsigned int i = 0; i < _ringBuffers.size(); i++) {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
if (_ringBuffers[i]->shouldBeAddedToMix(jitterBufferLengthSamples)) {
|
||||
// this is a ring buffer that is ready to go
|
||||
// set its flag so we know to push its buffer when all is said and done
|
||||
|
@ -113,7 +113,7 @@ void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSam
|
|||
}
|
||||
|
||||
void AudioMixerClientData::pushBuffersAfterFrameSend() {
|
||||
for (unsigned int i = 0; i < _ringBuffers.size(); i++) {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
// this was a used buffer, push the output pointer forwards
|
||||
PositionalAudioRingBuffer* audioBuffer = _ringBuffers[i];
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ bool ModelServer::hasSpecialPacketToSend(const SharedNodePointer& node) {
|
|||
return shouldSendDeletedModels;
|
||||
}
|
||||
|
||||
int ModelServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node) {
|
||||
int ModelServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) {
|
||||
unsigned char outputBuffer[MAX_PACKET_SIZE];
|
||||
size_t packetLength = 0;
|
||||
|
||||
|
@ -99,6 +99,7 @@ int ModelServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodeP
|
|||
bool hasMoreToSend = true;
|
||||
|
||||
// TODO: is it possible to send too many of these packets? what if you deleted 1,000,000 models?
|
||||
packetsSent = 0;
|
||||
while (hasMoreToSend) {
|
||||
hasMoreToSend = tree->encodeModelsDeletedSince(queryNode->getSequenceNumber(), deletedModelsSentAt,
|
||||
outputBuffer, MAX_PACKET_SIZE, packetLength);
|
||||
|
@ -107,6 +108,7 @@ int ModelServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodeP
|
|||
|
||||
NodeList::getInstance()->writeDatagram((char*) outputBuffer, packetLength, SharedNodePointer(node));
|
||||
queryNode->packetSent(outputBuffer, packetLength);
|
||||
packetsSent++;
|
||||
}
|
||||
|
||||
nodeData->setLastDeletedModelsSentAt(deletePacketSentAt);
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
// subclass may implement these method
|
||||
virtual void beforeRun();
|
||||
virtual bool hasSpecialPacketToSend(const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
|
||||
|
||||
virtual void modelCreated(const ModelItem& newModel, const SharedNodePointer& senderNode);
|
||||
|
||||
|
|
|
@ -85,7 +85,6 @@ bool OctreeSendThread::process() {
|
|||
if (nodeData && !nodeData->isShuttingDown()) {
|
||||
bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
|
||||
packetDistributor(nodeData, viewFrustumChanged);
|
||||
resendNackedPackets(nodeData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,26 +280,6 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
|
|||
return packetsSent;
|
||||
}
|
||||
|
||||
int OctreeSendThread::resendNackedPackets(OctreeQueryNode* nodeData) {
|
||||
|
||||
const int MAX_PACKETS_RESEND = 10;
|
||||
int packetsSent = 0;
|
||||
|
||||
const QByteArray* packet;
|
||||
while (nodeData->hasNextNackedPacket() && packetsSent < MAX_PACKETS_RESEND) {
|
||||
packet = nodeData->getNextNackedPacket();
|
||||
if (packet) {
|
||||
NodeList::getInstance()->writeDatagram(*packet, _node);
|
||||
packetsSent++;
|
||||
|
||||
_totalBytes += packet->size();
|
||||
_totalPackets++;
|
||||
_totalWastedBytes += MAX_PACKET_SIZE - packet->size();
|
||||
}
|
||||
}
|
||||
return packetsSent;
|
||||
}
|
||||
|
||||
/// Version of voxel distributor that sends the deepest LOD level at once
|
||||
int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrustumChanged) {
|
||||
|
||||
|
@ -311,6 +290,10 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
|||
return 0;
|
||||
}
|
||||
|
||||
// calculate max number of packets that can be sent during this interval
|
||||
int clientMaxPacketsPerInterval = std::max(1, (nodeData->getMaxOctreePacketsPerSecond() / INTERVALS_PER_SECOND));
|
||||
int maxPacketsPerInterval = std::min(clientMaxPacketsPerInterval, _myServer->getPacketsPerClientPerInterval());
|
||||
|
||||
int truePacketsSent = 0;
|
||||
int trueBytesSent = 0;
|
||||
int packetsSentThisInterval = 0;
|
||||
|
@ -408,9 +391,6 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
|||
//quint64 startCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000;
|
||||
//quint64 startCompressCalls = OctreePacketData::getCompressContentCalls();
|
||||
|
||||
int clientMaxPacketsPerInterval = std::max(1,(nodeData->getMaxOctreePacketsPerSecond() / INTERVALS_PER_SECOND));
|
||||
int maxPacketsPerInterval = std::min(clientMaxPacketsPerInterval, _myServer->getPacketsPerClientPerInterval());
|
||||
|
||||
int extraPackingAttempts = 0;
|
||||
bool completedScene = false;
|
||||
while (somethingToSend && packetsSentThisInterval < maxPacketsPerInterval && !nodeData->isShuttingDown()) {
|
||||
|
@ -581,12 +561,26 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
|||
// send the environment packet
|
||||
// TODO: should we turn this into a while loop to better handle sending multiple special packets
|
||||
if (_myServer->hasSpecialPacketToSend(_node) && !nodeData->isShuttingDown()) {
|
||||
trueBytesSent += _myServer->sendSpecialPacket(nodeData, _node);
|
||||
int specialPacketsSent;
|
||||
trueBytesSent += _myServer->sendSpecialPacket(_node, nodeData, specialPacketsSent);
|
||||
nodeData->resetOctreePacket(); // because nodeData's _sequenceNumber has changed
|
||||
truePacketsSent++;
|
||||
packetsSentThisInterval++;
|
||||
truePacketsSent += specialPacketsSent;
|
||||
packetsSentThisInterval += specialPacketsSent;
|
||||
}
|
||||
|
||||
// Re-send packets that were nacked by the client
|
||||
while (nodeData->hasNextNackedPacket() && packetsSentThisInterval < maxPacketsPerInterval) {
|
||||
const QByteArray* packet = nodeData->getNextNackedPacket();
|
||||
if (packet) {
|
||||
NodeList::getInstance()->writeDatagram(*packet, _node);
|
||||
truePacketsSent++;
|
||||
packetsSentThisInterval++;
|
||||
|
||||
_totalBytes += packet->size();
|
||||
_totalPackets++;
|
||||
_totalWastedBytes += MAX_PACKET_SIZE - packet->size();
|
||||
}
|
||||
}
|
||||
|
||||
quint64 end = usecTimestampNow();
|
||||
int elapsedmsec = (end - start)/USECS_PER_MSEC;
|
||||
|
|
|
@ -55,9 +55,6 @@ private:
|
|||
|
||||
int _nodeMissingCount;
|
||||
bool _isShuttingDown;
|
||||
|
||||
int resendNackedPackets(OctreeQueryNode* nodeData);
|
||||
|
||||
};
|
||||
|
||||
#endif // hifi_OctreeSendThread_h
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
// subclass may implement these method
|
||||
virtual void beforeRun() { };
|
||||
virtual bool hasSpecialPacketToSend(const SharedNodePointer& node) { return false; }
|
||||
virtual int sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node) { return 0; }
|
||||
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) { return 0; }
|
||||
|
||||
static void attachQueryNodeToNode(Node* newNode);
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ bool ParticleServer::hasSpecialPacketToSend(const SharedNodePointer& node) {
|
|||
return shouldSendDeletedParticles;
|
||||
}
|
||||
|
||||
int ParticleServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node) {
|
||||
int ParticleServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) {
|
||||
unsigned char outputBuffer[MAX_PACKET_SIZE];
|
||||
size_t packetLength = 0;
|
||||
|
||||
|
@ -99,6 +99,7 @@ int ParticleServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNo
|
|||
bool hasMoreToSend = true;
|
||||
|
||||
// TODO: is it possible to send too many of these packets? what if you deleted 1,000,000 particles?
|
||||
packetsSent = 0;
|
||||
while (hasMoreToSend) {
|
||||
hasMoreToSend = tree->encodeParticlesDeletedSince(queryNode->getSequenceNumber(), deletedParticlesSentAt,
|
||||
outputBuffer, MAX_PACKET_SIZE, packetLength);
|
||||
|
@ -107,6 +108,7 @@ int ParticleServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNo
|
|||
|
||||
NodeList::getInstance()->writeDatagram((char*) outputBuffer, packetLength, SharedNodePointer(node));
|
||||
queryNode->packetSent(outputBuffer, packetLength);
|
||||
packetsSent++;
|
||||
}
|
||||
|
||||
nodeData->setLastDeletedParticlesSentAt(deletePacketSentAt);
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
// subclass may implement these method
|
||||
virtual void beforeRun();
|
||||
virtual bool hasSpecialPacketToSend(const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
|
||||
|
||||
virtual void particleCreated(const Particle& newParticle, const SharedNodePointer& senderNode);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ bool VoxelServer::hasSpecialPacketToSend(const SharedNodePointer& node) {
|
|||
return shouldSendEnvironments;
|
||||
}
|
||||
|
||||
int VoxelServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node) {
|
||||
int VoxelServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) {
|
||||
|
||||
unsigned char* copyAt = _tempOutputBuffer;
|
||||
|
||||
|
@ -76,6 +76,7 @@ int VoxelServer::sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodeP
|
|||
|
||||
NodeList::getInstance()->writeDatagram((char*) _tempOutputBuffer, envPacketLength, SharedNodePointer(node));
|
||||
queryNode->packetSent(_tempOutputBuffer, envPacketLength);
|
||||
packetsSent = 1;
|
||||
|
||||
return envPacketLength;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
// subclass may implement these method
|
||||
virtual void beforeRun();
|
||||
virtual bool hasSpecialPacketToSend(const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(OctreeQueryNode* queryNode, const SharedNodePointer& node);
|
||||
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
|
||||
|
||||
private:
|
||||
bool _sendEnvironments;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -691,6 +691,10 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
|||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if (altIsPressed) {
|
||||
return;
|
||||
}
|
||||
|
||||
mouseLastPosition = { x: event.x, y: event.y };
|
||||
modelSelected = false;
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
|
||||
|
@ -790,6 +794,10 @@ var oldModifier = 0;
|
|||
var modifier = 0;
|
||||
var wasShifted = false;
|
||||
function mouseMoveEvent(event) {
|
||||
if (altIsPressed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
||||
if (!modelSelected) {
|
||||
|
@ -894,6 +902,10 @@ function mouseMoveEvent(event) {
|
|||
}
|
||||
|
||||
function mouseReleaseEvent(event) {
|
||||
if (altIsPressed) {
|
||||
return;
|
||||
}
|
||||
|
||||
modelSelected = false;
|
||||
|
||||
glowedModelID.id = -1;
|
||||
|
@ -962,4 +974,16 @@ Menu.menuItemEvent.connect(function(menuItem){
|
|||
}
|
||||
});
|
||||
|
||||
// handling of inspect.js concurrence
|
||||
altIsPressed = false;
|
||||
Controller.keyPressEvent.connect(function(event) {
|
||||
if (event.text == "ALT") {
|
||||
altIsPressed = true;
|
||||
}
|
||||
});
|
||||
Controller.keyReleaseEvent.connect(function(event) {
|
||||
if (event.text == "ALT") {
|
||||
altIsPressed = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
832
examples/growTrees.js
Normal file
832
examples/growTrees.js
Normal file
|
@ -0,0 +1,832 @@
|
|||
//
|
||||
// growPlants.js
|
||||
// examples
|
||||
//
|
||||
// Created by Benjamin Arnold on May 29, 2014
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This sample script allows the user to grow different types of plants on the voxels
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z fighting
|
||||
var previewLineWidth = 2.0;
|
||||
|
||||
var voxelSize = 1;
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
var toolIconUrl = "http://highfidelity-public.s3-us-west-1.amazonaws.com/images/tools/";
|
||||
|
||||
var MAX_VOXEL_SCALE_POWER = 5;
|
||||
var MIN_VOXEL_SCALE_POWER = -8;
|
||||
var MAX_VOXEL_SCALE = Math.pow(2.0, MAX_VOXEL_SCALE_POWER);
|
||||
var MIN_VOXEL_SCALE = Math.pow(2.0, MIN_VOXEL_SCALE_POWER);
|
||||
|
||||
|
||||
var linePreviewTop = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewBottom = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewLeft = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewRight = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
|
||||
var UIColor = { red: 0, green: 160, blue: 0};
|
||||
var activeUIColor = { red: 0, green: 255, blue: 0};
|
||||
|
||||
var toolHeight = 50;
|
||||
var toolWidth = 50;
|
||||
|
||||
var editToolsOn = true;
|
||||
|
||||
var voxelToolSelected = false;
|
||||
|
||||
var scaleSelectorWidth = 144;
|
||||
var scaleSelectorHeight = 37;
|
||||
|
||||
var scaleSelectorX = windowDimensions.x / 5.0;
|
||||
var scaleSelectorY = windowDimensions.y - scaleSelectorHeight;
|
||||
|
||||
var voxelTool = Overlays.addOverlay("image", {
|
||||
x: scaleSelectorX + scaleSelectorWidth + 1, y: windowDimensions.y - toolHeight, width: toolWidth, height: toolHeight,
|
||||
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-tool.svg",
|
||||
visible: editToolsOn,
|
||||
color: UIColor,
|
||||
alpha: 0.9
|
||||
});
|
||||
|
||||
var copyScale = true;
|
||||
function ScaleSelector() {
|
||||
this.x = scaleSelectorX;
|
||||
this.y = scaleSelectorY;
|
||||
this.width = scaleSelectorWidth;
|
||||
this.height = scaleSelectorHeight;
|
||||
|
||||
this.displayPower = false;
|
||||
this.scale = 1.0;
|
||||
this.power = 0;
|
||||
|
||||
this.FIRST_PART = this.width * 40.0 / 100.0;
|
||||
this.SECOND_PART = this.width * 37.0 / 100.0;
|
||||
|
||||
this.buttonsOverlay = Overlays.addOverlay("image", {
|
||||
x: this.x, y: this.y,
|
||||
width: this.width, height: this.height,
|
||||
//subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-size-selector.svg",
|
||||
alpha: 0.9,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.textOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
alpha: 0.0,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.powerOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
alpha: 0.0,
|
||||
visible: false,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.setScale = function(scale) {
|
||||
if (scale > MAX_VOXEL_SCALE) {
|
||||
scale = MAX_VOXEL_SCALE;
|
||||
}
|
||||
if (scale < MIN_VOXEL_SCALE) {
|
||||
scale = MIN_VOXEL_SCALE;
|
||||
}
|
||||
|
||||
this.scale = scale;
|
||||
this.power = Math.floor(Math.log(scale) / Math.log(2));
|
||||
this.update();
|
||||
}
|
||||
|
||||
this.show = function(doShow) {
|
||||
Overlays.editOverlay(this.buttonsOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.textOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.powerOverlay, {visible: doShow && this.displayPower});
|
||||
}
|
||||
|
||||
this.move = function() {
|
||||
this.x = swatchesX + swatchesWidth;
|
||||
this.y = swatchesY;
|
||||
|
||||
Overlays.editOverlay(this.buttonsOverlay, {
|
||||
x: this.x, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.switchDisplay = function() {
|
||||
this.displayPower = !this.displayPower;
|
||||
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 18,
|
||||
text: "2"
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
text: this.power.toString(),
|
||||
visible: editToolsOn
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 13,
|
||||
text: this.scale.toString()
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
visible: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.update = function() {
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.powerOverlay, {text: this.power.toString()});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {text: this.scale.toString()});
|
||||
}
|
||||
}
|
||||
|
||||
this.incrementScale = function() {
|
||||
copyScale = false;
|
||||
if (this.power < MAX_VOXEL_SCALE_POWER) {
|
||||
++this.power;
|
||||
this.scale *= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.decrementScale = function() {
|
||||
copyScale = false;
|
||||
if (MIN_VOXEL_SCALE_POWER < this.power) {
|
||||
--this.power;
|
||||
this.scale /= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.clicked = function(x, y) {
|
||||
if (this.x < x && x < this.x + this.width &&
|
||||
this.y < y && y < this.y + this.height) {
|
||||
|
||||
if (x < this.x + this.FIRST_PART) {
|
||||
this.decrementScale();
|
||||
} else if (x < this.x + this.FIRST_PART + this.SECOND_PART) {
|
||||
this.switchDisplay();
|
||||
} else {
|
||||
this.incrementScale();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
Overlays.deleteOverlay(this.buttonsOverlay);
|
||||
Overlays.deleteOverlay(this.textOverlay);
|
||||
Overlays.deleteOverlay(this.powerOverlay);
|
||||
}
|
||||
|
||||
}
|
||||
var scaleSelector = new ScaleSelector();
|
||||
|
||||
|
||||
function calculateVoxelFromIntersection(intersection, operation) {
|
||||
|
||||
var resultVoxel;
|
||||
|
||||
var x;
|
||||
var y;
|
||||
var z;
|
||||
|
||||
// if our "target voxel size" is larger than the voxel we intersected with, then we need to find the closest
|
||||
// ancestor voxel of our target size that contains our intersected voxel.
|
||||
if (voxelSize > intersection.voxel.s) {
|
||||
x = Math.floor(intersection.voxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(intersection.voxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(intersection.voxel.z / voxelSize) * voxelSize;
|
||||
} else {
|
||||
// otherwise, calculate the enclosed voxel of size voxelSize that the intersection point falls inside of.
|
||||
// if you have a voxelSize that's smaller than the voxel you're intersecting, this calculation will result
|
||||
// in the subvoxel that the intersection point falls in, if the target voxelSize matches the intersecting
|
||||
// voxel this still works and results in returning the intersecting voxel which is what we want
|
||||
var adjustToCenter = Vec3.multiply(Voxels.getFaceVector(intersection.face), (voxelSize * -0.5));
|
||||
|
||||
var centerOfIntersectingVoxel = Vec3.sum(intersection.intersection, adjustToCenter);
|
||||
x = Math.floor(centerOfIntersectingVoxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(centerOfIntersectingVoxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(centerOfIntersectingVoxel.z / voxelSize) * voxelSize;
|
||||
}
|
||||
resultVoxel = { x: x, y: y, z: z, s: voxelSize };
|
||||
var highlightAt = { x: x, y: y, z: z, s: voxelSize };
|
||||
|
||||
|
||||
|
||||
// we only do the "add to the face we're pointing at" adjustment, if the operation is an add
|
||||
// operation, and the target voxel size is equal to or smaller than the intersecting voxel.
|
||||
var wantAddAdjust = (operation == "add" && (voxelSize <= intersection.voxel.s));
|
||||
|
||||
// now we also want to calculate the "edge square" for the face for this voxel
|
||||
if (intersection.face == "MIN_X_FACE") {
|
||||
|
||||
highlightAt.x = x - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_X_FACE") {
|
||||
|
||||
highlightAt.x = x + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x += resultVoxel.s;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MIN_Y_FACE") {
|
||||
|
||||
highlightAt.y = y - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_Y_FACE") {
|
||||
|
||||
highlightAt.y = y + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
|
||||
} else if (intersection.face == "MIN_Z_FACE") {
|
||||
|
||||
highlightAt.z = z - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
} else if (intersection.face == "MAX_Z_FACE") {
|
||||
|
||||
highlightAt.z = z + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
}
|
||||
return resultVoxel;
|
||||
}
|
||||
|
||||
var trackLastMouseX = 0;
|
||||
var trackLastMouseY = 0;
|
||||
|
||||
function showPreviewLines() {
|
||||
|
||||
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
||||
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
|
||||
if (intersection.intersects) {
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "");
|
||||
Overlays.editOverlay(linePreviewTop, { position: resultVoxel.topLeft, end: resultVoxel.topRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewBottom, { position: resultVoxel.bottomLeft, end: resultVoxel.bottomRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewLeft, { position: resultVoxel.topLeft, end: resultVoxel.bottomLeft, visible: true });
|
||||
Overlays.editOverlay(linePreviewRight, { position: resultVoxel.topRight, end: resultVoxel.bottomRight, visible: true });
|
||||
} else {
|
||||
Overlays.editOverlay(linePreviewTop, { visible: false });
|
||||
Overlays.editOverlay(linePreviewBottom, { visible: false });
|
||||
Overlays.editOverlay(linePreviewLeft, { visible: false });
|
||||
Overlays.editOverlay(linePreviewRight, { visible: false });
|
||||
}
|
||||
}
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
trackLastMouseX = event.x;
|
||||
trackLastMouseY = event.y;
|
||||
if (!voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
showPreviewLines();
|
||||
}
|
||||
|
||||
|
||||
// Array of possible trees, right now there is only one
|
||||
var treeTypes = [];
|
||||
|
||||
treeTypes.push({
|
||||
name: "Tall Green",
|
||||
// Voxel Colors
|
||||
wood: { r: 133, g: 81, b: 53 },
|
||||
leaves: { r: 22, g: 83, b: 31 },
|
||||
|
||||
// How tall the tree is
|
||||
height: { min: 20, max: 60 },
|
||||
middleHeight: 0.3,
|
||||
|
||||
// Chance of making a branch
|
||||
branchChance: { min: 0.01, max: 0.1 },
|
||||
branchLength: { min: 30, max: 60 },
|
||||
branchThickness: { min: 2, max: 7},
|
||||
|
||||
// The width of the core, affects width and shape
|
||||
coreWidth: { min: 1, max: 4 },
|
||||
|
||||
//TODO: Make this quadratic splines instead of linear
|
||||
bottomThickness: { min: 2, max: 8 },
|
||||
middleThickness: { min: 1, max: 4 },
|
||||
topThickness: { min: 3, max: 6 },
|
||||
|
||||
//Modifies leaves at top
|
||||
leafCapSizeOffset: 0
|
||||
});
|
||||
|
||||
// Applies noise to color
|
||||
var colorNoiseRange = 0.2;
|
||||
|
||||
|
||||
// Useful constants
|
||||
var LEFT = 0;
|
||||
var BACK = 1;
|
||||
var RIGHT = 2;
|
||||
var FRONT = 3;
|
||||
var UP = 4;
|
||||
|
||||
// Interpolates between min and max of treevar based on b
|
||||
function interpolate(treeVar, b) {
|
||||
return (treeVar.min + (treeVar.max - treeVar.min) * b);
|
||||
}
|
||||
|
||||
function makeBranch(x, y, z, step, length, dir, thickness, wood, leaves) {
|
||||
var moveDir;
|
||||
|
||||
var currentThickness;
|
||||
//thickness attenuates to thickness - 3
|
||||
var finalThickness = thickness - 3;
|
||||
if (finalThickness < 1) {
|
||||
finalThickness = 1;
|
||||
}
|
||||
//Iterative branch generation
|
||||
while (true) {
|
||||
|
||||
//If we are at the end, place a ball of leaves
|
||||
if (step == 0) {
|
||||
makeSphere(x, y, z, 2 + finalThickness, leaves);
|
||||
return;
|
||||
}
|
||||
//thickness attenuation
|
||||
currentThickness = Math.round((finalThickness + (thickness - finalThickness) * (step/length))) - 1;
|
||||
|
||||
|
||||
// If the branch is thick, grow a vertical slice
|
||||
if (currentThickness > 0) {
|
||||
for (var i = -currentThickness; i <= currentThickness; i++) {
|
||||
var len = currentThickness - Math.abs(i);
|
||||
switch (dir) {
|
||||
case 0: //left
|
||||
case 2: //right
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, BACK, wood, false, true);
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, FRONT, wood, false, false)
|
||||
break;
|
||||
case 1: //back
|
||||
case 3: //front
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, LEFT, wood, false, true);
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, RIGHT, wood, false, false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Otherwise place a single voxel
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x, y, z, voxelSize, wood.r * colorNoise, wood.g * colorNoise, wood.b * colorNoise);
|
||||
}
|
||||
|
||||
// determines random change in direction for branch
|
||||
var r = Math.floor(Math.random() * 9);
|
||||
|
||||
|
||||
if (r >= 6){
|
||||
moveDir = dir; //in same direction
|
||||
} else if (r >= 4) {
|
||||
moveDir = UP; //up
|
||||
}
|
||||
else if (dir == LEFT){
|
||||
if (r >= 2){
|
||||
moveDir = FRONT;
|
||||
}
|
||||
else{
|
||||
moveDir = BACK;
|
||||
}
|
||||
}
|
||||
else if (dir == BACK){
|
||||
if (r >= 2){
|
||||
moveDir = LEFT;
|
||||
}
|
||||
else{
|
||||
moveDir = RIGHT;
|
||||
}
|
||||
}
|
||||
else if (dir == RIGHT){
|
||||
if (r >= 2){
|
||||
moveDir = BACK;
|
||||
}
|
||||
else{
|
||||
moveDir = FRONT;
|
||||
}
|
||||
}
|
||||
else if (dir == FRONT){
|
||||
if (r >= 2){
|
||||
moveDir = RIGHT;
|
||||
}
|
||||
else{
|
||||
moveDir = LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
//Move the branch by moveDir
|
||||
switch (moveDir) {
|
||||
case 0: //left
|
||||
x = x - voxelSize;
|
||||
break;
|
||||
case 1: //back
|
||||
z = z - voxelSize;
|
||||
break;
|
||||
case 2: //right
|
||||
x = x + voxelSize;
|
||||
break;
|
||||
case 3: //front
|
||||
z = z + voxelSize;
|
||||
break;
|
||||
case 4: //up
|
||||
y = y + voxelSize;
|
||||
break;
|
||||
}
|
||||
|
||||
step--;
|
||||
}
|
||||
}
|
||||
|
||||
// Places a sphere of voxels
|
||||
function makeSphere(x, y, z, radius, color) {
|
||||
if (radius <= 0) {
|
||||
return;
|
||||
}
|
||||
var width = radius * 2 + 1;
|
||||
var distance;
|
||||
|
||||
for (var i = -radius; i <= radius; i++){
|
||||
for (var j = -radius; j <= radius; j++){
|
||||
for (var k = -radius; k <= radius; k++){
|
||||
distance = Math.sqrt(i * i + j * j + k * k);
|
||||
if (distance <= radius){
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x + i * voxelSize, y + j * voxelSize, z + k * voxelSize, voxelSize, color.r * colorNoise, color.g * colorNoise, color.b * colorNoise);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function growInDirection(x, y, z, step, length, dir, color, isSideBranching, addVoxel) {
|
||||
|
||||
|
||||
if (addVoxel == true) {
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x, y, z, voxelSize, color.r * colorNoise, color.g * colorNoise, color.b * colorNoise);
|
||||
}
|
||||
|
||||
// If this is a main vein, it will branch outward perpendicular to its motion
|
||||
if (isSideBranching == true){
|
||||
var step2;
|
||||
if (step >= length - 1){
|
||||
step2 = length;
|
||||
}
|
||||
else{
|
||||
step2 = step + 1;
|
||||
}
|
||||
growInDirection(x, y, z, step, length, BACK, color, false, false);
|
||||
growInDirection(x, y, z, step, length, FRONT, color, false, false);
|
||||
}
|
||||
|
||||
if (step < 1) return;
|
||||
|
||||
// Recursively move in the direction
|
||||
if (dir == LEFT) { //left
|
||||
growInDirection(x - voxelSize, y, z, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == BACK) { //back
|
||||
growInDirection(x, y, z - voxelSize, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == RIGHT) { //right
|
||||
growInDirection(x + voxelSize, y, z, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == FRONT) {//front
|
||||
growInDirection(x, y, z + voxelSize, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Grows the thickness of the tree
|
||||
function growHorizontalSlice(x, y, z, thickness, color, side) {
|
||||
// The side variable determines which directions we should grow in
|
||||
// it is an optimization that prevents us from visiting voxels multiple
|
||||
// times for trees with a coreWidth > 1
|
||||
|
||||
// side:
|
||||
// 8 == all directions
|
||||
// 0 1 2
|
||||
// 3 -1 4
|
||||
// 5 6 7
|
||||
|
||||
Voxels.setVoxel(x, y, z, voxelSize, color.r, color.g, color.b);
|
||||
|
||||
//We are done if there is no thickness
|
||||
if (thickness == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (side) {
|
||||
case 0:
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, true, false);
|
||||
break;
|
||||
case 1:
|
||||
growInDirection(x, y, z, thickness, thickness, BACK, color, false, false);
|
||||
break;
|
||||
case 2:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 3:
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, false, false);
|
||||
break;
|
||||
case 4:
|
||||
growInDirection(x, y, z, thickness, thickness, BACK, color, false, false);
|
||||
break;
|
||||
case 5:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 6:
|
||||
growInDirection(x, y, z, thickness, thickness, FRONT, color, false, false);
|
||||
break;
|
||||
case 7:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 8:
|
||||
if (thickness > 1){
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, true, false);
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false)
|
||||
} else if (thickness == 1){
|
||||
Voxels.setVoxel(x - voxelSize, y, z, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x + voxelSize, y, z, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x, y, z - voxelSize, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x, y, z + voxelSize, voxelSize, color.r, color.g, color.b);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function computeSide(x, z, coreWidth) {
|
||||
// side:
|
||||
// 8 == all directions
|
||||
// 0 1 2
|
||||
// 3 -1 4
|
||||
// 5 6 7
|
||||
|
||||
// if the core is only a single block, we can grow out in all directions
|
||||
if (coreWidth == 1){
|
||||
return 8;
|
||||
}
|
||||
|
||||
// Back face
|
||||
if (z == 0) {
|
||||
if (x == 0) {
|
||||
return 0;
|
||||
} else if (x == coreWidth - 1) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Front face
|
||||
if (z == (coreWidth - 1)) {
|
||||
if (x == 0) {
|
||||
return 5;
|
||||
} else if (x == (coreWidth - 1)) {
|
||||
return 7;
|
||||
} else {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
// Left face
|
||||
if (x == 0) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Right face
|
||||
if (x == (coreWidth - 1)) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
//Interior
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
function growTree(x, y, z, tree) {
|
||||
|
||||
// The size of the tree, from 0-1
|
||||
var treeSize = Math.random();
|
||||
|
||||
// Get tree properties by interpolating with the treeSize
|
||||
var height = interpolate(tree.height, treeSize);
|
||||
var baseHeight = Math.ceil(tree.middleHeight * height);
|
||||
var bottomThickness = interpolate(tree.bottomThickness, treeSize);
|
||||
var middleThickness = interpolate(tree.middleThickness, treeSize);
|
||||
var topThickness = interpolate(tree.topThickness, treeSize);
|
||||
var coreWidth = Math.ceil(interpolate(tree.coreWidth, treeSize));
|
||||
|
||||
var thickness;
|
||||
var side;
|
||||
|
||||
//Loop upwards through each slice of the tree
|
||||
for (var i = 0; i < height; i++){
|
||||
|
||||
//Branch properties are based on current height as well as the overall tree size
|
||||
var branchChance = interpolate(tree.branchChance, i / height);
|
||||
var branchLength = Math.ceil(interpolate(tree.branchLength, (i / height) * treeSize));
|
||||
var branchThickness = Math.round(interpolate(tree.branchThickness, (i / height) * treeSize));
|
||||
|
||||
// Get the "thickness" of the tree by doing linear interpolation between the middle thickness
|
||||
// and the top and bottom thickness.
|
||||
if (i <= baseHeight && baseHeight != 0){
|
||||
thickness = (i / (baseHeight) * (middleThickness - bottomThickness) + bottomThickness);
|
||||
} else {
|
||||
var denom = ((height - baseHeight)) * (topThickness - middleThickness) + middleThickness;
|
||||
if (denom != 0) {
|
||||
thickness = (i - baseHeight) / denom;
|
||||
} else {
|
||||
thickness = 0;
|
||||
}
|
||||
}
|
||||
// The core of the tree is a vertical rectangular prism through the middle of the tree
|
||||
|
||||
//Loop through the "core", which helps shape the trunk
|
||||
var startX = x - Math.floor(coreWidth / 2) * voxelSize;
|
||||
var startZ = z - Math.floor(coreWidth / 2) * voxelSize;
|
||||
for (var j = 0; j < coreWidth; j++) {
|
||||
for (var k = 0; k < coreWidth; k++) {
|
||||
//determine which side of the tree we are on
|
||||
side = computeSide(j, k, coreWidth);
|
||||
//grow a horizontal slice of the tree
|
||||
growHorizontalSlice(startX + j * voxelSize, y + i * voxelSize, startZ + k * voxelSize, Math.floor(thickness), tree.wood, side);
|
||||
|
||||
// Branches
|
||||
if (side != -1) {
|
||||
var r = Math.random();
|
||||
if (r <= branchChance){
|
||||
var dir = Math.floor((Math.random() * 4));
|
||||
makeBranch(startX + j * voxelSize, y + i * voxelSize, startZ + k * voxelSize, branchLength, branchLength, dir, branchThickness, tree.wood, tree.leaves);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
makeSphere(x, y + height * voxelSize, z, topThickness + coreWidth + tree.leafCapSizeOffset, tree.leaves);
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
var mouseX = event.x;
|
||||
var mouseY = event.y;
|
||||
|
||||
var clickedOnSomething = false;
|
||||
// Check if we clicked an overlay
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: mouseX, y: mouseY});
|
||||
|
||||
if (clickedOverlay == voxelTool) {
|
||||
voxelToolSelected = !voxelToolSelected;
|
||||
|
||||
if (voxelToolSelected == true) {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: activeUIColor
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: UIColor
|
||||
});
|
||||
}
|
||||
|
||||
clickedOnSomething = true;
|
||||
} else if (scaleSelector.clicked(event.x, event.y)) {
|
||||
clickedOnSomething = true;
|
||||
voxelSize = scaleSelector.scale;
|
||||
}
|
||||
|
||||
// Return if we clicked on the UI or the voxel tool is disabled
|
||||
if (clickedOnSomething || !voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the picking ray for the click
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "add");
|
||||
|
||||
// Currently not in use, could randomly select a tree
|
||||
var treeIndex = Math.floor(Math.random() * treeTypes.length);
|
||||
|
||||
// Grow the first tree type
|
||||
growTree(resultVoxel.x, resultVoxel.y, resultVoxel.z, treeTypes[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function scriptEnding() {
|
||||
Overlays.deleteOverlay(linePreviewTop);
|
||||
Overlays.deleteOverlay(linePreviewBottom);
|
||||
Overlays.deleteOverlay(linePreviewLeft);
|
||||
Overlays.deleteOverlay(linePreviewRight);
|
||||
scaleSelector.cleanup();
|
||||
Overlays.deleteOverlay(voxelTool);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
Voxels.setPacketsPerSecond(10000);
|
|
@ -19,8 +19,8 @@
|
|||
var damping = 0.9;
|
||||
var position = { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z };
|
||||
var joysticksCaptured = false;
|
||||
var THRUST_CONTROLLER = 1;
|
||||
var VIEW_CONTROLLER = 0;
|
||||
var THRUST_CONTROLLER = 0;
|
||||
var VIEW_CONTROLLER = 1;
|
||||
var INITIAL_THRUST_MULTPLIER = 1.0;
|
||||
var THRUST_INCREASE_RATE = 1.05;
|
||||
var MAX_THRUST_MULTIPLIER = 75.0;
|
||||
|
|
|
@ -34,6 +34,7 @@ var noMode = 0;
|
|||
var orbitMode = 1;
|
||||
var radialMode = 2;
|
||||
var panningMode = 3;
|
||||
var detachedMode = 4;
|
||||
|
||||
var mode = noMode;
|
||||
|
||||
|
@ -48,6 +49,9 @@ var radius = 0.0;
|
|||
var azimuth = 0.0;
|
||||
var altitude = 0.0;
|
||||
|
||||
var avatarPosition;
|
||||
var avatarOrientation;
|
||||
|
||||
|
||||
function handleRadialMode(dx, dy) {
|
||||
azimuth += dx / AZIMUTH_RATE;
|
||||
|
@ -108,7 +112,7 @@ function restoreCameraState() {
|
|||
}
|
||||
|
||||
function handleModes() {
|
||||
var newMode = noMode;
|
||||
var newMode = (mode == noMode) ? noMode : detachedMode;
|
||||
if (alt) {
|
||||
if (control) {
|
||||
if (shift) {
|
||||
|
@ -121,6 +125,22 @@ function handleModes() {
|
|||
}
|
||||
}
|
||||
|
||||
// if entering detachMode
|
||||
if (newMode == detachedMode && mode != detachedMode) {
|
||||
avatarPosition = MyAvatar.position;
|
||||
avatarOrientation = MyAvatar.orientation;
|
||||
}
|
||||
// if leaving detachMode
|
||||
if (mode == detachedMode && newMode == detachedMode &&
|
||||
(avatarPosition.x != MyAvatar.position.x ||
|
||||
avatarPosition.y != MyAvatar.position.y ||
|
||||
avatarPosition.z != MyAvatar.position.z ||
|
||||
avatarOrientation.x != MyAvatar.orientation.x ||
|
||||
avatarOrientation.y != MyAvatar.orientation.y ||
|
||||
avatarOrientation.z != MyAvatar.orientation.z ||
|
||||
avatarOrientation.w != MyAvatar.orientation.w)) {
|
||||
newMode = noMode;
|
||||
}
|
||||
// if leaving noMode
|
||||
if (mode == noMode && newMode != noMode) {
|
||||
saveCameraState();
|
||||
|
@ -177,30 +197,45 @@ function keyReleaseEvent(event) {
|
|||
|
||||
function mousePressEvent(event) {
|
||||
if (alt && !isActive) {
|
||||
isActive = true;
|
||||
mouseLastX = event.x;
|
||||
mouseLastY = event.y;
|
||||
|
||||
// Compute trajectories related values
|
||||
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var voxelIntersection = Voxels.findRayIntersection(pickRay);
|
||||
var modelIntersection = Models.findRayIntersection(pickRay);
|
||||
|
||||
position = Camera.getPosition();
|
||||
|
||||
avatarTarget = MyAvatar.getTargetAvatarPosition();
|
||||
voxelTarget = intersection.intersection;
|
||||
if (Vec3.length(Vec3.subtract(avatarTarget, position)) < Vec3.length(Vec3.subtract(voxelTarget, position))) {
|
||||
if (avatarTarget.x != 0 || avatarTarget.y != 0 || avatarTarget.z != 0) {
|
||||
center = avatarTarget;
|
||||
} else {
|
||||
center = voxelTarget;
|
||||
}
|
||||
} else {
|
||||
if (voxelTarget.x != 0 || voxelTarget.y != 0 || voxelTarget.z != 0) {
|
||||
center = voxelTarget;
|
||||
} else {
|
||||
center = avatarTarget;
|
||||
}
|
||||
var avatarTarget = MyAvatar.getTargetAvatarPosition();
|
||||
var voxelTarget = voxelIntersection.intersection;
|
||||
|
||||
|
||||
var distance = -1;
|
||||
var string;
|
||||
|
||||
if (modelIntersection.intersects && modelIntersection.accurate) {
|
||||
distance = modelIntersection.distance;
|
||||
center = modelIntersection.modelProperties.position;
|
||||
string = "Inspecting model";
|
||||
}
|
||||
|
||||
if ((distance == -1 || Vec3.length(Vec3.subtract(avatarTarget, position)) < distance) &&
|
||||
(avatarTarget.x != 0 || avatarTarget.y != 0 || avatarTarget.z != 0)) {
|
||||
distance = Vec3.length(Vec3.subtract(avatarTarget, position));
|
||||
center = avatarTarget;
|
||||
string = "Inspecting avatar";
|
||||
}
|
||||
|
||||
if ((distance == -1 || Vec3.length(Vec3.subtract(voxelTarget, position)) < distance) &&
|
||||
(voxelTarget.x != 0 || voxelTarget.y != 0 || voxelTarget.z != 0)) {
|
||||
distance = Vec3.length(Vec3.subtract(voxelTarget, position));
|
||||
center = voxelTarget;
|
||||
string = "Inspecting voxel";
|
||||
}
|
||||
|
||||
if (distance == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector = Vec3.subtract(position, center);
|
||||
|
@ -209,6 +244,8 @@ function mousePressEvent(event) {
|
|||
altitude = Math.asin(vector.y / Vec3.length(vector));
|
||||
|
||||
Camera.keepLookingAt(center);
|
||||
print(string);
|
||||
isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,6 +272,10 @@ function mouseMoveEvent(event) {
|
|||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
handleModes();
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
if (mode != noMode) {
|
||||
restoreCameraState();
|
||||
|
@ -248,4 +289,5 @@ Controller.mousePressEvent.connect(mousePressEvent);
|
|||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
BIN
interface/resources/images/sixense-reticle.png
Normal file
BIN
interface/resources/images/sixense-reticle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -150,6 +150,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
_lastMouseMove(usecTimestampNow()),
|
||||
_lastMouseMoveType(QEvent::MouseMove),
|
||||
_mouseHidden(false),
|
||||
_seenMouseMove(false),
|
||||
_touchAvgX(0.0f),
|
||||
|
@ -158,7 +159,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_mousePressed(false),
|
||||
_audio(STARTUP_JITTER_SAMPLES),
|
||||
_enableProcessVoxelsThread(true),
|
||||
_voxelProcessor(),
|
||||
_octreeProcessor(),
|
||||
_voxelHideShowThread(&_voxels),
|
||||
_packetsPerSecond(0),
|
||||
_bytesPerSecond(0),
|
||||
|
@ -418,7 +419,7 @@ Application::~Application() {
|
|||
_audio.thread()->quit();
|
||||
_audio.thread()->wait();
|
||||
|
||||
_voxelProcessor.terminate();
|
||||
_octreeProcessor.terminate();
|
||||
_voxelHideShowThread.terminate();
|
||||
_voxelEditSender.terminate();
|
||||
_particleEditSender.terminate();
|
||||
|
@ -517,7 +518,7 @@ void Application::initializeGL() {
|
|||
qDebug( "init() complete.");
|
||||
|
||||
// create thread for parsing of voxel data independent of the main network and rendering threads
|
||||
_voxelProcessor.initialize(_enableProcessVoxelsThread);
|
||||
_octreeProcessor.initialize(_enableProcessVoxelsThread);
|
||||
_voxelEditSender.initialize(_enableProcessVoxelsThread);
|
||||
_voxelHideShowThread.initialize(_enableProcessVoxelsThread);
|
||||
_particleEditSender.initialize(_enableProcessVoxelsThread);
|
||||
|
@ -1089,6 +1090,16 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
|||
}
|
||||
|
||||
void Application::mouseMoveEvent(QMouseEvent* event) {
|
||||
|
||||
bool showMouse = true;
|
||||
// If this mouse move event is emitted by a controller, dont show the mouse cursor
|
||||
if (event->type() == CONTROLLER_MOVE_EVENT) {
|
||||
showMouse = false;
|
||||
}
|
||||
|
||||
// Used by application overlay to determine how to draw cursor(s)
|
||||
_lastMouseMoveType = event->type();
|
||||
|
||||
_controllerScriptingInterface.emitMouseMoveEvent(event); // send events to any registered scripts
|
||||
|
||||
// if one of our scripts have asked to capture this event, then stop processing it
|
||||
|
@ -1096,10 +1107,9 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
_lastMouseMove = usecTimestampNow();
|
||||
|
||||
if (_mouseHidden && !OculusManager::isConnected()) {
|
||||
if (_mouseHidden && showMouse && !OculusManager::isConnected()) {
|
||||
getGLWidget()->setCursor(Qt::ArrowCursor);
|
||||
_mouseHidden = false;
|
||||
_seenMouseMove = true;
|
||||
|
@ -1369,6 +1379,9 @@ void Application::setEnable3DTVMode(bool enable3DTVMode) {
|
|||
resizeGL(_glWidget->width(),_glWidget->height());
|
||||
}
|
||||
|
||||
void Application::setEnableVRMode(bool enableVRMode) {
|
||||
resizeGL(_glWidget->width(), _glWidget->height());
|
||||
}
|
||||
|
||||
void Application::setRenderVoxels(bool voxelRender) {
|
||||
_voxelEditSender.setShouldSend(voxelRender);
|
||||
|
@ -1884,7 +1897,7 @@ void Application::updateThreads(float deltaTime) {
|
|||
|
||||
// parse voxel packets
|
||||
if (!_enableProcessVoxelsThread) {
|
||||
_voxelProcessor.threadRoutine();
|
||||
_octreeProcessor.threadRoutine();
|
||||
_voxelHideShowThread.threadRoutine();
|
||||
_voxelEditSender.threadRoutine();
|
||||
_particleEditSender.threadRoutine();
|
||||
|
@ -2095,7 +2108,7 @@ void Application::updateMyAvatar(float deltaTime) {
|
|||
}
|
||||
}
|
||||
|
||||
// sent a nack packet containing missing sequence numbers of received packets
|
||||
// sent nack packets containing missing sequence numbers of received packets from nodes
|
||||
{
|
||||
quint64 now = usecTimestampNow();
|
||||
quint64 sinceLastNack = now - _lastNackTime;
|
||||
|
@ -2125,6 +2138,12 @@ void Application::sendNack() {
|
|||
|| node->getType() == NodeType::ModelServer)
|
||||
) {
|
||||
|
||||
// if there are octree packets from this node that are waiting to be processed,
|
||||
// don't send a NACK since the missing packets may be among those waiting packets.
|
||||
if (_octreeProcessor.hasPacketsToProcessFrom(node)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QUuid nodeUUID = node->getUUID();
|
||||
|
||||
_octreeSceneStatsLock.lockForRead();
|
||||
|
@ -3242,6 +3261,11 @@ void Application::nodeAdded(SharedNodePointer node) {
|
|||
}
|
||||
|
||||
void Application::nodeKilled(SharedNodePointer node) {
|
||||
|
||||
// this is here because connecting NodeList::nodeKilled to OctreePacketProcessor::nodeKilled doesn't work:
|
||||
// OctreePacketProcessor::nodeKilled is not called when NodeList::nodeKilled is emitted for some reason.
|
||||
_octreeProcessor.nodeKilled(node);
|
||||
|
||||
if (node->getType() == NodeType::VoxelServer) {
|
||||
QUuid nodeUUID = node->getUUID();
|
||||
// see if this is the first we've heard of this node...
|
||||
|
@ -3487,8 +3511,10 @@ void Application::saveScripts() {
|
|||
}
|
||||
|
||||
ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScriptFromEditor) {
|
||||
if(loadScriptFromEditor && _scriptEnginesHash.contains(scriptName) && !_scriptEnginesHash[scriptName]->isFinished()){
|
||||
return _scriptEnginesHash[scriptName];
|
||||
QUrl scriptUrl(scriptName);
|
||||
const QString& scriptURLString = scriptUrl.toString();
|
||||
if(loadScriptFromEditor && _scriptEnginesHash.contains(scriptURLString) && !_scriptEnginesHash[scriptURLString]->isFinished()){
|
||||
return _scriptEnginesHash[scriptURLString];
|
||||
}
|
||||
|
||||
ScriptEngine* scriptEngine;
|
||||
|
@ -3496,14 +3522,14 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
|||
scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface);
|
||||
} else {
|
||||
// start the script on a new thread...
|
||||
QUrl scriptUrl(scriptName);
|
||||
scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface);
|
||||
_scriptEnginesHash.insert(scriptName, scriptEngine);
|
||||
|
||||
if (!scriptEngine->hasScript()) {
|
||||
qDebug() << "Application::loadScript(), script failed to load...";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_scriptEnginesHash.insert(scriptURLString, scriptEngine);
|
||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
#include "voxels/VoxelFade.h"
|
||||
#include "voxels/VoxelHideShowThread.h"
|
||||
#include "voxels/VoxelImporter.h"
|
||||
#include "voxels/VoxelPacketProcessor.h"
|
||||
#include "voxels/OctreePacketProcessor.h"
|
||||
#include "voxels/VoxelSystem.h"
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ static const float MIRROR_FIELD_OF_VIEW = 30.0f;
|
|||
class Application : public QApplication {
|
||||
Q_OBJECT
|
||||
|
||||
friend class VoxelPacketProcessor;
|
||||
friend class OctreePacketProcessor;
|
||||
friend class VoxelEditPacketSender;
|
||||
friend class DatagramProcessor;
|
||||
|
||||
|
@ -192,7 +192,7 @@ public:
|
|||
ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; }
|
||||
VoxelSystem* getVoxels() { return &_voxels; }
|
||||
VoxelTree* getVoxelTree() { return _voxels.getTree(); }
|
||||
const VoxelPacketProcessor& getVoxelPacketProcessor() const { return _voxelProcessor; }
|
||||
const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; }
|
||||
ParticleTreeRenderer* getParticles() { return &_particles; }
|
||||
MetavoxelSystem* getMetavoxels() { return &_metavoxels; }
|
||||
ModelTreeRenderer* getModels() { return &_models; }
|
||||
|
@ -206,6 +206,7 @@ public:
|
|||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
int getMouseX() const { return _mouseX; }
|
||||
int getMouseY() const { return _mouseY; }
|
||||
unsigned int getLastMouseMoveType() const { return _lastMouseMoveType; }
|
||||
Faceplus* getFaceplus() { return &_faceplus; }
|
||||
Faceshift* getFaceshift() { return &_faceshift; }
|
||||
Visage* getVisage() { return &_visage; }
|
||||
|
@ -345,6 +346,7 @@ private slots:
|
|||
|
||||
void setFullscreen(bool fullscreen);
|
||||
void setEnable3DTVMode(bool enable3DTVMode);
|
||||
void setEnableVRMode(bool enableVRMode);
|
||||
void cameraMenuChanged();
|
||||
|
||||
glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint);
|
||||
|
@ -505,6 +507,7 @@ private:
|
|||
int _mouseDragStartedX;
|
||||
int _mouseDragStartedY;
|
||||
quint64 _lastMouseMove;
|
||||
unsigned int _lastMouseMoveType;
|
||||
bool _mouseHidden;
|
||||
bool _seenMouseMove;
|
||||
|
||||
|
@ -521,6 +524,7 @@ private:
|
|||
|
||||
QSet<int> _keysPressed;
|
||||
|
||||
|
||||
GeometryCache _geometryCache;
|
||||
AnimationCache _animationCache;
|
||||
TextureCache _textureCache;
|
||||
|
@ -533,7 +537,7 @@ private:
|
|||
Audio _audio;
|
||||
|
||||
bool _enableProcessVoxelsThread;
|
||||
VoxelPacketProcessor _voxelProcessor;
|
||||
OctreePacketProcessor _octreeProcessor;
|
||||
VoxelHideShowThread _voxelHideShowThread;
|
||||
VoxelEditPacketSender _voxelEditSender;
|
||||
ParticleEditPacketSender _particleEditSender;
|
||||
|
|
|
@ -306,7 +306,7 @@ void linearResampling(int16_t* sourceSamples, int16_t* destinationSamples,
|
|||
} else {
|
||||
// this is a 48 to 24 resampling but both source and destination are two channels
|
||||
// squish two samples into one in each channel
|
||||
for (int i = 0; i < numSourceSamples; i += 4) {
|
||||
for (unsigned int i = 0; i < numSourceSamples; i += 4) {
|
||||
destinationSamples[i / 2] = (sourceSamples[i] / 2) + (sourceSamples[i + 2] / 2);
|
||||
destinationSamples[(i / 2) + 1] = (sourceSamples[i + 1] / 2) + (sourceSamples[i + 3] / 2);
|
||||
}
|
||||
|
@ -1419,7 +1419,7 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
|
|||
// proportional to the accelerator ratio.
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
const float Audio::CALLBACK_ACCELERATOR_RATIO = 0.4f;
|
||||
const float Audio::CALLBACK_ACCELERATOR_RATIO = 0.1f;
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
|
|
|
@ -71,7 +71,7 @@ void DatagramProcessor::processDatagrams() {
|
|||
case PacketTypeOctreeStats:
|
||||
case PacketTypeEnvironmentData: {
|
||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
|
||||
"Application::networkReceive()... _octreeProcessor.queueReceivedPacket()");
|
||||
|
||||
bool wantExtraDebugging = application->getLogger()->extraDebugging();
|
||||
if (wantExtraDebugging && packetTypeForPacket(incomingPacket) == PacketTypeVoxelData) {
|
||||
|
@ -92,7 +92,7 @@ void DatagramProcessor::processDatagrams() {
|
|||
|
||||
if (matchedNode) {
|
||||
// add this packet to our list of voxel packets and process them on the voxel processing
|
||||
application->_voxelProcessor.queueReceivedPacket(matchedNode, incomingPacket);
|
||||
application->_octreeProcessor.queueReceivedPacket(matchedNode, incomingPacket);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "ui/ModelsBrowser.h"
|
||||
#include "ui/LoginDialog.h"
|
||||
#include "ui/NodeBounds.h"
|
||||
#include "devices/OculusManager.h"
|
||||
|
||||
|
||||
Menu* Menu::_instance = NULL;
|
||||
|
@ -83,6 +84,7 @@ Menu::Menu() :
|
|||
_audioJitterBufferSamples(0),
|
||||
_bandwidthDialog(NULL),
|
||||
_fieldOfView(DEFAULT_FIELD_OF_VIEW_DEGREES),
|
||||
_realWorldFieldOfView(DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
|
||||
_faceshiftEyeDeflection(DEFAULT_FACESHIFT_EYE_DEFLECTION),
|
||||
_frustumDrawMode(FRUSTUM_DRAW_MODE_ALL),
|
||||
_viewFrustumOffset(DEFAULT_FRUSTUM_OFFSET),
|
||||
|
@ -91,6 +93,9 @@ Menu::Menu() :
|
|||
_lodToolsDialog(NULL),
|
||||
_maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM),
|
||||
_voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE),
|
||||
_oculusUIAngularSize(DEFAULT_OCULUS_UI_ANGULAR_SIZE),
|
||||
_sixenseReticleMoveSpeed(DEFAULT_SIXENSE_RETICLE_MOVE_SPEED),
|
||||
_invertSixenseButtons(DEFAULT_INVERT_SIXENSE_MOUSE_BUTTONS),
|
||||
_automaticAvatarLOD(true),
|
||||
_avatarLODDecreaseFPS(DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS),
|
||||
_avatarLODIncreaseFPS(ADJUST_LOD_UP_FPS),
|
||||
|
@ -103,6 +108,7 @@ Menu::Menu() :
|
|||
_fastFPSAverage(ONE_SECOND_OF_FRAMES),
|
||||
_loginAction(NULL),
|
||||
_preferencesDialog(NULL),
|
||||
_loginDialog(NULL),
|
||||
_snapshotsLocation()
|
||||
{
|
||||
Application *appInstance = Application::getInstance();
|
||||
|
@ -126,7 +132,7 @@ Menu::Menu() :
|
|||
toggleLoginMenuItem();
|
||||
|
||||
// connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item
|
||||
connect(&accountManager, &AccountManager::accessTokenChanged, this, &Menu::toggleLoginMenuItem);
|
||||
connect(&accountManager, &AccountManager::profileChanged, this, &Menu::toggleLoginMenuItem);
|
||||
connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem);
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Scripts");
|
||||
|
@ -164,6 +170,8 @@ Menu::Menu() :
|
|||
Qt::Key_At,
|
||||
this,
|
||||
SLOT(goTo()));
|
||||
connect(&LocationManager::getInstance(), &LocationManager::multipleDestinationsFound,
|
||||
this, &Menu::multipleDestinationsDecision);
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Upload Avatar Model");
|
||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::UploadHead, 0, Application::getInstance(), SLOT(uploadHead()));
|
||||
|
@ -253,6 +261,11 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::FullscreenMirror, Qt::Key_H, false,
|
||||
appInstance, SLOT(cameraMenuChanged()));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::EnableVRMode, 0,
|
||||
false,
|
||||
appInstance,
|
||||
SLOT(setEnableVRMode(bool)));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Enable3DTVMode, 0,
|
||||
false,
|
||||
appInstance,
|
||||
|
@ -320,7 +333,7 @@ Menu::Menu() :
|
|||
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, "None", 0, true));
|
||||
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::SimpleShadows, 0, false));
|
||||
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::CascadedShadows, 0, false));
|
||||
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::BuckyBalls, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Particles, 0, true);
|
||||
|
@ -379,6 +392,9 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(oculusOptionsMenu, MenuOption::AllowOculusCameraModeChange, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(oculusOptionsMenu, MenuOption::DisplayOculusOverlays, 0, true);
|
||||
|
||||
QMenu* sixenseOptionsMenu = developerMenu->addMenu("Sixense Options");
|
||||
addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu, MenuOption::SixenseMouseInput, 0, true);
|
||||
|
||||
QMenu* handOptionsMenu = developerMenu->addMenu("Hand Options");
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu,
|
||||
|
@ -397,7 +413,7 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::DisableNackPackets, 0, false);
|
||||
|
||||
addDisabledActionAndSeparator(developerMenu, "Testing");
|
||||
|
||||
|
||||
QMenu* timingMenu = developerMenu->addMenu("Timing and Statistics Tools");
|
||||
QMenu* perfTimerMenu = timingMenu->addMenu("Performance Timer");
|
||||
addCheckableActionToQMenuAndActionHash(perfTimerMenu, MenuOption::DisplayTimingDetails, 0, true);
|
||||
|
@ -452,7 +468,7 @@ Menu::Menu() :
|
|||
false,
|
||||
appInstance->getAudio(),
|
||||
SLOT(toggleToneInjection()));
|
||||
addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioScope,
|
||||
addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioScope,
|
||||
Qt::CTRL | Qt::Key_P, false,
|
||||
appInstance->getAudio(),
|
||||
SLOT(toggleScope()));
|
||||
|
@ -913,9 +929,11 @@ void sendFakeEnterEvent() {
|
|||
const float DIALOG_RATIO_OF_WINDOW = 0.30f;
|
||||
|
||||
void Menu::loginForCurrentDomain() {
|
||||
LoginDialog* loginDialog = new LoginDialog(Application::getInstance()->getWindow());
|
||||
loginDialog->show();
|
||||
loginDialog->resizeAndPosition(false);
|
||||
if (!_loginDialog) {
|
||||
_loginDialog = new LoginDialog(Application::getInstance()->getWindow());
|
||||
_loginDialog->show();
|
||||
_loginDialog->resizeAndPosition(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::editPreferences() {
|
||||
|
@ -1060,9 +1078,7 @@ bool Menu::goToURL(QString location) {
|
|||
}
|
||||
|
||||
void Menu::goToUser(const QString& user) {
|
||||
LocationManager* manager = &LocationManager::getInstance();
|
||||
manager->goTo(user);
|
||||
connect(manager, &LocationManager::multipleDestinationsFound, this, &Menu::multipleDestinationsDecision);
|
||||
LocationManager::getInstance().goTo(user);
|
||||
}
|
||||
|
||||
/// Open a url, shortcutting any "hifi" scheme URLs to the local application.
|
||||
|
@ -1084,13 +1100,10 @@ void Menu::multipleDestinationsDecision(const QJsonObject& userData, const QJson
|
|||
int userResponse = msgBox.exec();
|
||||
|
||||
if (userResponse == QMessageBox::Ok) {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromResponse(userData);
|
||||
Application::getInstance()->getAvatar()->goToLocationFromAddress(userData["address"].toObject());
|
||||
} else if (userResponse == QMessageBox::Open) {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromResponse(userData);
|
||||
Application::getInstance()->getAvatar()->goToLocationFromAddress(placeData["address"].toObject());
|
||||
}
|
||||
|
||||
LocationManager* manager = reinterpret_cast<LocationManager*>(sender());
|
||||
disconnect(manager, &LocationManager::multipleDestinationsFound, this, &Menu::multipleDestinationsDecision);
|
||||
}
|
||||
|
||||
void Menu::muteEnvironment() {
|
||||
|
@ -1763,4 +1776,3 @@ QString Menu::getSnapshotsLocation() const {
|
|||
}
|
||||
return _snapshotsLocation;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "ui/PreferencesDialog.h"
|
||||
#include "ui/ChatWindow.h"
|
||||
#include "ui/JSConsole.h"
|
||||
#include "ui/LoginDialog.h"
|
||||
#include "ui/ScriptEditorWindow.h"
|
||||
|
||||
const float ADJUST_LOD_DOWN_FPS = 40.0;
|
||||
|
@ -89,6 +90,12 @@ public:
|
|||
void setFieldOfView(float fieldOfView) { _fieldOfView = fieldOfView; }
|
||||
float getRealWorldFieldOfView() const { return _realWorldFieldOfView; }
|
||||
void setRealWorldFieldOfView(float realWorldFieldOfView) { _realWorldFieldOfView = realWorldFieldOfView; }
|
||||
float getOculusUIAngularSize() const { return _oculusUIAngularSize; }
|
||||
void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; }
|
||||
float getSixenseReticleMoveSpeed() const { return _sixenseReticleMoveSpeed; }
|
||||
void setSixenseReticleMoveSpeed(float sixenseReticleMoveSpeed) { _sixenseReticleMoveSpeed = sixenseReticleMoveSpeed; }
|
||||
bool getInvertSixenseButtons() const { return _invertSixenseButtons; }
|
||||
void setInvertSixenseButtons(bool invertSixenseButtons) { _invertSixenseButtons = invertSixenseButtons; }
|
||||
|
||||
float getFaceshiftEyeDeflection() const { return _faceshiftEyeDeflection; }
|
||||
void setFaceshiftEyeDeflection(float faceshiftEyeDeflection) { _faceshiftEyeDeflection = faceshiftEyeDeflection; }
|
||||
|
@ -254,6 +261,9 @@ private:
|
|||
LodToolsDialog* _lodToolsDialog;
|
||||
int _maxVoxels;
|
||||
float _voxelSizeScale;
|
||||
float _oculusUIAngularSize;
|
||||
float _sixenseReticleMoveSpeed;
|
||||
bool _invertSixenseButtons;
|
||||
bool _automaticAvatarLOD;
|
||||
float _avatarLODDecreaseFPS;
|
||||
float _avatarLODIncreaseFPS;
|
||||
|
@ -270,6 +280,7 @@ private:
|
|||
QPointer<PreferencesDialog> _preferencesDialog;
|
||||
QPointer<AttachmentsDialog> _attachmentsDialog;
|
||||
QPointer<AnimationsDialog> _animationsDialog;
|
||||
QPointer<LoginDialog> _loginDialog;
|
||||
QAction* _chatAction;
|
||||
QString _snapshotsLocation;
|
||||
};
|
||||
|
@ -334,6 +345,7 @@ namespace MenuOption {
|
|||
const QString EchoLocalAudio = "Echo Local Audio";
|
||||
const QString EchoServerAudio = "Echo Server Audio";
|
||||
const QString Enable3DTVMode = "Enable 3DTV Mode";
|
||||
const QString EnableVRMode = "Enable VR Mode";
|
||||
const QString ExpandMiscAvatarTiming = "Expand Misc MyAvatar Timing";
|
||||
const QString ExpandAvatarUpdateTiming = "Expand MyAvatar update Timing";
|
||||
const QString ExpandAvatarSimulateTiming = "Expand MyAvatar simulate Timing";
|
||||
|
@ -397,6 +409,7 @@ namespace MenuOption {
|
|||
const QString SettingsExport = "Export Settings";
|
||||
const QString SettingsImport = "Import Settings";
|
||||
const QString SimpleShadows = "Simple";
|
||||
const QString SixenseMouseInput = "Enable Sixense Mouse Input";
|
||||
const QString ShowBordersVoxelNodes = "Show Voxel Nodes";
|
||||
const QString ShowBordersModelNodes = "Show Model Nodes";
|
||||
const QString ShowBordersParticleNodes = "Show Particle Nodes";
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
#include "ui/TextRenderer.h"
|
||||
#include "VoxelConstants.h"
|
||||
|
@ -409,8 +411,44 @@ void runTimingTests() {
|
|||
|
||||
float NSEC_TO_USEC = 1.0f / 1000.0f;
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("QElapsedTimer::nsecElapsed() usecs: %f", elapsedUsecs / (float) numTests);
|
||||
qDebug("QElapsedTimer::nsecElapsed() usecs: %f", elapsedUsecs);
|
||||
|
||||
// Test sleep functions for accuracy
|
||||
startTime.start();
|
||||
QThread::msleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("QThread::msleep(1) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
QThread::sleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("QThread::sleep(1) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
usleep(1);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("usleep(1) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
usleep(10);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("usleep(10) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
usleep(100);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("usleep(100) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
usleep(1000);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("usleep(1000) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
startTime.start();
|
||||
usleep(15000);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("usleep(15000) ms: %f", elapsedUsecs / 1000.0f);
|
||||
|
||||
// Random number generation
|
||||
startTime.start();
|
||||
for (int i = 0; i < numTests; i++) {
|
||||
|
|
|
@ -23,7 +23,7 @@ XmppClient::XmppClient() :
|
|||
_xmppMUCManager()
|
||||
{
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
connect(&accountManager, SIGNAL(accessTokenChanged()), this, SLOT(connectToServer()));
|
||||
connect(&accountManager, SIGNAL(profileChanged()), this, SLOT(connectToServer()));
|
||||
connect(&accountManager, SIGNAL(logoutComplete()), this, SLOT(disconnectFromServer()));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) {
|
|||
}
|
||||
setTranslation(neckPosition);
|
||||
glm::quat neckParentRotation;
|
||||
if (!owningAvatar->getSkeletonModel().getNeckParentRotation(neckParentRotation)) {
|
||||
if (!owningAvatar->getSkeletonModel().getNeckParentRotationFromDefaultOrientation(neckParentRotation)) {
|
||||
neckParentRotation = owningAvatar->getOrientation();
|
||||
}
|
||||
setRotation(neckParentRotation);
|
||||
|
|
|
@ -1631,44 +1631,46 @@ void MyAvatar::resetSize() {
|
|||
}
|
||||
|
||||
void MyAvatar::goToLocationFromResponse(const QJsonObject& jsonObject) {
|
||||
|
||||
if (jsonObject["status"].toString() == "success") {
|
||||
|
||||
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
|
||||
sendKillAvatar();
|
||||
|
||||
QJsonObject locationObject = jsonObject["data"].toObject()["address"].toObject();
|
||||
QString positionString = locationObject["position"].toString();
|
||||
QString orientationString = locationObject["orientation"].toString();
|
||||
QString domainHostnameString = locationObject["domain"].toString();
|
||||
|
||||
qDebug() << "Changing domain to" << domainHostnameString <<
|
||||
", position to" << positionString <<
|
||||
", and orientation to" << orientationString;
|
||||
|
||||
QStringList coordinateItems = positionString.split(',');
|
||||
QStringList orientationItems = orientationString.split(',');
|
||||
|
||||
NodeList::getInstance()->getDomainHandler().setHostname(domainHostnameString);
|
||||
|
||||
// orient the user to face the target
|
||||
glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
|
||||
orientationItems[1].toFloat(),
|
||||
orientationItems[2].toFloat())))
|
||||
* glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
setOrientation(newOrientation);
|
||||
|
||||
// move the user a couple units away
|
||||
const float DISTANCE_TO_USER = 2.0f;
|
||||
glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
|
||||
coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
||||
setPosition(newPosition);
|
||||
emit transformChanged();
|
||||
goToLocationFromAddress(locationObject);
|
||||
} else {
|
||||
QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found.");
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::goToLocationFromAddress(const QJsonObject& locationObject) {
|
||||
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
|
||||
sendKillAvatar();
|
||||
|
||||
QString positionString = locationObject["position"].toString();
|
||||
QString orientationString = locationObject["orientation"].toString();
|
||||
QString domainHostnameString = locationObject["domain"].toString();
|
||||
|
||||
qDebug() << "Changing domain to" << domainHostnameString <<
|
||||
", position to" << positionString <<
|
||||
", and orientation to" << orientationString;
|
||||
|
||||
QStringList coordinateItems = positionString.split(',');
|
||||
QStringList orientationItems = orientationString.split(',');
|
||||
|
||||
NodeList::getInstance()->getDomainHandler().setHostname(domainHostnameString);
|
||||
|
||||
// orient the user to face the target
|
||||
glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
|
||||
orientationItems[1].toFloat(),
|
||||
orientationItems[2].toFloat())))
|
||||
* glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
setOrientation(newOrientation);
|
||||
|
||||
// move the user a couple units away
|
||||
const float DISTANCE_TO_USER = 2.0f;
|
||||
glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
|
||||
coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
||||
setPosition(newPosition);
|
||||
emit transformChanged();
|
||||
}
|
||||
|
||||
void MyAvatar::updateMotionBehaviorsFromMenu() {
|
||||
Menu* menu = Menu::getInstance();
|
||||
if (menu->isOptionChecked(MenuOption::ObeyEnvironmentalGravity)) {
|
||||
|
|
|
@ -131,6 +131,7 @@ public slots:
|
|||
void resetSize();
|
||||
|
||||
void goToLocationFromResponse(const QJsonObject& jsonObject);
|
||||
void goToLocationFromAddress(const QJsonObject& jsonObject);
|
||||
|
||||
// Set/Get update the thrust that will move the avatar around
|
||||
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };
|
||||
|
|
|
@ -465,7 +465,7 @@ bool SkeletonModel::getNeckPosition(glm::vec3& neckPosition) const {
|
|||
return isActive() && getJointPositionInWorldFrame(_geometry->getFBXGeometry().neckJointIndex, neckPosition);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getNeckParentRotation(glm::quat& neckParentRotation) const {
|
||||
bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -473,7 +473,13 @@ bool SkeletonModel::getNeckParentRotation(glm::quat& neckParentRotation) const {
|
|||
if (geometry.neckJointIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
return getJointRotationInWorldFrame(geometry.joints.at(geometry.neckJointIndex).parentIndex, neckParentRotation);
|
||||
int parentIndex = geometry.joints.at(geometry.neckJointIndex).parentIndex;
|
||||
glm::quat worldFrameRotation;
|
||||
if (getJointRotationInWorldFrame(parentIndex, worldFrameRotation)) {
|
||||
neckParentRotation = worldFrameRotation * _jointStates[parentIndex].getFBXJoint().inverseDefaultRotation;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||
|
|
|
@ -87,9 +87,9 @@ public:
|
|||
/// \return whether or not the neck was found
|
||||
bool getNeckPosition(glm::vec3& neckPosition) const;
|
||||
|
||||
/// Returns the rotation of the neck joint's parent.
|
||||
/// Returns the rotation of the neck joint's parent from default orientation
|
||||
/// \return whether or not the neck was found
|
||||
bool getNeckParentRotation(glm::quat& neckRotation) const;
|
||||
bool getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const;
|
||||
|
||||
/// Retrieve the positions of up to two eye meshes.
|
||||
/// \return whether or not both eye meshes were found
|
||||
|
|
|
@ -72,6 +72,14 @@ void OculusManager::connect() {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool OculusManager::isConnected() {
|
||||
#ifdef HAVE_LIBOVR
|
||||
return _isConnected && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenHeight) {
|
||||
#ifdef HAVE_LIBOVR
|
||||
_stereoConfig.SetFullViewport(Viewport(0, 0, screenWidth, screenHeight));
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f;
|
||||
|
||||
class Camera;
|
||||
|
||||
/// Handles interaction with the Oculus Rift.
|
||||
|
@ -27,7 +29,7 @@ class OculusManager {
|
|||
public:
|
||||
static void connect();
|
||||
|
||||
static bool isConnected() { return _isConnected; }
|
||||
static bool isConnected();
|
||||
|
||||
static void configureCamera(Camera& camera, int screenWidth, int screenHeight);
|
||||
|
||||
|
|
|
@ -39,6 +39,14 @@ SixenseManager::SixenseManager() {
|
|||
|
||||
sixenseInit();
|
||||
#endif
|
||||
_triggerPressed[0] = false;
|
||||
_bumperPressed[0] = false;
|
||||
_oldX[0] = -1;
|
||||
_oldY[0] = -1;
|
||||
_triggerPressed[1] = false;
|
||||
_bumperPressed[1] = false;
|
||||
_oldX[1] = -1;
|
||||
_oldY[1] = -1;
|
||||
}
|
||||
|
||||
SixenseManager::~SixenseManager() {
|
||||
|
@ -107,6 +115,12 @@ void SixenseManager::update(float deltaTime) {
|
|||
palm->setTrigger(data->trigger);
|
||||
palm->setJoystick(data->joystick_x, data->joystick_y);
|
||||
|
||||
|
||||
// Emulate the mouse so we can use scripts
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
||||
emulateMouse(palm, numActiveControllers - 1);
|
||||
}
|
||||
|
||||
// NOTE: Sixense API returns pos data in millimeters but we IMMEDIATELY convert to meters.
|
||||
glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]);
|
||||
position *= METERS_PER_MILLIMETER;
|
||||
|
@ -171,6 +185,17 @@ void SixenseManager::update(float deltaTime) {
|
|||
#endif // HAVE_SIXENSE
|
||||
}
|
||||
|
||||
//Constants for getCursorPixelRangeMultiplier()
|
||||
const float MIN_PIXEL_RANGE_MULT = 0.4f;
|
||||
const float MAX_PIXEL_RANGE_MULT = 2.0f;
|
||||
const float RANGE_MULT = (MAX_PIXEL_RANGE_MULT - MIN_PIXEL_RANGE_MULT) * 0.01;
|
||||
|
||||
//Returns a multiplier to be applied to the cursor range for the controllers
|
||||
float SixenseManager::getCursorPixelRangeMult() const {
|
||||
//scales (0,100) to (MINIMUM_PIXEL_RANGE_MULT, MAXIMUM_PIXEL_RANGE_MULT)
|
||||
return Menu::getInstance()->getSixenseReticleMoveSpeed() * RANGE_MULT + MIN_PIXEL_RANGE_MULT;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIXENSE
|
||||
|
||||
// the calibration sequence is:
|
||||
|
@ -313,5 +338,109 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Injecting mouse movements and clicks
|
||||
void SixenseManager::emulateMouse(PalmData* palm, int index) {
|
||||
MyAvatar* avatar = Application::getInstance()->getAvatar();
|
||||
QGLWidget* widget = Application::getInstance()->getGLWidget();
|
||||
QPoint pos;
|
||||
// Get directon relative to avatar orientation
|
||||
glm::vec3 direction = glm::inverse(avatar->getOrientation()) * palm->getFingerDirection();
|
||||
|
||||
Qt::MouseButton bumperButton;
|
||||
Qt::MouseButton triggerButton;
|
||||
|
||||
if (Menu::getInstance()->getInvertSixenseButtons()) {
|
||||
bumperButton = Qt::LeftButton;
|
||||
triggerButton = Qt::RightButton;
|
||||
} else {
|
||||
bumperButton = Qt::RightButton;
|
||||
triggerButton = Qt::LeftButton;
|
||||
}
|
||||
|
||||
// Get the angles, scaled between (-0.5,0.5)
|
||||
float xAngle = (atan2(direction.z, direction.x) + M_PI_2);
|
||||
float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2));
|
||||
|
||||
// Get the pixel range over which the xAngle and yAngle are scaled
|
||||
float cursorRange = widget->width() * getCursorPixelRangeMult();
|
||||
|
||||
pos.setX(widget->width() / 2.0f + cursorRange * xAngle);
|
||||
pos.setY(widget->height() / 2.0f + cursorRange * yAngle);
|
||||
|
||||
//If we are off screen then we should stop processing, and if a trigger or bumper is pressed,
|
||||
//we should unpress them.
|
||||
if (pos.x() < 0 || pos.x() > widget->width() || pos.y() < 0 || pos.y() > widget->height()) {
|
||||
if (_bumperPressed[index]) {
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0);
|
||||
|
||||
Application::getInstance()->mouseReleaseEvent(&mouseEvent);
|
||||
|
||||
_bumperPressed[index] = false;
|
||||
}
|
||||
if (_triggerPressed[index]) {
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0);
|
||||
|
||||
Application::getInstance()->mouseReleaseEvent(&mouseEvent);
|
||||
|
||||
_triggerPressed[index] = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//If position has changed, emit a mouse move to the application
|
||||
if (pos.x() != _oldX[index] || pos.y() != _oldY[index]) {
|
||||
QMouseEvent mouseEvent(static_cast<QEvent::Type>(CONTROLLER_MOVE_EVENT), pos, Qt::NoButton, Qt::NoButton, 0);
|
||||
|
||||
//Only send the mouse event if the opposite left button isnt held down.
|
||||
//This is specifically for edit voxels
|
||||
if (triggerButton == Qt::LeftButton) {
|
||||
if (!_triggerPressed[(int)(!index)]) {
|
||||
Application::getInstance()->mouseMoveEvent(&mouseEvent);
|
||||
}
|
||||
} else {
|
||||
if (!_bumperPressed[(int)(!index)]) {
|
||||
Application::getInstance()->mouseMoveEvent(&mouseEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
_oldX[index] = pos.x();
|
||||
_oldY[index] = pos.y();
|
||||
|
||||
//Check for bumper press ( Right Click )
|
||||
if (palm->getControllerButtons() & BUTTON_FWD) {
|
||||
if (!_bumperPressed[index]) {
|
||||
_bumperPressed[index] = true;
|
||||
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, bumperButton, bumperButton, 0);
|
||||
|
||||
Application::getInstance()->mousePressEvent(&mouseEvent);
|
||||
}
|
||||
} else if (_bumperPressed[index]) {
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0);
|
||||
|
||||
Application::getInstance()->mouseReleaseEvent(&mouseEvent);
|
||||
|
||||
_bumperPressed[index] = false;
|
||||
}
|
||||
|
||||
//Check for trigger press ( Left Click )
|
||||
if (palm->getTrigger() == 1.0f) {
|
||||
if (!_triggerPressed[index]) {
|
||||
_triggerPressed[index] = true;
|
||||
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, triggerButton, triggerButton, 0);
|
||||
|
||||
Application::getInstance()->mousePressEvent(&mouseEvent);
|
||||
}
|
||||
} else if (_triggerPressed[index]) {
|
||||
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0);
|
||||
|
||||
Application::getInstance()->mouseReleaseEvent(&mouseEvent);
|
||||
|
||||
_triggerPressed[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_SIXENSE
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@ const unsigned int BUTTON_3 = 1U << 3;
|
|||
const unsigned int BUTTON_4 = 1U << 4;
|
||||
const unsigned int BUTTON_FWD = 1U << 7;
|
||||
|
||||
// Event type that represents moving the controller
|
||||
const unsigned int CONTROLLER_MOVE_EVENT = 1500U;
|
||||
|
||||
const float DEFAULT_SIXENSE_RETICLE_MOVE_SPEED = 37.5f;
|
||||
const bool DEFAULT_INVERT_SIXENSE_MOUSE_BUTTONS = false;
|
||||
|
||||
/// Handles interaction with the Sixense SDK (e.g., Razer Hydra).
|
||||
class SixenseManager : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -36,6 +42,7 @@ public:
|
|||
~SixenseManager();
|
||||
|
||||
void update(float deltaTime);
|
||||
float getCursorPixelRangeMult() const;
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -44,6 +51,7 @@ public slots:
|
|||
private:
|
||||
#ifdef HAVE_SIXENSE
|
||||
void updateCalibration(const sixenseControllerData* controllers);
|
||||
void emulateMouse(PalmData* palm, int index);
|
||||
|
||||
int _calibrationState;
|
||||
|
||||
|
@ -65,6 +73,12 @@ private:
|
|||
#endif
|
||||
quint64 _lastMovement;
|
||||
glm::vec3 _amountMoved;
|
||||
|
||||
// for mouse emulation with the two controllers
|
||||
bool _triggerPressed[2];
|
||||
bool _bumperPressed[2];
|
||||
int _oldX[2];
|
||||
int _oldY[2];
|
||||
};
|
||||
|
||||
#endif // hifi_SixenseManager_h
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
const QString GET_USER_ADDRESS = "/api/v1/users/%1/address";
|
||||
const QString GET_PLACE_ADDRESS = "/api/v1/places/%1/address";
|
||||
const QString GET_ADDRESSES = "/api/v1/addresses/%1";
|
||||
const QString POST_PLACE_CREATE = "/api/v1/places/";
|
||||
|
||||
|
||||
LocationManager::LocationManager() : _userData(), _placeData() {
|
||||
LocationManager::LocationManager() {
|
||||
|
||||
};
|
||||
|
||||
|
@ -74,59 +75,38 @@ void LocationManager::goTo(QString destination) {
|
|||
|
||||
// go to coordinate destination or to Username
|
||||
if (!goToDestination(destination)) {
|
||||
// reset data on local variables
|
||||
_userData = QJsonObject();
|
||||
_placeData = QJsonObject();
|
||||
|
||||
destination = QString(QUrl::toPercentEncoding(destination));
|
||||
|
||||
JSONCallbackParameters callbackParams;
|
||||
callbackParams.jsonCallbackReceiver = this;
|
||||
callbackParams.jsonCallbackMethod = "goToUserFromResponse";
|
||||
AccountManager::getInstance().authenticatedRequest(GET_USER_ADDRESS.arg(destination),
|
||||
QNetworkAccessManager::GetOperation,
|
||||
callbackParams);
|
||||
|
||||
callbackParams.jsonCallbackMethod = "goToLocationFromResponse";
|
||||
AccountManager::getInstance().authenticatedRequest(GET_PLACE_ADDRESS.arg(destination),
|
||||
callbackParams.jsonCallbackMethod = "goToAddressFromResponse";
|
||||
AccountManager::getInstance().authenticatedRequest(GET_ADDRESSES.arg(destination),
|
||||
QNetworkAccessManager::GetOperation,
|
||||
callbackParams);
|
||||
}
|
||||
}
|
||||
|
||||
void LocationManager::goToUserFromResponse(const QJsonObject& jsonObject) {
|
||||
_userData = jsonObject;
|
||||
checkForMultipleDestinations();
|
||||
}
|
||||
void LocationManager::goToAddressFromResponse(const QJsonObject& responseData) {
|
||||
QJsonValue status = responseData["status"];
|
||||
qDebug() << responseData;
|
||||
if (!status.isUndefined() && status.toString() == "success") {
|
||||
const QJsonObject& data = responseData["data"].toObject();
|
||||
const QJsonValue& userObject = data["user"];
|
||||
const QJsonValue& placeObject = data["place"];
|
||||
|
||||
void LocationManager::goToLocationFromResponse(const QJsonObject& jsonObject) {
|
||||
_placeData = jsonObject;
|
||||
checkForMultipleDestinations();
|
||||
}
|
||||
|
||||
void LocationManager::checkForMultipleDestinations() {
|
||||
if (!_userData.isEmpty() && !_placeData.isEmpty()) {
|
||||
if (_userData.contains("status") && _userData["status"].toString() == "success" &&
|
||||
_placeData.contains("status") && _placeData["status"].toString() == "success") {
|
||||
emit multipleDestinationsFound(_userData, _placeData);
|
||||
return;
|
||||
if (!placeObject.isUndefined() && !userObject.isUndefined()) {
|
||||
emit multipleDestinationsFound(userObject.toObject(), placeObject.toObject());
|
||||
} else if (placeObject.isUndefined()) {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromAddress(userObject.toObject()["address"].toObject());
|
||||
} else {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromAddress(placeObject.toObject()["address"].toObject());
|
||||
}
|
||||
|
||||
if (_userData.contains("status") && _userData["status"].toString() == "success") {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromResponse(_userData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_placeData.contains("status") && _placeData["status"].toString() == "success") {
|
||||
Application::getInstance()->getAvatar()->goToLocationFromResponse(_placeData);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found.");
|
||||
}
|
||||
}
|
||||
|
||||
void LocationManager::goToUser(QString userName) {
|
||||
|
||||
JSONCallbackParameters callbackParams;
|
||||
callbackParams.jsonCallbackReceiver = Application::getInstance()->getAvatar();
|
||||
callbackParams.jsonCallbackMethod = "goToLocationFromResponse";
|
||||
|
|
|
@ -39,11 +39,7 @@ public:
|
|||
bool goToDestination(QString destination);
|
||||
|
||||
private:
|
||||
QJsonObject _userData;
|
||||
QJsonObject _placeData;
|
||||
|
||||
void replaceLastOccurrence(const QChar search, const QChar replace, QString& string);
|
||||
void checkForMultipleDestinations();
|
||||
|
||||
signals:
|
||||
void creationCompleted(LocationManager::NamedLocationCreateResponse response);
|
||||
|
@ -52,8 +48,7 @@ signals:
|
|||
private slots:
|
||||
void namedLocationDataReceived(const QJsonObject& data);
|
||||
void errorDataReceived(QNetworkReply::NetworkError error, const QString& message);
|
||||
void goToLocationFromResponse(const QJsonObject& jsonObject);
|
||||
void goToUserFromResponse(const QJsonObject& jsonObject);
|
||||
void goToAddressFromResponse(const QJsonObject& jsonObject);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -57,21 +57,29 @@ void ModelTreeRenderer::render(RenderMode renderMode) {
|
|||
|
||||
const FBXGeometry* ModelTreeRenderer::getGeometryForModel(const ModelItem& modelItem) {
|
||||
const FBXGeometry* result = NULL;
|
||||
|
||||
Model* model = getModel(modelItem);
|
||||
if (model) {
|
||||
result = &model->getGeometry()->getFBXGeometry();
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Model* ModelTreeRenderer::getModel(const ModelItem& modelItem) {
|
||||
Model* model = NULL;
|
||||
|
||||
|
||||
if (modelItem.isKnownID()) {
|
||||
if (_knownModelsItemModels.find(modelItem.getID()) != _knownModelsItemModels.end()) {
|
||||
model = _knownModelsItemModels[modelItem.getID()];
|
||||
} else {
|
||||
|
||||
// Make sure we only create new models on the thread that owns the ModelTreeRenderer
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(Model*, model), Q_ARG(const ModelItem&, modelItem));
|
||||
return model;
|
||||
}
|
||||
|
||||
model = new Model();
|
||||
model->init();
|
||||
model->setURL(QUrl(modelItem.getModelURL()));
|
||||
|
@ -81,6 +89,13 @@ Model* ModelTreeRenderer::getModel(const ModelItem& modelItem) {
|
|||
if (_unknownModelsItemModels.find(modelItem.getCreatorTokenID()) != _unknownModelsItemModels.end()) {
|
||||
model = _unknownModelsItemModels[modelItem.getCreatorTokenID()];
|
||||
} else {
|
||||
// Make sure we only create new models on the thread that owns the ModelTreeRenderer
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(Model*, model), Q_ARG(const ModelItem&, modelItem));
|
||||
return model;
|
||||
}
|
||||
|
||||
model = new Model();
|
||||
model->init();
|
||||
model->setURL(QUrl(modelItem.getModelURL()));
|
||||
|
@ -187,92 +202,122 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args)
|
|||
|
||||
if (drawAsModel) {
|
||||
glPushMatrix();
|
||||
{
|
||||
const float alpha = 1.0f;
|
||||
|
||||
Model* model = getModel(modelItem);
|
||||
|
||||
model->setScaleToFit(true, radius * 2.0f);
|
||||
model->setSnapModelToCenter(true);
|
||||
|
||||
// set the rotation
|
||||
glm::quat rotation = modelItem.getModelRotation();
|
||||
model->setRotation(rotation);
|
||||
|
||||
// set the position
|
||||
model->setTranslation(position);
|
||||
|
||||
// handle animations..
|
||||
if (modelItem.hasAnimation()) {
|
||||
if (!modelItem.jointsMapped()) {
|
||||
QStringList modelJointNames = model->getJointNames();
|
||||
modelItem.mapJoints(modelJointNames);
|
||||
if (model) {
|
||||
model->setScaleToFit(true, radius * 2.0f);
|
||||
model->setSnapModelToCenter(true);
|
||||
|
||||
// set the rotation
|
||||
glm::quat rotation = modelItem.getModelRotation();
|
||||
model->setRotation(rotation);
|
||||
|
||||
// set the position
|
||||
model->setTranslation(position);
|
||||
|
||||
// handle animations..
|
||||
if (modelItem.hasAnimation()) {
|
||||
if (!modelItem.jointsMapped()) {
|
||||
QStringList modelJointNames = model->getJointNames();
|
||||
modelItem.mapJoints(modelJointNames);
|
||||
}
|
||||
|
||||
QVector<glm::quat> frameData = modelItem.getAnimationFrame();
|
||||
for (int i = 0; i < frameData.size(); i++) {
|
||||
model->setJointState(i, true, frameData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure to simulate so everything gets set up correctly for rendering
|
||||
model->simulate(0.0f);
|
||||
|
||||
// TODO: should we allow modelItems to have alpha on their models?
|
||||
Model::RenderMode modelRenderMode = args->_renderMode == OctreeRenderer::SHADOW_RENDER_MODE
|
||||
? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
|
||||
|
||||
if (modelItem.getGlowLevel() > 0.0f) {
|
||||
Glower glower(modelItem.getGlowLevel());
|
||||
|
||||
if (model->isActive()) {
|
||||
model->render(alpha, modelRenderMode);
|
||||
} else {
|
||||
// if we couldn't get a model, then just draw a sphere
|
||||
glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glutSolidSphere(radius, 15, 15);
|
||||
glPopMatrix();
|
||||
}
|
||||
} else {
|
||||
if (model->isActive()) {
|
||||
model->render(alpha, modelRenderMode);
|
||||
} else {
|
||||
// if we couldn't get a model, then just draw a sphere
|
||||
glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glutSolidSphere(radius, 15, 15);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<glm::quat> frameData = modelItem.getAnimationFrame();
|
||||
for (int i = 0; i < frameData.size(); i++) {
|
||||
model->setJointState(i, true, frameData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure to simulate so everything gets set up correctly for rendering
|
||||
model->simulate(0.0f);
|
||||
if (!isShadowMode && displayModelBounds) {
|
||||
|
||||
// TODO: should we allow modelItems to have alpha on their models?
|
||||
Model::RenderMode modelRenderMode = args->_renderMode == OctreeRenderer::SHADOW_RENDER_MODE
|
||||
? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
|
||||
|
||||
if (modelItem.getGlowLevel() > 0.0f) {
|
||||
Glower glower(modelItem.getGlowLevel());
|
||||
model->render(alpha, modelRenderMode);
|
||||
glm::vec3 unRotatedMinimum = model->getUnscaledMeshExtents().minimum;
|
||||
glm::vec3 unRotatedMaximum = model->getUnscaledMeshExtents().maximum;
|
||||
glm::vec3 unRotatedExtents = unRotatedMaximum - unRotatedMinimum;
|
||||
|
||||
float width = unRotatedExtents.x;
|
||||
float height = unRotatedExtents.y;
|
||||
float depth = unRotatedExtents.z;
|
||||
|
||||
Extents rotatedExtents = model->getUnscaledMeshExtents();
|
||||
calculateRotatedExtents(rotatedExtents, rotation);
|
||||
|
||||
glm::vec3 rotatedSize = rotatedExtents.maximum - rotatedExtents.minimum;
|
||||
|
||||
const glm::vec3& modelScale = model->getScale();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
|
||||
// draw the orignal bounding cube
|
||||
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
glutWireCube(size);
|
||||
|
||||
// draw the rotated bounding cube
|
||||
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
glPushMatrix();
|
||||
glScalef(rotatedSize.x * modelScale.x, rotatedSize.y * modelScale.y, rotatedSize.z * modelScale.z);
|
||||
glutWireCube(1.0);
|
||||
glPopMatrix();
|
||||
|
||||
// draw the model relative bounding box
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glScalef(width * modelScale.x, height * modelScale.y, depth * modelScale.z);
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glutWireCube(1.0);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
} else {
|
||||
model->render(alpha, modelRenderMode);
|
||||
}
|
||||
|
||||
if (!isShadowMode && displayModelBounds) {
|
||||
|
||||
glm::vec3 unRotatedMinimum = model->getUnscaledMeshExtents().minimum;
|
||||
glm::vec3 unRotatedMaximum = model->getUnscaledMeshExtents().maximum;
|
||||
glm::vec3 unRotatedExtents = unRotatedMaximum - unRotatedMinimum;
|
||||
|
||||
float width = unRotatedExtents.x;
|
||||
float height = unRotatedExtents.y;
|
||||
float depth = unRotatedExtents.z;
|
||||
|
||||
Extents rotatedExtents = model->getUnscaledMeshExtents();
|
||||
calculateRotatedExtents(rotatedExtents, rotation);
|
||||
|
||||
glm::vec3 rotatedSize = rotatedExtents.maximum - rotatedExtents.minimum;
|
||||
|
||||
const glm::vec3& modelScale = model->getScale();
|
||||
|
||||
// if we couldn't get a model, then just draw a sphere
|
||||
glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
|
||||
// draw the orignal bounding cube
|
||||
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
glutWireCube(size);
|
||||
|
||||
// draw the rotated bounding cube
|
||||
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
glPushMatrix();
|
||||
glScalef(rotatedSize.x * modelScale.x, rotatedSize.y * modelScale.y, rotatedSize.z * modelScale.z);
|
||||
glutWireCube(1.0);
|
||||
glPopMatrix();
|
||||
|
||||
// draw the model relative bounding box
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glScalef(width * modelScale.x, height * modelScale.y, depth * modelScale.z);
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glutWireCube(1.0);
|
||||
|
||||
glutSolidSphere(radius, 15, 15);
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
glPopMatrix();
|
||||
} else {
|
||||
glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]);
|
||||
//glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]);
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glutSolidSphere(radius, 15, 15);
|
||||
|
|
|
@ -16,14 +16,25 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "ApplicationOverlay.h"
|
||||
#include "devices/OculusManager.h"
|
||||
|
||||
#include "ui/Stats.h"
|
||||
|
||||
// Fast helper functions
|
||||
inline float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
inline float min(float a, float b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
ApplicationOverlay::ApplicationOverlay() :
|
||||
_framebufferObject(NULL),
|
||||
_oculusAngle(65.0f * RADIANS_PER_DEGREE),
|
||||
_distance(0.5f),
|
||||
_uiType(HEMISPHERE) {
|
||||
_textureFov(DEFAULT_OCULUS_UI_ANGULAR_SIZE * RADIANS_PER_DEGREE),
|
||||
_crosshairTexture(0) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,23 +46,19 @@ ApplicationOverlay::~ApplicationOverlay() {
|
|||
|
||||
const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f };
|
||||
|
||||
const float RETICLE_COLOR[] = { 0.0f, 198.0f / 255.0f, 244.0f / 255.0f };
|
||||
|
||||
// Renders the overlays either to a texture or to the screen
|
||||
void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()");
|
||||
|
||||
_textureFov = Menu::getInstance()->getOculusUIAngularSize() * RADIANS_PER_DEGREE;
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
|
||||
Overlays& overlays = application->getOverlays();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
MyAvatar* myAvatar = application->getAvatar();
|
||||
Audio* audio = application->getAudio();
|
||||
const VoxelPacketProcessor& voxelPacketProcessor = application->getVoxelPacketProcessor();
|
||||
BandwidthMeter* bandwidthMeter = application->getBandwidthMeter();
|
||||
NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
|
||||
|
||||
int mouseX = application->getMouseX();
|
||||
int mouseY = application->getMouseY();
|
||||
bool renderPointer = renderToTexture;
|
||||
|
||||
if (renderToTexture) {
|
||||
getFramebufferObject()->bind();
|
||||
|
@ -60,7 +67,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Render 2D overlay: I/O level bar graphs and text
|
||||
// Render 2D overlay
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
|
@ -69,6 +76,379 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
renderAudioMeter();
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) {
|
||||
myAvatar->renderHeadMouse(glWidget->width(), glWidget->height());
|
||||
}
|
||||
|
||||
renderStatsAndLogs();
|
||||
|
||||
// give external parties a change to hook in
|
||||
emit application->renderingOverlay();
|
||||
|
||||
overlays.render2D();
|
||||
|
||||
renderPointers();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
|
||||
if (renderToTexture) {
|
||||
getFramebufferObject()->release();
|
||||
}
|
||||
}
|
||||
|
||||
// Draws the FBO texture for the screen
|
||||
void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) {
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture());
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0, glWidget->width(), glWidget->height(), 0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, glWidget->height());
|
||||
glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height());
|
||||
glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0);
|
||||
glTexCoord2f(0, 1); glVertex2i(0, 0);
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direction) const {
|
||||
glm::quat rot = Application::getInstance()->getAvatar()->getOrientation();
|
||||
|
||||
//invert y direction
|
||||
y = 1.0 - y;
|
||||
|
||||
//Get position on hemisphere UI
|
||||
x = sin((x - 0.5f) * _textureFov);
|
||||
y = sin((y - 0.5f) * _textureFov);
|
||||
|
||||
float dist = sqrt(x * x + y * y);
|
||||
float z = -sqrt(1.0f - dist * dist);
|
||||
|
||||
//Rotate the UI pick ray by the avatar orientation
|
||||
direction = glm::normalize(rot * glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
// Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane.
|
||||
void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
|
||||
MyAvatar* myAvatar = application->getAvatar();
|
||||
const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture());
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
// Transform to world space
|
||||
glm::quat rotation = whichCamera.getRotation();
|
||||
glm::vec3 axis2 = glm::axis(rotation);
|
||||
glRotatef(-glm::degrees(glm::angle(rotation)), axis2.x, axis2.y, axis2.z);
|
||||
glTranslatef(viewMatrixTranslation.x, viewMatrixTranslation.y, viewMatrixTranslation.z);
|
||||
|
||||
// Translate to the front of the camera
|
||||
glm::vec3 pos = whichCamera.getPosition();
|
||||
glm::quat rot = myAvatar->getOrientation();
|
||||
glm::vec3 axis = glm::axis(rot);
|
||||
|
||||
glTranslatef(pos.x, pos.y, pos.z);
|
||||
glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.01f);
|
||||
|
||||
//Draw the magnifiers
|
||||
for (int i = 0; i < _numMagnifiers; i++) {
|
||||
renderMagnifier(_mouseX[i], _mouseY[i]);
|
||||
}
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
renderTexturedHemisphere();
|
||||
|
||||
renderControllerPointersOculus();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
//Renders optional pointers
|
||||
void ApplicationOverlay::renderPointers() {
|
||||
Application* application = Application::getInstance();
|
||||
// Render a crosshair over the mouse when in Oculus
|
||||
_numMagnifiers = 0;
|
||||
|
||||
//lazily load crosshair texture
|
||||
if (_crosshairTexture == 0) {
|
||||
_crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png"));
|
||||
}
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
|
||||
|
||||
|
||||
if (OculusManager::isConnected() && application->getLastMouseMoveType() == QEvent::MouseMove) {
|
||||
//If we are in oculus, render reticle later
|
||||
_numMagnifiers = 1;
|
||||
_mouseX[0] = application->getMouseX();
|
||||
_mouseY[0] = application->getMouseY();
|
||||
} else if (application->getLastMouseMoveType() == CONTROLLER_MOVE_EVENT && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
||||
//only render controller pointer if we aren't already rendering a mouse pointer
|
||||
renderControllerPointers();
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderControllerPointers() {
|
||||
Application* application = Application::getInstance();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
MyAvatar* myAvatar = application->getAvatar();
|
||||
|
||||
const HandData* handData = Application::getInstance()->getAvatar()->getHandData();
|
||||
|
||||
for (unsigned int palmIndex = 2; palmIndex < 4; palmIndex++) {
|
||||
const PalmData* palmData = NULL;
|
||||
|
||||
if (palmIndex >= handData->getPalms().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (handData->getPalms()[palmIndex].isActive()) {
|
||||
palmData = &handData->getPalms()[palmIndex];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get directon relative to avatar orientation
|
||||
glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection();
|
||||
|
||||
// Get the angles, scaled between (-0.5,0.5)
|
||||
float xAngle = (atan2(direction.z, direction.x) + M_PI_2) ;
|
||||
float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2));
|
||||
|
||||
// Get the pixel range over which the xAngle and yAngle are scaled
|
||||
float cursorRange = glWidget->width() * application->getSixenseManager()->getCursorPixelRangeMult();
|
||||
|
||||
int mouseX = glWidget->width() / 2.0f + cursorRange * xAngle;
|
||||
int mouseY = glWidget->height() / 2.0f + cursorRange * yAngle;
|
||||
|
||||
//If the cursor is out of the screen then don't render it
|
||||
if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float pointerWidth = 40;
|
||||
float pointerHeight = 40;
|
||||
|
||||
//if we have the oculus, we should make the cursor smaller since it will be
|
||||
//magnified
|
||||
if (OculusManager::isConnected()) {
|
||||
|
||||
_mouseX[_numMagnifiers] = mouseX;
|
||||
_mouseY[_numMagnifiers] = mouseY;
|
||||
_numMagnifiers++;
|
||||
//If oculus is enabled, we draw the crosshairs later
|
||||
continue;
|
||||
}
|
||||
|
||||
mouseX -= pointerWidth / 2.0f;
|
||||
mouseY += pointerHeight / 2.0f;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
|
||||
|
||||
glTexCoord2d(0.0f, 0.0f); glVertex2i(mouseX, mouseY);
|
||||
glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + pointerWidth, mouseY);
|
||||
glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + pointerWidth, mouseY - pointerHeight);
|
||||
glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - pointerHeight);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderControllerPointersOculus() {
|
||||
Application* application = Application::getInstance();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
|
||||
const int widgetWidth = glWidget->width();
|
||||
const int widgetHeight = glWidget->height();
|
||||
|
||||
const float reticleSize = 50.0f;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
for (int i = 0; i < _numMagnifiers; i++) {
|
||||
|
||||
float mouseX = (float)_mouseX[i];
|
||||
float mouseY = (float)_mouseY[i];
|
||||
mouseX -= reticleSize / 2;
|
||||
mouseY += reticleSize / 2;
|
||||
|
||||
//Get new UV coordinates from our magnification window
|
||||
float newULeft = mouseX / widgetWidth;
|
||||
float newURight = (mouseX + reticleSize) / widgetWidth;
|
||||
float newVBottom = 1.0 - mouseY / widgetHeight;
|
||||
float newVTop = 1.0 - (mouseY - reticleSize) / widgetHeight;
|
||||
|
||||
// Project our position onto the hemisphere using the UV coordinates
|
||||
float lX = sin((newULeft - 0.5f) * _textureFov);
|
||||
float rX = sin((newURight - 0.5f) * _textureFov);
|
||||
float bY = sin((newVBottom - 0.5f) * _textureFov);
|
||||
float tY = sin((newVTop - 0.5f) * _textureFov);
|
||||
|
||||
float dist;
|
||||
//Bottom Left
|
||||
dist = sqrt(lX * lX + bY * bY);
|
||||
float blZ = sqrt(1.0f - dist * dist);
|
||||
//Top Left
|
||||
dist = sqrt(lX * lX + tY * tY);
|
||||
float tlZ = sqrt(1.0f - dist * dist);
|
||||
//Bottom Right
|
||||
dist = sqrt(rX * rX + bY * bY);
|
||||
float brZ = sqrt(1.0f - dist * dist);
|
||||
//Top Right
|
||||
dist = sqrt(rX * rX + tY * tY);
|
||||
float trZ = sqrt(1.0f - dist * dist);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
|
||||
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(lX, tY, -tlZ);
|
||||
glTexCoord2f(1.0f, 0.0f); glVertex3f(rX, tY, -trZ);
|
||||
glTexCoord2f(1.0f, 1.0f); glVertex3f(rX, bY, -brZ);
|
||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(lX, bY, -blZ);
|
||||
|
||||
glEnd();
|
||||
|
||||
}
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
//Renders a small magnification of the currently bound texture at the coordinates
|
||||
void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY)
|
||||
{
|
||||
Application* application = Application::getInstance();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
|
||||
|
||||
const int widgetWidth = glWidget->width();
|
||||
const int widgetHeight = glWidget->height();
|
||||
const float magnification = 4.0f;
|
||||
|
||||
float magnifyWidth = 80.0f;
|
||||
float magnifyHeight = 60.0f;
|
||||
|
||||
mouseX -= magnifyWidth / 2;
|
||||
mouseY -= magnifyHeight / 2;
|
||||
|
||||
float newWidth = magnifyWidth * magnification;
|
||||
float newHeight = magnifyHeight * magnification;
|
||||
|
||||
// Magnification Texture Coordinates
|
||||
float magnifyULeft = mouseX / (float)widgetWidth;
|
||||
float magnifyURight = (mouseX + magnifyWidth) / (float)widgetWidth;
|
||||
float magnifyVBottom = 1.0f - mouseY / (float)widgetHeight;
|
||||
float magnifyVTop = 1.0f - (mouseY + magnifyHeight) / (float)widgetHeight;
|
||||
|
||||
// Coordinates of magnification overlay
|
||||
float newMouseX = (mouseX + magnifyWidth / 2) - newWidth / 2.0f;
|
||||
float newMouseY = (mouseY + magnifyHeight / 2) + newHeight / 2.0f;
|
||||
|
||||
// Get position on hemisphere using angle
|
||||
|
||||
//Get new UV coordinates from our magnification window
|
||||
float newULeft = newMouseX / widgetWidth;
|
||||
float newURight = (newMouseX + newWidth) / widgetWidth;
|
||||
float newVBottom = 1.0 - newMouseY / widgetHeight;
|
||||
float newVTop = 1.0 - (newMouseY - newHeight) / widgetHeight;
|
||||
|
||||
// Project our position onto the hemisphere using the UV coordinates
|
||||
float lX = sin((newULeft - 0.5f) * _textureFov);
|
||||
float rX = sin((newURight - 0.5f) * _textureFov);
|
||||
float bY = sin((newVBottom - 0.5f) * _textureFov);
|
||||
float tY = sin((newVTop - 0.5f) * _textureFov);
|
||||
|
||||
float dist;
|
||||
//Bottom Left
|
||||
dist = sqrt(lX * lX + bY * bY);
|
||||
float blZ = sqrt(1.0f - dist * dist);
|
||||
//Top Left
|
||||
dist = sqrt(lX * lX + tY * tY);
|
||||
float tlZ = sqrt(1.0f - dist * dist);
|
||||
//Bottom Right
|
||||
dist = sqrt(rX * rX + bY * bY);
|
||||
float brZ = sqrt(1.0f - dist * dist);
|
||||
//Top Right
|
||||
dist = sqrt(rX * rX + tY * tY);
|
||||
float trZ = sqrt(1.0f - dist * dist);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(lX, tY, -tlZ);
|
||||
glTexCoord2f(magnifyURight, magnifyVBottom); glVertex3f(rX, tY, -trZ);
|
||||
glTexCoord2f(magnifyURight, magnifyVTop); glVertex3f(rX, bY, -brZ);
|
||||
glTexCoord2f(magnifyULeft, magnifyVTop); glVertex3f(lX, bY, -blZ);
|
||||
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderAudioMeter() {
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
Audio* audio = application->getAudio();
|
||||
|
||||
// Display a single screen-size quad to create an alpha blended 'collision' flash
|
||||
if (audio->getCollisionFlashesScreen()) {
|
||||
float collisionSoundMagnitude = audio->getCollisionSoundMagnitude();
|
||||
|
@ -187,11 +567,16 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
|||
glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET);
|
||||
glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderStatsAndLogs() {
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) {
|
||||
myAvatar->renderHeadMouse(glWidget->width(), glWidget->height());
|
||||
}
|
||||
Application* application = Application::getInstance();
|
||||
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor();
|
||||
BandwidthMeter* bandwidthMeter = application->getBandwidthMeter();
|
||||
NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
|
||||
|
||||
// Display stats and log text onscreen
|
||||
glLineWidth(1.0f);
|
||||
|
@ -200,7 +585,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
|||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
// let's set horizontal offset to give stats some margin to mirror
|
||||
int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
|
||||
int voxelPacketsToProcess = voxelPacketProcessor.packetsToProcessCount();
|
||||
int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount();
|
||||
// Onscreen text about position, servers, etc
|
||||
Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess);
|
||||
// Bandwidth meter
|
||||
|
@ -222,346 +607,22 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
|||
drawText(glWidget->width() - 100, glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT);
|
||||
}
|
||||
nodeBoundsDisplay.drawOverlay();
|
||||
|
||||
// give external parties a change to hook in
|
||||
emit application->renderingOverlay();
|
||||
|
||||
overlays.render2D();
|
||||
|
||||
// Render a crosshair over the pointer when in Oculus
|
||||
if (renderPointer) {
|
||||
const float pointerWidth = 10;
|
||||
const float pointerHeight = 10;
|
||||
const float crossPad = 4;
|
||||
|
||||
mouseX -= pointerWidth / 2.0f;
|
||||
mouseY += pointerHeight / 2.0f;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glColor3f(1, 0, 0);
|
||||
|
||||
//Horizontal crosshair
|
||||
glVertex2i(mouseX, mouseY - crossPad);
|
||||
glVertex2i(mouseX + pointerWidth, mouseY - crossPad);
|
||||
glVertex2i(mouseX + pointerWidth, mouseY - pointerHeight + crossPad);
|
||||
glVertex2i(mouseX, mouseY - pointerHeight + crossPad);
|
||||
|
||||
//Vertical crosshair
|
||||
glVertex2i(mouseX + crossPad, mouseY);
|
||||
glVertex2i(mouseX + pointerWidth - crossPad, mouseY);
|
||||
glVertex2i(mouseX + pointerWidth - crossPad, mouseY - pointerHeight);
|
||||
glVertex2i(mouseX + crossPad, mouseY - pointerHeight);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
|
||||
if (renderToTexture) {
|
||||
getFramebufferObject()->release();
|
||||
}
|
||||
}
|
||||
|
||||
// Draws the FBO texture for the screen
|
||||
void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) {
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture());
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0, glWidget->width(), glWidget->height(), 0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2i(0, glWidget->height());
|
||||
glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height());
|
||||
glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0);
|
||||
glTexCoord2f(0, 1); glVertex2i(0, 0);
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
const float textureFov = PI / 2.5f;
|
||||
|
||||
void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direction) const {
|
||||
glm::quat rot = Application::getInstance()->getAvatar()->getOrientation();
|
||||
|
||||
//invert y direction
|
||||
y = 1.0 - y;
|
||||
|
||||
//Get position on hemisphere UI
|
||||
x = sin((x - 0.5f) * textureFov);
|
||||
y = sin((y - 0.5f) * textureFov);
|
||||
|
||||
float dist = sqrt(x * x + y * y);
|
||||
float z = -sqrt(1.0f - dist * dist);
|
||||
|
||||
//Rotate the UI pick ray by the avatar orientation
|
||||
direction = glm::normalize(rot * glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
// Fast helper functions
|
||||
inline float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
inline float min(float a, float b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
// Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane.
|
||||
void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
|
||||
|
||||
Application* application = Application::getInstance();
|
||||
|
||||
QGLWidget* glWidget = application->getGLWidget();
|
||||
MyAvatar* myAvatar = application->getAvatar();
|
||||
const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
|
||||
|
||||
int mouseX = application->getMouseX();
|
||||
int mouseY = application->getMouseY();
|
||||
const int widgetWidth = glWidget->width();
|
||||
const int widgetHeight = glWidget->height();
|
||||
float magnifyWidth = 80.0f;
|
||||
float magnifyHeight = 60.0f;
|
||||
const float magnification = 4.0f;
|
||||
|
||||
// Get vertical FoV of the displayed overlay texture
|
||||
const float halfVerticalAngle = _oculusAngle / 2.0f;
|
||||
const float overlayAspectRatio = glWidget->width() / (float)glWidget->height();
|
||||
const float halfOverlayHeight = _distance * tan(halfVerticalAngle);
|
||||
const float overlayHeight = halfOverlayHeight * 2.0f;
|
||||
|
||||
// The more vertices, the better the curve
|
||||
const int numHorizontalVertices = 20;
|
||||
const int numVerticalVertices = 20;
|
||||
// U texture coordinate width at each quad
|
||||
const float quadTexWidth = 1.0f / (numHorizontalVertices - 1);
|
||||
const float quadTexHeight = 1.0f / (numVerticalVertices - 1);
|
||||
|
||||
// Get horizontal angle and angle increment from vertical angle and aspect ratio
|
||||
const float horizontalAngle = halfVerticalAngle * 2.0f * overlayAspectRatio;
|
||||
const float angleIncrement = horizontalAngle / (numHorizontalVertices - 1);
|
||||
const float halfHorizontalAngle = horizontalAngle / 2;
|
||||
|
||||
const float verticalAngleIncrement = _oculusAngle / (numVerticalVertices - 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture());
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
// Transform to world space
|
||||
glm::quat rotation = whichCamera.getRotation();
|
||||
glm::vec3 axis2 = glm::axis(rotation);
|
||||
glRotatef(-glm::degrees(glm::angle(rotation)), axis2.x, axis2.y, axis2.z);
|
||||
glTranslatef(viewMatrixTranslation.x, viewMatrixTranslation.y, viewMatrixTranslation.z);
|
||||
|
||||
// Translate to the front of the camera
|
||||
glm::vec3 pos = whichCamera.getPosition();
|
||||
glm::quat rot = myAvatar->getOrientation();
|
||||
glm::vec3 axis = glm::axis(rot);
|
||||
|
||||
glTranslatef(pos.x, pos.y, pos.z);
|
||||
glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z);
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.01f);
|
||||
|
||||
//Draw the magnifying glass
|
||||
|
||||
mouseX -= magnifyWidth / 2;
|
||||
mouseY -= magnifyHeight / 2;
|
||||
|
||||
//clamp the magnification
|
||||
if (mouseX < 0) {
|
||||
magnifyWidth += mouseX;
|
||||
mouseX = 0;
|
||||
} else if (mouseX + magnifyWidth > widgetWidth) {
|
||||
magnifyWidth = widgetWidth - mouseX;
|
||||
}
|
||||
if (mouseY < 0) {
|
||||
magnifyHeight += mouseY;
|
||||
mouseY = 0;
|
||||
} else if (mouseY + magnifyHeight > widgetHeight) {
|
||||
magnifyHeight = widgetHeight - mouseY;
|
||||
}
|
||||
|
||||
const float halfMagnifyHeight = magnifyHeight / 2.0f;
|
||||
|
||||
float newWidth = magnifyWidth * magnification;
|
||||
float newHeight = magnifyHeight * magnification;
|
||||
|
||||
// Magnification Texture Coordinates
|
||||
float magnifyULeft = mouseX / (float)widgetWidth;
|
||||
float magnifyURight = (mouseX + magnifyWidth) / (float)widgetWidth;
|
||||
float magnifyVBottom = 1.0f - mouseY / (float)widgetHeight;
|
||||
float magnifyVTop = 1.0f - (mouseY + magnifyHeight) / (float)widgetHeight;
|
||||
|
||||
// Coordinates of magnification overlay
|
||||
float newMouseX = (mouseX + magnifyWidth / 2) - newWidth / 2.0f;
|
||||
float newMouseY = (mouseY + magnifyHeight / 2) + newHeight / 2.0f;
|
||||
|
||||
// Get angle on the UI
|
||||
float leftAngle = (newMouseX / (float)widgetWidth) * horizontalAngle - halfHorizontalAngle;
|
||||
float rightAngle = ((newMouseX + newWidth) / (float)widgetWidth) * horizontalAngle - halfHorizontalAngle;
|
||||
|
||||
float bottomAngle = (newMouseY / (float)widgetHeight) * _oculusAngle - halfVerticalAngle;
|
||||
float topAngle = ((newMouseY - newHeight) / (float)widgetHeight) * _oculusAngle - halfVerticalAngle;
|
||||
|
||||
float leftX, rightX, leftZ, rightZ, topZ, bottomZ;
|
||||
|
||||
// Get position on hemisphere using angle
|
||||
if (_uiType == HEMISPHERE) {
|
||||
|
||||
//Get new UV coordinates from our magnification window
|
||||
float newULeft = newMouseX / widgetWidth;
|
||||
float newURight = (newMouseX + newWidth) / widgetWidth;
|
||||
float newVBottom = 1.0 - newMouseY / widgetHeight;
|
||||
float newVTop = 1.0 - (newMouseY - newHeight) / widgetHeight;
|
||||
|
||||
// Project our position onto the hemisphere using the UV coordinates
|
||||
float lX = sin((newULeft - 0.5f) * textureFov);
|
||||
float rX = sin((newURight - 0.5f) * textureFov);
|
||||
float bY = sin((newVBottom - 0.5f) * textureFov);
|
||||
float tY = sin((newVTop - 0.5f) * textureFov);
|
||||
|
||||
float dist;
|
||||
//Bottom Left
|
||||
dist = sqrt(lX * lX + bY * bY);
|
||||
float blZ = sqrt(1.0f - dist * dist);
|
||||
//Top Left
|
||||
dist = sqrt(lX * lX + tY * tY);
|
||||
float tlZ = sqrt(1.0f - dist * dist);
|
||||
//Bottom Right
|
||||
dist = sqrt(rX * rX + bY * bY);
|
||||
float brZ = sqrt(1.0f - dist * dist);
|
||||
//Top Right
|
||||
dist = sqrt(rX * rX + tY * tY);
|
||||
float trZ = sqrt(1.0f - dist * dist);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(lX, tY, -tlZ);
|
||||
glTexCoord2f(magnifyURight, magnifyVBottom); glVertex3f(rX, tY, -trZ);
|
||||
glTexCoord2f(magnifyURight, magnifyVTop); glVertex3f(rX, bY, -brZ);
|
||||
glTexCoord2f(magnifyULeft, magnifyVTop); glVertex3f(lX, bY, -blZ);
|
||||
|
||||
glEnd();
|
||||
|
||||
} else {
|
||||
leftX = sin(leftAngle) * _distance;
|
||||
rightX = sin(rightAngle) * _distance;
|
||||
leftZ = -cos(leftAngle) * _distance;
|
||||
rightZ = -cos(rightAngle) * _distance;
|
||||
if (_uiType == CURVED_SEMICIRCLE) {
|
||||
topZ = -cos(topAngle * overlayAspectRatio) * _distance;
|
||||
bottomZ = -cos(bottomAngle * overlayAspectRatio) * _distance;
|
||||
} else {
|
||||
// Dont want to use topZ or bottomZ for SEMICIRCLE
|
||||
topZ = -99999;
|
||||
bottomZ = -99999;
|
||||
}
|
||||
|
||||
float bottomY = (1.0 - newMouseY / (float)widgetHeight) * halfOverlayHeight * 2.0f - halfOverlayHeight;
|
||||
float topY = bottomY + (newHeight / widgetHeight) * halfOverlayHeight * 2;
|
||||
|
||||
//TODO: Remove immediate mode in favor of VBO
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(leftX, topY, max(topZ, leftZ));
|
||||
glTexCoord2f(magnifyURight, magnifyVBottom); glVertex3f(rightX, topY, max(topZ, rightZ));
|
||||
glTexCoord2f(magnifyURight, magnifyVTop); glVertex3f(rightX, bottomY, max(bottomZ, rightZ));
|
||||
glTexCoord2f(magnifyULeft, magnifyVTop); glVertex3f(leftX, bottomY, max(bottomZ, leftZ));
|
||||
|
||||
glEnd();
|
||||
}
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
//TODO: Remove immediate mode in favor of VBO
|
||||
if (_uiType == HEMISPHERE) {
|
||||
renderTexturedHemisphere();
|
||||
} else{
|
||||
glBegin(GL_QUADS);
|
||||
// Place the vertices in a semicircle curve around the camera
|
||||
for (int i = 0; i < numHorizontalVertices - 1; i++) {
|
||||
for (int j = 0; j < numVerticalVertices - 1; j++) {
|
||||
|
||||
// Calculate the X and Z coordinates from the angles and radius from camera
|
||||
leftX = sin(angleIncrement * i - halfHorizontalAngle) * _distance;
|
||||
rightX = sin(angleIncrement * (i + 1) - halfHorizontalAngle) * _distance;
|
||||
leftZ = -cos(angleIncrement * i - halfHorizontalAngle) * _distance;
|
||||
rightZ = -cos(angleIncrement * (i + 1) - halfHorizontalAngle) * _distance;
|
||||
if (_uiType == 2) {
|
||||
topZ = -cos((verticalAngleIncrement * (j + 1) - halfVerticalAngle) * overlayAspectRatio) * _distance;
|
||||
bottomZ = -cos((verticalAngleIncrement * j - halfVerticalAngle) * overlayAspectRatio) * _distance;
|
||||
} else {
|
||||
topZ = -99999;
|
||||
bottomZ = -99999;
|
||||
}
|
||||
|
||||
glTexCoord2f(quadTexWidth * i, (j + 1) * quadTexHeight);
|
||||
glVertex3f(leftX, (j + 1) * quadTexHeight * overlayHeight - halfOverlayHeight, max(topZ, leftZ));
|
||||
glTexCoord2f(quadTexWidth * (i + 1), (j + 1) * quadTexHeight);
|
||||
glVertex3f(rightX, (j + 1) * quadTexHeight * overlayHeight - halfOverlayHeight, max(topZ, rightZ));
|
||||
glTexCoord2f(quadTexWidth * (i + 1), j * quadTexHeight);
|
||||
glVertex3f(rightX, j * quadTexHeight * overlayHeight - halfOverlayHeight, max(bottomZ, rightZ));
|
||||
glTexCoord2f(quadTexWidth * i, j * quadTexHeight);
|
||||
glVertex3f(leftX, j * quadTexHeight * overlayHeight - halfOverlayHeight, max(bottomZ, leftZ));
|
||||
}
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
//Renders a hemisphere with texture coordinates.
|
||||
void ApplicationOverlay::renderTexturedHemisphere() {
|
||||
const int slices = 80;
|
||||
const int stacks = 80;
|
||||
|
||||
//UV mapping source: http://www.mvps.org/directx/articles/spheremap.htm
|
||||
static VerticesIndices vbo(0, 0);
|
||||
int vertices = slices * (stacks - 1) + 1;
|
||||
int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;
|
||||
if (vbo.first == 0) {
|
||||
|
||||
static float oldTextureFOV = _textureFov;
|
||||
//We only generate the VBO when the _textureFov changes
|
||||
if (vbo.first == 0 || oldTextureFOV != _textureFov) {
|
||||
oldTextureFOV = _textureFov;
|
||||
TextureVertex* vertexData = new TextureVertex[vertices];
|
||||
TextureVertex* vertex = vertexData;
|
||||
for (int i = 0; i < stacks - 1; i++) {
|
||||
|
@ -574,8 +635,8 @@ void ApplicationOverlay::renderTexturedHemisphere() {
|
|||
vertex->position.x = sinf(theta) * radius;
|
||||
vertex->position.y = cosf(theta) * radius;
|
||||
vertex->position.z = z;
|
||||
vertex->uv.x = asin(vertex->position.x) / (textureFov) + 0.5f;
|
||||
vertex->uv.y = asin(vertex->position.y) / (textureFov) + 0.5f;
|
||||
vertex->uv.x = asin(vertex->position.x) / (_textureFov) + 0.5f;
|
||||
vertex->uv.y = asin(vertex->position.y) / (_textureFov) + 0.5f;
|
||||
vertex++;
|
||||
}
|
||||
}
|
||||
|
@ -586,7 +647,9 @@ void ApplicationOverlay::renderTexturedHemisphere() {
|
|||
vertex->uv.y = 0.5f;
|
||||
vertex++;
|
||||
|
||||
glGenBuffers(1, &vbo.first);
|
||||
if (vbo.first == 0){
|
||||
glGenBuffers(1, &vbo.first);
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
const int BYTES_PER_VERTEX = sizeof(TextureVertex);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
|
||||
|
|
|
@ -19,8 +19,6 @@ class QOpenGLFramebufferObject;
|
|||
class ApplicationOverlay {
|
||||
public:
|
||||
|
||||
enum UIType { HEMISPHERE, SEMICIRCLE, CURVED_SEMICIRCLE };
|
||||
|
||||
ApplicationOverlay();
|
||||
~ApplicationOverlay();
|
||||
|
||||
|
@ -31,12 +29,7 @@ public:
|
|||
|
||||
// Getters
|
||||
QOpenGLFramebufferObject* getFramebufferObject();
|
||||
float getOculusAngle() const { return _oculusAngle; }
|
||||
|
||||
// Setters
|
||||
void setOculusAngle(float oculusAngle) { _oculusAngle = oculusAngle; }
|
||||
void setUIType(UIType uiType) { _uiType = uiType; }
|
||||
|
||||
|
||||
private:
|
||||
// Interleaved vertex data
|
||||
struct TextureVertex {
|
||||
|
@ -46,13 +39,24 @@ private:
|
|||
|
||||
typedef QPair<GLuint, GLuint> VerticesIndices;
|
||||
|
||||
void renderPointers();
|
||||
void renderControllerPointers();
|
||||
void renderControllerPointersOculus();
|
||||
void renderMagnifier(int mouseX, int mouseY);
|
||||
void renderAudioMeter();
|
||||
void renderStatsAndLogs();
|
||||
void renderTexturedHemisphere();
|
||||
|
||||
QOpenGLFramebufferObject* _framebufferObject;
|
||||
float _trailingAudioLoudness;
|
||||
float _oculusAngle;
|
||||
float _distance;
|
||||
UIType _uiType;
|
||||
float _textureFov;
|
||||
int _mouseX[2];
|
||||
int _mouseY[2];
|
||||
int _numMagnifiers;
|
||||
|
||||
GLuint _crosshairTexture;
|
||||
};
|
||||
|
||||
#endif // hifi_ApplicationOverlay_h
|
|
@ -103,8 +103,9 @@ void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authoriz
|
|||
codedAuthorizationURL.setQuery(authQuery);
|
||||
}
|
||||
|
||||
connect(_activeWebView.data(), &QWebView::urlChanged, this, &OAuthWebViewHandler::handleURLChanged);
|
||||
|
||||
_activeWebView->load(codedAuthorizationURL);
|
||||
_activeWebView->show();
|
||||
|
||||
connect(_activeWebView->page()->networkAccessManager(), &QNetworkAccessManager::sslErrors,
|
||||
this, &OAuthWebViewHandler::handleSSLErrors);
|
||||
|
@ -137,3 +138,17 @@ void OAuthWebViewHandler::handleLoadFinished(bool success) {
|
|||
void OAuthWebViewHandler::handleWebViewDestroyed(QObject* destroyedObject) {
|
||||
_webViewRedisplayTimer.restart();
|
||||
}
|
||||
|
||||
void OAuthWebViewHandler::handleURLChanged(const QUrl& url) {
|
||||
// check if this is the authorization screen - if it is then we need to show the OAuthWebViewHandler
|
||||
const QString ACCESS_TOKEN_URL_REGEX_STRING = "redirect_uri=[\\w:\\/\\.]+&access_token=";
|
||||
QRegExp accessTokenRegex(ACCESS_TOKEN_URL_REGEX_STRING);
|
||||
|
||||
if (accessTokenRegex.indexIn(url.toString()) != -1) {
|
||||
_activeWebView->show();
|
||||
} else if (url.toString() == DEFAULT_NODE_AUTH_URL.toString() + "/login") {
|
||||
// this is a login request - we're going to close the webview and signal the AccountManager that we need a login
|
||||
_activeWebView->close();
|
||||
AccountManager::getInstance().checkAndSignalForAccessToken();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ private slots:
|
|||
void handleSSLErrors(QNetworkReply* networkReply, const QList<QSslError>& errorList);
|
||||
void handleLoadFinished(bool success);
|
||||
void handleWebViewDestroyed(QObject* destroyedObject);
|
||||
void handleURLChanged(const QUrl& url);
|
||||
private:
|
||||
QPointer<QWebView> _activeWebView;
|
||||
QElapsedTimer _webViewRedisplayTimer;
|
||||
|
|
|
@ -137,6 +137,13 @@ void PreferencesDialog::loadPreferences() {
|
|||
ui.maxVoxelsSpin->setValue(menuInstance->getMaxVoxels());
|
||||
|
||||
ui.maxVoxelsPPSSpin->setValue(menuInstance->getMaxVoxelPacketsPerSecond());
|
||||
|
||||
ui.oculusUIAngularSizeSpin->setValue(menuInstance->getOculusUIAngularSize());
|
||||
|
||||
ui.sixenseReticleMoveSpeedSpin->setValue(menuInstance->getSixenseReticleMoveSpeed());
|
||||
|
||||
ui.invertSixenseButtonsCheckBox->setChecked(menuInstance->getInvertSixenseButtons());
|
||||
|
||||
}
|
||||
|
||||
void PreferencesDialog::savePreferences() {
|
||||
|
@ -189,6 +196,12 @@ void PreferencesDialog::savePreferences() {
|
|||
(float)ui.faceshiftEyeDeflectionSider->maximum());
|
||||
Menu::getInstance()->setMaxVoxelPacketsPerSecond(ui.maxVoxelsPPSSpin->value());
|
||||
|
||||
Menu::getInstance()->setOculusUIAngularSize(ui.oculusUIAngularSizeSpin->value());
|
||||
|
||||
Menu::getInstance()->setSixenseReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value());
|
||||
|
||||
Menu::getInstance()->setInvertSixenseButtons(ui.invertSixenseButtonsCheckBox->isChecked());
|
||||
|
||||
Menu::getInstance()->setAudioJitterBufferSamples(ui.audioJitterSpin->value());
|
||||
Application::getInstance()->getAudio()->setJitterBufferSamples(ui.audioJitterSpin->value());
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// VoxelPacketProcessor.cpp
|
||||
// OctreePacketProcessor.cpp
|
||||
// interface/src/voxels
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
|
@ -13,18 +13,18 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "Menu.h"
|
||||
#include "VoxelPacketProcessor.h"
|
||||
#include "OctreePacketProcessor.h"
|
||||
|
||||
void VoxelPacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
||||
void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"VoxelPacketProcessor::processPacket()");
|
||||
"OctreePacketProcessor::processPacket()");
|
||||
|
||||
QByteArray mutablePacket = packet;
|
||||
|
||||
const int WAY_BEHIND = 300;
|
||||
|
||||
if (packetsToProcessCount() > WAY_BEHIND && Application::getInstance()->getLogger()->extraDebugging()) {
|
||||
qDebug("VoxelPacketProcessor::processPacket() packets to process=%d", packetsToProcessCount());
|
||||
qDebug("OctreePacketProcessor::processPacket() packets to process=%d", packetsToProcessCount());
|
||||
}
|
||||
ssize_t messageLength = mutablePacket.size();
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// VoxelPacketProcessor.h
|
||||
// OctreePacketProcessor.h
|
||||
// interface/src/voxels
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 8/12/13.
|
||||
|
@ -9,16 +9,16 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_VoxelPacketProcessor_h
|
||||
#define hifi_VoxelPacketProcessor_h
|
||||
#ifndef hifi_OctreePacketProcessor_h
|
||||
#define hifi_OctreePacketProcessor_h
|
||||
|
||||
#include <ReceivedPacketProcessor.h>
|
||||
|
||||
/// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes
|
||||
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
|
||||
class VoxelPacketProcessor : public ReceivedPacketProcessor {
|
||||
class OctreePacketProcessor : public ReceivedPacketProcessor {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
|
||||
};
|
||||
#endif // hifi_VoxelPacketProcessor_h
|
||||
#endif // hifi_OctreePacketProcessor_h
|
|
@ -154,9 +154,9 @@ color: #0e7077</string>
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>-204</y>
|
||||
<width>494</width>
|
||||
<height>1091</height>
|
||||
<y>-1002</y>
|
||||
<width>477</width>
|
||||
<height>1386</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
@ -1605,6 +1605,331 @@ padding: 10px;margin-top:10px</string>
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="oculusRiftTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>20</pointsize>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: #0e7077</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Oculus Rift</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_15">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: rgb(51, 51, 51)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>User Interface Angular Size</string>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>maxVoxelsSpin</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_15">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="oculusUIAngularSizeSpin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>125</width>
|
||||
<height>36</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>160</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>72</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="sixenseControllersTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>20</pointsize>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: #0e7077</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sixense Controllers</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_17">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: rgb(51, 51, 51)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Invert Mouse Buttons</string>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>maxVoxelsSpin</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_17">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="invertSixenseButtonsCheckBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_16">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: rgb(51, 51, 51)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reticle Movement Speed</string>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>maxVoxelsSpin</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_16">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="sixenseReticleMoveSpeedSpin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>125</width>
|
||||
<height>36</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>50</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
|
@ -258,7 +258,7 @@ void Sound::interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& ou
|
|||
// Now pull out the data
|
||||
quint32 outputAudioByteArraySize = qFromLittleEndian<quint32>(dataHeader.descriptor.size);
|
||||
outputAudioByteArray.resize(outputAudioByteArraySize);
|
||||
if (waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize) != outputAudioByteArraySize) {
|
||||
if (waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize) != (int)outputAudioByteArraySize) {
|
||||
qDebug() << "Error reading WAV file";
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -29,21 +29,32 @@
|
|||
class QByteArray;
|
||||
class QColor;
|
||||
class QDataStream;
|
||||
class QScriptValue;
|
||||
class QUrl;
|
||||
|
||||
class Attribute;
|
||||
class AttributeValue;
|
||||
class Bitstream;
|
||||
class FieldReader;
|
||||
class GenericValue;
|
||||
class ObjectReader;
|
||||
class ObjectStreamer;
|
||||
class OwnedAttributeValue;
|
||||
class PropertyReader;
|
||||
class PropertyWriter;
|
||||
class TypeReader;
|
||||
class TypeStreamer;
|
||||
|
||||
typedef SharedObjectPointerTemplate<Attribute> AttributePointer;
|
||||
|
||||
typedef QPair<QByteArray, QByteArray> ScopeNamePair;
|
||||
typedef QPair<QByteArray, int> NameIntPair;
|
||||
typedef QSharedPointer<ObjectStreamer> ObjectStreamerPointer;
|
||||
typedef QWeakPointer<ObjectStreamer> WeakObjectStreamerPointer;
|
||||
typedef QSharedPointer<TypeStreamer> TypeStreamerPointer;
|
||||
typedef QWeakPointer<TypeStreamer> WeakTypeStreamerPointer;
|
||||
|
||||
typedef QPair<QVariant, QVariant> QVariantPair;
|
||||
typedef QList<QVariantPair> QVariantPairList;
|
||||
|
||||
Q_DECLARE_METATYPE(QVariantPairList)
|
||||
|
||||
/// Streams integer identifiers that conform to the following pattern: each ID encountered in the stream is either one that
|
||||
/// has been sent (received) before, or is one more than the highest previously encountered ID (starting at zero). This allows
|
||||
/// us to use the minimum number of bits to encode the IDs.
|
||||
|
@ -192,7 +203,7 @@ public:
|
|||
|
||||
class WriteMappings {
|
||||
public:
|
||||
QHash<const QMetaObject*, int> metaObjectOffsets;
|
||||
QHash<const ObjectStreamer*, int> objectStreamerOffsets;
|
||||
QHash<const TypeStreamer*, int> typeStreamerOffsets;
|
||||
QHash<AttributePointer, int> attributeOffsets;
|
||||
QHash<QScriptString, int> scriptStringOffsets;
|
||||
|
@ -201,8 +212,8 @@ public:
|
|||
|
||||
class ReadMappings {
|
||||
public:
|
||||
QHash<int, ObjectReader> metaObjectValues;
|
||||
QHash<int, TypeReader> typeStreamerValues;
|
||||
QHash<int, ObjectStreamerPointer> objectStreamerValues;
|
||||
QHash<int, TypeStreamerPointer> typeStreamerValues;
|
||||
QHash<int, AttributePointer> attributeValues;
|
||||
QHash<int, QScriptString> scriptStringValues;
|
||||
QHash<int, SharedObjectPointer> sharedObjectValues;
|
||||
|
@ -227,8 +238,17 @@ public:
|
|||
|
||||
enum MetadataType { NO_METADATA, HASH_METADATA, FULL_METADATA };
|
||||
|
||||
enum GenericsMode { NO_GENERICS, FALLBACK_GENERICS, ALL_GENERICS };
|
||||
|
||||
/// Creates a new bitstream. Note: the stream may be used for reading or writing, but not both.
|
||||
Bitstream(QDataStream& underlying, MetadataType metadataType = NO_METADATA, QObject* parent = NULL);
|
||||
/// \param metadataType the metadata type, which determines the amount of version-resiliency: with no metadata, all types
|
||||
/// must match exactly; with hash metadata, any types which do not match exactly will be ignored; with full metadata,
|
||||
/// fields (and enum values, etc.) will be remapped by name
|
||||
/// \param genericsMode the generics mode, which determines which types will be replaced by generic equivalents: with
|
||||
/// no generics, no generics will be created; with fallback generics, generics will be created for any unknown types; with
|
||||
/// all generics, generics will be created for all non-simple types
|
||||
Bitstream(QDataStream& underlying, MetadataType metadataType = NO_METADATA,
|
||||
GenericsMode = NO_GENERICS, QObject* parent = NULL);
|
||||
|
||||
/// Substitutes the supplied metaobject for the given class name's default mapping.
|
||||
void addMetaObjectSubstitution(const QByteArray& className, const QMetaObject* metaObject);
|
||||
|
@ -287,11 +307,15 @@ public:
|
|||
template<class T> void writeDelta(const T& value, const T& reference);
|
||||
template<class T> void readDelta(T& value, const T& reference);
|
||||
|
||||
void writeRawDelta(const QVariant& value, const QVariant& reference);
|
||||
void readRawDelta(QVariant& value, const QVariant& reference);
|
||||
|
||||
void writeRawDelta(const QObject* value, const QObject* reference);
|
||||
void readRawDelta(QObject*& value, const QObject* reference);
|
||||
|
||||
void writeRawDelta(const QScriptValue& value, const QScriptValue& reference);
|
||||
void readRawDelta(QScriptValue& value, const QScriptValue& reference);
|
||||
|
||||
template<class T> void writeRawDelta(const T& value, const T& reference);
|
||||
template<class T> void readRawDelta(T& value, const T& reference);
|
||||
|
||||
|
@ -316,9 +340,15 @@ public:
|
|||
Bitstream& operator<<(uint value);
|
||||
Bitstream& operator>>(uint& value);
|
||||
|
||||
Bitstream& operator<<(qint64 value);
|
||||
Bitstream& operator>>(qint64& value);
|
||||
|
||||
Bitstream& operator<<(float value);
|
||||
Bitstream& operator>>(float& value);
|
||||
|
||||
Bitstream& operator<<(double value);
|
||||
Bitstream& operator>>(double& value);
|
||||
|
||||
Bitstream& operator<<(const glm::vec3& value);
|
||||
Bitstream& operator>>(glm::vec3& value);
|
||||
|
||||
|
@ -337,12 +367,21 @@ public:
|
|||
Bitstream& operator<<(const QUrl& url);
|
||||
Bitstream& operator>>(QUrl& url);
|
||||
|
||||
Bitstream& operator<<(const QDateTime& dateTime);
|
||||
Bitstream& operator>>(QDateTime& dateTime);
|
||||
|
||||
Bitstream& operator<<(const QRegExp& regExp);
|
||||
Bitstream& operator>>(QRegExp& regExp);
|
||||
|
||||
Bitstream& operator<<(const QVariant& value);
|
||||
Bitstream& operator>>(QVariant& value);
|
||||
|
||||
Bitstream& operator<<(const AttributeValue& attributeValue);
|
||||
Bitstream& operator>>(OwnedAttributeValue& attributeValue);
|
||||
|
||||
Bitstream& operator<<(const GenericValue& value);
|
||||
Bitstream& operator>>(GenericValue& value);
|
||||
|
||||
template<class T> Bitstream& operator<<(const QList<T>& list);
|
||||
template<class T> Bitstream& operator>>(QList<T>& list);
|
||||
|
||||
|
@ -360,11 +399,14 @@ public:
|
|||
|
||||
Bitstream& operator<<(const QMetaObject* metaObject);
|
||||
Bitstream& operator>>(const QMetaObject*& metaObject);
|
||||
Bitstream& operator>>(ObjectReader& objectReader);
|
||||
|
||||
Bitstream& operator<<(const ObjectStreamer* streamer);
|
||||
Bitstream& operator>>(const ObjectStreamer*& streamer);
|
||||
Bitstream& operator>>(ObjectStreamerPointer& streamer);
|
||||
|
||||
Bitstream& operator<<(const TypeStreamer* streamer);
|
||||
Bitstream& operator>>(const TypeStreamer*& streamer);
|
||||
Bitstream& operator>>(TypeReader& reader);
|
||||
Bitstream& operator>>(TypeStreamerPointer& streamer);
|
||||
|
||||
Bitstream& operator<<(const AttributePointer& attribute);
|
||||
Bitstream& operator>>(AttributePointer& attribute);
|
||||
|
@ -372,14 +414,17 @@ public:
|
|||
Bitstream& operator<<(const QScriptString& string);
|
||||
Bitstream& operator>>(QScriptString& string);
|
||||
|
||||
Bitstream& operator<<(const QScriptValue& value);
|
||||
Bitstream& operator>>(QScriptValue& value);
|
||||
|
||||
Bitstream& operator<<(const SharedObjectPointer& object);
|
||||
Bitstream& operator>>(SharedObjectPointer& object);
|
||||
|
||||
Bitstream& operator<(const QMetaObject* metaObject);
|
||||
Bitstream& operator>(ObjectReader& objectReader);
|
||||
Bitstream& operator<(const ObjectStreamer* streamer);
|
||||
Bitstream& operator>(ObjectStreamerPointer& streamer);
|
||||
|
||||
Bitstream& operator<(const TypeStreamer* streamer);
|
||||
Bitstream& operator>(TypeReader& reader);
|
||||
Bitstream& operator>(TypeStreamerPointer& streamer);
|
||||
|
||||
Bitstream& operator<(const AttributePointer& attribute);
|
||||
Bitstream& operator>(AttributePointer& attribute);
|
||||
|
@ -400,14 +445,18 @@ private slots:
|
|||
|
||||
private:
|
||||
|
||||
ObjectStreamerPointer readGenericObjectStreamer(const QByteArray& name);
|
||||
TypeStreamerPointer readGenericTypeStreamer(const QByteArray& name, int category);
|
||||
|
||||
QDataStream& _underlying;
|
||||
quint8 _byte;
|
||||
int _position;
|
||||
|
||||
MetadataType _metadataType;
|
||||
GenericsMode _genericsMode;
|
||||
|
||||
RepeatedValueStreamer<const QMetaObject*, const QMetaObject*, ObjectReader> _metaObjectStreamer;
|
||||
RepeatedValueStreamer<const TypeStreamer*, const TypeStreamer*, TypeReader> _typeStreamerStreamer;
|
||||
RepeatedValueStreamer<const ObjectStreamer*, const ObjectStreamer*, ObjectStreamerPointer> _objectStreamerStreamer;
|
||||
RepeatedValueStreamer<const TypeStreamer*, const TypeStreamer*, TypeStreamerPointer> _typeStreamerStreamer;
|
||||
RepeatedValueStreamer<AttributePointer> _attributeStreamer;
|
||||
RepeatedValueStreamer<QScriptString> _scriptStringStreamer;
|
||||
RepeatedValueStreamer<SharedObjectPointer, SharedObject*> _sharedObjectStreamer;
|
||||
|
@ -422,14 +471,18 @@ private:
|
|||
static QHash<QByteArray, const QMetaObject*>& getMetaObjects();
|
||||
static QMultiHash<const QMetaObject*, const QMetaObject*>& getMetaObjectSubClasses();
|
||||
static QHash<int, const TypeStreamer*>& getTypeStreamers();
|
||||
static const QHash<QPair<QByteArray, QByteArray>, const TypeStreamer*>& getEnumStreamers();
|
||||
static QHash<QPair<QByteArray, QByteArray>, const TypeStreamer*> createEnumStreamers();
|
||||
|
||||
static const QHash<const QMetaObject*, const ObjectStreamer*>& getObjectStreamers();
|
||||
static QHash<const QMetaObject*, const ObjectStreamer*> createObjectStreamers();
|
||||
|
||||
static const QHash<ScopeNamePair, const TypeStreamer*>& getEnumStreamers();
|
||||
static QHash<ScopeNamePair, const TypeStreamer*> createEnumStreamers();
|
||||
|
||||
static const QHash<QByteArray, const TypeStreamer*>& getEnumStreamersByName();
|
||||
static QHash<QByteArray, const TypeStreamer*> createEnumStreamersByName();
|
||||
static const QHash<const QMetaObject*, QVector<PropertyReader> >& getPropertyReaders();
|
||||
static QHash<const QMetaObject*, QVector<PropertyReader> > createPropertyReaders();
|
||||
static const QHash<const QMetaObject*, QVector<PropertyWriter> >& getPropertyWriters();
|
||||
static QHash<const QMetaObject*, QVector<PropertyWriter> > createPropertyWriters();
|
||||
|
||||
static const TypeStreamer* getInvalidTypeStreamer();
|
||||
static const TypeStreamer* createInvalidTypeStreamer();
|
||||
};
|
||||
|
||||
template<class T> inline void Bitstream::writeDelta(const T& value, const T& reference) {
|
||||
|
@ -713,133 +766,75 @@ template<class K, class V> inline Bitstream& Bitstream::operator>>(QHash<K, V>&
|
|||
return *this;
|
||||
}
|
||||
|
||||
typedef QSharedPointer<TypeReader> TypeReaderPointer;
|
||||
typedef QPair<TypeStreamerPointer, QMetaProperty> StreamerPropertyPair;
|
||||
|
||||
/// Contains the information required to read a type from the stream.
|
||||
class TypeReader {
|
||||
/// Contains the information required to stream an object.
|
||||
class ObjectStreamer {
|
||||
public:
|
||||
|
||||
enum Type { SIMPLE_TYPE, ENUM_TYPE, STREAMABLE_TYPE, LIST_TYPE, SET_TYPE, MAP_TYPE };
|
||||
|
||||
TypeReader(const QByteArray& typeName = QByteArray(), const TypeStreamer* streamer = NULL);
|
||||
|
||||
TypeReader(const QByteArray& typeName, const TypeStreamer* streamer, int bits, const QHash<int, int>& mappings);
|
||||
|
||||
TypeReader(const QByteArray& typeName, const TypeStreamer* streamer, const QVector<FieldReader>& fields);
|
||||
ObjectStreamer(const QMetaObject* metaObject);
|
||||
|
||||
TypeReader(const QByteArray& typeName, const TypeStreamer* streamer, Type type,
|
||||
const TypeReaderPointer& valueReader);
|
||||
|
||||
TypeReader(const QByteArray& typeName, const TypeStreamer* streamer,
|
||||
const TypeReaderPointer& keyReader, const TypeReaderPointer& valueReader);
|
||||
|
||||
const QByteArray& getTypeName() const { return _typeName; }
|
||||
const TypeStreamer* getStreamer() const { return _streamer; }
|
||||
|
||||
QVariant read(Bitstream& in) const;
|
||||
void readDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
bool matchesExactly(const TypeStreamer* streamer) const;
|
||||
|
||||
bool operator==(const TypeReader& other) const { return _typeName == other._typeName; }
|
||||
bool operator!=(const TypeReader& other) const { return _typeName != other._typeName; }
|
||||
|
||||
private:
|
||||
|
||||
QByteArray _typeName;
|
||||
const TypeStreamer* _streamer;
|
||||
bool _exactMatch;
|
||||
Type _type;
|
||||
int _bits;
|
||||
QHash<int, int> _mappings;
|
||||
TypeReaderPointer _keyReader;
|
||||
TypeReaderPointer _valueReader;
|
||||
QVector<FieldReader> _fields;
|
||||
};
|
||||
|
||||
uint qHash(const TypeReader& typeReader, uint seed = 0);
|
||||
|
||||
QDebug& operator<<(QDebug& debug, const TypeReader& typeReader);
|
||||
|
||||
/// Contains the information required to read a metatype field from the stream and apply it.
|
||||
class FieldReader {
|
||||
public:
|
||||
|
||||
FieldReader(const TypeReader& reader = TypeReader(), int index = -1);
|
||||
|
||||
const TypeReader& getReader() const { return _reader; }
|
||||
int getIndex() const { return _index; }
|
||||
|
||||
void read(Bitstream& in, const TypeStreamer* streamer, QVariant& object) const;
|
||||
void readDelta(Bitstream& in, const TypeStreamer* streamer, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
private:
|
||||
|
||||
TypeReader _reader;
|
||||
int _index;
|
||||
};
|
||||
|
||||
/// Contains the information required to read an object from the stream.
|
||||
class ObjectReader {
|
||||
public:
|
||||
|
||||
ObjectReader(const QByteArray& className = QByteArray(), const QMetaObject* metaObject = NULL,
|
||||
const QVector<PropertyReader>& properties = QVector<PropertyReader>());
|
||||
|
||||
const QByteArray& getClassName() const { return _className; }
|
||||
const QMetaObject* getMetaObject() const { return _metaObject; }
|
||||
const ObjectStreamerPointer& getSelf() const { return _self; }
|
||||
|
||||
virtual const char* getName() const = 0;
|
||||
virtual const QVector<StreamerPropertyPair>& getProperties() const;
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const = 0;
|
||||
virtual void write(Bitstream& out, const QObject* object) const = 0;
|
||||
virtual void writeRawDelta(Bitstream& out, const QObject* object, const QObject* reference) const = 0;
|
||||
virtual QObject* read(Bitstream& in, QObject* object = NULL) const = 0;
|
||||
virtual QObject* readRawDelta(Bitstream& in, const QObject* reference, QObject* object = NULL) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
friend class Bitstream;
|
||||
|
||||
QObject* read(Bitstream& in, QObject* object = NULL) const;
|
||||
QObject* readDelta(Bitstream& in, const QObject* reference, QObject* object = NULL) const;
|
||||
|
||||
bool operator==(const ObjectReader& other) const { return _className == other._className; }
|
||||
bool operator!=(const ObjectReader& other) const { return _className != other._className; }
|
||||
|
||||
private:
|
||||
|
||||
QByteArray _className;
|
||||
const QMetaObject* _metaObject;
|
||||
QVector<PropertyReader> _properties;
|
||||
ObjectStreamerPointer _self;
|
||||
};
|
||||
|
||||
uint qHash(const ObjectReader& objectReader, uint seed = 0);
|
||||
|
||||
QDebug& operator<<(QDebug& debug, const ObjectReader& objectReader);
|
||||
|
||||
/// Contains the information required to read an object property from the stream and apply it.
|
||||
class PropertyReader {
|
||||
/// A streamer that maps to a local class.
|
||||
class MappedObjectStreamer : public ObjectStreamer {
|
||||
public:
|
||||
|
||||
PropertyReader(const TypeReader& reader = TypeReader(), const QMetaProperty& property = QMetaProperty());
|
||||
|
||||
const TypeReader& getReader() const { return _reader; }
|
||||
|
||||
void read(Bitstream& in, QObject* object) const;
|
||||
void readDelta(Bitstream& in, QObject* object, const QObject* reference) const;
|
||||
|
||||
private:
|
||||
|
||||
TypeReader _reader;
|
||||
QMetaProperty _property;
|
||||
};
|
||||
|
||||
/// Contains the information required to obtain an object property and write it to the stream.
|
||||
class PropertyWriter {
|
||||
public:
|
||||
|
||||
PropertyWriter(const QMetaProperty& property = QMetaProperty(), const TypeStreamer* streamer = NULL);
|
||||
|
||||
const QMetaProperty& getProperty() const { return _property; }
|
||||
const TypeStreamer* getStreamer() const { return _streamer; }
|
||||
|
||||
void write(Bitstream& out, const QObject* object) const;
|
||||
void writeDelta(Bitstream& out, const QObject* object, const QObject* reference) const;
|
||||
MappedObjectStreamer(const QMetaObject* metaObject, const QVector<StreamerPropertyPair>& properties);
|
||||
|
||||
virtual const char* getName() const;
|
||||
virtual const QVector<StreamerPropertyPair>& getProperties() const;
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QObject* object) const;
|
||||
virtual void writeRawDelta(Bitstream& out, const QObject* object, const QObject* reference) const;
|
||||
virtual QObject* read(Bitstream& in, QObject* object = NULL) const;
|
||||
virtual QObject* readRawDelta(Bitstream& in, const QObject* reference, QObject* object = NULL) const;
|
||||
|
||||
private:
|
||||
|
||||
QMetaProperty _property;
|
||||
const TypeStreamer* _streamer;
|
||||
QVector<StreamerPropertyPair> _properties;
|
||||
};
|
||||
|
||||
typedef QPair<TypeStreamerPointer, QByteArray> StreamerNamePair;
|
||||
|
||||
/// A streamer for generic objects.
|
||||
class GenericObjectStreamer : public ObjectStreamer {
|
||||
public:
|
||||
|
||||
GenericObjectStreamer(const QByteArray& name, const QVector<StreamerNamePair>& properties, const QByteArray& hash);
|
||||
|
||||
virtual const char* getName() const;
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QObject* object) const;
|
||||
virtual void writeRawDelta(Bitstream& out, const QObject* object, const QObject* reference) const;
|
||||
virtual QObject* read(Bitstream& in, QObject* object = NULL) const;
|
||||
virtual QObject* readRawDelta(Bitstream& in, const QObject* reference, QObject* object = NULL) const;
|
||||
|
||||
private:
|
||||
|
||||
friend class Bitstream;
|
||||
|
||||
QByteArray _name;
|
||||
WeakObjectStreamerPointer _weakSelf;
|
||||
QVector<StreamerNamePair> _properties;
|
||||
QByteArray _hash;
|
||||
};
|
||||
|
||||
/// Describes a metatype field.
|
||||
|
@ -862,27 +857,75 @@ Q_DECLARE_METATYPE(const QMetaObject*)
|
|||
/// Macro for registering streamable meta-objects.
|
||||
#define REGISTER_META_OBJECT(x) static int x##Registration = Bitstream::registerMetaObject(#x, &x::staticMetaObject);
|
||||
|
||||
/// Contains a value along with a pointer to its streamer.
|
||||
class GenericValue {
|
||||
public:
|
||||
|
||||
GenericValue(const TypeStreamerPointer& streamer = TypeStreamerPointer(), const QVariant& value = QVariant());
|
||||
|
||||
const TypeStreamerPointer& getStreamer() const { return _streamer; }
|
||||
const QVariant& getValue() const { return _value; }
|
||||
|
||||
bool operator==(const GenericValue& other) const;
|
||||
|
||||
private:
|
||||
|
||||
TypeStreamerPointer _streamer;
|
||||
QVariant _value;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(GenericValue)
|
||||
|
||||
/// Contains a list of property values along with a pointer to their metadata.
|
||||
class GenericSharedObject : public SharedObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
GenericSharedObject(const ObjectStreamerPointer& streamer);
|
||||
|
||||
const ObjectStreamerPointer& getStreamer() const { return _streamer; }
|
||||
|
||||
void setValues(const QVariantList& values) { _values = values; }
|
||||
const QVariantList& getValues() const { return _values; }
|
||||
|
||||
private:
|
||||
|
||||
ObjectStreamerPointer _streamer;
|
||||
QVariantList _values;
|
||||
};
|
||||
|
||||
/// Interface for objects that can write values to and read values from bitstreams.
|
||||
class TypeStreamer {
|
||||
public:
|
||||
|
||||
enum Category { SIMPLE_CATEGORY, ENUM_CATEGORY, STREAMABLE_CATEGORY, LIST_CATEGORY, SET_CATEGORY, MAP_CATEGORY };
|
||||
|
||||
virtual ~TypeStreamer();
|
||||
|
||||
void setType(int type) { _type = type; }
|
||||
int getType() const { return _type; }
|
||||
|
||||
const TypeStreamerPointer& getSelf() const { return _self; }
|
||||
|
||||
virtual const char* getName() const;
|
||||
|
||||
virtual bool equal(const QVariant& first, const QVariant& second) const = 0;
|
||||
virtual const TypeStreamer* getStreamerToWrite(const QVariant& value) const;
|
||||
|
||||
virtual void write(Bitstream& out, const QVariant& value) const = 0;
|
||||
virtual QVariant read(Bitstream& in) const = 0;
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
|
||||
virtual bool equal(const QVariant& first, const QVariant& second) const;
|
||||
|
||||
virtual void write(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
|
||||
virtual void writeDelta(Bitstream& out, const QVariant& value, const QVariant& reference) const = 0;
|
||||
virtual void readDelta(Bitstream& in, QVariant& value, const QVariant& reference) const = 0;
|
||||
virtual void writeVariant(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant readVariant(Bitstream& in) const;
|
||||
|
||||
virtual void writeRawDelta(Bitstream& out, const QVariant& value, const QVariant& reference) const = 0;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& value, const QVariant& reference) const = 0;
|
||||
virtual void writeDelta(Bitstream& out, const QVariant& value, const QVariant& reference) const;
|
||||
virtual void readDelta(Bitstream& in, QVariant& value, const QVariant& reference) const;
|
||||
|
||||
virtual void writeRawDelta(Bitstream& out, const QVariant& value, const QVariant& reference) const;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& value, const QVariant& reference) const;
|
||||
|
||||
virtual void setEnumValue(QVariant& object, int value, const QHash<int, int>& mappings) const;
|
||||
|
||||
|
@ -891,7 +934,7 @@ public:
|
|||
virtual void setField(QVariant& object, int index, const QVariant& value) const;
|
||||
virtual QVariant getField(const QVariant& object, int index) const;
|
||||
|
||||
virtual TypeReader::Type getReaderType() const;
|
||||
virtual Category getCategory() const;
|
||||
|
||||
virtual int getBits() const;
|
||||
virtual QMetaEnum getMetaEnum() const;
|
||||
|
@ -909,9 +952,12 @@ public:
|
|||
virtual QVariant getValue(const QVariant& object, int index) const;
|
||||
virtual void setValue(QVariant& object, int index, const QVariant& value) const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
friend class Bitstream;
|
||||
|
||||
int _type;
|
||||
TypeStreamerPointer _self;
|
||||
};
|
||||
|
||||
QDebug& operator<<(QDebug& debug, const TypeStreamer* typeStreamer);
|
||||
|
@ -943,7 +989,8 @@ public:
|
|||
EnumTypeStreamer(const QMetaEnum& metaEnum);
|
||||
|
||||
virtual const char* getName() const;
|
||||
virtual TypeReader::Type getReaderType() const;
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual Category getCategory() const;
|
||||
virtual int getBits() const;
|
||||
virtual QMetaEnum getMetaEnum() const;
|
||||
virtual bool equal(const QVariant& first, const QVariant& second) const;
|
||||
|
@ -964,11 +1011,62 @@ private:
|
|||
int _bits;
|
||||
};
|
||||
|
||||
/// A streamer class for enums that maps to a local type.
|
||||
class MappedEnumTypeStreamer : public TypeStreamer {
|
||||
public:
|
||||
|
||||
MappedEnumTypeStreamer(const TypeStreamer* baseStreamer, int bits, const QHash<int, int>& mappings);
|
||||
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
private:
|
||||
|
||||
const TypeStreamer* _baseStreamer;
|
||||
int _bits;
|
||||
QHash<int, int> _mappings;
|
||||
};
|
||||
|
||||
/// Base class for generic type streamers, which contain all the metadata required to write out a type.
|
||||
class GenericTypeStreamer : public TypeStreamer {
|
||||
public:
|
||||
|
||||
GenericTypeStreamer(const QByteArray& name);
|
||||
|
||||
virtual const char* getName() const;
|
||||
virtual QVariant readVariant(Bitstream& in) const;
|
||||
|
||||
protected:
|
||||
|
||||
friend class Bitstream;
|
||||
|
||||
QByteArray _name;
|
||||
WeakTypeStreamerPointer _weakSelf;
|
||||
};
|
||||
|
||||
/// A streamer for generic enums.
|
||||
class GenericEnumTypeStreamer : public GenericTypeStreamer {
|
||||
public:
|
||||
|
||||
GenericEnumTypeStreamer(const QByteArray& name, const QVector<NameIntPair>& values, int bits, const QByteArray& hash);
|
||||
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual Category getCategory() const;
|
||||
|
||||
private:
|
||||
|
||||
QVector<NameIntPair> _values;
|
||||
int _bits;
|
||||
QByteArray _hash;
|
||||
};
|
||||
|
||||
/// A streamer for types compiled by mtc.
|
||||
template<class T> class StreamableTypeStreamer : public SimpleTypeStreamer<T> {
|
||||
public:
|
||||
|
||||
virtual TypeReader::Type getReaderType() const { return TypeReader::STREAMABLE_TYPE; }
|
||||
virtual TypeStreamer::Category getCategory() const { return TypeStreamer::STREAMABLE_CATEGORY; }
|
||||
virtual const QVector<MetaField>& getMetaFields() const { return T::getMetaFields(); }
|
||||
virtual int getFieldIndex(const QByteArray& name) const { return T::getFieldIndex(name); }
|
||||
virtual void setField(QVariant& object, int index, const QVariant& value) const {
|
||||
|
@ -977,6 +1075,40 @@ public:
|
|||
return static_cast<const T*>(object.constData())->getField(index); }
|
||||
};
|
||||
|
||||
typedef QPair<TypeStreamerPointer, int> StreamerIndexPair;
|
||||
|
||||
/// A streamer class for streamables that maps to a local type.
|
||||
class MappedStreamableTypeStreamer : public TypeStreamer {
|
||||
public:
|
||||
|
||||
MappedStreamableTypeStreamer(const TypeStreamer* baseStreamer, const QVector<StreamerIndexPair>& fields);
|
||||
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
private:
|
||||
|
||||
const TypeStreamer* _baseStreamer;
|
||||
QVector<StreamerIndexPair> _fields;
|
||||
};
|
||||
|
||||
/// A streamer for generic enums.
|
||||
class GenericStreamableTypeStreamer : public GenericTypeStreamer {
|
||||
public:
|
||||
|
||||
GenericStreamableTypeStreamer(const QByteArray& name, const QVector<StreamerNamePair>& fields, const QByteArray& hash);
|
||||
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual Category getCategory() const;
|
||||
|
||||
private:
|
||||
|
||||
QVector<StreamerNamePair> _fields;
|
||||
QByteArray _hash;
|
||||
};
|
||||
|
||||
/// Base template for collection streamers.
|
||||
template<class T> class CollectionTypeStreamer : public SimpleTypeStreamer<T> {
|
||||
};
|
||||
|
@ -985,7 +1117,8 @@ template<class T> class CollectionTypeStreamer : public SimpleTypeStreamer<T> {
|
|||
template<class T> class CollectionTypeStreamer<QList<T> > : public SimpleTypeStreamer<QList<T> > {
|
||||
public:
|
||||
|
||||
virtual TypeReader::Type getReaderType() const { return TypeReader::LIST_TYPE; }
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const { out << getValueStreamer(); }
|
||||
virtual TypeStreamer::Category getCategory() const { return TypeStreamer::LIST_CATEGORY; }
|
||||
virtual const TypeStreamer* getValueStreamer() const { return Bitstream::getTypeStreamer(qMetaTypeId<T>()); }
|
||||
virtual void insert(QVariant& object, const QVariant& value) const {
|
||||
static_cast<QList<T>*>(object.data())->append(value.value<T>()); }
|
||||
|
@ -1001,7 +1134,8 @@ public:
|
|||
template<class T> class CollectionTypeStreamer<QVector<T> > : public SimpleTypeStreamer<QVector<T> > {
|
||||
public:
|
||||
|
||||
virtual TypeReader::Type getReaderType() const { return TypeReader::LIST_TYPE; }
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const { out << getValueStreamer(); }
|
||||
virtual TypeStreamer::Category getCategory() const { return TypeStreamer::LIST_CATEGORY; }
|
||||
virtual const TypeStreamer* getValueStreamer() const { return Bitstream::getTypeStreamer(qMetaTypeId<T>()); }
|
||||
virtual void insert(QVariant& object, const QVariant& value) const {
|
||||
static_cast<QVector<T>*>(object.data())->append(value.value<T>()); }
|
||||
|
@ -1013,11 +1147,43 @@ public:
|
|||
static_cast<QVector<T>*>(object.data())->replace(index, value.value<T>()); }
|
||||
};
|
||||
|
||||
/// A streamer for lists that maps to a local type.
|
||||
class MappedListTypeStreamer : public TypeStreamer {
|
||||
public:
|
||||
|
||||
MappedListTypeStreamer(const TypeStreamer* baseStreamer, const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
protected:
|
||||
|
||||
const TypeStreamer* _baseStreamer;
|
||||
TypeStreamerPointer _valueStreamer;
|
||||
};
|
||||
|
||||
/// A streamer for generic lists.
|
||||
class GenericListTypeStreamer : public GenericTypeStreamer {
|
||||
public:
|
||||
|
||||
GenericListTypeStreamer(const QByteArray& name, const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual Category getCategory() const;
|
||||
|
||||
private:
|
||||
|
||||
TypeStreamerPointer _valueStreamer;
|
||||
};
|
||||
|
||||
/// A streamer for set types.
|
||||
template<class T> class CollectionTypeStreamer<QSet<T> > : public SimpleTypeStreamer<QSet<T> > {
|
||||
public:
|
||||
|
||||
virtual TypeReader::Type getReaderType() const { return TypeReader::SET_TYPE; }
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const { out << getValueStreamer(); }
|
||||
virtual TypeStreamer::Category getCategory() const { return TypeStreamer::SET_CATEGORY; }
|
||||
virtual const TypeStreamer* getValueStreamer() const { return Bitstream::getTypeStreamer(qMetaTypeId<T>()); }
|
||||
virtual void insert(QVariant& object, const QVariant& value) const {
|
||||
static_cast<QSet<T>*>(object.data())->insert(value.value<T>()); }
|
||||
|
@ -1025,11 +1191,30 @@ public:
|
|||
return static_cast<QSet<T>*>(object.data())->remove(key.value<T>()); }
|
||||
};
|
||||
|
||||
/// A streamer for sets that maps to a local type.
|
||||
class MappedSetTypeStreamer : public MappedListTypeStreamer {
|
||||
public:
|
||||
|
||||
MappedSetTypeStreamer(const TypeStreamer* baseStreamer, const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
};
|
||||
|
||||
/// A streamer for generic sets.
|
||||
class GenericSetTypeStreamer : public GenericListTypeStreamer {
|
||||
public:
|
||||
|
||||
GenericSetTypeStreamer(const QByteArray& name, const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual Category getCategory() const;
|
||||
};
|
||||
|
||||
/// A streamer for hash types.
|
||||
template<class K, class V> class CollectionTypeStreamer<QHash<K, V> > : public SimpleTypeStreamer<QHash<K, V> > {
|
||||
public:
|
||||
|
||||
virtual TypeReader::Type getReaderType() const { return TypeReader::MAP_TYPE; }
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const { out << getKeyStreamer() << getValueStreamer(); }
|
||||
virtual TypeStreamer::Category getCategory() const { return TypeStreamer::MAP_CATEGORY; }
|
||||
virtual const TypeStreamer* getKeyStreamer() const { return Bitstream::getTypeStreamer(qMetaTypeId<K>()); }
|
||||
virtual const TypeStreamer* getValueStreamer() const { return Bitstream::getTypeStreamer(qMetaTypeId<V>()); }
|
||||
virtual void insert(QVariant& object, const QVariant& key, const QVariant& value) const {
|
||||
|
@ -1040,6 +1225,48 @@ public:
|
|||
return QVariant::fromValue(static_cast<const QHash<K, V>*>(object.constData())->value(key.value<K>())); }
|
||||
};
|
||||
|
||||
/// A streamer for maps that maps to a local type.
|
||||
class MappedMapTypeStreamer : public TypeStreamer {
|
||||
public:
|
||||
|
||||
MappedMapTypeStreamer(const TypeStreamer* baseStreamer, const TypeStreamerPointer& keyStreamer,
|
||||
const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual void readRawDelta(Bitstream& in, QVariant& object, const QVariant& reference) const;
|
||||
|
||||
private:
|
||||
|
||||
const TypeStreamer* _baseStreamer;
|
||||
TypeStreamerPointer _keyStreamer;
|
||||
TypeStreamerPointer _valueStreamer;
|
||||
};
|
||||
|
||||
/// A streamer for generic maps.
|
||||
class GenericMapTypeStreamer : public GenericTypeStreamer {
|
||||
public:
|
||||
|
||||
GenericMapTypeStreamer(const QByteArray& name, const TypeStreamerPointer& keyStreamer,
|
||||
const TypeStreamerPointer& valueStreamer);
|
||||
|
||||
virtual void writeMetadata(Bitstream& out, bool full) const;
|
||||
virtual void write(Bitstream& out, const QVariant& value) const;
|
||||
virtual QVariant read(Bitstream& in) const;
|
||||
virtual Category getCategory() const;
|
||||
|
||||
private:
|
||||
|
||||
TypeStreamerPointer _keyStreamer;
|
||||
TypeStreamerPointer _valueStreamer;
|
||||
};
|
||||
|
||||
/// A streamer class for generic values.
|
||||
class GenericValueStreamer : public SimpleTypeStreamer<GenericValue> {
|
||||
public:
|
||||
|
||||
virtual void writeVariant(Bitstream& out, const QVariant& value) const;
|
||||
};
|
||||
|
||||
/// Macro for registering simple type streamers.
|
||||
#define REGISTER_SIMPLE_TYPE_STREAMER(X) static int X##Streamer = \
|
||||
Bitstream::registerTypeStreamer(qMetaTypeId<X>(), new SimpleTypeStreamer<X>());
|
||||
|
|
|
@ -13,11 +13,96 @@
|
|||
|
||||
#include <QNetworkReply>
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "AttributeRegistry.h"
|
||||
#include "ScriptCache.h"
|
||||
|
||||
static int scriptValueMetaTypeId = qRegisterMetaType<QScriptValue>();
|
||||
static bool scriptValueComparators = QMetaType::registerComparators<QScriptValue>();
|
||||
|
||||
bool operator==(const QScriptValue& first, const QScriptValue& second) {
|
||||
if (first.isUndefined()) {
|
||||
return second.isUndefined();
|
||||
|
||||
} else if (first.isNull()) {
|
||||
return second.isNull();
|
||||
|
||||
} else if (first.isBool()) {
|
||||
return second.isBool() && first.toBool() == second.toBool();
|
||||
|
||||
} else if (first.isNumber()) {
|
||||
return second.isNumber() && first.toNumber() == second.toNumber();
|
||||
|
||||
} else if (first.isString()) {
|
||||
return second.isString() && first.toString() == second.toString();
|
||||
|
||||
} else if (first.isVariant()) {
|
||||
return second.isVariant() && first.toVariant() == second.toVariant();
|
||||
|
||||
} else if (first.isQObject()) {
|
||||
return second.isQObject() && first.toQObject() == second.toQObject();
|
||||
|
||||
} else if (first.isQMetaObject()) {
|
||||
return second.isQMetaObject() && first.toQMetaObject() == second.toQMetaObject();
|
||||
|
||||
} else if (first.isDate()) {
|
||||
return second.isDate() && first.toDateTime() == second.toDateTime();
|
||||
|
||||
} else if (first.isRegExp()) {
|
||||
return second.isRegExp() && first.toRegExp() == second.toRegExp();
|
||||
|
||||
} else if (first.isArray()) {
|
||||
if (!second.isArray()) {
|
||||
return false;
|
||||
}
|
||||
int length = first.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
||||
if (second.property(ScriptCache::getInstance()->getLengthString()).toInt32() != length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (first.property(i) != second.property(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (first.isObject()) {
|
||||
if (!second.isObject()) {
|
||||
return false;
|
||||
}
|
||||
int propertyCount = 0;
|
||||
for (QScriptValueIterator it(first); it.hasNext(); ) {
|
||||
it.next();
|
||||
if (second.property(it.scriptName()) != it.value()) {
|
||||
return false;
|
||||
}
|
||||
propertyCount++;
|
||||
}
|
||||
// make sure the second has exactly as many properties as the first
|
||||
for (QScriptValueIterator it(second); it.hasNext(); ) {
|
||||
it.next();
|
||||
if (--propertyCount < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// if none of the above tests apply, first must be invalid
|
||||
return !second.isValid();
|
||||
}
|
||||
}
|
||||
|
||||
bool operator!=(const QScriptValue& first, const QScriptValue& second) {
|
||||
return !(first == second);
|
||||
}
|
||||
|
||||
bool operator<(const QScriptValue& first, const QScriptValue& second) {
|
||||
return first.lessThan(second);
|
||||
}
|
||||
|
||||
ScriptCache* ScriptCache::getInstance() {
|
||||
static ScriptCache cache;
|
||||
return &cache;
|
||||
|
|
|
@ -65,6 +65,12 @@ private:
|
|||
QScriptString _generatorString;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QScriptValue)
|
||||
|
||||
bool operator==(const QScriptValue& first, const QScriptValue& second);
|
||||
bool operator!=(const QScriptValue& first, const QScriptValue& second);
|
||||
bool operator<(const QScriptValue& first, const QScriptValue& second);
|
||||
|
||||
/// A program loaded from the network.
|
||||
class NetworkProgram : public Resource {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -30,6 +30,11 @@ SharedObject::SharedObject() :
|
|||
_weakHash.insert(_id, this);
|
||||
}
|
||||
|
||||
void SharedObject::setID(int id) {
|
||||
_weakHash.remove(_id);
|
||||
_weakHash.insert(_id = id, this);
|
||||
}
|
||||
|
||||
void SharedObject::incrementReferenceCount() {
|
||||
_referenceCount.ref();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
/// Returns the unique local ID for this object.
|
||||
int getID() const { return _id; }
|
||||
|
||||
void setID(int id);
|
||||
|
||||
/// Returns the local origin ID for this object.
|
||||
int getOriginID() const { return _originID; }
|
||||
|
||||
|
|
|
@ -186,6 +186,11 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons
|
|||
if (fbxGeometry && fbxGeometry->meshExtents.isValid()) {
|
||||
Extents extents = fbxGeometry->meshExtents;
|
||||
|
||||
// NOTE: If the model has a bad mesh, then extents will be 0,0,0 & 0,0,0
|
||||
if (extents.minimum == extents.maximum && extents.minimum == glm::vec3(0,0,0)) {
|
||||
extents.maximum = glm::vec3(1.0f,1.0f,1.0f); // in this case we will simulate the unit cube
|
||||
}
|
||||
|
||||
// NOTE: these extents are model space, so we need to scale and center them accordingly
|
||||
// size is our "target size in world space"
|
||||
// we need to set our model scale so that the extents of the mesh, fit in a cube that size...
|
||||
|
|
|
@ -55,13 +55,13 @@ AccountManager::AccountManager() :
|
|||
{
|
||||
qRegisterMetaType<OAuthAccessToken>("OAuthAccessToken");
|
||||
qRegisterMetaTypeStreamOperators<OAuthAccessToken>("OAuthAccessToken");
|
||||
|
||||
|
||||
qRegisterMetaType<DataServerAccountInfo>("DataServerAccountInfo");
|
||||
qRegisterMetaTypeStreamOperators<DataServerAccountInfo>("DataServerAccountInfo");
|
||||
|
||||
|
||||
qRegisterMetaType<QNetworkAccessManager::Operation>("QNetworkAccessManager::Operation");
|
||||
qRegisterMetaType<JSONCallbackParameters>("JSONCallbackParameters");
|
||||
|
||||
|
||||
connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
|
||||
}
|
||||
|
||||
|
@ -70,18 +70,18 @@ const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
|
|||
void AccountManager::logout() {
|
||||
// a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
|
||||
_accountInfo = DataServerAccountInfo();
|
||||
|
||||
|
||||
emit balanceChanged(0);
|
||||
connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
|
||||
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup(ACCOUNTS_GROUP);
|
||||
|
||||
|
||||
QString keyURLString(_authURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE));
|
||||
settings.remove(keyURLString);
|
||||
|
||||
|
||||
qDebug() << "Removed account info for" << _authURL << "from in-memory accounts and .ini file";
|
||||
|
||||
|
||||
emit logoutComplete();
|
||||
// the username has changed to blank
|
||||
emit usernameChanged(QString());
|
||||
|
@ -93,7 +93,7 @@ void AccountManager::updateBalance() {
|
|||
JSONCallbackParameters callbackParameters;
|
||||
callbackParameters.jsonCallbackReceiver = &_accountInfo;
|
||||
callbackParameters.jsonCallbackMethod = "setBalanceFromJSON";
|
||||
|
||||
|
||||
authenticatedRequest("/api/v1/wallets/mine", QNetworkAccessManager::GetOperation, callbackParameters);
|
||||
}
|
||||
}
|
||||
|
@ -105,28 +105,33 @@ void AccountManager::accountInfoBalanceChanged(qint64 newBalance) {
|
|||
void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||
if (_authURL != authURL) {
|
||||
_authURL = authURL;
|
||||
|
||||
|
||||
qDebug() << "URL for node authentication has been changed to" << qPrintable(_authURL.toString());
|
||||
qDebug() << "Re-setting authentication flow.";
|
||||
|
||||
|
||||
// check if there are existing access tokens to load from settings
|
||||
QSettings settings;
|
||||
settings.beginGroup(ACCOUNTS_GROUP);
|
||||
|
||||
|
||||
foreach(const QString& key, settings.allKeys()) {
|
||||
// take a key copy to perform the double slash replacement
|
||||
QString keyCopy(key);
|
||||
QUrl keyURL(keyCopy.replace("slashslash", "//"));
|
||||
|
||||
|
||||
if (keyURL == _authURL) {
|
||||
// pull out the stored access token and store it in memory
|
||||
_accountInfo = settings.value(key).value<DataServerAccountInfo>();
|
||||
qDebug() << "Found a data-server access token for" << qPrintable(keyURL.toString());
|
||||
|
||||
emit accessTokenChanged();
|
||||
|
||||
// profile info isn't guaranteed to be saved too
|
||||
if (_accountInfo.hasProfile()) {
|
||||
emit profileChanged();
|
||||
} else {
|
||||
requestProfile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// tell listeners that the auth endpoint has changed
|
||||
emit authEndpointChanged();
|
||||
}
|
||||
|
@ -147,36 +152,36 @@ void AccountManager::authenticatedRequest(const QString& path, QNetworkAccessMan
|
|||
void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::Operation operation,
|
||||
const JSONCallbackParameters& callbackParams,
|
||||
const QByteArray& dataByteArray, QHttpMultiPart* dataMultiPart) {
|
||||
|
||||
|
||||
if (!_networkAccessManager) {
|
||||
_networkAccessManager = new QNetworkAccessManager(this);
|
||||
}
|
||||
|
||||
|
||||
if (hasValidAccessToken()) {
|
||||
QNetworkRequest authenticatedRequest;
|
||||
|
||||
|
||||
QUrl requestURL = _authURL;
|
||||
|
||||
|
||||
if (path.startsWith("/")) {
|
||||
requestURL.setPath(path);
|
||||
} else {
|
||||
requestURL.setPath("/" + path);
|
||||
}
|
||||
|
||||
|
||||
requestURL.setQuery("access_token=" + _accountInfo.getAccessToken().token);
|
||||
|
||||
|
||||
authenticatedRequest.setUrl(requestURL);
|
||||
|
||||
|
||||
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
||||
qDebug() << "Making an authenticated request to" << qPrintable(requestURL.toString());
|
||||
|
||||
|
||||
if (!dataByteArray.isEmpty()) {
|
||||
qDebug() << "The POST/PUT body -" << QString(dataByteArray);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QNetworkReply* networkReply = NULL;
|
||||
|
||||
|
||||
switch (operation) {
|
||||
case QNetworkAccessManager::GetOperation:
|
||||
networkReply = _networkAccessManager->get(authenticatedRequest);
|
||||
|
@ -198,24 +203,24 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
|||
networkReply = _networkAccessManager->put(authenticatedRequest, dataByteArray);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
// other methods not yet handled
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (networkReply) {
|
||||
if (!callbackParams.isEmpty()) {
|
||||
// if we have information for a callback, insert the callbackParams into our local map
|
||||
_pendingCallbackMap.insert(networkReply, callbackParams);
|
||||
|
||||
|
||||
if (callbackParams.updateReciever && !callbackParams.updateSlot.isEmpty()) {
|
||||
callbackParams.updateReciever->connect(networkReply, SIGNAL(uploadProgress(qint64, qint64)),
|
||||
callbackParams.updateSlot.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if we ended up firing of a request, hook up to it now
|
||||
connect(networkReply, SIGNAL(finished()), SLOT(processReply()));
|
||||
}
|
||||
|
@ -224,7 +229,7 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
|||
|
||||
void AccountManager::processReply() {
|
||||
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
|
||||
|
||||
if (requestReply->error() == QNetworkReply::NoError) {
|
||||
passSuccessToCallback(requestReply);
|
||||
} else {
|
||||
|
@ -235,17 +240,17 @@ void AccountManager::processReply() {
|
|||
|
||||
void AccountManager::passSuccessToCallback(QNetworkReply* requestReply) {
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll());
|
||||
|
||||
|
||||
JSONCallbackParameters callbackParams = _pendingCallbackMap.value(requestReply);
|
||||
|
||||
|
||||
if (callbackParams.jsonCallbackReceiver) {
|
||||
// invoke the right method on the callback receiver
|
||||
QMetaObject::invokeMethod(callbackParams.jsonCallbackReceiver, qPrintable(callbackParams.jsonCallbackMethod),
|
||||
Q_ARG(const QJsonObject&, jsonResponse.object()));
|
||||
|
||||
|
||||
// remove the related reply-callback group from the map
|
||||
_pendingCallbackMap.remove(requestReply);
|
||||
|
||||
|
||||
} else {
|
||||
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
||||
qDebug() << "Received JSON response from data-server that has no matching callback.";
|
||||
|
@ -256,13 +261,13 @@ void AccountManager::passSuccessToCallback(QNetworkReply* requestReply) {
|
|||
|
||||
void AccountManager::passErrorToCallback(QNetworkReply* requestReply) {
|
||||
JSONCallbackParameters callbackParams = _pendingCallbackMap.value(requestReply);
|
||||
|
||||
|
||||
if (callbackParams.errorCallbackReceiver) {
|
||||
// invoke the right method on the callback receiver
|
||||
QMetaObject::invokeMethod(callbackParams.errorCallbackReceiver, qPrintable(callbackParams.errorCallbackMethod),
|
||||
Q_ARG(QNetworkReply::NetworkError, requestReply->error()),
|
||||
Q_ARG(const QString&, requestReply->errorString()));
|
||||
|
||||
|
||||
// remove the related reply-callback group from the map
|
||||
_pendingCallbackMap.remove(requestReply);
|
||||
} else {
|
||||
|
@ -274,12 +279,12 @@ void AccountManager::passErrorToCallback(QNetworkReply* requestReply) {
|
|||
}
|
||||
|
||||
bool AccountManager::hasValidAccessToken() {
|
||||
|
||||
|
||||
if (_accountInfo.getAccessToken().token.isEmpty() || _accountInfo.getAccessToken().isExpired()) {
|
||||
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
||||
qDebug() << "An access token is required for requests to" << qPrintable(_authURL.toString());
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -288,12 +293,12 @@ bool AccountManager::hasValidAccessToken() {
|
|||
|
||||
bool AccountManager::checkAndSignalForAccessToken() {
|
||||
bool hasToken = hasValidAccessToken();
|
||||
|
||||
|
||||
if (!hasToken) {
|
||||
// emit a signal so somebody can call back to us and request an access token given a username and password
|
||||
emit authRequired();
|
||||
}
|
||||
|
||||
|
||||
return hasToken;
|
||||
}
|
||||
|
||||
|
@ -304,36 +309,36 @@ void AccountManager::requestAccessToken(const QString& login, const QString& pas
|
|||
}
|
||||
|
||||
QNetworkRequest request;
|
||||
|
||||
|
||||
QUrl grantURL = _authURL;
|
||||
grantURL.setPath("/oauth/token");
|
||||
|
||||
|
||||
const QString ACCOUNT_MANAGER_REQUESTED_SCOPE = "owner";
|
||||
|
||||
|
||||
QByteArray postData;
|
||||
postData.append("grant_type=password&");
|
||||
postData.append("username=" + login + "&");
|
||||
postData.append("password=" + QUrl::toPercentEncoding(password) + "&");
|
||||
postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE);
|
||||
|
||||
|
||||
request.setUrl(grantURL);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
|
||||
QNetworkReply* requestReply = _networkAccessManager->post(request, postData);
|
||||
connect(requestReply, &QNetworkReply::finished, this, &AccountManager::requestFinished);
|
||||
connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError)));
|
||||
connect(requestReply, &QNetworkReply::finished, this, &AccountManager::requestAccessTokenFinished);
|
||||
connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestAccessTokenError(QNetworkReply::NetworkError)));
|
||||
}
|
||||
|
||||
|
||||
void AccountManager::requestFinished() {
|
||||
void AccountManager::requestAccessTokenFinished() {
|
||||
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
|
||||
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll());
|
||||
const QJsonObject& rootObject = jsonResponse.object();
|
||||
|
||||
|
||||
if (!rootObject.contains("error")) {
|
||||
// construct an OAuthAccessToken from the json object
|
||||
|
||||
|
||||
if (!rootObject.contains("access_token") || !rootObject.contains("expires_in")
|
||||
|| !rootObject.contains("token_type")) {
|
||||
// TODO: error handling - malformed token response
|
||||
|
@ -342,23 +347,21 @@ void AccountManager::requestFinished() {
|
|||
// clear the path from the response URL so we have the right root URL for this access token
|
||||
QUrl rootURL = requestReply->url();
|
||||
rootURL.setPath("");
|
||||
|
||||
|
||||
qDebug() << "Storing an account with access-token for" << qPrintable(rootURL.toString());
|
||||
|
||||
_accountInfo = DataServerAccountInfo(rootObject);
|
||||
|
||||
|
||||
_accountInfo = DataServerAccountInfo();
|
||||
_accountInfo.setAccessTokenFromJSON(rootObject);
|
||||
|
||||
emit loginComplete(rootURL);
|
||||
// the username has changed to whatever came back
|
||||
emit usernameChanged(_accountInfo.getUsername());
|
||||
|
||||
// we have found or requested an access token
|
||||
emit accessTokenChanged();
|
||||
|
||||
|
||||
// store this access token into the local settings
|
||||
QSettings localSettings;
|
||||
localSettings.beginGroup(ACCOUNTS_GROUP);
|
||||
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
|
||||
QVariant::fromValue(_accountInfo));
|
||||
|
||||
requestProfile();
|
||||
}
|
||||
} else {
|
||||
// TODO: error handling
|
||||
|
@ -367,7 +370,53 @@ void AccountManager::requestFinished() {
|
|||
}
|
||||
}
|
||||
|
||||
void AccountManager::requestError(QNetworkReply::NetworkError error) {
|
||||
void AccountManager::requestAccessTokenError(QNetworkReply::NetworkError error) {
|
||||
// TODO: error handling
|
||||
qDebug() << "AccountManager requestError - " << error;
|
||||
}
|
||||
|
||||
void AccountManager::requestProfile() {
|
||||
if (!_networkAccessManager) {
|
||||
_networkAccessManager = new QNetworkAccessManager(this);
|
||||
}
|
||||
|
||||
QUrl profileURL = _authURL;
|
||||
profileURL.setPath("/api/v1/users/profile");
|
||||
profileURL.setQuery("access_token=" + _accountInfo.getAccessToken().token);
|
||||
|
||||
QNetworkReply* profileReply = _networkAccessManager->get(QNetworkRequest(profileURL));
|
||||
connect(profileReply, &QNetworkReply::finished, this, &AccountManager::requestProfileFinished);
|
||||
connect(profileReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestProfileError(QNetworkReply::NetworkError)));
|
||||
}
|
||||
|
||||
void AccountManager::requestProfileFinished() {
|
||||
QNetworkReply* profileReply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(profileReply->readAll());
|
||||
const QJsonObject& rootObject = jsonResponse.object();
|
||||
|
||||
if (rootObject.contains("status") && rootObject["status"].toString() == "success") {
|
||||
_accountInfo.setProfileInfoFromJSON(rootObject);
|
||||
|
||||
emit profileChanged();
|
||||
|
||||
// the username has changed to whatever came back
|
||||
emit usernameChanged(_accountInfo.getUsername());
|
||||
|
||||
// store the whole profile into the local settings
|
||||
QUrl rootURL = profileReply->url();
|
||||
rootURL.setPath("");
|
||||
QSettings localSettings;
|
||||
localSettings.beginGroup(ACCOUNTS_GROUP);
|
||||
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
|
||||
QVariant::fromValue(_accountInfo));
|
||||
} else {
|
||||
// TODO: error handling
|
||||
qDebug() << "Error in response for profile";
|
||||
}
|
||||
}
|
||||
|
||||
void AccountManager::requestProfileError(QNetworkReply::NetworkError error) {
|
||||
// TODO: error handling
|
||||
qDebug() << "AccountManager requestProfileError - " << error;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
class JSONCallbackParameters {
|
||||
public:
|
||||
JSONCallbackParameters();
|
||||
|
||||
|
||||
bool isEmpty() const { return !jsonCallbackReceiver && !errorCallbackReceiver; }
|
||||
|
||||
|
||||
QObject* jsonCallbackReceiver;
|
||||
QString jsonCallbackMethod;
|
||||
QObject* errorCallbackReceiver;
|
||||
|
@ -38,30 +38,33 @@ class AccountManager : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
static AccountManager& getInstance();
|
||||
|
||||
|
||||
void authenticatedRequest(const QString& path,
|
||||
QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
|
||||
const JSONCallbackParameters& callbackParams = JSONCallbackParameters(),
|
||||
const QByteArray& dataByteArray = QByteArray(),
|
||||
QHttpMultiPart* dataMultiPart = NULL);
|
||||
|
||||
|
||||
const QUrl& getAuthURL() const { return _authURL; }
|
||||
void setAuthURL(const QUrl& authURL);
|
||||
bool hasAuthEndpoint() { return !_authURL.isEmpty(); }
|
||||
|
||||
|
||||
bool isLoggedIn() { return !_authURL.isEmpty() && hasValidAccessToken(); }
|
||||
bool hasValidAccessToken();
|
||||
Q_INVOKABLE bool checkAndSignalForAccessToken();
|
||||
|
||||
|
||||
void requestAccessToken(const QString& login, const QString& password);
|
||||
|
||||
void requestProfile();
|
||||
|
||||
const DataServerAccountInfo& getAccountInfo() const { return _accountInfo; }
|
||||
|
||||
|
||||
void destroy() { delete _networkAccessManager; }
|
||||
|
||||
|
||||
public slots:
|
||||
void requestFinished();
|
||||
void requestError(QNetworkReply::NetworkError error);
|
||||
void requestAccessTokenFinished();
|
||||
void requestProfileFinished();
|
||||
void requestAccessTokenError(QNetworkReply::NetworkError error);
|
||||
void requestProfileError(QNetworkReply::NetworkError error);
|
||||
void logout();
|
||||
void updateBalance();
|
||||
void accountInfoBalanceChanged(qint64 newBalance);
|
||||
|
@ -69,7 +72,7 @@ signals:
|
|||
void authRequired();
|
||||
void authEndpointChanged();
|
||||
void usernameChanged(const QString& username);
|
||||
void accessTokenChanged();
|
||||
void profileChanged();
|
||||
void loginComplete(const QUrl& authURL);
|
||||
void loginFailed();
|
||||
void logoutComplete();
|
||||
|
@ -80,19 +83,19 @@ private:
|
|||
AccountManager();
|
||||
AccountManager(AccountManager const& other); // not implemented
|
||||
void operator=(AccountManager const& other); // not implemented
|
||||
|
||||
|
||||
void passSuccessToCallback(QNetworkReply* reply);
|
||||
void passErrorToCallback(QNetworkReply* reply);
|
||||
|
||||
|
||||
Q_INVOKABLE void invokedRequest(const QString& path, QNetworkAccessManager::Operation operation,
|
||||
const JSONCallbackParameters& callbackParams,
|
||||
const QByteArray& dataByteArray,
|
||||
QHttpMultiPart* dataMultiPart);
|
||||
|
||||
|
||||
QUrl _authURL;
|
||||
QNetworkAccessManager* _networkAccessManager;
|
||||
QMap<QNetworkReply*, JSONCallbackParameters> _pendingCallbackMap;
|
||||
|
||||
|
||||
DataServerAccountInfo _accountInfo;
|
||||
};
|
||||
|
||||
|
|
|
@ -21,20 +21,7 @@ DataServerAccountInfo::DataServerAccountInfo() :
|
|||
_balance(0),
|
||||
_hasBalance(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DataServerAccountInfo::DataServerAccountInfo(const QJsonObject& jsonObject) :
|
||||
_accessToken(jsonObject),
|
||||
_username(),
|
||||
_xmppPassword(),
|
||||
_balance(0),
|
||||
_hasBalance(false)
|
||||
{
|
||||
QJsonObject userJSONObject = jsonObject["user"].toObject();
|
||||
setUsername(userJSONObject["username"].toString());
|
||||
setXMPPPassword(userJSONObject["xmpp_password"].toString());
|
||||
setDiscourseApiKey(userJSONObject["discourse_api_key"].toString());
|
||||
}
|
||||
|
||||
DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherInfo) {
|
||||
|
@ -54,7 +41,7 @@ DataServerAccountInfo& DataServerAccountInfo::operator=(const DataServerAccountI
|
|||
|
||||
void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) {
|
||||
using std::swap;
|
||||
|
||||
|
||||
swap(_accessToken, otherInfo._accessToken);
|
||||
swap(_username, otherInfo._username);
|
||||
swap(_xmppPassword, otherInfo._xmppPassword);
|
||||
|
@ -63,10 +50,14 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) {
|
|||
swap(_hasBalance, otherInfo._hasBalance);
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setAccessTokenFromJSON(const QJsonObject& jsonObject) {
|
||||
_accessToken = OAuthAccessToken(jsonObject);
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setUsername(const QString& username) {
|
||||
if (_username != username) {
|
||||
_username = username;
|
||||
|
||||
|
||||
qDebug() << "Username changed to" << username;
|
||||
}
|
||||
}
|
||||
|
@ -87,18 +78,29 @@ void DataServerAccountInfo::setBalance(qint64 balance) {
|
|||
if (!_hasBalance || _balance != balance) {
|
||||
_balance = balance;
|
||||
_hasBalance = true;
|
||||
|
||||
|
||||
emit balanceChanged(_balance);
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setBalanceFromJSON(const QJsonObject& jsonObject) {
|
||||
if (jsonObject["status"].toString() == "success") {
|
||||
qint64 balanceInSatoshis = jsonObject["data"].toObject()["wallet"].toObject()["balance"].toInt();
|
||||
qint64 balanceInSatoshis = jsonObject["data"].toObject()["wallet"].toObject()["balance"].toDouble();
|
||||
setBalance(balanceInSatoshis);
|
||||
}
|
||||
}
|
||||
|
||||
bool DataServerAccountInfo::hasProfile() const {
|
||||
return _username.length() > 0;
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject) {
|
||||
QJsonObject user = jsonObject["data"].toObject()["user"].toObject();
|
||||
setUsername(user["username"].toString());
|
||||
setXMPPPassword(user["xmpp_password"].toString());
|
||||
setDiscourseApiKey(user["discourse_api_key"].toString());
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) {
|
||||
out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey;
|
||||
return out;
|
||||
|
|
|
@ -22,12 +22,12 @@ class DataServerAccountInfo : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
DataServerAccountInfo();
|
||||
DataServerAccountInfo(const QJsonObject& jsonObject);
|
||||
DataServerAccountInfo(const DataServerAccountInfo& otherInfo);
|
||||
DataServerAccountInfo& operator=(const DataServerAccountInfo& otherInfo);
|
||||
|
||||
|
||||
const OAuthAccessToken& getAccessToken() const { return _accessToken; }
|
||||
|
||||
void setAccessTokenFromJSON(const QJsonObject& jsonObject);
|
||||
|
||||
const QString& getUsername() const { return _username; }
|
||||
void setUsername(const QString& username);
|
||||
|
||||
|
@ -36,20 +36,24 @@ public:
|
|||
|
||||
const QString& getDiscourseApiKey() const { return _discourseApiKey; }
|
||||
void setDiscourseApiKey(const QString& discourseApiKey);
|
||||
|
||||
|
||||
qint64 getBalance() const { return _balance; }
|
||||
void setBalance(qint64 balance);
|
||||
bool hasBalance() const { return _hasBalance; }
|
||||
void setHasBalance(bool hasBalance) { _hasBalance = hasBalance; }
|
||||
Q_INVOKABLE void setBalanceFromJSON(const QJsonObject& jsonObject);
|
||||
|
||||
bool hasProfile() const;
|
||||
|
||||
void setProfileInfoFromJSON(const QJsonObject& jsonObject);
|
||||
|
||||
friend QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info);
|
||||
friend QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info);
|
||||
signals:
|
||||
qint64 balanceChanged(qint64 newBalance);
|
||||
private:
|
||||
void swap(DataServerAccountInfo& otherInfo);
|
||||
|
||||
|
||||
OAuthAccessToken _accessToken;
|
||||
QString _username;
|
||||
QString _xmppPassword;
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
#include "NetworkPacket.h"
|
||||
|
||||
void NetworkPacket::copyContents(const SharedNodePointer& destinationNode, const QByteArray& packet) {
|
||||
void NetworkPacket::copyContents(const SharedNodePointer& node, const QByteArray& packet) {
|
||||
if (packet.size() && packet.size() <= MAX_PACKET_SIZE) {
|
||||
_destinationNode = destinationNode;
|
||||
_node = node;
|
||||
_byteArray = packet;
|
||||
} else {
|
||||
qDebug(">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
|
||||
|
@ -27,28 +27,28 @@ void NetworkPacket::copyContents(const SharedNodePointer& destinationNode, const
|
|||
}
|
||||
|
||||
NetworkPacket::NetworkPacket(const NetworkPacket& packet) {
|
||||
copyContents(packet.getDestinationNode(), packet.getByteArray());
|
||||
copyContents(packet.getNode(), packet.getByteArray());
|
||||
}
|
||||
|
||||
NetworkPacket::NetworkPacket(const SharedNodePointer& destinationNode, const QByteArray& packet) {
|
||||
copyContents(destinationNode, packet);
|
||||
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const QByteArray& packet) {
|
||||
copyContents(node, packet);
|
||||
};
|
||||
|
||||
// copy assignment
|
||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
|
||||
copyContents(other.getDestinationNode(), other.getByteArray());
|
||||
copyContents(other.getNode(), other.getByteArray());
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef HAS_MOVE_SEMANTICS
|
||||
// move, same as copy, but other packet won't be used further
|
||||
NetworkPacket::NetworkPacket(NetworkPacket && packet) {
|
||||
copyContents(packet.getDestinationNode(), packet.getByteArray());
|
||||
copyContents(packet.getNode(), packet.getByteArray());
|
||||
}
|
||||
|
||||
// move assignment
|
||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
|
||||
copyContents(other.getDestinationNode(), other.getByteArray());
|
||||
copyContents(other.getNode(), other.getByteArray());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
||||
class NetworkPacket {
|
||||
public:
|
||||
NetworkPacket() { }
|
||||
NetworkPacket(const NetworkPacket& packet); // copy constructor
|
||||
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
||||
|
||||
|
@ -34,15 +35,15 @@ public:
|
|||
NetworkPacket& operator= (NetworkPacket&& other); // move assignment
|
||||
#endif
|
||||
|
||||
NetworkPacket(const SharedNodePointer& destinationNode, const QByteArray& byteArray);
|
||||
NetworkPacket(const SharedNodePointer& node, const QByteArray& byteArray);
|
||||
|
||||
const SharedNodePointer& getDestinationNode() const { return _destinationNode; }
|
||||
const SharedNodePointer& getNode() const { return _node; }
|
||||
const QByteArray& getByteArray() const { return _byteArray; }
|
||||
|
||||
private:
|
||||
void copyContents(const SharedNodePointer& destinationNode, const QByteArray& byteArray);
|
||||
void copyContents(const SharedNodePointer& node, const QByteArray& byteArray);
|
||||
|
||||
SharedNodePointer _destinationNode;
|
||||
SharedNodePointer _node;
|
||||
QByteArray _byteArray;
|
||||
};
|
||||
|
||||
|
|
|
@ -281,7 +281,7 @@ void NodeList::processSTUNResponse(const QByteArray& packet) {
|
|||
int byteIndex = attributeStartIndex + NUM_BYTES_STUN_ATTR_TYPE_AND_LENGTH + NUM_BYTES_FAMILY_ALIGN;
|
||||
|
||||
uint8_t addressFamily = 0;
|
||||
memcpy(&addressFamily, packet.data(), sizeof(addressFamily));
|
||||
memcpy(&addressFamily, packet.data() + byteIndex, sizeof(addressFamily));
|
||||
|
||||
byteIndex += sizeof(addressFamily);
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ bool PacketSender::nonThreadedProcess() {
|
|||
unlock();
|
||||
|
||||
// send the packet through the NodeList...
|
||||
NodeList::getInstance()->writeDatagram(temporary.getByteArray(), temporary.getDestinationNode());
|
||||
NodeList::getInstance()->writeDatagram(temporary.getByteArray(), temporary.getNode());
|
||||
packetsSentThisCall++;
|
||||
_packetsOverCheckInterval++;
|
||||
_totalPacketsSent++;
|
||||
|
|
|
@ -17,13 +17,14 @@ void ReceivedPacketProcessor::terminating() {
|
|||
_hasPackets.wakeAll();
|
||||
}
|
||||
|
||||
void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& destinationNode, const QByteArray& packet) {
|
||||
void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
||||
// Make sure our Node and NodeList knows we've heard from this node.
|
||||
destinationNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||
sendingNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||
|
||||
NetworkPacket networkPacket(destinationNode, packet);
|
||||
NetworkPacket networkPacket(sendingNode, packet);
|
||||
lock();
|
||||
_packets.push_back(networkPacket);
|
||||
_nodePacketCounts[sendingNode->getUUID()]++;
|
||||
unlock();
|
||||
|
||||
// Make sure to wake our actual processing thread because we now have packets for it to process.
|
||||
|
@ -42,8 +43,15 @@ bool ReceivedPacketProcessor::process() {
|
|||
NetworkPacket& packet = _packets.front(); // get the oldest packet
|
||||
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
|
||||
_packets.erase(_packets.begin()); // remove the oldest packet
|
||||
_nodePacketCounts[temporary.getNode()->getUUID()]--;
|
||||
unlock(); // let others add to the packets
|
||||
processPacket(temporary.getDestinationNode(), temporary.getByteArray()); // process our temporary copy
|
||||
processPacket(temporary.getNode(), temporary.getByteArray()); // process our temporary copy
|
||||
}
|
||||
return isStillRunning(); // keep running till they terminate us
|
||||
}
|
||||
|
||||
void ReceivedPacketProcessor::nodeKilled(SharedNodePointer node) {
|
||||
lock();
|
||||
_nodePacketCounts.remove(node->getUUID());
|
||||
unlock();
|
||||
}
|
||||
|
|
|
@ -28,20 +28,26 @@ public:
|
|||
/// \param packetData pointer to received data
|
||||
/// \param ssize_t packetLength size of received data
|
||||
/// \thread network receive thread
|
||||
void queueReceivedPacket(const SharedNodePointer& destinationNode, const QByteArray& packet);
|
||||
void queueReceivedPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
|
||||
|
||||
/// Are there received packets waiting to be processed
|
||||
bool hasPacketsToProcess() const { return _packets.size() > 0; }
|
||||
|
||||
/// Are there received packets waiting to be processed from a certain node
|
||||
bool hasPacketsToProcessFrom(const SharedNodePointer& sendingNode) const {
|
||||
return _nodePacketCounts[sendingNode->getUUID()] > 0;
|
||||
}
|
||||
|
||||
/// How many received packets waiting are to be processed
|
||||
int packetsToProcessCount() const { return _packets.size(); }
|
||||
|
||||
public slots:
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
|
||||
protected:
|
||||
/// Callback for processing of recieved packets. Implement this to process the incoming packets.
|
||||
/// \param sockaddr& senderAddress the address of the sender
|
||||
/// \param packetData pointer to received data
|
||||
/// \param ssize_t packetLength size of received data
|
||||
/// \thread "this" individual processing thread
|
||||
/// \param SharedNodePointer& sendingNode the node that sent this packet
|
||||
/// \param QByteArray& the packet to be processed
|
||||
virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) = 0;
|
||||
|
||||
/// Implements generic processing behavior for this thread.
|
||||
|
@ -51,7 +57,9 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
std::vector<NetworkPacket> _packets;
|
||||
QVector<NetworkPacket> _packets;
|
||||
QHash<QUuid, int> _nodePacketCounts;
|
||||
|
||||
QWaitCondition _hasPackets;
|
||||
QMutex _waitingOnPacketsMutex;
|
||||
};
|
||||
|
|
|
@ -180,6 +180,18 @@ static bool findIntersection(float origin, float direction, float corner, float
|
|||
return false;
|
||||
}
|
||||
|
||||
// finds the intersection between a ray and the inside facing plane on one axis
|
||||
static bool findInsideOutIntersection(float origin, float direction, float corner, float size, float& distance) {
|
||||
if (direction > EPSILON) {
|
||||
distance = -1.0f * (origin - (corner + size)) / direction;
|
||||
return true;
|
||||
} else if (direction < -EPSILON) {
|
||||
distance = -1.0f * (origin - corner) / direction;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AABox::expandedIntersectsSegment(const glm::vec3& start, const glm::vec3& end, float expansion) const {
|
||||
// handle the trivial cases where the expanded box contains the start or end
|
||||
if (expandedContains(start, expansion) || expandedContains(end, expansion)) {
|
||||
|
@ -207,9 +219,34 @@ bool AABox::expandedIntersectsSegment(const glm::vec3& start, const glm::vec3& e
|
|||
bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const {
|
||||
// handle the trivial case where the box contains the origin
|
||||
if (contains(origin)) {
|
||||
// We still want to calculate the distance from the origin to the inside out plane
|
||||
float axisDistance;
|
||||
if ((findInsideOutIntersection(origin.x, direction.x, _corner.x, _scale.x, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale.y) &&
|
||||
isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale.z))) {
|
||||
distance = axisDistance;
|
||||
face = direction.x > 0 ? MAX_X_FACE : MIN_X_FACE;
|
||||
return true;
|
||||
}
|
||||
if ((findInsideOutIntersection(origin.y, direction.y, _corner.y, _scale.y, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale.x) &&
|
||||
isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale.z))) {
|
||||
distance = axisDistance;
|
||||
face = direction.y > 0 ? MAX_Y_FACE : MIN_Y_FACE;
|
||||
return true;
|
||||
}
|
||||
if ((findInsideOutIntersection(origin.z, direction.z, _corner.z, _scale.z, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale.y) &&
|
||||
isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale.x))) {
|
||||
distance = axisDistance;
|
||||
face = direction.z > 0 ? MAX_Z_FACE : MIN_Z_FACE;
|
||||
return true;
|
||||
}
|
||||
// This case is unexpected, but mimics the previous behavior for inside out intersections
|
||||
distance = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// check each axis
|
||||
float axisDistance;
|
||||
if ((findIntersection(origin.x, direction.x, _corner.x, _scale.x, axisDistance) && axisDistance >= 0 &&
|
||||
|
|
|
@ -169,6 +169,18 @@ static bool findIntersection(float origin, float direction, float corner, float
|
|||
return false;
|
||||
}
|
||||
|
||||
// finds the intersection between a ray and the inside facing plane on one axis
|
||||
static bool findInsideOutIntersection(float origin, float direction, float corner, float size, float& distance) {
|
||||
if (direction > EPSILON) {
|
||||
distance = -1.0f * (origin - (corner + size)) / direction;
|
||||
return true;
|
||||
} else if (direction < -EPSILON) {
|
||||
distance = -1.0f * (origin - corner) / direction;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AACube::expandedIntersectsSegment(const glm::vec3& start, const glm::vec3& end, float expansion) const {
|
||||
// handle the trivial cases where the expanded box contains the start or end
|
||||
if (expandedContains(start, expansion) || expandedContains(end, expansion)) {
|
||||
|
@ -196,9 +208,35 @@ bool AACube::expandedIntersectsSegment(const glm::vec3& start, const glm::vec3&
|
|||
bool AACube::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const {
|
||||
// handle the trivial case where the box contains the origin
|
||||
if (contains(origin)) {
|
||||
|
||||
// We still want to calculate the distance from the origin to the inside out plane
|
||||
float axisDistance;
|
||||
if ((findInsideOutIntersection(origin.x, direction.x, _corner.x, _scale, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale) &&
|
||||
isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale))) {
|
||||
distance = axisDistance;
|
||||
face = direction.x > 0 ? MAX_X_FACE : MIN_X_FACE;
|
||||
return true;
|
||||
}
|
||||
if ((findInsideOutIntersection(origin.y, direction.y, _corner.y, _scale, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale) &&
|
||||
isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale))) {
|
||||
distance = axisDistance;
|
||||
face = direction.y > 0 ? MAX_Y_FACE : MIN_Y_FACE;
|
||||
return true;
|
||||
}
|
||||
if ((findInsideOutIntersection(origin.z, direction.z, _corner.z, _scale, axisDistance) && axisDistance >= 0 &&
|
||||
isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale) &&
|
||||
isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale))) {
|
||||
distance = axisDistance;
|
||||
face = direction.z > 0 ? MAX_Z_FACE : MIN_Z_FACE;
|
||||
return true;
|
||||
}
|
||||
// This case is unexpected, but mimics the previous behavior for inside out intersections
|
||||
distance = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// check each axis
|
||||
float axisDistance;
|
||||
if ((findIntersection(origin.x, direction.x, _corner.x, _scale, axisDistance) && axisDistance >= 0 &&
|
||||
|
|
|
@ -147,7 +147,12 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL,
|
|||
QEventLoop loop;
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
_scriptContents = reply->readAll();
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptContents = reply->readAll();
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << url.toString();
|
||||
emit errorMessage("ERROR Loading file:" + url.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
#include "CapsuleShape.h"
|
||||
|
||||
#include "GeometryUtil.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
|
||||
|
@ -84,3 +86,11 @@ void CapsuleShape::setEndPoints(const glm::vec3& startPoint, const glm::vec3& en
|
|||
updateBoundingRadius();
|
||||
}
|
||||
|
||||
bool CapsuleShape::findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const {
|
||||
glm::vec3 capsuleStart, capsuleEnd;
|
||||
getStartPoint(capsuleStart);
|
||||
getEndPoint(capsuleEnd);
|
||||
// NOTE: findRayCapsuleIntersection returns 'true' with distance = 0 when rayStart is inside capsule.
|
||||
// TODO: implement the raycast to return inside surface intersection for the internal rayStart.
|
||||
return findRayCapsuleIntersection(rayStart, rayDirection, capsuleStart, capsuleEnd, _radius, distance);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
/// Sets the endpoints and updates center, rotation, and halfHeight to agree.
|
||||
virtual void setEndPoints(const glm::vec3& startPoint, const glm::vec3& endPoint);
|
||||
|
||||
bool findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const;
|
||||
|
||||
protected:
|
||||
virtual void updateBoundingRadius() { _boundingRadius = _radius + getHalfHeight(); }
|
||||
|
||||
|
|
|
@ -19,71 +19,70 @@
|
|||
#include "HifiConfigVariantMap.h"
|
||||
|
||||
QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringList& argumentList) {
|
||||
|
||||
|
||||
QVariantMap mergedMap;
|
||||
|
||||
|
||||
// Add anything in the CL parameter list to the variant map.
|
||||
// Take anything with a dash in it as a key, and the values after it as the value.
|
||||
|
||||
|
||||
const QString DASHED_KEY_REGEX_STRING = "(^-{1,2})([\\w-]+)";
|
||||
QRegExp dashedKeyRegex(DASHED_KEY_REGEX_STRING);
|
||||
|
||||
|
||||
int keyIndex = argumentList.indexOf(dashedKeyRegex);
|
||||
int nextKeyIndex = 0;
|
||||
|
||||
|
||||
// check if there is a config file to read where we can pull config info not passed on command line
|
||||
const QString CONFIG_FILE_OPTION = "--config";
|
||||
|
||||
|
||||
while (keyIndex != -1) {
|
||||
if (argumentList[keyIndex] != CONFIG_FILE_OPTION) {
|
||||
// we have a key - look forward to see how many values associate to it
|
||||
QString key = dashedKeyRegex.cap(2);
|
||||
|
||||
|
||||
nextKeyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
|
||||
|
||||
|
||||
if (nextKeyIndex == keyIndex + 1 || keyIndex == argumentList.size() - 1) {
|
||||
// there's no value associated with this option, it's a boolean
|
||||
// so add it to the variant map with NULL as value
|
||||
mergedMap.insertMulti(key, QVariant());
|
||||
// this option is simply a switch, so add it to the map with a value of `true`
|
||||
mergedMap.insertMulti(key, QVariant(true));
|
||||
} else {
|
||||
int maxIndex = (nextKeyIndex == -1) ? argumentList.size() - 1: nextKeyIndex;
|
||||
|
||||
int maxIndex = (nextKeyIndex == -1) ? argumentList.size() : nextKeyIndex;
|
||||
|
||||
// there's at least one value associated with the option
|
||||
// pull the first value to start
|
||||
QString value = argumentList[keyIndex + 1];
|
||||
|
||||
|
||||
// for any extra values, append them, with a space, to the value string
|
||||
for (int i = keyIndex + 2; i <= maxIndex; i++) {
|
||||
for (int i = keyIndex + 2; i < maxIndex; i++) {
|
||||
value += " " + argumentList[i];
|
||||
}
|
||||
|
||||
|
||||
// add the finalized value to the merged map
|
||||
mergedMap.insert(key, value);
|
||||
}
|
||||
|
||||
|
||||
keyIndex = nextKeyIndex;
|
||||
} else {
|
||||
keyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int configIndex = argumentList.indexOf(CONFIG_FILE_OPTION);
|
||||
|
||||
|
||||
if (configIndex != -1) {
|
||||
// we have a config file - try and read it
|
||||
QString configFilePath = argumentList[configIndex + 1];
|
||||
QFile configFile(configFilePath);
|
||||
|
||||
|
||||
if (configFile.exists()) {
|
||||
qDebug() << "Reading JSON config file at" << configFilePath;
|
||||
configFile.open(QIODevice::ReadOnly);
|
||||
|
||||
|
||||
QJsonDocument configDocument = QJsonDocument::fromJson(configFile.readAll());
|
||||
QJsonObject rootObject = configDocument.object();
|
||||
|
||||
|
||||
// enumerate the keys of the configDocument object
|
||||
foreach(const QString& key, rootObject.keys()) {
|
||||
|
||||
|
||||
if (!mergedMap.contains(key)) {
|
||||
// no match in existing list, add it
|
||||
mergedMap.insert(key, QVariant(rootObject[key]));
|
||||
|
@ -93,6 +92,6 @@ QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringL
|
|||
qDebug() << "Could not find JSON config file at" << configFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mergedMap;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,9 @@ public:
|
|||
|
||||
void setShapes(QVector<ListShapeEntry>& shapes);
|
||||
|
||||
// TODO: either implement this or remove ListShape altogether
|
||||
bool findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const { return false; }
|
||||
|
||||
protected:
|
||||
void clear();
|
||||
void computeBoundingRadius();
|
||||
|
|
|
@ -30,7 +30,28 @@ PlaneShape::PlaneShape(const glm::vec4& coefficients) :
|
|||
}
|
||||
}
|
||||
|
||||
glm::vec3 PlaneShape::getNormal() const {
|
||||
return _rotation * UNROTATED_NORMAL;
|
||||
}
|
||||
|
||||
glm::vec4 PlaneShape::getCoefficients() const {
|
||||
glm::vec3 normal = _rotation * UNROTATED_NORMAL;
|
||||
return glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, _center));
|
||||
}
|
||||
|
||||
bool PlaneShape::findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const {
|
||||
glm::vec3 n = getNormal();
|
||||
float denominator = glm::dot(n, rayDirection);
|
||||
if (fabsf(denominator) < EPSILON) {
|
||||
// line is parallel to plane
|
||||
return glm::dot(_center - rayStart, n) < EPSILON;
|
||||
} else {
|
||||
float d = glm::dot(_center - rayStart, n) / denominator;
|
||||
if (d > 0.0f) {
|
||||
// ray points toward plane
|
||||
distance = d;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@ class PlaneShape : public Shape {
|
|||
public:
|
||||
PlaneShape(const glm::vec4& coefficients = glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
|
||||
|
||||
glm::vec3 getNormal() const;
|
||||
glm::vec4 getCoefficients() const;
|
||||
|
||||
bool findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const;
|
||||
};
|
||||
|
||||
#endif // hifi_PlaneShape_h
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
virtual void setCenter(const glm::vec3& center) { _center = center; }
|
||||
virtual glm::vec3 getCenter() const { return _center; }
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const = 0;
|
||||
|
||||
protected:
|
||||
// these ctors are protected (used by derived classes only)
|
||||
Shape(Type type) : _type(type), _owningEntity(NULL), _boundingRadius(0.f), _center(0.f), _rotation() {}
|
||||
|
|
|
@ -822,5 +822,24 @@ bool capsuleAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, fl
|
|||
return sphereAACube(nearestApproach, capsuleA->getRadius(), cubeCenter, cubeSide, collisions);
|
||||
}
|
||||
|
||||
bool findRayIntersectionWithShapes(const QVector<Shape*> shapes, const glm::vec3& rayStart, const glm::vec3& rayDirection, float& minDistance) {
|
||||
float hitDistance = FLT_MAX;
|
||||
int numShapes = shapes.size();
|
||||
for (int i = 0; i < numShapes; ++i) {
|
||||
Shape* shape = shapes.at(i);
|
||||
if (shape) {
|
||||
float distance;
|
||||
if (shape->findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
if (distance < hitDistance) {
|
||||
hitDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hitDistance < FLT_MAX) {
|
||||
minDistance = hitDistance;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ShapeCollider
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
namespace ShapeCollider {
|
||||
|
||||
/// \param shapeA pointer to first shape
|
||||
/// \param shapeB pointer to second shape
|
||||
/// \param shapeA pointer to first shape (cannot be NULL)
|
||||
/// \param shapeB pointer to second shape (cannot be NULL)
|
||||
/// \param collisions[out] collision details
|
||||
/// \return true if shapes collide
|
||||
bool collideShapes(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions);
|
||||
|
@ -38,123 +38,130 @@ namespace ShapeCollider {
|
|||
bool collideShapeWithShapes(const Shape* shapeA, const QVector<Shape*>& shapes, int startIndex, CollisionList& collisions);
|
||||
bool collideShapesWithShapes(const QVector<Shape*>& shapesA, const QVector<Shape*>& shapesB, CollisionList& collisions);
|
||||
|
||||
/// \param shapeA a pointer to a shape
|
||||
/// \param shapeA a pointer to a shape (cannot be NULL)
|
||||
/// \param cubeCenter center of cube
|
||||
/// \param cubeSide lenght of side of cube
|
||||
/// \param collisions[out] average collision details
|
||||
/// \return true if shapeA collides with axis aligned cube
|
||||
bool collideShapeWithAACube(const Shape* shapeA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to first shape
|
||||
/// \param sphereB pointer to second shape
|
||||
/// \param sphereA pointer to first shape (cannot be NULL)
|
||||
/// \param sphereB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool sphereSphere(const SphereShape* sphereA, const SphereShape* sphereB, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to first shape
|
||||
/// \param capsuleB pointer to second shape
|
||||
/// \param sphereA pointer to first shape (cannot be NULL)
|
||||
/// \param capsuleB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool sphereCapsule(const SphereShape* sphereA, const CapsuleShape* capsuleB, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to first shape
|
||||
/// \param planeB pointer to second shape
|
||||
/// \param sphereA pointer to first shape (cannot be NULL)
|
||||
/// \param planeB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool spherePlane(const SphereShape* sphereA, const PlaneShape* planeB, CollisionList& collisions);
|
||||
|
||||
/// \param capsuleA pointer to first shape
|
||||
/// \param sphereB pointer to second shape
|
||||
/// \param capsuleA pointer to first shape (cannot be NULL)
|
||||
/// \param sphereB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool capsuleSphere(const CapsuleShape* capsuleA, const SphereShape* sphereB, CollisionList& collisions);
|
||||
|
||||
/// \param capsuleA pointer to first shape
|
||||
/// \param capsuleB pointer to second shape
|
||||
/// \param capsuleA pointer to first shape (cannot be NULL)
|
||||
/// \param capsuleB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool capsuleCapsule(const CapsuleShape* capsuleA, const CapsuleShape* capsuleB, CollisionList& collisions);
|
||||
|
||||
/// \param capsuleA pointer to first shape
|
||||
/// \param planeB pointer to second shape
|
||||
/// \param capsuleA pointer to first shape (cannot be NULL)
|
||||
/// \param planeB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool capsulePlane(const CapsuleShape* capsuleA, const PlaneShape* planeB, CollisionList& collisions);
|
||||
|
||||
/// \param planeA pointer to first shape
|
||||
/// \param sphereB pointer to second shape
|
||||
/// \param planeA pointer to first shape (cannot be NULL)
|
||||
/// \param sphereB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool planeSphere(const PlaneShape* planeA, const SphereShape* sphereB, CollisionList& collisions);
|
||||
|
||||
/// \param planeA pointer to first shape
|
||||
/// \param capsuleB pointer to second shape
|
||||
/// \param planeA pointer to first shape (cannot be NULL)
|
||||
/// \param capsuleB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool planeCapsule(const PlaneShape* planeA, const CapsuleShape* capsuleB, CollisionList& collisions);
|
||||
|
||||
/// \param planeA pointer to first shape
|
||||
/// \param planeB pointer to second shape
|
||||
/// \param planeA pointer to first shape (cannot be NULL)
|
||||
/// \param planeB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool planePlane(const PlaneShape* planeA, const PlaneShape* planeB, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to first shape
|
||||
/// \param listB pointer to second shape
|
||||
/// \param sphereA pointer to first shape (cannot be NULL)
|
||||
/// \param listB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool sphereList(const SphereShape* sphereA, const ListShape* listB, CollisionList& collisions);
|
||||
|
||||
/// \param capuleA pointer to first shape
|
||||
/// \param listB pointer to second shape
|
||||
/// \param capuleA pointer to first shape (cannot be NULL)
|
||||
/// \param listB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool capsuleList(const CapsuleShape* capsuleA, const ListShape* listB, CollisionList& collisions);
|
||||
|
||||
/// \param planeA pointer to first shape
|
||||
/// \param listB pointer to second shape
|
||||
/// \param planeA pointer to first shape (cannot be NULL)
|
||||
/// \param listB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool planeList(const PlaneShape* planeA, const ListShape* listB, CollisionList& collisions);
|
||||
|
||||
/// \param listA pointer to first shape
|
||||
/// \param sphereB pointer to second shape
|
||||
/// \param listA pointer to first shape (cannot be NULL)
|
||||
/// \param sphereB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool listSphere(const ListShape* listA, const SphereShape* sphereB, CollisionList& collisions);
|
||||
|
||||
/// \param listA pointer to first shape
|
||||
/// \param capsuleB pointer to second shape
|
||||
/// \param listA pointer to first shape (cannot be NULL)
|
||||
/// \param capsuleB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool listCapsule(const ListShape* listA, const CapsuleShape* capsuleB, CollisionList& collisions);
|
||||
|
||||
/// \param listA pointer to first shape
|
||||
/// \param planeB pointer to second shape
|
||||
/// \param listA pointer to first shape (cannot be NULL)
|
||||
/// \param planeB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool listPlane(const ListShape* listA, const PlaneShape* planeB, CollisionList& collisions);
|
||||
|
||||
/// \param listA pointer to first shape
|
||||
/// \param capsuleB pointer to second shape
|
||||
/// \param listA pointer to first shape (cannot be NULL)
|
||||
/// \param capsuleB pointer to second shape (cannot be NULL)
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if shapes collide
|
||||
bool listList(const ListShape* listA, const ListShape* listB, CollisionList& collisions);
|
||||
|
||||
/// \param sphereA pointer to sphere
|
||||
/// \param sphereA pointer to sphere (cannot be NULL)
|
||||
/// \param cubeCenter center of cube
|
||||
/// \param cubeSide lenght of side of cube
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if sphereA collides with axis aligned cube
|
||||
bool sphereAACube(const SphereShape* sphereA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions);
|
||||
|
||||
/// \param capsuleA pointer to capsule
|
||||
/// \param capsuleA pointer to capsule (cannot be NULL)
|
||||
/// \param cubeCenter center of cube
|
||||
/// \param cubeSide lenght of side of cube
|
||||
/// \param[out] collisions where to append collision details
|
||||
/// \return true if capsuleA collides with axis aligned cube
|
||||
bool capsuleAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions);
|
||||
|
||||
/// \param shapes list of pointers to shapes (shape pointers may be NULL)
|
||||
/// \param startPoint beginning of ray
|
||||
/// \param direction direction of ray
|
||||
/// \param minDistance[out] shortest distance to intersection of ray with a shapes
|
||||
/// \return true if ray hits any shape in shapes
|
||||
bool findRayIntersectionWithShapes(const QVector<Shape*> shapes, const glm::vec3& startPoint, const glm::vec3& direction, float& minDistance);
|
||||
|
||||
} // namespace ShapeCollider
|
||||
|
||||
#endif // hifi_ShapeCollider_h
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QtCore/QDebug>
|
||||
#include <QDateTime>
|
||||
#include <QElapsedTimer>
|
||||
#include <QThread>
|
||||
|
||||
#include "OctalCode.h"
|
||||
#include "SharedUtil.h"
|
||||
|
@ -415,13 +416,17 @@ void printVoxelCode(unsigned char* voxelCode) {
|
|||
|
||||
#ifdef _WIN32
|
||||
void usleep(int waitTime) {
|
||||
__int64 time1 = 0, time2 = 0, sysFreq = 0;
|
||||
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&time1);
|
||||
QueryPerformanceFrequency((LARGE_INTEGER *)&sysFreq);
|
||||
do {
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)&time2);
|
||||
} while( (time2 - time1) < waitTime);
|
||||
const quint64 BUSY_LOOP_USECS = 2000;
|
||||
quint64 compTime = waitTime + usecTimestampNow();
|
||||
quint64 compTimeSleep = compTime - BUSY_LOOP_USECS;
|
||||
while (true) {
|
||||
if (usecTimestampNow() < compTimeSleep) {
|
||||
QThread::msleep(1);
|
||||
}
|
||||
if (usecTimestampNow() >= compTime) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
44
libraries/shared/src/SphereShape.cpp
Normal file
44
libraries/shared/src/SphereShape.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// SphereShape.cpp
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Created by Andrew Meadows on 2014.06.17
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <glm/gtx/norm.hpp>
|
||||
|
||||
#include "SphereShape.h"
|
||||
|
||||
bool SphereShape::findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const {
|
||||
float r2 = _boundingRadius * _boundingRadius;
|
||||
|
||||
// compute closest approach (CA)
|
||||
float a = glm::dot(_center - rayStart, rayDirection); // a = distance from ray-start to CA
|
||||
float b2 = glm::distance2(_center, rayStart + a * rayDirection); // b2 = squared distance from sphere-center to CA
|
||||
if (b2 > r2) {
|
||||
// ray does not hit sphere
|
||||
return false;
|
||||
}
|
||||
float c = sqrtf(r2 - b2); // c = distance from CA to sphere surface along rayDirection
|
||||
float d2 = glm::distance2(rayStart, _center); // d2 = squared distance from sphere-center to ray-start
|
||||
if (a < 0.0f) {
|
||||
// ray points away from sphere-center
|
||||
if (d2 > r2) {
|
||||
// ray starts outside sphere
|
||||
return false;
|
||||
}
|
||||
// ray starts inside sphere
|
||||
distance = c + a;
|
||||
} else if (d2 > r2) {
|
||||
// ray starts outside sphere
|
||||
distance = a - c;
|
||||
} else {
|
||||
// ray starts inside sphere
|
||||
distance = a + c;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -31,6 +31,8 @@ public:
|
|||
float getRadius() const { return _boundingRadius; }
|
||||
|
||||
void setRadius(float radius) { _boundingRadius = radius; }
|
||||
|
||||
bool findRayIntersection(const glm::vec3& rayStart, const glm::vec3& rayDirection, float& distance) const;
|
||||
};
|
||||
|
||||
#endif // hifi_SphereShape_h
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QScriptValueIterator>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include <MetavoxelMessages.h>
|
||||
|
@ -41,6 +43,8 @@ static int streamedBytesReceived = 0;
|
|||
static int sharedObjectsCreated = 0;
|
||||
static int sharedObjectsDestroyed = 0;
|
||||
static int objectMutationsPerformed = 0;
|
||||
static int scriptObjectsCreated = 0;
|
||||
static int scriptMutationsPerformed = 0;
|
||||
|
||||
static QByteArray createRandomBytes(int minimumSize, int maximumSize) {
|
||||
QByteArray bytes(randIntInRange(minimumSize, maximumSize), 0);
|
||||
|
@ -79,6 +83,48 @@ static TestSharedObjectA::TestFlags getRandomTestFlags() {
|
|||
return flags;
|
||||
}
|
||||
|
||||
static QScriptValue createRandomScriptValue(bool complex = false) {
|
||||
scriptObjectsCreated++;
|
||||
switch (randIntInRange(0, complex ? 5 : 3)) {
|
||||
case 0:
|
||||
return QScriptValue(QScriptValue::NullValue);
|
||||
|
||||
case 1:
|
||||
return QScriptValue(randomBoolean());
|
||||
|
||||
case 2:
|
||||
return QScriptValue(randFloat());
|
||||
|
||||
case 3:
|
||||
return QScriptValue(QString(createRandomBytes()));
|
||||
|
||||
case 4: {
|
||||
int length = randIntInRange(2, 6);
|
||||
QScriptValue value = ScriptCache::getInstance()->getEngine()->newArray(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
value.setProperty(i, createRandomScriptValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
default: {
|
||||
QScriptValue value = ScriptCache::getInstance()->getEngine()->newObject();
|
||||
if (randomBoolean()) {
|
||||
value.setProperty("foo", createRandomScriptValue());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
value.setProperty("bar", createRandomScriptValue());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
value.setProperty("baz", createRandomScriptValue());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
value.setProperty("bong", createRandomScriptValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static TestMessageC createRandomMessageC() {
|
||||
TestMessageC message;
|
||||
message.foo = randomBoolean();
|
||||
|
@ -86,6 +132,7 @@ static TestMessageC createRandomMessageC() {
|
|||
message.baz = randFloat();
|
||||
message.bong.foo = createRandomBytes();
|
||||
message.bong.baz = getRandomTestEnum();
|
||||
message.bizzle = createRandomScriptValue(true);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -167,6 +214,35 @@ static bool testSerialization(Bitstream::MetadataType metadataType) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// go back to the beginning and read everything as generics
|
||||
inStream.device()->seek(0);
|
||||
Bitstream genericIn(inStream, metadataType, Bitstream::ALL_GENERICS);
|
||||
genericIn >> testObjectReadA;
|
||||
genericIn >> testObjectReadB;
|
||||
genericIn >> messageRead;
|
||||
genericIn >> endRead;
|
||||
|
||||
// reassign the ids
|
||||
testObjectReadA->setID(testObjectWrittenA->getID());
|
||||
testObjectReadA->setOriginID(testObjectWrittenA->getOriginID());
|
||||
testObjectReadB->setID(testObjectWrittenB->getID());
|
||||
testObjectReadB->setOriginID(testObjectWrittenB->getOriginID());
|
||||
|
||||
// write it back out and compare
|
||||
QByteArray compareArray;
|
||||
QDataStream compareOutStream(&compareArray, QIODevice::WriteOnly);
|
||||
Bitstream compareOut(compareOutStream, metadataType);
|
||||
compareOut << testObjectReadA;
|
||||
compareOut << testObjectReadB;
|
||||
compareOut << messageRead;
|
||||
compareOut << endRead;
|
||||
compareOut.flush();
|
||||
|
||||
if (array != compareArray) {
|
||||
qDebug() << "Mismatch between written/generic written streams.";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -201,6 +277,7 @@ bool MetavoxelTests::run() {
|
|||
datagramsReceived << "with" << bytesReceived << "bytes";
|
||||
qDebug() << "Created" << sharedObjectsCreated << "shared objects, destroyed" << sharedObjectsDestroyed;
|
||||
qDebug() << "Performed" << objectMutationsPerformed << "object mutations";
|
||||
qDebug() << "Created" << scriptObjectsCreated << "script objects, mutated" << scriptMutationsPerformed;
|
||||
qDebug();
|
||||
|
||||
qDebug() << "Running serialization tests...";
|
||||
|
@ -284,7 +361,7 @@ static QVariant createRandomMessage() {
|
|||
}
|
||||
|
||||
static SharedObjectPointer mutate(const SharedObjectPointer& state) {
|
||||
switch(randIntInRange(0, 3)) {
|
||||
switch (randIntInRange(0, 4)) {
|
||||
case 0: {
|
||||
SharedObjectPointer newState = state->clone(true);
|
||||
static_cast<TestSharedObjectA*>(newState.data())->setFoo(randFloat());
|
||||
|
@ -303,6 +380,38 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
|
|||
objectMutationsPerformed++;
|
||||
return newState;
|
||||
}
|
||||
case 3: {
|
||||
SharedObjectPointer newState = state->clone(true);
|
||||
QScriptValue oldValue = static_cast<TestSharedObjectA*>(newState.data())->getBizzle();
|
||||
QScriptValue newValue = ScriptCache::getInstance()->getEngine()->newObject();
|
||||
for (QScriptValueIterator it(oldValue); it.hasNext(); ) {
|
||||
it.next();
|
||||
newValue.setProperty(it.scriptName(), it.value());
|
||||
}
|
||||
switch (randIntInRange(0, 2)) {
|
||||
case 0: {
|
||||
QScriptValue oldArray = oldValue.property("foo");
|
||||
int oldLength = oldArray.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
||||
QScriptValue newArray = ScriptCache::getInstance()->getEngine()->newArray(oldLength);
|
||||
for (int i = 0; i < oldLength; i++) {
|
||||
newArray.setProperty(i, oldArray.property(i));
|
||||
}
|
||||
newArray.setProperty(randIntInRange(0, oldLength - 1), createRandomScriptValue(true));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
newValue.setProperty("bar", QScriptValue(randFloat()));
|
||||
break;
|
||||
|
||||
default:
|
||||
newValue.setProperty("baz", createRandomScriptValue(true));
|
||||
break;
|
||||
}
|
||||
static_cast<TestSharedObjectA*>(newState.data())->setBizzle(newValue);
|
||||
scriptMutationsPerformed++;
|
||||
objectMutationsPerformed++;
|
||||
return newState;
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -503,7 +612,10 @@ TestSharedObjectA::TestSharedObjectA(float foo, TestEnum baz, TestFlags bong) :
|
|||
_foo(foo),
|
||||
_baz(baz),
|
||||
_bong(bong) {
|
||||
sharedObjectsCreated++;
|
||||
sharedObjectsCreated++;
|
||||
|
||||
_bizzle = ScriptCache::getInstance()->getEngine()->newObject();
|
||||
_bizzle.setProperty("foo", ScriptCache::getInstance()->getEngine()->newArray(4));
|
||||
}
|
||||
|
||||
TestSharedObjectA::~TestSharedObjectA() {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QVariantList>
|
||||
|
||||
#include <DatagramSequencer.h>
|
||||
#include <ScriptCache.h>
|
||||
|
||||
class SequencedTestMessage;
|
||||
|
||||
|
@ -96,7 +97,8 @@ class TestSharedObjectA : public SharedObject {
|
|||
Q_PROPERTY(float foo READ getFoo WRITE setFoo NOTIFY fooChanged)
|
||||
Q_PROPERTY(TestEnum baz READ getBaz WRITE setBaz)
|
||||
Q_PROPERTY(TestFlags bong READ getBong WRITE setBong)
|
||||
|
||||
Q_PROPERTY(QScriptValue bizzle READ getBizzle WRITE setBizzle)
|
||||
|
||||
public:
|
||||
|
||||
enum TestEnum { FIRST_TEST_ENUM, SECOND_TEST_ENUM, THIRD_TEST_ENUM };
|
||||
|
@ -116,6 +118,9 @@ public:
|
|||
void setBong(TestFlags bong) { _bong = bong; }
|
||||
TestFlags getBong() const { return _bong; }
|
||||
|
||||
void setBizzle(const QScriptValue& bizzle) { _bizzle = bizzle; }
|
||||
const QScriptValue& getBizzle() const { return _bizzle; }
|
||||
|
||||
signals:
|
||||
|
||||
void fooChanged(float foo);
|
||||
|
@ -125,6 +130,7 @@ private:
|
|||
float _foo;
|
||||
TestEnum _baz;
|
||||
TestFlags _bong;
|
||||
QScriptValue _bizzle;
|
||||
};
|
||||
|
||||
DECLARE_ENUM_METATYPE(TestSharedObjectA, TestEnum)
|
||||
|
@ -204,6 +210,7 @@ class TestMessageC : STREAM public TestMessageA {
|
|||
public:
|
||||
|
||||
STREAM TestMessageB bong;
|
||||
STREAM QScriptValue bizzle;
|
||||
};
|
||||
|
||||
DECLARE_STREAMABLE_METATYPE(TestMessageC)
|
||||
|
|
100
tests/octree/src/AABoxCubeTests.cpp
Normal file
100
tests/octree/src/AABoxCubeTests.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// AABoxCubeTests.h
|
||||
// tests/octree/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 06/04/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <AACube.h>
|
||||
|
||||
#include "AABoxCubeTests.h"
|
||||
|
||||
void AABoxCubeTests::AABoxCubeTests() {
|
||||
qDebug() << "******************************************************************************************";
|
||||
qDebug() << "AABoxCubeTests::AABoxCubeTests()";
|
||||
|
||||
{
|
||||
qDebug() << "Test 1: AABox.findRayIntersection() inside out MIN_X_FACE";
|
||||
|
||||
glm::vec3 corner(0.0f, 0.0f, 0.0f);
|
||||
float size = 1.0f;
|
||||
|
||||
AABox box(corner, size);
|
||||
glm::vec3 origin(0.5f, 0.5f, 0.5f);
|
||||
glm::vec3 direction(-1.0f, 0.0f, 0.0f);
|
||||
float distance;
|
||||
BoxFace face;
|
||||
|
||||
bool intersects = box.findRayIntersection(origin, direction, distance, face);
|
||||
|
||||
if (intersects && distance == 0.5f && face == MIN_X_FACE) {
|
||||
qDebug() << "Test 1: PASSED";
|
||||
} else {
|
||||
qDebug() << "intersects=" << intersects << "expected=" << true;
|
||||
qDebug() << "distance=" << distance << "expected=" << 0.5f;
|
||||
qDebug() << "face=" << face << "expected=" << MIN_X_FACE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qDebug() << "Test 2: AABox.findRayIntersection() inside out MAX_X_FACE";
|
||||
|
||||
glm::vec3 corner(0.0f, 0.0f, 0.0f);
|
||||
float size = 1.0f;
|
||||
|
||||
AABox box(corner, size);
|
||||
glm::vec3 origin(0.5f, 0.5f, 0.5f);
|
||||
glm::vec3 direction(1.0f, 0.0f, 0.0f);
|
||||
float distance;
|
||||
BoxFace face;
|
||||
|
||||
bool intersects = box.findRayIntersection(origin, direction, distance, face);
|
||||
|
||||
if (intersects && distance == 0.5f && face == MAX_X_FACE) {
|
||||
qDebug() << "Test 2: PASSED";
|
||||
} else {
|
||||
qDebug() << "intersects=" << intersects << "expected=" << true;
|
||||
qDebug() << "distance=" << distance << "expected=" << 0.5f;
|
||||
qDebug() << "face=" << face << "expected=" << MAX_X_FACE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qDebug() << "Test 3: AABox.findRayIntersection() outside in";
|
||||
|
||||
glm::vec3 corner(0.5f, 0.0f, 0.0f);
|
||||
float size = 0.5f;
|
||||
|
||||
AABox box(corner, size);
|
||||
glm::vec3 origin(0.25f, 0.25f, 0.25f);
|
||||
glm::vec3 direction(1.0f, 0.0f, 0.0f);
|
||||
float distance;
|
||||
BoxFace face;
|
||||
|
||||
bool intersects = box.findRayIntersection(origin, direction, distance, face);
|
||||
|
||||
if (intersects && distance == 0.25f && face == MIN_X_FACE) {
|
||||
qDebug() << "Test 3: PASSED";
|
||||
} else {
|
||||
qDebug() << "intersects=" << intersects << "expected=" << true;
|
||||
qDebug() << "distance=" << distance << "expected=" << 0.5f;
|
||||
qDebug() << "face=" << face << "expected=" << MIN_X_FACE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "******************************************************************************************";
|
||||
}
|
||||
|
||||
void AABoxCubeTests::runAllTests() {
|
||||
AABoxCubeTests();
|
||||
}
|
20
tests/octree/src/AABoxCubeTests.h
Normal file
20
tests/octree/src/AABoxCubeTests.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// AABoxCubeTests.h
|
||||
// tests/octree/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 06/04/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_AABoxCubeTests_h
|
||||
#define hifi_AABoxCubeTests_h
|
||||
|
||||
namespace AABoxCubeTests {
|
||||
void AABoxCubeTests();
|
||||
void runAllTests();
|
||||
}
|
||||
|
||||
#endif // hifi_AABoxCubeTests_h
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// OctreeTests.h
|
||||
// tests/physics/src
|
||||
// tests/octree/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 06/04/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// OctreeTests.h
|
||||
// tests/physics/src
|
||||
// tests/octree/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 06/04/2014.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
//
|
||||
|
||||
#include "OctreeTests.h"
|
||||
#include "AABoxCubeTests.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
OctreeTests::runAllTests();
|
||||
AABoxCubeTests::runAllTests();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
//#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
@ -897,6 +898,405 @@ void ShapeColliderTests::sphereMissesAACube() {
|
|||
}
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayHitsSphere() {
|
||||
float startDistance = 3.0f;
|
||||
glm::vec3 rayStart(-startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection(1.0f, 0.0f, 0.0f);
|
||||
|
||||
float radius = 1.0f;
|
||||
glm::vec3 center(0.0f);
|
||||
|
||||
SphereShape sphere(radius, center);
|
||||
|
||||
// very simple ray along xAxis
|
||||
{
|
||||
float distance = FLT_MAX;
|
||||
if (!sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl;
|
||||
}
|
||||
|
||||
float expectedDistance = startDistance - radius;
|
||||
float relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// ray along a diagonal axis
|
||||
{
|
||||
rayStart = glm::vec3(startDistance, startDistance, 0.0f);
|
||||
rayDirection = - glm::normalize(rayStart);
|
||||
|
||||
float distance = FLT_MAX;
|
||||
if (!sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl;
|
||||
}
|
||||
|
||||
float expectedDistance = SQUARE_ROOT_OF_2 * startDistance - radius;
|
||||
float relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// rotated and displaced ray and sphere
|
||||
{
|
||||
startDistance = 7.41f;
|
||||
radius = 3.917f;
|
||||
|
||||
glm::vec3 axis = glm::normalize(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
glm::quat rotation = glm::angleAxis(0.987654321f, axis);
|
||||
glm::vec3 translation(35.7f, 2.46f, -1.97f);
|
||||
|
||||
glm::vec3 unrotatedRayDirection(-1.0f, 0.0f, 0.0f);
|
||||
glm::vec3 untransformedRayStart(startDistance, 0.0f, 0.0f);
|
||||
|
||||
rayStart = rotation * (untransformedRayStart + translation);
|
||||
rayDirection = rotation * unrotatedRayDirection;
|
||||
|
||||
sphere.setRadius(radius);
|
||||
sphere.setCenter(rotation * translation);
|
||||
|
||||
float distance = FLT_MAX;
|
||||
if (!sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl;
|
||||
}
|
||||
|
||||
float expectedDistance = startDistance - radius;
|
||||
float relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayBarelyHitsSphere() {
|
||||
float radius = 1.0f;
|
||||
glm::vec3 center(0.0f);
|
||||
float delta = 2.0f * EPSILON;
|
||||
|
||||
float startDistance = 3.0f;
|
||||
glm::vec3 rayStart(-startDistance, radius - delta, 0.0f);
|
||||
glm::vec3 rayDirection(1.0f, 0.0f, 0.0f);
|
||||
|
||||
SphereShape sphere(radius, center);
|
||||
|
||||
// very simple ray along xAxis
|
||||
float distance = FLT_MAX;
|
||||
if (!sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely hit sphere" << std::endl;
|
||||
}
|
||||
|
||||
// translate and rotate the whole system...
|
||||
glm::vec3 axis = glm::normalize(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
glm::quat rotation = glm::angleAxis(0.987654321f, axis);
|
||||
glm::vec3 translation(35.7f, 2.46f, -1.97f);
|
||||
|
||||
rayStart = rotation * (rayStart + translation);
|
||||
rayDirection = rotation * rayDirection;
|
||||
sphere.setCenter(rotation * translation);
|
||||
|
||||
// ...and test again
|
||||
distance = FLT_MAX;
|
||||
if (!sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely hit sphere" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShapeColliderTests::rayBarelyMissesSphere() {
|
||||
// same as the barely-hits case, but this time we move the ray away from sphere
|
||||
float radius = 1.0f;
|
||||
glm::vec3 center(0.0f);
|
||||
float delta = 2.0f * EPSILON;
|
||||
|
||||
float startDistance = 3.0f;
|
||||
glm::vec3 rayStart(-startDistance, radius + delta, 0.0f);
|
||||
glm::vec3 rayDirection(1.0f, 0.0f, 0.0f);
|
||||
|
||||
SphereShape sphere(radius, center);
|
||||
|
||||
// very simple ray along xAxis
|
||||
float distance = FLT_MAX;
|
||||
if (sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely miss sphere" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
|
||||
// translate and rotate the whole system...
|
||||
glm::vec3 axis = glm::normalize(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
glm::quat rotation = glm::angleAxis(0.987654321f, axis);
|
||||
glm::vec3 translation(35.7f, 2.46f, -1.97f);
|
||||
|
||||
rayStart = rotation * (rayStart + translation);
|
||||
rayDirection = rotation * rayDirection;
|
||||
sphere.setCenter(rotation * translation);
|
||||
|
||||
// ...and test again
|
||||
distance = FLT_MAX;
|
||||
if (sphere.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely miss sphere" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayHitsCapsule() {
|
||||
float startDistance = 3.0f;
|
||||
float radius = 1.0f;
|
||||
float halfHeight = 2.0f;
|
||||
glm::vec3 center(0.0f);
|
||||
CapsuleShape capsule(radius, halfHeight);
|
||||
|
||||
{ // simple test along xAxis
|
||||
// toward capsule center
|
||||
glm::vec3 rayStart(startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection(-1.0f, 0.0f, 0.0f);
|
||||
float distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
float expectedDistance = startDistance - radius;
|
||||
float relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
// toward top of cylindrical wall
|
||||
rayStart.y = halfHeight;
|
||||
distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
// toward top cap
|
||||
float delta = 2.0f * EPSILON;
|
||||
rayStart.y = halfHeight + delta;
|
||||
distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
const float EDGE_CASE_SLOP_FACTOR = 20.0f;
|
||||
|
||||
// toward tip of top cap
|
||||
rayStart.y = halfHeight + radius - delta;
|
||||
distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine
|
||||
relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
// for edge cases we allow a LOT of error
|
||||
if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
// toward tip of bottom cap
|
||||
rayStart.y = - halfHeight - radius + delta;
|
||||
distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine
|
||||
relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
// for edge cases we allow a LOT of error
|
||||
if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
// toward edge of capsule cylindrical face
|
||||
rayStart.y = 0.0f;
|
||||
rayStart.z = radius - delta;
|
||||
distance = FLT_MAX;
|
||||
if (!capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl;
|
||||
}
|
||||
expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine
|
||||
relativeError = fabsf(distance - expectedDistance) / startDistance;
|
||||
// for edge cases we allow a LOT of error
|
||||
if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
}
|
||||
// TODO: test at steep angles near cylinder/cap junction
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayMissesCapsule() {
|
||||
// same as edge case hit tests, but shifted in the opposite direction
|
||||
float startDistance = 3.0f;
|
||||
float radius = 1.0f;
|
||||
float halfHeight = 2.0f;
|
||||
glm::vec3 center(0.0f);
|
||||
CapsuleShape capsule(radius, halfHeight);
|
||||
|
||||
{ // simple test along xAxis
|
||||
// toward capsule center
|
||||
glm::vec3 rayStart(startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection(-1.0f, 0.0f, 0.0f);
|
||||
float delta = 2.0f * EPSILON;
|
||||
|
||||
// over top cap
|
||||
rayStart.y = halfHeight + radius + delta;
|
||||
float distance = FLT_MAX;
|
||||
if (capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
|
||||
// below bottom cap
|
||||
rayStart.y = - halfHeight - radius - delta;
|
||||
distance = FLT_MAX;
|
||||
if (capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
|
||||
// past edge of capsule cylindrical face
|
||||
rayStart.y = 0.0f;
|
||||
rayStart.z = radius + delta;
|
||||
distance = FLT_MAX;
|
||||
if (capsule.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
}
|
||||
// TODO: test at steep angles near edge
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayHitsPlane() {
|
||||
// make a simple plane
|
||||
float planeDistanceFromOrigin = 3.579;
|
||||
glm::vec3 planePosition(0.0f, planeDistanceFromOrigin, 0.0f);
|
||||
PlaneShape plane;
|
||||
plane.setCenter(planePosition);
|
||||
|
||||
// make a simple ray
|
||||
float startDistance = 1.234f;
|
||||
glm::vec3 rayStart(-startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection = glm::normalize(glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
|
||||
float distance = FLT_MAX;
|
||||
if (!plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit plane" << std::endl;
|
||||
}
|
||||
|
||||
float expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin;
|
||||
float relativeError = fabsf(distance - expectedDistance) / planeDistanceFromOrigin;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
|
||||
// rotate the whole system and try again
|
||||
float angle = 37.8f;
|
||||
glm::vec3 axis = glm::normalize( glm::vec3(-7.0f, 2.8f, 9.3f) );
|
||||
glm::quat rotation = glm::angleAxis(angle, axis);
|
||||
|
||||
plane.setCenter(rotation * planePosition);
|
||||
plane.setRotation(rotation);
|
||||
rayStart = rotation * rayStart;
|
||||
rayDirection = rotation * rayDirection;
|
||||
|
||||
distance = FLT_MAX;
|
||||
if (!plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit plane" << std::endl;
|
||||
}
|
||||
|
||||
expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin;
|
||||
relativeError = fabsf(distance - expectedDistance) / planeDistanceFromOrigin;
|
||||
if (relativeError > EPSILON) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " << relativeError << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeColliderTests::rayMissesPlane() {
|
||||
// make a simple plane
|
||||
float planeDistanceFromOrigin = 3.579;
|
||||
glm::vec3 planePosition(0.0f, planeDistanceFromOrigin, 0.0f);
|
||||
PlaneShape plane;
|
||||
plane.setCenter(planePosition);
|
||||
|
||||
{ // parallel rays should miss
|
||||
float startDistance = 1.234f;
|
||||
glm::vec3 rayStart(-startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection = glm::normalize(glm::vec3(-1.0f, 0.0f, -1.0f));
|
||||
|
||||
float distance = FLT_MAX;
|
||||
if (plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
|
||||
// rotate the whole system and try again
|
||||
float angle = 37.8f;
|
||||
glm::vec3 axis = glm::normalize( glm::vec3(-7.0f, 2.8f, 9.3f) );
|
||||
glm::quat rotation = glm::angleAxis(angle, axis);
|
||||
|
||||
plane.setCenter(rotation * planePosition);
|
||||
plane.setRotation(rotation);
|
||||
rayStart = rotation * rayStart;
|
||||
rayDirection = rotation * rayDirection;
|
||||
|
||||
distance = FLT_MAX;
|
||||
if (plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
{ // make a simple ray that points away from plane
|
||||
float startDistance = 1.234f;
|
||||
glm::vec3 rayStart(-startDistance, 0.0f, 0.0f);
|
||||
glm::vec3 rayDirection = glm::normalize(glm::vec3(-1.0f, -1.0f, -1.0f));
|
||||
|
||||
float distance = FLT_MAX;
|
||||
if (plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
|
||||
// rotate the whole system and try again
|
||||
float angle = 37.8f;
|
||||
glm::vec3 axis = glm::normalize( glm::vec3(-7.0f, 2.8f, 9.3f) );
|
||||
glm::quat rotation = glm::angleAxis(angle, axis);
|
||||
|
||||
plane.setCenter(rotation * planePosition);
|
||||
plane.setRotation(rotation);
|
||||
rayStart = rotation * rayStart;
|
||||
rayDirection = rotation * rayDirection;
|
||||
|
||||
distance = FLT_MAX;
|
||||
if (plane.findRayIntersection(rayStart, rayDirection, distance)) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl;
|
||||
}
|
||||
if (distance != FLT_MAX) {
|
||||
std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeColliderTests::runAllTests() {
|
||||
sphereMissesSphere();
|
||||
|
@ -911,4 +1311,12 @@ void ShapeColliderTests::runAllTests() {
|
|||
sphereTouchesAACubeFaces();
|
||||
sphereTouchesAACubeEdges();
|
||||
sphereMissesAACube();
|
||||
|
||||
rayHitsSphere();
|
||||
rayBarelyHitsSphere();
|
||||
rayBarelyMissesSphere();
|
||||
rayHitsCapsule();
|
||||
rayMissesCapsule();
|
||||
rayHitsPlane();
|
||||
rayMissesPlane();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,14 @@ namespace ShapeColliderTests {
|
|||
void sphereTouchesAACubeEdges();
|
||||
void sphereMissesAACube();
|
||||
|
||||
void rayHitsSphere();
|
||||
void rayBarelyHitsSphere();
|
||||
void rayBarelyMissesSphere();
|
||||
void rayHitsCapsule();
|
||||
void rayMissesCapsule();
|
||||
void rayHitsPlane();
|
||||
void rayMissesPlane();
|
||||
|
||||
void runAllTests();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue