Skip to content

Commit

Permalink
fixed irrlicht bug EJUOR_CONTROL were node transformation was wrong &…
Browse files Browse the repository at this point in the history
… updated to quaternions
  • Loading branch information
MiniTurtle committed Aug 16, 2024
1 parent 1420669 commit 2ac90ea
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/IAnimatedMeshSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace scene
//! Constructor
IAnimatedMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
: ISceneNode(parent, mgr, id, position, rotation, scale) {}

Expand Down
4 changes: 2 additions & 2 deletions include/ICameraSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace scene
//! Constructor
ICameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f))
: ISceneNode(parent, mgr, id, position, rotation, scale), IsOrthogonal(false) {}

Expand Down Expand Up @@ -89,7 +89,7 @@ namespace scene
bindTargetAndRotation() ) then calling this will also change
the camera's target to match the rotation.
\param rotation New rotation of the node in degrees. */
void setRotation(const core::vector3df& rotation) override =0;
void setRotation(const core::quaternion& rotation) override =0;

//! Gets the current look at target of the camera
/** \return The current look at target of the camera, in world co-ordinates */
Expand Down
2 changes: 1 addition & 1 deletion include/IMeshSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IMeshSceneNode : public ISceneNode
*/
IMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1,1,1))
: ISceneNode(parent, mgr, id, position, rotation, scale) {}

Expand Down
42 changes: 35 additions & 7 deletions include/ISceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace scene
//! Constructor
ISceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
: RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),
Parent(0), SceneManager(mgr), ID(id),
Expand Down Expand Up @@ -186,8 +186,9 @@ namespace scene
virtual core::matrix4 getRelativeTransformation() const
{
core::matrix4 mat;
mat.setRotationDegrees(RelativeRotation);
mat.setTranslation(RelativeTranslation);
//mat.setRotationDegrees(RelativeRotation);
RelativeRotation.getMatrix(mat, RelativeTranslation);
//mat.setTranslation(RelativeTranslation);

if (RelativeScale != core::vector3df(1.f,1.f,1.f))
{
Expand Down Expand Up @@ -372,21 +373,33 @@ namespace scene
}


virtual const core::quaternion& getRotation() const
{
return RelativeRotation;
}

//! Gets the rotation of the node relative to its parent.
/** Note that this is the relative rotation of the node.
If you want the absolute rotation, use
getAbsoluteTransformation().getRotation()
\return Current relative rotation of the scene node. */
virtual const core::vector3df& getRotation() const
virtual const core::vector3df getEuler() const
{
return RelativeRotation;
core::vector3df euler;
RelativeRotation.toEuler(euler);
return euler * core::RADTODEG;
}


//! Sets the rotation of the node relative to its parent.
/** This only modifies the relative rotation of the node.
\param rotation New rotation of the node in degrees. */
virtual void setRotation(const core::vector3df& rotation)
virtual void fromEuler(const core::vector3df& rotation)
{
RelativeRotation = core::quaternion(rotation*core::DEGTORAD);
}

virtual void setRotation(const core::quaternion& rotation)
{
RelativeRotation = rotation;
}
Expand Down Expand Up @@ -519,6 +532,20 @@ namespace scene
AbsoluteTransformation = getRelativeTransformation();
}

virtual void updateAbsolutePositionRecursive()
{
if (Parent)
{
AbsoluteTransformation =
Parent->getAbsoluteTransformation() * getRelativeTransformation();
}
else
AbsoluteTransformation = getRelativeTransformation();

for (auto c : Children)
c->updateAbsolutePositionRecursive();
}


//! Returns the parent of this scene node
/** \return A pointer to the parent. */
Expand Down Expand Up @@ -601,7 +628,8 @@ namespace scene
core::vector3df RelativeTranslation;

//! Relative rotation of the scene node.
core::vector3df RelativeRotation;
//core::vector3df RelativeRotation;
core::quaternion RelativeRotation;

