ref #110 Added new method for recalculate position.

This commit is contained in:
IgorekLoschinin 2021-10-05 23:33:30 +03:00
parent db8b9b3f21
commit 6dbb7debaf
4 changed files with 41 additions and 4 deletions

View File

@ -22,10 +22,20 @@ void GroupObject::render(unsigned int tbfMsec) {
for (ClasterItem* object: objects()) {
if (Localpropertys *props = getLocalpropertys(object->guiId())) {
if (!props->_rotation.isNull())
if (!props->_rotation.isNull()) {
object->setRotation(_this->rotation() * props->_rotation);
object->setposition(_this->position() + props->_position);
QVector3D reCalcVectorPs = reCalcPos(props->_position,
_this->rotation().toEulerAngles());
object->setposition(_this->position() + reCalcVectorPs);
} else {
object->setposition(_this->position() + props->_position);
}
}
}
@ -48,6 +58,31 @@ void GroupObject::updateRotation(int id, const QQuaternion &roatation) {
_extrapropertys[id]._rotation = roatation;
}
const QVector3D GroupObject::reCalcPos(const QVector3D& pos, const QVector3D &eulerAngles) const
{
float alha = eulerAngles[0];
float beta = eulerAngles[1];
float gamma = eulerAngles[2];
float x = pos[0];
float y = pos[1];
float z = pos[2];
float newX = x*(qCos(alha)*qCos(beta)) +
y*(qCos(alha)*qSin(beta)*qSin(gamma) - qSin(alha)*qCos(gamma)) +
z*(qCos(alha)*qSin(beta)*qCos(gamma) + qSin(alha)*qSin(gamma));
float newY = x*(qSin(alha)*qCos(beta)) +
y*(qSin(alha)*qSin(beta)*qSin(gamma) + qCos(alha)*qCos(gamma)) +
z*(qSin(alha)*qSin(beta)*qCos(gamma) - qCos(alha)*qSin(gamma));
float newZ = x*(-qSin(beta)) +
y*(qCos(beta)*qSin(gamma)) +
z*(qCos(beta)*qCos(gamma));
return QVector3D({newX, newY, newZ});
}
QQuaternion *GroupObject::getLocalrotation(int id) {
if (_extrapropertys.contains(id)) {
return &_extrapropertys[id]._rotation;

View File

@ -123,6 +123,8 @@ protected:
private:
QHash<int, Localpropertys> _extrapropertys;
const QVector3D reCalcPos(const QVector3D& pos, const QVector3D& eulerAngles) const;
};
}
#endif // GROUPOBJECT_H

View File

@ -38,7 +38,7 @@ CRAWL::WorldRule *AbsLvlWorld::initWorldRules() {
}
},
{210,
{250,
{
{registerObject<GroupObstacleRed>(), 1}, {registerObject<CRAWL::DefaultLight>(), 1}
}

View File

@ -13,7 +13,7 @@ namespace AbstractLvl {
GroupObstacleRed::GroupObstacleRed(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
QQuaternion rotation =
QQuaternion::fromAxisAndAngle(QVector3D(0,1,0), 90);
QQuaternion::fromEulerAngles(QVector3D(0,0,60));
setDistance(7);
setRotation(rotation);