mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-28 18:54:40 +00:00
ref #110 Added new method for recalculate position.
This commit is contained in:
parent
db8b9b3f21
commit
6dbb7debaf
@ -22,10 +22,20 @@ void GroupObject::render(unsigned int tbfMsec) {
|
|||||||
for (ClasterItem* object: objects()) {
|
for (ClasterItem* object: objects()) {
|
||||||
|
|
||||||
if (Localpropertys *props = getLocalpropertys(object->guiId())) {
|
if (Localpropertys *props = getLocalpropertys(object->guiId())) {
|
||||||
if (!props->_rotation.isNull())
|
|
||||||
|
if (!props->_rotation.isNull()) {
|
||||||
object->setRotation(_this->rotation() * props->_rotation);
|
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;
|
_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) {
|
QQuaternion *GroupObject::getLocalrotation(int id) {
|
||||||
if (_extrapropertys.contains(id)) {
|
if (_extrapropertys.contains(id)) {
|
||||||
return &_extrapropertys[id]._rotation;
|
return &_extrapropertys[id]._rotation;
|
||||||
|
@ -123,6 +123,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QHash<int, Localpropertys> _extrapropertys;
|
QHash<int, Localpropertys> _extrapropertys;
|
||||||
|
|
||||||
|
const QVector3D reCalcPos(const QVector3D& pos, const QVector3D& eulerAngles) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // GROUPOBJECT_H
|
#endif // GROUPOBJECT_H
|
||||||
|
@ -38,7 +38,7 @@ CRAWL::WorldRule *AbsLvlWorld::initWorldRules() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{210,
|
{250,
|
||||||
{
|
{
|
||||||
{registerObject<GroupObstacleRed>(), 1}, {registerObject<CRAWL::DefaultLight>(), 1}
|
{registerObject<GroupObstacleRed>(), 1}, {registerObject<CRAWL::DefaultLight>(), 1}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace AbstractLvl {
|
|||||||
GroupObstacleRed::GroupObstacleRed(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
GroupObstacleRed::GroupObstacleRed(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||||
|
|
||||||
QQuaternion rotation =
|
QQuaternion rotation =
|
||||||
QQuaternion::fromAxisAndAngle(QVector3D(0,1,0), 90);
|
QQuaternion::fromEulerAngles(QVector3D(0,0,60));
|
||||||
|
|
||||||
setDistance(7);
|
setDistance(7);
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user