//! Relative scale of the scene node.
core::vector3df RelativeScale;
Expand Down
12 changes: 5 additions & 7 deletions source/Irrlicht/CAnimatedMeshSceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace scene
CAnimatedMeshSceneNode::CAnimatedMeshSceneNode(IAnimatedMesh* mesh,
ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::quaternion& rotation,
const core::vector3df& scale)
: IAnimatedMeshSceneNode(parent, mgr, id, position, rotation, scale), Mesh(0),
StartFrame(0), EndFrame(0), FramesPerSecond(0.025f),
Expand Down Expand Up @@ -718,16 +718,14 @@ void CAnimatedMeshSceneNode::animateJoints(bool CalculateAbsolutePositions)

//Code is slow, needs to be fixed up

const core::quaternion RotationStart(PretransitingSave[n].getRotationDegrees()*core::DEGTORAD);
const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation()*core::DEGTORAD);
//const core::quaternion RotationStart(PretransitingSave[n].getRotationDegrees()*core::DEGTORAD);
const core::quaternion RotationStart = core::quaternion(0,0,0,1) * PretransitingSave[n];
const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation());

core::quaternion QRotation;
QRotation.slerp(RotationStart, RotationEnd, TransitingBlend);

core::vector3df tmpVector;
QRotation.toEuler(tmpVector);
tmpVector*=core::RADTODEG; //convert from radians back to degrees
JointChildSceneNodes[n]->setRotation( tmpVector );
JointChildSceneNodes[n]->setRotation( QRotation );

//------Scale------

Expand Down
2 changes: 1 addition & 1 deletion source/Irrlicht/CAnimatedMeshSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace scene
//! constructor
CAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));

//! destructor
Expand Down
6 changes: 3 additions & 3 deletions source/Irrlicht/CCameraSceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void CCameraSceneNode::setTarget(const core::vector3df& pos)
if(TargetAndRotationAreBound)
{
const core::vector3df toTarget = Target - getAbsolutePosition();
ISceneNode::setRotation(toTarget.getHorizontalAngle());
ISceneNode::fromEuler(toTarget.getHorizontalAngle());
}
}

Expand All @@ -132,10 +132,10 @@ void CCameraSceneNode::setTarget(const core::vector3df& pos)
If the camera's target and rotation are bound ( @see bindTargetAndRotation() )
then calling this will also change the camera's target to match the rotation.
\param rotation New rotation of the node in degrees. */
void CCameraSceneNode::setRotation(const core::vector3df& rotation)
void CCameraSceneNode::setRotation(const core::quaternion& rotation)
{
if(TargetAndRotationAreBound)
Target = getAbsolutePosition() + rotation.rotationToDirection();
Target = getAbsolutePosition() + rotation * core::vector3df(1, 0, 0);

ISceneNode::setRotation(rotation);
}
Expand Down
2 changes: 1 addition & 1 deletion source/Irrlicht/CCameraSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace scene
If the camera's target and rotation are bound ( @see bindTargetAndRotation() )
then calling this will also change the camera's target to match the rotation.
\param rotation New rotation of the node in degrees. */
void setRotation(const core::vector3df& rotation) override;
void setRotation(const core::quaternion& rotation) override;

//! Gets the current look at target of the camera
/** \return The current look at target of the camera */
Expand Down
4 changes: 2 additions & 2 deletions source/Irrlicht/CDummyTransformationSceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ void CDummyTransformationSceneNode::setScale(const core::vector3df& scale)
RelativeScale = scale;
}

const core::vector3df& CDummyTransformationSceneNode::getRotation() const
const core::quaternion& CDummyTransformationSceneNode::getRotation() const
{
os::Printer::log("CDummyTransformationSceneNode::getRotation() does not contain the relative transformation.", ELL_DEBUG);
return RelativeRotation;
}

