mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
Render avatar collision shapes in the right spot
This commit is contained in:
parent
4d984b1054
commit
8ef657e5b2
2 changed files with 12 additions and 7 deletions
|
@ -137,9 +137,10 @@ void Model::createCollisionShapes() {
|
|||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
float uniformScale = extractUniformScale(_scale);
|
||||
for (int i = 0; i < _jointStates.size(); i++) {
|
||||
glm::vec3 position = extractTranslation(_jointStates[i].transform);
|
||||
const FBXJoint& joint = geometry.joints[i];
|
||||
// for now make everything a sphere at joint end
|
||||
glm::vec3 meshCenter = _jointStates[i].combinedRotation * joint.averageVertex;
|
||||
glm::vec3 position = _rotation * (extractTranslation(_jointStates[i].transform) + uniformScale * meshCenter) + _translation;
|
||||
|
||||
float radius = uniformScale * joint.boneRadius;
|
||||
SphereShape* shape = new SphereShape(radius, position);
|
||||
_shapes.push_back(shape);
|
||||
|
@ -147,10 +148,14 @@ void Model::createCollisionShapes() {
|
|||
}
|
||||
|
||||
void Model::updateShapePositions() {
|
||||
float uniformScale = extractUniformScale(_scale);
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
if (_shapesAreDirty && _shapes.size() == _jointStates.size()) {
|
||||
for (int i = 0; i < _jointStates.size(); i++) {
|
||||
const FBXJoint& joint = geometry.joints[i];
|
||||
// shape positions are stored in world-frame
|
||||
_shapes[i]->setPosition(_rotation * extractTranslation(_jointStates[i].transform) + _translation);
|
||||
glm::vec3 meshCenter = _jointStates[i].combinedRotation * joint.averageVertex;
|
||||
_shapes[i]->setPosition(_rotation * (extractTranslation(_jointStates[i].transform) + uniformScale * meshCenter) + _translation);
|
||||
_shapes[i]->setRotation(_jointStates[i].combinedRotation);
|
||||
}
|
||||
_shapesAreDirty = false;
|
||||
|
|
|
@ -182,10 +182,10 @@ protected:
|
|||
|
||||
class JointState {
|
||||
public:
|
||||
glm::vec3 translation;
|
||||
glm::quat rotation;
|
||||
glm::mat4 transform;
|
||||
glm::quat combinedRotation;
|
||||
glm::vec3 translation; // translation relative to parent
|
||||
glm::quat rotation; // rotation relative to parent
|
||||
glm::mat4 transform; // rotation to world frame + translation in model frame
|
||||
glm::quat combinedRotation; // rotation to world frame
|
||||
};
|
||||
|
||||
bool _shapesAreDirty;
|
||||
|
|
Loading…
Reference in a new issue