mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:37:17 +02:00
Position Rift camera at avatar model's mid-eye location
This commit is contained in:
parent
f95e20153c
commit
aa9511c263
9 changed files with 54 additions and 15 deletions
|
@ -682,7 +682,7 @@ void Application::paintGL() {
|
||||||
if (whichCamera.getMode() == CAMERA_MODE_MIRROR) {
|
if (whichCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||||
OculusManager::display(whichCamera.getRotation(), whichCamera.getPosition(), whichCamera);
|
OculusManager::display(whichCamera.getRotation(), whichCamera.getPosition(), whichCamera);
|
||||||
} else {
|
} else {
|
||||||
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getUprightHeadPosition(), whichCamera);
|
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), whichCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (TV3DManager::isConnected()) {
|
} else if (TV3DManager::isConnected()) {
|
||||||
|
|
|
@ -1028,6 +1028,10 @@ float Avatar::getPelvisFloatingHeight() const {
|
||||||
return -_skeletonModel.getBindExtents().minimum.y;
|
return -_skeletonModel.getBindExtents().minimum.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Avatar::getPelvisToHeadLength() const {
|
||||||
|
return glm::distance(_position, getHead()->getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::setShowDisplayName(bool showDisplayName) {
|
void Avatar::setShowDisplayName(bool showDisplayName) {
|
||||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::NamesAboveHeads)) {
|
if (!Menu::getInstance()->isOptionChecked(MenuOption::NamesAboveHeads)) {
|
||||||
_displayNameAlpha = 0.0f;
|
_displayNameAlpha = 0.0f;
|
||||||
|
|
|
@ -223,6 +223,7 @@ protected:
|
||||||
float getSkeletonHeight() const;
|
float getSkeletonHeight() const;
|
||||||
float getHeadHeight() const;
|
float getHeadHeight() const;
|
||||||
float getPelvisFloatingHeight() const;
|
float getPelvisFloatingHeight() const;
|
||||||
|
float getPelvisToHeadLength() const;
|
||||||
glm::vec3 getDisplayNamePosition();
|
glm::vec3 getDisplayNamePosition();
|
||||||
|
|
||||||
void renderDisplayName();
|
void renderDisplayName();
|
||||||
|
|
|
@ -977,7 +977,11 @@ void MyAvatar::clearLookAtTargetAvatar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 MyAvatar::getUprightHeadPosition() const {
|
glm::vec3 MyAvatar::getUprightHeadPosition() const {
|
||||||
return _position + getWorldAlignedOrientation() * _skeletonModel.getDefaultHeadModelPosition();
|
return _position + getWorldAlignedOrientation() * glm::vec3(0.0f, getPelvisToHeadLength(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 MyAvatar::getDefaultEyePosition() const {
|
||||||
|
return _position + getWorldAlignedOrientation() * _skeletonModel.getDefaultEyeModelPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f;
|
const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f;
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||||
glm::vec3 getGravity() const { return _gravity; }
|
glm::vec3 getGravity() const { return _gravity; }
|
||||||
glm::vec3 getUprightHeadPosition() const;
|
glm::vec3 getUprightHeadPosition() const;
|
||||||
|
glm::vec3 getDefaultEyePosition() const;
|
||||||
bool getShouldRenderLocally() const { return _shouldRender; }
|
bool getShouldRenderLocally() const { return _shouldRender; }
|
||||||
|
|
||||||
const QList<AnimationHandlePointer>& getAnimationHandles() const { return _animationHandles; }
|
const QList<AnimationHandlePointer>& getAnimationHandles() const { return _animationHandles; }
|
||||||
|
|
|
@ -470,23 +470,23 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
bool SkeletonModel::getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
if (getJointPositionInWorldFrame(geometry.leftEyeJointIndex, firstEyePosition) &&
|
if (getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) &&
|
||||||
getJointPositionInWorldFrame(geometry.rightEyeJointIndex, secondEyePosition)) {
|
getJointPosition(geometry.rightEyeJointIndex, secondEyePosition)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// no eye joints; try to estimate based on head/neck joints
|
// no eye joints; try to estimate based on head/neck joints
|
||||||
glm::vec3 neckPosition, headPosition;
|
glm::vec3 neckPosition, headPosition;
|
||||||
if (getJointPositionInWorldFrame(geometry.neckJointIndex, neckPosition) &&
|
if (getJointPosition(geometry.neckJointIndex, neckPosition) &&
|
||||||
getJointPositionInWorldFrame(geometry.headJointIndex, headPosition)) {
|
getJointPosition(geometry.headJointIndex, headPosition)) {
|
||||||
const float EYE_PROPORTION = 0.6f;
|
const float EYE_PROPORTION = 0.6f;
|
||||||
glm::vec3 baseEyePosition = glm::mix(neckPosition, headPosition, EYE_PROPORTION);
|
glm::vec3 baseEyePosition = glm::mix(neckPosition, headPosition, EYE_PROPORTION);
|
||||||
glm::quat headRotation;
|
glm::quat headRotation;
|
||||||
getJointRotationInWorldFrame(geometry.headJointIndex, headRotation);
|
getJointRotation(geometry.headJointIndex, headRotation);
|
||||||
const float EYES_FORWARD = 0.25f;
|
const float EYES_FORWARD = 0.25f;
|
||||||
const float EYE_SEPARATION = 0.1f;
|
const float EYE_SEPARATION = 0.1f;
|
||||||
float headHeight = glm::distance(neckPosition, headPosition);
|
float headHeight = glm::distance(neckPosition, headPosition);
|
||||||
|
@ -497,6 +497,15 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||||
|
if (getEyeModelPositions(firstEyePosition, secondEyePosition)) {
|
||||||
|
firstEyePosition = _translation + _rotation * firstEyePosition;
|
||||||
|
secondEyePosition = _translation + _rotation * secondEyePosition;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void SkeletonModel::renderRagdoll() {
|
void SkeletonModel::renderRagdoll() {
|
||||||
if (!_ragdoll) {
|
if (!_ragdoll) {
|
||||||
return;
|
return;
|
||||||
|
@ -658,13 +667,18 @@ void SkeletonModel::buildShapes() {
|
||||||
|
|
||||||
int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
|
int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
|
||||||
if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {
|
if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {
|
||||||
|
glm::vec3 leftEyePosition, rightEyePosition;
|
||||||
|
getEyeModelPositions(leftEyePosition, rightEyePosition);
|
||||||
|
glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.f;
|
||||||
|
|
||||||
int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
|
int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
|
||||||
glm::vec3 rootModelPosition;
|
glm::vec3 rootModelPosition;
|
||||||
getJointPosition(headJointIndex, _defaultHeadModelPosition);
|
|
||||||
getJointPosition(rootJointIndex, rootModelPosition);
|
getJointPosition(rootJointIndex, rootModelPosition);
|
||||||
_defaultHeadModelPosition = _defaultHeadModelPosition - rootModelPosition;
|
|
||||||
|
_defaultEyeModelPosition = midEyePosition - rootModelPosition;
|
||||||
|
_defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;
|
||||||
} else {
|
} else {
|
||||||
_defaultHeadModelPosition = glm::vec3(0.f, 0.f, 0.f);
|
_defaultEyeModelPosition = glm::vec3(0.f, 0.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// While the shapes are in their default position we disable collisions between
|
// While the shapes are in their default position we disable collisions between
|
||||||
|
|
|
@ -97,9 +97,9 @@ public:
|
||||||
/// \return whether or not both eye meshes were found
|
/// \return whether or not both eye meshes were found
|
||||||
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
||||||
|
|
||||||
/// Gets the default position of the head in model frame coordinates.
|
/// Gets the default position of the mid eye point in model frame coordinates.
|
||||||
/// \return whether or not the head was found.
|
/// \return whether or not the head was found.
|
||||||
glm::vec3 getDefaultHeadModelPosition() const { return _defaultHeadModelPosition; }
|
glm::vec3 getDefaultEyeModelPosition() const { return _defaultEyeModelPosition; }
|
||||||
|
|
||||||
virtual void updateVisibleJointStates();
|
virtual void updateVisibleJointStates();
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ private:
|
||||||
/// \param position position of joint in model-frame
|
/// \param position position of joint in model-frame
|
||||||
/// \param rotation rotation of joint in model-frame
|
/// \param rotation rotation of joint in model-frame
|
||||||
void setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation);
|
void setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation);
|
||||||
|
|
||||||
|
bool getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
||||||
|
|
||||||
Avatar* _owningAvatar;
|
Avatar* _owningAvatar;
|
||||||
|
|
||||||
|
@ -151,7 +153,7 @@ private:
|
||||||
glm::vec3 _boundingShapeLocalOffset;
|
glm::vec3 _boundingShapeLocalOffset;
|
||||||
SkeletonRagdoll* _ragdoll;
|
SkeletonRagdoll* _ragdoll;
|
||||||
|
|
||||||
glm::vec3 _defaultHeadModelPosition;
|
glm::vec3 _defaultEyeModelPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_SkeletonModel_h
|
#endif // hifi_SkeletonModel_h
|
||||||
|
|
|
@ -768,6 +768,14 @@ bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) co
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const {
|
||||||
|
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rotation = _jointStates[jointIndex].getRotation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const {
|
bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const {
|
||||||
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -153,6 +153,11 @@ public:
|
||||||
/// \return true if joint exists
|
/// \return true if joint exists
|
||||||
bool getJointPosition(int jointIndex, glm::vec3& position) const;
|
bool getJointPosition(int jointIndex, glm::vec3& position) const;
|
||||||
|
|
||||||
|
/// \param jointIndex index of joint in model structure
|
||||||
|
/// \param rotation[out] rotation of joint in model-frame
|
||||||
|
/// \return true if joint exists
|
||||||
|
bool getJointRotation(int jointIndex, glm::quat& rotation) const;
|
||||||
|
|
||||||
QStringList getJointNames() const;
|
QStringList getJointNames() const;
|
||||||
|
|
||||||
AnimationHandlePointer createAnimationHandle();
|
AnimationHandlePointer createAnimationHandle();
|
||||||
|
|
Loading…
Reference in a new issue