void CDummyTransformationSceneNode::setRotation(const core::vector3df& rotation)
void CDummyTransformationSceneNode::setRotation(const core::quaternion& rotation)
{
os::Printer::log("CDummyTransformationSceneNode::setRotation() does not affect the relative transformation.", ELL_DEBUG);
RelativeRotation = rotation;
Expand Down
4 changes: 2 additions & 2 deletions source/Irrlicht/CDummyTransformationSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace scene
// fixed bug id 2318691.
const core::vector3df& getScale() const override;
void setScale(const core::vector3df& scale) override;
const core::vector3df& getRotation() const override;
void setRotation(const core::vector3df& rotation) override;
const core::quaternion& getRotation() const override;
void setRotation(const core::quaternion& rotation) override;
const core::vector3df& getPosition() const override;
void setPosition(const core::vector3df& newpos) override;

Expand Down
3 changes: 2 additions & 1 deletion source/Irrlicht/CMeshSceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace scene

//! constructor
CMeshSceneNode::CMeshSceneNode(IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& position,
const core::quaternion& rotation,
const core::vector3df& scale)
: IMeshSceneNode(parent, mgr, id, position, rotation, scale), Mesh(0),
PassCount(0), ReadOnlyMaterials(false)
Expand Down
2 changes: 1 addition & 1 deletion source/Irrlicht/CMeshSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace scene
//! constructor
CMeshSceneNode(IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::quaternion& rotation = core::quaternion(0,0,0,1),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));

//! destructor
Expand Down
41 changes: 34 additions & 7 deletions source/Irrlicht/CSkinnedMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,16 +1340,41 @@ void CSkinnedMesh::recoverJointsFromMesh(core::array<IBoneSceneNode*> &jointChil
{
IBoneSceneNode* node=jointChildSceneNodes[i];
SJoint *joint=AllJoints[i];
node->setPosition(joint->LocalAnimatedMatrix.getTranslation());
node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees());
node->setScale(joint->LocalAnimatedMatrix.getScale());

node->setPosition(joint->Animatedposition);
node->setRotation(joint->Animatedrotation);
node->setScale(joint->Animatedscale);

node->positionHint=joint->positionHint;
node->scaleHint=joint->scaleHint;
node->rotationHint=joint->rotationHint;
}

IBoneSceneNode* top = nullptr;
for (u32 i=0; i<jointChildSceneNodes.size(); ++i)
{
IBoneSceneNode* node=jointChildSceneNodes[i];
if (!top || !node->getParent()) {
top = node;
continue;
}

node->updateAbsolutePosition();
bool is_child = false;
for (u32 j=0; j<jointChildSceneNodes.size(); ++j)
if (jointChildSceneNodes[j] == node->getParent()) {
is_child = true;
break;
}
if (is_child)
continue;

top = node;


}

if (top)
top->updateAbsolutePositionRecursive();
}


Expand All @@ -1360,9 +1385,9 @@ void CSkinnedMesh::transferJointsToMesh(const core::array<IBoneSceneNode*> &join
const IBoneSceneNode* const node=jointChildSceneNodes[i];
SJoint *joint=AllJoints[i];

joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation());
joint->LocalAnimatedMatrix.setTranslation(node->getPosition());
joint->LocalAnimatedMatrix *= core::matrix4().setScale(node->getScale());
joint->Animatedposition = node->getPosition();
joint->Animatedrotation = node->getRotation();
joint->Animatedscale = node->getScale();

joint->positionHint=node->positionHint;
joint->scaleHint=node->scaleHint;
Expand All @@ -1373,6 +1398,8 @@ void CSkinnedMesh::transferJointsToMesh(const core::array<IBoneSceneNode*> &join
// Make sure we recalc the next frame
LastAnimatedFrame=-1;
SkinnedLastFrame=false;

buildAllLocalAnimatedMatrices();
}


Expand Down

0 comments on commit 2ac90ea

Please sign in to comment.