standalone 21180 branch with just the C++ changes

This commit is contained in:
humbletim 2017-06-05 15:13:56 -04:00
parent a186d4f5e7
commit 7cab0363a9
16 changed files with 123 additions and 35 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

View file

@ -882,14 +882,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_glWidget->setFocusPolicy(Qt::StrongFocus);
_glWidget->setFocus();
#ifdef Q_OS_MAC
auto cursorTarget = _window; // OSX doesn't seem to provide for hiding the cursor only on the GL widget
#else
// On windows and linux, hiding the top level cursor also means it's invisible when hovering over the
// window menu, which is a pain, so only hide it for the GL surface
auto cursorTarget = _glWidget;
#endif
cursorTarget->setCursor(Qt::BlankCursor);
bool useSystemCursor = cmdOptionExists(argc, constArgv, "--system-cursor");
showCursor(useSystemCursor ? Cursor::Icon::SYSTEM : Cursor::Icon::DEFAULT);
// enable mouse tracking; otherwise, we only get drag events
_glWidget->setMouseTracking(true);
@ -1547,9 +1541,16 @@ void Application::checkChangeCursor() {
}
}
void Application::showCursor(const QCursor& cursor) {
void Application::showCursor(const Cursor::Icon& cursor) {
QMutexLocker locker(&_changeCursorLock);
_desiredCursor = cursor;
auto managedCursor = Cursor::Manager::instance().getCursor();
auto curIcon = managedCursor->getIcon();
if (curIcon != cursor) {
managedCursor->setIcon(cursor);
curIcon = cursor;
}
_desiredCursor = cursor == Cursor::Icon::SYSTEM ? Qt::ArrowCursor : Qt::BlankCursor;
_cursorNeedsChanging = true;
}
@ -1958,9 +1959,9 @@ void Application::initializeUi() {
_window->setMenuBar(new Menu());
auto compositorHelper = DependencyManager::get<CompositorHelper>();
connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, [=] {
connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, this, [=] {
if (isHMDMode()) {
showCursor(compositorHelper->getAllowMouseCapture() ? Qt::BlankCursor : Qt::ArrowCursor);
showCursor(compositorHelper->getAllowMouseCapture() ? Cursor::Icon::DEFAULT : Cursor::Icon::SYSTEM);
}
});
@ -2784,9 +2785,11 @@ void Application::keyPressEvent(QKeyEvent* event) {
auto cursor = Cursor::Manager::instance().getCursor();
auto curIcon = cursor->getIcon();
if (curIcon == Cursor::Icon::DEFAULT) {
cursor->setIcon(Cursor::Icon::LINK);
showCursor(Cursor::Icon::SYSTEM);
} else if (curIcon == Cursor::Icon::SYSTEM) {
showCursor(Cursor::Icon::LINK);
} else {
cursor->setIcon(Cursor::Icon::DEFAULT);
showCursor(Cursor::Icon::DEFAULT);
}
} else {
resetSensors(true);
@ -3958,10 +3961,13 @@ void Application::updateMyAvatarLookAtPosition() {
}
} else {
AvatarSharedPointer lookingAt = myAvatar->getLookAtTargetAvatar().lock();
if (lookingAt && myAvatar.get() != lookingAt.get()) {
bool haveLookAtCandidate = lookingAt && myAvatar.get() != lookingAt.get();
auto avatar = static_pointer_cast<Avatar>(lookingAt);
bool mutualLookAtSnappingEnabled = avatar && avatar->getLookAtSnappingEnabled() && myAvatar->getLookAtSnappingEnabled();
if (haveLookAtCandidate && mutualLookAtSnappingEnabled) {
// If I am looking at someone else, look directly at one of their eyes
isLookingAtSomeone = true;
auto lookingAtHead = static_pointer_cast<Avatar>(lookingAt)->getHead();
auto lookingAtHead = avatar->getHead();
const float MAXIMUM_FACE_ANGLE = 65.0f * RADIANS_PER_DEGREE;
glm::vec3 lookingAtFaceOrientation = lookingAtHead->getFinalOrientationInWorldFrame() * IDENTITY_FORWARD;

View file

@ -54,6 +54,7 @@
#include "BandwidthRecorder.h"
#include "FancyCamera.h"
#include "ConnectionMonitor.h"
#include "CursorManager.h"
#include "gpu/Context.h"
#include "Menu.h"
#include "octree/OctreePacketProcessor.h"
@ -163,7 +164,7 @@ public:
QSize getDeviceSize() const;
bool hasFocus() const;
void showCursor(const QCursor& cursor);
void showCursor(const Cursor::Icon& cursor);
bool isThrottleRendering() const;
@ -639,7 +640,7 @@ private:
void checkChangeCursor();
mutable QMutex _changeCursorLock { QMutex::Recursive };
QCursor _desiredCursor{ Qt::BlankCursor };
Qt::CursorShape _desiredCursor{ Qt::BlankCursor };
bool _cursorNeedsChanging { false };
QThread* _deadlockWatchdogThread;

View file

@ -504,6 +504,11 @@ Menu::Menu() {
action = addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ShowOtherLookAtVectors, 0, false);
connect(action, &QAction::triggered, [this]{ Avatar::setShowOtherLookAtVectors(isOptionChecked(MenuOption::ShowOtherLookAtVectors)); });
action = addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableLookAtSnapping, 0, true);
connect(action, &QAction::triggered, [this, avatar]{
avatar->setProperty("lookAtSnappingEnabled", isOptionChecked(MenuOption::EnableLookAtSnapping));
});
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::FixGaze, 0, false);
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AnimDebugDrawDefaultPose, 0, false,
avatar.get(), SLOT(setEnableDebugDrawDefaultPose(bool)));

View file

@ -177,6 +177,7 @@ namespace MenuOption {
const QString ShowDSConnectTable = "Show Domain Connection Timing";
const QString ShowMyLookAtVectors = "Show My Eye Vectors";
const QString ShowOtherLookAtVectors = "Show Other Eye Vectors";
const QString EnableLookAtSnapping = "Enable LookAt Snapping";
const QString ShowRealtimeEntityStats = "Show Realtime Entity Stats";
const QString StandingHMDSensorMode = "Standing HMD Sensor Mode";
const QString SimulateEyeTracking = "Simulate";

View file

@ -834,6 +834,9 @@ void MyAvatar::saveData() {
settings.setValue("scale", _targetScale);
settings.setValue("yawSpeed", _yawSpeed);
settings.setValue("pitchSpeed", _pitchSpeed);
settings.setValue("fullAvatarURL",
_fullAvatarURLFromPreferences == AvatarData::defaultFullAvatarModelUrl() ?
"" :
@ -974,6 +977,9 @@ void MyAvatar::loadData() {
getHead()->setBasePitch(loadSetting(settings, "headPitch", 0.0f));
_yawSpeed = loadSetting(settings, "yawSpeed", _yawSpeed);
_pitchSpeed = loadSetting(settings, "pitchSpeed", _pitchSpeed);
_targetScale = loadSetting(settings, "scale", 1.0f);
setScale(glm::vec3(_targetScale));
@ -1099,6 +1105,15 @@ int MyAvatar::parseDataFromBuffer(const QByteArray& buffer) {
return buffer.size();
}
ScriptAvatarData* MyAvatar::getTargetAvatar() const {
auto avatar = std::static_pointer_cast<Avatar>(_lookAtTargetAvatar.lock());
if (avatar) {
return new ScriptAvatar(avatar);
} else {
return nullptr;
}
}
void MyAvatar::updateLookAtTargetAvatar() {
//
// Look at the avatar whose eyes are closest to the ray in direction of my avatar's head
@ -1127,9 +1142,8 @@ void MyAvatar::updateLookAtTargetAvatar() {
if (angleTo < (smallestAngleTo * (isCurrentTarget ? KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR : 1.0f))) {
_lookAtTargetAvatar = avatarPointer;
_targetAvatarPosition = avatarPointer->getPosition();
smallestAngleTo = angleTo;
}
if (isLookingAtMe(avatar)) {
if (_lookAtSnappingEnabled && avatar->getLookAtSnappingEnabled() && isLookingAtMe(avatar)) {
// Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face.
glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar.
@ -1146,14 +1160,19 @@ void MyAvatar::updateLookAtTargetAvatar() {
ViewFrustum viewFrustum;
qApp->copyViewFrustum(viewFrustum);
glm::vec3 viewPosition = viewFrustum.getPosition();
glm::quat viewOrientation = viewFrustum.getOrientation();
#if DEBUG_ALWAYS_LOOKAT_EYES_NOT_CAMERA
viewPosition = (avatarLeftEye + avatarRightEye) / 2.0f;
#endif
// scale gazeOffset by IPD, if wearing an HMD.
if (qApp->isHMDMode()) {
glm::mat4 leftEye = qApp->getEyeOffset(Eye::Left);
glm::mat4 rightEye = qApp->getEyeOffset(Eye::Right);
glm::vec3 leftEyeHeadLocal = glm::vec3(leftEye[3]);
glm::vec3 rightEyeHeadLocal = glm::vec3(rightEye[3]);
glm::vec3 humanLeftEye = viewFrustum.getPosition() + (viewFrustum.getOrientation() * leftEyeHeadLocal);
glm::vec3 humanRightEye = viewFrustum.getPosition() + (viewFrustum.getOrientation() * rightEyeHeadLocal);
glm::vec3 humanLeftEye = + (viewOrientation * leftEyeHeadLocal);
glm::vec3 humanRightEye = viewPosition + (viewOrientation * rightEyeHeadLocal);
auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
float ipdScale = hmdInterface->getIPDScale();
@ -1167,7 +1186,7 @@ void MyAvatar::updateLookAtTargetAvatar() {
}
// And now we can finally add that offset to the camera.
glm::vec3 corrected = viewFrustum.getPosition() + gazeOffset;
glm::vec3 corrected = viewPosition + gazeOffset;
avatar->getHead()->setCorrectedLookAtPosition(corrected);
@ -2199,6 +2218,7 @@ void MyAvatar::updateMotionBehaviorFromMenu() {
_motionBehaviors &= ~AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED;
}
setCollisionsEnabled(menu->isOptionChecked(MenuOption::EnableAvatarCollisions));
setProperty("lookAtSnappingEnabled", menu->isOptionChecked(MenuOption::EnableLookAtSnapping));
}
void MyAvatar::setCollisionsEnabled(bool enabled) {

View file

@ -23,6 +23,7 @@
#include <controllers/Pose.h>
#include <controllers/Actions.h>
#include <avatars-renderer/Avatar.h>
#include <avatars-renderer/ScriptAvatar.h>
#include "AtRestDetector.h"
#include "MyCharacterController.h"
@ -132,6 +133,9 @@ class MyAvatar : public Avatar {
Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled)
Q_PROPERTY(bool useAdvancedMovementControls READ useAdvancedMovementControls WRITE setUseAdvancedMovementControls)
Q_PROPERTY(float yawSpeed MEMBER _yawSpeed)
Q_PROPERTY(float pitchSpeed MEMBER _pitchSpeed)
public:
enum DriveKeys {
TRANSLATE_X = 0,
@ -368,6 +372,7 @@ public:
Q_INVOKABLE glm::vec3 getEyePosition() const { return getHead()->getEyePosition(); }
Q_INVOKABLE glm::vec3 getTargetAvatarPosition() const { return _targetAvatarPosition; }
Q_INVOKABLE ScriptAvatarData* getTargetAvatar() const;
Q_INVOKABLE glm::vec3 getLeftHandPosition() const;
Q_INVOKABLE glm::vec3 getRightHandPosition() const;

View file

@ -506,8 +506,8 @@ void Avatar::postUpdate(float deltaTime) {
if (isMyAvatar() ? showMyLookAtVectors : showOtherLookAtVectors) {
const float EYE_RAY_LENGTH = 10.0;
const glm::vec4 BLUE(0.0f, 0.0f, 1.0f, 1.0f);
const glm::vec4 RED(1.0f, 0.0f, 0.0f, 1.0f);
const glm::vec4 BLUE(0.0f, 0.0f, _lookAtSnappingEnabled ? 1.0f : 0.25f, 1.0f);
const glm::vec4 RED(_lookAtSnappingEnabled ? 1.0f : 0.25f, 0.0f, 0.0f, 1.0f);
int leftEyeJoint = getJointIndex("LeftEye");
glm::vec3 leftEyePosition;

View file

@ -85,6 +85,8 @@ AvatarData::AvatarData() :
ASSERT(sizeof(AvatarDataPacket::AdditionalFlags) == AvatarDataPacket::ADDITIONAL_FLAGS_SIZE);
ASSERT(sizeof(AvatarDataPacket::ParentInfo) == AvatarDataPacket::PARENT_INFO_SIZE);
ASSERT(sizeof(AvatarDataPacket::FaceTrackerInfo) == AvatarDataPacket::FACE_TRACKER_INFO_SIZE);
connect(this, &AvatarData::lookAtSnappingChanged, this, &AvatarData::markIdentityDataChanged);
}
AvatarData::~AvatarData() {
@ -1479,14 +1481,18 @@ void AvatarData::parseAvatarIdentityPacket(const QByteArray& data, Identity& ide
>> identityOut.displayName
>> identityOut.sessionDisplayName
>> identityOut.avatarEntityData
>> identityOut.sequenceId;
>> identityOut.sequenceId
>> identityOut.lookAtSnappingEnabled
;
#ifdef WANT_DEBUG
qCDebug(avatars) << __FUNCTION__
<< "identityOut.uuid:" << identityOut.uuid
<< "identityOut.skeletonModelURL:" << identityOut.skeletonModelURL
<< "identityOut.displayName:" << identityOut.displayName
<< "identityOut.sessionDisplayName:" << identityOut.sessionDisplayName;
<< "identityOut.sessionDisplayName:" << identityOut.sessionDisplayName
<< "identityOut.lookAtSnappingEnabled:" << identityOut.lookAtSnappingEnabled
;
#endif
}
@ -1541,6 +1547,13 @@ void AvatarData::processAvatarIdentity(const Identity& identity, bool& identityC
identityChanged = true;
}
if (_lookAtSnappingEnabled != identity.lookAtSnappingEnabled) {
#ifdef DEBUG_LOOKAT_SNAPPING
qCDebug(avatars) << __FUNCTION__ << identity.sessionDisplayName << "_lookAtSnappingEnabled" << _lookAtSnappingEnabled << "->" << identity.lookAtSnappingEnabled;
#endif
setProperty("lookAtSnappingEnabled", identity.lookAtSnappingEnabled);
identityChanged = true;
}
}
QByteArray AvatarData::identityByteArray() const {
@ -1549,13 +1562,16 @@ QByteArray AvatarData::identityByteArray() const {
const QUrl& urlToSend = cannonicalSkeletonModelURL(emptyURL); // depends on _skeletonModelURL
_avatarEntitiesLock.withReadLock([&] {
identityStream << getSessionUUID()
<< urlToSend
<< _attachmentData
<< _displayName
<< getSessionDisplayNameForTransport() // depends on _sessionDisplayName
<< _avatarEntityData
<< _identitySequenceId;
identityStream
<< getSessionUUID()
<< urlToSend
<< _attachmentData
<< _displayName
<< getSessionDisplayNameForTransport() // depends on _sessionDisplayName
<< _avatarEntityData
<< _identitySequenceId
<< _lookAtSnappingEnabled
;
});
return identityData;

View file

@ -323,6 +323,7 @@ class AvatarData : public QObject, public SpatiallyNestable {
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
Q_PROPERTY(float scale READ getTargetScale WRITE setTargetScale)
Q_PROPERTY(float density READ getDensity)
Q_PROPERTY(glm::vec3 handPosition READ getHandPosition WRITE setHandPosition)
Q_PROPERTY(float bodyYaw READ getBodyYaw WRITE setBodyYaw)
Q_PROPERTY(float bodyPitch READ getBodyPitch WRITE setBodyPitch)
@ -344,6 +345,7 @@ class AvatarData : public QObject, public SpatiallyNestable {
// sessionDisplayName is sanitized, defaulted version displayName that is defined by the AvatarMixer rather than by Interface clients.
// The result is unique among all avatars present at the time.
Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName WRITE setSessionDisplayName)
Q_PROPERTY(bool lookAtSnappingEnabled MEMBER _lookAtSnappingEnabled NOTIFY lookAtSnappingChanged)
Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript WRITE setSkeletonModelURLFromScript)
Q_PROPERTY(QVector<AttachmentData> attachmentData READ getAttachmentData WRITE setAttachmentData)
@ -532,6 +534,7 @@ public:
QString sessionDisplayName;
AvatarEntityMap avatarEntityData;
quint64 sequenceId;
bool lookAtSnappingEnabled;
};
static void parseAvatarIdentityPacket(const QByteArray& data, Identity& identityOut);
@ -545,6 +548,8 @@ public:
const QUrl& getSkeletonModelURL() const { return _skeletonModelURL; }
const QString& getDisplayName() const { return _displayName; }
const QString& getSessionDisplayName() const { return _sessionDisplayName; }
bool getLookAtSnappingEnabled() const { return _lookAtSnappingEnabled; }
virtual void setSkeletonModelURL(const QUrl& skeletonModelURL);
virtual void setDisplayName(const QString& displayName);
@ -633,6 +638,7 @@ public:
signals:
void displayNameChanged();
void lookAtSnappingChanged(bool enabled);
public slots:
void sendAvatarDataPacket();
@ -697,6 +703,7 @@ protected:
QVector<AttachmentData> _attachmentData;
QString _displayName;
QString _sessionDisplayName { };
bool _lookAtSnappingEnabled { true };
QUrl cannonicalSkeletonModelURL(const QUrl& empty) const;
QHash<QString, int> _jointIndices; ///< 1-based, since zero is returned for missing keys

View file

@ -15,6 +15,7 @@ ScriptAvatarData::ScriptAvatarData(AvatarSharedPointer avatarData) :
_avatarData(avatarData)
{
QObject::connect(avatarData.get(), &AvatarData::displayNameChanged, this, &ScriptAvatarData::displayNameChanged);
QObject::connect(avatarData.get(), &AvatarData::lookAtSnappingChanged, this, &ScriptAvatarData::lookAtSnappingChanged);
}
//
@ -152,6 +153,13 @@ QString ScriptAvatarData::getSessionDisplayName() const {
return QString();
}
}
bool ScriptAvatarData::getLookAtSnappingEnabled() const {
if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) {
return sharedAvatarData->getLookAtSnappingEnabled();
} else {
return false;
}
}
//
// IDENTIFIER PROPERTIES
// END

View file

@ -45,6 +45,7 @@ class ScriptAvatarData : public QObject {
Q_PROPERTY(QUuid sessionUUID READ getSessionUUID)
Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName)
Q_PROPERTY(bool lookAtSnappingEnabled READ getLookAtSnappingEnabled NOTIFY lookAtSnappingChanged)
//
// ATTACHMENT AND JOINT PROPERTIES
@ -95,6 +96,7 @@ public:
QUuid getSessionUUID() const;
QString getDisplayName() const;
QString getSessionDisplayName() const;
bool getLookAtSnappingEnabled() const;
//
// ATTACHMENT AND JOINT PROPERTIES
@ -127,6 +129,7 @@ public:
signals:
void displayNameChanged();
void lookAtSnappingChanged(bool enabled);
public slots:
glm::quat getAbsoluteJointRotationInObjectFrame(int index) const;

View file

@ -436,7 +436,7 @@ glm::mat4 CompositorHelper::getReticleTransform(const glm::mat4& eyePose, const
mousePosition -= 1.0;
mousePosition.y *= -1.0f;
vec2 mouseSize = CURSOR_PIXEL_SIZE / canvasSize;
vec2 mouseSize = CURSOR_PIXEL_SIZE * Cursor::Manager::instance().getScale() / canvasSize;
result = glm::scale(glm::translate(glm::mat4(), vec3(mousePosition, 0.0f)), vec3(mouseSize, 1.0f));
}
return result;
@ -450,3 +450,13 @@ QVariant ReticleInterface::getPosition() const {
void ReticleInterface::setPosition(QVariant position) {
_compositor->setReticlePosition(vec2FromVariant(position));
}
float ReticleInterface::getScale() const {
auto& cursorManager = Cursor::Manager::instance();
return cursorManager.getScale();
}
void ReticleInterface::setScale(float scale) {
auto& cursorManager = Cursor::Manager::instance();
cursorManager.setScale(scale);
}

View file

@ -179,6 +179,7 @@ class ReticleInterface : public QObject {
Q_PROPERTY(QVariant position READ getPosition WRITE setPosition)
Q_PROPERTY(bool visible READ getVisible WRITE setVisible)
Q_PROPERTY(float depth READ getDepth WRITE setDepth)
Q_PROPERTY(float scale READ getScale WRITE setScale)
Q_PROPERTY(glm::vec2 maximumPosition READ getMaximumPosition)
Q_PROPERTY(bool mouseCaptured READ isMouseCaptured)
Q_PROPERTY(bool allowMouseCapture READ getAllowMouseCapture WRITE setAllowMouseCapture)
@ -200,6 +201,9 @@ public:
Q_INVOKABLE float getDepth() { return _compositor->getReticleDepth(); }
Q_INVOKABLE void setDepth(float depth) { _compositor->setReticleDepth(depth); }
Q_INVOKABLE float getScale() const;
Q_INVOKABLE void setScale(float scale);
Q_INVOKABLE QVariant getPosition() const;
Q_INVOKABLE void setPosition(QVariant position);

View file

@ -35,6 +35,7 @@ namespace Cursor {
static uint16_t _customIconId = Icon::USER_BASE;
Manager::Manager() {
ICONS[Icon::SYSTEM] = PathUtils::resourcesPath() + "images/cursor-none.png";
ICONS[Icon::DEFAULT] = PathUtils::resourcesPath() + "images/arrow.png";
ICONS[Icon::LINK] = PathUtils::resourcesPath() + "images/link.png";
}

View file

@ -18,6 +18,7 @@ namespace Cursor {
};
enum Icon {
SYSTEM,
DEFAULT,
LINK,
GRAB,