mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +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) {
|
||||
OculusManager::display(whichCamera.getRotation(), whichCamera.getPosition(), whichCamera);
|
||||
} else {
|
||||
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getUprightHeadPosition(), whichCamera);
|
||||
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), whichCamera);
|
||||
}
|
||||
|
||||
} else if (TV3DManager::isConnected()) {
|
||||
|
|
|
@ -1028,6 +1028,10 @@ float Avatar::getPelvisFloatingHeight() const {
|
|||
return -_skeletonModel.getBindExtents().minimum.y;
|
||||
}
|
||||
|
||||
float Avatar::getPelvisToHeadLength() const {
|
||||
return glm::distance(_position, getHead()->getPosition());
|
||||
}
|
||||
|
||||
void Avatar::setShowDisplayName(bool showDisplayName) {
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::NamesAboveHeads)) {
|
||||
_displayNameAlpha = 0.0f;
|
||||
|
|
|
@ -223,6 +223,7 @@ protected:
|
|||
float getSkeletonHeight() const;
|
||||
float getHeadHeight() const;
|
||||
float getPelvisFloatingHeight() const;
|
||||
float getPelvisToHeadLength() const;
|
||||
glm::vec3 getDisplayNamePosition();
|
||||
|
||||
void renderDisplayName();
|
||||
|
|
|
@ -977,7 +977,11 @@ void MyAvatar::clearLookAtTargetAvatar() {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
glm::vec3 getGravity() const { return _gravity; }
|
||||
glm::vec3 getUprightHeadPosition() const;
|
||||
glm::vec3 getDefaultEyePosition() const;
|
||||
bool getShouldRenderLocally() const { return _shouldRender; }
|
||||
|
||||
const QList<AnimationHandlePointer>& getAnimationHandles() const { return _animationHandles; }
|
||||
|
|
|
@ -470,23 +470,23 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP
|
|||
return success;
|
||||
}
|
||||
|
||||
bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||
bool SkeletonModel::getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
if (getJointPositionInWorldFrame(geometry.leftEyeJointIndex, firstEyePosition) &&
|
||||
getJointPositionInWorldFrame(geometry.rightEyeJointIndex, secondEyePosition)) {
|
||||
if (getJointPosition(geometry.leftEyeJointIndex, firstEyePosition) &&
|
||||
getJointPosition(geometry.rightEyeJointIndex, secondEyePosition)) {
|
||||
return true;
|
||||
}
|
||||
// no eye joints; try to estimate based on head/neck joints
|
||||
glm::vec3 neckPosition, headPosition;
|
||||
if (getJointPositionInWorldFrame(geometry.neckJointIndex, neckPosition) &&
|
||||
getJointPositionInWorldFrame(geometry.headJointIndex, headPosition)) {
|
||||
if (getJointPosition(geometry.neckJointIndex, neckPosition) &&
|
||||
getJointPosition(geometry.headJointIndex, headPosition)) {
|
||||
const float EYE_PROPORTION = 0.6f;
|
||||
glm::vec3 baseEyePosition = glm::mix(neckPosition, headPosition, EYE_PROPORTION);
|
||||
glm::quat headRotation;
|
||||
getJointRotationInWorldFrame(geometry.headJointIndex, headRotation);
|
||||
getJointRotation(geometry.headJointIndex, headRotation);
|
||||
const float EYES_FORWARD = 0.25f;
|
||||
const float EYE_SEPARATION = 0.1f;
|
||||
float headHeight = glm::distance(neckPosition, headPosition);
|
||||
|
@ -497,6 +497,15 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco
|
|||
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() {
|
||||
if (!_ragdoll) {
|
||||
return;
|
||||
|
@ -658,13 +667,18 @@ void SkeletonModel::buildShapes() {
|
|||
|
||||
int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
|
||||
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;
|
||||
glm::vec3 rootModelPosition;
|
||||
getJointPosition(headJointIndex, _defaultHeadModelPosition);
|
||||
getJointPosition(rootJointIndex, rootModelPosition);
|
||||
_defaultHeadModelPosition = _defaultHeadModelPosition - rootModelPosition;
|
||||
|
||||
_defaultEyeModelPosition = midEyePosition - rootModelPosition;
|
||||
_defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;
|
||||
} 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
|
||||
|
|
|
@ -97,9 +97,9 @@ public:
|
|||
/// \return whether or not both eye meshes were found
|
||||
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.
|
||||
glm::vec3 getDefaultHeadModelPosition() const { return _defaultHeadModelPosition; }
|
||||
glm::vec3 getDefaultEyeModelPosition() const { return _defaultEyeModelPosition; }
|
||||
|
||||
virtual void updateVisibleJointStates();
|
||||
|
||||
|
@ -144,6 +144,8 @@ private:
|
|||
/// \param position position 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);
|
||||
|
||||
bool getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
||||
|
||||
Avatar* _owningAvatar;
|
||||
|
||||
|
@ -151,7 +153,7 @@ private:
|
|||
glm::vec3 _boundingShapeLocalOffset;
|
||||
SkeletonRagdoll* _ragdoll;
|
||||
|
||||
glm::vec3 _defaultHeadModelPosition;
|
||||
glm::vec3 _defaultEyeModelPosition;
|
||||
};
|
||||
|
||||
#endif // hifi_SkeletonModel_h
|
||||
|
|
|
@ -768,6 +768,14 @@ bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) co
|
|||
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 {
|
||||
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||
return false;
|
||||
|
|
|
@ -153,6 +153,11 @@ public:
|
|||
/// \return true if joint exists
|
||||
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;
|
||||
|
||||
AnimationHandlePointer createAnimationHandle();
|
||||
|
|
Loading…
Reference in a new issue