mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-22 21:36:34 +02:00
More accurate HMD-cursor on virtual keyboard, thanks Simon and @ctrlaltdavid for the help on this!
This commit is contained in:
parent
7a3530ae14
commit
9e51bece63
4 changed files with 38 additions and 26 deletions
|
@ -510,16 +510,14 @@ Cursor = (function(params) {
|
|||
});
|
||||
}
|
||||
var editobject = {};
|
||||
//if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
//angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.x = HMD.getHUDLookAtPositionX;//angle * windowDimensions.x;
|
||||
if (tthis.x !== HMD.getHUDLookAtPosition2D.x) {
|
||||
tthis.x = HMD.getHUDLookAtPosition2D.x;
|
||||
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
|
||||
// }
|
||||
// if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
// angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.y = HMD.getHUDLookAtPositionY;//angle * windowDimensions.y;
|
||||
}
|
||||
if (tthis.y !== HMD.getHUDLookAtPosition2D.y) {
|
||||
tthis.y = HMD.getHUDLookAtPosition2D.y;
|
||||
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
|
||||
// }
|
||||
}
|
||||
if (Object.keys(editobject).length > 0) {
|
||||
Overlays.editOverlay(tthis.overlay, editobject);
|
||||
if (tthis.onUpdate != null) {
|
||||
|
|
|
@ -685,7 +685,7 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) {
|
|||
roll = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 OculusManager::getRelativePosition() {
|
||||
#if (defined(__APPLE__) || defined(_WIN32)) && HAVE_LIBOVR
|
||||
ovrTrackingState trackingState = ovrHmd_GetTrackingState(_ovrHmd, ovr_GetTimeInSeconds());
|
||||
|
|
|
@ -15,3 +15,30 @@ HMDScriptingInterface& HMDScriptingInterface::getInstance() {
|
|||
static HMDScriptingInterface sharedInstance;
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const {
|
||||
Camera* camera = Application::getInstance()->getCamera();
|
||||
glm::vec3 position = camera->getPosition();
|
||||
glm::quat orientation = camera->getOrientation();
|
||||
|
||||
glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
|
||||
ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay();
|
||||
|
||||
glm::vec3 result;
|
||||
applicationOverlay.calculateRayUICollisionPoint(position, direction, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const {
|
||||
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
|
||||
glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition();
|
||||
|
||||
glm::vec3 hudIntersection = getHUDLookAtPosition3D();
|
||||
|
||||
glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter);
|
||||
glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction);
|
||||
glm::vec3 eulers = ::safeEulerAngles(rotation);
|
||||
|
||||
return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x));;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ class HMDScriptingInterface : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(bool magnifier READ getMagnifier)
|
||||
Q_PROPERTY(bool active READ isHMDMode)
|
||||
Q_PROPERTY(float getHUDLookAtPositionX READ getHUDLookAtPositionX)
|
||||
Q_PROPERTY(float getHUDLookAtPositionY READ getHUDLookAtPositionY)
|
||||
Q_PROPERTY(glm::vec3 HUDLookAtPosition3D READ getHUDLookAtPosition3D)
|
||||
Q_PROPERTY(glm::vec2 HUDLookAtPosition2D READ getHUDLookAtPosition2D)
|
||||
public:
|
||||
static HMDScriptingInterface& getInstance();
|
||||
|
||||
|
@ -33,22 +33,9 @@ private:
|
|||
HMDScriptingInterface() {};
|
||||
bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); };
|
||||
bool isHMDMode() const { return Application::getInstance()->isHMDMode(); }
|
||||
float getHUDLookAtPositionX() const {
|
||||
float pitch, yaw, roll;
|
||||
OculusManager::getEulerAngles(yaw, pitch, roll);
|
||||
glm::vec3 relativePos = OculusManager::getRelativePosition();
|
||||
glm::quat rotation = ::rotationBetween(glm::vec3(), relativePos);
|
||||
glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch));
|
||||
|
||||
return screenPos.x;
|
||||
}
|
||||
float getHUDLookAtPositionY() const {
|
||||
float pitch, yaw, roll;
|
||||
OculusManager::getEulerAngles(yaw, pitch, roll);
|
||||
glm::vec2 screenPos = Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(yaw, -pitch));
|
||||
return screenPos.y;
|
||||
}
|
||||
|
||||
glm::vec3 getHUDLookAtPosition3D() const;
|
||||
glm::vec2 getHUDLookAtPosition2D() const;
|
||||
};
|
||||
|
||||
#endif // hifi_HMDScriptingInterface_h
|
||||
|
|
Loading…
Reference in a new issue