mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 09:33:45 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into punk
This commit is contained in:
commit
84d244ec52
287 changed files with 15744 additions and 9346 deletions
|
@ -17,4 +17,5 @@ if (UNIX)
|
|||
target_link_libraries(${TARGET_NAME} ${CMAKE_DL_LIBS})
|
||||
endif (UNIX)
|
||||
|
||||
include_application_version()
|
||||
copy_dlls_beside_windows_executable()
|
|
@ -129,6 +129,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
|
|||
packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
|
||||
packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");
|
||||
}
|
||||
|
||||
void AssignmentClient::stopAssignmentClient() {
|
||||
qDebug() << "Forced stop of assignment-client.";
|
||||
|
||||
|
@ -172,7 +173,6 @@ void AssignmentClient::aboutToQuit() {
|
|||
qInstallMessageHandler(0);
|
||||
}
|
||||
|
||||
|
||||
void AssignmentClient::setUpStatusToMonitor() {
|
||||
// send a stats packet every 1 seconds
|
||||
connect(&_statsTimerACM, &QTimer::timeout, this, &AssignmentClient::sendStatusPacketToACM);
|
||||
|
@ -217,7 +217,6 @@ void AssignmentClient::sendAssignmentRequest() {
|
|||
qDebug() << "Failed to read local assignment server port from shared memory"
|
||||
<< "- will send assignment request to previous assignment server socket.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nodeList->sendAssignment(_requestAssignment);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QCommandLineParser>
|
||||
#include <QThread>
|
||||
|
||||
#include <ApplicationVersion.h>
|
||||
#include <LogHandler.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <HifiConfigVariantMap.h>
|
||||
|
@ -40,6 +41,7 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
|||
setOrganizationName("High Fidelity");
|
||||
setOrganizationDomain("highfidelity.io");
|
||||
setApplicationName("assignment-client");
|
||||
setApplicationName(BUILD_VERSION);
|
||||
|
||||
// use the verbose message handler in Logging
|
||||
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||
|
@ -93,10 +95,8 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
|||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
const QVariantMap argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments());
|
||||
|
||||
|
||||
unsigned int numForks = 0;
|
||||
if (parser.isSet(numChildsOption)) {
|
||||
numForks = parser.value(numChildsOption).toInt();
|
||||
|
@ -139,7 +139,6 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
|||
assignmentPool = parser.value(poolOption);
|
||||
}
|
||||
|
||||
|
||||
QUuid walletUUID;
|
||||
if (argumentVariantMap.contains(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION)) {
|
||||
walletUUID = argumentVariantMap.value(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION).toString();
|
||||
|
|
|
@ -203,7 +203,7 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
|
||||
void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer<NLPacket> packet) {
|
||||
// read out the sender ID
|
||||
QUuid senderID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid senderID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ int AudioMixerClientData::parseData(NLPacket& packet) {
|
|||
|
||||
// grab the stream identifier for this injected audio
|
||||
packet.seek(sizeof(quint16));
|
||||
QUuid streamIdentifier = QUuid::fromRfc4122(packet.read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid streamIdentifier = QUuid::fromRfc4122(packet.readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
bool isStereo;
|
||||
packet.readPrimitive(&isStereo);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet) {
|
||||
// compute the offset to the data payload
|
||||
return _avatar.parseDataFromBuffer(packet.read(packet.bytesLeftToRead()));
|
||||
return _avatar.parseDataFromBuffer(packet.readWithoutCopy(packet.bytesLeftToRead()));
|
||||
}
|
||||
|
||||
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
|
||||
|
|
|
@ -971,12 +971,7 @@ void OctreeServer::readConfiguration() {
|
|||
strcpy(_persistFilename, qPrintable(persistFilename));
|
||||
qDebug("persistFilename=%s", _persistFilename);
|
||||
|
||||
QString persistAsFileType;
|
||||
if (!readOptionString(QString("persistAsFileType"), settingsSectionObject, persistAsFileType)) {
|
||||
persistAsFileType = "svo";
|
||||
}
|
||||
_persistAsFileType = persistAsFileType;
|
||||
qDebug() << "persistAsFileType=" << _persistAsFileType;
|
||||
_persistAsFileType = "json.gz";
|
||||
|
||||
_persistInterval = OctreePersistThread::DEFAULT_PERSIST_INTERVAL;
|
||||
readOptionInt(QString("persistInterval"), settingsSectionObject, _persistInterval);
|
||||
|
|
4
cmake/externals/LibOVR/CMakeLists.txt
vendored
4
cmake/externals/LibOVR/CMakeLists.txt
vendored
|
@ -9,8 +9,8 @@ if (WIN32)
|
|||
|
||||
ExternalProject_Add(
|
||||
${EXTERNAL_NAME}
|
||||
URL http://static.oculus.com/sdk-downloads/0.6.0.0/1431634088/ovr_sdk_win_0.6.0.0.zip
|
||||
URL_MD5 a3dfdab037a854fdcf7e6033fa8d7028
|
||||
URL http://static.oculus.com/sdk-downloads/0.6.0.1/Public/1435190862/ovr_sdk_win_0.6.0.1.zip
|
||||
URL_MD5 4b3ef825f9a1d6d3035c9f6820687da9
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
|
|
5
cmake/externals/openvr/CMakeLists.txt
vendored
5
cmake/externals/openvr/CMakeLists.txt
vendored
|
@ -26,16 +26,19 @@ if (WIN32)
|
|||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/win32/openvr_api.lib CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/win32)
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/osx32/libopenvr_api.dylib CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/osx32)
|
||||
|
||||
elseif(NOT ANDROID)
|
||||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/linux32/libopenvr_api.so CACHE TYPE INTERNAL)
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/linux64/libopenvr_api.so CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/linux64)
|
||||
|
||||
endif()
|
||||
|
||||
|
|
60
cmake/externals/sixense/CMakeLists.txt
vendored
Normal file
60
cmake/externals/sixense/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
include(ExternalProject)
|
||||
include(SelectLibraryConfigurations)
|
||||
|
||||
set(EXTERNAL_NAME Sixense)
|
||||
|
||||
string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
|
||||
|
||||
ExternalProject_Add(
|
||||
${EXTERNAL_NAME}
|
||||
URL ./SixenseSDK_062612.zip
|
||||
URL_MD5 10cc8dc470d2ac1244a88cf04bc549cc
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
LOG_DOWNLOAD 1
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
find_library(SIXENSE_LIBRARY_RELEASE lib/osx_x64/release_dll/libsixense_x64.dylib HINTS ${SIXENSE_SEARCH_DIRS})
|
||||
find_library(SIXENSE_LIBRARY_DEBUG lib/osx_x64/debug_dll/libsixensed_x64.dylib HINTS ${SIXENSE_SEARCH_DIRS})
|
||||
elseif (UNIX)
|
||||
find_library(SIXENSE_LIBRARY_RELEASE lib/linux_x64/release/libsixense_x64.so HINTS ${SIXENSE_SEARCH_DIRS})
|
||||
# find_library(SIXENSE_LIBRARY_DEBUG lib/linux_x64/debug/libsixensed_x64.so HINTS ${SIXENSE_SEARCH_DIRS})
|
||||
elseif (WIN32)
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR)
|
||||
|
||||
set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE INTERNAL)
|
||||
|
||||
if (WIN32)
|
||||
|
||||
if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
|
||||
set(ARCH_DIR "x64")
|
||||
set(ARCH_SUFFIX "_x64")
|
||||
else()
|
||||
set(ARCH_DIR "Win32")
|
||||
set(ARCH_SUFFIX "")
|
||||
endif()
|
||||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES "${SOURCE_DIR}/lib/${ARCH_DIR}/release_dll/sixense${ARCH_SUFFIX}.lib" CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/win32)
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/osx32/libopenvr_api.dylib CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/osx32)
|
||||
|
||||
elseif(NOT ANDROID)
|
||||
|
||||
# FIXME need to account for different architectures
|
||||
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/linux32/libopenvr_api.so CACHE TYPE INTERNAL)
|
||||
add_paths_to_fixup_libs(${SOURCE_DIR}/bin/linux32)
|
||||
|
||||
endif()
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
//
|
||||
// InterfaceVersion.h
|
||||
// interface/src
|
||||
// ApplicationVersion.h.in
|
||||
// cmake/macros
|
||||
//
|
||||
// Created by Leonardo Murillo on 12/16/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Declaration of version and build data
|
||||
// Created by Leonardo Murillo on 8/13/15.
|
||||
// Copyright 2015 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
|
16
cmake/macros/GroupSources.cmake
Normal file
16
cmake/macros/GroupSources.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# Distributed under the Apache License, Version 2.0.
|
||||
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
#
|
||||
|
||||
macro(GroupSources curdir)
|
||||
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
|
||||
foreach(child ${children})
|
||||
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
|
||||
GroupSources(${curdir}/${child})
|
||||
else()
|
||||
string(REPLACE "/" "\\" groupname ${curdir})
|
||||
source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
22
cmake/macros/IncludeApplicationVersion.cmake
Normal file
22
cmake/macros/IncludeApplicationVersion.cmake
Normal file
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# IncludeApplicationVersion.cmake
|
||||
# cmake/macros
|
||||
#
|
||||
# Created by Leonardo Murillo on 07/14/2015.
|
||||
# Copyright 2015 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
|
||||
#
|
||||
|
||||
macro(INCLUDE_APPLICATION_VERSION)
|
||||
if (DEFINED ENV{JOB_ID})
|
||||
set (BUILD_SEQ $ENV{JOB_ID})
|
||||
elseif (DEFINED ENV{ghprbPullId})
|
||||
set (BUILD_SEQ "PR: $ENV{ghprbPullId} - Commit: $ENV{ghprbActualCommit}")
|
||||
else ()
|
||||
set(BUILD_SEQ "dev")
|
||||
endif ()
|
||||
configure_file("${MACRO_DIR}/ApplicationVersion.h.in" "${PROJECT_BINARY_DIR}/includes/ApplicationVersion.h")
|
||||
include_directories("${PROJECT_BINARY_DIR}/includes")
|
||||
endmacro(INCLUDE_APPLICATION_VERSION)
|
66
cmake/modules/FindiViewHMD.cmake
Normal file
66
cmake/modules/FindiViewHMD.cmake
Normal file
|
@ -0,0 +1,66 @@
|
|||
#
|
||||
# FindiViewHMD.cmake
|
||||
#
|
||||
# Try to find the SMI iViewHMD eye tracker library
|
||||
#
|
||||
# You must provide a IVIEWHMD_ROOT_DIR which contains 3rdParty, include, and libs directories
|
||||
#
|
||||
# Once done this will define
|
||||
#
|
||||
# IVIEWHMD_FOUND - system found iViewHMD
|
||||
# IVIEWHMD_INCLUDE_DIRS - the iViewHMD include directory
|
||||
# IVIEWHMD_LIBRARIES - link this to use iViewHMD
|
||||
#
|
||||
# Created on 27 Jul 2015 by David Rowe
|
||||
# Copyright 2015 High Fidelity, Inc.
|
||||
#
|
||||
|
||||
if (WIN32)
|
||||
|
||||
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
|
||||
hifi_library_search_hints("iViewHMD")
|
||||
|
||||
find_path(IVIEWHMD_INCLUDE_DIRS iViewHMDAPI.h PATH_SUFFIXES include HINTS ${IVIEWHMD_SEARCH_DIRS})
|
||||
find_library(IVIEWHMD_LIBRARIES NAMES iViewHMDAPI PATH_SUFFIXES libs HINTS ${IVIEWHMD_SEARCH_DIRS})
|
||||
find_path(IVIEWHMD_API_DLL_PATH iViewHMDAPI.dll PATH_SUFFIXES libs HINTS ${IVIEWHMD_SEARCH_DIRS})
|
||||
list(APPEND IVIEWHMD_REQUIREMENTS IVIEWHMD_INCLUDE_DIRS IVIEWHMD_LIBRARIES IVIEWHMD_API_DLL_PATH)
|
||||
|
||||
set(IVIEWHMD_DLLS
|
||||
avcodec-53.dll
|
||||
avformat-53.dll
|
||||
avutil-51.dll
|
||||
libboost_filesystem-mgw45-mt-1_49.dll
|
||||
libboost_system-mgw45-mt-1_49.dll
|
||||
libboost_thread-mgw45-mt-1_49.dll
|
||||
libgcc_s_dw2-1.dll
|
||||
libiViewNG-LibCore.dll
|
||||
libopencv_calib3d244.dll
|
||||
libopencv_core244.dll
|
||||
libopencv_features2d244.dll
|
||||
libopencv_flann244.dll
|
||||
libopencv_highgui244.dll
|
||||
libopencv_imgproc244.dll
|
||||
libopencv_legacy244.dll
|
||||
libopencv_ml244.dll
|
||||
libopencv_video244.dll
|
||||
libstdc++-6.dll
|
||||
opencv_core220.dll
|
||||
opencv_highgui220.dll
|
||||
opencv_imgproc220.dll
|
||||
swscale-2.dll
|
||||
)
|
||||
|
||||
foreach(IVIEWHMD_DLL ${IVIEWHMD_DLLS})
|
||||
find_path(IVIEWHMD_DLL_PATH ${IVIEWHMD_DLL} PATH_SUFFIXES 3rdParty HINTS ${IVIEWHMD_SEARCH_DIRS})
|
||||
list(APPEND IVIEWHMD_REQUIREMENTS IVIEWHMD_DLL_PATH)
|
||||
list(APPEND IVIEWHMD_DLL_PATHS ${IVIEWHMD_DLL_PATH})
|
||||
endforeach()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(IVIEWHMD DEFAULT_MSG ${IVIEWHMD_REQUIREMENTS})
|
||||
|
||||
add_paths_to_fixup_libs(${IVIEWHMD_API_DLL_PATH} ${IVIEWHMD_DLL_PATHS})
|
||||
|
||||
mark_as_advanced(IVIEWHMD_INCLUDE_DIRS IVIEWHMD_LIBRARIES IVIEWHMD_SEARCH_DIRS)
|
||||
|
||||
endif()
|
|
@ -31,4 +31,5 @@ include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
|
|||
# append OpenSSL to our list of libraries to link
|
||||
target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES})
|
||||
|
||||
include_application_version()
|
||||
copy_dlls_beside_windows_executable()
|
||||
|
|
|
@ -371,30 +371,8 @@
|
|||
"name": "persistFilename",
|
||||
"label": "Entities Filename",
|
||||
"help": "the path to the file entities are stored in. Make sure the path exists.",
|
||||
"placeholder": "resources/models.svo",
|
||||
"default": "resources/models.svo",
|
||||
"advanced": true
|
||||
},
|
||||
{
|
||||
"name": "persistAsFileType",
|
||||
"label": "File format for entity server's persistent data",
|
||||
"help": "This defines how the entity server will save entities to disk.",
|
||||
"default": "svo",
|
||||
"type": "select",
|
||||
"options": [
|
||||
{
|
||||
"value": "svo",
|
||||
"label": "Entity server persists data as SVO"
|
||||
},
|
||||
{
|
||||
"value": "json",
|
||||
"label": "Entity server persists data as JSON"
|
||||
},
|
||||
{
|
||||
"value": "json.gz",
|
||||
"label": "Entity server persists data as gzipped JSON"
|
||||
}
|
||||
],
|
||||
"placeholder": "resources/models.json.gz",
|
||||
"default": "resources/models.json.gz",
|
||||
"advanced": true
|
||||
},
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th>Version</th>
|
||||
<th>UUID</th>
|
||||
<th>Pool</th>
|
||||
<th>Username</th>
|
||||
|
@ -24,6 +25,7 @@
|
|||
<% _.each(nodes, function(node, node_index){ %>
|
||||
<tr>
|
||||
<td><%- node.type %></td>
|
||||
<td><%- node.version %></td>
|
||||
<td><a href="stats/?uuid=<%- node.uuid %>"><%- node.uuid %></a></td>
|
||||
<td><%- node.pool %></td>
|
||||
<td><%- node.username %></td>
|
||||
|
@ -75,4 +77,4 @@
|
|||
<!--#include file="footer.html"-->
|
||||
<script src='js/underscore-min.js'></script>
|
||||
<script src='js/tables.js'></script>
|
||||
<!--#include file="page-end.html"-->
|
||||
<!--#include file="page-end.html"-->
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QUrlQuery>
|
||||
|
||||
#include <AccountManager.h>
|
||||
#include <ApplicationVersion.h>
|
||||
#include <HifiConfigVariantMap.h>
|
||||
#include <HTTPConnection.h>
|
||||
#include <JSONBreakableMarshal.h>
|
||||
|
@ -75,6 +76,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
setOrganizationName("High Fidelity");
|
||||
setOrganizationDomain("highfidelity.io");
|
||||
setApplicationName("domain-server");
|
||||
setApplicationVersion(BUILD_VERSION);
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
|
||||
// make sure we have a fresh AccountManager instance
|
||||
|
@ -738,6 +740,7 @@ void DomainServer::processConnectRequestPacket(QSharedPointer<NLPacket> packet)
|
|||
if (isAssignment) {
|
||||
nodeData->setAssignmentUUID(matchingQueuedAssignment->getUUID());
|
||||
nodeData->setWalletUUID(pendingAssigneeData->getWalletUUID());
|
||||
nodeData->setNodeVersion(pendingAssigneeData->getNodeVersion());
|
||||
|
||||
// always allow assignment clients to create and destroy entities
|
||||
newNode->setCanAdjustLocks(true);
|
||||
|
@ -1168,7 +1171,8 @@ void DomainServer::processRequestAssignmentPacket(QSharedPointer<NLPacket> packe
|
|||
|
||||
// add the information for that deployed assignment to the hash of pending assigned nodes
|
||||
PendingAssignedNodeData* pendingNodeData = new PendingAssignedNodeData(assignmentToDeploy->getUUID(),
|
||||
requestAssignment.getWalletUUID());
|
||||
requestAssignment.getWalletUUID(),
|
||||
requestAssignment.getNodeVersion());
|
||||
_pendingAssignedNodes.insert(uniqueAssignment.getUUID(), pendingNodeData);
|
||||
} else {
|
||||
if (requestAssignment.getType() != Assignment::AgentType
|
||||
|
@ -1478,7 +1482,7 @@ const char JSON_KEY_POOL[] = "pool";
|
|||
const char JSON_KEY_PENDING_CREDITS[] = "pending_credits";
|
||||
const char JSON_KEY_WAKE_TIMESTAMP[] = "wake_timestamp";
|
||||
const char JSON_KEY_USERNAME[] = "username";
|
||||
|
||||
const char JSON_KEY_VERSION[] = "version";
|
||||
QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
|
||||
QJsonObject nodeJson;
|
||||
|
||||
|
@ -1505,6 +1509,7 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
|
|||
|
||||
// add the node username, if it exists
|
||||
nodeJson[JSON_KEY_USERNAME] = nodeData->getUsername();
|
||||
nodeJson[JSON_KEY_VERSION] = nodeData->getNodeVersion();
|
||||
|
||||
SharedAssignmentPointer matchingAssignment = _allAssignments.value(nodeData->getAssignmentUUID());
|
||||
if (matchingAssignment) {
|
||||
|
@ -1527,7 +1532,6 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
|
|||
}
|
||||
|
||||
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
||||
|
||||
QString pathForAssignmentScript(const QUuid& assignmentUUID) {
|
||||
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
|
||||
newPath += "/scripts/";
|
||||
|
@ -1537,7 +1541,6 @@ QString pathForAssignmentScript(const QUuid& assignmentUUID) {
|
|||
}
|
||||
|
||||
const QString URI_OAUTH = "/oauth";
|
||||
|
||||
bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {
|
||||
const QString JSON_MIME_TYPE = "application/json";
|
||||
|
||||
|
@ -2024,8 +2027,6 @@ bool DomainServer::isAuthenticatedRequest(HTTPConnection* connection, const QUrl
|
|||
}
|
||||
|
||||
const QString OAUTH_JSON_ACCESS_TOKEN_KEY = "access_token";
|
||||
|
||||
|
||||
QNetworkReply* DomainServer::profileRequestGivenTokenReply(QNetworkReply* tokenReply) {
|
||||
// pull the access token from the returned JSON and store it with the matching session UUID
|
||||
QJsonDocument returnedJSON = QJsonDocument::fromJson(tokenReply->readAll());
|
||||
|
@ -2042,7 +2043,6 @@ QNetworkReply* DomainServer::profileRequestGivenTokenReply(QNetworkReply* tokenR
|
|||
}
|
||||
|
||||
const QString DS_SETTINGS_SESSIONS_GROUP = "web-sessions";
|
||||
|
||||
Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileReply) {
|
||||
Headers cookieHeaders;
|
||||
|
||||
|
|
|
@ -50,6 +50,10 @@ public:
|
|||
|
||||
const NodeSet& getNodeInterestSet() const { return _nodeInterestSet; }
|
||||
void setNodeInterestSet(const NodeSet& nodeInterestSet) { _nodeInterestSet = nodeInterestSet; }
|
||||
|
||||
void setNodeVersion(const QString& nodeVersion) { _nodeVersion = nodeVersion; }
|
||||
const QString& getNodeVersion() { return _nodeVersion; }
|
||||
|
||||
private:
|
||||
QJsonObject mergeJSONStatsFromNewObject(const QJsonObject& newObject, QJsonObject destinationObject);
|
||||
|
||||
|
@ -62,6 +66,7 @@ private:
|
|||
HifiSockAddr _sendingSockAddr;
|
||||
bool _isAuthenticated;
|
||||
NodeSet _nodeInterestSet;
|
||||
QString _nodeVersion;
|
||||
};
|
||||
|
||||
#endif // hifi_DomainServerNodeData_h
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtCore/QDataStream>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QJsonObject>
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
|
||||
#include "PendingAssignedNodeData.h"
|
||||
|
||||
PendingAssignedNodeData::PendingAssignedNodeData(const QUuid& assignmentUUID, const QUuid& walletUUID) :
|
||||
PendingAssignedNodeData::PendingAssignedNodeData(const QUuid& assignmentUUID, const QUuid& walletUUID, const QString& nodeVersion) :
|
||||
_assignmentUUID(assignmentUUID),
|
||||
_walletUUID(walletUUID)
|
||||
_walletUUID(walletUUID),
|
||||
_nodeVersion(nodeVersion)
|
||||
{
|
||||
|
||||
}
|
|
@ -18,16 +18,20 @@
|
|||
class PendingAssignedNodeData : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PendingAssignedNodeData(const QUuid& assignmentUUID, const QUuid& walletUUID);
|
||||
PendingAssignedNodeData(const QUuid& assignmentUUID, const QUuid& walletUUID, const QString& nodeVersion);
|
||||
|
||||
void setAssignmentUUID(const QUuid& assignmentUUID) { _assignmentUUID = assignmentUUID; }
|
||||
const QUuid& getAssignmentUUID() const { return _assignmentUUID; }
|
||||
|
||||
void setWalletUUID(const QUuid& walletUUID) { _walletUUID = walletUUID; }
|
||||
const QUuid& getWalletUUID() const { return _walletUUID; }
|
||||
|
||||
const QString& getNodeVersion() const { return _nodeVersion; }
|
||||
|
||||
private:
|
||||
QUuid _assignmentUUID;
|
||||
QUuid _walletUUID;
|
||||
QString _nodeVersion;
|
||||
};
|
||||
|
||||
#endif // hifi_PendingAssignedNodeData_h
|
79
examples/controllers/squeezeHands.js
Normal file
79
examples/controllers/squeezeHands.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// squeezeHands.js
|
||||
// examples
|
||||
//
|
||||
// Created by Philip Rosedale on June 4, 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
|
||||
//
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
|
||||
var rightHandAnimation = HIFI_PUBLIC_BUCKET + "animations/RightHandAnimPhilip.fbx";
|
||||
var leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx";
|
||||
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
|
||||
var lastLeftFrame = 0;
|
||||
var lastRightFrame = 0;
|
||||
|
||||
var leftDirection = true;
|
||||
var rightDirection = true;
|
||||
|
||||
var LAST_FRAME = 15.0; // What is the number of the last frame we want to use in the animation?
|
||||
var SMOOTH_FACTOR = 0.0;
|
||||
var MAX_FRAMES = 30.0;
|
||||
|
||||
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
||||
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
var leftTriggerValue = Controller.getActionValue(LEFT_HAND_CLICK);
|
||||
var rightTriggerValue = Controller.getActionValue(RIGHT_HAND_CLICK);
|
||||
|
||||
var leftFrame, rightFrame;
|
||||
|
||||
// Average last few trigger frames together for a bit of smoothing
|
||||
leftFrame = (leftTriggerValue * LAST_FRAME) * (1.0 - SMOOTH_FACTOR) + lastLeftFrame * SMOOTH_FACTOR;
|
||||
rightFrame = (rightTriggerValue * LAST_FRAME) * (1.0 - SMOOTH_FACTOR) + lastRightFrame * SMOOTH_FACTOR;
|
||||
|
||||
if (!leftDirection) {
|
||||
leftFrame = MAX_FRAMES - leftFrame;
|
||||
}
|
||||
if (!rightDirection) {
|
||||
rightFrame = MAX_FRAMES - rightFrame;
|
||||
}
|
||||
|
||||
if ((leftTriggerValue == 1.0) && (leftDirection == true)) {
|
||||
leftDirection = false;
|
||||
lastLeftFrame = MAX_FRAMES - leftFrame;
|
||||
} else if ((leftTriggerValue == 0.0) && (leftDirection == false)) {
|
||||
leftDirection = true;
|
||||
lastLeftFrame = leftFrame;
|
||||
}
|
||||
if ((rightTriggerValue == 1.0) && (rightDirection == true)) {
|
||||
rightDirection = false;
|
||||
lastRightFrame = MAX_FRAMES - rightFrame;
|
||||
} else if ((rightTriggerValue == 0.0) && (rightDirection == false)) {
|
||||
rightDirection = true;
|
||||
lastRightFrame = rightFrame;
|
||||
}
|
||||
|
||||
if ((leftFrame != lastLeftFrame) && leftHandAnimation.length){
|
||||
MyAvatar.startAnimation(leftHandAnimation, 30.0, 1.0, false, true, leftFrame, leftFrame);
|
||||
}
|
||||
if ((rightFrame != lastRightFrame) && rightHandAnimation.length) {
|
||||
MyAvatar.startAnimation(rightHandAnimation, 30.0, 1.0, false, true, rightFrame, rightFrame);
|
||||
}
|
||||
|
||||
lastLeftFrame = leftFrame;
|
||||
lastRightFrame = rightFrame;
|
||||
});
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
MyAvatar.stopAnimation(leftHandAnimation);
|
||||
MyAvatar.stopAnimation(rightHandAnimation);
|
||||
});
|
430
examples/controllers/toybox.js
Normal file
430
examples/controllers/toybox.js
Normal file
|
@ -0,0 +1,430 @@
|
|||
// handGrab.js
|
||||
// examples
|
||||
//
|
||||
// Created by Sam Gondelman on 8/3/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Allow avatar to grab the closest object to each hand and throw them
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
Script.include("http://s3.amazonaws.com/hifi-public/scripts/libraries/toolBars.js");
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
|
||||
var nullActionID = "00000000-0000-0000-0000-000000000000";
|
||||
var controllerID;
|
||||
var controllerActive;
|
||||
var leftHandObjectID = null;
|
||||
var rightHandObjectID = null;
|
||||
var leftHandActionID = nullActionID;
|
||||
var rightHandActionID = nullActionID;
|
||||
|
||||
var TRIGGER_THRESHOLD = 0.2;
|
||||
var GRAB_RADIUS = 0.15;
|
||||
|
||||
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
||||
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
||||
var ACTION1 = Controller.findAction("ACTION1");
|
||||
var ACTION2 = Controller.findAction("ACTION2");
|
||||
|
||||
var rightHandGrabAction = RIGHT_HAND_CLICK;
|
||||
var leftHandGrabAction = LEFT_HAND_CLICK;
|
||||
|
||||
var rightHandGrabValue = 0;
|
||||
var leftHandGrabValue = 0;
|
||||
var prevRightHandGrabValue = 0
|
||||
var prevLeftHandGrabValue = 0;
|
||||
|
||||
var grabColor = { red: 0, green: 255, blue: 0};
|
||||
var releaseColor = { red: 0, green: 0, blue: 255};
|
||||
|
||||
var toolBar = new ToolBar(0, 0, ToolBar.vertical, "highfidelity.toybox.toolbar", function() {
|
||||
return {
|
||||
x: 100,
|
||||
y: 380
|
||||
};
|
||||
});
|
||||
|
||||
var BUTTON_SIZE = 32;
|
||||
var SWORD_IMAGE = "https://hifi-public.s3.amazonaws.com/images/sword/sword.svg"; // TODO: replace this with a table icon
|
||||
var CLEANUP_IMAGE = "http://s3.amazonaws.com/hifi-public/images/delete.png";
|
||||
var tableButton = toolBar.addOverlay("image", {
|
||||
width: BUTTON_SIZE,
|
||||
height: BUTTON_SIZE,
|
||||
imageURL: SWORD_IMAGE,
|
||||
alpha: 1
|
||||
});
|
||||
var cleanupButton = toolBar.addOverlay("image", {
|
||||
width: BUTTON_SIZE,
|
||||
height: BUTTON_SIZE,
|
||||
imageURL: CLEANUP_IMAGE,
|
||||
alpha: 1
|
||||
});
|
||||
|
||||
var overlays = false;
|
||||
var leftHandOverlay;
|
||||
var rightHandOverlay;
|
||||
if (overlays) {
|
||||
leftHandOverlay = Overlays.addOverlay("sphere", {
|
||||
position: MyAvatar.getLeftPalmPosition(),
|
||||
size: GRAB_RADIUS,
|
||||
color: releaseColor,
|
||||
alpha: 0.5,
|
||||
solid: false
|
||||
});
|
||||
rightHandOverlay = Overlays.addOverlay("sphere", {
|
||||
position: MyAvatar.getRightPalmPosition(),
|
||||
size: GRAB_RADIUS,
|
||||
color: releaseColor,
|
||||
alpha: 0.5,
|
||||
solid: false
|
||||
});
|
||||
}
|
||||
|
||||
var OBJECT_HEIGHT_OFFSET = 0.5;
|
||||
var MIN_OBJECT_SIZE = 0.05;
|
||||
var MAX_OBJECT_SIZE = 0.3;
|
||||
var TABLE_DIMENSIONS = {
|
||||
x: 10.0,
|
||||
y: 0.2,
|
||||
z: 5.0
|
||||
};
|
||||
|
||||
var GRAVITY = {
|
||||
x: 0.0,
|
||||
y: -2.0,
|
||||
z: 0.0
|
||||
}
|
||||
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
|
||||
var tableCreated = false;
|
||||
|
||||
var NUM_OBJECTS = 100;
|
||||
var tableEntities = Array(NUM_OBJECTS + 1); // Also includes table
|
||||
|
||||
var VELOCITY_MAG = 0.3;
|
||||
|
||||
var entitiesToResize = [];
|
||||
|
||||
var MODELS = Array(
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.fbx" },
|
||||
{ modelURL: "https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Vehicles/clara/spaceshuttle.fbx" },
|
||||
{ modelURL: "https://s3.amazonaws.com/hifi-public/cozza13/apartment/Stargate.fbx" },
|
||||
{ modelURL: "https://dl.dropboxusercontent.com/u/17344741/kelectricguitar10/kelectricguitar10.fbx" },
|
||||
{ modelURL: "https://dl.dropboxusercontent.com/u/17344741/ktoilet10/ktoilet10.fbx" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/models/props/MidCenturyModernLivingRoom/Interior/BilliardsTable.fbx" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/ozan/avatars/robotMedic/robotMedicRed/robotMedicRed.fst" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/ozan/avatars/robotMedic/robotMedicFaceRig/robotMedic.fst" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/marketplace/contents/029db3d4-da2c-4cb2-9c08-b9612ba576f5/02949063e7c4aed42ad9d1a58461f56d.fst?1427169842" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/models/props/MidCenturyModernLivingRoom/Interior/Bar.fbx" },
|
||||
{ modelURL: "https://hifi-public.s3.amazonaws.com/marketplace/contents/96124d04-d603-4707-a5b3-e03bf47a53b2/1431770eba362c1c25c524126f2970fb.fst?1436924721" }
|
||||
// Complex models:
|
||||
// { modelURL: "https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Architecture/sketchfab/cudillero.fbx" },
|
||||
// { modelURL: "https://hifi-public.s3.amazonaws.com/ozan/sets/musicality/musicality.fbx" },
|
||||
// { modelURL: "https://hifi-public.s3.amazonaws.com/ozan/sets/statelyHome/statelyHome.fbx" }
|
||||
);
|
||||
|
||||
var COLLISION_SOUNDS = Array(
|
||||
"http://public.highfidelity.io/sounds/Collisions-ballhitsandcatches/pingpong_TableBounceMono.wav",
|
||||
"http://public.highfidelity.io/sounds/Collisions-ballhitsandcatches/billiards/collision1.wav"
|
||||
);
|
||||
|
||||
var RESIZE_TIMER = 0.0;
|
||||
var RESIZE_WAIT = 0.05; // 50 milliseconds
|
||||
|
||||
var leftFist = Entities.addEntity( {
|
||||
type: "Sphere",
|
||||
shapeType: 'sphere',
|
||||
position: MyAvatar.getLeftPalmPosition(),
|
||||
dimensions: { x: GRAB_RADIUS, y: GRAB_RADIUS, z: GRAB_RADIUS },
|
||||
rotation: MyAvatar.getLeftPalmRotation(),
|
||||
visible: false,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true
|
||||
});
|
||||
var rightFist = Entities.addEntity( {
|
||||
type: "Sphere",
|
||||
shapeType: 'sphere',
|
||||
position: MyAvatar.getRightPalmPosition(),
|
||||
dimensions: { x: GRAB_RADIUS, y: GRAB_RADIUS, z: GRAB_RADIUS },
|
||||
rotation: MyAvatar.getRightPalmRotation(),
|
||||
visible: false,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true
|
||||
});
|
||||
|
||||
function letGo(hand) {
|
||||
var actionIDToRemove = (hand == LEFT) ? leftHandActionID : rightHandActionID;
|
||||
var entityIDToEdit = (hand == LEFT) ? leftHandObjectID : rightHandObjectID;
|
||||
var handVelocity = (hand == LEFT) ? MyAvatar.getLeftPalmVelocity() : MyAvatar.getRightPalmVelocity();
|
||||
var handAngularVelocity = (hand == LEFT) ? MyAvatar.getLeftPalmAngularVelocity() :
|
||||
MyAvatar.getRightPalmAngularVelocity();
|
||||
if (actionIDToRemove != nullActionID && entityIDToEdit != null) {
|
||||
Entities.deleteAction(entityIDToEdit, actionIDToRemove);
|
||||
// TODO: upon successful letGo, restore collision groups
|
||||
if (hand == LEFT) {
|
||||
leftHandObjectID = null;
|
||||
leftHandActionID = nullActionID;
|
||||
} else {
|
||||
rightHandObjectID = null;
|
||||
rightHandActionID = nullActionID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setGrabbedObject(hand) {
|
||||
var handPosition = (hand == LEFT) ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition();
|
||||
var entities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
var objectID = null;
|
||||
var minDistance = GRAB_RADIUS;
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
// Don't grab the object in your other hands, your fists, or the table
|
||||
if ((hand == LEFT && entities[i] == rightHandObjectID) ||
|
||||
(hand == RIGHT && entities[i] == leftHandObjectID) ||
|
||||
entities[i] == leftFist || entities[i] == rightFist ||
|
||||
(tableCreated && entities[i] == tableEntities[0])) {
|
||||
continue;
|
||||
} else {
|
||||
var distance = Vec3.distance(Entities.getEntityProperties(entities[i]).position, handPosition);
|
||||
if (distance <= minDistance) {
|
||||
objectID = entities[i];
|
||||
minDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (objectID == null) {
|
||||
return false;
|
||||
}
|
||||
if (hand == LEFT) {
|
||||
leftHandObjectID = objectID;
|
||||
} else {
|
||||
rightHandObjectID = objectID;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function grab(hand) {
|
||||
if (!setGrabbedObject(hand)) {
|
||||
// If you don't grab an object, make a fist
|
||||
Entities.editEntity((hand == LEFT) ? leftFist : rightFist, { ignoreForCollisions: false } );
|
||||
return;
|
||||
}
|
||||
var objectID = (hand == LEFT) ? leftHandObjectID : rightHandObjectID;
|
||||
var handRotation = (hand == LEFT) ? MyAvatar.getLeftPalmRotation() : MyAvatar.getRightPalmRotation();
|
||||
var handPosition = (hand == LEFT) ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition();
|
||||
|
||||
var objectRotation = Entities.getEntityProperties(objectID).rotation;
|
||||
var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
||||
|
||||
var objectPosition = Entities.getEntityProperties(objectID).position;
|
||||
var offset = Vec3.subtract(objectPosition, handPosition);
|
||||
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
|
||||
// print(JSON.stringify(offsetPosition));
|
||||
var actionID = Entities.addAction("hold", objectID, {
|
||||
relativePosition: { x: 0, y: 0, z: 0 },
|
||||
relativeRotation: offsetRotation,
|
||||
hand: (hand == LEFT) ? "left" : "right",
|
||||
timeScale: 0.05
|
||||
});
|
||||
if (actionID == nullActionID) {
|
||||
if (hand == LEFT) {
|
||||
leftHandObjectID = null;
|
||||
} else {
|
||||
rightHandObjectID = null;
|
||||
}
|
||||
} else {
|
||||
// TODO: upon successful grab, add to collision group so object doesn't collide with immovable entities
|
||||
if (hand == LEFT) {
|
||||
leftHandActionID = actionID;
|
||||
} else {
|
||||
rightHandActionID = actionID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resizeModels() {
|
||||
var newEntitiesToResize = [];
|
||||
for (var i = 0; i < entitiesToResize.length; i++) {
|
||||
var naturalDimensions = Entities.getEntityProperties(entitiesToResize[i]).naturalDimensions;
|
||||
if (naturalDimensions.x != 1.0 || naturalDimensions.y != 1.0 || naturalDimensions.z != 1.0) {
|
||||
// bigger range of sizes for models
|
||||
var dimensions = Vec3.multiply(randFloat(MIN_OBJECT_SIZE, 3.0*MAX_OBJECT_SIZE), Vec3.normalize(naturalDimensions));
|
||||
Entities.editEntity(entitiesToResize[i], {
|
||||
dimensions: dimensions,
|
||||
shapeType: "box"
|
||||
});
|
||||
} else {
|
||||
newEntitiesToResize.push(entitiesToResize[i]);
|
||||
}
|
||||
|
||||
}
|
||||
entitiesToResize = newEntitiesToResize;
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
if (overlays) {
|
||||
Overlays.editOverlay(leftHandOverlay, { position: MyAvatar.getLeftPalmPosition() });
|
||||
Overlays.editOverlay(rightHandOverlay, { position: MyAvatar.getRightPalmPosition() });
|
||||
}
|
||||
|
||||
// if (tableCreated && RESIZE_TIMER < RESIZE_WAIT) {
|
||||
// RESIZE_TIMER += deltaTime;
|
||||
// } else if (tableCreated) {
|
||||
// resizeModels();
|
||||
// }
|
||||
|
||||
rightHandGrabValue = Controller.getActionValue(rightHandGrabAction);
|
||||
leftHandGrabValue = Controller.getActionValue(leftHandGrabAction);
|
||||
|
||||
Entities.editEntity(leftFist, { position: MyAvatar.getLeftPalmPosition() });
|
||||
Entities.editEntity(rightFist, { position: MyAvatar.getRightPalmPosition() });
|
||||
|
||||
if (rightHandGrabValue > TRIGGER_THRESHOLD &&
|
||||
prevRightHandGrabValue < TRIGGER_THRESHOLD) {
|
||||
if (overlays) {
|
||||
Overlays.editOverlay(rightHandOverlay, { color: grabColor });
|
||||
}
|
||||
grab(RIGHT);
|
||||
} else if (rightHandGrabValue < TRIGGER_THRESHOLD &&
|
||||
prevRightHandGrabValue > TRIGGER_THRESHOLD) {
|
||||
Entities.editEntity(rightFist, { ignoreForCollisions: true } );
|
||||
if (overlays) {
|
||||
Overlays.editOverlay(rightHandOverlay, { color: releaseColor });
|
||||
}
|
||||
letGo(RIGHT);
|
||||
}
|
||||
|
||||
if (leftHandGrabValue > TRIGGER_THRESHOLD &&
|
||||
prevLeftHandGrabValue < TRIGGER_THRESHOLD) {
|
||||
if (overlays) {
|
||||
Overlays.editOverlay(leftHandOverlay, { color: grabColor });
|
||||
}
|
||||
grab(LEFT);
|
||||
} else if (leftHandGrabValue < TRIGGER_THRESHOLD &&
|
||||
prevLeftHandGrabValue > TRIGGER_THRESHOLD) {
|
||||
Entities.editEntity(leftFist, { ignoreForCollisions: true } );
|
||||
if (overlays) {
|
||||
Overlays.editOverlay(leftHandOverlay, { color: releaseColor });
|
||||
}
|
||||
letGo(LEFT);
|
||||
}
|
||||
|
||||
prevRightHandGrabValue = rightHandGrabValue;
|
||||
prevLeftHandGrabValue = leftHandGrabValue;
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
letGo(RIGHT);
|
||||
letGo(LEFT);
|
||||
if (overlays) {
|
||||
Overlays.deleteOverlay(leftHandOverlay);
|
||||
Overlays.deleteOverlay(rightHandOverlay);
|
||||
}
|
||||
Entities.deleteEntity(leftFist);
|
||||
Entities.deleteEntity(rightFist);
|
||||
removeTable();
|
||||
toolBar.cleanup();
|
||||
}
|
||||
|
||||
function onClick(event) {
|
||||
if (event.deviceID != 0) {
|
||||
return;
|
||||
}
|
||||
switch (Overlays.getOverlayAtPoint(event)) {
|
||||
case tableButton:
|
||||
if (!tableCreated) {
|
||||
createTable();
|
||||
tableCreated = true;
|
||||
}
|
||||
break;
|
||||
case cleanupButton:
|
||||
if (tableCreated) {
|
||||
removeTable();
|
||||
tableCreated = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
randFloat = function(low, high) {
|
||||
return low + Math.random() * (high - low);
|
||||
}
|
||||
|
||||
randInt = function(low, high) {
|
||||
return Math.floor(randFloat(low, high));
|
||||
}
|
||||
|
||||
function createTable() {
|
||||
var tablePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(MyAvatar.orientation)));
|
||||
tableEntities[0] = Entities.addEntity( {
|
||||
type: "Model",
|
||||
shapeType: 'box',
|
||||
position: tablePosition,
|
||||
dimensions: TABLE_DIMENSIONS,
|
||||
rotation: MyAvatar.orientation,
|
||||
// color: { red: 102, green: 51, blue: 0 },
|
||||
modelURL: HIFI_PUBLIC_BUCKET + 'eric/models/woodFloor.fbx',
|
||||
collisionSoundURL: "http://public.highfidelity.io/sounds/dice/diceCollide.wav"
|
||||
});
|
||||
|
||||
for (var i = 1; i < NUM_OBJECTS + 1; i++) {
|
||||
var objectOffset = { x: TABLE_DIMENSIONS.x/2.0 * randFloat(-1, 1),
|
||||
y: OBJECT_HEIGHT_OFFSET,
|
||||
z: TABLE_DIMENSIONS.z/2.0 * randFloat(-1, 1) };
|
||||
var objectPosition = Vec3.sum(tablePosition, Vec3.multiplyQbyV(MyAvatar.orientation, objectOffset));
|
||||
var type;
|
||||
var randType = randInt(0, 3);
|
||||
switch (randType) {
|
||||
case 0:
|
||||
type = "Box";
|
||||
break;
|
||||
case 1:
|
||||
type = "Sphere";
|
||||
// break;
|
||||
case 2:
|
||||
type = "Model";
|
||||
break;
|
||||
}
|
||||
tableEntities[i] = Entities.addEntity( {
|
||||
type: type,
|
||||
position: objectPosition,
|
||||
velocity: { x: randFloat(-VELOCITY_MAG, VELOCITY_MAG),
|
||||
y: randFloat(-VELOCITY_MAG, VELOCITY_MAG),
|
||||
z: randFloat(-VELOCITY_MAG, VELOCITY_MAG) },
|
||||
dimensions: { x: randFloat(MIN_OBJECT_SIZE, MAX_OBJECT_SIZE),
|
||||
y: randFloat(MIN_OBJECT_SIZE, MAX_OBJECT_SIZE),
|
||||
z: randFloat(MIN_OBJECT_SIZE, MAX_OBJECT_SIZE) },
|
||||
rotation: MyAvatar.orientation,
|
||||
gravity: GRAVITY,
|
||||
damping: 0.1,
|
||||
restitution: 0.01,
|
||||
density: 0.5,
|
||||
collisionsWillMove: true,
|
||||
color: { red: randInt(0, 255), green: randInt(0, 255), blue: randInt(0, 255) },
|
||||
// collisionSoundURL: COLLISION_SOUNDS[randInt(0, COLLISION_SOUNDS.length)]
|
||||
});
|
||||
if (type == "Model") {
|
||||
var randModel = randInt(0, MODELS.length);
|
||||
Entities.editEntity(tableEntities[i], {
|
||||
shapeType: "box",
|
||||
modelURL: MODELS[randModel].modelURL
|
||||
});
|
||||
entitiesToResize.push(tableEntities[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeTable() {
|
||||
RESIZE_TIMER = 0.0;
|
||||
for (var i = 0; i < tableEntities.length; i++) {
|
||||
Entities.deleteEntity(tableEntities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanUp);
|
||||
Script.update.connect(update);
|
||||
Controller.mousePressEvent.connect(onClick);
|
|
@ -16,6 +16,4 @@ Script.load("notifications.js");
|
|||
Script.load("users.js");
|
||||
Script.load("grab.js");
|
||||
Script.load("directory.js");
|
||||
Script.load("mouseLook.js");
|
||||
Script.load("hmdControls.js");
|
||||
Script.load("dialTone.js");
|
||||
|
|
|
@ -574,8 +574,14 @@ function findClickedEntity(event) {
|
|||
}
|
||||
|
||||
var mouseHasMovedSincePress = false;
|
||||
var mousePressStartTime = 0;
|
||||
var mousePressStartPosition = { x: 0, y: 0 };
|
||||
var mouseDown = false;
|
||||
|
||||
function mousePressEvent(event) {
|
||||
mouseDown = true;
|
||||
mousePressStartPosition = { x: event.x, y: event.y };
|
||||
mousePressStartTime = Date.now();
|
||||
mouseHasMovedSincePress = false;
|
||||
mouseCapturedByTool = false;
|
||||
|
||||
|
@ -595,6 +601,8 @@ var highlightedEntityID = null;
|
|||
var mouseCapturedByTool = false;
|
||||
var lastMousePosition = null;
|
||||
var idleMouseTimerId = null;
|
||||
var CLICK_TIME_THRESHOLD = 500 * 1000; // 500 ms
|
||||
var CLICK_MOVE_DISTANCE_THRESHOLD = 8;
|
||||
var IDLE_MOUSE_TIMEOUT = 200;
|
||||
var DEFAULT_ENTITY_DRAG_DROP_DISTANCE = 2.0;
|
||||
|
||||
|
@ -603,7 +611,21 @@ function mouseMoveEventBuffered(event) {
|
|||
lastMouseMoveEvent = event;
|
||||
}
|
||||
function mouseMove(event) {
|
||||
mouseHasMovedSincePress = true;
|
||||
if (mouseDown && !mouseHasMovedSincePress) {
|
||||
var timeSincePressMicro = Date.now() - mousePressStartTime;
|
||||
|
||||
var dX = mousePressStartPosition.x - event.x;
|
||||
var dY = mousePressStartPosition.y - event.y;
|
||||
var sqDist = (dX * dX) + (dY * dY);
|
||||
|
||||
// If less than CLICK_TIME_THRESHOLD has passed since the mouse click AND the mouse has moved
|
||||
// less than CLICK_MOVE_DISTANCE_THRESHOLD distance, then don't register this as a mouse move
|
||||
// yet. The goal is to provide mouse clicks that are more lenient to small movements.
|
||||
if (timeSincePressMicro < CLICK_TIME_THRESHOLD && sqDist < CLICK_MOVE_DISTANCE_THRESHOLD) {
|
||||
return;
|
||||
}
|
||||
mouseHasMovedSincePress = true;
|
||||
}
|
||||
|
||||
if (placingEntityID) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
@ -670,6 +692,8 @@ function highlightEntityUnderCursor(position, accurateRay) {
|
|||
|
||||
|
||||
function mouseReleaseEvent(event) {
|
||||
mouseDown = false;
|
||||
|
||||
if (lastMouseMoveEvent) {
|
||||
mouseMove(lastMouseMoveEvent);
|
||||
lastMouseMoveEvent = null;
|
||||
|
@ -1012,6 +1036,7 @@ function handeMenuEvent(menuItem) {
|
|||
// This function tries to find a reasonable position to place a new entity based on the camera
|
||||
// position. If a reasonable position within the world bounds can't be found, `null` will
|
||||
// be returned. The returned position will also take into account grid snapping settings.
|
||||
// FIXME - technically we should guard against very large positions too
|
||||
function getPositionToCreateEntity() {
|
||||
var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE;
|
||||
var direction = Quat.getFront(Camera.orientation);
|
||||
|
@ -1019,17 +1044,21 @@ function getPositionToCreateEntity() {
|
|||
var placementPosition = Vec3.sum(Camera.position, offset);
|
||||
|
||||
var cameraPosition = Camera.position;
|
||||
|
||||
var HALF_TREE_SCALE = 16384;
|
||||
|
||||
var cameraOutOfBounds = cameraPosition.x < 0 || cameraPosition.y < 0 || cameraPosition.z < 0;
|
||||
var placementOutOfBounds = placementPosition.x < 0 || placementPosition.y < 0 || placementPosition.z < 0;
|
||||
var cameraOutOfBounds = cameraPosition.x < -HALF_TREE_SCALE || cameraPosition.y < -HALF_TREE_SCALE ||
|
||||
cameraPosition.z < -HALF_TREE_SCALE;
|
||||
var placementOutOfBounds = placementPosition.x < -HALF_TREE_SCALE || placementPosition.y < -HALF_TREE_SCALE ||
|
||||
placementPosition.z < -HALF_TREE_SCALE;
|
||||
|
||||
if (cameraOutOfBounds && placementOutOfBounds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
placementPosition.x = Math.max(0, placementPosition.x);
|
||||
placementPosition.y = Math.max(0, placementPosition.y);
|
||||
placementPosition.z = Math.max(0, placementPosition.z);
|
||||
placementPosition.x = Math.max(-HALF_TREE_SCALE, placementPosition.x);
|
||||
placementPosition.y = Math.max(-HALF_TREE_SCALE, placementPosition.y);
|
||||
placementPosition.z = Math.max(-HALF_TREE_SCALE, placementPosition.z);
|
||||
|
||||
return placementPosition;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ Script.include('../utilities/tools/vector.js');
|
|||
|
||||
var URL = "https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Scripts/planets/";
|
||||
|
||||
SatelliteGame = function() {
|
||||
SatelliteCreator = function() {
|
||||
print("initializing satellite game");
|
||||
|
||||
var MAX_RANGE = 50.0;
|
||||
var Y_AXIS = {
|
||||
x: 0,
|
||||
|
@ -36,6 +38,10 @@ SatelliteGame = function() {
|
|||
var ZONE_DIM = 100.0;
|
||||
var LIGHT_INTENSITY = 1.5;
|
||||
|
||||
var center, distance;
|
||||
var earth;
|
||||
|
||||
|
||||
Earth = function(position, size) {
|
||||
this.earth = Entities.addEntity({
|
||||
type: "Model",
|
||||
|
@ -68,7 +74,7 @@ SatelliteGame = function() {
|
|||
this.clouds = Entities.addEntity({
|
||||
type: "Model",
|
||||
shapeType: 'sphere',
|
||||
modelURL: URL + "clouds.fbx?i=2",
|
||||
modelURL: URL + "clouds.fbx",
|
||||
position: position,
|
||||
dimensions: {
|
||||
x: size + CLOUDS_OFFSET,
|
||||
|
@ -101,16 +107,42 @@ SatelliteGame = function() {
|
|||
});
|
||||
|
||||
this.cleanup = function() {
|
||||
print('cleaning up earth models');
|
||||
Entities.deleteEntity(this.clouds);
|
||||
Entities.deleteEntity(this.earth);
|
||||
Entities.deleteEntity(this.zone);
|
||||
}
|
||||
}
|
||||
|
||||
// Create earth model
|
||||
var center = Vec3.sum(Camera.getPosition(), Vec3.multiply(MAX_RANGE, Quat.getFront(Camera.getOrientation())));
|
||||
var distance = Vec3.length(Vec3.subtract(center, Camera.getPosition()));
|
||||
var earth = new Earth(center, EARTH_SIZE);
|
||||
|
||||
this.init = function() {
|
||||
if (this.isActive) {
|
||||
this.quitGame();
|
||||
}
|
||||
var confirmed = Window.confirm("Start satellite game?");
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.isActive = true;
|
||||
MyAvatar.position = {
|
||||
x: 1000,
|
||||
y: 1000,
|
||||
z: 1000
|
||||
};
|
||||
Camera.setPosition({
|
||||
x: 1000,
|
||||
y: 1000,
|
||||
z: 1000
|
||||
});
|
||||
|
||||
// Create earth model
|
||||
center = Vec3.sum(Camera.getPosition(), Vec3.multiply(MAX_RANGE, Quat.getFront(Camera.getOrientation())));
|
||||
distance = Vec3.length(Vec3.subtract(center, Camera.getPosition()));
|
||||
earth = new Earth(center, EARTH_SIZE);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
var satellites = [];
|
||||
var SATELLITE_SIZE = 2.0;
|
||||
|
@ -257,12 +289,16 @@ SatelliteGame = function() {
|
|||
}
|
||||
}
|
||||
|
||||
this.endGame = function() {
|
||||
this.quitGame = function() {
|
||||
print("ending satellite game");
|
||||
this.isActive = false;
|
||||
|
||||
for (var i = 0; i < satellites.length; i++) {
|
||||
Entities.deleteEntity(satellites[i].satellite);
|
||||
satellites[i].arrow.cleanup();
|
||||
}
|
||||
earth.cleanup();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,6 +319,7 @@ SatelliteGame = function() {
|
|||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(this.endGame);
|
||||
Script.scriptEnding.connect(this.quitGame);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -13,11 +13,15 @@
|
|||
/*jslint vars: true*/
|
||||
var Script, Entities, MyAvatar, Window, Overlays, Controller, Vec3, Quat, print, ToolBar, Settings; // Referenced globals provided by High Fidelity.
|
||||
Script.include("http://s3.amazonaws.com/hifi-public/scripts/libraries/toolBars.js");
|
||||
var zombieGameScriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/zombieFight.js?v2";
|
||||
// var zombieGameScriptURL = "zombieFight.js";
|
||||
Script.include(zombieGameScriptURL);
|
||||
|
||||
var zombieFight;
|
||||
|
||||
var zombieFight = new ZombieFight();
|
||||
|
||||
var hand = "right";
|
||||
|
||||
var zombieFight;
|
||||
var nullActionID = "00000000-0000-0000-0000-000000000000";
|
||||
var controllerID;
|
||||
var controllerActive;
|
||||
|
@ -78,7 +82,7 @@ var cleanupButton = toolBar.addOverlay("image", {
|
|||
|
||||
var flasher;
|
||||
|
||||
var leftTriggerButton = 0;
|
||||
var leftHandClick = 14;
|
||||
var leftTriggerValue = 0;
|
||||
var prevLeftTriggerValue = 0;
|
||||
|
||||
|
@ -88,7 +92,7 @@ var RIGHT = 1;
|
|||
|
||||
var leftPalm = 2 * LEFT;
|
||||
var rightPalm = 2 * RIGHT;
|
||||
var rightTriggerButton = 1;
|
||||
var rightHandClick = 15;
|
||||
var prevRightTriggerValue = 0;
|
||||
var rightTriggerValue = 0;
|
||||
var TRIGGER_THRESHOLD = 0.2;
|
||||
|
@ -357,8 +361,8 @@ function update() {
|
|||
}
|
||||
|
||||
function updateControllerState() {
|
||||
rightTriggerValue = Controller.getTriggerValue(rightTriggerButton);
|
||||
leftTriggerValue = Controller.getTriggerValue(leftTriggerButton);
|
||||
rightTriggerValue = Controller.getActionValue(rightHandClick);
|
||||
leftTriggerValue = Controller.getActionValue(leftHandClick);
|
||||
|
||||
if (rightTriggerValue > TRIGGER_THRESHOLD && !swordHeld) {
|
||||
grabSword("right")
|
||||
|
@ -470,4 +474,4 @@ function onClick(event) {
|
|||
|
||||
Script.scriptEnding.connect(cleanUp);
|
||||
Script.update.connect(update);
|
||||
Controller.mousePressEvent.connect(onClick);
|
||||
Controller.mousePressEvent.connect(onClick);
|
||||
|
|
225
examples/example/painting/hydraPaint.js
Normal file
225
examples/example/painting/hydraPaint.js
Normal file
|
@ -0,0 +1,225 @@
|
|||
//
|
||||
// hydraPaint.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 5/14/15.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This script allows you to paint with the hydra!
|
||||
//
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
var LEFT = 0;
|
||||
var RIGHT = 1;
|
||||
var LASER_WIDTH = 3;
|
||||
var LASER_COLOR = {
|
||||
red: 50,
|
||||
green: 150,
|
||||
blue: 200
|
||||
};
|
||||
var TRIGGER_THRESHOLD = .1;
|
||||
|
||||
var MAX_POINTS_PER_LINE = 40;
|
||||
|
||||
var LIFETIME = 6000;
|
||||
var DRAWING_DEPTH = 1;
|
||||
var LINE_DIMENSIONS = 20;
|
||||
|
||||
|
||||
var MIN_POINT_DISTANCE = 0.01;
|
||||
|
||||
var MIN_BRUSH_RADIUS = 0.08;
|
||||
var MAX_BRUSH_RADIUS = 0.1;
|
||||
|
||||
var RIGHT_BUTTON_1 = 7
|
||||
var RIGHT_BUTTON_2 = 8
|
||||
var RIGHT_BUTTON_3 = 9;
|
||||
var RIGHT_BUTTON_4 = 10
|
||||
var LEFT_BUTTON_1 = 1;
|
||||
var LEFT_BUTTON_2 = 2;
|
||||
var LEFT_BUTTON_3 = 3;
|
||||
var LEFT_BUTTON_4 = 4;
|
||||
|
||||
var colorPalette = [{
|
||||
red: 250,
|
||||
green: 0,
|
||||
blue: 0
|
||||
}, {
|
||||
red: 214,
|
||||
green: 91,
|
||||
blue: 67
|
||||
}, {
|
||||
red: 192,
|
||||
green: 41,
|
||||
blue: 66
|
||||
}, {
|
||||
red: 84,
|
||||
green: 36,
|
||||
blue: 55
|
||||
}, {
|
||||
red: 83,
|
||||
green: 119,
|
||||
blue: 122
|
||||
}];
|
||||
|
||||
var MIN_STROKE_WIDTH = 0.002;
|
||||
var MAX_STROKE_WIDTH = 0.05;
|
||||
|
||||
function controller(side, cycleColorButton) {
|
||||
this.triggerHeld = false;
|
||||
this.triggerThreshold = 0.9;
|
||||
this.side = side;
|
||||
this.palm = 2 * side;
|
||||
this.tip = 2 * side + 1;
|
||||
this.trigger = side;
|
||||
this.cycleColorButton = cycleColorButton;
|
||||
|
||||
this.points = [];
|
||||
this.normals = [];
|
||||
this.strokeWidths = [];
|
||||
|
||||
this.currentColorIndex = 0;
|
||||
this.currentColor = colorPalette[this.currentColorIndex];
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
this.brush = Entities.addEntity({
|
||||
type: 'Sphere',
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: MIN_BRUSH_RADIUS,
|
||||
y: MIN_BRUSH_RADIUS,
|
||||
z: MIN_BRUSH_RADIUS
|
||||
}
|
||||
});
|
||||
|
||||
this.cycleColor = function() {
|
||||
this.currentColor = colorPalette[++this.currentColorIndex];
|
||||
if (this.currentColorIndex === colorPalette.length - 1) {
|
||||
this.currentColorIndex = -1;
|
||||
}
|
||||
}
|
||||
this.newLine = function(position) {
|
||||
this.linePosition = position;
|
||||
this.line = Entities.addEntity({
|
||||
position: position,
|
||||
type: "PolyLine",
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: LINE_DIMENSIONS,
|
||||
y: LINE_DIMENSIONS,
|
||||
z: LINE_DIMENSIONS
|
||||
},
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
this.points = [];
|
||||
this.normals = []
|
||||
this.strokeWidths = [];
|
||||
}
|
||||
|
||||
this.update = function(deltaTime) {
|
||||
this.updateControllerState();
|
||||
var newBrushPosOffset = Vec3.multiply(Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)), DRAWING_DEPTH);
|
||||
var newBrushPos = Vec3.sum(this.palmPosition, newBrushPosOffset);
|
||||
var brushRadius = map(this.triggerValue, TRIGGER_THRESHOLD, 1, MIN_BRUSH_RADIUS, MAX_BRUSH_RADIUS)
|
||||
Entities.editEntity(this.brush, {
|
||||
position: newBrushPos,
|
||||
color: this.currentColor,
|
||||
dimensions: {
|
||||
x: brushRadius,
|
||||
y: brushRadius,
|
||||
z: brushRadius
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (this.triggerValue > TRIGGER_THRESHOLD && !this.drawing) {
|
||||
this.newLine(newBrushPos);
|
||||
this.drawing = true;
|
||||
} else if (this.drawing && this.triggerValue < TRIGGER_THRESHOLD) {
|
||||
this.drawing = false;
|
||||
}
|
||||
|
||||
if (this.drawing && this.points.length < MAX_POINTS_PER_LINE) {
|
||||
var localPoint = Vec3.subtract(newBrushPos, this.linePosition);
|
||||
if (Vec3.distance(localPoint, this.points[this.points.length - 1]) < MIN_POINT_DISTANCE) {
|
||||
//Need a minimum distance to avoid binormal NANs
|
||||
return;
|
||||
}
|
||||
|
||||
this.points.push(localPoint);
|
||||
var normal = computeNormal(newBrushPos, Camera.getPosition());
|
||||
|
||||
this.normals.push(normal);
|
||||
var strokeWidth = map(this.triggerValue, TRIGGER_THRESHOLD, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH);
|
||||
this.strokeWidths.push(strokeWidth);
|
||||
Entities.editEntity(this.line, {
|
||||
linePoints: this.points,
|
||||
normals: this.normals,
|
||||
strokeWidths: this.strokeWidths,
|
||||
color: this.currentColor
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.updateControllerState = function() {
|
||||
this.cycleColorButtonPressed = Controller.isButtonPressed(this.cycleColorButton);
|
||||
this.palmPosition = Controller.getSpatialControlPosition(this.palm);
|
||||
this.tipPosition = Controller.getSpatialControlPosition(this.tip);
|
||||
this.palmNormal = Controller.getSpatialControlNormal(this.palm);
|
||||
this.triggerValue = Controller.getTriggerValue(this.trigger);
|
||||
|
||||
|
||||
if (this.prevCycleColorButtonPressed === true && this.cycleColorButtonPressed === false) {
|
||||
this.cycleColor();
|
||||
Entities.editEntity(this.brush, {
|
||||
// color: this.currentColor
|
||||
});
|
||||
}
|
||||
|
||||
this.prevCycleColorButtonPressed = this.cycleColorButtonPressed;
|
||||
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
Entities.deleteEntity(self.brush);
|
||||
}
|
||||
}
|
||||
|
||||
function computeNormal(p1, p2) {
|
||||
return Vec3.normalize(Vec3.subtract(p2, p1));
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
leftController.update(deltaTime);
|
||||
rightController.update(deltaTime);
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
leftController.cleanup();
|
||||
rightController.cleanup();
|
||||
}
|
||||
|
||||
function vectorIsZero(v) {
|
||||
return v.x === 0 && v.y === 0 && v.z === 0;
|
||||
}
|
||||
|
||||
|
||||
var rightController = new controller(RIGHT, RIGHT_BUTTON_4);
|
||||
var leftController = new controller(LEFT, LEFT_BUTTON_4);
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
function map(value, min1, max1, min2, max2) {
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
}
|
194
examples/example/painting/mousePaint.js
Normal file
194
examples/example/painting/mousePaint.js
Normal file
|
@ -0,0 +1,194 @@
|
|||
//
|
||||
// mousePaint.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 6/4/15.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This script allows you to paint with the hydra or mouse!
|
||||
//
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var LINE_DIMENSIONS = 10;
|
||||
var LIFETIME = 6000;
|
||||
var EVENT_CHANGE_THRESHOLD = 200;
|
||||
var LINE_WIDTH = .07;
|
||||
var MAX_POINTS_PER_LINE = 40;
|
||||
var points = [];
|
||||
var normals = [];
|
||||
var deletedLines = [];
|
||||
var strokeWidths = [];
|
||||
var count = 0;
|
||||
var prevEvent = {x: 0, y: 0};
|
||||
var eventChange;
|
||||
|
||||
var MIN_POINT_DISTANCE = .01;
|
||||
|
||||
var colorPalette = [{
|
||||
red: 250,
|
||||
green: 0,
|
||||
blue: 0
|
||||
}, {
|
||||
red: 214,
|
||||
green: 91,
|
||||
blue: 67
|
||||
}, {
|
||||
red: 192,
|
||||
green: 41,
|
||||
blue: 66
|
||||
}, {
|
||||
red: 84,
|
||||
green: 36,
|
||||
blue: 55
|
||||
}, {
|
||||
red: 83,
|
||||
green: 119,
|
||||
blue: 122
|
||||
}];
|
||||
|
||||
var currentColorIndex = 0;
|
||||
var currentColor = colorPalette[currentColorIndex];
|
||||
|
||||
function cycleColor() {
|
||||
currentColor = colorPalette[++currentColorIndex];
|
||||
if (currentColorIndex === colorPalette.length - 1) {
|
||||
currentColorIndex = -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MousePaint();
|
||||
|
||||
function MousePaint() {
|
||||
var DRAWING_DISTANCE = 5;
|
||||
var lines = [];
|
||||
var isDrawing = false;
|
||||
|
||||
var line, linePosition;
|
||||
|
||||
var BRUSH_SIZE = .05;
|
||||
|
||||
var brush = Entities.addEntity({
|
||||
type: 'Sphere',
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
color: currentColor,
|
||||
dimensions: {
|
||||
x: BRUSH_SIZE,
|
||||
y: BRUSH_SIZE,
|
||||
z: BRUSH_SIZE
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function newLine(position) {
|
||||
linePosition = position;
|
||||
line = Entities.addEntity({
|
||||
position: position,
|
||||
type: "PolyLine",
|
||||
color: currentColor,
|
||||
dimensions: {
|
||||
x: LINE_DIMENSIONS,
|
||||
y: LINE_DIMENSIONS,
|
||||
z: LINE_DIMENSIONS
|
||||
},
|
||||
linePoints: [],
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
points = [];
|
||||
normals = []
|
||||
strokeWidths = [];
|
||||
lines.push(line);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
count++;
|
||||
var worldPoint = computeWorldPoint(pickRay);
|
||||
Entities.editEntity(brush, {
|
||||
position: worldPoint
|
||||
});
|
||||
|
||||
eventChange = Math.sqrt(Math.pow(event.x - prevEvent.x, 2) + Math.pow(event.y - prevEvent.y, 2));
|
||||
localPoint = computeLocalPoint(worldPoint);
|
||||
if (!isDrawing || points.length > MAX_POINTS_PER_LINE || eventChange > EVENT_CHANGE_THRESHOLD ||
|
||||
Vec3.distance(points[points.length - 1], localPoint) < MIN_POINT_DISTANCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
points.push(localPoint)
|
||||
normals.push(computeNormal(worldPoint, pickRay.origin));
|
||||
strokeWidths.push(LINE_WIDTH);
|
||||
Entities.editEntity(line, {
|
||||
strokeWidths: strokeWidths,
|
||||
linePoints: points,
|
||||
normals: normals,
|
||||
});
|
||||
prevEvent = event;
|
||||
}
|
||||
|
||||
function computeNormal(p1, p2) {
|
||||
return Vec3.normalize(Vec3.subtract(p2, p1));
|
||||
}
|
||||
|
||||
function computeWorldPoint(pickRay) {
|
||||
var addVector = Vec3.multiply(Vec3.normalize(pickRay.direction), DRAWING_DISTANCE);
|
||||
return Vec3.sum(pickRay.origin, addVector);
|
||||
}
|
||||
|
||||
function computeLocalPoint(worldPoint) {
|
||||
var localPoint = Vec3.subtract(worldPoint, linePosition);
|
||||
return localPoint;
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if (!event.isLeftButton) {
|
||||
isDrawing = false;
|
||||
return;
|
||||
}
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
prevEvent = {x: event.x, y:event.y};
|
||||
var worldPoint = computeWorldPoint(pickRay);
|
||||
newLine(worldPoint);
|
||||
var localPoint = computeLocalPoint(worldPoint);
|
||||
points.push(localPoint);
|
||||
normals.push(computeNormal(worldPoint, pickRay.origin));
|
||||
strokeWidths.push(0.07);
|
||||
isDrawing = true;
|
||||
}
|
||||
|
||||
function mouseReleaseEvent() {
|
||||
isDrawing = false;
|
||||
}
|
||||
|
||||
function keyPressEvent(event) {
|
||||
if (event.text === "SPACE") {
|
||||
cycleColor();
|
||||
Entities.editEntity(brush, {
|
||||
color: currentColor
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
lines.forEach(function(line) {
|
||||
// Entities.deleteEntity(line);
|
||||
});
|
||||
Entities.deleteEntity(brush);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
}
|
515
examples/example/planets-ui.js
Normal file
515
examples/example/planets-ui.js
Normal file
|
@ -0,0 +1,515 @@
|
|||
//
|
||||
// widgets-example.js
|
||||
// games
|
||||
//
|
||||
// Copyright 2015 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
|
||||
//
|
||||
var ICONS_URL = 'https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Scripts/planets/images/';
|
||||
|
||||
var panelX = 1250;
|
||||
var panelY = 500;
|
||||
var panelWidth = 50;
|
||||
var panelHeight = 210;
|
||||
|
||||
Script.include('../libraries/uiwidgets.js');
|
||||
|
||||
UI.setDefaultVisibility(true);
|
||||
|
||||
var ICON_WIDTH = 40.0;
|
||||
var ICON_HEIGHT = 40.0;
|
||||
var ICON_COLOR = UI.rgba(45, 45, 45, 0.7);
|
||||
var FOCUSED_COLOR = UI.rgba(250, 250, 250, 1.0);
|
||||
|
||||
var PANEL_BACKGROUND_COLOR = UI.rgba(120, 120, 120, 0.8);
|
||||
|
||||
var PANEL_PADDING = 7.0;
|
||||
var PANEL_BORDER = 12.0;
|
||||
var SUBPANEL_GAP = 1.0;
|
||||
|
||||
var icons = [];
|
||||
|
||||
function addImage(panel, iconId) {
|
||||
var icon = panel.add(new UI.Image({
|
||||
'imageURL': ICONS_URL + iconId + '.svg',
|
||||
'width': ICON_WIDTH,
|
||||
'height': ICON_HEIGHT,
|
||||
'color': ICON_COLOR,
|
||||
'alpha': ICON_COLOR.a
|
||||
}));
|
||||
icons.push(icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
var panels = [];
|
||||
|
||||
function addPanel(properties) {
|
||||
properties.background = properties.background || {};
|
||||
properties.background.backgroundColor = properties.background.backgroundColor ||
|
||||
PANEL_BACKGROUND_COLOR;
|
||||
properties.background.backgroundAlpha = properties.background.backgroundAlpha ||
|
||||
PANEL_BACKGROUND_COLOR.a;
|
||||
properties.padding = properties.padding || {
|
||||
x: PANEL_PADDING,
|
||||
y: PANEL_PADDING
|
||||
};
|
||||
properties.border = properties.border || {
|
||||
x: PANEL_BORDER,
|
||||
y: PANEL_BORDER
|
||||
};
|
||||
|
||||
var panel = new UI.WidgetStack(properties);
|
||||
panels.push(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
function makeDraggable(panel, target) {
|
||||
if (!target) {
|
||||
target = panel;
|
||||
}
|
||||
var dragStart = null;
|
||||
var initialPos = null;
|
||||
|
||||
panel.addAction('onDragBegin', function(event) {
|
||||
dragStart = {
|
||||
x: event.x,
|
||||
y: event.y
|
||||
};
|
||||
initialPos = {
|
||||
x: target.position.x,
|
||||
y: target.position.y
|
||||
};
|
||||
});
|
||||
panel.addAction('onDragUpdate', function(event) {
|
||||
target.setPosition(
|
||||
initialPos.x + event.x - dragStart.x,
|
||||
initialPos.y + event.y - dragStart.y
|
||||
);
|
||||
UI.updateLayout();
|
||||
});
|
||||
panel.addAction('onDragEnd', function() {
|
||||
dragStart = dragEnd = null;
|
||||
});
|
||||
}
|
||||
|
||||
function setText(text) {
|
||||
return function() {
|
||||
demoLabel.setText(text);
|
||||
UI.updateLayout();
|
||||
};
|
||||
}
|
||||
|
||||
function join(obj) {
|
||||
var s = "{";
|
||||
var sep = "\n";
|
||||
for (var k in obj) {
|
||||
s += sep + k + ": " + ("" + obj[k]).replace("\n", "\n");
|
||||
sep = ",\n";
|
||||
}
|
||||
if (s.length > 1)
|
||||
return s + " }";
|
||||
return s + "}";
|
||||
}
|
||||
|
||||
setText = undefined;
|
||||
|
||||
var tooltipWidget = new UI.Label({
|
||||
text: "<tooltip>",
|
||||
width: 500,
|
||||
height: 20,
|
||||
visible: false
|
||||
});
|
||||
|
||||
function addTooltip(widget, text) {
|
||||
widget.addAction('onMouseOver', function(event, widget) {
|
||||
tooltipWidget.setVisible(true);
|
||||
tooltipWidget.setPosition(widget.position.x + widget.getWidth() + 20, widget.position.y + 10);
|
||||
tooltipWidget.setText(text);
|
||||
UI.updateLayout();
|
||||
});
|
||||
widget.addAction('onMouseExit', function() {
|
||||
tooltipWidget.setVisible(false);
|
||||
UI.updateLayout();
|
||||
});
|
||||
}
|
||||
|
||||
var mainPanel = addPanel({
|
||||
dir: '+y'
|
||||
});
|
||||
makeDraggable(mainPanel);
|
||||
mainPanel.setPosition(1200, 250);
|
||||
mainPanel.setVisible(true);
|
||||
|
||||
var systemViewButton = addImage(mainPanel, 'solarsystems');
|
||||
var zoomButton = addImage(mainPanel, 'magnifier');
|
||||
var satelliteButton = addImage(mainPanel, 'satellite');
|
||||
var settingsButton = addImage(mainPanel, 'settings');
|
||||
var stopButton = addImage(mainPanel, 'close');
|
||||
|
||||
addTooltip(systemViewButton, "system view");
|
||||
addTooltip(zoomButton, "zoom");
|
||||
addTooltip(satelliteButton, "satelite view");
|
||||
addTooltip(settingsButton, "settings");
|
||||
addTooltip(stopButton, "exit");
|
||||
|
||||
var systemViewPanel = addPanel({
|
||||
dir: '+x',
|
||||
visible: false
|
||||
});
|
||||
var restartButton = addImage(systemViewPanel, 'refresh');
|
||||
var pauseButton = addImage(systemViewPanel, 'playpause');
|
||||
var rideButton = addImage(systemViewPanel, 'rocket');
|
||||
|
||||
var tweening, tweeningPaused;
|
||||
Script.include('https://hifi-staff.s3.amazonaws.com/bridget/tween.js');
|
||||
|
||||
|
||||
pauseButton.addAction('onClick', function() {
|
||||
if (tweening) {
|
||||
if (!tweeningPaused) {
|
||||
tweeningPaused = true;
|
||||
} else {
|
||||
tweeningPaused = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!paused) {
|
||||
pause();
|
||||
} else {
|
||||
resume();
|
||||
}
|
||||
});
|
||||
|
||||
// Allow to toggle pause with spacebar
|
||||
function keyPressEvent(event) {
|
||||
if (event.text == "SPACE") {
|
||||
if (!paused) {
|
||||
pause();
|
||||
} else {
|
||||
resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rideButton.addAction('onClick', function() {
|
||||
if (!paused) {
|
||||
pause();
|
||||
}
|
||||
if (tweening) {
|
||||
tweening = false;
|
||||
tweeningPaused = true;
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
var confirmed = Window.confirm('Ride through the solar system?');
|
||||
if (confirmed) {
|
||||
init();
|
||||
tweening = true;
|
||||
tweeningPaused = false;
|
||||
}
|
||||
});
|
||||
|
||||
restartButton.addAction('onClick', function() {
|
||||
restart();
|
||||
tweening = false;
|
||||
});
|
||||
|
||||
var zoomPanel = addPanel({
|
||||
dir: '+x',
|
||||
visible: false
|
||||
});
|
||||
var zoomButtons = [];
|
||||
for (var i = 0; i < planets.length; ++i) {
|
||||
var label = zoomPanel.add(new UI.Label({
|
||||
text: planets[i].name,
|
||||
width: 80,
|
||||
height: 20
|
||||
}));
|
||||
zoomButtons.push(label);
|
||||
UI.updateLayout();
|
||||
}
|
||||
UI.updateLayout();
|
||||
|
||||
|
||||
var zoomView = false;
|
||||
zoomButtons.forEach(function(button, i) {
|
||||
var planet = planets[i];
|
||||
button.addAction('onClick', function() {
|
||||
if (!planets[i].isZoomed) {
|
||||
planet.zoom();
|
||||
planet.isZoomed = true;
|
||||
zoomView = true;
|
||||
} else {
|
||||
MyAvatar.position = startingPosition;
|
||||
Camera.setPosition(cameraStart);
|
||||
planet.isZoomed = false;
|
||||
zoomView = false;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var settingsPanel = addPanel({
|
||||
dir: '+y',
|
||||
visible: false
|
||||
});
|
||||
|
||||
function addCheckbox(parent, label, labelWidth, enabled, onValueChanged) {
|
||||
var layout = parent.add(new UI.WidgetStack({
|
||||
dir: '+x',
|
||||
visible: true,
|
||||
backgroundAlpha: 0.0
|
||||
}));
|
||||
var label = layout.add(new UI.Label({
|
||||
text: label,
|
||||
width: labelWidth,
|
||||
height: 20,
|
||||
backgroundAlpha: 0.0
|
||||
}));
|
||||
|
||||
var defaultColor = UI.rgb(10, 10, 10);
|
||||
|
||||
var checkbox = layout.add(new UI.Checkbox({
|
||||
width: 20,
|
||||
height: 20,
|
||||
padding: {
|
||||
x: 3,
|
||||
y: 3
|
||||
},
|
||||
backgroundColor: defaultColor,
|
||||
backgroundAlpha: 0.9,
|
||||
checked: enabled,
|
||||
onValueChanged: onValueChanged
|
||||
}));
|
||||
|
||||
checkbox.label = label;
|
||||
checkbox.layout = layout;
|
||||
checkbox.setValue = function(value) {
|
||||
checkbox.setChecked(value);
|
||||
}
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
function addSlider(parent, label, labelWidth, defaultValue, min, max, valueChanged) {
|
||||
var layout = parent.add(new UI.WidgetStack({
|
||||
dir: '+x',
|
||||
visible: true
|
||||
}));
|
||||
var label = layout.add(new UI.Label({
|
||||
text: label,
|
||||
width: labelWidth,
|
||||
height: 27
|
||||
}));
|
||||
var display = layout.add(new UI.Label({
|
||||
text: " ",
|
||||
width: 50,
|
||||
height: 27
|
||||
}));
|
||||
var slider = layout.add(new UI.Slider({
|
||||
value: defaultValue,
|
||||
maxValue: max,
|
||||
minValue: min,
|
||||
width: 300,
|
||||
height: 20,
|
||||
backgroundColor: UI.rgb(10, 10, 10),
|
||||
backgroundAlpha: 1.0,
|
||||
slider: { // slider knob
|
||||
width: 30,
|
||||
height: 18,
|
||||
backgroundColor: UI.rgb(120, 120, 120),
|
||||
backgroundAlpha: 1.0
|
||||
}
|
||||
}));
|
||||
slider.addAction('onDoubleClick', function() {
|
||||
slider.setValue(defaultValue);
|
||||
UI.updateLayout();
|
||||
});
|
||||
display.setText("" + (+slider.getValue().toFixed(2)));
|
||||
slider.onValueChanged = function(value) {
|
||||
valueChanged(value);
|
||||
display.setText("" + (+value.toFixed(2)));
|
||||
UI.updateLayout();
|
||||
}
|
||||
slider.label = label;
|
||||
slider.layout = layout;
|
||||
return slider;
|
||||
}
|
||||
|
||||
settingsPanel.showTrailsButton = addCheckbox(settingsPanel, "show trails", 120, trailsEnabled, function(value) {
|
||||
trailsEnabled = value;
|
||||
if (trailsEnabled) {
|
||||
for (var i = 0; i < planets.length; ++i) {
|
||||
planets[i].resetTrails();
|
||||
}
|
||||
//if trails are off and we've already created trails, remove existing trails
|
||||
} else {
|
||||
for (var i = 0; i < planets.length; ++i) {
|
||||
planets[i].clearTrails();
|
||||
}
|
||||
}
|
||||
});
|
||||
var g_multiplier = 1.0;
|
||||
settingsPanel.gravitySlider = addSlider(settingsPanel, "gravity scale ", 200, g_multiplier, 0.0, 5.0, function(value) {
|
||||
g_multiplier = value;
|
||||
GRAVITY = REFERENCE_GRAVITY * g_multiplier;
|
||||
});
|
||||
|
||||
var period_multiplier = 1.0;
|
||||
var last_alpha = period_multiplier;
|
||||
|
||||
settingsPanel.periodSlider = addSlider(settingsPanel, "orbital period scale ", 200, period_multiplier, 0.0, 3.0, function(value) {
|
||||
period_multiplier = value;
|
||||
changePeriod(period_multiplier);
|
||||
});
|
||||
|
||||
function changePeriod(alpha) {
|
||||
var ratio = last_alpha / alpha;
|
||||
GRAVITY = Math.pow(ratio, 2.0) * GRAVITY;
|
||||
for (var i = 0; i < planets.length; ++i) {
|
||||
planets[i].period = ratio * planets[i].period;
|
||||
planets[i].velocity = Vec3.multiply(ratio, planets[i].velocity);
|
||||
planets[i].resetTrails();
|
||||
}
|
||||
last_alpha = alpha;
|
||||
}
|
||||
|
||||
var satelliteGame;
|
||||
satelliteButton.addAction('onClick', function() {
|
||||
if (satelliteGame && satelliteGame.isActive) {
|
||||
MyAvatar.position = startingPosition;
|
||||
satelliteGame.quitGame();
|
||||
if (paused) {
|
||||
resume();
|
||||
}
|
||||
} else {
|
||||
pause();
|
||||
satelliteGame = new SatelliteCreator();
|
||||
satelliteGame.init();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var subpanels = [systemViewPanel, zoomPanel, settingsPanel];
|
||||
|
||||
function hideSubpanelsExcept(panel) {
|
||||
subpanels.forEach(function(x) {
|
||||
if (x != panel) {
|
||||
x.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function attachPanel(panel, button) {
|
||||
button.addAction('onClick', function() {
|
||||
hideSubpanelsExcept(panel);
|
||||
panel.setVisible(!panel.isVisible());
|
||||
UI.updateLayout();
|
||||
})
|
||||
|
||||
UI.addAttachment(panel, button, function(target, rel) {
|
||||
target.setPosition(
|
||||
rel.position.x - (target.getWidth() + target.border.x + SUBPANEL_GAP),
|
||||
rel.position.y - target.border.y
|
||||
);
|
||||
});
|
||||
}
|
||||
attachPanel(systemViewPanel, systemViewButton);
|
||||
attachPanel(zoomPanel, zoomButton);
|
||||
attachPanel(settingsPanel, settingsButton);
|
||||
|
||||
|
||||
var addColorToggle = function(widget) {
|
||||
widget.addAction('onMouseOver', function() {
|
||||
widget.setColor(FOCUSED_COLOR);
|
||||
});
|
||||
widget.addAction('onMouseExit', function() {
|
||||
widget.setColor(ICON_COLOR);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
systemViewPanel.addAction('onMouseOver', function() {
|
||||
hideSubpanelsExcept(systemViewPanel);
|
||||
UI.updateLayout();
|
||||
});
|
||||
|
||||
|
||||
zoomButton.addAction('onClick', function() {
|
||||
if (zoomView) {
|
||||
restart();
|
||||
}
|
||||
hideSubpanelsExcept(zoomPanel);
|
||||
UI.updateLayout();
|
||||
});
|
||||
UI.updateLayout();
|
||||
|
||||
stopButton.addAction('onClick', function() {
|
||||
teardown();
|
||||
Script.stop();
|
||||
});
|
||||
|
||||
// Panel drag behavior
|
||||
// (click + drag on border to drag)
|
||||
(function() {
|
||||
var dragged = null;
|
||||
this.startDrag = function(dragAction) {
|
||||
dragged = dragAction;
|
||||
}
|
||||
this.updateDrag = function(event) {
|
||||
if (dragged) {
|
||||
print("Update drag");
|
||||
dragged.updateDrag(event);
|
||||
}
|
||||
}
|
||||
this.clearDrag = function(event) {
|
||||
if (dragged)
|
||||
print("End drag");
|
||||
dragged = null;
|
||||
}
|
||||
})();
|
||||
|
||||
var buttons = icons;
|
||||
|
||||
buttons.map(addColorToggle);
|
||||
panels.map(function(panel) {
|
||||
makeDraggable(panel, mainPanel);
|
||||
});
|
||||
|
||||
// Cleanup script resources
|
||||
function teardown() {
|
||||
UI.teardown();
|
||||
if (satelliteGame) {
|
||||
satelliteGame.quitGame();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
UI.debug.setVisible(false);
|
||||
|
||||
var inputHandler = {
|
||||
onMouseMove: function(event) {
|
||||
updateDrag(event);
|
||||
UI.handleMouseMove(event);
|
||||
},
|
||||
onMousePress: function(event) {
|
||||
UI.handleMousePress(event);
|
||||
},
|
||||
onMouseRelease: function(event) {
|
||||
clearDrag(event);
|
||||
UI.handleMouseRelease(event);
|
||||
},
|
||||
onMouseDoublePress: function(event) {
|
||||
UI.handleMouseDoublePress(event);
|
||||
}
|
||||
};
|
||||
Controller.mousePressEvent.connect(inputHandler.onMousePress);
|
||||
Controller.mouseMoveEvent.connect(inputHandler.onMouseMove);
|
||||
Controller.mouseReleaseEvent.connect(inputHandler.onMouseRelease);
|
||||
Controller.mouseDoublePressEvent.connect(inputHandler.onMouseDoublePress);
|
||||
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
|
||||
Script.scriptEnding.connect(teardown);
|
File diff suppressed because it is too large
Load diff
439
examples/example/widgets-example.js
Normal file
439
examples/example/widgets-example.js
Normal file
|
@ -0,0 +1,439 @@
|
|||
//
|
||||
// widgets-example.js
|
||||
// games
|
||||
//
|
||||
// Copyright 2015 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
|
||||
//
|
||||
|
||||
var paddingX = 8;
|
||||
var paddingY = 8;
|
||||
var buttonWidth = 30;
|
||||
var buttonHeight = 30;
|
||||
|
||||
var ICONS_URL = 'https://s3.amazonaws.com/hifi-public/marketplace/hificontent/Scripts/planets/images/';
|
||||
|
||||
var panelX = 1250;
|
||||
var panelY = 500;
|
||||
var panelWidth = 50;
|
||||
var panelHeight = 210;
|
||||
|
||||
// var mainPanel = new UIPanel(panelX, panelY, panelWidth, panelHeight);
|
||||
// var systemViewButton = mainPanel.addImage('solarsystems');
|
||||
// var zoomButton = mainPanel.addImage('magnifier');
|
||||
// var satelliteButton = mainPanel.addImage('satellite');
|
||||
// var settingsButton = mainPanel.addImage('settings');
|
||||
// var stopButton = mainPanel.addImage('close');
|
||||
//
|
||||
// mainPanel.show();
|
||||
//
|
||||
// var systemViewPanel = new UIPanel(panelX - 120, panelY, 120, 40);
|
||||
// var reverseButton = systemViewPanel.addImage('reverse');
|
||||
// var pauseButton = systemViewPanel.addImage('playpause');
|
||||
// var forwardButton = systemViewPanel.addImage('forward');
|
||||
//
|
||||
// var zoomPanel = new UIPanel(panelX - 60, panelY + buttonHeight + paddingY, 650, 50);
|
||||
// for (var i = 0; i < planets.length; ++i) {
|
||||
// zoomPanel.addText(planets[i].name);
|
||||
// }
|
||||
Script.include('../libraries/uiwidgets.js');
|
||||
|
||||
UI.setDefaultVisibility(true);
|
||||
UI.setErrorHandler(function(err) {
|
||||
teardown();
|
||||
// print(err);
|
||||
// Script.stop();
|
||||
});
|
||||
|
||||
// Controller.mouseMoveEvent.connect(function panelMouseMoveEvent(event) { return settings.mouseMoveEvent(event); });
|
||||
// Controller.mousePressEvent.connect( function panelMousePressEvent(event) { return settings.mousePressEvent(event); });
|
||||
// Controller.mouseDoublePressEvent.connect( function panelMouseDoublePressEvent(event) { return settings.mouseDoublePressEvent(event); });
|
||||
// Controller.mouseReleaseEvent.connect(function(event) { return settings.mouseReleaseEvent(event); });
|
||||
// Controller.keyPressEvent.connect(function(event) { return settings.keyPressEvent(event); });
|
||||
|
||||
// var ICON_WIDTH = 50.0;
|
||||
// var ICON_HEIGHT = 50.0;
|
||||
var ICON_WIDTH = 40.0;
|
||||
var ICON_HEIGHT = 40.0;
|
||||
var ICON_COLOR = UI.rgba(45, 45, 45, 0.7);
|
||||
var FOCUSED_COLOR = UI.rgba(250, 250, 250, 1.0);
|
||||
|
||||
var PANEL_BACKGROUND_COLOR = UI.rgba(50, 50, 50, 0.7);
|
||||
|
||||
var PANEL_PADDING = 7.0;
|
||||
var PANEL_BORDER = 12.0;
|
||||
var SUBPANEL_GAP = 1.0;
|
||||
|
||||
var icons = [];
|
||||
function addImage(panel, iconId) {
|
||||
var icon = panel.add(new UI.Image({
|
||||
'imageURL': ICONS_URL + iconId + '.svg',
|
||||
'width': ICON_WIDTH,
|
||||
'height': ICON_HEIGHT,
|
||||
'color': ICON_COLOR,
|
||||
'alpha': ICON_COLOR.a
|
||||
}));
|
||||
icons.push(icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
var panels = [];
|
||||
function addPanel (properties) {
|
||||
properties.background = properties.background || {};
|
||||
properties.background.backgroundColor = properties.background.backgroundColor ||
|
||||
PANEL_BACKGROUND_COLOR;
|
||||
properties.background.backgroundAlpha = properties.background.backgroundAlpha ||
|
||||
PANEL_BACKGROUND_COLOR.a;
|
||||
properties.padding = properties.padding || { x: PANEL_PADDING, y: PANEL_PADDING };
|
||||
properties.border = properties.border || { x: PANEL_BORDER, y: PANEL_BORDER };
|
||||
|
||||
var panel = new UI.WidgetStack(properties);
|
||||
panels.push(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
function makeDraggable (panel, target) {
|
||||
if (!target)
|
||||
target = panel;
|
||||
|
||||
var dragStart = null;
|
||||
var initialPos = null;
|
||||
|
||||
panel.addAction('onDragBegin', function (event) {
|
||||
dragStart = { x: event.x, y: event.y };
|
||||
initialPos = { x: target.position.x, y: target.position.y };
|
||||
});
|
||||
panel.addAction('onDragUpdate', function (event) {
|
||||
target.setPosition(
|
||||
initialPos.x + event.x - dragStart.x,
|
||||
initialPos.y + event.y - dragStart.y
|
||||
);
|
||||
UI.updateLayout();
|
||||
});
|
||||
panel.addAction('onDragEnd', function () {
|
||||
dragStart = dragEnd = null;
|
||||
});
|
||||
}
|
||||
|
||||
// var panelContainer = new UI.WidgetContainer();
|
||||
// panelContainer.setPosition(500, 250);
|
||||
// panelContainer.setVisible(true);
|
||||
|
||||
var demoPane = addPanel({ dir: '+y' });
|
||||
var demoLabel = demoPane.add(new UI.Label({
|
||||
text: "< no events >",
|
||||
width: 400, height: 20
|
||||
}));
|
||||
var demoButton = demoPane.add(new UI.Box({
|
||||
width: 200, height: 80,
|
||||
text: "Button"
|
||||
}));
|
||||
function setText(text) {
|
||||
return function () {
|
||||
demoLabel.setText(text);
|
||||
UI.updateLayout();
|
||||
};
|
||||
}
|
||||
function addDebugActions(widget, msg, actions) {
|
||||
actions.forEach(function(action) {
|
||||
widget.addAction(action, setText(action + " " + msg + widget));
|
||||
});
|
||||
}
|
||||
|
||||
var debugEvents = [
|
||||
'onMouseOver',
|
||||
'onMouseExit',
|
||||
'onMouseDown',
|
||||
'onMouseUp',
|
||||
'onDragBegin',
|
||||
'onDragEnd',
|
||||
'onDragUpdate'
|
||||
];
|
||||
addDebugActions(demoPane, "(container) ", debugEvents);
|
||||
addDebugActions(demoButton, "(button) ", debugEvents);
|
||||
addDebugActions(demoLabel, "(label) ", debugEvents);
|
||||
|
||||
// demoPane.addAction('onMouseOver', setText("onMouseOver " + demoPane));
|
||||
// demoPane.addAction('onMouseExit', setText("onMouseExit " + demoPane));
|
||||
// demoPane.addAction('onMouseDown', setText("onMouseDown " + demoPane));
|
||||
// demoPane.addAction('onMouseUp', setText("onMouseUp " + demoPane));
|
||||
makeDraggable(demoPane, demoPane);
|
||||
demoPane.setPosition(600, 200);
|
||||
|
||||
// demoButton.addAction('onMouseOver', setText("onMouseOver " + demoButton));
|
||||
// demoButton.addAction('onMouseExit', setText("onMouseExit " + demoButton));
|
||||
// demoButton.addAction()
|
||||
|
||||
// var resizablePanel = new UI.Label({
|
||||
// text: "Resizable panel",
|
||||
// width: 200, height: 200,
|
||||
// backgroundAlpha: 0.5
|
||||
// });
|
||||
// resizablePanel.setPosition(1100, 200);
|
||||
|
||||
var debugToggle = new UI.Box({
|
||||
text: "debug", width: 150, height: 20
|
||||
});
|
||||
debugToggle.setPosition(200, 0);
|
||||
debugToggle.addAction('onClick', function () {
|
||||
UI.debug.setVisible(!UI.debug.isVisible());
|
||||
});
|
||||
|
||||
// debugEvents.forEach(function (action) {
|
||||
// resizablePanel.addAction(action, function (event, widget) {
|
||||
// widget.setText(action + " " + widget);
|
||||
// });
|
||||
// })
|
||||
|
||||
function join(obj) {
|
||||
var s = "{";
|
||||
var sep = "\n";
|
||||
for (var k in obj) {
|
||||
s += sep + k + ": " + (""+obj[k]).replace("\n", "\n");
|
||||
sep = ",\n";
|
||||
}
|
||||
if (s.length > 1)
|
||||
return s + " }";
|
||||
return s + "}";
|
||||
}
|
||||
|
||||
// resizablePanel.getOverlay().update({
|
||||
// text: "" + join(resizablePanel.actions)
|
||||
// });
|
||||
|
||||
|
||||
setText = addDebugActions = undefined;
|
||||
|
||||
|
||||
var tooltipWidget = new UI.Label({
|
||||
text: "<tooltip>",
|
||||
width: 500, height: 20,
|
||||
visible: false
|
||||
});
|
||||
function addTooltip (widget, text) {
|
||||
widget.addAction('onMouseOver', function (event, widget) {
|
||||
tooltipWidget.setVisible(true);
|
||||
tooltipWidget.setPosition(widget.position.x + widget.getWidth() + 20, widget.position.y);
|
||||
tooltipWidget.setText(text);
|
||||
UI.updateLayout();
|
||||
});
|
||||
widget.addAction('onMouseExit', function () {
|
||||
tooltipWidget.setVisible(false);
|
||||
UI.updateLayout();
|
||||
});
|
||||
}
|
||||
|
||||
var mainPanel = addPanel({ dir: '+y' });
|
||||
mainPanel.setPosition(500, 250);
|
||||
mainPanel.setVisible(true);
|
||||
|
||||
var systemViewButton = addImage(mainPanel, 'solarsystems');
|
||||
var zoomButton = addImage(mainPanel, 'magnifier');
|
||||
var satelliteButton = addImage(mainPanel, 'satellite');
|
||||
var settingsButton = addImage(mainPanel, 'settings');
|
||||
var stopButton = addImage(mainPanel, 'close');
|
||||
|
||||
|
||||
addTooltip(systemViewButton, "system view");
|
||||
addTooltip(zoomButton, "zoom");
|
||||
addTooltip(satelliteButton, "satelite view");
|
||||
addTooltip(settingsButton, "settings");
|
||||
addTooltip(stopButton, "exit");
|
||||
|
||||
var systemViewPanel = addPanel({ dir: '+x', visible: false });
|
||||
var reverseButton = addImage(systemViewPanel, 'reverse');
|
||||
var pauseButton = addImage(systemViewPanel, 'playpause');
|
||||
var forwardButton = addImage(systemViewPanel, 'forward');
|
||||
|
||||
var zoomPanel = addPanel({ dir: '+y', visible: true });
|
||||
var label = new UI.Label({
|
||||
text: "Foo",
|
||||
width: 120,
|
||||
height: 15,
|
||||
color: UI.rgb(245, 290, 20),
|
||||
alpha: 1.0,
|
||||
backgroundColor: UI.rgb(10, 10, 10),
|
||||
backgroundAlpha: 0.0
|
||||
});
|
||||
zoomPanel.add(label);
|
||||
label.addAction('onMouseOver', function () {
|
||||
label.setText("Bar");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.addAction('onMouseExit', function () {
|
||||
label.setText("Foo");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.setText("Label id: " + label.id + ", parent id " + label.parent.id);
|
||||
label.parent.addAction('onMouseOver', function () {
|
||||
label.setText("on parent");
|
||||
UI.updateLayout();
|
||||
});
|
||||
label.parent.addAction('onMouseExit', function () {
|
||||
label.setText('exited parent');
|
||||
UI.updateLayout();
|
||||
});
|
||||
|
||||
var sliderLayout = zoomPanel.add(new UI.WidgetStack({
|
||||
dir: '+x', visible: true, backgroundAlpha: 0.0
|
||||
}));
|
||||
var sliderLabel = sliderLayout.add(new UI.Label({
|
||||
text: " ", width: 45, height: 20
|
||||
}));
|
||||
var slider = sliderLayout.add(new UI.Slider({
|
||||
value: 10, maxValue: 100, minValue: 0,
|
||||
width: 300, height: 20,
|
||||
backgroundColor: UI.rgb(10, 10, 10),
|
||||
backgroundAlpha: 1.0,
|
||||
slider: { // slider knob
|
||||
width: 30,
|
||||
height: 18,
|
||||
backgroundColor: UI.rgb(120, 120, 120),
|
||||
backgroundAlpha: 1.0
|
||||
}
|
||||
}));
|
||||
sliderLabel.setText("" + (+slider.getValue().toFixed(1)));
|
||||
slider.onValueChanged = function (value) {
|
||||
sliderLabel.setText("" + (+value.toFixed(1)));
|
||||
UI.updateLayout();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var checkBoxLayout = zoomPanel.add(new UI.WidgetStack({
|
||||
dir: '+x', visible: true, backgroundAlpha: 0.0
|
||||
}));
|
||||
// var padding = checkBoxLayout.add(new UI.Label({
|
||||
// text: " ", width: 45, height: 20
|
||||
// }));
|
||||
var checkBoxLabel = checkBoxLayout.add(new UI.Label({
|
||||
text: "set red", width: 60, height: 20,
|
||||
backgroundAlpha: 0.0
|
||||
}));
|
||||
checkBoxLabel.setText("set red");
|
||||
|
||||
var defaultColor = UI.rgb(10, 10, 10);
|
||||
var redColor = UI.rgb(210, 80, 80);
|
||||
|
||||
var checkbox = checkBoxLayout.add(new UI.Checkbox({
|
||||
width: 20, height: 20, padding: { x: 3, y: 3 },
|
||||
backgroundColor: defaultColor,
|
||||
backgroundAlpha: 0.9,
|
||||
checked: false,
|
||||
onValueChanged: function (red) {
|
||||
zoomPanel.getOverlay().update({
|
||||
// backgroundAlpha: 0.1,
|
||||
backgroundColor: red ? redColor : defaultColor
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
addImage(zoomPanel, 'reverse');
|
||||
UI.updateLayout();
|
||||
|
||||
var subpanels = [ systemViewPanel, zoomPanel ];
|
||||
function hideSubpanelsExcept (panel) {
|
||||
subpanels.forEach(function (x) {
|
||||
if (x != panel) {
|
||||
x.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function attachPanel (panel, button) {
|
||||
button.addAction('onClick', function () {
|
||||
hideSubpanelsExcept(panel);
|
||||
panel.setVisible(!panel.isVisible());
|
||||
UI.updateLayout();
|
||||
})
|
||||
|
||||
UI.addAttachment(panel, button, function (target, rel) {
|
||||
target.setPosition(
|
||||
rel.position.x - (target.getWidth() + target.border.x + SUBPANEL_GAP),
|
||||
rel.position.y - target.border.y
|
||||
);
|
||||
});
|
||||
}
|
||||
attachPanel(systemViewPanel, systemViewButton);
|
||||
attachPanel(zoomPanel, zoomButton);
|
||||
|
||||
var addColorToggle = function (widget) {
|
||||
widget.addAction('onMouseOver', function () {
|
||||
widget.setColor(FOCUSED_COLOR);
|
||||
});
|
||||
widget.addAction('onMouseExit', function () {
|
||||
widget.setColor(ICON_COLOR);
|
||||
});
|
||||
}
|
||||
|
||||
reverseButton.addAction('onClick', function() {});
|
||||
|
||||
systemViewPanel.addAction('onMouseOver', function() {
|
||||
hideSubpanels();
|
||||
UI.updateLayout();
|
||||
});
|
||||
|
||||
|
||||
zoomButton.addAction('onClick', function() {
|
||||
hideSubpanels();
|
||||
UI.updateLayout();
|
||||
});
|
||||
UI.updateLayout();
|
||||
|
||||
stopButton.addAction('onClick', function() {
|
||||
// Script.stop();
|
||||
teardown();
|
||||
});
|
||||
|
||||
// Panel drag behavior
|
||||
// (click + drag on border to drag)
|
||||
(function () {
|
||||
var dragged = null;
|
||||
this.startDrag = function (dragAction) {
|
||||
dragged = dragAction;
|
||||
}
|
||||
this.updateDrag = function (event) {
|
||||
if (dragged) {
|
||||
print("Update drag");
|
||||
dragged.updateDrag(event);
|
||||
}
|
||||
}
|
||||
this.clearDrag = function (event) {
|
||||
if (dragged)
|
||||
print("End drag");
|
||||
dragged = null;
|
||||
}
|
||||
})();
|
||||
|
||||
var buttons = icons;
|
||||
|
||||
buttons.map(addColorToggle);
|
||||
panels.map(function (panel) { makeDraggable(panel, mainPanel); });
|
||||
|
||||
// Cleanup script resources
|
||||
function teardown() {
|
||||
UI.teardown();
|
||||
|
||||
// etc...
|
||||
};
|
||||
|
||||
var inputHandler = {
|
||||
onMouseMove: function (event) {
|
||||
updateDrag(event);
|
||||
UI.handleMouseMove(event);
|
||||
},
|
||||
onMousePress: function (event) {
|
||||
UI.handleMousePress(event);
|
||||
},
|
||||
onMouseRelease: function (event) {
|
||||
clearDrag(event);
|
||||
UI.handleMouseRelease(event);
|
||||
}
|
||||
};
|
||||
Controller.mousePressEvent.connect(inputHandler.onMousePress);
|
||||
Controller.mouseMoveEvent.connect(inputHandler.onMouseMove);
|
||||
Controller.mouseReleaseEvent.connect(inputHandler.onMouseRelease);
|
||||
|
||||
Script.scriptEnding.connect(teardown);
|
251
examples/fireworks.js
Normal file
251
examples/fireworks.js
Normal file
|
@ -0,0 +1,251 @@
|
|||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
var fireSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw");
|
||||
var audioOptions = {
|
||||
volume: 0.9,
|
||||
position: Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()))
|
||||
};
|
||||
|
||||
var DISTANCE_FROM_CAMERA = 7.0;
|
||||
|
||||
var bluePalette = [{
|
||||
red: 0,
|
||||
green: 206,
|
||||
blue: 209
|
||||
}, {
|
||||
red: 173,
|
||||
green: 216,
|
||||
blue: 230
|
||||
}, {
|
||||
red: 0,
|
||||
green: 191,
|
||||
blue: 255
|
||||
}];
|
||||
|
||||
var greenPalette = [{
|
||||
red: 152,
|
||||
green: 251,
|
||||
blue: 152
|
||||
}, {
|
||||
red: 127,
|
||||
green: 255,
|
||||
blue: 0
|
||||
}, {
|
||||
red: 50,
|
||||
green: 205,
|
||||
blue: 50
|
||||
}];
|
||||
|
||||
var redPalette = [{
|
||||
red: 255,
|
||||
green: 20,
|
||||
blue: 147
|
||||
}, {
|
||||
red: 255,
|
||||
green: 69,
|
||||
blue: 0
|
||||
}, {
|
||||
red: 255,
|
||||
green: 90,
|
||||
blue: 120
|
||||
}];
|
||||
|
||||
|
||||
var COLOR_RED = {red: 255, green: 0, blue: 0 };
|
||||
var COLOR_GREEN = {red: 0, green: 255, blue: 0};
|
||||
var COLOR_BLUE = {red: 0, green: 0, blue: 255};
|
||||
var iconsX = 700;
|
||||
var iconsY = 660;
|
||||
var ICON_SIZE = 30;
|
||||
|
||||
var redIcon = Overlays.addOverlay("text", {
|
||||
backgroundColor: COLOR_RED,
|
||||
x: iconsX,
|
||||
y: iconsY,
|
||||
width: ICON_SIZE,
|
||||
height: ICON_SIZE,
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
var greenIcon = Overlays.addOverlay("text", {
|
||||
backgroundColor: COLOR_GREEN,
|
||||
x: iconsX + 50,
|
||||
y: iconsY,
|
||||
width: ICON_SIZE,
|
||||
height: ICON_SIZE,
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
var blueIcon = Overlays.addOverlay("text", {
|
||||
backgroundColor: COLOR_BLUE,
|
||||
x: iconsX + 100,
|
||||
y: iconsY,
|
||||
width: ICON_SIZE,
|
||||
height: ICON_SIZE,
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
|
||||
|
||||
var NUM_BURSTS = 11;
|
||||
var SPEED = 6.0;
|
||||
|
||||
var rockets = [];
|
||||
Rocket = function(point, colorPalette) {
|
||||
//default to blue palette if no palette passed in
|
||||
this.colors = colorPalette;
|
||||
this.point = point;
|
||||
this.bursts = [];
|
||||
this.burst = false;
|
||||
|
||||
this.emitRate = randInt(80, 120);
|
||||
this.emitStrength = randInt(5.0, 7.0);
|
||||
|
||||
this.rocket = Entities.addEntity({
|
||||
type: "Sphere",
|
||||
position: this.point,
|
||||
dimensions: {
|
||||
x: 0.07,
|
||||
y: 0.07,
|
||||
z: 0.07
|
||||
},
|
||||
color: {
|
||||
red: 240,
|
||||
green: 240,
|
||||
blue: 240
|
||||
}
|
||||
});
|
||||
|
||||
this.animationSettings = JSON.stringify({
|
||||
fps: 40,
|
||||
frameIndex: 0,
|
||||
running: true,
|
||||
firstFrame: 0,
|
||||
lastFrame: 20,
|
||||
loop: false
|
||||
});
|
||||
|
||||
this.direction = {
|
||||
x: randFloat(-0.4, 0.4),
|
||||
y: 1.0,
|
||||
z: 0.0
|
||||
}
|
||||
|
||||
this.time = 0.0;
|
||||
this.timeout = randInt(15, 40);
|
||||
};
|
||||
|
||||
Rocket.prototype.update = function(deltaTime) {
|
||||
this.time++;
|
||||
|
||||
Entities.editEntity(this.rocket, {
|
||||
velocity: Vec3.multiply(SPEED, this.direction)
|
||||
});
|
||||
var position = Entities.getEntityProperties(this.rocket).position;
|
||||
|
||||
if (this.time > this.timeout) {
|
||||
this.explode(position);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Rocket.prototype.explode = function(position) {
|
||||
Audio.playSound(fireSound, audioOptions);
|
||||
Entities.editEntity(this.rocket, {
|
||||
velocity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
});
|
||||
|
||||
var colorIndex = 0;
|
||||
for (var i = 0; i < NUM_BURSTS; ++i) {
|
||||
var color = this.colors[colorIndex];
|
||||
print(JSON.stringify(color));
|
||||
this.bursts.push(Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
animationSettings: this.animationSettings,
|
||||
position: position,
|
||||
textures: 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png',
|
||||
emitRate: this.emitRate,
|
||||
emitStrength: this.emitStrength,
|
||||
emitDirection: {
|
||||
x: Math.pow(-1, i) * randFloat(0.0, 1.4),
|
||||
y: 1.0,
|
||||
z: 0.0
|
||||
},
|
||||
color: color,
|
||||
lifespan: 1.0,
|
||||
visible: true,
|
||||
locked: false
|
||||
}));
|
||||
|
||||
if (colorIndex < this.colors.length - 1) {
|
||||
colorIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
this.burst = true;
|
||||
Entities.deleteEntity(this.rocket);
|
||||
};
|
||||
|
||||
//var lastLoudness;
|
||||
var LOUDNESS_RADIUS_RATIO = 10;
|
||||
|
||||
function update(deltaTime) {
|
||||
for (var i = 0; i < rockets.length; i++) {
|
||||
if (!rockets[i].burst) {
|
||||
rockets[i].update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function randFloat(min, max) {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
function randInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
||||
|
||||
function computeWorldPoint(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var addVector = Vec3.multiply(Vec3.normalize(pickRay.direction), DISTANCE_FROM_CAMERA);
|
||||
return Vec3.sum(Camera.getPosition(), addVector);
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||
x: event.x,
|
||||
y: event.y
|
||||
});
|
||||
if(clickedOverlay === redIcon) {
|
||||
rockets.push(new Rocket(computeWorldPoint(event), redPalette));
|
||||
} else if (clickedOverlay === greenIcon) {
|
||||
rockets.push(new Rocket(computeWorldPoint(event), greenPalette));
|
||||
} else if (clickedOverlay === blueIcon) {
|
||||
rockets.push(new Rocket(computeWorldPoint(event), bluePalette));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
Overlays.deleteOverlay(redIcon);
|
||||
Overlays.deleteOverlay(greenIcon);
|
||||
Overlays.deleteOverlay(blueIcon);
|
||||
for (var i = 0; i < rockets.length; ++i) {
|
||||
Entities.deleteEntity(rockets[i].rocket);
|
||||
for (var j = 0; j < NUM_BURSTS; ++j) {
|
||||
Entities.deleteEntity(rockets[i].bursts[j]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
|
@ -55,8 +55,8 @@ var warpLine = Overlays.addOverlay("line3d", {
|
|||
var velocity = { x: 0, y: 0, z: 0 };
|
||||
var VERY_LONG_TIME = 1000000.0;
|
||||
|
||||
var active = Menu.isOptionChecked("Enable VR Mode");
|
||||
var prevVRMode = Menu.isOptionChecked("Enable VR Mode");
|
||||
var active = HMD.active;
|
||||
var prevVRMode = HMD.active;
|
||||
|
||||
var hmdControls = (function () {
|
||||
|
||||
|
@ -121,28 +121,28 @@ var hmdControls = (function () {
|
|||
velocity = Vec3.sum(velocity, direction);
|
||||
break;
|
||||
case findAction("YAW_LEFT"):
|
||||
if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
|
||||
if (yawTimer < 0.0 && HMD.active) {
|
||||
yawChange = yawChange + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT);
|
||||
yawTimer = CAMERA_UPDATE_TIME;
|
||||
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
|
||||
} else if (!HMD.active) {
|
||||
yawChange = yawChange + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT);
|
||||
}
|
||||
break;
|
||||
case findAction("YAW_RIGHT"):
|
||||
if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) {
|
||||
if (yawTimer < 0.0 && HMD.active) {
|
||||
yawChange = yawChange - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT);
|
||||
yawTimer = CAMERA_UPDATE_TIME;
|
||||
} else if (!Menu.isOptionChecked("Enable VR Mode")) {
|
||||
} else if (!HMD.active) {
|
||||
yawChange = yawChange - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT);
|
||||
}
|
||||
break;
|
||||
case findAction("PITCH_DOWN"):
|
||||
if (!Menu.isOptionChecked("Enable VR Mode")) {
|
||||
if (!HMD.active) {
|
||||
pitchChange = pitchChange - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT);
|
||||
}
|
||||
break;
|
||||
case findAction("PITCH_UP"):
|
||||
if (!Menu.isOptionChecked("Enable VR Mode")) {
|
||||
if (!HMD.active) {
|
||||
pitchChange = pitchChange + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT);
|
||||
}
|
||||
break;
|
||||
|
@ -175,9 +175,9 @@ var hmdControls = (function () {
|
|||
}
|
||||
|
||||
function update(dt) {
|
||||
if (prevVRMode != Menu.isOptionChecked("Enable VR Mode")) {
|
||||
active = Menu.isOptionChecked("Enable VR Mode");
|
||||
prevVRMode = Menu.isOptionChecked("Enable VR Mode");
|
||||
if (prevVRMode != HMD.active) {
|
||||
active = HMD.active;
|
||||
prevVRMode = HMD.active;
|
||||
}
|
||||
|
||||
if (yawTimer >= 0.0) {
|
||||
|
|
|
@ -362,6 +362,9 @@
|
|||
var elVoxelVolumeSizeY = document.getElementById("property-voxel-volume-size-y");
|
||||
var elVoxelVolumeSizeZ = document.getElementById("property-voxel-volume-size-z");
|
||||
var elVoxelSurfaceStyle = document.getElementById("property-voxel-surface-style");
|
||||
var elXTextureURL = document.getElementById("property-x-texture-url");
|
||||
var elYTextureURL = document.getElementById("property-y-texture-url");
|
||||
var elZTextureURL = document.getElementById("property-z-texture-url");
|
||||
|
||||
var elHyperlinkHref = document.getElementById("property-hyperlink-href");
|
||||
var elHyperlinkDescription = document.getElementById("property-hyperlink-description");
|
||||
|
@ -614,6 +617,9 @@
|
|||
elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2);
|
||||
elVoxelVolumeSizeZ.value = properties.voxelVolumeSize.z.toFixed(2);
|
||||
elVoxelSurfaceStyle.value = properties.voxelSurfaceStyle;
|
||||
elXTextureURL.value = properties.xTextureURL;
|
||||
elYTextureURL.value = properties.yTextureURL;
|
||||
elZTextureURL.value = properties.zTextureURL;
|
||||
}
|
||||
|
||||
if (selected) {
|
||||
|
@ -867,6 +873,9 @@
|
|||
elVoxelVolumeSizeY.addEventListener('change', voxelVolumeSizeChangeFunction);
|
||||
elVoxelVolumeSizeZ.addEventListener('change', voxelVolumeSizeChangeFunction);
|
||||
elVoxelSurfaceStyle.addEventListener('change', createEmitTextPropertyUpdateFunction('voxelSurfaceStyle'));
|
||||
elXTextureURL.addEventListener('change', createEmitTextPropertyUpdateFunction('xTextureURL'));
|
||||
elYTextureURL.addEventListener('change', createEmitTextPropertyUpdateFunction('yTextureURL'));
|
||||
elZTextureURL.addEventListener('change', createEmitTextPropertyUpdateFunction('zTextureURL'));
|
||||
|
||||
elMoveSelectionToGrid.addEventListener("click", function() {
|
||||
EventBridge.emitWebEvent(JSON.stringify({
|
||||
|
@ -1063,7 +1072,23 @@
|
|||
<option value='0'>marching cubes</option>
|
||||
<option value='1'>cubic</option>
|
||||
<option value='2'>edged cubic</option>
|
||||
</select>
|
||||
<option value='3'>edged marching cubes</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="label">X-axis Texture URL</div>
|
||||
<div class="value">
|
||||
<input type="text" id="property-x-texture-url" class="url"></input>
|
||||
</div>
|
||||
|
||||
<div class="label">Y-axis Texture URL</div>
|
||||
<div class="value">
|
||||
<input type="text" id="property-y-texture-url" class="url"></input>
|
||||
</div>
|
||||
|
||||
<div class="label">Z-axis Texture URL</div>
|
||||
<div class="value">
|
||||
<input type="text" id="property-z-texture-url" class="url"></input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -98,8 +98,8 @@ EntityPropertyDialogBox = (function () {
|
|||
index++;
|
||||
}
|
||||
|
||||
if (properties.type == "PolyVox") {
|
||||
array.push({ label: "Voxel Space Size:", type: "header" });
|
||||
if (properties.type == "PolyVox") {
|
||||
array.push({ label: "Voxel Space Size:", type: "header" });
|
||||
index++;
|
||||
|
||||
array.push({ label: "X:", value: properties.voxelVolumeSize.x.toFixed(decimals) });
|
||||
|
@ -109,9 +109,16 @@ EntityPropertyDialogBox = (function () {
|
|||
array.push({ label: "Z:", value: properties.voxelVolumeSize.z.toFixed(decimals) });
|
||||
index++;
|
||||
|
||||
array.push({ label: "Surface Extractor", value: properties.voxelSurfaceStyle });
|
||||
index++;
|
||||
}
|
||||
array.push({ label: "Surface Extractor", value: properties.voxelSurfaceStyle });
|
||||
index++;
|
||||
|
||||
array.push({ label: "X-axis Texture URL:", value: properties.xTextureURL });
|
||||
index++;
|
||||
array.push({ label: "Y-axis Texture URL:", value: properties.yTextureURL });
|
||||
index++;
|
||||
array.push({ label: "Z-axis Texture URL:", value: properties.zTextureURL });
|
||||
index++;
|
||||
}
|
||||
|
||||
array.push({ label: "Position:", type: "header" });
|
||||
index++;
|
||||
|
@ -348,14 +355,17 @@ EntityPropertyDialogBox = (function () {
|
|||
properties.backgroundColor.blue = array[index++].value;
|
||||
}
|
||||
|
||||
if (properties.type == "PolyVox") {
|
||||
if (properties.type == "PolyVox") {
|
||||
properties.shapeType = array[index++].value;
|
||||
|
||||
index++; // skip header
|
||||
properties.voxelVolumeSize.x = array[index++].value;
|
||||
properties.voxelVolumeSize.y = array[index++].value;
|
||||
properties.voxelVolumeSize.z = array[index++].value;
|
||||
properties.voxelSurfaceStyle = array[index++].value;
|
||||
index++; // skip header
|
||||
properties.voxelVolumeSize.x = array[index++].value;
|
||||
properties.voxelVolumeSize.y = array[index++].value;
|
||||
properties.voxelVolumeSize.z = array[index++].value;
|
||||
properties.voxelSurfaceStyle = array[index++].value;
|
||||
properties.xTextureURL = array[index++].value;
|
||||
properties.yTextureURL = array[index++].value;
|
||||
properties.zTextureURL = array[index++].value;
|
||||
}
|
||||
|
||||
index++; // skip header
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
// Created by Zander Otavka on 7/24/15
|
||||
// Copyright 2015 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
|
||||
//
|
||||
// Manage overlays with object oriented goodness, instead of ugly `Overlays.h` methods.
|
||||
// Instead of:
|
||||
//
|
||||
|
@ -22,39 +25,59 @@
|
|||
// ...
|
||||
// billboard.destroy();
|
||||
//
|
||||
// See more on usage below.
|
||||
// More on usage below. Examples in `examples/example/overlayPanelExample.js`.
|
||||
//
|
||||
// Note that including this file will delete Overlays from the global scope. All the
|
||||
// functionality of Overlays is represented here, just better. If you try to use Overlays in
|
||||
// tandem, there may be performance problems or nasty surprises.
|
||||
// Note that including this file will delete `Overlays` from the global scope. All the
|
||||
// functionality of `Overlays` is represented here, just better. If you try to use `Overlays`
|
||||
// in tandem, there may be performance problems or nasty surprises.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
(function() {
|
||||
// Delete `Overlays` from the global scope.
|
||||
var Overlays = this.Overlays;
|
||||
delete this.Overlays;
|
||||
|
||||
|
||||
var ABSTRACT = null;
|
||||
|
||||
var overlays = {};
|
||||
var panels = {};
|
||||
|
||||
var overlayTypes;
|
||||
var overlayTypes = {};
|
||||
|
||||
// Abstract overlay types
|
||||
var Overlay,
|
||||
Overlay2D,
|
||||
Base3DOverlay,
|
||||
Planar3DOverlay,
|
||||
Billboard3DOverlay,
|
||||
Volume3DOverlay;
|
||||
|
||||
// Multiple inheritance mixins
|
||||
var PanelAttachable,
|
||||
Billboardable;
|
||||
function generateOverlayClass(superclass, type, properties) {
|
||||
var that;
|
||||
if (type == ABSTRACT) {
|
||||
that = function(type, params) {
|
||||
superclass.call(this, type, params);
|
||||
};
|
||||
} else {
|
||||
that = function(params) {
|
||||
superclass.call(this, type, params);
|
||||
};
|
||||
overlayTypes[type] = that;
|
||||
}
|
||||
|
||||
that.prototype = new superclass();
|
||||
that.prototype.constructor = that;
|
||||
|
||||
properties.forEach(function(prop) {
|
||||
Object.defineProperty(that.prototype, prop, {
|
||||
get: function() {
|
||||
return Overlays.getProperty(this._id, prop);
|
||||
},
|
||||
set: function(newValue) {
|
||||
var keyValuePair = {};
|
||||
keyValuePair[prop] = newValue;
|
||||
this.setProperties(keyValuePair);
|
||||
},
|
||||
configurable: false
|
||||
});
|
||||
});
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a new JavaScript object for an overlay of given ID.
|
||||
|
@ -137,249 +160,131 @@
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// Perform global scoped operations on overlays, such as finding by ray intersection.
|
||||
//
|
||||
OverlayManager = {
|
||||
findOnRay: function(pickRay, knownOverlaysOnly, searchList) {
|
||||
var rayPickResult = Overlays.findRayIntersection(pickRay);
|
||||
if (rayPickResult.intersects) {
|
||||
return findOverlay(rayPickResult.overlayID, knownOverlaysOnly, searchList);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
findAtPoint: function(point, knownOverlaysOnly, searchList) {
|
||||
var foundID = Overlays.getOverlayAtPoint(point);
|
||||
if (foundID) {
|
||||
return findOverlay(foundID, knownOverlaysOnly, searchList);
|
||||
var Overlay = (function() {
|
||||
var that = function(type, params) {
|
||||
if (type && params) {
|
||||
this._id = Overlays.addOverlay(type, params);
|
||||
overlays[this._id] = this;
|
||||
} else {
|
||||
var pickRay = Camera.computePickRay(point.x, point.y);
|
||||
return OverlayManager.findOnRay(pickRay, knownOverlaysOnly, searchList);
|
||||
this._id = 0;
|
||||
}
|
||||
},
|
||||
makeSearchList: function(array) {
|
||||
var searchList = {};
|
||||
array.forEach(function(object) {
|
||||
searchList[object._id] = object;
|
||||
});
|
||||
return searchList;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
that.prototype.constructor = that;
|
||||
|
||||
//
|
||||
// Object oriented abstraction layer for overlays.
|
||||
//
|
||||
// Usage:
|
||||
// // Create an overlay
|
||||
// var billboard = new Image3DOverlay({
|
||||
// visible: true,
|
||||
// isFacingAvatar: true,
|
||||
// ignoreRayIntersections: false
|
||||
// });
|
||||
//
|
||||
// // Get a property
|
||||
// var isVisible = billboard.visible;
|
||||
//
|
||||
// // Set a single property
|
||||
// billboard.position = { x: 1, y: 3, z: 2 };
|
||||
//
|
||||
// // Set multiple properties at the same time
|
||||
// billboard.setProperties({
|
||||
// url: "http://images.com/overlayImage.jpg",
|
||||
// dimensions: { x: 2, y: 2 }
|
||||
// });
|
||||
//
|
||||
// // Clone an overlay
|
||||
// var clonedBillboard = billboard.clone();
|
||||
//
|
||||
// // Remove an overlay from the world
|
||||
// billboard.destroy();
|
||||
//
|
||||
// // Remember, there is a poor orphaned JavaScript object left behind. You should
|
||||
// // remove any references to it so you don't accidentally try to modify an overlay that
|
||||
// // isn't there.
|
||||
// billboard = undefined;
|
||||
//
|
||||
(function() {
|
||||
var ABSTRACT = null;
|
||||
overlayTypes = {};
|
||||
|
||||
function generateOverlayClass(superclass, type, properties) {
|
||||
var that;
|
||||
if (type == ABSTRACT) {
|
||||
that = function(type, params) {
|
||||
superclass.call(this, type, params);
|
||||
};
|
||||
} else {
|
||||
that = function(params) {
|
||||
superclass.call(this, type, params);
|
||||
};
|
||||
overlayTypes[type] = that;
|
||||
Object.defineProperty(that.prototype, "isLoaded", {
|
||||
get: function() {
|
||||
return Overlays.isLoaded(this._id);
|
||||
}
|
||||
});
|
||||
|
||||
that.prototype = new superclass();
|
||||
that.prototype.constructor = that;
|
||||
Object.defineProperty(that.prototype, "parentPanel", {
|
||||
get: function() {
|
||||
return findPanel(Overlays.getParentPanel(this._id));
|
||||
}
|
||||
});
|
||||
|
||||
properties.forEach(function(prop) {
|
||||
Object.defineProperty(that.prototype, prop, {
|
||||
get: function() {
|
||||
return Overlays.getProperty(this._id, prop);
|
||||
},
|
||||
set: function(newValue) {
|
||||
var keyValuePair = {};
|
||||
keyValuePair[prop] = newValue;
|
||||
this.setProperties(keyValuePair);
|
||||
},
|
||||
configurable: false
|
||||
});
|
||||
});
|
||||
that.prototype.getTextSize = function(text) {
|
||||
return Overlays.textSize(this._id, text);
|
||||
};
|
||||
|
||||
return that;
|
||||
}
|
||||
that.prototype.setProperties = function(properties) {
|
||||
Overlays.editOverlay(this._id, properties);
|
||||
};
|
||||
|
||||
Overlay = (function() {
|
||||
var that = function(type, params) {
|
||||
if (type && params) {
|
||||
this._id = Overlays.addOverlay(type, params);
|
||||
overlays[this._id] = this;
|
||||
} else {
|
||||
this._id = 0;
|
||||
}
|
||||
};
|
||||
that.prototype.clone = function() {
|
||||
return makeOverlayFromId(Overlays.cloneOverlay(this._id));
|
||||
};
|
||||
|
||||
that.prototype.constructor = that;
|
||||
that.prototype.destroy = function() {
|
||||
Overlays.deleteOverlay(this._id);
|
||||
};
|
||||
|
||||
Object.defineProperty(that.prototype, "isLoaded", {
|
||||
get: function() {
|
||||
return Overlays.isLoaded(this._id);
|
||||
}
|
||||
});
|
||||
that.prototype.isPanelAttachable = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
Object.defineProperty(that.prototype, "parentPanel", {
|
||||
get: function() {
|
||||
return findPanel(Overlays.getParentPanel(this._id));
|
||||
}
|
||||
});
|
||||
|
||||
that.prototype.getTextSize = function(text) {
|
||||
return Overlays.textSize(this._id, text);
|
||||
};
|
||||
|
||||
that.prototype.setProperties = function(properties) {
|
||||
Overlays.editOverlay(this._id, properties);
|
||||
};
|
||||
|
||||
that.prototype.clone = function() {
|
||||
return makeOverlayFromId(Overlays.cloneOverlay(this._id));
|
||||
};
|
||||
|
||||
that.prototype.destroy = function() {
|
||||
Overlays.deleteOverlay(this._id);
|
||||
};
|
||||
|
||||
that.prototype.isPanelAttachable = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
return generateOverlayClass(that, ABSTRACT, [
|
||||
"alpha", "glowLevel", "pulseMax", "pulseMin", "pulsePeriod", "glowLevelPulse",
|
||||
"alphaPulse", "colorPulse", "visible", "anchor"
|
||||
]);
|
||||
})();
|
||||
|
||||
// Supports multiple inheritance of properties. Just `concat` them onto the end of the
|
||||
// properties list.
|
||||
PanelAttachable = ["offsetPosition", "offsetRotation", "offsetScale"];
|
||||
Billboardable = ["isFacingAvatar"];
|
||||
|
||||
Overlay2D = generateOverlayClass(Overlay, ABSTRACT, [
|
||||
"bounds", "x", "y", "width", "height"
|
||||
]);
|
||||
|
||||
Base3DOverlay = generateOverlayClass(Overlay, ABSTRACT, [
|
||||
"position", "lineWidth", "rotation", "isSolid", "isFilled", "isWire", "isDashedLine",
|
||||
"ignoreRayIntersection", "drawInFront", "drawOnHUD"
|
||||
]);
|
||||
|
||||
Planar3DOverlay = generateOverlayClass(Base3DOverlay, ABSTRACT, [
|
||||
"dimensions"
|
||||
]);
|
||||
|
||||
Billboard3DOverlay = generateOverlayClass(Planar3DOverlay, ABSTRACT, [
|
||||
].concat(PanelAttachable).concat(Billboardable));
|
||||
Billboard3DOverlay.prototype.isPanelAttachable = function() { return true; };
|
||||
|
||||
Volume3DOverlay = generateOverlayClass(Base3DOverlay, ABSTRACT, [
|
||||
"dimensions"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Overlay2D, "image", [
|
||||
"subImage", "imageURL"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Billboard3DOverlay, "image3d", [
|
||||
"url", "subImage"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Overlay2D, "text", [
|
||||
"font", "text", "backgroundColor", "backgroundAlpha", "leftMargin", "topMargin"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Billboard3DOverlay, "text3d", [
|
||||
"text", "backgroundColor", "backgroundAlpha", "lineHeight", "leftMargin", "topMargin",
|
||||
"rightMargin", "bottomMargin"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Volume3DOverlay, "cube", [
|
||||
"borderSize"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Volume3DOverlay, "sphere", [
|
||||
]);
|
||||
|
||||
generateOverlayClass(Planar3DOverlay, "circle3d", [
|
||||
"startAt", "endAt", "outerRadius", "innerRadius", "hasTickMarks",
|
||||
"majorTickMarksAngle", "minorTickMarksAngle", "majorTickMarksLength",
|
||||
"minorTickMarksLength", "majorTickMarksColor", "minorTickMarksColor"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Planar3DOverlay, "rectangle3d", [
|
||||
]);
|
||||
|
||||
generateOverlayClass(Base3DOverlay, "line3d", [
|
||||
"start", "end"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Planar3DOverlay, "grid", [
|
||||
"minorGridWidth", "majorGridEvery"
|
||||
]);
|
||||
|
||||
generateOverlayClass(Volume3DOverlay, "localmodels", [
|
||||
]);
|
||||
|
||||
generateOverlayClass(Volume3DOverlay, "model", [
|
||||
"url", "dimensions", "textures"
|
||||
return generateOverlayClass(that, ABSTRACT, [
|
||||
"alpha", "glowLevel", "pulseMax", "pulseMin", "pulsePeriod", "glowLevelPulse",
|
||||
"alphaPulse", "colorPulse", "visible", "anchor"
|
||||
]);
|
||||
})();
|
||||
|
||||
ImageOverlay = overlayTypes["image"];
|
||||
Image3DOverlay = overlayTypes["image3d"];
|
||||
TextOverlay = overlayTypes["text"];
|
||||
Text3DOverlay = overlayTypes["text3d"];
|
||||
Cube3DOverlay = overlayTypes["cube"];
|
||||
Sphere3DOverlay = overlayTypes["sphere"];
|
||||
Circle3DOverlay = overlayTypes["circle3d"];
|
||||
Rectangle3DOverlay = overlayTypes["rectangle3d"];
|
||||
Line3DOverlay = overlayTypes["line3d"];
|
||||
Grid3DOverlay = overlayTypes["grid"];
|
||||
LocalModelsOverlay = overlayTypes["localmodels"];
|
||||
ModelOverlay = overlayTypes["model"];
|
||||
// Supports multiple inheritance of properties. Just `concat` them onto the end of the
|
||||
// properties list.
|
||||
var PanelAttachable = ["offsetPosition", "offsetRotation", "offsetScale"];
|
||||
var Billboardable = ["isFacingAvatar"];
|
||||
|
||||
var Overlay2D = generateOverlayClass(Overlay, ABSTRACT, [
|
||||
"bounds", "x", "y", "width", "height"
|
||||
]);
|
||||
|
||||
var Base3DOverlay = generateOverlayClass(Overlay, ABSTRACT, [
|
||||
"position", "lineWidth", "rotation", "isSolid", "isFilled", "isWire", "isDashedLine",
|
||||
"ignoreRayIntersection", "drawInFront", "drawOnHUD"
|
||||
]);
|
||||
|
||||
var Planar3DOverlay = generateOverlayClass(Base3DOverlay, ABSTRACT, [
|
||||
"dimensions"
|
||||
]);
|
||||
|
||||
var Billboard3DOverlay = generateOverlayClass(Planar3DOverlay, ABSTRACT, [
|
||||
].concat(PanelAttachable).concat(Billboardable));
|
||||
Billboard3DOverlay.prototype.isPanelAttachable = function() { return true; };
|
||||
|
||||
var Volume3DOverlay = generateOverlayClass(Base3DOverlay, ABSTRACT, [
|
||||
"dimensions"
|
||||
]);
|
||||
|
||||
ImageOverlay = generateOverlayClass(Overlay2D, "image", [
|
||||
"subImage", "imageURL"
|
||||
]);
|
||||
|
||||
Image3DOverlay = generateOverlayClass(Billboard3DOverlay, "image3d", [
|
||||
"url", "subImage"
|
||||
]);
|
||||
|
||||
TextOverlay = generateOverlayClass(Overlay2D, "text", [
|
||||
"font", "text", "backgroundColor", "backgroundAlpha", "leftMargin", "topMargin"
|
||||
]);
|
||||
|
||||
Text3DOverlay = generateOverlayClass(Billboard3DOverlay, "text3d", [
|
||||
"text", "backgroundColor", "backgroundAlpha", "lineHeight", "leftMargin", "topMargin",
|
||||
"rightMargin", "bottomMargin"
|
||||
]);
|
||||
|
||||
Cube3DOverlay = generateOverlayClass(Volume3DOverlay, "cube", [
|
||||
"borderSize"
|
||||
]);
|
||||
|
||||
Sphere3DOverlay = generateOverlayClass(Volume3DOverlay, "sphere", [
|
||||
]);
|
||||
|
||||
Circle3DOverlay = generateOverlayClass(Planar3DOverlay, "circle3d", [
|
||||
"startAt", "endAt", "outerRadius", "innerRadius", "hasTickMarks",
|
||||
"majorTickMarksAngle", "minorTickMarksAngle", "majorTickMarksLength",
|
||||
"minorTickMarksLength", "majorTickMarksColor", "minorTickMarksColor"
|
||||
]);
|
||||
|
||||
Rectangle3DOverlay = generateOverlayClass(Planar3DOverlay, "rectangle3d", [
|
||||
]);
|
||||
|
||||
Line3DOverlay = generateOverlayClass(Base3DOverlay, "line3d", [
|
||||
"start", "end"
|
||||
]);
|
||||
|
||||
Grid3DOverlay = generateOverlayClass(Planar3DOverlay, "grid", [
|
||||
"minorGridWidth", "majorGridEvery"
|
||||
]);
|
||||
|
||||
LocalModelsOverlay = generateOverlayClass(Volume3DOverlay, "localmodels", [
|
||||
]);
|
||||
|
||||
ModelOverlay = generateOverlayClass(Volume3DOverlay, "model", [
|
||||
"url", "dimensions", "textures"
|
||||
]);
|
||||
|
||||
|
||||
//
|
||||
// Object oriented abstraction layer for panels.
|
||||
//
|
||||
OverlayPanel = (function() {
|
||||
var that = function(params) {
|
||||
this._id = Overlays.addPanel(params);
|
||||
|
@ -455,6 +360,35 @@
|
|||
})();
|
||||
|
||||
|
||||
OverlayManager = {
|
||||
findOnRay: function(pickRay, knownOverlaysOnly, searchList) {
|
||||
var rayPickResult = Overlays.findRayIntersection(pickRay);
|
||||
if (rayPickResult.intersects) {
|
||||
return findOverlay(rayPickResult.overlayID, knownOverlaysOnly, searchList);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
findAtPoint: function(point, knownOverlaysOnly, searchList) {
|
||||
var foundID = Overlays.getOverlayAtPoint(point);
|
||||
if (foundID) {
|
||||
return findOverlay(foundID, knownOverlaysOnly, searchList);
|
||||
} else {
|
||||
var pickRay = Camera.computePickRay(point.x, point.y);
|
||||
return OverlayManager.findOnRay(pickRay, knownOverlaysOnly, searchList);
|
||||
}
|
||||
},
|
||||
makeSearchList: function(array) {
|
||||
var searchList = {};
|
||||
array.forEach(function(object) {
|
||||
searchList[object._id] = object;
|
||||
});
|
||||
return searchList;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Threadsafe cleanup of JavaScript objects.
|
||||
|
||||
function onOverlayDeleted(id) {
|
||||
if (id in overlays) {
|
||||
if (overlays[id].parentPanel) {
|
||||
|
|
|
@ -362,8 +362,11 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
|||
this.fractionKey = optionalPersistenceKey + '.fraction';
|
||||
this.save = function () {
|
||||
var screenSize = Controller.getViewportDimensions();
|
||||
var fraction = {x: that.x / screenSize.x, y: that.y / screenSize.y};
|
||||
Settings.setValue(this.fractionKey, JSON.stringify(fraction));
|
||||
if (screenSize.x > 0 && screenSize.y > 0) {
|
||||
// Guard against invalid screen size that can occur at shut-down.
|
||||
var fraction = {x: that.x / screenSize.x, y: that.y / screenSize.y};
|
||||
Settings.setValue(this.fractionKey, JSON.stringify(fraction));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.save = function () { }; // Called on move. Can be overriden or extended by clients.
|
||||
|
|
1039
examples/libraries/uiwidgets.js
Normal file
1039
examples/libraries/uiwidgets.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -130,7 +130,6 @@ var heights = [];
|
|||
var myAlpha = [];
|
||||
var arrays = [];
|
||||
var isOnHMD = false,
|
||||
ENABLE_VR_MODE = "Enable VR Mode",
|
||||
NOTIFICATIONS_3D_DIRECTION = 0.0, // Degrees from avatar orientation.
|
||||
NOTIFICATIONS_3D_DISTANCE = 0.6, // Horizontal distance from avatar position.
|
||||
NOTIFICATIONS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes.
|
||||
|
@ -414,7 +413,7 @@ function update() {
|
|||
j,
|
||||
k;
|
||||
|
||||
if (isOnHMD !== Menu.isOptionChecked(ENABLE_VR_MODE)) {
|
||||
if (isOnHMD !== HMD.active) {
|
||||
while (arrays.length > 0) {
|
||||
deleteNotification(0);
|
||||
}
|
||||
|
@ -596,7 +595,7 @@ function menuItemEvent(menuItem) {
|
|||
LODManager.LODDecreased.connect(function() {
|
||||
var warningText = "\n"
|
||||
+ "Due to the complexity of the content, the \n"
|
||||
+ "level of detail has been decreased."
|
||||
+ "level of detail has been decreased. "
|
||||
+ "You can now see: \n"
|
||||
+ LODManager.getLODFeedbackText();
|
||||
|
||||
|
|
155
examples/particleDance.js
Normal file
155
examples/particleDance.js
Normal file
|
@ -0,0 +1,155 @@
|
|||
(function() {
|
||||
var NUM_BURSTS = 3;
|
||||
var NUM_EMITTERS_PER_BURST = 11;
|
||||
|
||||
var RANGE = 5.0;
|
||||
var AUDIO_RANGE = 0.5 * RANGE;
|
||||
var DIST_BETWEEN_BURSTS = 1.0;
|
||||
|
||||
var LOUDNESS_RADIUS_RATIO = 10;
|
||||
|
||||
var TEXTURE_PATH = 'https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png';
|
||||
var cameraAxis = Quat.getFront(Camera.getOrientation());
|
||||
var center = Vec3.sum(Camera.getPosition(), Vec3.multiply(RANGE, cameraAxis));
|
||||
var audioPosition = Vec3.sum(Camera.getPosition(), Vec3.multiply(AUDIO_RANGE, cameraAxis));
|
||||
|
||||
var song = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/songs/Made%20In%20Heights%20-%20Forgiveness.wav");
|
||||
var audioOptions = {
|
||||
volume: 0.9, position: audioPosition
|
||||
};
|
||||
|
||||
var DISTANCE_FROM_CAMERA = 7.0;
|
||||
|
||||
var colorPalette = [{
|
||||
red: 0,
|
||||
green: 206,
|
||||
blue: 209
|
||||
}, {
|
||||
red: 173,
|
||||
green: 216,
|
||||
blue: 230
|
||||
}, {
|
||||
red: 0,
|
||||
green: 191,
|
||||
blue: 255
|
||||
}];
|
||||
|
||||
var bursts = [];
|
||||
var audioStats;
|
||||
|
||||
Burst = function(point) {
|
||||
if (!audioStats) {
|
||||
audioStats = Audio.playSound(song, audioOptions);
|
||||
}
|
||||
|
||||
this.point = point;
|
||||
this.emitters = [];
|
||||
|
||||
this.emitRate = randInt(80, 120);
|
||||
this.emitStrength = randInt(4.0, 6.0);
|
||||
|
||||
this.animationSettings = JSON.stringify({
|
||||
fps: 10,
|
||||
frameIndex: 0,
|
||||
running: true,
|
||||
firstFrame: 0,
|
||||
lastFrame: 50,
|
||||
loop: true
|
||||
});
|
||||
|
||||
this.direction = {
|
||||
x: randFloat(-0.3, 0.3),
|
||||
y: 1.0,
|
||||
z: 0.0
|
||||
}
|
||||
|
||||
this.base = Entities.addEntity({
|
||||
type: "Sphere",
|
||||
position: this.point,
|
||||
dimensions: {
|
||||
x: 0.05,
|
||||
y: 0.05,
|
||||
z: 0.05
|
||||
},
|
||||
color: {
|
||||
red: 240,
|
||||
green: 240,
|
||||
blue: 240
|
||||
}
|
||||
});
|
||||
for (var i = 0; i < NUM_EMITTERS_PER_BURST; ++i) {
|
||||
var colorIndex = randInt(0, colorPalette.length - 1);
|
||||
var color = colorPalette[colorIndex];
|
||||
this.emitters.push(Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
animationSettings: this.animationSettings,
|
||||
position: this.point,
|
||||
textures: TEXTURE_PATH,
|
||||
emitRate: this.emitRate,
|
||||
emitStrength: this.emitStrength,
|
||||
emitDirection: {
|
||||
x: Math.pow(-1, i) * randFloat(0.0, 0.4),
|
||||
y: 1.0,
|
||||
z: 0.0
|
||||
},
|
||||
color: color,
|
||||
lifespan: 1.0,
|
||||
visible: true,
|
||||
locked: false
|
||||
}));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var nextPosition = center;
|
||||
var posOrNeg = -1;
|
||||
|
||||
for (var i = 0; i < NUM_BURSTS; ++i) {
|
||||
posOrNeg *= -1;
|
||||
bursts.push(new Burst(nextPosition));
|
||||
var offset = {
|
||||
x: RANGE/(i+2) * posOrNeg,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
var nextPosition = Vec3.sum(nextPosition, offset);
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
for (var i = 0; i < NUM_BURSTS; i++) {
|
||||
if (audioStats && audioStats.loudness > 0.0) {
|
||||
for (var j = 0; j < NUM_EMITTERS_PER_BURST; ++j) {
|
||||
Entities.editEntity(bursts[i].emitters[j], {
|
||||
particleRadius: audioStats.loudness / LOUDNESS_RADIUS_RATIO
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function randFloat(min, max) {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
function randInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
for (var i = 0; i < NUM_BURSTS; ++i) {
|
||||
Entities.deleteEntity(bursts[i].base);
|
||||
for (var j = 0; j < NUM_EMITTERS_PER_BURST; ++j) {
|
||||
var emitter = bursts[i].emitters[j];
|
||||
Entities.deleteEntity(emitter);
|
||||
}
|
||||
|
||||
}
|
||||
Audio.stop();
|
||||
}
|
||||
|
||||
Script.update.connect(update);
|
||||
|
||||
})();
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var lineEntityID = null;
|
||||
var sphereEntityID = null;
|
||||
var lineIsRezzed = false;
|
||||
|
||||
var BUTTON_SIZE = 32;
|
||||
|
@ -56,16 +57,24 @@ function nearLinePoint(targetPosition) {
|
|||
|
||||
|
||||
function removeLine() {
|
||||
if (lineIsRezzed) {
|
||||
Entities.deleteEntity(lineEntityID);
|
||||
lineEntityID = null;
|
||||
lineIsRezzed = false;
|
||||
}
|
||||
if (lineIsRezzed) {
|
||||
Entities.deleteEntity(lineEntityID);
|
||||
if (sphereEntityID) {
|
||||
Entities.deleteEntity(sphereEntityID);
|
||||
}
|
||||
lineEntityID = null;
|
||||
sphereEntityID = null;
|
||||
lineIsRezzed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createOrUpdateLine(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
if (sphereEntityID) {
|
||||
Entities.deleteEntity(sphereEntityID);
|
||||
sphereEntityID = null;
|
||||
}
|
||||
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
|
||||
var props = Entities.getEntityProperties(intersection.entityID);
|
||||
|
||||
|
@ -78,7 +87,6 @@ function createOrUpdateLine(event) {
|
|||
position: MyAvatar.position,
|
||||
lifetime: 15 + props.lifespan // renew lifetime
|
||||
});
|
||||
// Entities.setAllPoints(lineEntityID, points);
|
||||
} else {
|
||||
lineIsRezzed = true;
|
||||
lineEntityID = Entities.addEntity({
|
||||
|
@ -90,6 +98,15 @@ function createOrUpdateLine(event) {
|
|||
lifetime: 15 // if someone crashes while pointing, don't leave the line there forever.
|
||||
});
|
||||
}
|
||||
|
||||
sphereEntityID = Entities.addEntity({
|
||||
type: "Sphere",
|
||||
position: intersection.intersection,
|
||||
ignoreForCollisions: 1,
|
||||
dimensions: { x: 0.6, y: 0.6, z: 0.6 },
|
||||
color: { red: 0, green: 255, blue: 0 },
|
||||
lifetime: 15 // if someone crashes while pointing, don't leave the line there forever.
|
||||
});
|
||||
} else {
|
||||
removeLine();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
SCALE_2D = 0.35, // Scale the SVGs for 2D display.
|
||||
background3D = {},
|
||||
bar3D = {},
|
||||
ENABLE_VR_MODE_MENU_ITEM = "Enable VR Mode",
|
||||
PROGRESS_3D_DIRECTION = 0.0, // Degrees from avatar orientation.
|
||||
PROGRESS_3D_DISTANCE = 0.602, // Horizontal distance from avatar position.
|
||||
PROGRESS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes.
|
||||
|
@ -157,7 +156,7 @@
|
|||
eyePosition,
|
||||
avatarOrientation;
|
||||
|
||||
if (isOnHMD !== Menu.isOptionChecked(ENABLE_VR_MODE_MENU_ITEM)) {
|
||||
if (isOnHMD !== HMD.active) {
|
||||
deleteOverlays();
|
||||
isOnHMD = !isOnHMD;
|
||||
createOverlays();
|
||||
|
|
|
@ -1378,7 +1378,7 @@ var CHECK_MARK_COLOR = {
|
|||
|
||||
this.nextY = this.y + this.getHeight();
|
||||
|
||||
var item = new CollapsablePanelItem(name, this.x, this.nextY, textWidth, rawHeight, panel);
|
||||
var item = new CollapsablePanelItem(name, this.x, this.nextY, textWidth, rawHeight);
|
||||
item.isSubPanel = true;
|
||||
|
||||
this.nextY += 1.5 * item.height;
|
||||
|
|
|
@ -1,32 +1,37 @@
|
|||
var controlHeld = false;
|
||||
var shiftHeld = false;
|
||||
|
||||
|
||||
function attemptVoxelChange(intersection) {
|
||||
var ids = Entities.findEntities(intersection.intersection, 10);
|
||||
var success = false;
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
var id = ids[i];
|
||||
if (controlHeld) {
|
||||
// hold control to erase a sphere
|
||||
if (Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0)) {
|
||||
success = true;
|
||||
}
|
||||
} else if (shiftHeld) {
|
||||
// hold shift to set all voxels to 255
|
||||
if (Entities.setAllVoxels(id, 255)) {
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
// no modifier key means to add a sphere
|
||||
if (Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255)) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
function floorVector(v) {
|
||||
return {x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z)};
|
||||
}
|
||||
|
||||
function attemptVoxelChange(pickRayDir, intersection) {
|
||||
|
||||
var properties = Entities.getEntityProperties(intersection.entityID);
|
||||
if (properties.type != "PolyVox") {
|
||||
return false;
|
||||
}
|
||||
|
||||
var voxelPosition = Entities.worldCoordsToVoxelCoords(intersection.entityID, intersection.intersection);
|
||||
voxelPosition = Vec3.subtract(voxelPosition, {x: 0.5, y: 0.5, z: 0.5});
|
||||
var pickRayDirInVoxelSpace = Entities.localCoordsToVoxelCoords(intersection.entityID, pickRayDir);
|
||||
pickRayDirInVoxelSpace = Vec3.normalize(pickRayDirInVoxelSpace);
|
||||
|
||||
if (controlHeld) {
|
||||
// hold control to erase a voxel
|
||||
var toErasePosition = Vec3.sum(voxelPosition, Vec3.multiply(pickRayDirInVoxelSpace, 0.1));
|
||||
return Entities.setVoxel(intersection.entityID, floorVector(toErasePosition), 0);
|
||||
} else if (shiftHeld) {
|
||||
// hold shift to set all voxels to 255
|
||||
return Entities.setAllVoxels(intersection.entityID, 255);
|
||||
} else {
|
||||
// no modifier key to add a voxel
|
||||
var toDrawPosition = Vec3.subtract(voxelPosition, Vec3.multiply(pickRayDirInVoxelSpace, 0.1));
|
||||
return Entities.setVoxel(intersection.entityID, floorVector(toDrawPosition), 255);
|
||||
}
|
||||
|
||||
// Entities.setVoxelSphere(id, intersection.intersection, radius, 0)
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if (!event.isLeftButton) {
|
||||
|
@ -36,19 +41,17 @@ function mousePressEvent(event) {
|
|||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
|
||||
|
||||
// we've used a picking ray to decide where to add the new sphere of voxels. If we pick nothing
|
||||
// or if we pick a non-PolyVox entity, we fall through to the next picking attempt.
|
||||
if (intersection.intersects) {
|
||||
if (attemptVoxelChange(intersection)) {
|
||||
if (attemptVoxelChange(pickRay.direction, intersection)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if the PolyVox entity is empty, we can't pick against its voxel. try picking against its
|
||||
// if the PolyVox entity is empty, we can't pick against its "on" voxels. try picking against its
|
||||
// bounding box, instead.
|
||||
intersection = Entities.findRayIntersection(pickRay, false); // bounding box picking
|
||||
if (intersection.intersects) {
|
||||
attemptVoxelChange(intersection);
|
||||
attemptVoxelChange(pickRay.direction, intersection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ set(TARGET_NAME interface)
|
|||
project(${TARGET_NAME})
|
||||
|
||||
# set a default root dir for each of our optional externals if it was not passed
|
||||
set(OPTIONAL_EXTERNALS "Faceshift" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK" "3DConnexionClient")
|
||||
set(OPTIONAL_EXTERNALS "Faceshift" "LeapMotion" "RtMidi" "RSSDK" "3DConnexionClient" "iViewHMD")
|
||||
foreach(EXTERNAL ${OPTIONAL_EXTERNALS})
|
||||
string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE)
|
||||
if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR)
|
||||
|
@ -14,32 +14,12 @@ endforeach()
|
|||
find_package(Qt5LinguistTools REQUIRED)
|
||||
find_package(Qt5LinguistToolsMacros)
|
||||
|
||||
if (DEFINED ENV{JOB_ID})
|
||||
set(BUILD_SEQ $ENV{JOB_ID})
|
||||
elseif (DEFINED ENV{ghprbPullId})
|
||||
set(BUILD_SEQ "PR: $ENV{ghprbPullId} - Commit: $ENV{ghprbActualCommit}")
|
||||
else ()
|
||||
set(BUILD_SEQ "dev")
|
||||
endif ()
|
||||
|
||||
if (WIN32)
|
||||
add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h
|
||||
add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines
|
||||
endif()
|
||||
|
||||
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
|
||||
|
||||
macro(GroupSources curdir)
|
||||
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
|
||||
foreach(child ${children})
|
||||
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
|
||||
GroupSources(${curdir}/${child})
|
||||
else()
|
||||
string(REPLACE "/" "\\" groupname ${curdir})
|
||||
source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
include_application_version()
|
||||
|
||||
# grab the implementation and header files from src dirs
|
||||
file(GLOB_RECURSE INTERFACE_SRCS "src/*.cpp" "src/*.h")
|
||||
|
@ -115,16 +95,12 @@ else()
|
|||
add_executable(${TARGET_NAME} ${INTERFACE_SRCS} ${QM})
|
||||
endif()
|
||||
|
||||
# set up the external glm library
|
||||
add_dependency_external_projects(glm bullet)
|
||||
|
||||
# set up the external glm library
|
||||
find_package(GLM REQUIRED)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS})
|
||||
|
||||
add_dependency_external_projects(LibOVR)
|
||||
find_package(LibOVR REQUIRED)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES})
|
||||
|
||||
find_package(Bullet REQUIRED)
|
||||
|
||||
# perform the system include hack for OS X to ignore warnings
|
||||
|
@ -137,9 +113,10 @@ endif()
|
|||
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
|
||||
|
||||
# link required hifi libraries
|
||||
link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars
|
||||
audio audio-client animation script-engine physics
|
||||
render-utils entities-renderer ui auto-updater)
|
||||
link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars
|
||||
audio audio-client animation script-engine physics
|
||||
render-utils entities-renderer ui auto-updater
|
||||
plugins display-plugins input-plugins)
|
||||
|
||||
add_dependency_external_projects(sdl2)
|
||||
|
||||
|
@ -189,7 +166,7 @@ if (RTMIDI_FOUND AND NOT DISABLE_RTMIDI AND APPLE)
|
|||
endif ()
|
||||
|
||||
# include headers for interface and InterfaceConfig.
|
||||
include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/src")
|
||||
|
||||
target_link_libraries(
|
||||
${TARGET_NAME}
|
||||
|
|
14
interface/external/iViewHMD/readme.txt
vendored
Normal file
14
interface/external/iViewHMD/readme.txt
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
Instructions for adding SMI HMD Eye Tracking to Interface on Windows
|
||||
David Rowe, 27 Jul 2015.
|
||||
|
||||
1. Download and install the SMI HMD Eye Tracking software from http://update.smivision.com/iViewNG-HMD.exe.
|
||||
|
||||
2. Copy the SDK folders (3rdParty, include, libs) from the SDK installation folder C:\Program Files (x86)\SMI\iViewNG-HMD\SDK
|
||||
into the interface/externals/iViewHMD folder. This readme.txt should be there as well.
|
||||
|
||||
You may optionally choose to copy the SDK folders to a location outside the repository (so you can re-use with different
|
||||
checkouts and different projects). If so, set the ENV variable "HIFI_LIB_DIR" to a directory containing a subfolder
|
||||
"iViewHMD" that contains the folders mentioned above.
|
||||
|
||||
3. Clear your build directory, run cmake and build, and you should be all set.
|
BIN
interface/resources/images/paintStroke.png
Normal file
BIN
interface/resources/images/paintStroke.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
|
@ -47,6 +47,11 @@ Item {
|
|||
font.pixelSize: root.fontSize
|
||||
text: "Framerate: " + root.framerate
|
||||
}
|
||||
Text {
|
||||
color: root.fontColor;
|
||||
font.pixelSize: root.fontSize
|
||||
text: "Simrate: " + root.simrate
|
||||
}
|
||||
Text {
|
||||
color: root.fontColor;
|
||||
font.pixelSize: root.fontSize
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,6 +36,9 @@
|
|||
#include <StDev.h>
|
||||
#include <udt/PacketHeaders.h>
|
||||
#include <ViewFrustum.h>
|
||||
#include <plugins/PluginContainer.h>
|
||||
#include <plugins/PluginManager.h>
|
||||
#include <SimpleMovingAverage.h>
|
||||
|
||||
#include "AudioClient.h"
|
||||
#include "Bookmarks.h"
|
||||
|
@ -47,13 +50,12 @@
|
|||
#include "Stars.h"
|
||||
#include "avatar/Avatar.h"
|
||||
#include "avatar/MyAvatar.h"
|
||||
#include "devices/SixenseManager.h"
|
||||
#include <input-plugins/KeyboardMouseDevice.h>
|
||||
#include "scripting/ControllerScriptingInterface.h"
|
||||
#include "scripting/DialogsManagerScriptingInterface.h"
|
||||
#include "scripting/WebWindowClass.h"
|
||||
#include "ui/AudioStatsDialog.h"
|
||||
#include "ui/BandwidthDialog.h"
|
||||
#include "ui/HMDToolsDialog.h"
|
||||
#include "ui/ModelsBrowser.h"
|
||||
#include "ui/OctreeStatsDialog.h"
|
||||
#include "ui/SnapshotShareDialog.h"
|
||||
|
@ -62,10 +64,9 @@
|
|||
#include "ui/overlays/Overlays.h"
|
||||
#include "ui/ApplicationOverlay.h"
|
||||
#include "ui/ApplicationCompositor.h"
|
||||
#include "ui/OverlayConductor.h"
|
||||
#include "ui/RunningScriptsWidget.h"
|
||||
#include "ui/ToolWindow.h"
|
||||
#include "ui/UserInputMapper.h"
|
||||
#include "devices/KeyboardMouseDevice.h"
|
||||
#include "octree/OctreePacketProcessor.h"
|
||||
#include "UndoStackScriptingInterface.h"
|
||||
|
||||
|
@ -79,6 +80,7 @@ class QMouseEvent;
|
|||
class QSystemTrayIcon;
|
||||
class QTouchEvent;
|
||||
class QWheelEvent;
|
||||
class OffscreenGlCanvas;
|
||||
|
||||
class GLCanvas;
|
||||
class FaceTracker;
|
||||
|
@ -86,6 +88,12 @@ class MainWindow;
|
|||
class Node;
|
||||
class ScriptEngine;
|
||||
|
||||
namespace gpu {
|
||||
class Context;
|
||||
typedef std::shared_ptr<Context> ContextPointer;
|
||||
}
|
||||
|
||||
|
||||
static const QString SNAPSHOT_EXTENSION = ".jpg";
|
||||
static const QString SVO_EXTENSION = ".svo";
|
||||
static const QString SVO_JSON_EXTENSION = ".svo.json";
|
||||
|
@ -124,7 +132,7 @@ class Application;
|
|||
|
||||
typedef bool (Application::* AcceptURLMethod)(const QString &);
|
||||
|
||||
class Application : public QApplication, public AbstractViewStateInterface, public AbstractScriptingServicesInterface {
|
||||
class Application : public QApplication, public AbstractViewStateInterface, public AbstractScriptingServicesInterface, PluginContainer {
|
||||
Q_OBJECT
|
||||
|
||||
friend class OctreePacketProcessor;
|
||||
|
@ -136,7 +144,6 @@ public:
|
|||
static glm::quat getOrientationForPath() { return getInstance()->_myAvatar->getOrientation(); }
|
||||
static glm::vec3 getPositionForAudio() { return getInstance()->_myAvatar->getHead()->getPosition(); }
|
||||
static glm::quat getOrientationForAudio() { return getInstance()->_myAvatar->getHead()->getFinalOrientationInWorldFrame(); }
|
||||
static UserInputMapper* getUserInputMapper() { return &getInstance()->_userInputMapper; }
|
||||
static void initPlugins();
|
||||
static void shutdownPlugins();
|
||||
|
||||
|
@ -179,6 +186,7 @@ public:
|
|||
bool eventFilter(QObject* object, QEvent* event);
|
||||
|
||||
glm::uvec2 getCanvasSize() const;
|
||||
glm::uvec2 getUiSize() const;
|
||||
QSize getDeviceSize() const;
|
||||
bool hasFocus() const;
|
||||
PickRay computePickRay() const;
|
||||
|
@ -262,11 +270,6 @@ public:
|
|||
void displaySide(RenderArgs* renderArgs, Camera& whichCamera, bool selfAvatarOnly = false, bool billboard = false);
|
||||
|
||||
virtual const glm::vec3& getShadowDistances() const { return _shadowDistances; }
|
||||
|
||||
/// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account.
|
||||
virtual void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
|
||||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
|
||||
|
||||
virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); }
|
||||
virtual QThread* getMainThread() { return thread(); }
|
||||
virtual float getSizeScale() const;
|
||||
|
@ -277,6 +280,26 @@ public:
|
|||
virtual void endOverrideEnvironmentData() { _environment.endOverride(); }
|
||||
virtual qreal getDevicePixelRatio();
|
||||
|
||||
// Plugin container support
|
||||
virtual void addMenu(const QString& menuName);
|
||||
virtual void removeMenu(const QString& menuName);
|
||||
virtual void addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName);
|
||||
virtual void removeMenuItem(const QString& menuName, const QString& menuItem);
|
||||
virtual bool isOptionChecked(const QString& name);
|
||||
virtual void setIsOptionChecked(const QString& path, bool checked);
|
||||
virtual void setFullscreen(const QScreen* target) override;
|
||||
virtual void unsetFullscreen(const QScreen* avoid) override;
|
||||
virtual void showDisplayPluginsTools() override;
|
||||
virtual QGLWidget* getPrimarySurface() override;
|
||||
virtual bool isForeground() override;
|
||||
|
||||
void setActiveDisplayPlugin(const QString& pluginName);
|
||||
|
||||
DisplayPlugin * getActiveDisplayPlugin();
|
||||
const DisplayPlugin * getActiveDisplayPlugin() const;
|
||||
|
||||
public:
|
||||
|
||||
FileLogger* getLogger() { return _logger; }
|
||||
|
||||
glm::vec2 getViewportDimensions() const;
|
||||
|
@ -300,10 +323,9 @@ public:
|
|||
// rendering of several elements depend on that
|
||||
// TODO: carry that information on the Camera as a setting
|
||||
bool isHMDMode() const;
|
||||
glm::quat getHeadOrientation() const;
|
||||
glm::vec3 getHeadPosition() const;
|
||||
glm::mat4 getHeadPose() const;
|
||||
glm::mat4 getHMDSensorPose() const;
|
||||
glm::mat4 getEyePose(int eye) const;
|
||||
glm::mat4 getEyeOffset(int eye) const;
|
||||
glm::mat4 getEyeProjection(int eye) const;
|
||||
|
||||
QRect getDesirableApplicationGeometry();
|
||||
|
@ -330,6 +352,8 @@ public:
|
|||
|
||||
const QRect& getMirrorViewRect() const { return _mirrorViewRect; }
|
||||
|
||||
float getAverageSimsPerSecond();
|
||||
|
||||
signals:
|
||||
|
||||
/// Fired when we're simulating; allows external parties to hook in.
|
||||
|
@ -353,6 +377,7 @@ signals:
|
|||
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
||||
|
||||
void beforeAboutToQuit();
|
||||
void activeDisplayPluginChanged();
|
||||
|
||||
public slots:
|
||||
void setSessionUUID(const QUuid& sessionUUID);
|
||||
|
@ -361,6 +386,8 @@ public slots:
|
|||
void nodeAdded(SharedNodePointer node);
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
void packetSent(quint64 length);
|
||||
void updateDisplayMode();
|
||||
void updateInputModes();
|
||||
|
||||
QVector<EntityItemID> pasteEntities(float x, float y, float z);
|
||||
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
|
||||
|
@ -406,6 +433,11 @@ public slots:
|
|||
void resetSensors();
|
||||
void setActiveFaceTracker();
|
||||
|
||||
void setActiveEyeTracker();
|
||||
void calibrateEyeTracker1Point();
|
||||
void calibrateEyeTracker3Points();
|
||||
void calibrateEyeTracker5Points();
|
||||
|
||||
void aboutApp();
|
||||
void showEditEntitiesHelp();
|
||||
|
||||
|
@ -431,15 +463,8 @@ private slots:
|
|||
|
||||
void connectedToDomain(const QString& hostname);
|
||||
|
||||
friend class HMDToolsDialog;
|
||||
void setFullscreen(bool fullscreen);
|
||||
void setEnable3DTVMode(bool enable3DTVMode);
|
||||
void setEnableVRMode(bool enableVRMode);
|
||||
|
||||
void rotationModeChanged();
|
||||
|
||||
glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint);
|
||||
|
||||
void closeMirrorView();
|
||||
void restoreMirrorView();
|
||||
void shrinkMirrorView();
|
||||
|
@ -452,6 +477,7 @@ private slots:
|
|||
void faceTrackerMuteToggled();
|
||||
|
||||
void setCursorVisible(bool visible);
|
||||
void activeChanged(Qt::ApplicationState state);
|
||||
|
||||
private:
|
||||
void resetCameras(Camera& camera, const glm::uvec2& size);
|
||||
|
@ -467,6 +493,9 @@ private:
|
|||
|
||||
void update(float deltaTime);
|
||||
|
||||
void setPalmData(Hand* hand, UserInputMapper::PoseValue pose, float deltaTime, int index);
|
||||
void emulateMouse(Hand* hand, float click, float shift, int index);
|
||||
|
||||
// Various helper functions called during update()
|
||||
void updateLOD();
|
||||
void updateMouseRay();
|
||||
|
@ -495,6 +524,11 @@ private:
|
|||
int sendNackPackets();
|
||||
|
||||
bool _dependencyManagerIsSetup;
|
||||
|
||||
OffscreenGlCanvas* _offscreenContext;
|
||||
DisplayPluginPointer _displayPlugin;
|
||||
InputPluginList _activeInputPlugins;
|
||||
|
||||
MainWindow* _window;
|
||||
|
||||
ToolWindow* _toolWindow;
|
||||
|
@ -532,11 +566,10 @@ private:
|
|||
|
||||
OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers
|
||||
|
||||
KeyboardMouseDevice _keyboardMouseDevice; // Default input device, the good old keyboard mouse and maybe touchpad
|
||||
UserInputMapper _userInputMapper; // User input mapper allowing to mapp different real devices to the action channels that the application has to offer
|
||||
MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be)
|
||||
Camera _myCamera; // My view onto the world
|
||||
Camera _mirrorCamera; // Cammera for mirror view
|
||||
KeyboardMouseDevice* _keyboardMouseDevice{ nullptr }; // Default input device, the good old keyboard mouse and maybe touchpad
|
||||
MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be)
|
||||
Camera _myCamera; // My view onto the world
|
||||
Camera _mirrorCamera; // Cammera for mirror view
|
||||
QRect _mirrorViewRect;
|
||||
|
||||
Setting::Handle<bool> _firstRun;
|
||||
|
@ -623,9 +656,6 @@ private:
|
|||
|
||||
void checkSkeleton();
|
||||
|
||||
QWidget* _fullscreenMenuWidget = new QWidget();
|
||||
int _menuBarHeight;
|
||||
|
||||
QHash<QString, AcceptURLMethod> _acceptedExtensions;
|
||||
|
||||
QList<QString> _domainConnectionRefusals;
|
||||
|
@ -642,9 +672,25 @@ private:
|
|||
Overlays _overlays;
|
||||
ApplicationOverlay _applicationOverlay;
|
||||
ApplicationCompositor _compositor;
|
||||
OverlayConductor _overlayConductor;
|
||||
|
||||
int _oldHandMouseX[2];
|
||||
int _oldHandMouseY[2];
|
||||
bool _oldHandLeftClick[2];
|
||||
bool _oldHandRightClick[2];
|
||||
int _numFramesSinceLastResize = 0;
|
||||
|
||||
bool _overlayEnabled = true;
|
||||
QRect _savedGeometry;
|
||||
DialogsManagerScriptingInterface* _dialogsManagerScriptingInterface = new DialogsManagerScriptingInterface();
|
||||
|
||||
EntityItemID _keyboardFocusedItem;
|
||||
quint64 _lastAcceptedKeyPress = 0;
|
||||
|
||||
SimpleMovingAverage _simsPerSecond{10};
|
||||
int _simsPerSecondReport = 0;
|
||||
quint64 _lastSimsPerSecondUpdate = 0;
|
||||
bool _isForeground = true; // starts out assumed to be in foreground
|
||||
};
|
||||
|
||||
#endif // hifi_Application_h
|
||||
|
|
|
@ -46,11 +46,7 @@ QString modeToString(CameraMode mode) {
|
|||
}
|
||||
|
||||
Camera::Camera() :
|
||||
_mode(CAMERA_MODE_THIRD_PERSON),
|
||||
_position(0.0f, 0.0f, 0.0f),
|
||||
_projection(glm::perspective(glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES), 16.0f/9.0f, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)),
|
||||
_isKeepLookingAt(false),
|
||||
_lookingAt(0.0f, 0.0f, 0.0f)
|
||||
_projection(glm::perspective(glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES), 16.0f/9.0f, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -61,12 +57,33 @@ void Camera::update(float deltaTime) {
|
|||
return;
|
||||
}
|
||||
|
||||
void Camera::recompose() {
|
||||
mat4 orientation = glm::mat4_cast(_rotation);
|
||||
mat4 translation = glm::translate(mat4(), _position);
|
||||
_transform = translation * orientation;
|
||||
}
|
||||
|
||||
void Camera::decompose() {
|
||||
_position = vec3(_transform[3]);
|
||||
_rotation = glm::quat_cast(_transform);
|
||||
}
|
||||
|
||||
void Camera::setTransform(const glm::mat4& transform) {
|
||||
_transform = transform;
|
||||
decompose();
|
||||
}
|
||||
|
||||
void Camera::setPosition(const glm::vec3& position) {
|
||||
_position = position;
|
||||
_position = position;
|
||||
recompose();
|
||||
if (_isKeepLookingAt) {
|
||||
lookAt(_lookingAt);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::setRotation(const glm::quat& rotation) {
|
||||
_rotation = rotation;
|
||||
recompose();
|
||||
if (_isKeepLookingAt) {
|
||||
lookAt(_lookingAt);
|
||||
}
|
||||
|
@ -129,3 +146,21 @@ void Camera::keepLookingAt(const glm::vec3& point) {
|
|||
_isKeepLookingAt = true;
|
||||
_lookingAt = point;
|
||||
}
|
||||
|
||||
void Camera::loadViewFrustum(ViewFrustum& frustum) const {
|
||||
// We will use these below, from either the camera or head vectors calculated above
|
||||
frustum.setProjection(getProjection());
|
||||
|
||||
// Set the viewFrustum up with the correct position and orientation of the camera
|
||||
frustum.setPosition(getPosition());
|
||||
frustum.setOrientation(getRotation());
|
||||
|
||||
// Ask the ViewFrustum class to calculate our corners
|
||||
frustum.calculate();
|
||||
}
|
||||
|
||||
ViewFrustum Camera::toViewFrustum() const {
|
||||
ViewFrustum result;
|
||||
loadViewFrustum(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -43,24 +43,31 @@ public:
|
|||
|
||||
void update( float deltaTime );
|
||||
|
||||
void setRotation(const glm::quat& rotation);
|
||||
void setProjection(const glm::mat4 & projection);
|
||||
CameraMode getMode() const { return _mode; }
|
||||
void setMode(CameraMode m);
|
||||
|
||||
glm::quat getRotation() const { return _rotation; }
|
||||
const glm::mat4& getProjection() const { return _projection; }
|
||||
CameraMode getMode() const { return _mode; }
|
||||
void loadViewFrustum(ViewFrustum& frustum) const;
|
||||
ViewFrustum toViewFrustum() const;
|
||||
|
||||
public slots:
|
||||
QString getModeString() const;
|
||||
void setModeString(const QString& mode);
|
||||
|
||||
glm::quat getRotation() const { return _rotation; }
|
||||
void setRotation(const glm::quat& rotation);
|
||||
|
||||
glm::vec3 getPosition() const { return _position; }
|
||||
void setPosition(const glm::vec3& position);
|
||||
|
||||
glm::quat getOrientation() const { return getRotation(); }
|
||||
void setOrientation(const glm::quat& orientation) { setRotation(orientation); }
|
||||
|
||||
const glm::mat4& getTransform() const { return _transform; }
|
||||
void setTransform(const glm::mat4& transform);
|
||||
|
||||
const glm::mat4& getProjection() const { return _projection; }
|
||||
void setProjection(const glm::mat4& projection);
|
||||
|
||||
PickRay computePickRay(float x, float y);
|
||||
|
||||
// These only work on independent cameras
|
||||
|
@ -78,11 +85,17 @@ signals:
|
|||
void modeUpdated(const QString& newMode);
|
||||
|
||||
private:
|
||||
CameraMode _mode;
|
||||
void recompose();
|
||||
void decompose();
|
||||
|
||||
CameraMode _mode{ CAMERA_MODE_THIRD_PERSON };
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _projection;
|
||||
|
||||
// derived
|
||||
glm::vec3 _position;
|
||||
glm::quat _rotation;
|
||||
glm::mat4 _projection;
|
||||
bool _isKeepLookingAt;
|
||||
bool _isKeepLookingAt{ false };
|
||||
glm::vec3 _lookingAt;
|
||||
};
|
||||
|
||||
|
|
|
@ -9,16 +9,15 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Application.h"
|
||||
#include "GLCanvas.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QWindow>
|
||||
|
||||
#include "Application.h"
|
||||
#include "GLCanvas.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
const int MSECS_PER_FRAME_WHEN_THROTTLED = 66;
|
||||
|
||||
static QGLFormat& getDesiredGLFormat() {
|
||||
// Specify an OpenGL 3.3 format using the Core profile.
|
||||
// That is, no old-school fixed pipeline functionality
|
||||
|
@ -34,10 +33,7 @@ static QGLFormat& getDesiredGLFormat() {
|
|||
return glFormat;
|
||||
}
|
||||
|
||||
GLCanvas::GLCanvas() : QGLWidget(getDesiredGLFormat()),
|
||||
_throttleRendering(false),
|
||||
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
|
||||
{
|
||||
GLCanvas::GLCanvas() : QGLWidget(getDesiredGLFormat()) {
|
||||
#ifdef Q_OS_LINUX
|
||||
// Cause GLCanvas::eventFilter to be called.
|
||||
// It wouldn't hurt to do this on Mac and PC too; but apparently it's only needed on linux.
|
||||
|
@ -45,15 +41,6 @@ GLCanvas::GLCanvas() : QGLWidget(getDesiredGLFormat()),
|
|||
#endif
|
||||
}
|
||||
|
||||
void GLCanvas::stopFrameTimer() {
|
||||
_frameTimer.stop();
|
||||
}
|
||||
|
||||
bool GLCanvas::isThrottleRendering() const {
|
||||
return (_throttleRendering
|
||||
|| (Application::getInstance()->getWindow()->isMinimized() && Application::getInstance()->isThrottleFPSEnabled()));
|
||||
}
|
||||
|
||||
int GLCanvas::getDeviceWidth() const {
|
||||
return width() * (windowHandle() ? (float)windowHandle()->devicePixelRatio() : 1.0f);
|
||||
}
|
||||
|
@ -63,20 +50,19 @@ int GLCanvas::getDeviceHeight() const {
|
|||
}
|
||||
|
||||
void GLCanvas::initializeGL() {
|
||||
Application::getInstance()->initializeGL();
|
||||
setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
setAcceptDrops(true);
|
||||
connect(Application::getInstance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeChanged(Qt::ApplicationState)));
|
||||
connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(throttleRender()));
|
||||
|
||||
// Note, we *DO NOT* want Qt to automatically swap buffers for us. This results in the "ringing" bug mentioned in WL#19514 when we're throttling the framerate.
|
||||
setAutoBufferSwap(false);
|
||||
}
|
||||
|
||||
void GLCanvas::paintGL() {
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
if (!_throttleRendering &&
|
||||
(!Application::getInstance()->getWindow()->isMinimized() || !Application::getInstance()->isThrottleFPSEnabled())) {
|
||||
|
||||
// FIXME - I'm not sure why this still remains, it appears as if this GLCanvas gets a single paintGL call near
|
||||
// the beginning of the application starting up. I'm not sure if we really need to call Application::paintGL()
|
||||
// in this case, since the display plugins eventually handle all the painting
|
||||
if ((!Application::getInstance()->getWindow()->isMinimized() || !Application::getInstance()->isThrottleFPSEnabled())) {
|
||||
Application::getInstance()->paintGL();
|
||||
}
|
||||
}
|
||||
|
@ -85,39 +71,6 @@ void GLCanvas::resizeGL(int width, int height) {
|
|||
Application::getInstance()->resizeGL();
|
||||
}
|
||||
|
||||
void GLCanvas::activeChanged(Qt::ApplicationState state) {
|
||||
switch (state) {
|
||||
case Qt::ApplicationActive:
|
||||
// If we're active, stop the frame timer and the throttle.
|
||||
_frameTimer.stop();
|
||||
_throttleRendering = false;
|
||||
break;
|
||||
|
||||
case Qt::ApplicationSuspended:
|
||||
case Qt::ApplicationHidden:
|
||||
// If we're hidden or are about to suspend, don't render anything.
|
||||
_throttleRendering = false;
|
||||
_frameTimer.stop();
|
||||
break;
|
||||
|
||||
default:
|
||||
// Otherwise, throttle.
|
||||
if (!_throttleRendering && !Application::getInstance()->isAboutToQuit()
|
||||
&& Application::getInstance()->isThrottleFPSEnabled()) {
|
||||
_frameTimer.start(_idleRenderInterval);
|
||||
_throttleRendering = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas::throttleRender() {
|
||||
_frameTimer.start(_idleRenderInterval);
|
||||
if (!Application::getInstance()->getWindow()->isMinimized()) {
|
||||
Application::getInstance()->paintGL();
|
||||
}
|
||||
}
|
||||
|
||||
int updateTime = 0;
|
||||
bool GLCanvas::event(QEvent* event) {
|
||||
switch (event->type()) {
|
||||
|
|
|
@ -22,29 +22,19 @@ class GLCanvas : public QGLWidget {
|
|||
|
||||
public:
|
||||
GLCanvas();
|
||||
|
||||
void stopFrameTimer();
|
||||
|
||||
bool isThrottleRendering() const;
|
||||
|
||||
int getDeviceWidth() const;
|
||||
int getDeviceHeight() const;
|
||||
QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); }
|
||||
|
||||
protected:
|
||||
|
||||
QTimer _frameTimer;
|
||||
bool _throttleRendering;
|
||||
int _idleRenderInterval;
|
||||
|
||||
virtual void initializeGL();
|
||||
virtual void paintGL();
|
||||
virtual void resizeGL(int width, int height);
|
||||
virtual bool event(QEvent* event);
|
||||
|
||||
private slots:
|
||||
void activeChanged(Qt::ApplicationState state);
|
||||
void throttleRender();
|
||||
bool eventFilter(QObject*, QEvent* event);
|
||||
|
||||
};
|
||||
|
|
|
@ -97,10 +97,6 @@ void MainWindow::changeEvent(QEvent* event) {
|
|||
} else {
|
||||
emit windowShown(true);
|
||||
}
|
||||
|
||||
if (isFullScreen() != Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::Fullscreen, isFullScreen());
|
||||
}
|
||||
} else if (event->type() == QEvent::ActivationChange) {
|
||||
if (isActiveWindow()) {
|
||||
emit windowShown(true);
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "devices/DdeFaceTracker.h"
|
||||
#include "devices/Faceshift.h"
|
||||
#include "devices/RealSense.h"
|
||||
#include "devices/SixenseManager.h"
|
||||
#include "devices/3DConnexionClient.h"
|
||||
#include "MainWindow.h"
|
||||
#include "scripting/MenuScriptingInterface.h"
|
||||
|
@ -221,9 +220,20 @@ Menu::Menu() {
|
|||
addActionToQMenuAndActionHash(toolsMenu, MenuOption::PackageModel, 0,
|
||||
qApp, SLOT(packageModel()));
|
||||
|
||||
MenuWrapper* displayMenu = addMenu("Display");
|
||||
{
|
||||
MenuWrapper* displayModeMenu = addMenu(MenuOption::OutputMenu);
|
||||
QActionGroup* displayModeGroup = new QActionGroup(displayModeMenu);
|
||||
displayModeGroup->setExclusive(true);
|
||||
}
|
||||
|
||||
MenuWrapper* avatarMenu = addMenu("Avatar");
|
||||
QObject* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
|
||||
MenuWrapper* inputModeMenu = addMenu(MenuOption::InputMenu);
|
||||
QActionGroup* inputModeGroup = new QActionGroup(inputModeMenu);
|
||||
inputModeGroup->setExclusive(false);
|
||||
|
||||
MenuWrapper* avatarSizeMenu = avatarMenu->addMenu("Size");
|
||||
addActionToQMenuAndActionHash(avatarSizeMenu,
|
||||
MenuOption::IncreaseAvatarSize,
|
||||
|
@ -242,26 +252,16 @@ Menu::Menu() {
|
|||
SLOT(resetSize()));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::KeyboardMotorControl,
|
||||
Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar, SLOT(updateMotionBehavior()));
|
||||
Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar, SLOT(updateMotionBehaviorFromMenu()));
|
||||
addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::ScriptedMotorControl, 0, true,
|
||||
avatar, SLOT(updateMotionBehavior()));
|
||||
avatar, SLOT(updateMotionBehaviorFromMenu()));
|
||||
addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::NamesAboveHeads, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::BlueSpeechSphere, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::EnableCharacterController, 0, true,
|
||||
avatar, SLOT(updateMotionBehavior()));
|
||||
avatar, SLOT(updateMotionBehaviorFromMenu()));
|
||||
|
||||
MenuWrapper* viewMenu = addMenu("View");
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu,
|
||||
MenuOption::Fullscreen,
|
||||
#ifdef Q_OS_MAC
|
||||
Qt::CTRL | Qt::META | Qt::Key_F,
|
||||
#else
|
||||
Qt::CTRL | Qt::Key_F,
|
||||
#endif
|
||||
false,
|
||||
qApp,
|
||||
SLOT(setFullscreen(bool)));
|
||||
addActionToQMenuAndActionHash(viewMenu, MenuOption::ReloadContent, 0, qApp, SLOT(reloadResourceCaches()));
|
||||
|
||||
MenuWrapper* cameraModeMenu = viewMenu->addMenu("Camera Mode");
|
||||
QActionGroup* cameraModeGroup = new QActionGroup(cameraModeMenu);
|
||||
|
@ -289,28 +289,11 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::CenterPlayerInView,
|
||||
0, false, qApp, SLOT(rotationModeChanged()));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::HMDTools,
|
||||
#ifdef Q_OS_MAC
|
||||
Qt::META | Qt::Key_H,
|
||||
#else
|
||||
Qt::CTRL | Qt::Key_H,
|
||||
#endif
|
||||
false,
|
||||
dialogsManager.data(),
|
||||
SLOT(hmdTools(bool)));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::EnableVRMode, 0,
|
||||
false,
|
||||
qApp,
|
||||
SLOT(setEnableVRMode(bool)));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Enable3DTVMode, 0,
|
||||
false,
|
||||
qApp,
|
||||
SLOT(setEnable3DTVMode(bool)));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::TurnWithHead, 0, false);
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::StandingHMDSensorMode, 0, false,
|
||||
avatar, SLOT(updateStandingHMDModeFromMenu()));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Stats);
|
||||
addActionToQMenuAndActionHash(viewMenu, MenuOption::Log,
|
||||
Qt::CTRL | Qt::SHIFT | Qt::Key_L,
|
||||
|
@ -432,6 +415,23 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::AutoMuteAudio, 0, false);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
MenuWrapper* eyeTrackingMenu = avatarDebugMenu->addMenu("Eye Tracking");
|
||||
addCheckableActionToQMenuAndActionHash(eyeTrackingMenu, MenuOption::SMIEyeTracking, 0, false,
|
||||
qApp, SLOT(setActiveEyeTracker()));
|
||||
{
|
||||
MenuWrapper* calibrateEyeTrackingMenu = eyeTrackingMenu->addMenu("Calibrate");
|
||||
addActionToQMenuAndActionHash(calibrateEyeTrackingMenu, MenuOption::OnePointCalibration, 0,
|
||||
qApp, SLOT(calibrateEyeTracker1Point()));
|
||||
addActionToQMenuAndActionHash(calibrateEyeTrackingMenu, MenuOption::ThreePointCalibration, 0,
|
||||
qApp, SLOT(calibrateEyeTracker3Points()));
|
||||
addActionToQMenuAndActionHash(calibrateEyeTrackingMenu, MenuOption::FivePointCalibration, 0,
|
||||
qApp, SLOT(calibrateEyeTracker5Points()));
|
||||
}
|
||||
addCheckableActionToQMenuAndActionHash(eyeTrackingMenu, MenuOption::SimulateEyeTracking, 0, false,
|
||||
qApp, SLOT(setActiveEyeTracker()));
|
||||
#endif
|
||||
|
||||
auto avatarManager = DependencyManager::get<AvatarManager>();
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AvatarReceiveStats, 0, false,
|
||||
avatarManager.data(), SLOT(setShouldShowReceiveStats(bool)));
|
||||
|
@ -440,8 +440,10 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderHeadCollisionShapes);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderBoundingCollisionShapes);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderLookAtVectors, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderLookAtTargets, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderFocusIndicator, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ShowWhosLookingAtMe, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::FixGaze, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu,
|
||||
MenuOption::Connexion,
|
||||
0, false,
|
||||
|
@ -453,30 +455,11 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlternateIK, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHands, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandMouseInput, 0, true);
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::LowVelocityFilter, 0, true,
|
||||
qApp, SLOT(setLowVelocityFilter(bool)));
|
||||
addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false);
|
||||
|
||||
MenuWrapper* sixenseOptionsMenu = handOptionsMenu->addMenu("Sixense");
|
||||
#ifdef __APPLE__
|
||||
addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu,
|
||||
MenuOption::SixenseEnabled,
|
||||
0, false,
|
||||
&SixenseManager::getInstance(),
|
||||
SLOT(toggleSixense(bool)));
|
||||
#endif
|
||||
addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu,
|
||||
MenuOption::FilterSixense,
|
||||
0,
|
||||
true,
|
||||
&SixenseManager::getInstance(),
|
||||
SLOT(setFilter(bool)));
|
||||
addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu,
|
||||
MenuOption::LowVelocityFilter,
|
||||
0,
|
||||
true,
|
||||
qApp,
|
||||
SLOT(setLowVelocityFilter(bool)));
|
||||
addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu, MenuOption::SixenseMouseInput, 0, true);
|
||||
|
||||
MenuWrapper* leapOptionsMenu = handOptionsMenu->addMenu("Leap Motion");
|
||||
addCheckableActionToQMenuAndActionHash(leapOptionsMenu, MenuOption::LeapMotionOnHMD, 0, false);
|
||||
|
||||
|
|
|
@ -80,6 +80,13 @@ public:
|
|||
const QKeySequence& shortcut = 0,
|
||||
QAction::MenuRole role = QAction::NoRole,
|
||||
int menuItemLocation = UNSPECIFIED_POSITION);
|
||||
QAction* addCheckableActionToQMenuAndActionHash(MenuWrapper* destinationMenu,
|
||||
const QString& actionName,
|
||||
const QKeySequence& shortcut = 0,
|
||||
const bool checked = false,
|
||||
const QObject* receiver = NULL,
|
||||
const char* member = NULL,
|
||||
int menuItemLocation = UNSPECIFIED_POSITION);
|
||||
|
||||
void removeAction(MenuWrapper* menu, const QString& actionName);
|
||||
|
||||
|
@ -109,14 +116,6 @@ private:
|
|||
void addDisabledActionAndSeparator(MenuWrapper* destinationMenu, const QString& actionName,
|
||||
int menuItemLocation = UNSPECIFIED_POSITION);
|
||||
|
||||
QAction* addCheckableActionToQMenuAndActionHash(MenuWrapper* destinationMenu,
|
||||
const QString& actionName,
|
||||
const QKeySequence& shortcut = 0,
|
||||
const bool checked = false,
|
||||
const QObject* receiver = NULL,
|
||||
const char* member = NULL,
|
||||
int menuItemLocation = UNSPECIFIED_POSITION);
|
||||
|
||||
QAction* getActionFromName(const QString& menuName, MenuWrapper* menu);
|
||||
MenuWrapper* getSubMenuFromName(const QString& menuName, MenuWrapper* menu);
|
||||
MenuWrapper* getMenuParent(const QString& menuName, QString& finalMenuPart);
|
||||
|
@ -186,22 +185,23 @@ namespace MenuOption {
|
|||
const QString EditEntitiesHelp = "Edit Entities Help...";
|
||||
const QString Enable3DTVMode = "Enable 3DTV Mode";
|
||||
const QString EnableCharacterController = "Enable avatar collisions";
|
||||
const QString EnableVRMode = "Enable VR Mode";
|
||||
const QString ExpandMyAvatarSimulateTiming = "Expand /myAvatar/simulation";
|
||||
const QString ExpandMyAvatarTiming = "Expand /myAvatar";
|
||||
const QString ExpandOtherAvatarTiming = "Expand /otherAvatar";
|
||||
const QString ExpandPaintGLTiming = "Expand /paintGL";
|
||||
const QString ExpandUpdateTiming = "Expand /update";
|
||||
const QString Faceshift = "Faceshift";
|
||||
const QString FilterSixense = "Smooth Sixense Movement";
|
||||
const QString FirstPerson = "First Person";
|
||||
const QString FivePointCalibration = "5 Point Calibration";
|
||||
const QString FixGaze = "Fix Gaze (no saccade)";
|
||||
const QString Forward = "Forward";
|
||||
const QString FrameTimer = "Show Timer";
|
||||
const QString Fullscreen = "Fullscreen";
|
||||
const QString FullscreenMirror = "Fullscreen Mirror";
|
||||
const QString HMDTools = "HMD Tools";
|
||||
const QString GlowWhenSpeaking = "Glow When Speaking";
|
||||
const QString HandMouseInput = "Enable Hand Mouse Input";
|
||||
const QString IncreaseAvatarSize = "Increase Avatar Size";
|
||||
const QString IndependentMode = "Independent Mode";
|
||||
const QString InputMenu = "Avatar>Input Devices";
|
||||
const QString KeyboardMotorControl = "Enable Keyboard Motor Control";
|
||||
const QString LeapMotionOnHMD = "Leap Motion on HMD";
|
||||
const QString LoadScript = "Open and Run Script File...";
|
||||
|
@ -219,7 +219,9 @@ namespace MenuOption {
|
|||
const QString NamesAboveHeads = "Names Above Heads";
|
||||
const QString NoFaceTracking = "None";
|
||||
const QString OctreeStats = "Entity Statistics";
|
||||
const QString OnePointCalibration = "1 Point Calibration";
|
||||
const QString OnlyDisplayTopTen = "Only Display Top Ten";
|
||||
const QString OutputMenu = "Display>Mode";
|
||||
const QString PackageModel = "Package Model...";
|
||||
const QString Pair = "Pair";
|
||||
const QString PhysicsShowOwned = "Highlight Simulation Ownership";
|
||||
|
@ -232,6 +234,7 @@ namespace MenuOption {
|
|||
const QString RenderBoundingCollisionShapes = "Show Bounding Collision Shapes";
|
||||
const QString RenderFocusIndicator = "Show Eye Focus";
|
||||
const QString RenderHeadCollisionShapes = "Show Head Collision Shapes";
|
||||
const QString RenderLookAtTargets = "Show Look-at Targets";
|
||||
const QString RenderLookAtVectors = "Show Look-at Vectors";
|
||||
const QString RenderSkeletonCollisionShapes = "Show Skeleton Collision Shapes";
|
||||
const QString RenderTargetFramerate = "Framerate";
|
||||
|
@ -270,15 +273,17 @@ namespace MenuOption {
|
|||
const QString ShowIKConstraints = "Show IK Constraints";
|
||||
const QString ShowRealtimeEntityStats = "Show Realtime Entity Stats";
|
||||
const QString ShowWhosLookingAtMe = "Show Who's Looking at Me";
|
||||
const QString SixenseEnabled = "Enable Hydra Support";
|
||||
const QString SixenseMouseInput = "Enable Sixense Mouse Input";
|
||||
const QString StandingHMDSensorMode = "Standing HMD Sensor Mode";
|
||||
const QString SimulateEyeTracking = "Simulate";
|
||||
const QString SMIEyeTracking = "SMI Eye Tracking";
|
||||
const QString Stars = "Stars";
|
||||
const QString Stats = "Stats";
|
||||
const QString StopAllScripts = "Stop All Scripts";
|
||||
const QString SuppressShortTimings = "Suppress Timings Less than 10ms";
|
||||
const QString TestPing = "Test Ping";
|
||||
const QString ThirdPerson = "Third Person";
|
||||
const QString ThrottleFPSIfNotFocus = "Throttle FPS If Not Focus";
|
||||
const QString ThreePointCalibration = "3 Point Calibration";
|
||||
const QString ThrottleFPSIfNotFocus = "Throttle FPS If Not Focus"; // FIXME - this value duplicated in Basic2DWindowOpenGLDisplayPlugin.cpp
|
||||
const QString ToolWindow = "Tool Window";
|
||||
const QString TransmitterDrive = "Transmitter Drive";
|
||||
const QString TurnWithHead = "Turn using Head";
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
#include <QStyle>
|
||||
#include <QStyleOptionTitleBar>
|
||||
|
||||
#include "GLCanvas.h"
|
||||
|
||||
#include "UIUtil.h"
|
||||
|
||||
int UIUtil::getWindowTitleBarHeight(const QWidget* window) {
|
||||
|
|
|
@ -43,11 +43,13 @@ void renderWorldBox(gpu::Batch& batch) {
|
|||
|
||||
auto transform = Transform{};
|
||||
batch.setModelTransform(transform);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(TREE_SCALE, 0.0f, 0.0f), red);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, TREE_SCALE, 0.0f), green);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, TREE_SCALE), blue);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), grey);
|
||||
geometryCache->renderLine(batch, glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, 0.0f), grey);
|
||||
|
||||
// TODO - consider alternate rendering for negative build-able space in the domain
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(HALF_TREE_SCALE, 0.0f, 0.0f), red);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, HALF_TREE_SCALE, 0.0f), green);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, HALF_TREE_SCALE), blue);
|
||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, HALF_TREE_SCALE), glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), grey);
|
||||
geometryCache->renderLine(batch, glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), glm::vec3(HALF_TREE_SCALE, 0.0f, 0.0f), grey);
|
||||
|
||||
// Draw meter markers along the 3 axis to help with measuring things
|
||||
const float MARKER_DISTANCE = 1.0f;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <NodeList.h>
|
||||
#include <NumericalConstants.h>
|
||||
#include <udt/PacketHeaders.h>
|
||||
#include <PathUtils.h>
|
||||
#include <PerfStat.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <TextRenderer3D.h>
|
||||
|
@ -69,6 +68,8 @@ namespace render {
|
|||
auto avatarPtr = static_pointer_cast<Avatar>(avatar);
|
||||
bool renderLookAtVectors = Menu::getInstance()->isOptionChecked(MenuOption::RenderLookAtVectors);
|
||||
avatarPtr->setDisplayingLookatVectors(renderLookAtVectors);
|
||||
bool renderLookAtTarget = Menu::getInstance()->isOptionChecked(MenuOption::RenderLookAtTargets);
|
||||
avatarPtr->setDisplayingLookatTarget(renderLookAtTarget);
|
||||
|
||||
if (avatarPtr->isInitialized() && args) {
|
||||
avatarPtr->render(args, Application::getInstance()->getCamera()->getPosition());
|
||||
|
@ -245,7 +246,7 @@ void Avatar::simulate(float deltaTime) {
|
|||
}
|
||||
|
||||
void Avatar::slamPosition(const glm::vec3& newPosition) {
|
||||
AvatarData::setPosition(newPosition);
|
||||
setPosition(newPosition);
|
||||
_positionDeltaAccumulator = glm::vec3(0.0f);
|
||||
_velocity = glm::vec3(0.0f);
|
||||
_lastVelocity = glm::vec3(0.0f);
|
||||
|
@ -561,6 +562,9 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
|||
}
|
||||
|
||||
void Avatar::fixupModelsInScene() {
|
||||
if (!(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
||||
// fix them up in the scene
|
||||
|
@ -601,7 +605,9 @@ void Avatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, floa
|
|||
|
||||
getHand()->render(renderArgs, false);
|
||||
}
|
||||
|
||||
getHead()->render(renderArgs, 1.0f, renderFrustum);
|
||||
getHead()->renderLookAts(renderArgs);
|
||||
}
|
||||
|
||||
bool Avatar::shouldRenderHead(const RenderArgs* renderArgs) const {
|
||||
|
@ -684,6 +690,23 @@ glm::vec3 Avatar::getDisplayNamePosition() const {
|
|||
const float HEAD_PROPORTION = 0.75f;
|
||||
namePosition = _position + getBodyUpDirection() * (getBillboardSize() * HEAD_PROPORTION);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
// TODO: Temporary logging to track cause of invalid scale value; remove once cause has been fixed.
|
||||
// See other TODO below.
|
||||
if (glm::isnan(namePosition.x) || glm::isnan(namePosition.y) || glm::isnan(namePosition.z)
|
||||
|| glm::isinf(namePosition.x) || glm::isinf(namePosition.y) || glm::isinf(namePosition.z)) {
|
||||
qDebug() << "namePosition =" << namePosition;
|
||||
glm::vec3 tempPosition(0.0f);
|
||||
if (getSkeletonModel().getNeckPosition(tempPosition)) {
|
||||
qDebug() << "getBodyUpDirection() =" << getBodyUpDirection();
|
||||
qDebug() << "getHeadHeight() =" << getHeadHeight();
|
||||
} else {
|
||||
qDebug() << "_position =" << _position;
|
||||
qDebug() << "getBodyUpDirection() =" << getBodyUpDirection();
|
||||
qDebug() << "getBillboardSize() =" << getBillboardSize();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return namePosition;
|
||||
}
|
||||
|
||||
|
@ -718,7 +741,8 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa
|
|||
// Compute correct scale to apply
|
||||
float scale = DESIRED_HIGHT_ON_SCREEN / (fontSize * pixelHeight) * devicePixelRatio;
|
||||
#ifdef DEBUG
|
||||
// TODO: Temporary logging to track cause of invalid scale vale; remove once cause has been fixed.
|
||||
// TODO: Temporary logging to track cause of invalid scale value; remove once cause has been fixed.
|
||||
// Problem is probably due to an invalid getDisplayNamePosition(). See extra logging above.
|
||||
if (scale == 0.0f || glm::isnan(scale) || glm::isinf(scale)) {
|
||||
if (scale == 0.0f) {
|
||||
qDebug() << "ASSERT because scale == 0.0f";
|
||||
|
@ -729,6 +753,7 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa
|
|||
if (glm::isinf(scale)) {
|
||||
qDebug() << "ASSERT because isinf(scale)";
|
||||
}
|
||||
qDebug() << "textPosition =" << textPosition;
|
||||
qDebug() << "windowSizeY =" << windowSizeY;
|
||||
qDebug() << "p1.y =" << p1.y;
|
||||
qDebug() << "p1.w =" << p1.w;
|
||||
|
@ -953,20 +978,12 @@ void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const {
|
|||
|
||||
void Avatar::setFaceModelURL(const QUrl& faceModelURL) {
|
||||
AvatarData::setFaceModelURL(faceModelURL);
|
||||
const QUrl DEFAULT_FACE_MODEL_URL = QUrl::fromLocalFile(PathUtils::resourcesPath() + "meshes/defaultAvatar_head.fst");
|
||||
getHead()->getFaceModel().setURL(_faceModelURL, DEFAULT_FACE_MODEL_URL, true, !isMyAvatar());
|
||||
getHead()->getFaceModel().setURL(_faceModelURL, AvatarData::defaultFullAvatarModelUrl(), true, !isMyAvatar());
|
||||
}
|
||||
|
||||
void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||
AvatarData::setSkeletonModelURL(skeletonModelURL);
|
||||
const QUrl DEFAULT_FULL_MODEL_URL = QUrl::fromLocalFile(PathUtils::resourcesPath() + "meshes/defaultAvatar_full.fst");
|
||||
const QUrl DEFAULT_SKELETON_MODEL_URL = QUrl::fromLocalFile(PathUtils::resourcesPath() + "meshes/defaultAvatar_body.fst");
|
||||
if (isMyAvatar()) {
|
||||
_skeletonModel.setURL(_skeletonModelURL,
|
||||
getUseFullAvatar() ? DEFAULT_FULL_MODEL_URL : DEFAULT_SKELETON_MODEL_URL, true, !isMyAvatar());
|
||||
} else {
|
||||
_skeletonModel.setURL(_skeletonModelURL, DEFAULT_SKELETON_MODEL_URL, true, !isMyAvatar());
|
||||
}
|
||||
_skeletonModel.setURL(_skeletonModelURL, AvatarData::defaultFullAvatarModelUrl(), true, !isMyAvatar());
|
||||
}
|
||||
|
||||
void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
|
||||
|
|
|
@ -91,6 +91,7 @@ public:
|
|||
|
||||
//setters
|
||||
void setDisplayingLookatVectors(bool displayingLookatVectors) { getHead()->setRenderLookatVectors(displayingLookatVectors); }
|
||||
void setDisplayingLookatTarget(bool displayingLookatTarget) { getHead()->setRenderLookatTarget(displayingLookatTarget); }
|
||||
void setIsLookAtTarget(const bool isLookAtTarget) { _isLookAtTarget = isLookAtTarget; }
|
||||
bool getIsLookAtTarget() const { return _isLookAtTarget; }
|
||||
//getters
|
||||
|
@ -149,8 +150,6 @@ public:
|
|||
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
||||
Q_INVOKABLE glm::vec3 getAngularVelocity() const { return _angularVelocity; }
|
||||
Q_INVOKABLE glm::vec3 getAngularAcceleration() const { return _angularAcceleration; }
|
||||
|
||||
virtual bool getUseFullAvatar() const { return false; }
|
||||
|
||||
/// Scales a world space position vector relative to the avatar position and scale
|
||||
/// \param vector position to be scaled. Will store the result
|
||||
|
|
|
@ -279,7 +279,7 @@ void AvatarManager::handleCollisionEvents(CollisionEvents& collisionEvents) {
|
|||
const QString& collisionSoundURL = myAvatar->getCollisionSoundURL();
|
||||
if (!collisionSoundURL.isEmpty()) {
|
||||
const float velocityChange = glm::length(collision.velocityChange);
|
||||
const float MIN_AVATAR_COLLISION_ACCELERATION = 0.01;
|
||||
const float MIN_AVATAR_COLLISION_ACCELERATION = 0.01f;
|
||||
const bool isSound = (collision.type == CONTACT_EVENT_TYPE_START) && (velocityChange > MIN_AVATAR_COLLISION_ACCELERATION);
|
||||
|
||||
if (!isSound) {
|
||||
|
|
|
@ -47,66 +47,10 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) {
|
|||
|
||||
if (isActive()) {
|
||||
setOffset(-_geometry->getFBXGeometry().neckPivot);
|
||||
|
||||
for (int i = 0; i < _rig->getJointStateCount(); i++) {
|
||||
maybeUpdateNeckAndEyeRotation(i);
|
||||
}
|
||||
|
||||
Model::simulateInternal(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const JointState& state, int index) {
|
||||
// get the rotation axes in joint space and use them to adjust the rotation
|
||||
glm::mat3 axes = glm::mat3_cast(glm::quat());
|
||||
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransform() *
|
||||
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||
state.getPreTransform() * glm::mat4_cast(state.getPreRotation())));
|
||||
glm::vec3 pitchYawRoll = safeEulerAngles(_owningHead->getFinalOrientationInLocalFrame());
|
||||
glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(),
|
||||
_owningHead->getTorsoTwist(),
|
||||
_owningHead->getFinalLeanSideways()));
|
||||
pitchYawRoll -= lean;
|
||||
_rig->setJointRotationInConstrainedFrame(index,
|
||||
glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2]))
|
||||
* glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1]))
|
||||
* glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0]))
|
||||
* state.getDefaultRotation(), DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentState, const JointState& state, int index) {
|
||||
// likewise with the eye joints
|
||||
// NOTE: at the moment we do the math in the world-frame, hence the inverse transform is more complex than usual.
|
||||
glm::mat4 inverse = glm::inverse(glm::mat4_cast(model->getRotation()) * parentState.getTransform() *
|
||||
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||
state.getPreTransform() * glm::mat4_cast(state.getPreRotation() * state.getDefaultRotation()));
|
||||
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT, 0.0f));
|
||||
glm::vec3 lookAtDelta = _owningHead->getCorrectedLookAtPosition() - model->getTranslation();
|
||||
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(lookAtDelta + glm::length(lookAtDelta) * _owningHead->getSaccade(), 1.0f));
|
||||
glm::quat between = rotationBetween(front, lookAt);
|
||||
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE;
|
||||
_rig->setJointRotationInConstrainedFrame(index, glm::angleAxis(glm::clamp(glm::angle(between),
|
||||
-MAX_ANGLE, MAX_ANGLE), glm::axis(between)) *
|
||||
state.getDefaultRotation(), DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
void FaceModel::maybeUpdateNeckAndEyeRotation(int index) {
|
||||
const JointState& state = _rig->getJointState(index);
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
const int parentIndex = state.getParentIndex();
|
||||
|
||||
// guard against out-of-bounds access to _jointStates
|
||||
if (parentIndex != -1 && parentIndex >= 0 && parentIndex < _rig->getJointStateCount()) {
|
||||
const JointState& parentState = _rig->getJointState(parentIndex);
|
||||
if (index == geometry.neckJointIndex) {
|
||||
maybeUpdateNeckRotation(parentState, state, index);
|
||||
|
||||
} else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
|
||||
maybeUpdateEyeRotation(this, parentState, state, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FaceModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
|
|
|
@ -26,10 +26,6 @@ public:
|
|||
|
||||
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
||||
|
||||
void maybeUpdateNeckRotation(const JointState& parentState, const JointState& state, int index);
|
||||
void maybeUpdateEyeRotation(Model* model, const JointState& parentState, const JointState& state, int index);
|
||||
void maybeUpdateNeckAndEyeRotation(int index);
|
||||
|
||||
/// Retrieve the positions of up to two eye meshes.
|
||||
/// \return whether or not both eye meshes were found
|
||||
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
|
||||
#include "Application.h"
|
||||
#include "Avatar.h"
|
||||
#include "DependencyManager.h"
|
||||
#include "GeometryUtil.h"
|
||||
#include "Head.h"
|
||||
#include "Menu.h"
|
||||
#include "Util.h"
|
||||
#include "devices/DdeFaceTracker.h"
|
||||
#include "devices/EyeTracker.h"
|
||||
#include "devices/Faceshift.h"
|
||||
#include "AvatarRig.h"
|
||||
|
||||
|
@ -44,6 +46,7 @@ Head::Head(Avatar* owningAvatar) :
|
|||
_mouth3(0.0f),
|
||||
_mouth4(0.0f),
|
||||
_renderLookatVectors(false),
|
||||
_renderLookatTarget(false),
|
||||
_saccade(0.0f, 0.0f, 0.0f),
|
||||
_saccadeTarget(0.0f, 0.0f, 0.0f),
|
||||
_leftEyeBlinkVelocity(0.0f),
|
||||
|
@ -116,29 +119,40 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
|||
applyEyelidOffset(getFinalOrientationInWorldFrame());
|
||||
}
|
||||
}
|
||||
|
||||
auto eyeTracker = DependencyManager::get<EyeTracker>();
|
||||
_isEyeTrackerConnected = eyeTracker->isTracking();
|
||||
}
|
||||
|
||||
if (!myAvatar->getStandingHMDSensorMode()) {
|
||||
// Twist the upper body to follow the rotation of the head, but only do this with my avatar,
|
||||
// since everyone else will see the full joint rotations for other people.
|
||||
const float BODY_FOLLOW_HEAD_YAW_RATE = 0.1f;
|
||||
const float BODY_FOLLOW_HEAD_FACTOR = 0.66f;
|
||||
float currentTwist = getTorsoTwist();
|
||||
setTorsoTwist(currentTwist + (getFinalYaw() * BODY_FOLLOW_HEAD_FACTOR - currentTwist) * BODY_FOLLOW_HEAD_YAW_RATE);
|
||||
}
|
||||
// Twist the upper body to follow the rotation of the head, but only do this with my avatar,
|
||||
// since everyone else will see the full joint rotations for other people.
|
||||
const float BODY_FOLLOW_HEAD_YAW_RATE = 0.1f;
|
||||
const float BODY_FOLLOW_HEAD_FACTOR = 0.66f;
|
||||
float currentTwist = getTorsoTwist();
|
||||
setTorsoTwist(currentTwist + (getFinalYaw() * BODY_FOLLOW_HEAD_FACTOR - currentTwist) * BODY_FOLLOW_HEAD_YAW_RATE);
|
||||
}
|
||||
|
||||
if (!(_isFaceTrackerConnected || billboard)) {
|
||||
// Update eye saccades
|
||||
const float AVERAGE_MICROSACCADE_INTERVAL = 1.0f;
|
||||
const float AVERAGE_SACCADE_INTERVAL = 6.0f;
|
||||
const float MICROSACCADE_MAGNITUDE = 0.002f;
|
||||
const float SACCADE_MAGNITUDE = 0.04f;
|
||||
const float NOMINAL_FRAME_RATE = 60.0f;
|
||||
|
||||
if (randFloat() < deltaTime / AVERAGE_MICROSACCADE_INTERVAL) {
|
||||
_saccadeTarget = MICROSACCADE_MAGNITUDE * randVector();
|
||||
} else if (randFloat() < deltaTime / AVERAGE_SACCADE_INTERVAL) {
|
||||
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
||||
if (!_isEyeTrackerConnected) {
|
||||
// Update eye saccades
|
||||
const float AVERAGE_MICROSACCADE_INTERVAL = 1.0f;
|
||||
const float AVERAGE_SACCADE_INTERVAL = 6.0f;
|
||||
const float MICROSACCADE_MAGNITUDE = 0.002f;
|
||||
const float SACCADE_MAGNITUDE = 0.04f;
|
||||
const float NOMINAL_FRAME_RATE = 60.0f;
|
||||
|
||||
if (randFloat() < deltaTime / AVERAGE_MICROSACCADE_INTERVAL) {
|
||||
_saccadeTarget = MICROSACCADE_MAGNITUDE * randVector();
|
||||
} else if (randFloat() < deltaTime / AVERAGE_SACCADE_INTERVAL) {
|
||||
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
||||
}
|
||||
_saccade += (_saccadeTarget - _saccade) * pow(0.5f, NOMINAL_FRAME_RATE * deltaTime);
|
||||
} else {
|
||||
_saccade = glm::vec3();
|
||||
}
|
||||
_saccade += (_saccadeTarget - _saccade) * pow(0.5f, NOMINAL_FRAME_RATE * deltaTime);
|
||||
|
||||
// Detect transition from talking to not; force blink after that and a delay
|
||||
bool forceBlink = false;
|
||||
|
@ -215,6 +229,9 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
|||
} else {
|
||||
_saccade = glm::vec3();
|
||||
}
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::FixGaze)) { // if debug menu turns off, use no saccade
|
||||
_saccade = glm::vec3();
|
||||
}
|
||||
|
||||
if (!isMine) {
|
||||
_faceModel.setLODDistance(static_cast<Avatar*>(_owningAvatar)->getLODDistance());
|
||||
|
@ -260,7 +277,7 @@ void Head::calculateMouthShapes() {
|
|||
void Head::applyEyelidOffset(glm::quat headOrientation) {
|
||||
// Adjusts the eyelid blendshape coefficients so that the eyelid follows the iris as the head pitches.
|
||||
|
||||
glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FRONT, getCorrectedLookAtPosition() - _eyePosition);
|
||||
glm::quat eyeRotation = rotationBetween(headOrientation * IDENTITY_FRONT, getLookAtPosition() - _eyePosition);
|
||||
eyeRotation = eyeRotation * glm::angleAxis(safeEulerAngles(headOrientation).y, IDENTITY_UP); // Rotation w.r.t. head
|
||||
float eyePitch = safeEulerAngles(eyeRotation).x;
|
||||
|
||||
|
@ -297,8 +314,18 @@ void Head::relaxLean(float deltaTime) {
|
|||
}
|
||||
|
||||
void Head::render(RenderArgs* renderArgs, float alpha, ViewFrustum* renderFrustum) {
|
||||
}
|
||||
|
||||
void Head::renderLookAts(RenderArgs* renderArgs) {
|
||||
renderLookAts(renderArgs, _leftEyePosition, _rightEyePosition);
|
||||
}
|
||||
|
||||
void Head::renderLookAts(RenderArgs* renderArgs, glm::vec3 leftEyePosition, glm::vec3 rightEyePosition) {
|
||||
if (_renderLookatVectors) {
|
||||
renderLookatVectors(renderArgs, _leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition());
|
||||
renderLookatVectors(renderArgs, leftEyePosition, rightEyePosition, getCorrectedLookAtPosition());
|
||||
}
|
||||
if (_renderLookatTarget) {
|
||||
renderLookatTarget(renderArgs, getCorrectedLookAtPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,6 +344,20 @@ glm::quat Head::getFinalOrientationInLocalFrame() const {
|
|||
return glm::quat(glm::radians(glm::vec3(getFinalPitch(), getFinalYaw(), getFinalRoll() )));
|
||||
}
|
||||
|
||||
// Everyone else's head keeps track of a lookAtPosition that everybody sees the same, and refers to where that head
|
||||
// is looking in model space -- e.g., at someone's eyeball, or between their eyes, or mouth, etc. Everyon's Interface
|
||||
// will have the same value for the lookAtPosition of any given head.
|
||||
//
|
||||
// Everyone else's head also keeps track of a correctedLookAtPosition that may be different for the same head within
|
||||
// different Interfaces. If that head is not looking at me, the correctedLookAtPosition is the same as the lookAtPosition.
|
||||
// However, if that head is looking at me, then I will attempt to adjust the lookAtPosition by the difference between
|
||||
// my (singular) eye position and my actual camera position. This adjustment is used on their eyeballs during rendering
|
||||
// (and also on any lookAt vector display for that head, during rendering). Note that:
|
||||
// 1. this adjustment can be made directly to the other head's eyeball joints, because we won't be send their joint information to others.
|
||||
// 2. the corrected position is a separate ivar, so the common/uncorrected value is still available
|
||||
//
|
||||
// There is a pun here: The two lookAtPositions will always be the same for my own avatar in my own Interface, because I
|
||||
// will not be looking at myself. (Even in a mirror, I will be looking at the camera.)
|
||||
glm::vec3 Head::getCorrectedLookAtPosition() {
|
||||
if (isLookingAtMe()) {
|
||||
return _correctedLookAtPosition;
|
||||
|
@ -337,21 +378,27 @@ void Head::setCorrectedLookAtPosition(glm::vec3 correctedLookAtPosition) {
|
|||
bool Head::isLookingAtMe() {
|
||||
// Allow for outages such as may be encountered during avatar movement
|
||||
quint64 now = usecTimestampNow();
|
||||
const quint64 LOOKING_AT_ME_GAP_ALLOWED = 1000000; // microseconds
|
||||
const quint64 LOOKING_AT_ME_GAP_ALLOWED = (5 * 1000 * 1000) / 60; // n frames, in microseconds
|
||||
return _isLookingAtMe || (now - _wasLastLookingAtMe) < LOOKING_AT_ME_GAP_ALLOWED;
|
||||
}
|
||||
|
||||
glm::quat Head::getCameraOrientation() const {
|
||||
// NOTE: Head::getCameraOrientation() is not used for orienting the camera "view" while in Oculus mode, so
|
||||
// you may wonder why this code is here. This method will be called while in Oculus mode to determine how
|
||||
// to change the driving direction while in Oculus mode. It is used to support driving toward where you're
|
||||
// to change the driving direction while in Oculus mode. It is used to support driving toward where you're
|
||||
// head is looking. Note that in oculus mode, your actual camera view and where your head is looking is not
|
||||
// always the same.
|
||||
if (qApp->isHMDMode()) {
|
||||
return getOrientation();
|
||||
MyAvatar* myAvatar = dynamic_cast<MyAvatar*>(_owningAvatar);
|
||||
if (myAvatar && myAvatar->getStandingHMDSensorMode()) {
|
||||
return glm::quat_cast(myAvatar->getSensorToWorldMatrix()) * myAvatar->getHMDSensorOrientation();
|
||||
} else {
|
||||
return getOrientation();
|
||||
}
|
||||
} else {
|
||||
Avatar* owningAvatar = static_cast<Avatar*>(_owningAvatar);
|
||||
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(glm::vec3(_basePitch, 0.0f, 0.0f)));
|
||||
}
|
||||
Avatar* owningAvatar = static_cast<Avatar*>(_owningAvatar);
|
||||
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(glm::vec3(_basePitch, 0.0f, 0.0f)));
|
||||
}
|
||||
|
||||
glm::quat Head::getEyeRotation(const glm::vec3& eyePosition) const {
|
||||
|
@ -409,4 +456,17 @@ void Head::renderLookatVectors(RenderArgs* renderArgs, glm::vec3 leftEyePosition
|
|||
geometryCache->renderLine(batch, rightEyePosition, lookatPosition, startColor, endColor, _rightEyeLookAtID);
|
||||
}
|
||||
|
||||
void Head::renderLookatTarget(RenderArgs* renderArgs, glm::vec3 lookatPosition) {
|
||||
auto& batch = *renderArgs->_batch;
|
||||
auto transform = Transform{};
|
||||
transform.setTranslation(lookatPosition);
|
||||
batch.setModelTransform(transform);
|
||||
|
||||
auto deferredLighting = DependencyManager::get<DeferredLightingEffect>();
|
||||
deferredLighting->bindSimpleProgram(batch);
|
||||
|
||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
const float LOOK_AT_TARGET_RADIUS = 0.075f;
|
||||
const glm::vec4 LOOK_AT_TARGET_COLOR = { 0.8f, 0.0f, 0.0f, 0.75f };
|
||||
geometryCache->renderSphere(batch, LOOK_AT_TARGET_RADIUS, 15, 15, LOOK_AT_TARGET_COLOR, true);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ public:
|
|||
void setAverageLoudness(float averageLoudness) { _averageLoudness = averageLoudness; }
|
||||
void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
|
||||
void setRenderLookatVectors(bool onOff) { _renderLookatVectors = onOff; }
|
||||
void setRenderLookatTarget(bool onOff) { _renderLookatTarget = onOff; }
|
||||
void renderLookAts(RenderArgs* renderArgs);
|
||||
void renderLookAts(RenderArgs* renderArgs, glm::vec3 leftEyePosition, glm::vec3 rightEyePosition);
|
||||
|
||||
/// \return orientationBase+Delta
|
||||
glm::quat getFinalOrientationInLocalFrame() const;
|
||||
|
@ -123,6 +126,7 @@ private:
|
|||
float _mouth3;
|
||||
float _mouth4;
|
||||
bool _renderLookatVectors;
|
||||
bool _renderLookatTarget;
|
||||
glm::vec3 _saccade;
|
||||
glm::vec3 _saccadeTarget;
|
||||
float _leftEyeBlinkVelocity;
|
||||
|
@ -151,6 +155,7 @@ private:
|
|||
|
||||
// private methods
|
||||
void renderLookatVectors(RenderArgs* renderArgs, glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition);
|
||||
void renderLookatTarget(RenderArgs* renderArgs, glm::vec3 lookatPosition);
|
||||
void calculateMouthShapes();
|
||||
void applyEyelidOffset(glm::quat headOrientation);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <AnimationHandle.h>
|
||||
#include <AudioClient.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <display-plugins/DisplayPlugin.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <NodeList.h>
|
||||
#include <udt/PacketHeaders.h>
|
||||
|
@ -34,7 +35,6 @@
|
|||
#include <UserActivityLogger.h>
|
||||
|
||||
#include "devices/Faceshift.h"
|
||||
#include "devices/OculusManager.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "AvatarManager.h"
|
||||
|
@ -97,6 +97,15 @@ MyAvatar::MyAvatar(RigPointer rig) :
|
|||
_eyeContactTarget(LEFT_EYE),
|
||||
_realWorldFieldOfView("realWorldFieldOfView",
|
||||
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
|
||||
_hmdSensorMatrix(),
|
||||
_hmdSensorOrientation(),
|
||||
_hmdSensorPosition(),
|
||||
_bodySensorMatrix(),
|
||||
_sensorToWorldMatrix(),
|
||||
_standingHMDSensorMode(false),
|
||||
_goToPending(false),
|
||||
_goToPosition(),
|
||||
_goToOrientation(),
|
||||
_rig(rig),
|
||||
_prevShouldDrawHead(true)
|
||||
{
|
||||
|
@ -142,6 +151,13 @@ void MyAvatar::reset() {
|
|||
}
|
||||
|
||||
void MyAvatar::update(float deltaTime) {
|
||||
|
||||
if (_goToPending) {
|
||||
setPosition(_goToPosition);
|
||||
setOrientation(_goToOrientation);
|
||||
_goToPending = false;
|
||||
}
|
||||
|
||||
if (_referential) {
|
||||
_referential->update();
|
||||
}
|
||||
|
@ -149,6 +165,7 @@ void MyAvatar::update(float deltaTime) {
|
|||
Head* head = getHead();
|
||||
head->relaxLean(deltaTime);
|
||||
updateFromTrackers(deltaTime);
|
||||
|
||||
// Get audio loudness data from audio input device
|
||||
auto audio = DependencyManager::get<AudioClient>();
|
||||
head->setAudioLoudness(audio->getLastInputLoudness());
|
||||
|
@ -228,6 +245,41 @@ void MyAvatar::simulate(float deltaTime) {
|
|||
maybeUpdateBillboard();
|
||||
}
|
||||
|
||||
glm::mat4 MyAvatar::getSensorToWorldMatrix() const {
|
||||
if (getStandingHMDSensorMode()) {
|
||||
return _sensorToWorldMatrix;
|
||||
} else {
|
||||
return createMatFromQuatAndPos(getWorldAlignedOrientation(), getDefaultEyePosition());
|
||||
}
|
||||
}
|
||||
|
||||
// best called at start of main loop just after we have a fresh hmd pose.
|
||||
// update internal body position from new hmd pose.
|
||||
void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
|
||||
// update the sensorMatrices based on the new hmd pose
|
||||
_hmdSensorMatrix = hmdSensorMatrix;
|
||||
_hmdSensorPosition = extractTranslation(hmdSensorMatrix);
|
||||
_hmdSensorOrientation = glm::quat_cast(hmdSensorMatrix);
|
||||
_bodySensorMatrix = deriveBodyFromHMDSensor();
|
||||
|
||||
if (getStandingHMDSensorMode()) {
|
||||
// set the body position/orientation to reflect motion due to the head.
|
||||
auto worldMat = _sensorToWorldMatrix * _bodySensorMatrix;
|
||||
setPosition(extractTranslation(worldMat));
|
||||
setOrientation(glm::quat_cast(worldMat));
|
||||
}
|
||||
}
|
||||
|
||||
// best called at end of main loop, just before rendering.
|
||||
// update sensor to world matrix from current body position and hmd sensor.
|
||||
// This is so the correct camera can be used for rendering.
|
||||
void MyAvatar::updateSensorToWorldMatrix() {
|
||||
// update the sensor mat so that the body position will end up in the desired
|
||||
// position when driven from the head.
|
||||
glm::mat4 desiredMat = createMatFromQuatAndPos(getOrientation(), getPosition());
|
||||
_sensorToWorldMatrix = desiredMat * glm::inverse(_bodySensorMatrix);
|
||||
}
|
||||
|
||||
// Update avatar head rotation with sensor data
|
||||
void MyAvatar::updateFromTrackers(float deltaTime) {
|
||||
glm::vec3 estimatedPosition, estimatedRotation;
|
||||
|
@ -242,7 +294,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
|
|||
bool inFacetracker = tracker && !tracker->isMuted();
|
||||
|
||||
if (inHmd) {
|
||||
estimatedPosition = qApp->getHeadPosition();
|
||||
estimatedPosition = extractTranslation(getHMDSensorMatrix());
|
||||
estimatedPosition.x *= -1.0f;
|
||||
_trackedHeadPosition = estimatedPosition;
|
||||
|
||||
|
@ -286,15 +338,18 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
|
|||
|
||||
Head* head = getHead();
|
||||
if (inHmd || isPlaying()) {
|
||||
head->setDeltaPitch(estimatedRotation.x);
|
||||
head->setDeltaYaw(estimatedRotation.y);
|
||||
if (!getStandingHMDSensorMode()) {
|
||||
head->setDeltaPitch(estimatedRotation.x);
|
||||
head->setDeltaYaw(estimatedRotation.y);
|
||||
head->setDeltaRoll(estimatedRotation.z);
|
||||
}
|
||||
} else {
|
||||
float magnifyFieldOfView = qApp->getFieldOfView() /
|
||||
_realWorldFieldOfView.get();
|
||||
head->setDeltaPitch(estimatedRotation.x * magnifyFieldOfView);
|
||||
head->setDeltaYaw(estimatedRotation.y * magnifyFieldOfView);
|
||||
head->setDeltaRoll(estimatedRotation.z);
|
||||
}
|
||||
head->setDeltaRoll(estimatedRotation.z);
|
||||
|
||||
// Update torso lean distance based on accelerometer data
|
||||
const float TORSO_LENGTH = 0.5f;
|
||||
|
@ -309,10 +364,12 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
|
|||
relativePosition.x = -relativePosition.x;
|
||||
}
|
||||
|
||||
head->setLeanSideways(glm::clamp(glm::degrees(atanf(relativePosition.x * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
head->setLeanForward(glm::clamp(glm::degrees(atanf(relativePosition.z * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
if (!(inHmd && getStandingHMDSensorMode())) {
|
||||
head->setLeanSideways(glm::clamp(glm::degrees(atanf(relativePosition.x * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
head->setLeanForward(glm::clamp(glm::degrees(atanf(relativePosition.z * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -343,6 +400,22 @@ glm::vec3 MyAvatar::getLeftPalmPosition() {
|
|||
return leftHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getLeftPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getLeftPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(LEFT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat MyAvatar::getLeftPalmRotation() {
|
||||
glm::quat leftRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getLeftHandJointIndex(), leftRotation);
|
||||
|
@ -358,6 +431,22 @@ glm::vec3 MyAvatar::getRightPalmPosition() {
|
|||
return rightHandPosition;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getRightPalmAngularVelocity() {
|
||||
const PalmData* palm = getHand()->getPalm(RIGHT_HAND_INDEX);
|
||||
if (palm != NULL) {
|
||||
return palm->getRawAngularVelocity();
|
||||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
glm::quat MyAvatar::getRightPalmRotation() {
|
||||
glm::quat rightRotation;
|
||||
getSkeletonModel().getJointRotationInWorldFrame(getSkeletonModel().getRightHandJointIndex(), rightRotation);
|
||||
|
@ -563,12 +652,7 @@ void MyAvatar::saveData() {
|
|||
settings.setValue("leanScale", _leanScale);
|
||||
settings.setValue("scale", _targetScale);
|
||||
|
||||
settings.setValue("useFullAvatar", _useFullAvatar);
|
||||
settings.setValue("fullAvatarURL", _fullAvatarURLFromPreferences);
|
||||
settings.setValue("faceModelURL", _headURLFromPreferences);
|
||||
settings.setValue("skeletonModelURL", _skeletonURLFromPreferences);
|
||||
settings.setValue("headModelName", _headModelName);
|
||||
settings.setValue("bodyModelName", _bodyModelName);
|
||||
settings.setValue("fullAvatarModelName", _fullAvatarModelName);
|
||||
|
||||
settings.beginWriteArray("attachmentData");
|
||||
|
@ -638,61 +722,10 @@ void MyAvatar::loadData() {
|
|||
_targetScale = loadSetting(settings, "scale", 1.0f);
|
||||
setScale(_scale);
|
||||
|
||||
// The old preferences only stored the face and skeleton URLs, we didn't track if the user wanted to use 1 or 2 urls
|
||||
// for their avatar, So we need to attempt to detect this old case and set our new preferences accordingly. If
|
||||
// the head URL is empty, then we will assume they are using a full url...
|
||||
bool isOldSettings = !(settings.contains("useFullAvatar") || settings.contains("fullAvatarURL"));
|
||||
|
||||
_useFullAvatar = settings.value("useFullAvatar").toBool();
|
||||
_headURLFromPreferences = settings.value("faceModelURL", DEFAULT_HEAD_MODEL_URL).toUrl();
|
||||
_fullAvatarURLFromPreferences = settings.value("fullAvatarURL", DEFAULT_FULL_AVATAR_MODEL_URL).toUrl();
|
||||
_skeletonURLFromPreferences = settings.value("skeletonModelURL", DEFAULT_BODY_MODEL_URL).toUrl();
|
||||
_headModelName = settings.value("headModelName", DEFAULT_HEAD_MODEL_NAME).toString();
|
||||
_bodyModelName = settings.value("bodyModelName", DEFAULT_BODY_MODEL_NAME).toString();
|
||||
_fullAvatarURLFromPreferences = settings.value("fullAvatarURL", AvatarData::defaultFullAvatarModelUrl()).toUrl();
|
||||
_fullAvatarModelName = settings.value("fullAvatarModelName", DEFAULT_FULL_AVATAR_MODEL_NAME).toString();
|
||||
|
||||
if (isOldSettings) {
|
||||
bool assumeFullAvatar = _headURLFromPreferences.isEmpty();
|
||||
_useFullAvatar = assumeFullAvatar;
|
||||
|
||||
if (_useFullAvatar) {
|
||||
_fullAvatarURLFromPreferences = settings.value("skeletonModelURL").toUrl();
|
||||
_headURLFromPreferences = DEFAULT_HEAD_MODEL_URL;
|
||||
_skeletonURLFromPreferences = DEFAULT_BODY_MODEL_URL;
|
||||
|
||||
QVariantHash fullAvatarFST = FSTReader::downloadMapping(_fullAvatarURLFromPreferences.toString());
|
||||
|
||||
_headModelName = "Default";
|
||||
_bodyModelName = "Default";
|
||||
_fullAvatarModelName = fullAvatarFST["name"].toString();
|
||||
|
||||
} else {
|
||||
_fullAvatarURLFromPreferences = DEFAULT_FULL_AVATAR_MODEL_URL;
|
||||
_skeletonURLFromPreferences = settings.value("skeletonModelURL", DEFAULT_BODY_MODEL_URL).toUrl();
|
||||
|
||||
if (_skeletonURLFromPreferences == DEFAULT_BODY_MODEL_URL) {
|
||||
_bodyModelName = DEFAULT_BODY_MODEL_NAME;
|
||||
} else {
|
||||
QVariantHash bodyFST = FSTReader::downloadMapping(_skeletonURLFromPreferences.toString());
|
||||
_bodyModelName = bodyFST["name"].toString();
|
||||
}
|
||||
|
||||
if (_headURLFromPreferences == DEFAULT_HEAD_MODEL_URL) {
|
||||
_headModelName = DEFAULT_HEAD_MODEL_NAME;
|
||||
} else {
|
||||
QVariantHash headFST = FSTReader::downloadMapping(_headURLFromPreferences.toString());
|
||||
_headModelName = headFST["name"].toString();
|
||||
}
|
||||
|
||||
_fullAvatarModelName = "Default";
|
||||
}
|
||||
}
|
||||
|
||||
if (_useFullAvatar) {
|
||||
useFullAvatarURL(_fullAvatarURLFromPreferences, _fullAvatarModelName);
|
||||
} else {
|
||||
useHeadAndBodyURLs(_headURLFromPreferences, _skeletonURLFromPreferences, _headModelName, _bodyModelName);
|
||||
}
|
||||
useFullAvatarURL(_fullAvatarURLFromPreferences, _fullAvatarModelName);
|
||||
|
||||
QVector<AttachmentData> attachmentData;
|
||||
int attachmentCount = settings.beginReadArray("attachmentData");
|
||||
|
@ -843,19 +876,13 @@ void MyAvatar::updateLookAtTargetAvatar() {
|
|||
const float HUMAN_EYE_SEPARATION = 0.065f;
|
||||
float myEyeSeparation = glm::length(getHead()->getLeftEyePosition() - getHead()->getRightEyePosition());
|
||||
gazeOffset = gazeOffset * HUMAN_EYE_SEPARATION / myEyeSeparation;
|
||||
|
||||
if (Application::getInstance()->isHMDMode()) {
|
||||
//avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getCamera()->getPosition()
|
||||
// + OculusManager::getMidEyePosition() + gazeOffset);
|
||||
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
|
||||
+ OculusManager::getMidEyePosition() + gazeOffset);
|
||||
} else {
|
||||
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
|
||||
+ gazeOffset);
|
||||
}
|
||||
avatar->getHead()->setCorrectedLookAtPosition(Application::getInstance()->getViewFrustum()->getPosition()
|
||||
+ gazeOffset);
|
||||
} else {
|
||||
avatar->getHead()->clearCorrectedLookAtPosition();
|
||||
}
|
||||
} else {
|
||||
avatar->getHead()->clearCorrectedLookAtPosition();
|
||||
}
|
||||
}
|
||||
auto avatarPointer = _lookAtTargetAvatar.lock();
|
||||
|
@ -889,7 +916,7 @@ eyeContactTarget MyAvatar::getEyeContactTarget() {
|
|||
}
|
||||
|
||||
glm::vec3 MyAvatar::getDefaultEyePosition() const {
|
||||
return _position + getWorldAlignedOrientation() * _skeletonModel.getDefaultEyeModelPosition();
|
||||
return getPosition() + getWorldAlignedOrientation() * _skeletonModel.getDefaultEyeModelPosition();
|
||||
}
|
||||
|
||||
const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f;
|
||||
|
@ -929,29 +956,6 @@ void MyAvatar::clearJointAnimationPriorities() {
|
|||
}
|
||||
}
|
||||
|
||||
QString MyAvatar::getModelDescription() const {
|
||||
QString result;
|
||||
if (_useFullAvatar) {
|
||||
if (!getFullAvartarModelName().isEmpty()) {
|
||||
result = "Full Avatar \"" + getFullAvartarModelName() + "\"";
|
||||
} else {
|
||||
result = "Full Avatar \"" + _fullAvatarURLFromPreferences.fileName() + "\"";
|
||||
}
|
||||
} else {
|
||||
if (!getHeadModelName().isEmpty()) {
|
||||
result = "Head \"" + getHeadModelName() + "\"";
|
||||
} else {
|
||||
result = "Head \"" + _headURLFromPreferences.fileName() + "\"";
|
||||
}
|
||||
if (!getBodyModelName().isEmpty()) {
|
||||
result += " and Body \"" + getBodyModelName() + "\"";
|
||||
} else {
|
||||
result += " and Body \"" + _skeletonURLFromPreferences.fileName() + "\"";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void MyAvatar::setFaceModelURL(const QUrl& faceModelURL) {
|
||||
|
||||
Avatar::setFaceModelURL(faceModelURL);
|
||||
|
@ -978,8 +982,6 @@ void MyAvatar::useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelN
|
|||
return;
|
||||
}
|
||||
|
||||
_useFullAvatar = true;
|
||||
|
||||
if (_fullAvatarURLFromPreferences != fullAvatarURL) {
|
||||
_fullAvatarURLFromPreferences = fullAvatarURL;
|
||||
if (modelName.isEmpty()) {
|
||||
|
@ -994,66 +996,14 @@ void MyAvatar::useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelN
|
|||
setFaceModelURL(QString());
|
||||
}
|
||||
|
||||
if (fullAvatarURL != getSkeletonModelURL()) {
|
||||
const QString& urlString = fullAvatarURL.toString();
|
||||
if (urlString.isEmpty() || (fullAvatarURL != getSkeletonModelURL())) {
|
||||
setSkeletonModelURL(fullAvatarURL);
|
||||
UserActivityLogger::getInstance().changedModel("skeleton", fullAvatarURL.toString());
|
||||
UserActivityLogger::getInstance().changedModel("skeleton", urlString);
|
||||
}
|
||||
sendIdentityPacket();
|
||||
}
|
||||
|
||||
void MyAvatar::useHeadURL(const QUrl& headURL, const QString& modelName) {
|
||||
useHeadAndBodyURLs(headURL, _skeletonURLFromPreferences, modelName, _bodyModelName);
|
||||
}
|
||||
|
||||
void MyAvatar::useBodyURL(const QUrl& bodyURL, const QString& modelName) {
|
||||
useHeadAndBodyURLs(_headURLFromPreferences, bodyURL, _headModelName, modelName);
|
||||
}
|
||||
|
||||
void MyAvatar::useHeadAndBodyURLs(const QUrl& headURL, const QUrl& bodyURL, const QString& headName, const QString& bodyName) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "useFullAvatarURL", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const QUrl&, headURL),
|
||||
Q_ARG(const QUrl&, bodyURL),
|
||||
Q_ARG(const QString&, headName),
|
||||
Q_ARG(const QString&, bodyName));
|
||||
return;
|
||||
}
|
||||
|
||||
_useFullAvatar = false;
|
||||
|
||||
if (_headURLFromPreferences != headURL) {
|
||||
_headURLFromPreferences = headURL;
|
||||
if (headName.isEmpty()) {
|
||||
QVariantHash headFST = FSTReader::downloadMapping(_headURLFromPreferences.toString());
|
||||
_headModelName = headFST["name"].toString();
|
||||
} else {
|
||||
_headModelName = headName;
|
||||
}
|
||||
}
|
||||
|
||||
if (_skeletonURLFromPreferences != bodyURL) {
|
||||
_skeletonURLFromPreferences = bodyURL;
|
||||
if (bodyName.isEmpty()) {
|
||||
QVariantHash bodyFST = FSTReader::downloadMapping(_skeletonURLFromPreferences.toString());
|
||||
_bodyModelName = bodyFST["name"].toString();
|
||||
} else {
|
||||
_bodyModelName = bodyName;
|
||||
}
|
||||
}
|
||||
|
||||
if (headURL != getFaceModelURL()) {
|
||||
setFaceModelURL(headURL);
|
||||
UserActivityLogger::getInstance().changedModel("head", headURL.toString());
|
||||
}
|
||||
|
||||
if (bodyURL != getSkeletonModelURL()) {
|
||||
setSkeletonModelURL(bodyURL);
|
||||
UserActivityLogger::getInstance().changedModel("skeleton", bodyURL.toString());
|
||||
}
|
||||
sendIdentityPacket();
|
||||
}
|
||||
|
||||
|
||||
void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
|
||||
Avatar::setAttachmentData(attachmentData);
|
||||
if (QThread::currentThread() != thread()) {
|
||||
|
@ -1163,6 +1113,24 @@ void MyAvatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, fl
|
|||
if (shouldRenderHead(renderArgs)) {
|
||||
getHead()->render(renderArgs, 1.0f, renderFrustum);
|
||||
}
|
||||
|
||||
if (qApp->isHMDMode()) {
|
||||
glm::vec3 cameraPosition = Application::getInstance()->getCamera()->getPosition();
|
||||
|
||||
glm::mat4 leftEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyePose(Eye::Left);
|
||||
glm::vec3 leftEyePosition = glm::vec3(leftEyePose[3]);
|
||||
glm::mat4 rightEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyePose(Eye::Right);
|
||||
glm::vec3 rightEyePosition = glm::vec3(rightEyePose[3]);
|
||||
glm::mat4 headPose = Application::getInstance()->getActiveDisplayPlugin()->getHeadPose();
|
||||
glm::vec3 headPosition = glm::vec3(headPose[3]);
|
||||
|
||||
getHead()->renderLookAts(renderArgs,
|
||||
cameraPosition + getOrientation() * (leftEyePosition - headPosition),
|
||||
cameraPosition + getOrientation() * (rightEyePosition - headPosition));
|
||||
} else {
|
||||
getHead()->renderLookAts(renderArgs);
|
||||
}
|
||||
|
||||
getHand()->render(renderArgs, true);
|
||||
}
|
||||
|
||||
|
@ -1209,11 +1177,7 @@ void MyAvatar::preRender(RenderArgs* renderArgs) {
|
|||
}
|
||||
|
||||
if (shouldDrawHead != _prevShouldDrawHead) {
|
||||
if (_useFullAvatar) {
|
||||
_skeletonModel.setCauterizeBones(!shouldDrawHead);
|
||||
} else {
|
||||
getHead()->getFaceModel().setVisibleInScene(shouldDrawHead, scene);
|
||||
}
|
||||
_skeletonModel.setCauterizeBones(!shouldDrawHead);
|
||||
}
|
||||
_prevShouldDrawHead = shouldDrawHead;
|
||||
}
|
||||
|
@ -1263,10 +1227,13 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
|||
glm::quat(glm::radians(glm::vec3(0.0f, _bodyYawDelta * deltaTime, 0.0f))));
|
||||
|
||||
if (qApp->isHMDMode()) {
|
||||
glm::quat orientation = glm::quat_cast(getSensorToWorldMatrix()) * getHMDSensorOrientation();
|
||||
glm::quat bodyOrientation = getWorldBodyOrientation();
|
||||
glm::quat localOrientation = glm::inverse(bodyOrientation) * orientation;
|
||||
|
||||
// these angles will be in radians
|
||||
glm::quat orientation = qApp->getHeadOrientation();
|
||||
// ... so they need to be converted to degrees before we do math...
|
||||
glm::vec3 euler = glm::eulerAngles(orientation) * DEGREES_PER_RADIAN;
|
||||
glm::vec3 euler = glm::eulerAngles(localOrientation) * DEGREES_PER_RADIAN;
|
||||
|
||||
//Invert yaw and roll when in mirror mode
|
||||
if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) {
|
||||
|
@ -1329,6 +1296,8 @@ glm::vec3 MyAvatar::applyKeyboardMotor(float deltaTime, const glm::vec3& localVe
|
|||
glm::vec3 direction = front + right + up;
|
||||
float directionLength = glm::length(direction);
|
||||
|
||||
//qCDebug(interfaceapp, "direction = (%.5f, %.5f, %.5f)", direction.x, direction.y, direction.z);
|
||||
|
||||
// Compute motor magnitude
|
||||
if (directionLength > EPSILON) {
|
||||
direction /= directionLength;
|
||||
|
@ -1433,7 +1402,6 @@ void MyAvatar::updatePosition(float deltaTime) {
|
|||
// update _moving flag based on speed
|
||||
const float MOVING_SPEED_THRESHOLD = 0.01f;
|
||||
_moving = speed > MOVING_SPEED_THRESHOLD;
|
||||
|
||||
}
|
||||
|
||||
void MyAvatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTime, float frequency) {
|
||||
|
@ -1528,32 +1496,31 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition,
|
|||
qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", "
|
||||
<< newPosition.y << ", " << newPosition.z;
|
||||
|
||||
glm::vec3 shiftedPosition = newPosition;
|
||||
|
||||
_goToPending = true;
|
||||
_goToPosition = newPosition;
|
||||
_goToOrientation = getOrientation();
|
||||
if (hasOrientation) {
|
||||
qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is "
|
||||
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
|
||||
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
|
||||
|
||||
// orient the user to face the target
|
||||
glm::quat quatOrientation = newOrientation;
|
||||
|
||||
if (shouldFaceLocation) {
|
||||
|
||||
quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// move the user a couple units away
|
||||
const float DISTANCE_TO_USER = 2.0f;
|
||||
shiftedPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
||||
_goToPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
||||
}
|
||||
|
||||
setOrientation(quatOrientation);
|
||||
_goToOrientation = quatOrientation;
|
||||
}
|
||||
|
||||
slamPosition(shiftedPosition);
|
||||
emit transformChanged();
|
||||
}
|
||||
|
||||
void MyAvatar::updateMotionBehavior() {
|
||||
void MyAvatar::updateMotionBehaviorFromMenu() {
|
||||
Menu* menu = Menu::getInstance();
|
||||
if (menu->isOptionChecked(MenuOption::KeyboardMotorControl)) {
|
||||
_motionBehaviors |= AVATAR_MOTION_KEYBOARD_MOTOR_ENABLED;
|
||||
|
@ -1568,6 +1535,11 @@ void MyAvatar::updateMotionBehavior() {
|
|||
_characterController.setEnabled(menu->isOptionChecked(MenuOption::EnableCharacterController));
|
||||
}
|
||||
|
||||
void MyAvatar::updateStandingHMDModeFromMenu() {
|
||||
Menu* menu = Menu::getInstance();
|
||||
_standingHMDSensorMode = menu->isOptionChecked(MenuOption::StandingHMDSensorMode);
|
||||
}
|
||||
|
||||
//Renders sixense laser pointers for UI selection with controllers
|
||||
void MyAvatar::renderLaserPointers(gpu::Batch& batch) {
|
||||
const float PALM_TIP_ROD_RADIUS = 0.002f;
|
||||
|
@ -1619,3 +1591,37 @@ void MyAvatar::relayDriveKeysToCharacterController() {
|
|||
_characterController.jump();
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getWorldBodyPosition() const {
|
||||
return transformPoint(_sensorToWorldMatrix, extractTranslation(_bodySensorMatrix));
|
||||
}
|
||||
|
||||
glm::quat MyAvatar::getWorldBodyOrientation() const {
|
||||
return glm::quat_cast(_sensorToWorldMatrix * _bodySensorMatrix);
|
||||
}
|
||||
|
||||
// derive avatar body position and orientation from the current HMD Sensor location.
|
||||
// results are in sensor space
|
||||
glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const {
|
||||
|
||||
// HMD is in sensor space.
|
||||
const glm::vec3 hmdPosition = getHMDSensorPosition();
|
||||
const glm::quat hmdOrientation = getHMDSensorOrientation();
|
||||
const glm::quat hmdOrientationYawOnly = cancelOutRollAndPitch(hmdOrientation);
|
||||
|
||||
// In sensor space, figure out where the avatar body should be,
|
||||
// by applying offsets from the avatar's neck & head joints.
|
||||
vec3 localEyes = _skeletonModel.getDefaultEyeModelPosition();
|
||||
vec3 localNeck(0.0f, 0.48f, 0.0f); // start with some kind of guess if the skeletonModel is not loaded yet.
|
||||
_skeletonModel.getLocalNeckPosition(localNeck);
|
||||
|
||||
// apply simplistic head/neck model
|
||||
// eyeToNeck offset is relative full HMD orientation.
|
||||
// while neckToRoot offset is only relative to HMDs yaw.
|
||||
glm::vec3 eyeToNeck = hmdOrientation * (localNeck - localEyes);
|
||||
glm::vec3 neckToRoot = hmdOrientationYawOnly * -localNeck;
|
||||
glm::vec3 bodyPos = hmdPosition + eyeToNeck + neckToRoot;
|
||||
|
||||
// avatar facing is determined solely by hmd orientation.
|
||||
return createMatFromQuatAndPos(hmdOrientationYawOnly, bodyPos);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,20 @@ public:
|
|||
void update(float deltaTime);
|
||||
void preRender(RenderArgs* renderArgs);
|
||||
|
||||
const glm::mat4& getHMDSensorMatrix() const { return _hmdSensorMatrix; }
|
||||
const glm::vec3& getHMDSensorPosition() const { return _hmdSensorPosition; }
|
||||
const glm::quat& getHMDSensorOrientation() const { return _hmdSensorOrientation; }
|
||||
glm::mat4 getSensorToWorldMatrix() const;
|
||||
|
||||
// best called at start of main loop just after we have a fresh hmd pose.
|
||||
// update internal body position from new hmd pose.
|
||||
void updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix);
|
||||
|
||||
// best called at end of main loop, just before rendering.
|
||||
// update sensor to world matrix from current body position and hmd sensor.
|
||||
// This is so the correct camera can be used for rendering.
|
||||
void updateSensorToWorldMatrix();
|
||||
|
||||
void setLeanScale(float scale) { _leanScale = scale; }
|
||||
void setRealWorldFieldOfView(float realWorldFov) { _realWorldFieldOfView.set(realWorldFov); }
|
||||
|
||||
|
@ -59,6 +73,7 @@ public:
|
|||
Q_INVOKABLE void startAnimation(const QString& url, float fps = 30.0f, float priority = 1.0f, bool loop = false,
|
||||
bool hold = false, float firstFrame = 0.0f,
|
||||
float lastFrame = FLT_MAX, const QStringList& maskedJoints = QStringList());
|
||||
|
||||
/// Stops an animation as identified by a URL.
|
||||
Q_INVOKABLE void stopAnimation(const QString& url);
|
||||
|
||||
|
@ -111,21 +126,8 @@ public:
|
|||
virtual void clearJointsData();
|
||||
|
||||
Q_INVOKABLE void useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelName = QString());
|
||||
Q_INVOKABLE void useHeadURL(const QUrl& headURL, const QString& modelName = QString());
|
||||
Q_INVOKABLE void useBodyURL(const QUrl& bodyURL, const QString& modelName = QString());
|
||||
Q_INVOKABLE void useHeadAndBodyURLs(const QUrl& headURL, const QUrl& bodyURL,
|
||||
const QString& headName = QString(), const QString& bodyName = QString());
|
||||
|
||||
Q_INVOKABLE virtual bool getUseFullAvatar() const { return _useFullAvatar; }
|
||||
Q_INVOKABLE const QUrl& getFullAvatarURLFromPreferences() const { return _fullAvatarURLFromPreferences; }
|
||||
Q_INVOKABLE const QUrl& getHeadURLFromPreferences() const { return _headURLFromPreferences; }
|
||||
Q_INVOKABLE const QUrl& getBodyURLFromPreferences() const { return _skeletonURLFromPreferences; }
|
||||
|
||||
Q_INVOKABLE const QString& getHeadModelName() const { return _headModelName; }
|
||||
Q_INVOKABLE const QString& getBodyModelName() const { return _bodyModelName; }
|
||||
Q_INVOKABLE const QString& getFullAvartarModelName() const { return _fullAvatarModelName; }
|
||||
|
||||
Q_INVOKABLE QString getModelDescription() const;
|
||||
Q_INVOKABLE const QString& getFullAvatarModelName() const { return _fullAvatarModelName; }
|
||||
|
||||
virtual void setAttachmentData(const QVector<AttachmentData>& attachmentData);
|
||||
|
||||
|
@ -148,6 +150,8 @@ public:
|
|||
static const float ZOOM_MAX;
|
||||
static const float ZOOM_DEFAULT;
|
||||
|
||||
bool getStandingHMDSensorMode() const { return _standingHMDSensorMode; }
|
||||
|
||||
public slots:
|
||||
void increaseSize();
|
||||
void decreaseSize();
|
||||
|
@ -162,11 +166,16 @@ public slots:
|
|||
glm::vec3 getThrust() { return _thrust; };
|
||||
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }
|
||||
|
||||
void updateMotionBehavior();
|
||||
void updateMotionBehaviorFromMenu();
|
||||
void updateStandingHMDModeFromMenu();
|
||||
|
||||
glm::vec3 getLeftPalmPosition();
|
||||
glm::vec3 getLeftPalmVelocity();
|
||||
glm::vec3 getLeftPalmAngularVelocity();
|
||||
glm::quat getLeftPalmRotation();
|
||||
glm::vec3 getRightPalmPosition();
|
||||
glm::vec3 getRightPalmVelocity();
|
||||
glm::vec3 getRightPalmAngularVelocity();
|
||||
glm::quat getRightPalmRotation();
|
||||
|
||||
void clearReferential();
|
||||
|
@ -189,6 +198,8 @@ signals:
|
|||
|
||||
private:
|
||||
|
||||
glm::vec3 getWorldBodyPosition() const;
|
||||
glm::quat getWorldBodyOrientation() const;
|
||||
QByteArray toByteArray();
|
||||
void simulate(float deltaTime);
|
||||
void updateFromTrackers(float deltaTime);
|
||||
|
@ -224,6 +235,10 @@ private:
|
|||
|
||||
void setVisibleInSceneIfReady(Model* model, render::ScenePointer scene, bool visiblity);
|
||||
|
||||
// derive avatar body position and orientation from the current HMD Sensor location.
|
||||
// results are in sensor space
|
||||
glm::mat4 deriveBodyFromHMDSensor() const;
|
||||
|
||||
glm::vec3 _gravity;
|
||||
|
||||
float _driveKeys[MAX_DRIVE_KEYS];
|
||||
|
@ -270,18 +285,31 @@ private:
|
|||
void initHeadBones();
|
||||
|
||||
// Avatar Preferences
|
||||
bool _useFullAvatar = false;
|
||||
QUrl _fullAvatarURLFromPreferences;
|
||||
QUrl _headURLFromPreferences;
|
||||
QUrl _skeletonURLFromPreferences;
|
||||
|
||||
QString _headModelName;
|
||||
QString _bodyModelName;
|
||||
QString _fullAvatarModelName;
|
||||
|
||||
// cache of the current HMD sensor position and orientation
|
||||
// in sensor space.
|
||||
glm::mat4 _hmdSensorMatrix;
|
||||
glm::quat _hmdSensorOrientation;
|
||||
glm::vec3 _hmdSensorPosition;
|
||||
|
||||
// cache of the current body position and orientation of the avatar's body,
|
||||
// in sensor space.
|
||||
glm::mat4 _bodySensorMatrix;
|
||||
|
||||
// used to transform any sensor into world space, including the _hmdSensorMat, or hand controllers.
|
||||
glm::mat4 _sensorToWorldMatrix;
|
||||
|
||||
bool _standingHMDSensorMode;
|
||||
|
||||
bool _goToPending;
|
||||
glm::vec3 _goToPosition;
|
||||
glm::quat _goToOrientation;
|
||||
|
||||
std::unordered_set<int> _headBoneSet;
|
||||
RigPointer _rig;
|
||||
bool _prevShouldDrawHead;
|
||||
std::unordered_set<int> _headBoneSet;
|
||||
};
|
||||
|
||||
#endif // hifi_MyAvatar_h
|
||||
|
|
|
@ -97,7 +97,7 @@ void SkeletonModel::initJointStates(QVector<JointState> states) {
|
|||
}
|
||||
|
||||
const float PALM_PRIORITY = DEFAULT_PRIORITY;
|
||||
|
||||
// Called within Model::simulate call, below.
|
||||
void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||
if (_owningAvatar->isMyAvatar()) {
|
||||
_rig->computeMotionAnimationState(deltaTime, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation());
|
||||
|
@ -105,24 +105,43 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
Model::updateRig(deltaTime, parentTransform);
|
||||
if (_owningAvatar->isMyAvatar()) {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
Head* head = _owningAvatar->getHead();
|
||||
|
||||
Rig::HeadParameters params;
|
||||
params.leanSideways = _owningAvatar->getHead()->getFinalLeanSideways();
|
||||
params.leanForward = _owningAvatar->getHead()->getFinalLeanSideways();
|
||||
params.torsoTwist = _owningAvatar->getHead()->getTorsoTwist();
|
||||
params.localHeadOrientation = _owningAvatar->getHead()->getFinalOrientationInLocalFrame();
|
||||
params.worldHeadOrientation = _owningAvatar->getHead()->getFinalOrientationInWorldFrame();
|
||||
params.eyeLookAt = _owningAvatar->getHead()->getCorrectedLookAtPosition();
|
||||
params.eyeSaccade = _owningAvatar->getHead()->getSaccade();
|
||||
params.modelRotation = getRotation();
|
||||
params.modelTranslation = getTranslation();
|
||||
params.leanSideways = head->getFinalLeanSideways();
|
||||
params.leanForward = head->getFinalLeanForward();
|
||||
params.torsoTwist = head->getTorsoTwist();
|
||||
params.localHeadOrientation = head->getFinalOrientationInLocalFrame();
|
||||
params.worldHeadOrientation = head->getFinalOrientationInWorldFrame();
|
||||
params.eyeLookAt = head->getLookAtPosition();
|
||||
params.eyeSaccade = head->getSaccade();
|
||||
params.leanJointIndex = geometry.leanJointIndex;
|
||||
params.neckJointIndex = geometry.neckJointIndex;
|
||||
params.leftEyeJointIndex = geometry.leftEyeJointIndex;
|
||||
params.rightEyeJointIndex = geometry.rightEyeJointIndex;
|
||||
|
||||
_rig->updateFromHeadParameters(params);
|
||||
} else {
|
||||
// This is a little more work than we really want.
|
||||
//
|
||||
// Other avatars joint, including their eyes, should already be set just like any other joints
|
||||
// from the wire data. But when looking at me, we want the eyes to use the corrected lookAt.
|
||||
//
|
||||
// Thus this should really only be ... else if (_owningAvatar->getHead()->isLookingAtMe()) {...
|
||||
// However, in the !isLookingAtMe case, the eyes aren't rotating the way they should right now.
|
||||
// (They latch their looking at me position.) We will revisit that as priorities allow.
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
Head* head = _owningAvatar->getHead();
|
||||
_rig->updateEyeJoints(geometry.leftEyeJointIndex, geometry.rightEyeJointIndex,
|
||||
getTranslation(), getRotation(),
|
||||
head->getFinalOrientationInWorldFrame(), head->getCorrectedLookAtPosition());
|
||||
}
|
||||
}
|
||||
|
||||
// Called by Avatar::simulate after it has set the joint states (fullUpdate true if changed),
|
||||
// but just before head has been simulated.
|
||||
void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||
setTranslation(_owningAvatar->getSkeletonPosition());
|
||||
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
@ -390,6 +409,10 @@ bool SkeletonModel::getNeckPosition(glm::vec3& neckPosition) const {
|
|||
return isActive() && getJointPositionInWorldFrame(_geometry->getFBXGeometry().neckJointIndex, neckPosition);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getLocalNeckPosition(glm::vec3& neckPosition) const {
|
||||
return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
|
|
|
@ -80,6 +80,8 @@ public:
|
|||
/// \return whether or not the neck was found
|
||||
bool getNeckPosition(glm::vec3& neckPosition) const;
|
||||
|
||||
bool getLocalNeckPosition(glm::vec3& neckPosition) const;
|
||||
|
||||
/// Returns the rotation of the neck joint's parent from default orientation
|
||||
/// \return whether or not the neck was found
|
||||
bool getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,12 +11,13 @@
|
|||
#ifndef hifi_3DConnexionClient_h
|
||||
#define hifi_3DConnexionClient_h
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qlibrary.h>
|
||||
#include <QObject>
|
||||
#include <QLibrary>
|
||||
#include <input-plugins/UserInputMapper.h>
|
||||
|
||||
#include "InterfaceLogging.h"
|
||||
#include "Application.h"
|
||||
|
||||
#include "ui/UserInputMapper.h"
|
||||
|
||||
#ifndef HAVE_3DCONNEXIONCLIENT
|
||||
class ConnexionClient : public QObject {
|
||||
|
|
305
interface/src/devices/EyeTracker.cpp
Normal file
305
interface/src/devices/EyeTracker.cpp
Normal file
|
@ -0,0 +1,305 @@
|
|||
//
|
||||
// EyeTracker.cpp
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by David Rowe on 27 Jul 2015.
|
||||
// Copyright 2015 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 "EyeTracker.h"
|
||||
|
||||
#include <QFuture>
|
||||
#include <QMessageBox>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "InterfaceLogging.h"
|
||||
#include "OctreeConstants.h"
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
char* HIGH_FIDELITY_EYE_TRACKER_CALIBRATION = "HighFidelityEyeTrackerCalibration";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
static void CALLBACK eyeTrackerCallback(smi_CallbackDataStruct* data) {
|
||||
auto eyeTracker = DependencyManager::get<EyeTracker>();
|
||||
if (eyeTracker) { // Guard against a few callbacks that continue to be received after smi_quit().
|
||||
eyeTracker->processData(data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
EyeTracker::~EyeTracker() {
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
if (_isStreaming) {
|
||||
int result = smi_quit();
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error terminating tracking:" << smiReturnValueToString(result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
void EyeTracker::processData(smi_CallbackDataStruct* data) {
|
||||
_lastProcessDataTimestamp = usecTimestampNow();
|
||||
|
||||
if (!_isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data->type == SMI_SIMPLE_GAZE_SAMPLE) {
|
||||
// Calculate the intersections of the left and right eye look-at vectors with a vertical plane along the monocular
|
||||
// gaze direction. Average these positions to give the look-at point.
|
||||
// If the eyes are parallel or diverged, gaze at a distant look-at point calculated the same as for non eye tracking.
|
||||
// Line-plane intersection: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
|
||||
|
||||
smi_SampleHMDStruct* sample = (smi_SampleHMDStruct*)data->result;
|
||||
// The iViewHMD coordinate system has x and z axes reversed compared to Interface, i.e., wearing the HMD:
|
||||
// - x is left
|
||||
// - y is up
|
||||
// - z is forwards
|
||||
|
||||
// Plane
|
||||
smi_Vec3d point = sample->gazeBasePoint; // mm
|
||||
smi_Vec3d direction = sample->gazeDirection;
|
||||
glm::vec3 planePoint = glm::vec3(-point.x, point.y, -point.z) / 1000.0f;
|
||||
glm::vec3 planeNormal = glm::vec3(-direction.z, 0.0f, direction.x);
|
||||
glm::vec3 monocularDirection = glm::vec3(-direction.x, direction.y, -direction.z);
|
||||
|
||||
// Left eye
|
||||
point = sample->left.gazeBasePoint; // mm
|
||||
direction = sample->left.gazeDirection;
|
||||
glm::vec3 leftLinePoint = glm::vec3(-point.x, point.y, -point.z) / 1000.0f;
|
||||
glm::vec3 leftLineDirection = glm::vec3(-direction.x, direction.y, -direction.z);
|
||||
|
||||
// Right eye
|
||||
point = sample->right.gazeBasePoint; // mm
|
||||
direction = sample->right.gazeDirection;
|
||||
glm::vec3 rightLinePoint = glm::vec3(-point.x, point.y, -point.z) / 1000.0f;
|
||||
glm::vec3 rightLineDirection = glm::vec3(-direction.x, direction.y, -direction.z);
|
||||
|
||||
// Plane - line dot products
|
||||
float leftLinePlaneDotProduct = glm::dot(leftLineDirection, planeNormal);
|
||||
float rightLinePlaneDotProduct = glm::dot(rightLineDirection, planeNormal);
|
||||
|
||||
// Gaze into distance if eyes are parallel or diverged; otherwise the look-at is the average of look-at points
|
||||
glm::vec3 lookAtPosition;
|
||||
if (abs(leftLinePlaneDotProduct) <= FLT_EPSILON || abs(rightLinePlaneDotProduct) <= FLT_EPSILON) {
|
||||
lookAtPosition = monocularDirection * (float)TREE_SCALE;
|
||||
} else {
|
||||
float leftDistance = glm::dot(planePoint - leftLinePoint, planeNormal) / leftLinePlaneDotProduct;
|
||||
float rightDistance = glm::dot(planePoint - rightLinePoint, planeNormal) / rightLinePlaneDotProduct;
|
||||
if (leftDistance <= 0.0f || rightDistance <= 0.0f
|
||||
|| leftDistance > (float)TREE_SCALE || rightDistance > (float)TREE_SCALE) {
|
||||
lookAtPosition = monocularDirection * (float)TREE_SCALE;
|
||||
} else {
|
||||
glm::vec3 leftIntersectionPoint = leftLinePoint + leftDistance * leftLineDirection;
|
||||
glm::vec3 rightIntersectionPoint = rightLinePoint + rightDistance * rightLineDirection;
|
||||
lookAtPosition = (leftIntersectionPoint + rightIntersectionPoint) / 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (glm::isnan(lookAtPosition.x) || glm::isnan(lookAtPosition.y) || glm::isnan(lookAtPosition.z)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_lookAtPosition = lookAtPosition;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void EyeTracker::init() {
|
||||
if (_isInitialized) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Already initialized";
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
int result = smi_setCallback(eyeTrackerCallback);
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error setting callback:" << smiReturnValueToString(result);
|
||||
QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result));
|
||||
} else {
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
connect(&_startStreamingWatcher, SIGNAL(finished()), this, SLOT(onStreamStarted()));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
int EyeTracker::startStreaming(bool simulate) {
|
||||
return smi_startStreaming(simulate); // This call blocks execution.
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
void EyeTracker::onStreamStarted() {
|
||||
int result = _startStreamingWatcher.result();
|
||||
_isStreaming = (result == SMI_RET_SUCCESS);
|
||||
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result);
|
||||
// Display error dialog unless SMI SDK has already displayed an error message.
|
||||
if (result != SMI_ERROR_HMD_NOT_SUPPORTED) {
|
||||
QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result));
|
||||
}
|
||||
} else {
|
||||
qCDebug(interfaceapp) << "Eye Tracker: Started streaming";
|
||||
}
|
||||
|
||||
if (_isStreaming) {
|
||||
// Automatically load calibration if one has been saved.
|
||||
QString availableCalibrations = QString(smi_getAvailableCalibrations());
|
||||
if (availableCalibrations.contains(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION)) {
|
||||
result = smi_loadCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION);
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error loading calibration:" << smiReturnValueToString(result);
|
||||
QMessageBox::warning(nullptr, "Eye Tracker Error", "Error loading calibration"
|
||||
+ smiReturnValueToString(result));
|
||||
} else {
|
||||
qCDebug(interfaceapp) << "Eye Tracker: Loaded calibration";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void EyeTracker::setEnabled(bool enabled, bool simulate) {
|
||||
if (!_isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
qCDebug(interfaceapp) << "Eye Tracker: Set enabled =" << enabled << ", simulate =" << simulate;
|
||||
|
||||
// There is no smi_stopStreaming() method and after an smi_quit(), streaming cannot be restarted (at least not for
|
||||
// simulated data). So keep streaming once started in case tracking is re-enabled after stopping.
|
||||
|
||||
// Try to stop streaming if changing whether simulating or not.
|
||||
if (enabled && _isStreaming && _isStreamSimulating != simulate) {
|
||||
int result = smi_quit();
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error stopping streaming:" << smiReturnValueToString(result);
|
||||
}
|
||||
_isStreaming = false;
|
||||
}
|
||||
|
||||
if (enabled && !_isStreaming) {
|
||||
// Start SMI streaming in a separate thread because it blocks.
|
||||
QFuture<int> future = QtConcurrent::run(this, &EyeTracker::startStreaming, simulate);
|
||||
_startStreamingWatcher.setFuture(future);
|
||||
_isStreamSimulating = simulate;
|
||||
}
|
||||
|
||||
_isEnabled = enabled;
|
||||
_isSimulating = simulate;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void EyeTracker::reset() {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
bool EyeTracker::isTracking() const {
|
||||
static const quint64 ACTIVE_TIMEOUT_USECS = 2000000; // 2 secs
|
||||
return _isEnabled && (usecTimestampNow() - _lastProcessDataTimestamp < ACTIVE_TIMEOUT_USECS);
|
||||
}
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
void EyeTracker::calibrate(int points) {
|
||||
|
||||
if (!_isStreaming) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Cannot calibrate because not streaming";
|
||||
return;
|
||||
}
|
||||
|
||||
smi_CalibrationHMDStruct* calibrationHMDStruct;
|
||||
smi_createCalibrationHMDStruct(&calibrationHMDStruct);
|
||||
|
||||
smi_CalibrationTypeEnum calibrationType;
|
||||
switch (points) {
|
||||
case 1:
|
||||
calibrationType = SMI_ONE_POINT_CALIBRATION;
|
||||
qCDebug(interfaceapp) << "Eye Tracker: One point calibration";
|
||||
break;
|
||||
case 3:
|
||||
calibrationType = SMI_THREE_POINT_CALIBRATION;
|
||||
qCDebug(interfaceapp) << "Eye Tracker: Three point calibration";
|
||||
break;
|
||||
case 5:
|
||||
calibrationType = SMI_FIVE_POINT_CALIBRATION;
|
||||
qCDebug(interfaceapp) << "Eye Tracker: Five point calibration";
|
||||
break;
|
||||
default:
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Invalid calibration specified";
|
||||
return;
|
||||
}
|
||||
|
||||
calibrationHMDStruct->type = calibrationType;
|
||||
calibrationHMDStruct->backgroundColor->blue = 0.5;
|
||||
calibrationHMDStruct->backgroundColor->green = 0.5;
|
||||
calibrationHMDStruct->backgroundColor->red = 0.5;
|
||||
calibrationHMDStruct->foregroundColor->blue = 1.0;
|
||||
calibrationHMDStruct->foregroundColor->green = 1.0;
|
||||
calibrationHMDStruct->foregroundColor->red = 1.0;
|
||||
|
||||
int result = smi_setupCalibration(calibrationHMDStruct);
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error setting up calibration:" << smiReturnValueToString(result);
|
||||
return;
|
||||
} else {
|
||||
result = smi_calibrate();
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error performing calibration:" << smiReturnValueToString(result);
|
||||
} else {
|
||||
result = smi_saveCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION);
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
qCWarning(interfaceapp) << "Eye Tracker: Error saving calibration:" << smiReturnValueToString(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != SMI_RET_SUCCESS) {
|
||||
QMessageBox::warning(nullptr, "Eye Tracker Error", "Calibration error: " + smiReturnValueToString(result));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
QString EyeTracker::smiReturnValueToString(int value) {
|
||||
switch (value)
|
||||
{
|
||||
case smi_ErrorReturnValue::SMI_ERROR_NO_CALLBACK_SET:
|
||||
return "No callback set";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_CONNECTING_TO_HMD:
|
||||
return "Error connecting to HMD";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_HMD_NOT_SUPPORTED:
|
||||
return "HMD not supported";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_NOT_IMPLEMENTED:
|
||||
return "Not implmented";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_INVALID_PARAMETER:
|
||||
return "Invalid parameter";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_EYECAMERAS_NOT_AVAILABLE:
|
||||
return "Eye cameras not available";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_OCULUS_RUNTIME_NOT_SUPPORTED:
|
||||
return "Oculus runtime not supported";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_FILE_NOT_FOUND:
|
||||
return "File not found";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_FILE_EMPTY:
|
||||
return "File empty";
|
||||
case smi_ErrorReturnValue::SMI_ERROR_UNKNOWN:
|
||||
return "Unknown error";
|
||||
default:
|
||||
QString number;
|
||||
number.setNum(value);
|
||||
return number;
|
||||
}
|
||||
}
|
||||
#endif
|
71
interface/src/devices/EyeTracker.h
Normal file
71
interface/src/devices/EyeTracker.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// EyeTracker.h
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by David Rowe on 27 Jul 2015.
|
||||
// Copyright 2015 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_EyeTracker_h
|
||||
#define hifi_EyeTracker_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
#include <iViewHMDAPI.h>
|
||||
#endif
|
||||
|
||||
|
||||
class EyeTracker : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
public:
|
||||
~EyeTracker();
|
||||
|
||||
void init();
|
||||
void setEnabled(bool enabled, bool simulate);
|
||||
void reset();
|
||||
|
||||
bool isInitialized() const { return _isInitialized; }
|
||||
bool isEnabled() const { return _isEnabled; }
|
||||
bool isTracking() const;
|
||||
bool isSimulating() const { return _isSimulating; }
|
||||
|
||||
glm::vec3 getLookAtPosition() const { return _lookAtPosition; } // From mid eye point in head frame.
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
void processData(smi_CallbackDataStruct* data);
|
||||
|
||||
void calibrate(int points);
|
||||
|
||||
int startStreaming(bool simulate);
|
||||
|
||||
private slots:
|
||||
void onStreamStarted();
|
||||
#endif
|
||||
|
||||
private:
|
||||
QString smiReturnValueToString(int value);
|
||||
|
||||
bool _isInitialized = false;
|
||||
bool _isEnabled = false;
|
||||
bool _isSimulating = false;
|
||||
bool _isStreaming = false;
|
||||
bool _isStreamSimulating = false;
|
||||
|
||||
quint64 _lastProcessDataTimestamp;
|
||||
|
||||
glm::vec3 _lookAtPosition;
|
||||
|
||||
QFutureWatcher<int> _startStreamingWatcher;
|
||||
};
|
||||
|
||||
#endif // hifi_EyeTracker_h
|
|
@ -1,887 +0,0 @@
|
|||
//
|
||||
// OculusManager.cpp
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by Stephen Birarda on 5/9/13.
|
||||
// Refactored by Ben Arnold on 6/30/2014
|
||||
// Copyright 2012 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 "OculusManager.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGuiApplication>
|
||||
#include <gpu/GPUConfig.h>
|
||||
#include <QScreen>
|
||||
#include <CursorManager.h>
|
||||
#include <QOpenGLTimerQuery>
|
||||
#include <QGLWidget>
|
||||
|
||||
|
||||
#include <avatar/AvatarManager.h>
|
||||
#include <avatar/MyAvatar.h>
|
||||
#include <GlWindow.h>
|
||||
#include <gpu/GLBackend.h>
|
||||
#include <OglplusHelpers.h>
|
||||
#include <PathUtils.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <UserActivityLogger.h>
|
||||
#include <FramebufferCache.h>
|
||||
|
||||
#include <OVR_CAPI_GL.h>
|
||||
|
||||
#include "InterfaceLogging.h"
|
||||
#include "Application.h"
|
||||
#include "ui/overlays/Text3DOverlay.h"
|
||||
|
||||
template <typename Function>
|
||||
void for_each_eye(Function function) {
|
||||
for (ovrEyeType eye = ovrEyeType::ovrEye_Left;
|
||||
eye < ovrEyeType::ovrEye_Count;
|
||||
eye = static_cast<ovrEyeType>(eye + 1)) {
|
||||
function(eye);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Function>
|
||||
void for_each_eye(const ovrHmd & hmd, Function function) {
|
||||
for (int i = 0; i < ovrEye_Count; ++i) {
|
||||
ovrEyeType eye = hmd->EyeRenderOrder[i];
|
||||
function(eye);
|
||||
}
|
||||
}
|
||||
enum CalibrationState {
|
||||
UNCALIBRATED,
|
||||
WAITING_FOR_DELTA,
|
||||
WAITING_FOR_ZERO,
|
||||
WAITING_FOR_ZERO_HELD,
|
||||
CALIBRATED
|
||||
};
|
||||
|
||||
inline glm::mat4 toGlm(const ovrMatrix4f & om) {
|
||||
return glm::transpose(glm::make_mat4(&om.M[0][0]));
|
||||
}
|
||||
|
||||
inline glm::mat4 toGlm(const ovrFovPort & fovport, float nearPlane = 0.01f, float farPlane = 10000.0f) {
|
||||
return toGlm(ovrMatrix4f_Projection(fovport, nearPlane, farPlane, true));
|
||||
}
|
||||
|
||||
inline glm::vec3 toGlm(const ovrVector3f & ov) {
|
||||
return glm::make_vec3(&ov.x);
|
||||
}
|
||||
|
||||
inline glm::vec2 toGlm(const ovrVector2f & ov) {
|
||||
return glm::make_vec2(&ov.x);
|
||||
}
|
||||
|
||||
inline glm::ivec2 toGlm(const ovrVector2i & ov) {
|
||||
return glm::ivec2(ov.x, ov.y);
|
||||
}
|
||||
|
||||
inline glm::uvec2 toGlm(const ovrSizei & ov) {
|
||||
return glm::uvec2(ov.w, ov.h);
|
||||
}
|
||||
|
||||
inline glm::quat toGlm(const ovrQuatf & oq) {
|
||||
return glm::make_quat(&oq.x);
|
||||
}
|
||||
|
||||
inline glm::mat4 toGlm(const ovrPosef & op) {
|
||||
glm::mat4 orientation = glm::mat4_cast(toGlm(op.Orientation));
|
||||
glm::mat4 translation = glm::translate(glm::mat4(), toGlm(op.Position));
|
||||
return translation * orientation;
|
||||
}
|
||||
|
||||
inline ovrMatrix4f ovrFromGlm(const glm::mat4 & m) {
|
||||
ovrMatrix4f result;
|
||||
glm::mat4 transposed(glm::transpose(m));
|
||||
memcpy(result.M, &(transposed[0][0]), sizeof(float) * 16);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline ovrVector3f ovrFromGlm(const glm::vec3 & v) {
|
||||
return{ v.x, v.y, v.z };
|
||||
}
|
||||
|
||||
inline ovrVector2f ovrFromGlm(const glm::vec2 & v) {
|
||||
return{ v.x, v.y };
|
||||
}
|
||||
|
||||
inline ovrSizei ovrFromGlm(const glm::uvec2 & v) {
|
||||
return{ (int)v.x, (int)v.y };
|
||||
}
|
||||
|
||||
inline ovrQuatf ovrFromGlm(const glm::quat & q) {
|
||||
return{ q.x, q.y, q.z, q.w };
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
// A base class for FBO wrappers that need to use the Oculus C
|
||||
// API to manage textures via ovrHmd_CreateSwapTextureSetGL,
|
||||
// ovrHmd_CreateMirrorTextureGL, etc
|
||||
template <typename C>
|
||||
struct RiftFramebufferWrapper : public FramebufferWrapper<C, char> {
|
||||
ovrHmd hmd;
|
||||
RiftFramebufferWrapper(const ovrHmd & hmd) : hmd(hmd) {
|
||||
color = 0;
|
||||
depth = 0;
|
||||
};
|
||||
|
||||
void Resize(const uvec2 & size) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oglplus::GetName(fbo));
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
this->size = size;
|
||||
initColor();
|
||||
initDone();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void initDepth() override final {
|
||||
}
|
||||
};
|
||||
|
||||
// A wrapper for constructing and using a swap texture set,
|
||||
// where each frame you draw to a texture via the FBO,
|
||||
// then submit it and increment to the next texture.
|
||||
// The Oculus SDK manages the creation and destruction of
|
||||
// the textures
|
||||
struct SwapFramebufferWrapper : public RiftFramebufferWrapper<ovrSwapTextureSet*> {
|
||||
SwapFramebufferWrapper(const ovrHmd & hmd)
|
||||
: RiftFramebufferWrapper(hmd) {
|
||||
}
|
||||
|
||||
~SwapFramebufferWrapper() {
|
||||
if (color) {
|
||||
ovrHmd_DestroySwapTextureSet(hmd, color);
|
||||
color = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Increment() {
|
||||
++color->CurrentIndex;
|
||||
color->CurrentIndex %= color->TextureCount;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void initColor() override {
|
||||
if (color) {
|
||||
ovrHmd_DestroySwapTextureSet(hmd, color);
|
||||
color = nullptr;
|
||||
}
|
||||
|
||||
ovrResult result = ovrHmd_CreateSwapTextureSetGL(hmd, GL_RGBA, size.x, size.y, &color);
|
||||
Q_ASSERT(OVR_SUCCESS(result));
|
||||
|
||||
for (int i = 0; i < color->TextureCount; ++i) {
|
||||
ovrGLTexture& ovrTex = (ovrGLTexture&)color->Textures[i];
|
||||
glBindTexture(GL_TEXTURE_2D, ovrTex.OGL.TexId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
virtual void initDone() override {
|
||||
}
|
||||
|
||||
virtual void onBind(oglplus::Framebuffer::Target target) override {
|
||||
ovrGLTexture& tex = (ovrGLTexture&)(color->Textures[color->CurrentIndex]);
|
||||
glFramebufferTexture2D(toEnum(target), GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.OGL.TexId, 0);
|
||||
}
|
||||
|
||||
virtual void onUnbind(oglplus::Framebuffer::Target target) override {
|
||||
glFramebufferTexture2D(toEnum(target), GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// We use a FBO to wrap the mirror texture because it makes it easier to
|
||||
// render to the screen via glBlitFramebuffer
|
||||
struct MirrorFramebufferWrapper : public RiftFramebufferWrapper<ovrGLTexture*> {
|
||||
MirrorFramebufferWrapper(const ovrHmd & hmd)
|
||||
: RiftFramebufferWrapper(hmd) {
|
||||
}
|
||||
|
||||
virtual ~MirrorFramebufferWrapper() {
|
||||
if (color) {
|
||||
ovrHmd_DestroyMirrorTexture(hmd, (ovrTexture*)color);
|
||||
color = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void initColor() override {
|
||||
if (color) {
|
||||
ovrHmd_DestroyMirrorTexture(hmd, (ovrTexture*)color);
|
||||
color = nullptr;
|
||||
}
|
||||
ovrResult result = ovrHmd_CreateMirrorTextureGL(hmd, GL_RGBA, size.x, size.y, (ovrTexture**)&color);
|
||||
Q_ASSERT(OVR_SUCCESS(result));
|
||||
}
|
||||
|
||||
void initDone() override {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oglplus::GetName(fbo));
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color->OGL.TexId, 0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
};
|
||||
|
||||
static SwapFramebufferWrapper* _swapFbo{ nullptr };
|
||||
static MirrorFramebufferWrapper* _mirrorFbo{ nullptr };
|
||||
static ovrLayerEyeFov _sceneLayer;
|
||||
|
||||
#else
|
||||
|
||||
static ovrTexture _eyeTextures[ovrEye_Count];
|
||||
static GlWindow* _outputWindow{ nullptr };
|
||||
|
||||
#endif
|
||||
|
||||
static bool _isConnected = false;
|
||||
static ovrHmd _ovrHmd;
|
||||
static ovrFovPort _eyeFov[ovrEye_Count];
|
||||
static ovrEyeRenderDesc _eyeRenderDesc[ovrEye_Count];
|
||||
static ovrSizei _renderTargetSize;
|
||||
static glm::mat4 _eyeProjection[ovrEye_Count];
|
||||
static unsigned int _frameIndex = 0;
|
||||
static bool _frameTimingActive = false;
|
||||
static Camera* _camera = NULL;
|
||||
static ovrEyeType _activeEye = ovrEye_Count;
|
||||
static bool _hswDismissed = false;
|
||||
|
||||
static const float CALIBRATION_DELTA_MINIMUM_LENGTH = 0.02f;
|
||||
static const float CALIBRATION_DELTA_MINIMUM_ANGLE = 5.0f * RADIANS_PER_DEGREE;
|
||||
static const float CALIBRATION_ZERO_MAXIMUM_LENGTH = 0.01f;
|
||||
static const float CALIBRATION_ZERO_MAXIMUM_ANGLE = 2.0f * RADIANS_PER_DEGREE;
|
||||
static const quint64 CALIBRATION_ZERO_HOLD_TIME = 3000000; // usec
|
||||
static const float CALIBRATION_MESSAGE_DISTANCE = 2.5f;
|
||||
static CalibrationState _calibrationState;
|
||||
static glm::vec3 _calibrationPosition;
|
||||
static glm::quat _calibrationOrientation;
|
||||
static quint64 _calibrationStartTime;
|
||||
static int _calibrationMessage = 0;
|
||||
static glm::vec3 _eyePositions[ovrEye_Count];
|
||||
// TODO expose this as a developer toggle
|
||||
static bool _eyePerFrameMode = false;
|
||||
static ovrEyeType _lastEyeRendered = ovrEye_Count;
|
||||
static ovrSizei _recommendedTexSize = { 0, 0 };
|
||||
static float _offscreenRenderScale = 1.0;
|
||||
static glm::mat4 _combinedProjection;
|
||||
static ovrPosef _eyeRenderPoses[ovrEye_Count];
|
||||
static ovrRecti _eyeViewports[ovrEye_Count];
|
||||
static ovrVector3f _eyeOffsets[ovrEye_Count];
|
||||
|
||||
|
||||
glm::vec3 OculusManager::getLeftEyePosition() { return _eyePositions[ovrEye_Left]; }
|
||||
glm::vec3 OculusManager::getRightEyePosition() { return _eyePositions[ovrEye_Right]; }
|
||||
glm::vec3 OculusManager::getMidEyePosition() { return (_eyePositions[ovrEye_Left] + _eyePositions[ovrEye_Right]) / 2.0f; }
|
||||
|
||||
void OculusManager::connect(QOpenGLContext* shareContext) {
|
||||
qCDebug(interfaceapp) << "Oculus SDK" << OVR_VERSION_STRING;
|
||||
|
||||
ovrInitParams initParams; memset(&initParams, 0, sizeof(initParams));
|
||||
|
||||
#ifdef DEBUG
|
||||
initParams.Flags |= ovrInit_Debug;
|
||||
#endif
|
||||
|
||||
ovr_Initialize(&initParams);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
ovrResult res = ovrHmd_Create(0, &_ovrHmd);
|
||||
#ifdef DEBUG
|
||||
if (!OVR_SUCCESS(res)) {
|
||||
res = ovrHmd_CreateDebug(ovrHmd_DK2, &_ovrHmd);
|
||||
Q_ASSERT(OVR_SUCCESS(res));
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
_ovrHmd = ovrHmd_Create(0);
|
||||
#ifdef DEBUG
|
||||
if (!_ovrHmd) {
|
||||
_ovrHmd = ovrHmd_CreateDebug(ovrHmd_DK2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (!_ovrHmd) {
|
||||
_isConnected = false;
|
||||
|
||||
// we're definitely not in "VR mode" so tell the menu that
|
||||
Menu::getInstance()->getActionForOption(MenuOption::EnableVRMode)->setChecked(false);
|
||||
ovr_Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
_calibrationState = UNCALIBRATED;
|
||||
if (!_isConnected) {
|
||||
UserActivityLogger::getInstance().connectedDevice("hmd", "oculus");
|
||||
}
|
||||
_isConnected = true;
|
||||
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
_eyeFov[eye] = _ovrHmd->DefaultEyeFov[eye];
|
||||
_eyeProjection[eye] = toGlm(ovrMatrix4f_Projection(_eyeFov[eye],
|
||||
DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, ovrProjection_RightHanded));
|
||||
ovrEyeRenderDesc erd = ovrHmd_GetRenderDesc(_ovrHmd, eye, _eyeFov[eye]);
|
||||
_eyeOffsets[eye] = erd.HmdToEyeViewOffset;
|
||||
});
|
||||
ovrFovPort combinedFov = _ovrHmd->MaxEyeFov[0];
|
||||
combinedFov.RightTan = _ovrHmd->MaxEyeFov[1].RightTan;
|
||||
_combinedProjection = toGlm(ovrMatrix4f_Projection(combinedFov,
|
||||
DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, ovrProjection_RightHanded));
|
||||
|
||||
_recommendedTexSize = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Left, _eyeFov[ovrEye_Left], 1.0f);
|
||||
_renderTargetSize = { _recommendedTexSize.w * 2, _recommendedTexSize.h };
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
_mirrorFbo = new MirrorFramebufferWrapper(_ovrHmd);
|
||||
_swapFbo = new SwapFramebufferWrapper(_ovrHmd);
|
||||
_swapFbo->Init(toGlm(_renderTargetSize));
|
||||
_sceneLayer.ColorTexture[0] = _swapFbo->color;
|
||||
_sceneLayer.ColorTexture[1] = nullptr;
|
||||
_sceneLayer.Viewport[0].Pos = { 0, 0 };
|
||||
_sceneLayer.Viewport[0].Size = _recommendedTexSize;
|
||||
_sceneLayer.Viewport[1].Pos = { _recommendedTexSize.w, 0 };
|
||||
_sceneLayer.Viewport[1].Size = _recommendedTexSize;
|
||||
_sceneLayer.Header.Type = ovrLayerType_EyeFov;
|
||||
_sceneLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft;
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
_eyeViewports[eye] = _sceneLayer.Viewport[eye];
|
||||
_sceneLayer.Fov[eye] = _eyeFov[eye];
|
||||
});
|
||||
|
||||
|
||||
|
||||
#else
|
||||
_outputWindow = new GlWindow(shareContext);
|
||||
_outputWindow->show();
|
||||
// _outputWindow->setFlags(Qt::FramelessWindowHint );
|
||||
// _outputWindow->resize(_ovrHmd->Resolution.w, _ovrHmd->Resolution.h);
|
||||
// _outputWindow->setPosition(_ovrHmd->WindowsPos.x, _ovrHmd->WindowsPos.y);
|
||||
ivec2 desiredPosition = toGlm(_ovrHmd->WindowsPos);
|
||||
foreach(QScreen* screen, qGuiApp->screens()) {
|
||||
ivec2 screenPosition = toGlm(screen->geometry().topLeft());
|
||||
if (screenPosition == desiredPosition) {
|
||||
_outputWindow->setScreen(screen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_outputWindow->showFullScreen();
|
||||
_outputWindow->makeCurrent();
|
||||
|
||||
ovrGLConfig cfg;
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
|
||||
cfg.OGL.Header.BackBufferSize = _ovrHmd->Resolution;
|
||||
cfg.OGL.Header.Multisample = 0;
|
||||
|
||||
int distortionCaps = 0
|
||||
| ovrDistortionCap_Vignette
|
||||
| ovrDistortionCap_Overdrive
|
||||
| ovrDistortionCap_TimeWarp;
|
||||
|
||||
int configResult = ovrHmd_ConfigureRendering(_ovrHmd, &cfg.Config,
|
||||
distortionCaps, _eyeFov, _eyeRenderDesc);
|
||||
assert(configResult);
|
||||
Q_UNUSED(configResult);
|
||||
|
||||
_outputWindow->doneCurrent();
|
||||
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
//Get texture size
|
||||
_eyeTextures[eye].Header.API = ovrRenderAPI_OpenGL;
|
||||
_eyeTextures[eye].Header.TextureSize = _renderTargetSize;
|
||||
_eyeTextures[eye].Header.RenderViewport.Pos = { 0, 0 };
|
||||
_eyeTextures[eye].Header.RenderViewport.Size = _renderTargetSize;
|
||||
_eyeTextures[eye].Header.RenderViewport.Size.w /= 2;
|
||||
});
|
||||
_eyeTextures[ovrEye_Right].Header.RenderViewport.Pos.x = _recommendedTexSize.w;
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
_eyeViewports[eye] = _eyeTextures[eye].Header.RenderViewport;
|
||||
});
|
||||
#endif
|
||||
|
||||
ovrHmd_SetEnabledCaps(_ovrHmd,
|
||||
ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
|
||||
|
||||
ovrHmd_ConfigureTracking(_ovrHmd,
|
||||
ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection,
|
||||
ovrTrackingCap_Orientation);
|
||||
|
||||
if (!_camera) {
|
||||
_camera = new Camera;
|
||||
configureCamera(*_camera); // no need to use screen dimensions; they're ignored
|
||||
}
|
||||
}
|
||||
|
||||
//Disconnects and deallocates the OR
|
||||
void OculusManager::disconnect() {
|
||||
if (_isConnected) {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (_swapFbo) {
|
||||
delete _swapFbo;
|
||||
_swapFbo = nullptr;
|
||||
}
|
||||
|
||||
if (_mirrorFbo) {
|
||||
delete _mirrorFbo;
|
||||
_mirrorFbo = nullptr;
|
||||
}
|
||||
#else
|
||||
_outputWindow->showNormal();
|
||||
_outputWindow->deleteLater();
|
||||
_outputWindow = nullptr;
|
||||
#endif
|
||||
|
||||
if (_ovrHmd) {
|
||||
ovrHmd_Destroy(_ovrHmd);
|
||||
_ovrHmd = nullptr;
|
||||
}
|
||||
ovr_Shutdown();
|
||||
|
||||
_isConnected = false;
|
||||
// Prepare to potentially have to dismiss the HSW again
|
||||
// if the user re-enables VR
|
||||
_hswDismissed = false;
|
||||
}
|
||||
}
|
||||
|
||||
void positionCalibrationBillboard(Text3DOverlay* billboard) {
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
glm::quat headOrientation = myAvatar->getHeadOrientation();
|
||||
headOrientation.x = 0;
|
||||
headOrientation.z = 0;
|
||||
glm::normalize(headOrientation);
|
||||
billboard->setPosition(myAvatar->getHeadPosition()
|
||||
+ headOrientation * glm::vec3(0.0f, 0.0f, -CALIBRATION_MESSAGE_DISTANCE));
|
||||
billboard->setRotation(headOrientation);
|
||||
}
|
||||
|
||||
void calibrate(const glm::vec3& position, const glm::quat& orientation) {
|
||||
static QString instructionMessage = "Hold still to calibrate";
|
||||
static QString progressMessage;
|
||||
static Text3DOverlay* billboard;
|
||||
|
||||
switch (_calibrationState) {
|
||||
|
||||
case UNCALIBRATED:
|
||||
if (position != glm::vec3() && orientation != glm::quat()) { // Handle zero values at start-up.
|
||||
_calibrationPosition = position;
|
||||
_calibrationOrientation = orientation;
|
||||
_calibrationState = WAITING_FOR_DELTA;
|
||||
}
|
||||
break;
|
||||
|
||||
case WAITING_FOR_DELTA:
|
||||
if (glm::length(position - _calibrationPosition) > CALIBRATION_DELTA_MINIMUM_LENGTH
|
||||
|| glm::angle(orientation * glm::inverse(_calibrationOrientation)) > CALIBRATION_DELTA_MINIMUM_ANGLE) {
|
||||
_calibrationPosition = position;
|
||||
_calibrationOrientation = orientation;
|
||||
_calibrationState = WAITING_FOR_ZERO;
|
||||
}
|
||||
break;
|
||||
|
||||
case WAITING_FOR_ZERO:
|
||||
if (glm::length(position - _calibrationPosition) < CALIBRATION_ZERO_MAXIMUM_LENGTH
|
||||
&& glm::angle(orientation * glm::inverse(_calibrationOrientation)) < CALIBRATION_ZERO_MAXIMUM_ANGLE) {
|
||||
_calibrationStartTime = usecTimestampNow();
|
||||
_calibrationState = WAITING_FOR_ZERO_HELD;
|
||||
|
||||
if (!_calibrationMessage) {
|
||||
qCDebug(interfaceapp) << "Hold still to calibrate HMD";
|
||||
|
||||
billboard = new Text3DOverlay();
|
||||
billboard->setDimensions(glm::vec2(2.0f, 1.25f));
|
||||
billboard->setTopMargin(0.35f);
|
||||
billboard->setLeftMargin(0.28f);
|
||||
billboard->setText(instructionMessage);
|
||||
billboard->setAlpha(0.5f);
|
||||
billboard->setLineHeight(0.1f);
|
||||
billboard->setIsFacingAvatar(false);
|
||||
positionCalibrationBillboard(billboard);
|
||||
|
||||
_calibrationMessage = Application::getInstance()->getOverlays().addOverlay(billboard);
|
||||
}
|
||||
|
||||
progressMessage = "";
|
||||
} else {
|
||||
_calibrationPosition = position;
|
||||
_calibrationOrientation = orientation;
|
||||
}
|
||||
break;
|
||||
|
||||
case WAITING_FOR_ZERO_HELD:
|
||||
if (glm::length(position - _calibrationPosition) < CALIBRATION_ZERO_MAXIMUM_LENGTH
|
||||
&& glm::angle(orientation * glm::inverse(_calibrationOrientation)) < CALIBRATION_ZERO_MAXIMUM_ANGLE) {
|
||||
if ((usecTimestampNow() - _calibrationStartTime) > CALIBRATION_ZERO_HOLD_TIME) {
|
||||
_calibrationState = CALIBRATED;
|
||||
qCDebug(interfaceapp) << "HMD calibrated";
|
||||
Application::getInstance()->getOverlays().deleteOverlay(_calibrationMessage);
|
||||
_calibrationMessage = 0;
|
||||
Application::getInstance()->resetSensors();
|
||||
} else {
|
||||
quint64 quarterSeconds = (usecTimestampNow() - _calibrationStartTime) / 250000;
|
||||
if (quarterSeconds + 1 > (quint64)progressMessage.length()) {
|
||||
// 3...2...1...
|
||||
if (quarterSeconds == 4 * (quarterSeconds / 4)) {
|
||||
quint64 wholeSeconds = CALIBRATION_ZERO_HOLD_TIME / 1000000 - quarterSeconds / 4;
|
||||
|
||||
if (wholeSeconds == 3) {
|
||||
positionCalibrationBillboard(billboard);
|
||||
}
|
||||
|
||||
progressMessage += QString::number(wholeSeconds);
|
||||
} else {
|
||||
progressMessage += ".";
|
||||
}
|
||||
billboard->setText(instructionMessage + "\n\n" + progressMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_calibrationPosition = position;
|
||||
_calibrationOrientation = orientation;
|
||||
_calibrationState = WAITING_FOR_ZERO;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OculusManager::recalibrate() {
|
||||
_calibrationState = UNCALIBRATED;
|
||||
}
|
||||
|
||||
void OculusManager::abandonCalibration() {
|
||||
_calibrationState = CALIBRATED;
|
||||
if (_calibrationMessage) {
|
||||
qCDebug(interfaceapp) << "Abandoned HMD calibration";
|
||||
Application::getInstance()->getOverlays().deleteOverlay(_calibrationMessage);
|
||||
_calibrationMessage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool OculusManager::isConnected() {
|
||||
return _isConnected;
|
||||
}
|
||||
|
||||
//Begins the frame timing for oculus prediction purposes
|
||||
void OculusManager::beginFrameTiming() {
|
||||
if (_frameTimingActive) {
|
||||
printf("WARNING: Called OculusManager::beginFrameTiming() twice in a row, need to call OculusManager::endFrameTiming().");
|
||||
}
|
||||
_frameTimingActive = true;
|
||||
}
|
||||
|
||||
bool OculusManager::allowSwap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Ends frame timing
|
||||
void OculusManager::endFrameTiming() {
|
||||
_frameIndex++;
|
||||
_frameTimingActive = false;
|
||||
}
|
||||
|
||||
//Sets the camera FoV and aspect ratio
|
||||
void OculusManager::configureCamera(Camera& camera) {
|
||||
if (_activeEye == ovrEye_Count) {
|
||||
// When not rendering, provide a FOV encompasing both eyes
|
||||
camera.setProjection(_combinedProjection);
|
||||
return;
|
||||
}
|
||||
camera.setProjection(_eyeProjection[_activeEye]);
|
||||
}
|
||||
|
||||
//Displays everything for the oculus, frame timing must be active
|
||||
void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const glm::quat &bodyOrientation, const glm::vec3 &position, Camera& whichCamera) {
|
||||
|
||||
#ifdef DEBUG
|
||||
// Ensure the frame counter always increments by exactly 1
|
||||
static int oldFrameIndex = -1;
|
||||
assert(oldFrameIndex == -1 || (unsigned int)oldFrameIndex == _frameIndex - 1);
|
||||
oldFrameIndex = _frameIndex;
|
||||
#endif
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
|
||||
// FIXME: we need a better way of responding to the HSW. In particular
|
||||
// we need to ensure that it's only displayed once per session, rather than
|
||||
// every time the user toggles VR mode, and we need to hook it up to actual
|
||||
// keyboard input. OVR claim they are refactoring HSW
|
||||
// https://forums.oculus.com/viewtopic.php?f=20&t=21720#p258599
|
||||
static ovrHSWDisplayState hasWarningState;
|
||||
if (!_hswDismissed) {
|
||||
ovrHmd_GetHSWDisplayState(_ovrHmd, &hasWarningState);
|
||||
if (hasWarningState.Displayed) {
|
||||
ovrHmd_DismissHSWDisplay(_ovrHmd);
|
||||
} else {
|
||||
_hswDismissed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//beginFrameTiming must be called before display
|
||||
if (!_frameTimingActive) {
|
||||
printf("WARNING: Called OculusManager::display() without calling OculusManager::beginFrameTiming() first.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto primaryFBO = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO));
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glm::quat orientation;
|
||||
glm::vec3 trackerPosition;
|
||||
auto deviceSize = qApp->getDeviceSize();
|
||||
|
||||
ovrTrackingState ts = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds());
|
||||
ovrVector3f ovrHeadPosition = ts.HeadPose.ThePose.Position;
|
||||
|
||||
trackerPosition = glm::vec3(ovrHeadPosition.x, ovrHeadPosition.y, ovrHeadPosition.z);
|
||||
|
||||
if (_calibrationState != CALIBRATED) {
|
||||
ovrQuatf ovrHeadOrientation = ts.HeadPose.ThePose.Orientation;
|
||||
orientation = glm::quat(ovrHeadOrientation.w, ovrHeadOrientation.x, ovrHeadOrientation.y, ovrHeadOrientation.z);
|
||||
calibrate(trackerPosition, orientation);
|
||||
}
|
||||
|
||||
trackerPosition = bodyOrientation * trackerPosition;
|
||||
ovrPosef eyePoses[ovrEye_Count];
|
||||
ovrHmd_GetEyePoses(_ovrHmd, _frameIndex, _eyeOffsets, eyePoses, nullptr);
|
||||
#ifndef Q_OS_WIN
|
||||
ovrHmd_BeginFrame(_ovrHmd, _frameIndex);
|
||||
#endif
|
||||
//Render each eye into an fbo
|
||||
for_each_eye(_ovrHmd, [&](ovrEyeType eye){
|
||||
// If we're in eye-per-frame mode, only render one eye
|
||||
// per call to display, and allow timewarp to correct for
|
||||
// the other eye. Poor man's perf improvement
|
||||
if (_eyePerFrameMode && eye == _lastEyeRendered) {
|
||||
return;
|
||||
}
|
||||
_lastEyeRendered = _activeEye = eye;
|
||||
_eyeRenderPoses[eye] = eyePoses[eye];
|
||||
// Set the camera rotation for this eye
|
||||
|
||||
_eyePositions[eye] = toGlm(_eyeRenderPoses[eye].Position);
|
||||
_eyePositions[eye] = whichCamera.getRotation() * _eyePositions[eye];
|
||||
quat eyeRotation = toGlm(_eyeRenderPoses[eye].Orientation);
|
||||
|
||||
// Update our camera to what the application camera is doing
|
||||
_camera->setRotation(whichCamera.getRotation() * eyeRotation);
|
||||
_camera->setPosition(whichCamera.getPosition() + _eyePositions[eye]);
|
||||
configureCamera(*_camera);
|
||||
_camera->update(1.0f / Application::getInstance()->getFps());
|
||||
|
||||
ovrRecti & vp = _eyeViewports[eye];
|
||||
vp.Size.h = _recommendedTexSize.h * _offscreenRenderScale;
|
||||
vp.Size.w = _recommendedTexSize.w * _offscreenRenderScale;
|
||||
glViewport(vp.Pos.x, vp.Pos.y, vp.Size.w, vp.Size.h);
|
||||
|
||||
renderArgs->_viewport = glm::ivec4(vp.Pos.x, vp.Pos.y, vp.Size.w, vp.Size.h);
|
||||
renderArgs->_renderSide = RenderArgs::MONO;
|
||||
qApp->displaySide(renderArgs, *_camera);
|
||||
qApp->getApplicationCompositor().displayOverlayTextureHmd(renderArgs, eye);
|
||||
});
|
||||
_activeEye = ovrEye_Count;
|
||||
|
||||
gpu::FramebufferPointer finalFbo;
|
||||
finalFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// restore our normal viewport
|
||||
glViewport(0, 0, deviceSize.width(), deviceSize.height());
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
auto srcFboSize = finalFbo->getSize();
|
||||
|
||||
|
||||
// Blit to the oculus provided texture
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
|
||||
_swapFbo->Bound(oglplus::Framebuffer::Target::Draw, [&] {
|
||||
glBlitFramebuffer(
|
||||
0, 0, srcFboSize.x, srcFboSize.y,
|
||||
0, 0, _swapFbo->size.x, _swapFbo->size.y,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
});
|
||||
|
||||
// Blit to the onscreen window
|
||||
auto destWindowSize = qApp->getDeviceSize();
|
||||
glBlitFramebuffer(
|
||||
0, 0, srcFboSize.x, srcFboSize.y,
|
||||
0, 0, destWindowSize.width(), destWindowSize.height(),
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
// Submit the frame to the Oculus SDK for timewarp and distortion
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
_sceneLayer.RenderPose[eye] = _eyeRenderPoses[eye];
|
||||
});
|
||||
auto header = &_sceneLayer.Header;
|
||||
ovrResult res = ovrHmd_SubmitFrame(_ovrHmd, _frameIndex, nullptr, &header, 1);
|
||||
Q_ASSERT(OVR_SUCCESS(res));
|
||||
_swapFbo->Increment();
|
||||
#else
|
||||
GLsync syncObject = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
glFlush();
|
||||
|
||||
|
||||
_outputWindow->makeCurrent();
|
||||
// force the compositing context to wait for the texture
|
||||
// rendering to complete before it starts the distortion rendering,
|
||||
// but without triggering a CPU/GPU synchronization
|
||||
glWaitSync(syncObject, 0, GL_TIMEOUT_IGNORED);
|
||||
glDeleteSync(syncObject);
|
||||
|
||||
GLuint textureId = gpu::GLBackend::getTextureID(finalFbo->getRenderBuffer(0));
|
||||
for_each_eye([&](ovrEyeType eye) {
|
||||
ovrGLTexture & glEyeTexture = reinterpret_cast<ovrGLTexture&>(_eyeTextures[eye]);
|
||||
glEyeTexture.OGL.TexId = textureId;
|
||||
|
||||
});
|
||||
|
||||
// restore our normal viewport
|
||||
ovrHmd_EndFrame(_ovrHmd, _eyeRenderPoses, _eyeTextures);
|
||||
glCanvas->makeCurrent();
|
||||
#endif
|
||||
|
||||
|
||||
// in order to account account for changes in the pick ray caused by head movement
|
||||
// we need to force a mouse move event on every frame (perhaps we could change this
|
||||
// to based on the head moving a minimum distance from the last position in which we
|
||||
// sent?)
|
||||
{
|
||||
QMouseEvent mouseEvent(QEvent::MouseMove, glCanvas->mapFromGlobal(QCursor::pos()),
|
||||
Qt::NoButton, Qt::NoButton, 0);
|
||||
qApp->mouseMoveEvent(&mouseEvent, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Tries to reconnect to the sensors
|
||||
void OculusManager::reset() {
|
||||
if (_isConnected) {
|
||||
ovrHmd_RecenterPose(_ovrHmd);
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 OculusManager::getRelativePosition() {
|
||||
ovrTrackingState trackingState = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds());
|
||||
return toGlm(trackingState.HeadPose.ThePose.Position);
|
||||
}
|
||||
|
||||
glm::quat OculusManager::getOrientation() {
|
||||
ovrTrackingState trackingState = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds());
|
||||
return toGlm(trackingState.HeadPose.ThePose.Orientation);
|
||||
}
|
||||
|
||||
QSize OculusManager::getRenderTargetSize() {
|
||||
QSize rv;
|
||||
rv.setWidth(_renderTargetSize.w);
|
||||
rv.setHeight(_renderTargetSize.h);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void OculusManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
|
||||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) {
|
||||
if (_activeEye != ovrEye_Count) {
|
||||
const ovrFovPort& port = _eyeFov[_activeEye];
|
||||
right = nearVal * port.RightTan;
|
||||
left = -nearVal * port.LeftTan;
|
||||
top = nearVal * port.UpTan;
|
||||
bottom = -nearVal * port.DownTan;
|
||||
}
|
||||
}
|
||||
|
||||
int OculusManager::getHMDScreen() {
|
||||
#ifdef Q_OS_WIN
|
||||
return -1;
|
||||
#else
|
||||
int hmdScreenIndex = -1; // unknown
|
||||
// TODO: it might be smarter to handle multiple HMDs connected in this case. but for now,
|
||||
// we will simply assume the initialization code that set up _ovrHmd picked the best hmd
|
||||
|
||||
if (_ovrHmd) {
|
||||
QString productNameFromOVR = _ovrHmd->ProductName;
|
||||
|
||||
int hmdWidth = _ovrHmd->Resolution.w;
|
||||
int hmdHeight = _ovrHmd->Resolution.h;
|
||||
int hmdAtX = _ovrHmd->WindowsPos.x;
|
||||
int hmdAtY = _ovrHmd->WindowsPos.y;
|
||||
|
||||
// we will score the likelihood that each screen is a match based on the following
|
||||
// rubrik of potential matching features
|
||||
const int EXACT_NAME_MATCH = 100;
|
||||
const int SIMILAR_NAMES = 10;
|
||||
const int EXACT_LOCATION_MATCH = 50;
|
||||
const int EXACT_RESOLUTION_MATCH = 25;
|
||||
|
||||
int bestMatchScore = 0;
|
||||
|
||||
// look at the display list and see if we can find the best match
|
||||
QDesktopWidget* desktop = QApplication::desktop();
|
||||
int screenNumber = 0;
|
||||
foreach (QScreen* screen, QGuiApplication::screens()) {
|
||||
QString screenName = screen->name();
|
||||
QRect screenRect = desktop->screenGeometry(screenNumber);
|
||||
|
||||
int screenScore = 0;
|
||||
if (screenName == productNameFromOVR) {
|
||||
screenScore += EXACT_NAME_MATCH;
|
||||
}
|
||||
if (similarStrings(screenName, productNameFromOVR)) {
|
||||
screenScore += SIMILAR_NAMES;
|
||||
}
|
||||
if (hmdWidth == screenRect.width() && hmdHeight == screenRect.height()) {
|
||||
screenScore += EXACT_RESOLUTION_MATCH;
|
||||
}
|
||||
if (hmdAtX == screenRect.x() && hmdAtY == screenRect.y()) {
|
||||
screenScore += EXACT_LOCATION_MATCH;
|
||||
}
|
||||
if (screenScore > bestMatchScore) {
|
||||
bestMatchScore = screenScore;
|
||||
hmdScreenIndex = screenNumber;
|
||||
}
|
||||
|
||||
screenNumber++;
|
||||
}
|
||||
}
|
||||
return hmdScreenIndex;
|
||||
#endif
|
||||
}
|
||||
|
||||
mat4 OculusManager::getEyeProjection(int eye) {
|
||||
return _eyeProjection[eye];
|
||||
}
|
||||
|
||||
mat4 OculusManager::getEyePose(int eye) {
|
||||
return toGlm(_eyeRenderPoses[eye]);
|
||||
}
|
||||
|
||||
mat4 OculusManager::getHeadPose() {
|
||||
ovrTrackingState ts = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds());
|
||||
return toGlm(ts.HeadPose.ThePose);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//
|
||||
// OculusManager.h
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by Stephen Birarda on 5/9/13.
|
||||
// Refactored by Ben Arnold on 6/30/2014
|
||||
// Copyright 2012 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_OculusManager_h
|
||||
#define hifi_OculusManager_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <QSize>
|
||||
|
||||
#include "RenderArgs.h"
|
||||
|
||||
class QOpenGLContext;
|
||||
class QGLWidget;
|
||||
class Camera;
|
||||
|
||||
/// Handles interaction with the Oculus Rift.
|
||||
class OculusManager {
|
||||
public:
|
||||
static void connect(QOpenGLContext* shareContext);
|
||||
static void disconnect();
|
||||
static bool isConnected();
|
||||
static void recalibrate();
|
||||
static void abandonCalibration();
|
||||
static void beginFrameTiming();
|
||||
static void endFrameTiming();
|
||||
static bool allowSwap();
|
||||
static void configureCamera(Camera& camera);
|
||||
static void display(QGLWidget * glCanvas, RenderArgs* renderArgs, const glm::quat &bodyOrientation, const glm::vec3 &position, Camera& whichCamera);
|
||||
static void reset();
|
||||
|
||||
static glm::vec3 getRelativePosition();
|
||||
static glm::quat getOrientation();
|
||||
static QSize getRenderTargetSize();
|
||||
|
||||
static void overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
|
||||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane);
|
||||
|
||||
static glm::vec3 getLeftEyePosition();
|
||||
static glm::vec3 getRightEyePosition();
|
||||
static glm::vec3 getMidEyePosition();
|
||||
|
||||
static int getHMDScreen();
|
||||
|
||||
static glm::mat4 getEyeProjection(int eye);
|
||||
static glm::mat4 getEyePose(int eye);
|
||||
static glm::mat4 getHeadPose();
|
||||
};
|
||||
|
||||
#endif // hifi_OculusManager_h
|
|
@ -1,151 +0,0 @@
|
|||
//
|
||||
// TV3DManager.cpp
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/24/13.
|
||||
// Copyright 2013 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 "TV3DManager.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <RenderArgs.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Menu.h"
|
||||
|
||||
int TV3DManager::_screenWidth = 1;
|
||||
int TV3DManager::_screenHeight = 1;
|
||||
double TV3DManager::_aspect = 1.0;
|
||||
eyeFrustum TV3DManager::_leftEye;
|
||||
eyeFrustum TV3DManager::_rightEye;
|
||||
eyeFrustum* TV3DManager::_activeEye = NULL;
|
||||
|
||||
|
||||
bool TV3DManager::isConnected() {
|
||||
return Menu::getInstance()->isOptionChecked(MenuOption::Enable3DTVMode);
|
||||
}
|
||||
|
||||
void TV3DManager::connect() {
|
||||
auto deviceSize = qApp->getDeviceSize();
|
||||
configureCamera(*(qApp->getCamera()), deviceSize.width(), deviceSize.height());
|
||||
}
|
||||
|
||||
|
||||
// The basic strategy of this stereoscopic rendering is explained here:
|
||||
// http://www.orthostereo.com/geometryopengl.html
|
||||
void TV3DManager::setFrustum(Camera& whichCamera) {
|
||||
const double DTR = 0.0174532925; // degree to radians
|
||||
const double IOD = 0.05; //intraocular distance
|
||||
double fovy = DEFAULT_FIELD_OF_VIEW_DEGREES; // field of view in y-axis
|
||||
double nearZ = DEFAULT_NEAR_CLIP; // near clipping plane
|
||||
double screenZ = 0.25f; // screen projection plane
|
||||
|
||||
double top = nearZ * tan(DTR * fovy / 2.0); //sets top of frustum based on fovy and near clipping plane
|
||||
double right = _aspect * top; // sets right of frustum based on aspect ratio
|
||||
double frustumshift = (IOD / 2) * nearZ / screenZ;
|
||||
|
||||
_leftEye.top = top;
|
||||
_leftEye.bottom = -top;
|
||||
_leftEye.left = -right + frustumshift;
|
||||
_leftEye.right = right + frustumshift;
|
||||
_leftEye.modelTranslation = IOD / 2;
|
||||
|
||||
_rightEye.top = top;
|
||||
_rightEye.bottom = -top;
|
||||
_rightEye.left = -right - frustumshift;
|
||||
_rightEye.right = right - frustumshift;
|
||||
_rightEye.modelTranslation = -IOD / 2;
|
||||
}
|
||||
|
||||
void TV3DManager::configureCamera(Camera& whichCamera, int screenWidth, int screenHeight) {
|
||||
#ifdef THIS_CURRENTLY_BROKEN_WAITING_FOR_DISPLAY_PLUGINS
|
||||
if (screenHeight == 0) {
|
||||
screenHeight = 1; // prevent divide by 0
|
||||
}
|
||||
_screenWidth = screenWidth;
|
||||
_screenHeight = screenHeight;
|
||||
_aspect= (double)_screenWidth / (double)_screenHeight;
|
||||
setFrustum(whichCamera);
|
||||
|
||||
glViewport (0, 0, _screenWidth, _screenHeight); // sets drawing viewport
|
||||
#endif
|
||||
}
|
||||
|
||||
void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) {
|
||||
|
||||
#ifdef THIS_CURRENTLY_BROKEN_WAITING_FOR_DISPLAY_PLUGINS
|
||||
|
||||
double nearZ = DEFAULT_NEAR_CLIP; // near clipping plane
|
||||
double farZ = DEFAULT_FAR_CLIP; // far clipping plane
|
||||
|
||||
// left eye portal
|
||||
int portalX = 0;
|
||||
int portalY = 0;
|
||||
QSize deviceSize = qApp->getDeviceSize() *
|
||||
qApp->getRenderResolutionScale();
|
||||
int portalW = deviceSize.width() / 2;
|
||||
int portalH = deviceSize.height();
|
||||
|
||||
|
||||
// FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working
|
||||
DependencyManager::get<GlowEffect>()->prepare(renderArgs);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Camera eyeCamera;
|
||||
eyeCamera.setRotation(whichCamera.getRotation());
|
||||
eyeCamera.setPosition(whichCamera.getPosition());
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
forEachEye([&](eyeFrustum& eye){
|
||||
_activeEye = &eye;
|
||||
glViewport(portalX, portalY, portalW, portalH);
|
||||
glScissor(portalX, portalY, portalW, portalH);
|
||||
renderArgs->_viewport = glm::ivec4(portalX, portalY, portalW, portalH);
|
||||
|
||||
glm::mat4 projection = glm::frustum<float>(eye.left, eye.right, eye.bottom, eye.top, nearZ, farZ);
|
||||
projection = glm::translate(projection, vec3(eye.modelTranslation, 0, 0));
|
||||
eyeCamera.setProjection(projection);
|
||||
renderArgs->_renderSide = RenderArgs::MONO;
|
||||
qApp->displaySide(renderArgs, eyeCamera, false);
|
||||
qApp->getApplicationCompositor().displayOverlayTexture(renderArgs);
|
||||
_activeEye = NULL;
|
||||
}, [&]{
|
||||
// render right side view
|
||||
portalX = deviceSize.width() / 2;
|
||||
});
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
// FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working
|
||||
auto finalFbo = DependencyManager::get<GlowEffect>()->render(renderArgs);
|
||||
auto fboSize = finalFbo->getSize();
|
||||
// Get the ACTUAL device size for the BLIT
|
||||
deviceSize = qApp->getDeviceSize();
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glBlitFramebuffer(0, 0, fboSize.x, fboSize.y,
|
||||
0, 0, deviceSize.width(), deviceSize.height(),
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
|
||||
// reset the viewport to how we started
|
||||
glViewport(0, 0, deviceSize.width(), deviceSize.height());
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void TV3DManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
|
||||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) {
|
||||
if (_activeEye) {
|
||||
left = _activeEye->left;
|
||||
right = _activeEye->right;
|
||||
bottom = _activeEye->bottom;
|
||||
top = _activeEye->top;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
//
|
||||
// TV3DManager.h
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/24/2013.
|
||||
// Copyright 2013 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_TV3DManager_h
|
||||
#define hifi_TV3DManager_h
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Camera;
|
||||
class RenderArgs;
|
||||
|
||||
struct eyeFrustum {
|
||||
double left;
|
||||
double right;
|
||||
double bottom;
|
||||
double top;
|
||||
float modelTranslation;
|
||||
};
|
||||
|
||||
|
||||
/// Handles interaction with 3D TVs
|
||||
class TV3DManager {
|
||||
public:
|
||||
static void connect();
|
||||
static bool isConnected();
|
||||
static void configureCamera(Camera& camera, int screenWidth, int screenHeight);
|
||||
static void display(RenderArgs* renderArgs, Camera& whichCamera);
|
||||
static void overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
|
||||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane);
|
||||
private:
|
||||
static void setFrustum(Camera& whichCamera);
|
||||
static int _screenWidth;
|
||||
static int _screenHeight;
|
||||
static double _aspect;
|
||||
static eyeFrustum _leftEye;
|
||||
static eyeFrustum _rightEye;
|
||||
static eyeFrustum* _activeEye;
|
||||
|
||||
// The first function is the code executed for each eye
|
||||
// while the second is code to be executed between the two eyes.
|
||||
// The use case here is to modify the output viewport coordinates
|
||||
// for the new eye.
|
||||
// FIXME: we'd like to have a default empty lambda for the second parameter,
|
||||
// but gcc 4.8.1 complains about it due to a bug. See
|
||||
// http://stackoverflow.com/questions/25490662/lambda-as-default-parameter-to-a-member-function-template
|
||||
template<typename F, typename FF>
|
||||
static void forEachEye(F f, FF ff) {
|
||||
f(_leftEye);
|
||||
ff();
|
||||
f(_rightEye);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // hifi_TV3DManager_h
|
|
@ -11,15 +11,16 @@
|
|||
|
||||
#include <avatar/AvatarManager.h>
|
||||
#include <avatar/MyAvatar.h>
|
||||
#include <GLCanvas.h>
|
||||
#include <HandData.h>
|
||||
#include <HFBackEvent.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "devices/MotionTracker.h"
|
||||
#include "devices/SixenseManager.h"
|
||||
#include "ControllerScriptingInterface.h"
|
||||
|
||||
// TODO: this needs to be removed, as well as any related controller-specific information
|
||||
#include <input-plugins/SixenseManager.h>
|
||||
|
||||
|
||||
ControllerScriptingInterface::ControllerScriptingInterface() :
|
||||
_mouseCaptured(false),
|
||||
|
@ -82,13 +83,14 @@ void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::In
|
|||
|
||||
QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
QVector<UserInputMapper::InputChannel> inputChannels = Application::getUserInputMapper()->getInputChannelsForAction(action);
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
QVector<UserInputMapper::InputChannel> inputChannels = userInputMapper->getInputChannelsForAction(action);
|
||||
QScriptValue _inputChannels = engine->newArray(inputChannels.size());
|
||||
for (int i = 0; i < inputChannels.size(); i++) {
|
||||
_inputChannels.setProperty(i, inputChannelToScriptValue(engine, inputChannels[i]));
|
||||
}
|
||||
obj.setProperty("action", (int) action);
|
||||
obj.setProperty("actionName", Application::getUserInputMapper()->getActionName(action));
|
||||
obj.setProperty("actionName", userInputMapper->getActionName(action));
|
||||
obj.setProperty("inputChannels", _inputChannels);
|
||||
return obj;
|
||||
}
|
||||
|
@ -376,7 +378,7 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) {
|
|||
}
|
||||
|
||||
glm::vec2 ControllerScriptingInterface::getViewportDimensions() const {
|
||||
return Application::getInstance()->getCanvasSize();
|
||||
return Application::getInstance()->getUiSize();
|
||||
}
|
||||
|
||||
AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
|
||||
|
@ -428,43 +430,59 @@ void ControllerScriptingInterface::updateInputControllers() {
|
|||
}
|
||||
|
||||
QVector<UserInputMapper::Action> ControllerScriptingInterface::getAllActions() {
|
||||
return Application::getUserInputMapper()->getAllActions();
|
||||
return DependencyManager::get<UserInputMapper>()->getAllActions();
|
||||
}
|
||||
|
||||
QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getInputChannelsForAction(UserInputMapper::Action action) {
|
||||
return Application::getUserInputMapper()->getInputChannelsForAction(action);
|
||||
return DependencyManager::get<UserInputMapper>()->getInputChannelsForAction(action);
|
||||
}
|
||||
|
||||
QString ControllerScriptingInterface::getDeviceName(unsigned int device) {
|
||||
return Application::getUserInputMapper()->getDeviceName((unsigned short) device);
|
||||
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
|
||||
}
|
||||
|
||||
QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getAllInputsForDevice(unsigned int device) {
|
||||
return Application::getUserInputMapper()->getAllInputsForDevice(device);
|
||||
return DependencyManager::get<UserInputMapper>()->getAllInputsForDevice(device);
|
||||
}
|
||||
|
||||
bool ControllerScriptingInterface::addInputChannel(UserInputMapper::InputChannel inputChannel) {
|
||||
return Application::getUserInputMapper()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale);
|
||||
return DependencyManager::get<UserInputMapper>()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale);
|
||||
}
|
||||
|
||||
bool ControllerScriptingInterface::removeInputChannel(UserInputMapper::InputChannel inputChannel) {
|
||||
return Application::getUserInputMapper()->removeInputChannel(inputChannel);
|
||||
return DependencyManager::get<UserInputMapper>()->removeInputChannel(inputChannel);
|
||||
}
|
||||
|
||||
QVector<UserInputMapper::InputPair> ControllerScriptingInterface::getAvailableInputs(unsigned int device) {
|
||||
return Application::getUserInputMapper()->getAvailableInputs((unsigned short) device);
|
||||
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
|
||||
}
|
||||
|
||||
void ControllerScriptingInterface::resetAllDeviceBindings() {
|
||||
Application::getUserInputMapper()->resetAllDeviceBindings();
|
||||
DependencyManager::get<UserInputMapper>()->resetAllDeviceBindings();
|
||||
}
|
||||
|
||||
void ControllerScriptingInterface::resetDevice(unsigned int device) {
|
||||
Application::getUserInputMapper()->resetDevice(device);
|
||||
DependencyManager::get<UserInputMapper>()->resetDevice(device);
|
||||
}
|
||||
|
||||
int ControllerScriptingInterface::findDevice(QString name) {
|
||||
return Application::getUserInputMapper()->findDevice(name);
|
||||
return DependencyManager::get<UserInputMapper>()->findDevice(name);
|
||||
}
|
||||
|
||||
float ControllerScriptingInterface::getActionValue(int action) {
|
||||
return DependencyManager::get<UserInputMapper>()->getActionState(UserInputMapper::Action(action));
|
||||
}
|
||||
|
||||
int ControllerScriptingInterface::findAction(QString actionName) {
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
auto actions = getAllActions();
|
||||
for (auto action : actions) {
|
||||
if (userInputMapper->getActionName(action) == actionName) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
// If the action isn't found, return -1
|
||||
return -1;
|
||||
}
|
||||
|
||||
InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
|
||||
|
@ -502,4 +520,4 @@ const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16;
|
|||
|
||||
InputController::Key InputController::getKey() const {
|
||||
return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "ui/UserInputMapper.h"
|
||||
#include <input-plugins/UserInputMapper.h>
|
||||
|
||||
#include <AbstractControllerScriptingInterface.h>
|
||||
class PalmData;
|
||||
|
@ -86,15 +86,24 @@ public:
|
|||
|
||||
public slots:
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::Action> getAllActions();
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::InputChannel> getInputChannelsForAction(UserInputMapper::Action action);
|
||||
Q_INVOKABLE virtual QString getDeviceName(unsigned int device);
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::InputChannel> getAllInputsForDevice(unsigned int device);
|
||||
|
||||
Q_INVOKABLE virtual bool addInputChannel(UserInputMapper::InputChannel inputChannel);
|
||||
Q_INVOKABLE virtual bool removeInputChannel(UserInputMapper::InputChannel inputChannel);
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::InputChannel> getInputChannelsForAction(UserInputMapper::Action action);
|
||||
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::InputPair> getAvailableInputs(unsigned int device);
|
||||
Q_INVOKABLE virtual void resetAllDeviceBindings();
|
||||
Q_INVOKABLE virtual QVector<UserInputMapper::InputChannel> getAllInputsForDevice(unsigned int device);
|
||||
|
||||
Q_INVOKABLE virtual QString getDeviceName(unsigned int device);
|
||||
|
||||
Q_INVOKABLE virtual float getActionValue(int action);
|
||||
|
||||
Q_INVOKABLE virtual void resetDevice(unsigned int device);
|
||||
Q_INVOKABLE virtual void resetAllDeviceBindings();
|
||||
Q_INVOKABLE virtual int findDevice(QString name);
|
||||
|
||||
Q_INVOKABLE virtual int findAction(QString actionName);
|
||||
|
||||
virtual bool isPrimaryButtonPressed() const;
|
||||
virtual glm::vec2 getPrimaryJoystickPosition() const;
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid
|
|||
auto dialogWidget = new QDialog(Application::getInstance()->getWindow(), Qt::Window);
|
||||
dialogWidget->setWindowTitle(title);
|
||||
dialogWidget->resize(width, height);
|
||||
dialogWidget->installEventFilter(this);
|
||||
connect(dialogWidget, &QDialog::finished, this, &WebWindowClass::hasClosed);
|
||||
|
||||
auto layout = new QVBoxLayout(dialogWidget);
|
||||
|
@ -93,6 +94,19 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid
|
|||
WebWindowClass::~WebWindowClass() {
|
||||
}
|
||||
|
||||
bool WebWindowClass::eventFilter(QObject* sender, QEvent* event) {
|
||||
if (sender == _windowWidget) {
|
||||
if (event->type() == QEvent::Move) {
|
||||
emit moved(getPosition());
|
||||
}
|
||||
if (event->type() == QEvent::Resize) {
|
||||
emit resized(getSize());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebWindowClass::hasClosed() {
|
||||
emit closed();
|
||||
}
|
||||
|
@ -122,6 +136,40 @@ void WebWindowClass::setURL(const QString& url) {
|
|||
_webView->setUrl(url);
|
||||
}
|
||||
|
||||
QSizeF WebWindowClass::getSize() const {
|
||||
QSizeF size = _windowWidget->size();
|
||||
return size;
|
||||
}
|
||||
|
||||
void WebWindowClass::setSize(QSizeF size) {
|
||||
setSize(size.width(), size.height());
|
||||
}
|
||||
|
||||
void WebWindowClass::setSize(int width, int height) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setSize", Qt::AutoConnection, Q_ARG(int, width), Q_ARG(int, height));
|
||||
return;
|
||||
}
|
||||
_windowWidget->resize(width, height);
|
||||
}
|
||||
|
||||
glm::vec2 WebWindowClass::getPosition() const {
|
||||
QPoint position = _windowWidget->pos();
|
||||
return glm::vec2(position.x(), position.y());
|
||||
}
|
||||
|
||||
void WebWindowClass::setPosition(glm::vec2 position) {
|
||||
setPosition(position.x, position.y);
|
||||
}
|
||||
|
||||
void WebWindowClass::setPosition(int x, int y) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setPosition", Qt::AutoConnection, Q_ARG(int, x), Q_ARG(int, y));
|
||||
return;
|
||||
}
|
||||
_windowWidget->move(x, y);
|
||||
}
|
||||
|
||||
void WebWindowClass::raise() {
|
||||
QMetaObject::invokeMethod(_windowWidget, "showNormal", Qt::AutoConnection);
|
||||
QMetaObject::invokeMethod(_windowWidget, "raise", Qt::AutoConnection);
|
||||
|
|
|
@ -35,6 +35,9 @@ class WebWindowClass : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QObject* eventBridge READ getEventBridge)
|
||||
Q_PROPERTY(QString url READ getURL)
|
||||
Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition);
|
||||
Q_PROPERTY(QSizeF size READ getSize WRITE setSize);
|
||||
|
||||
public:
|
||||
WebWindowClass(const QString& title, const QString& url, int width, int height, bool isToolWindow = false);
|
||||
~WebWindowClass();
|
||||
|
@ -43,6 +46,12 @@ public:
|
|||
|
||||
public slots:
|
||||
void setVisible(bool visible);
|
||||
glm::vec2 getPosition() const;
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(glm::vec2 position);
|
||||
QSizeF getSize() const;
|
||||
void setSize(QSizeF size);
|
||||
void setSize(int width, int height);
|
||||
QString getURL() const { return _webView->url().url(); }
|
||||
void setURL(const QString& url);
|
||||
void raise();
|
||||
|
@ -51,8 +60,13 @@ public slots:
|
|||
void setTitle(const QString& title);
|
||||
|
||||
signals:
|
||||
void moved(glm::vec2 position);
|
||||
void resized(QSizeF size);
|
||||
void closed();
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* sender, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void hasClosed();
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
#include "ApplicationCompositor.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <avatar/AvatarManager.h>
|
||||
|
@ -21,6 +25,8 @@
|
|||
#include "Tooltip.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include <input-plugins/SixenseManager.h> // TODO: any references to sixense should be removed here
|
||||
#include <input-plugins/InputDevice.h>
|
||||
|
||||
|
||||
// Used to animate the magnification windows
|
||||
|
@ -106,7 +112,9 @@ bool raySphereIntersect(const glm::vec3 &dir, const glm::vec3 &origin, float r,
|
|||
}
|
||||
}
|
||||
|
||||
ApplicationCompositor::ApplicationCompositor() {
|
||||
ApplicationCompositor::ApplicationCompositor() :
|
||||
_alphaPropertyAnimation(new QPropertyAnimation(this, "alpha"))
|
||||
{
|
||||
memset(_reticleActive, 0, sizeof(_reticleActive));
|
||||
memset(_magActive, 0, sizeof(_reticleActive));
|
||||
memset(_magSizeMult, 0, sizeof(_magSizeMult));
|
||||
|
@ -163,6 +171,8 @@ ApplicationCompositor::ApplicationCompositor() {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
_alphaPropertyAnimation.reset(new QPropertyAnimation(this, "alpha"));
|
||||
}
|
||||
|
||||
ApplicationCompositor::~ApplicationCompositor() {
|
||||
|
@ -184,7 +194,8 @@ void ApplicationCompositor::bindCursorTexture(gpu::Batch& batch, uint8_t cursorI
|
|||
// Draws the FBO texture for the screen
|
||||
void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) {
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
if (_alpha == 0.0f) {
|
||||
|
||||
if (_alpha <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -204,7 +215,7 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) {
|
|||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
|
||||
geometryCache->useSimpleDrawPipeline(batch);
|
||||
batch.setViewportTransform(glm::ivec4(0, 0, deviceSize.width(), deviceSize.height()));
|
||||
batch.setViewportTransform(renderArgs->_viewport);
|
||||
batch.setModelTransform(Transform());
|
||||
batch.setViewTransform(Transform());
|
||||
batch.setProjectionTransform(mat4());
|
||||
|
@ -232,15 +243,17 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) {
|
|||
}
|
||||
|
||||
|
||||
vec2 getPolarCoordinates(const PalmData& palm) {
|
||||
vec2 ApplicationCompositor::getPolarCoordinates(const PalmData& palm) const {
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
auto avatarOrientation = myAvatar->getOrientation();
|
||||
auto eyePos = myAvatar->getDefaultEyePosition();
|
||||
glm::vec3 tip = myAvatar->getLaserPointerTipPosition(&palm);
|
||||
// Direction of the tip relative to the eye
|
||||
glm::vec3 tipDirection = tip - eyePos;
|
||||
// orient into avatar space
|
||||
tipDirection = glm::inverse(avatarOrientation) * tipDirection;
|
||||
glm::vec3 relativePos = myAvatar->getDefaultEyePosition();
|
||||
glm::quat rotation = myAvatar->getOrientation();
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::StandingHMDSensorMode)) {
|
||||
relativePos = _modelTransform.getTranslation();
|
||||
rotation = _modelTransform.getRotation();
|
||||
}
|
||||
glm::vec3 tipDirection = tip - relativePos;
|
||||
tipDirection = glm::inverse(rotation) * tipDirection;
|
||||
// Normalize for trig functions
|
||||
tipDirection = glm::normalize(tipDirection);
|
||||
// Convert to polar coordinates
|
||||
|
@ -251,7 +264,8 @@ vec2 getPolarCoordinates(const PalmData& palm) {
|
|||
// Draws the FBO texture for Oculus rift.
|
||||
void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int eye) {
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
if (_alpha == 0.0f) {
|
||||
|
||||
if (_alpha <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -278,11 +292,13 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
|
||||
batch.setResourceTexture(0, overlayFramebuffer->getRenderBuffer(0));
|
||||
|
||||
batch.setViewTransform(Transform());
|
||||
batch.setProjectionTransform(qApp->getEyeProjection(eye));
|
||||
mat4 camMat;
|
||||
_cameraBaseTransform.getMatrix(camMat);
|
||||
camMat = camMat * qApp->getEyePose(eye);
|
||||
batch.setViewportTransform(renderArgs->_viewport);
|
||||
batch.setViewTransform(camMat);
|
||||
|
||||
mat4 eyePose = qApp->getEyePose(eye);
|
||||
glm::mat4 overlayXfm = glm::inverse(eyePose);
|
||||
batch.setProjectionTransform(qApp->getEyeProjection(eye));
|
||||
|
||||
#ifdef DEBUG_OVERLAY
|
||||
{
|
||||
|
@ -291,7 +307,9 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
}
|
||||
#else
|
||||
{
|
||||
batch.setModelTransform(overlayXfm);
|
||||
//batch.setModelTransform(overlayXfm);
|
||||
|
||||
batch.setModelTransform(_modelTransform);
|
||||
drawSphereSection(batch);
|
||||
}
|
||||
#endif
|
||||
|
@ -302,8 +320,11 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int
|
|||
|
||||
bindCursorTexture(batch);
|
||||
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
//Controller Pointers
|
||||
glm::mat4 overlayXfm;
|
||||
_modelTransform.getMatrix(overlayXfm);
|
||||
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
for (int i = 0; i < (int)myAvatar->getHand()->getNumPalms(); i++) {
|
||||
PalmData& palm = myAvatar->getHand()->getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
|
@ -345,13 +366,18 @@ void ApplicationCompositor::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& or
|
|||
|
||||
// We need the RAW camera orientation and position, because this is what the overlay is
|
||||
// rendered relative to
|
||||
const glm::vec3 overlayPosition = qApp->getCamera()->getPosition();
|
||||
const glm::quat overlayOrientation = qApp->getCamera()->getRotation();
|
||||
glm::vec3 overlayPosition = qApp->getCamera()->getPosition();
|
||||
glm::quat overlayOrientation = qApp->getCamera()->getRotation();
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::StandingHMDSensorMode)) {
|
||||
overlayPosition = _modelTransform.getTranslation();
|
||||
overlayOrientation = _modelTransform.getRotation();
|
||||
}
|
||||
|
||||
// Intersection UI overlay space
|
||||
glm::vec3 worldSpaceDirection = overlayOrientation * overlaySpaceDirection;
|
||||
glm::vec3 worldSpaceIntersection = (glm::normalize(worldSpaceDirection) * _oculusUIRadius) + overlayPosition;
|
||||
glm::vec3 worldSpaceHeadPosition = (overlayOrientation * glm::vec3(qApp->getHeadPose()[3])) + overlayPosition;
|
||||
glm::vec3 worldSpaceHeadPosition = (overlayOrientation * extractTranslation(qApp->getHMDSensorPose())) + overlayPosition;
|
||||
|
||||
// Intersection in world space
|
||||
origin = worldSpaceHeadPosition;
|
||||
|
@ -410,13 +436,15 @@ bool ApplicationCompositor::calculateRayUICollisionPoint(const glm::vec3& positi
|
|||
void ApplicationCompositor::renderPointers(gpu::Batch& batch) {
|
||||
if (qApp->isHMDMode() && !qApp->getLastMouseMoveWasSimulated() && !qApp->isMouseHidden()) {
|
||||
//If we are in oculus, render reticle later
|
||||
auto trueMouse = qApp->getTrueMouse();
|
||||
trueMouse /= qApp->getCanvasSize();
|
||||
QPoint position = QPoint(qApp->getTrueMouseX(), qApp->getTrueMouseY());
|
||||
_reticlePosition[MOUSE] = position;
|
||||
_reticleActive[MOUSE] = true;
|
||||
_magActive[MOUSE] = _magnifier;
|
||||
_reticleActive[LEFT_CONTROLLER] = false;
|
||||
_reticleActive[RIGHT_CONTROLLER] = false;
|
||||
} else if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
||||
} else if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::HandMouseInput)) {
|
||||
//only render controller pointer if we aren't already rendering a mouse pointer
|
||||
_reticleActive[MOUSE] = false;
|
||||
_magActive[MOUSE] = false;
|
||||
|
@ -491,6 +519,7 @@ void ApplicationCompositor::renderControllerPointers(gpu::Batch& batch) {
|
|||
|
||||
auto canvasSize = qApp->getCanvasSize();
|
||||
int mouseX, mouseY;
|
||||
|
||||
// Get directon relative to avatar orientation
|
||||
glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection();
|
||||
|
||||
|
@ -499,7 +528,7 @@ void ApplicationCompositor::renderControllerPointers(gpu::Batch& batch) {
|
|||
float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO));
|
||||
|
||||
// Get the pixel range over which the xAngle and yAngle are scaled
|
||||
float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult();
|
||||
float cursorRange = canvasSize.x * InputDevice::getCursorPixelRangeMult();
|
||||
|
||||
mouseX = (canvasSize.x / 2.0f + cursorRange * xAngle);
|
||||
mouseY = (canvasSize.y / 2.0f + cursorRange * yAngle);
|
||||
|
@ -611,6 +640,19 @@ void ApplicationCompositor::drawSphereSection(gpu::Batch& batch) {
|
|||
batch.setInputFormat(streamFormat);
|
||||
|
||||
static const int VERTEX_STRIDE = sizeof(vec3) + sizeof(vec2) + sizeof(vec4);
|
||||
|
||||
if (_prevAlpha != _alpha) {
|
||||
// adjust alpha by munging vertex color alpha.
|
||||
// FIXME we should probably just use a uniform for this.
|
||||
float* floatPtr = reinterpret_cast<float*>(_hemiVertices->editData());
|
||||
const auto ALPHA_FLOAT_OFFSET = (sizeof(vec3) + sizeof(vec2) + sizeof(vec3)) / sizeof(float);
|
||||
const auto VERTEX_FLOAT_STRIDE = (sizeof(vec3) + sizeof(vec2) + sizeof(vec4)) / sizeof(float);
|
||||
const auto NUM_VERTS = _hemiVertices->getSize() / VERTEX_STRIDE;
|
||||
for (size_t i = 0; i < NUM_VERTS; i++) {
|
||||
floatPtr[i * VERTEX_FLOAT_STRIDE + ALPHA_FLOAT_OFFSET] = _alpha;
|
||||
}
|
||||
}
|
||||
|
||||
gpu::BufferView posView(_hemiVertices, 0, _hemiVertices->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element);
|
||||
gpu::BufferView uvView(_hemiVertices, sizeof(vec3), _hemiVertices->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::TEXCOORD)._element);
|
||||
gpu::BufferView colView(_hemiVertices, sizeof(vec3) + sizeof(vec2), _hemiVertices->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
|
||||
|
@ -700,3 +742,29 @@ void ApplicationCompositor::updateTooltips() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const float FADE_DURATION = 500.0f;
|
||||
void ApplicationCompositor::fadeIn() {
|
||||
_fadeInAlpha = true;
|
||||
|
||||
_alphaPropertyAnimation->setDuration(FADE_DURATION);
|
||||
_alphaPropertyAnimation->setStartValue(_alpha);
|
||||
_alphaPropertyAnimation->setEndValue(1.0f);
|
||||
_alphaPropertyAnimation->start();
|
||||
}
|
||||
void ApplicationCompositor::fadeOut() {
|
||||
_fadeInAlpha = false;
|
||||
|
||||
_alphaPropertyAnimation->setDuration(FADE_DURATION);
|
||||
_alphaPropertyAnimation->setStartValue(_alpha);
|
||||
_alphaPropertyAnimation->setEndValue(0.0f);
|
||||
_alphaPropertyAnimation->start();
|
||||
}
|
||||
|
||||
void ApplicationCompositor::toggle() {
|
||||
if (_fadeInAlpha) {
|
||||
fadeOut();
|
||||
} else {
|
||||
fadeIn();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define hifi_ApplicationCompositor_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QPropertyAnimation>
|
||||
#include <cstdint>
|
||||
|
||||
#include <EntityItemID.h>
|
||||
|
@ -33,6 +34,8 @@ const float DEFAULT_HMD_UI_ANGULAR_SIZE = 72.0f;
|
|||
// facilities of this class
|
||||
class ApplicationCompositor : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(float alpha READ getAlpha WRITE setAlpha)
|
||||
public:
|
||||
ApplicationCompositor();
|
||||
~ApplicationCompositor();
|
||||
|
@ -64,6 +67,19 @@ public:
|
|||
void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const;
|
||||
uint32_t getOverlayTexture() const;
|
||||
|
||||
void setCameraBaseTransform(const Transform& transform) { _cameraBaseTransform = transform; }
|
||||
const Transform& getCameraBaseTransform() const { return _cameraBaseTransform; }
|
||||
|
||||
void setModelTransform(const Transform& transform) { _modelTransform = transform; }
|
||||
const Transform& getModelTransform() const { return _modelTransform; }
|
||||
|
||||
void fadeIn();
|
||||
void fadeOut();
|
||||
void toggle();
|
||||
|
||||
float getAlpha() const { return _alpha; }
|
||||
void setAlpha(float alpha) { _alpha = alpha; }
|
||||
|
||||
static glm::vec2 directionToSpherical(const glm::vec3 & direction);
|
||||
static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos);
|
||||
static glm::vec2 screenToSpherical(const glm::vec2 & screenPos);
|
||||
|
@ -78,7 +94,8 @@ private:
|
|||
|
||||
void renderPointers(gpu::Batch& batch);
|
||||
void renderControllerPointers(gpu::Batch& batch);
|
||||
void renderPointersOculus(gpu::Batch& batch);
|
||||
|
||||
vec2 getPolarCoordinates(const PalmData& palm) const;
|
||||
|
||||
// Support for hovering and tooltips
|
||||
static EntityItemID _noItemId;
|
||||
|
@ -100,6 +117,8 @@ private:
|
|||
bool _magnifier{ true };
|
||||
|
||||
float _alpha{ 1.0f };
|
||||
float _prevAlpha{ 1.0f };
|
||||
float _fadeInAlpha{ true };
|
||||
float _oculusUIRadius{ 1.0f };
|
||||
|
||||
QMap<uint16_t, gpu::TexturePointer> _cursors;
|
||||
|
@ -115,6 +134,11 @@ private:
|
|||
glm::vec3 _previousMagnifierBottomRight;
|
||||
glm::vec3 _previousMagnifierTopLeft;
|
||||
glm::vec3 _previousMagnifierTopRight;
|
||||
|
||||
Transform _modelTransform;
|
||||
Transform _cameraBaseTransform;
|
||||
|
||||
std::unique_ptr<QPropertyAnimation> _alphaPropertyAnimation;
|
||||
};
|
||||
|
||||
#endif // hifi_ApplicationCompositor_h
|
||||
|
|
|
@ -46,12 +46,7 @@ ApplicationOverlay::ApplicationOverlay()
|
|||
// then release it back to the UI for re-use
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
connect(offscreenUi.data(), &OffscreenUi::textureUpdated, this, [&](GLuint textureId) {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->lockTexture(textureId);
|
||||
std::swap(_uiTexture, textureId);
|
||||
if (textureId) {
|
||||
offscreenUi->releaseTexture(textureId);
|
||||
}
|
||||
_uiTexture = textureId;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
//
|
||||
// AvatarAppearanceDialog.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Stojce Slavkovski on 2/20/14.
|
||||
// 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 <QFileDialog>
|
||||
#include <QFont>
|
||||
|
||||
#include <AudioClient.h>
|
||||
#include <avatar/AvatarManager.h>
|
||||
#include <devices/Faceshift.h>
|
||||
#include <devices/SixenseManager.h>
|
||||
#include <NetworkingConstants.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "MainWindow.h"
|
||||
#include "LODManager.h"
|
||||
#include "Menu.h"
|
||||
#include "AvatarAppearanceDialog.h"
|
||||
#include "Snapshot.h"
|
||||
#include "UserActivityLogger.h"
|
||||
#include "UIUtil.h"
|
||||
#include "ui/DialogsManager.h"
|
||||
#include "ui/PreferencesDialog.h"
|
||||
|
||||
AvatarAppearanceDialog::AvatarAppearanceDialog(QWidget* parent) :
|
||||
QDialog(parent) {
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
ui.setupUi(this);
|
||||
|
||||
loadAvatarAppearance();
|
||||
|
||||
connect(ui.defaultButton, &QPushButton::clicked, this, &AvatarAppearanceDialog::accept);
|
||||
|
||||
connect(ui.buttonBrowseHead, &QPushButton::clicked, this, &AvatarAppearanceDialog::openHeadModelBrowser);
|
||||
connect(ui.buttonBrowseBody, &QPushButton::clicked, this, &AvatarAppearanceDialog::openBodyModelBrowser);
|
||||
connect(ui.buttonBrowseFullAvatar, &QPushButton::clicked, this, &AvatarAppearanceDialog::openFullAvatarModelBrowser);
|
||||
|
||||
connect(ui.useSeparateBodyAndHead, &QRadioButton::clicked, this, &AvatarAppearanceDialog::useSeparateBodyAndHead);
|
||||
connect(ui.useFullAvatar, &QRadioButton::clicked, this, &AvatarAppearanceDialog::useFullAvatar);
|
||||
|
||||
connect(Application::getInstance(), &Application::headURLChanged, this, &AvatarAppearanceDialog::headURLChanged);
|
||||
connect(Application::getInstance(), &Application::bodyURLChanged, this, &AvatarAppearanceDialog::bodyURLChanged);
|
||||
connect(Application::getInstance(), &Application::fullAvatarURLChanged, this, &AvatarAppearanceDialog::fullAvatarURLChanged);
|
||||
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
|
||||
ui.bodyNameLabel->setText("Body - " + myAvatar->getBodyModelName());
|
||||
ui.headNameLabel->setText("Head - " + myAvatar->getHeadModelName());
|
||||
ui.fullAvatarNameLabel->setText("Full Avatar - " + myAvatar->getFullAvartarModelName());
|
||||
|
||||
UIUtil::scaleWidgetFontSizes(this);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::useSeparateBodyAndHead(bool checked) {
|
||||
QUrl headURL(ui.faceURLEdit->text());
|
||||
QUrl bodyURL(ui.skeletonURLEdit->text());
|
||||
DependencyManager::get<AvatarManager>()->getMyAvatar()->useHeadAndBodyURLs(headURL, bodyURL);
|
||||
setUseFullAvatar(!checked);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::useFullAvatar(bool checked) {
|
||||
QUrl fullAvatarURL(ui.fullAvatarURLEdit->text());
|
||||
DependencyManager::get<AvatarManager>()->getMyAvatar()->useFullAvatarURL(fullAvatarURL);
|
||||
setUseFullAvatar(checked);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::setUseFullAvatar(bool useFullAvatar) {
|
||||
_useFullAvatar = useFullAvatar;
|
||||
ui.faceURLEdit->setEnabled(!_useFullAvatar);
|
||||
ui.skeletonURLEdit->setEnabled(!_useFullAvatar);
|
||||
ui.fullAvatarURLEdit->setEnabled(_useFullAvatar);
|
||||
|
||||
ui.useFullAvatar->setChecked(_useFullAvatar);
|
||||
ui.useSeparateBodyAndHead->setChecked(!_useFullAvatar);
|
||||
|
||||
QPointer<PreferencesDialog> prefs = DependencyManager::get<DialogsManager>()->getPreferencesDialog();
|
||||
if (prefs) { // Preferences dialog may have been closed
|
||||
prefs->avatarDescriptionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::headURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.faceURLEdit->setText(newValue);
|
||||
setUseFullAvatar(false);
|
||||
ui.headNameLabel->setText("Head - " + modelName);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::bodyURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.skeletonURLEdit->setText(newValue);
|
||||
setUseFullAvatar(false);
|
||||
ui.bodyNameLabel->setText("Body - " + modelName);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::fullAvatarURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.fullAvatarURLEdit->setText(newValue);
|
||||
setUseFullAvatar(true);
|
||||
ui.fullAvatarNameLabel->setText("Full Avatar - " + modelName);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::accept() {
|
||||
saveAvatarAppearance();
|
||||
|
||||
QPointer<PreferencesDialog> prefs = DependencyManager::get<DialogsManager>()->getPreferencesDialog();
|
||||
if (prefs) { // Preferences dialog may have been closed
|
||||
prefs->avatarDescriptionChanged();
|
||||
}
|
||||
|
||||
close();
|
||||
delete _marketplaceWindow;
|
||||
_marketplaceWindow = NULL;
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::setHeadUrl(QString modelUrl) {
|
||||
ui.faceURLEdit->setText(modelUrl);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::setSkeletonUrl(QString modelUrl) {
|
||||
ui.skeletonURLEdit->setText(modelUrl);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::openFullAvatarModelBrowser() {
|
||||
auto MARKETPLACE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace?category=avatars";
|
||||
auto WIDTH = 900;
|
||||
auto HEIGHT = 700;
|
||||
if (!_marketplaceWindow) {
|
||||
_marketplaceWindow = new WebWindowClass("Marketplace", MARKETPLACE_URL, WIDTH, HEIGHT, false);
|
||||
}
|
||||
_marketplaceWindow->setVisible(true);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::openHeadModelBrowser() {
|
||||
auto MARKETPLACE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace?category=avatars";
|
||||
auto WIDTH = 900;
|
||||
auto HEIGHT = 700;
|
||||
if (!_marketplaceWindow) {
|
||||
_marketplaceWindow = new WebWindowClass("Marketplace", MARKETPLACE_URL, WIDTH, HEIGHT, false);
|
||||
}
|
||||
_marketplaceWindow->setVisible(true);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::openBodyModelBrowser() {
|
||||
auto MARKETPLACE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace?category=avatars";
|
||||
auto WIDTH = 900;
|
||||
auto HEIGHT = 700;
|
||||
if (!_marketplaceWindow) {
|
||||
_marketplaceWindow = new WebWindowClass("Marketplace", MARKETPLACE_URL, WIDTH, HEIGHT, false);
|
||||
}
|
||||
_marketplaceWindow->setVisible(true);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::resizeEvent(QResizeEvent *resizeEvent) {
|
||||
|
||||
// keep buttons panel at the bottom
|
||||
ui.buttonsPanel->setGeometry(0,
|
||||
size().height() - ui.buttonsPanel->height(),
|
||||
size().width(),
|
||||
ui.buttonsPanel->height());
|
||||
|
||||
// set width and height of srcollarea to match bottom panel and width
|
||||
ui.scrollArea->setGeometry(ui.scrollArea->geometry().x(), ui.scrollArea->geometry().y(),
|
||||
size().width(),
|
||||
size().height() - ui.buttonsPanel->height() - ui.scrollArea->geometry().y());
|
||||
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::loadAvatarAppearance() {
|
||||
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
|
||||
_useFullAvatar = myAvatar->getUseFullAvatar();
|
||||
_fullAvatarURLString = myAvatar->getFullAvatarURLFromPreferences().toString();
|
||||
_headURLString = myAvatar->getHeadURLFromPreferences().toString();
|
||||
_bodyURLString = myAvatar->getBodyURLFromPreferences().toString();
|
||||
|
||||
ui.fullAvatarURLEdit->setText(_fullAvatarURLString);
|
||||
ui.faceURLEdit->setText(_headURLString);
|
||||
ui.skeletonURLEdit->setText(_bodyURLString);
|
||||
setUseFullAvatar(_useFullAvatar);
|
||||
}
|
||||
|
||||
void AvatarAppearanceDialog::saveAvatarAppearance() {
|
||||
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
|
||||
QUrl headURL(ui.faceURLEdit->text());
|
||||
QString headURLString = headURL.toString();
|
||||
|
||||
QUrl bodyURL(ui.skeletonURLEdit->text());
|
||||
QString bodyURLString = bodyURL.toString();
|
||||
|
||||
QUrl fullAvatarURL(ui.fullAvatarURLEdit->text());
|
||||
QString fullAvatarURLString = fullAvatarURL.toString();
|
||||
|
||||
bool somethingChanged =
|
||||
_useFullAvatar != myAvatar->getUseFullAvatar() ||
|
||||
fullAvatarURLString != myAvatar->getFullAvatarURLFromPreferences().toString() ||
|
||||
headURLString != myAvatar->getHeadURLFromPreferences().toString() ||
|
||||
bodyURLString != myAvatar->getBodyURLFromPreferences().toString();
|
||||
|
||||
if (somethingChanged) {
|
||||
if (_useFullAvatar) {
|
||||
myAvatar->useFullAvatarURL(fullAvatarURL);
|
||||
} else {
|
||||
myAvatar->useHeadAndBodyURLs(headURL, bodyURL);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
//
|
||||
// AvatarAppearanceDialog.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Stojce Slavkovski on 2/20/14.
|
||||
// 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_AvatarAppearanceDialog_h
|
||||
#define hifi_AvatarAppearanceDialog_h
|
||||
|
||||
#include "ui_avatarAppearance.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
#include "scripting/WebWindowClass.h"
|
||||
|
||||
class AvatarAppearanceDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AvatarAppearanceDialog(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* resizeEvent);
|
||||
|
||||
private:
|
||||
void loadAvatarAppearance();
|
||||
void saveAvatarAppearance();
|
||||
void openHeadModelBrowser();
|
||||
void openBodyModelBrowser();
|
||||
void openFullAvatarModelBrowser();
|
||||
void setUseFullAvatar(bool useFullAvatar);
|
||||
|
||||
Ui_AvatarAppearanceDialog ui;
|
||||
|
||||
bool _useFullAvatar;
|
||||
QString _headURLString;
|
||||
QString _bodyURLString;
|
||||
QString _fullAvatarURLString;
|
||||
|
||||
|
||||
QString _displayNameString;
|
||||
|
||||
WebWindowClass* _marketplaceWindow = NULL;
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void setHeadUrl(QString modelUrl);
|
||||
void setSkeletonUrl(QString modelUrl);
|
||||
void headURLChanged(const QString& newValue, const QString& modelName);
|
||||
void bodyURLChanged(const QString& newValue, const QString& modelName);
|
||||
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
||||
void useSeparateBodyAndHead(bool checked);
|
||||
void useFullAvatar(bool checked);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarAppearanceDialog_h
|
|
@ -20,7 +20,6 @@
|
|||
#include "AddressBarDialog.h"
|
||||
#include "AnimationsDialog.h"
|
||||
#include "AttachmentsDialog.h"
|
||||
#include "AvatarAppearanceDialog.h"
|
||||
#include "BandwidthDialog.h"
|
||||
#include "CachesSizeDialog.h"
|
||||
#include "DiskCacheEditor.h"
|
||||
|
@ -88,15 +87,6 @@ void DialogsManager::editPreferences() {
|
|||
}
|
||||
}
|
||||
|
||||
void DialogsManager::changeAvatarAppearance() {
|
||||
if (!_avatarAppearanceDialog) {
|
||||
maybeCreateDialog(_avatarAppearanceDialog);
|
||||
_avatarAppearanceDialog->show();
|
||||
} else {
|
||||
_avatarAppearanceDialog->close();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogsManager::editAttachments() {
|
||||
if (!_attachmentsDialog) {
|
||||
maybeCreateDialog(_attachmentsDialog);
|
||||
|
@ -173,7 +163,6 @@ void DialogsManager::hmdTools(bool showTools) {
|
|||
}
|
||||
|
||||
void DialogsManager::hmdToolsClosed() {
|
||||
Menu::getInstance()->getActionForOption(MenuOption::HMDTools)->setChecked(false);
|
||||
_hmdToolsDialog->hide();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ class OctreeStatsDialog;
|
|||
class PreferencesDialog;
|
||||
class ScriptEditorWindow;
|
||||
class QMessageBox;
|
||||
class AvatarAppearanceDialog;
|
||||
class DomainConnectionDialog;
|
||||
class UpdateDialog;
|
||||
|
||||
|
@ -66,7 +65,6 @@ public slots:
|
|||
void hmdTools(bool showTools);
|
||||
void showScriptEditor();
|
||||
void showIRCLink();
|
||||
void changeAvatarAppearance();
|
||||
void showDomainConnectionDialog();
|
||||
|
||||
// Application Update
|
||||
|
@ -110,7 +108,6 @@ private:
|
|||
QPointer<OctreeStatsDialog> _octreeStatsDialog;
|
||||
QPointer<PreferencesDialog> _preferencesDialog;
|
||||
QPointer<ScriptEditorWindow> _scriptEditor;
|
||||
QPointer<AvatarAppearanceDialog> _avatarAppearanceDialog;
|
||||
QPointer<DomainConnectionDialog> _domainConnectionDialog;
|
||||
QPointer<UpdateDialog> _updateDialog;
|
||||
};
|
||||
|
|
|
@ -19,48 +19,60 @@
|
|||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
|
||||
#include <plugins/PluginManager.h>
|
||||
#include <display-plugins/DisplayPlugin.h>
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Menu.h"
|
||||
#include "ui/DialogsManager.h"
|
||||
#include "ui/HMDToolsDialog.h"
|
||||
#include "devices/OculusManager.h"
|
||||
|
||||
static const int WIDTH = 350;
|
||||
static const int HEIGHT = 100;
|
||||
|
||||
|
||||
HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) ,
|
||||
_previousScreen(NULL),
|
||||
_hmdScreen(NULL),
|
||||
_hmdScreenNumber(-1),
|
||||
_switchModeButton(NULL),
|
||||
_debugDetails(NULL),
|
||||
_previousDialogScreen(NULL),
|
||||
_inHDMMode(false)
|
||||
QDialog(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint)
|
||||
{
|
||||
this->setWindowTitle("HMD Tools");
|
||||
// FIXME do we want to support more than one connected HMD? It seems like a pretty corner case
|
||||
foreach(auto displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) {
|
||||
// The first plugin is always the standard 2D display, by convention
|
||||
if (_defaultPluginName.isEmpty()) {
|
||||
_defaultPluginName = displayPlugin->getName();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (displayPlugin->isHmd()) {
|
||||
// Not all HMD's have corresponding screens
|
||||
if (displayPlugin->getHmdScreen() >= 0) {
|
||||
_hmdScreenNumber = displayPlugin->getHmdScreen();
|
||||
}
|
||||
_hmdPluginName = displayPlugin->getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setWindowTitle("HMD Tools");
|
||||
|
||||
// Create layouter
|
||||
QFormLayout* form = new QFormLayout();
|
||||
const int WIDTH = 350;
|
||||
{
|
||||
QFormLayout* form = new QFormLayout();
|
||||
// Add a button to enter
|
||||
_switchModeButton = new QPushButton("Toggle HMD Mode");
|
||||
if (_hmdPluginName.isEmpty()) {
|
||||
_switchModeButton->setEnabled(false);
|
||||
}
|
||||
// Add a button to enter
|
||||
_switchModeButton->setFixedWidth(WIDTH);
|
||||
form->addRow("", _switchModeButton);
|
||||
// Create a label with debug details...
|
||||
_debugDetails = new QLabel();
|
||||
_debugDetails->setFixedSize(WIDTH, HEIGHT);
|
||||
form->addRow("", _debugDetails);
|
||||
setLayout(form);
|
||||
}
|
||||
|
||||
// Add a button to enter
|
||||
_switchModeButton = new QPushButton("Enter HMD Mode");
|
||||
_switchModeButton->setFixedWidth(WIDTH);
|
||||
form->addRow("", _switchModeButton);
|
||||
connect(_switchModeButton,SIGNAL(clicked(bool)),this,SLOT(switchModeClicked(bool)));
|
||||
|
||||
// Create a label with debug details...
|
||||
_debugDetails = new QLabel();
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
const int HEIGHT = 100;
|
||||
_debugDetails->setFixedSize(WIDTH, HEIGHT);
|
||||
form->addRow("", _debugDetails);
|
||||
|
||||
this->QDialog::setLayout(form);
|
||||
|
||||
Application::getInstance()->getWindow()->activateWindow();
|
||||
|
||||
// watch for our application window moving screens. If it does we want to update our screen details
|
||||
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
||||
connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged);
|
||||
qApp->getWindow()->activateWindow();
|
||||
|
||||
// watch for our dialog window moving screens. If it does we want to enforce our rules about
|
||||
// what screens we're allowed on
|
||||
|
@ -82,11 +94,31 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
|||
watchWindow(dialogsManager->getLodToolsDialog()->windowHandle());
|
||||
}
|
||||
|
||||
connect(_switchModeButton, &QPushButton::clicked, [this]{
|
||||
toggleHMDMode();
|
||||
});
|
||||
|
||||
// when the application is about to quit, leave HDM mode
|
||||
connect(Application::getInstance(), SIGNAL(beforeAboutToQuit()), this, SLOT(aboutToQuit()));
|
||||
connect(qApp, &Application::beforeAboutToQuit, [this]{
|
||||
// FIXME this is ineffective because it doesn't trigger the menu to
|
||||
// save the fact that VR Mode is not checked.
|
||||
leaveHMDMode();
|
||||
});
|
||||
|
||||
connect(qApp, &Application::activeDisplayPluginChanged, [this]{
|
||||
updateUi();
|
||||
});
|
||||
|
||||
// watch for our application window moving screens. If it does we want to update our screen details
|
||||
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
||||
connect(mainWindow, &QWindow::screenChanged, [this]{
|
||||
updateUi();
|
||||
});
|
||||
|
||||
// keep track of changes to the number of screens
|
||||
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged);
|
||||
|
||||
updateUi();
|
||||
}
|
||||
|
||||
HMDToolsDialog::~HMDToolsDialog() {
|
||||
|
@ -96,18 +128,13 @@ HMDToolsDialog::~HMDToolsDialog() {
|
|||
_windowWatchers.clear();
|
||||
}
|
||||
|
||||
void HMDToolsDialog::applicationWindowScreenChanged(QScreen* screen) {
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
}
|
||||
|
||||
QString HMDToolsDialog::getDebugDetails() const {
|
||||
QString results;
|
||||
|
||||
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||
if (hmdScreenNumber >= 0) {
|
||||
results += "HMD Screen: " + QGuiApplication::screens()[hmdScreenNumber]->name() + "\n";
|
||||
if (_hmdScreenNumber >= 0) {
|
||||
results += "HMD Screen: " + QGuiApplication::screens()[_hmdScreenNumber]->name() + "\n";
|
||||
} else {
|
||||
results += "HMD Screen Name: Unknown\n";
|
||||
results += "HMD Screen Name: N/A\n";
|
||||
}
|
||||
|
||||
int desktopPrimaryScreenNumber = QApplication::desktop()->primaryScreen();
|
||||
|
@ -122,49 +149,35 @@ QString HMDToolsDialog::getDebugDetails() const {
|
|||
return results;
|
||||
}
|
||||
|
||||
void HMDToolsDialog::switchModeClicked(bool checked) {
|
||||
if (!_inHDMMode) {
|
||||
enterHDMMode();
|
||||
void HMDToolsDialog::toggleHMDMode() {
|
||||
if (!qApp->isHMDMode()) {
|
||||
enterHMDMode();
|
||||
} else {
|
||||
leaveHDMMode();
|
||||
leaveHMDMode();
|
||||
}
|
||||
}
|
||||
|
||||
void HMDToolsDialog::enterHDMMode() {
|
||||
if (!_inHDMMode) {
|
||||
_switchModeButton->setText("Leave HMD Mode");
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
|
||||
// if we're on a single screen setup, then hide our tools window when entering HMD mode
|
||||
if (QApplication::desktop()->screenCount() == 1) {
|
||||
close();
|
||||
}
|
||||
|
||||
Application::getInstance()->setEnableVRMode(true);
|
||||
|
||||
_inHDMMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HMDToolsDialog::leaveHDMMode() {
|
||||
if (_inHDMMode) {
|
||||
_switchModeButton->setText("Enter HMD Mode");
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
Application::getInstance()->setEnableVRMode(false);
|
||||
void HMDToolsDialog::enterHMDMode() {
|
||||
if (!qApp->isHMDMode()) {
|
||||
Application::getInstance()->setActiveDisplayPlugin(_hmdPluginName);
|
||||
Application::getInstance()->getWindow()->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void HMDToolsDialog::leaveHMDMode() {
|
||||
if (qApp->isHMDMode()) {
|
||||
Application::getInstance()->setActiveDisplayPlugin(_defaultPluginName);
|
||||
Application::getInstance()->getWindow()->activateWindow();
|
||||
_inHDMMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
void HMDToolsDialog::reject() {
|
||||
// Just regularly close upon ESC
|
||||
close();
|
||||
// We don't want this window to be closable from a close icon, just from our "Leave HMD Mode" button
|
||||
}
|
||||
|
||||
void HMDToolsDialog::closeEvent(QCloseEvent* event) {
|
||||
// TODO: consider if we want to prevent closing of this window with event->ignore();
|
||||
this->QDialog::closeEvent(event);
|
||||
emit closed();
|
||||
// We don't want this window to be closable from a close icon, just from our "Leave HMD Mode" button
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void HMDToolsDialog::centerCursorOnWidget(QWidget* widget) {
|
||||
|
@ -174,9 +187,15 @@ void HMDToolsDialog::centerCursorOnWidget(QWidget* widget) {
|
|||
QCursor::setPos(screen, windowCenter);
|
||||
}
|
||||
|
||||
void HMDToolsDialog::updateUi() {
|
||||
_switchModeButton->setText(qApp->isHMDMode() ? "Leave HMD Mode" : "Enter HMD Mode");
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
}
|
||||
|
||||
void HMDToolsDialog::showEvent(QShowEvent* event) {
|
||||
// center the cursor on the hmd tools dialog
|
||||
centerCursorOnWidget(this);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void HMDToolsDialog::hideEvent(QHideEvent* event) {
|
||||
|
@ -184,33 +203,31 @@ void HMDToolsDialog::hideEvent(QHideEvent* event) {
|
|||
centerCursorOnWidget(Application::getInstance()->getWindow());
|
||||
}
|
||||
|
||||
|
||||
void HMDToolsDialog::aboutToQuit() {
|
||||
if (_inHDMMode) {
|
||||
// FIXME this is ineffective because it doesn't trigger the menu to
|
||||
// save the fact that VR Mode is not checked.
|
||||
leaveHDMMode();
|
||||
}
|
||||
}
|
||||
|
||||
void HMDToolsDialog::screenCountChanged(int newCount) {
|
||||
if (!OculusManager::isConnected()) {
|
||||
//OculusManager::connect();
|
||||
int hmdScreenNumber = -1;
|
||||
auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
|
||||
foreach(auto dp, displayPlugins) {
|
||||
if (dp->isHmd()) {
|
||||
if (dp->getHmdScreen() >= 0) {
|
||||
hmdScreenNumber = dp->getHmdScreen();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||
|
||||
if (_inHDMMode && _hmdScreenNumber != hmdScreenNumber) {
|
||||
if (qApp->isHMDMode() && _hmdScreenNumber != hmdScreenNumber) {
|
||||
qDebug() << "HMD Display changed WHILE IN HMD MODE";
|
||||
leaveHDMMode();
|
||||
leaveHMDMode();
|
||||
|
||||
// if there is a new best HDM screen then go back into HDM mode after done leaving
|
||||
if (hmdScreenNumber >= 0) {
|
||||
qDebug() << "Trying to go back into HDM Mode";
|
||||
qDebug() << "Trying to go back into HMD Mode";
|
||||
const int SLIGHT_DELAY = 2000;
|
||||
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(enterHDMMode()));
|
||||
QTimer::singleShot(SLIGHT_DELAY, [this]{
|
||||
enterHMDMode();
|
||||
});
|
||||
}
|
||||
}
|
||||
_debugDetails->setText(getDebugDetails());
|
||||
}
|
||||
|
||||
void HMDToolsDialog::watchWindow(QWindow* window) {
|
||||
|
@ -247,9 +264,8 @@ void HMDWindowWatcher::windowScreenChanged(QScreen* screen) {
|
|||
// if we have more than one screen, and a known hmdScreen then try to
|
||||
// keep our dialog off of the hmdScreen
|
||||
if (QApplication::desktop()->screenCount() > 1) {
|
||||
|
||||
int hmdScreenNumber = _hmdTools->_hmdScreenNumber;
|
||||
// we want to use a local variable here because we are not necesarily in HMD mode
|
||||
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||
if (hmdScreenNumber >= 0) {
|
||||
QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber];
|
||||
if (screen == hmdScreen) {
|
||||
|
|
|
@ -34,9 +34,6 @@ signals:
|
|||
|
||||
public slots:
|
||||
void reject();
|
||||
void switchModeClicked(bool checked);
|
||||
void applicationWindowScreenChanged(QScreen* screen);
|
||||
void aboutToQuit();
|
||||
void screenCountChanged(int newCount);
|
||||
|
||||
protected:
|
||||
|
@ -46,20 +43,24 @@ protected:
|
|||
|
||||
private:
|
||||
void centerCursorOnWidget(QWidget* widget);
|
||||
void enterHDMMode();
|
||||
void leaveHDMMode();
|
||||
void enterHMDMode();
|
||||
void leaveHMDMode();
|
||||
void toggleHMDMode();
|
||||
void updateUi();
|
||||
|
||||
QScreen* _previousScreen;
|
||||
QScreen* _hmdScreen;
|
||||
int _hmdScreenNumber;
|
||||
QPushButton* _switchModeButton;
|
||||
QLabel* _debugDetails;
|
||||
QScreen* _previousScreen{ nullptr };
|
||||
QScreen* _hmdScreen{ nullptr };
|
||||
int _hmdScreenNumber{ -1 };
|
||||
QPushButton* _switchModeButton{ nullptr };
|
||||
QLabel* _debugDetails{ nullptr };
|
||||
|
||||
QRect _previousDialogRect;
|
||||
QScreen* _previousDialogScreen;
|
||||
bool _inHDMMode;
|
||||
QScreen* _previousDialogScreen{ nullptr };
|
||||
QString _hmdPluginName;
|
||||
QString _defaultPluginName;
|
||||
|
||||
QHash<QWindow*, HMDWindowWatcher*> _windowWatchers;
|
||||
friend class HMDWindowWatcher;
|
||||
};
|
||||
|
||||
|
||||
|
|
157
interface/src/ui/OverlayConductor.cpp
Normal file
157
interface/src/ui/OverlayConductor.cpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
//
|
||||
// OverlayConductor.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Copyright 2015 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 "Application.h"
|
||||
#include "InterfaceLogging.h"
|
||||
#include "avatar/AvatarManager.h"
|
||||
|
||||
#include "OverlayConductor.h"
|
||||
|
||||
OverlayConductor::OverlayConductor() {
|
||||
}
|
||||
|
||||
OverlayConductor::~OverlayConductor() {
|
||||
}
|
||||
|
||||
void OverlayConductor::update(float dt) {
|
||||
|
||||
updateMode();
|
||||
|
||||
switch (_mode) {
|
||||
case SITTING: {
|
||||
// when sitting, the overlay is at the origin, facing down the -z axis.
|
||||
// the camera is taken directly from the HMD.
|
||||
Transform identity;
|
||||
qApp->getApplicationCompositor().setModelTransform(identity);
|
||||
qApp->getApplicationCompositor().setCameraBaseTransform(identity);
|
||||
break;
|
||||
}
|
||||
case STANDING: {
|
||||
// when standing, the overlay is at a reference position, which is set when the overlay is
|
||||
// enabled. The camera is taken directly from the HMD, but in world space.
|
||||
// So the sensorToWorldMatrix must be applied.
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
Transform t;
|
||||
t.evalFromRawMatrix(myAvatar->getSensorToWorldMatrix());
|
||||
qApp->getApplicationCompositor().setCameraBaseTransform(t);
|
||||
|
||||
// detect when head moves out side of sweet spot, or looks away.
|
||||
mat4 headMat = myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose();
|
||||
vec3 headWorldPos = extractTranslation(headMat);
|
||||
vec3 headForward = glm::quat_cast(headMat) * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
Transform modelXform = qApp->getApplicationCompositor().getModelTransform();
|
||||
vec3 compositorWorldPos = modelXform.getTranslation();
|
||||
vec3 compositorForward = modelXform.getRotation() * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
const float MAX_COMPOSITOR_DISTANCE = 0.6f;
|
||||
const float MAX_COMPOSITOR_ANGLE = 110.0f;
|
||||
if (_enabled && (glm::distance(headWorldPos, compositorWorldPos) > MAX_COMPOSITOR_DISTANCE ||
|
||||
glm::dot(headForward, compositorForward) < cosf(glm::radians(MAX_COMPOSITOR_ANGLE)))) {
|
||||
// fade out the overlay
|
||||
setEnabled(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FLAT:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayConductor::updateMode() {
|
||||
|
||||
Mode newMode;
|
||||
if (qApp->isHMDMode()) {
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
if (myAvatar->getStandingHMDSensorMode()) {
|
||||
newMode = STANDING;
|
||||
} else {
|
||||
newMode = SITTING;
|
||||
}
|
||||
} else {
|
||||
newMode = FLAT;
|
||||
}
|
||||
|
||||
if (newMode != _mode) {
|
||||
switch (newMode) {
|
||||
case SITTING: {
|
||||
// enter the SITTING state
|
||||
// place the overlay at origin
|
||||
Transform identity;
|
||||
qApp->getApplicationCompositor().setModelTransform(identity);
|
||||
break;
|
||||
}
|
||||
case STANDING: {
|
||||
// enter the STANDING state
|
||||
// place the overlay at the current hmd position in world space
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose());
|
||||
Transform t;
|
||||
t.setTranslation(extractTranslation(camMat));
|
||||
t.setRotation(glm::quat_cast(camMat));
|
||||
qApp->getApplicationCompositor().setModelTransform(t);
|
||||
break;
|
||||
}
|
||||
|
||||
case FLAT:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_mode = newMode;
|
||||
}
|
||||
|
||||
void OverlayConductor::setEnabled(bool enabled) {
|
||||
|
||||
if (enabled == _enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_enabled) {
|
||||
// alpha fadeOut the overlay mesh.
|
||||
qApp->getApplicationCompositor().fadeOut();
|
||||
|
||||
// disable mouse clicks from script
|
||||
qApp->getOverlays().disable();
|
||||
|
||||
// disable QML events
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->getRootItem()->setEnabled(false);
|
||||
|
||||
_enabled = false;
|
||||
} else {
|
||||
// alpha fadeIn the overlay mesh.
|
||||
qApp->getApplicationCompositor().fadeIn();
|
||||
|
||||
// enable mouse clicks from script
|
||||
qApp->getOverlays().enable();
|
||||
|
||||
// enable QML events
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->getRootItem()->setEnabled(true);
|
||||
|
||||
if (_mode == STANDING) {
|
||||
// place the overlay at the current hmd position in world space
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose());
|
||||
Transform t;
|
||||
t.setTranslation(extractTranslation(camMat));
|
||||
t.setRotation(glm::quat_cast(camMat));
|
||||
qApp->getApplicationCompositor().setModelTransform(t);
|
||||
}
|
||||
|
||||
_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool OverlayConductor::getEnabled() const {
|
||||
return _enabled;
|
||||
}
|
||||
|
36
interface/src/ui/OverlayConductor.h
Normal file
36
interface/src/ui/OverlayConductor.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// OverlayConductor.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Copyright 2015 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_OverlayConductor_h
|
||||
#define hifi_OverlayConductor_h
|
||||
|
||||
class OverlayConductor {
|
||||
public:
|
||||
OverlayConductor();
|
||||
~OverlayConductor();
|
||||
|
||||
void update(float dt);
|
||||
void setEnabled(bool enable);
|
||||
bool getEnabled() const;
|
||||
|
||||
private:
|
||||
void updateMode();
|
||||
|
||||
enum Mode {
|
||||
FLAT,
|
||||
SITTING,
|
||||
STANDING
|
||||
};
|
||||
|
||||
Mode _mode = FLAT;
|
||||
bool _enabled = true;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -16,7 +16,7 @@
|
|||
#include <avatar/AvatarManager.h>
|
||||
#include <devices/DdeFaceTracker.h>
|
||||
#include <devices/Faceshift.h>
|
||||
#include <devices/SixenseManager.h>
|
||||
#include <input-plugins/SixenseManager.h> // TODO: This should be replaced with InputDevice/InputPlugin, or something similar
|
||||
#include <NetworkingConstants.h>
|
||||
|
||||
#include "Application.h"
|
||||
|
@ -47,45 +47,45 @@ PreferencesDialog::PreferencesDialog(QWidget* parent) :
|
|||
connect(ui.buttonBrowseScriptsLocation, &QPushButton::clicked, this, &PreferencesDialog::openScriptsLocationBrowser);
|
||||
connect(ui.buttonReloadDefaultScripts, &QPushButton::clicked, Application::getInstance(), &Application::loadDefaultScripts);
|
||||
|
||||
DialogsManager* dialogsManager = DependencyManager::get<DialogsManager>().data();
|
||||
connect(ui.buttonChangeApperance, &QPushButton::clicked, dialogsManager, &DialogsManager::changeAvatarAppearance);
|
||||
|
||||
connect(Application::getInstance(), &Application::headURLChanged, this, &PreferencesDialog::headURLChanged);
|
||||
connect(Application::getInstance(), &Application::bodyURLChanged, this, &PreferencesDialog::bodyURLChanged);
|
||||
connect(ui.buttonChangeAppearance, &QPushButton::clicked, this, &PreferencesDialog::openFullAvatarModelBrowser);
|
||||
connect(ui.appearanceDescription, &QLineEdit::textChanged, this, [this](const QString& url) {
|
||||
this->fullAvatarURLChanged(url, "");
|
||||
});
|
||||
connect(Application::getInstance(), &Application::fullAvatarURLChanged, this, &PreferencesDialog::fullAvatarURLChanged);
|
||||
|
||||
// move dialog to left side
|
||||
move(parentWidget()->geometry().topLeft());
|
||||
setFixedHeight(parentWidget()->size().height() - PREFERENCES_HEIGHT_PADDING);
|
||||
|
||||
ui.apperanceDescription->setText(DependencyManager::get<AvatarManager>()->getMyAvatar()->getModelDescription());
|
||||
|
||||
UIUtil::scaleWidgetFontSizes(this);
|
||||
}
|
||||
|
||||
void PreferencesDialog::avatarDescriptionChanged() {
|
||||
ui.apperanceDescription->setText(DependencyManager::get<AvatarManager>()->getMyAvatar()->getModelDescription());
|
||||
}
|
||||
|
||||
void PreferencesDialog::headURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.apperanceDescription->setText(DependencyManager::get<AvatarManager>()->getMyAvatar()->getModelDescription());
|
||||
}
|
||||
|
||||
void PreferencesDialog::bodyURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.apperanceDescription->setText(DependencyManager::get<AvatarManager>()->getMyAvatar()->getModelDescription());
|
||||
}
|
||||
|
||||
void PreferencesDialog::fullAvatarURLChanged(const QString& newValue, const QString& modelName) {
|
||||
ui.apperanceDescription->setText(DependencyManager::get<AvatarManager>()->getMyAvatar()->getModelDescription());
|
||||
ui.appearanceDescription->setText(newValue);
|
||||
const QString APPEARANCE_LABEL_TEXT("Appearance: ");
|
||||
ui.appearanceLabel->setText(APPEARANCE_LABEL_TEXT + modelName);
|
||||
DependencyManager::get<AvatarManager>()->getMyAvatar()->useFullAvatarURL(newValue, modelName);
|
||||
}
|
||||
|
||||
void PreferencesDialog::accept() {
|
||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
_lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
|
||||
_lastGoodAvatarName = myAvatar->getFullAvatarModelName();
|
||||
savePreferences();
|
||||
close();
|
||||
delete _marketplaceWindow;
|
||||
_marketplaceWindow = NULL;
|
||||
}
|
||||
|
||||
void PreferencesDialog::restoreLastGoodAvatar() {
|
||||
fullAvatarURLChanged(_lastGoodAvatarURL.toString(), _lastGoodAvatarName);
|
||||
}
|
||||
|
||||
void PreferencesDialog::reject() {
|
||||
restoreLastGoodAvatar();
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void PreferencesDialog::openSnapshotLocationBrowser() {
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
|
||||
|
@ -103,6 +103,16 @@ void PreferencesDialog::openScriptsLocationBrowser() {
|
|||
ui.scriptsLocationEdit->setText(dir);
|
||||
}
|
||||
}
|
||||
void PreferencesDialog::openFullAvatarModelBrowser() {
|
||||
const auto MARKETPLACE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace?category=avatars";
|
||||
const auto WIDTH = 900;
|
||||
const auto HEIGHT = 700;
|
||||
if (!_marketplaceWindow) {
|
||||
_marketplaceWindow = new WebWindowClass("Marketplace", MARKETPLACE_URL, WIDTH, HEIGHT, false);
|
||||
}
|
||||
_marketplaceWindow->setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
void PreferencesDialog::resizeEvent(QResizeEvent *resizeEvent) {
|
||||
|
||||
|
@ -129,6 +139,10 @@ void PreferencesDialog::loadPreferences() {
|
|||
|
||||
ui.collisionSoundURLEdit->setText(myAvatar->getCollisionSoundURL());
|
||||
|
||||
_lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
|
||||
_lastGoodAvatarName = myAvatar->getFullAvatarModelName();
|
||||
fullAvatarURLChanged(_lastGoodAvatarURL.toString(), _lastGoodAvatarName);
|
||||
|
||||
ui.sendDataCheckBox->setChecked(!menuInstance->isOptionChecked(MenuOption::DisableActivityLogger));
|
||||
|
||||
ui.snapshotLocationEdit->setText(Snapshot::snapshotsLocation.get());
|
||||
|
@ -177,10 +191,13 @@ void PreferencesDialog::loadPreferences() {
|
|||
|
||||
ui.maxOctreePPSSpin->setValue(qApp->getMaxOctreePacketsPerSecond());
|
||||
|
||||
#if 0
|
||||
ui.oculusUIAngularSizeSpin->setValue(qApp->getApplicationCompositor().getHmdUIAngularSize());
|
||||
#endif
|
||||
|
||||
ui.sixenseReticleMoveSpeedSpin->setValue(InputDevice::getReticleMoveSpeed());
|
||||
|
||||
SixenseManager& sixense = SixenseManager::getInstance();
|
||||
ui.sixenseReticleMoveSpeedSpin->setValue(sixense.getReticleMoveSpeed());
|
||||
ui.invertSixenseButtonsCheckBox->setChecked(sixense.getInvertButtons());
|
||||
|
||||
// LOD items
|
||||
|
@ -208,6 +225,11 @@ void PreferencesDialog::savePreferences() {
|
|||
|
||||
myAvatar->setCollisionSoundURL(ui.collisionSoundURLEdit->text());
|
||||
|
||||
// MyAvatar persists its own data. If it doesn't agree with what the user has explicitly accepted, set it back to old values.
|
||||
if (_lastGoodAvatarURL != myAvatar->getFullAvatarURLFromPreferences()) {
|
||||
restoreLastGoodAvatar();
|
||||
}
|
||||
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableActivityLogger)
|
||||
!= ui.sendDataCheckBox->isChecked()) {
|
||||
Menu::getInstance()->triggerOption(MenuOption::DisableActivityLogger);
|
||||
|
@ -244,7 +266,7 @@ void PreferencesDialog::savePreferences() {
|
|||
qApp->getApplicationCompositor().setHmdUIAngularSize(ui.oculusUIAngularSizeSpin->value());
|
||||
|
||||
SixenseManager& sixense = SixenseManager::getInstance();
|
||||
sixense.setReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value());
|
||||
InputDevice::setReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value());
|
||||
sixense.setInvertButtons(ui.invertSixenseButtonsCheckBox->isChecked());
|
||||
|
||||
auto audio = DependencyManager::get<AudioClient>();
|
||||
|
|
|
@ -33,6 +33,9 @@ protected:
|
|||
private:
|
||||
void loadPreferences();
|
||||
void savePreferences();
|
||||
QUrl _lastGoodAvatarURL;
|
||||
QString _lastGoodAvatarName;
|
||||
void restoreLastGoodAvatar();
|
||||
|
||||
Ui_PreferencesDialog ui;
|
||||
|
||||
|
@ -42,10 +45,10 @@ private:
|
|||
|
||||
private slots:
|
||||
void accept();
|
||||
void reject();
|
||||
void openFullAvatarModelBrowser();
|
||||
void openSnapshotLocationBrowser();
|
||||
void openScriptsLocationBrowser();
|
||||
void headURLChanged(const QString& newValue, const QString& modelName);
|
||||
void bodyURLChanged(const QString& newValue, const QString& modelName);
|
||||
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <avatar/AvatarManager.h>
|
||||
#include <avatar/MyAvatar.h>
|
||||
#include <FileUtils.h>
|
||||
#include <GLCanvas.h>
|
||||
#include <NodeList.h>
|
||||
|
||||
#include "Application.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <avatar/AvatarManager.h>
|
||||
#include <Application.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <GLCanvas.h>
|
||||
#include <LODManager.h>
|
||||
#include <PerfStat.h>
|
||||
|
||||
|
@ -115,6 +114,7 @@ void Stats::updateStats() {
|
|||
STAT_UPDATE(avatarCount, avatarManager->size() - 1);
|
||||
STAT_UPDATE(serverCount, nodeList->size());
|
||||
STAT_UPDATE(framerate, (int)qApp->getFps());
|
||||
STAT_UPDATE(simrate, (int)Application::getInstance()->getAverageSimsPerSecond());
|
||||
|
||||
auto bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
|
||||
STAT_UPDATE(packetInCount, bandwidthRecorder->getCachedTotalAverageInputPacketsPerSecond());
|
||||
|
|
|
@ -30,6 +30,7 @@ class Stats : public QQuickItem {
|
|||
|
||||
STATS_PROPERTY(int, serverCount, 0)
|
||||
STATS_PROPERTY(int, framerate, 0)
|
||||
STATS_PROPERTY(int, simrate, 0)
|
||||
STATS_PROPERTY(int, avatarCount, 0)
|
||||
STATS_PROPERTY(int, packetInCount, 0)
|
||||
STATS_PROPERTY(int, packetOutCount, 0)
|
||||
|
@ -95,6 +96,7 @@ signals:
|
|||
void timingExpandedChanged();
|
||||
void serverCountChanged();
|
||||
void framerateChanged();
|
||||
void simrateChanged();
|
||||
void avatarCountChanged();
|
||||
void packetInCountChanged();
|
||||
void packetOutCountChanged();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue