mirror of
https://github.com/JulianGro/overte.git
synced 2025-06-04 05:21:33 +02:00
send visible joint state when colliding as ragdoll
This commit is contained in:
parent
924cc600b0
commit
2aaa628a67
5 changed files with 37 additions and 9 deletions
|
@ -165,9 +165,16 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
PerformanceTimer perfTimer("joints");
|
PerformanceTimer perfTimer("joints");
|
||||||
// copy out the skeleton joints from the model
|
// copy out the skeleton joints from the model
|
||||||
_jointData.resize(_skeletonModel.getJointStateCount());
|
_jointData.resize(_skeletonModel.getJointStateCount());
|
||||||
for (int i = 0; i < _jointData.size(); i++) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::CollideAsRagdoll)) {
|
||||||
JointData& data = _jointData[i];
|
for (int i = 0; i < _jointData.size(); i++) {
|
||||||
data.valid = _skeletonModel.getJointState(i, data.rotation);
|
JointData& data = _jointData[i];
|
||||||
|
data.valid = _skeletonModel.getVisibleJointState(i, data.rotation);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < _jointData.size(); i++) {
|
||||||
|
JointData& data = _jointData[i];
|
||||||
|
data.valid = _skeletonModel.getJointState(i, data.rotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,14 @@ void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRot
|
||||||
_visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation;
|
_visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const {
|
||||||
|
glm::quat defaultRotation = _fbxJoint->rotation;
|
||||||
|
return glm::abs(rotation.x - defaultRotation.x) < tolerance &&
|
||||||
|
glm::abs(rotation.y - defaultRotation.y) < tolerance &&
|
||||||
|
glm::abs(rotation.z - defaultRotation.z) < tolerance &&
|
||||||
|
glm::abs(rotation.w - defaultRotation.w) < tolerance;
|
||||||
|
}
|
||||||
|
|
||||||
const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const {
|
const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const {
|
||||||
assert(_fbxJoint != NULL);
|
assert(_fbxJoint != NULL);
|
||||||
return _fbxJoint->translation;
|
return _fbxJoint->translation;
|
||||||
|
|
|
@ -82,6 +82,9 @@ public:
|
||||||
void setRotationInConstrainedFrame(const glm::quat& targetRotation);
|
void setRotationInConstrainedFrame(const glm::quat& targetRotation);
|
||||||
void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation);
|
void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation);
|
||||||
const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; }
|
const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; }
|
||||||
|
const glm::quat& getVisibleRotationInConstrainedFrame() const { return _visibleRotationInConstrainedFrame; }
|
||||||
|
|
||||||
|
const bool rotationIsDefault(const glm::quat& rotation, float tolerance = EPSILON) const;
|
||||||
|
|
||||||
const glm::vec3& getDefaultTranslationInConstrainedFrame() const;
|
const glm::vec3& getDefaultTranslationInConstrainedFrame() const;
|
||||||
|
|
||||||
|
|
|
@ -676,12 +676,18 @@ bool Model::getJointState(int index, glm::quat& rotation) const {
|
||||||
if (index == -1 || index >= _jointStates.size()) {
|
if (index == -1 || index >= _jointStates.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
rotation = _jointStates.at(index).getRotationInConstrainedFrame();
|
const JointState& state = _jointStates.at(index);
|
||||||
const glm::quat& defaultRotation = _geometry->getFBXGeometry().joints.at(index).rotation;
|
rotation = state.getRotationInConstrainedFrame();
|
||||||
return glm::abs(rotation.x - defaultRotation.x) >= EPSILON ||
|
return !state.rotationIsDefault(rotation);
|
||||||
glm::abs(rotation.y - defaultRotation.y) >= EPSILON ||
|
}
|
||||||
glm::abs(rotation.z - defaultRotation.z) >= EPSILON ||
|
|
||||||
glm::abs(rotation.w - defaultRotation.w) >= EPSILON;
|
bool Model::getVisibleJointState(int index, glm::quat& rotation) const {
|
||||||
|
if (index == -1 || index >= _jointStates.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const JointState& state = _jointStates.at(index);
|
||||||
|
rotation = state.getVisibleRotationInConstrainedFrame();
|
||||||
|
return !state.rotationIsDefault(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) {
|
void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) {
|
||||||
|
|
|
@ -114,6 +114,10 @@ public:
|
||||||
/// \return whether or not the joint state is "valid" (that is, non-default)
|
/// \return whether or not the joint state is "valid" (that is, non-default)
|
||||||
bool getJointState(int index, glm::quat& rotation) const;
|
bool getJointState(int index, glm::quat& rotation) const;
|
||||||
|
|
||||||
|
/// Fetches the visible joint state at the specified index.
|
||||||
|
/// \return whether or not the joint state is "valid" (that is, non-default)
|
||||||
|
bool getVisibleJointState(int index, glm::quat& rotation) const;
|
||||||
|
|
||||||
/// Sets the joint state at the specified index.
|
/// Sets the joint state at the specified index.
|
||||||
void setJointState(int index, bool valid, const glm::quat& rotation = glm::quat(), float priority = 1.0f);
|
void setJointState(int index, bool valid, const glm::quat& rotation = glm::quat(), float priority = 1.0f);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue