mirror of
https://github.com/overte-org/overte.git
synced 2025-08-13 09:49:45 +02:00
Various tweaks to ModelReferentials
This commit is contained in:
parent
5fd3fd9f8f
commit
c65dc3fb1e
3 changed files with 67 additions and 13 deletions
|
@ -12,23 +12,25 @@
|
|||
#include <AvatarData.h>
|
||||
|
||||
#include "ModelTree.h"
|
||||
#include "../renderer/Model.h"
|
||||
|
||||
#include "ModelReferential.h"
|
||||
|
||||
ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar) :
|
||||
Referential(avatar),
|
||||
Referential(MODEL, avatar),
|
||||
_modelID(modelID),
|
||||
_tree(tree)
|
||||
{
|
||||
const ModelItem* item = _tree->findModelByID(_modelID);
|
||||
if (!_isValid || item == NULL) {
|
||||
qDebug() << "Not Validd";
|
||||
_isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_refScale = item->getRadius();
|
||||
_refRotation = item->getModelRotation();
|
||||
_refPosition = item->getPosition();
|
||||
_refPosition = item->getPosition() * (float)TREE_SCALE;
|
||||
|
||||
glm::quat refInvRot = glm::inverse(_refRotation);
|
||||
_scale = _avatar->getTargetScale() / _refScale;
|
||||
|
@ -39,6 +41,7 @@ _tree(tree)
|
|||
void ModelReferential::update() {
|
||||
const ModelItem* item = _tree->findModelByID(_modelID);
|
||||
if (!_isValid || item == NULL || _avatar == NULL) {
|
||||
qDebug() << "Not Valid";
|
||||
_isValid = false;
|
||||
return;
|
||||
}
|
||||
|
@ -51,36 +54,71 @@ void ModelReferential::update() {
|
|||
}
|
||||
if (item->getModelRotation() != _refRotation) {
|
||||
_refRotation = item->getModelRotation();
|
||||
_avatar->setOrientation(_refRotation * _rotation);
|
||||
_avatar->setOrientation(_refRotation);// * _rotation);
|
||||
somethingChanged = true;
|
||||
}
|
||||
if (item->getPosition() != _refPosition || somethingChanged) {
|
||||
_refPosition = item->getPosition();
|
||||
_avatar->setPosition(_refPosition + _refRotation * (_translation * _refScale));
|
||||
_avatar->setPosition(_refPosition * (float)TREE_SCALE);// + _refRotation * (_translation * _refScale));
|
||||
//qDebug() << "Ref: " << item->getLastUpdated() << " " << item->getLastEdited();
|
||||
somethingChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
JointReferential::JointReferential(uint32_t jointID, uint32_t modelID, ModelTree* tree, AvatarData* avatar) :
|
||||
int ModelReferential::packReferential(unsigned char* destinationBuffer) {
|
||||
int size = packPosition(destinationBuffer);
|
||||
memcpy(destinationBuffer, &_modelID, sizeof(_modelID));
|
||||
return size + sizeof(_modelID);
|
||||
}
|
||||
|
||||
JointReferential::JointReferential(uint32_t jointIndex, uint32_t modelID, ModelTree* tree, AvatarData* avatar) :
|
||||
ModelReferential(modelID, tree, avatar),
|
||||
_jointID(jointID)
|
||||
_jointIndex(jointIndex)
|
||||
{
|
||||
const Model* model = getModel(_tree->findModelByID(_modelID));
|
||||
|
||||
if (!_isValid || model == NULL || model->getJointStateCount() <= jointID) {
|
||||
_type = JOINT;
|
||||
const ModelItem* item = _tree->findModelByID(_modelID);
|
||||
const Model* model = getModel(item);
|
||||
if (!_isValid || model == NULL || _jointIndex >= model->getJointStateCount()) {
|
||||
qDebug() << "Not Validd";
|
||||
_isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_refScale = item->getRadius();
|
||||
model->getJointRotationInWorldFrame(_jointIndex, _refRotation);
|
||||
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
|
||||
|
||||
glm::quat refInvRot = glm::inverse(_refRotation);
|
||||
_scale = _avatar->getTargetScale() / _refScale;
|
||||
_rotation = refInvRot * _avatar->getOrientation();
|
||||
_translation = refInvRot * (avatar->getPosition() - _refPosition) / _refScale;
|
||||
}
|
||||
|
||||
void JointReferential::update() {
|
||||
const ModelItem* item = _tree->findModelByID(_modelID);
|
||||
if (!_isValid || item == NULL) {
|
||||
const Model* model = getModel(item);
|
||||
if (!_isValid || model == NULL || _jointIndex >= model->getJointStateCount()) {
|
||||
qDebug() << "Not Valid";
|
||||
_isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool somethingChanged = false;
|
||||
if (item->getRadius() != _refScale) {
|
||||
_refScale = item->getRadius();
|
||||
_avatar->setTargetScale(_refScale * _scale);
|
||||
somethingChanged = true;
|
||||
}
|
||||
if (item->getModelRotation() != _refRotation) {
|
||||
model->getJointRotationInWorldFrame(_jointIndex, _refRotation);
|
||||
_avatar->setOrientation(_refRotation * _rotation);
|
||||
somethingChanged = true;
|
||||
}
|
||||
if (item->getPosition() != _refPosition || somethingChanged) {
|
||||
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
|
||||
_avatar->setPosition(_refPosition + _refRotation * (_translation * _refScale));
|
||||
somethingChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
const Model* JointReferential::getModel(const ModelItem* item) {
|
||||
|
@ -88,6 +126,7 @@ const Model* JointReferential::getModel(const ModelItem* item) {
|
|||
if (item != NULL && fbxService != NULL) {
|
||||
return fbxService->getModelForModelItem(*item);
|
||||
}
|
||||
qDebug() << "No Model";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ class Model;
|
|||
|
||||
class ModelReferential : public Referential {
|
||||
public:
|
||||
ModelReferential(Referential* ref);
|
||||
ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar);
|
||||
virtual void update();
|
||||
|
||||
|
@ -29,13 +30,14 @@ protected:
|
|||
|
||||
class JointReferential : public ModelReferential {
|
||||
public:
|
||||
JointReferential(uint32_t jointID, uint32_t modelID, ModelTree* tree, AvatarData* avatar);
|
||||
JointReferential(Referential* ref);
|
||||
JointReferential(uint32_t jointIndex, uint32_t modelID, ModelTree* tree, AvatarData* avatar);
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
const Model* getModel(const ModelItem* item);
|
||||
|
||||
uint32_t _jointID;
|
||||
uint32_t _jointIndex;
|
||||
};
|
||||
|
||||
#endif // hifi_ModelReferential_h
|
|
@ -32,6 +32,7 @@
|
|||
#include "Audio.h"
|
||||
#include "Environment.h"
|
||||
#include "Menu.h"
|
||||
#include "ModelReferential.h"
|
||||
#include "MyAvatar.h"
|
||||
#include "Physics.h"
|
||||
#include "devices/Faceshift.h"
|
||||
|
@ -126,6 +127,18 @@ void MyAvatar::update(float deltaTime) {
|
|||
}
|
||||
|
||||
simulate(deltaTime);
|
||||
|
||||
|
||||
const ModelItem* item = Application::getInstance()->getModels()->getTree()->findModelByID(278);
|
||||
if (_referential) {
|
||||
PerformanceTimer perfTimer("Referential");
|
||||
_referential->update();
|
||||
} else if (item != NULL) {
|
||||
const Model* model = Application::getInstance()->getModels()->getModelForModelItem(*item);
|
||||
if (model != NULL) {
|
||||
_referential = new ModelReferential(278, Application::getInstance()->getModels()->getTree(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::simulate(float deltaTime) {
|
||||
|
|
Loading…
Reference in a new issue