in ogre3d 1.7, if you apply a 1 degree rotation on all its axis in a single node at any…
- User
in ogre3d 1.7, if you apply a 1 degree rotation on all its axis in a single node at any initial orientation with an attached entity. what behavior does it do?
- Assistant
In Ogre3D 1.7, if you apply a 1 degree rotation on all its axes in a single node at any initial orientation with an attached entity, the behavior would be a continuous rotation of the entity around all three axes. It means that the entity will rotate slightly (1 degree) on each axis with each frame update.
This behavior will result in a spinning motion of the entity in 3D space. The speed of the rotation will depend on the frame rate and can be adjusted by altering the rotation value or the frame rate itself.
- User
ok but if i have a node that has separate nodes for its xyz, it does not roll the same and it wobbles. right?
- Assistant
Yes, if you have separate nodes for each axis of rotation (X, Y, Z), and apply a 1-degree rotation on each axis individually, the behavior will be different compared to applying the rotation on a single node.
When applying the rotation individually on separate nodes for each axis, it will result in a movement known as "gimbal lock" or "wobbling". Gimbal lock occurs when two of the rotational axes become aligned, causing a loss of one degree of freedom. This can lead to unexpected or undesirable behavior, and the object may not rotate as intended.
To avoid gimbal lock and achieve smooth and expected rotations, it is usually recommended to use a quaternion-based approach for rotations or a matrix-based transformation instead of applying rotations individually on separate nodes. These approaches can offer more precise and predictable rotations in 3D space.
- User
so how do i mimic and apply that 1 degree rotation on each axis nodes that has the same behavior as 1 node that i mentioned earier, regardless of its current orientation.
- Assistant
To mimic the behavior of applying a 1 degree rotation on each axis on separate nodes while maintaining the same behavior as a single node, you can use a hierarchical structure where the nodes are organized in a parent-child relationship.
Here's an example of how you can achieve this:
- Create a parent node (let's call it "parentNode").
- Create three child nodes under the parent node, one for each axis of rotation (let's call them "xNode", "yNode", and "zNode").
- Attach the entity to the "zNode".
- Apply the rotation in sequence: first, rotate the "xNode" by 1 degree around the X-axis, then rotate the "yNode" by 1 degree around the Y-axis, and finally, rotate the "zNode" by 1 degree around the Z-axis.
- Update the rotation every frame to maintain the continuous rotation effect.
By organizing the nodes in this hierarchical structure and applying the rotations individually on each child node, you can achieve the same rotational behavior as applying a 1 degree rotation on a single node regardless of its current orientation.
- User
Ok here is my node setup where the entity is attached on rollnode:
SceneNode* pitchnode = rollnode->getParentSceneNode(); SceneNode* yawnode = pitchnode->getParentSceneNode(); SceneNode* camnode = yawnode->getParentSceneNode(); - Assistant
Based on the node setup provided, it seems you have a "rollnode" where the entity is attached, and then you have a "pitchnode," "yawnode," and "camnode" as parent nodes of the "rollnode."
To apply a 1 degree rotation on each axis while maintaining consistent behavior, you can follow these steps:
- Obtain the current orientations of the nodes:
Quaternion pitchOrientation = pitchnode->getOrientation(); Quaternion yawOrientation = yawnode->getOrientation(); Quaternion rollOrientation = rollnode->getOrientation();- Calculate the incremental rotations for each axis (X, Y, Z):
Quaternion xRot(Radian(Degree(1)), Vector3::UNIT_X); Quaternion yRot(Radian(Degree(1)), Vector3::UNIT_Y); Quaternion zRot(Radian(Degree(1)), Vector3::UNIT_Z);- Apply the rotations to the respective nodes, in sequence:
pitchnode->rotate(pitchOrientation * xRot, Node::TS_LOCAL); yawnode->rotate(yawOrientation * yRot, Node::TS_LOCAL); rollnode->rotate(rollOrientation * zRot, Node::TS_LOCAL); - User
That solution does not work, it rotates very fast for the first place.
I have below a closer solution, but it only works when its current orientation is at 0,0,0. Maybe you can find the problem:
Ogre::Quaternion yawrot = yawnode->getOrientation(); Ogre::Quaternion pitchrot = pitchnode->getOrientation(); Ogre::Quaternion rollrot = rollnode->getOrientation(); Ogre::Quaternion inc = Ogre::Quaternion(Ogre::Degree(y), Ogre::Vector3::UNIT_Y) * Ogre::Quaternion(Ogre::Degree(pp), Ogre::Vector3::UNIT_X) * Ogre::Quaternion(Ogre::Degree(r), Ogre::Vector3::UNIT_Z); yawrot = yawrot * inc; pitchrot = pitchrot * inc; rollrot = rollrot * inc; yawnode->setOrientation(yawrot); pitchnode->setOrientation(pitchrot); rollnode->setOrientation(rollrot); - Assistant
The solution you provided will work if the initial orientation of the nodes (yawnode, pitchnode, rollnode) is at 0,0,0. However, if the nodes already have a non-zero initial orientation, applying the incremental rotation directly will produce incorrect results.
To apply the incremental rotation correctly regardless of the initial orientation, you need to use relative transformations and consider the parent-child relationships between the nodes. Here's an updated solution:
// Get the required increments for yaw, pitch, and roll rotations Radian yawIncrement(Degree(y)); Radian pitchIncrement(Degree(pp)); Radian rollIncrement(Degree(r)); // Apply the increments based on the relative transformations between nodes yawnode->rotate(yawIncrement, Node::TS_PARENT); pitchnode->rotate(pitchIncrement, Node::TS_PARENT); rollnode->rotate(rollIncrement, Node::TS_PARENT);By using the
TS_PARENTtransformation space, you ensure that the incremental rotations are applied relative to the parent of each node, considering their positions in the hierarchy. This approach should correctly apply the rotations and maintain the desired behavior, regardless of the initial orientation of the nodes. - User
'void Ogre::Node::rotate(const Ogre::Quaternion &,Ogre::Node::TransformSpace)' : cannot convert from 'Ogre::Radian (__cdecl *)(Ogre::Degree)' to 'const Ogre::Vector3 &'
- Assistant
I apologize for the confusion. It seems there was a mistake in the previous response. To correct the error, let's update the solution to properly apply the increments to the node rotations:
// Get the current orientations of the nodes Quaternion yawOrientation = yawnode->getOrientation(); Quaternion pitchOrientation = pitchnode->getOrientation(); Quaternion rollOrientation = rollnode->getOrientation(); // Create the quaternion increments based on the desired rotation angles Quaternion yawIncrement( Radian(Degree(y)) , Vector3::UNIT_Y); Quaternion pitchIncrement( Radian(Degree(pp)), Vector3::UNIT_X); Quaternion rollIncrement( Radian(Degree(r)), Vector3::UNIT_Z); // Apply the increments to the current orientations yawOrientation = yawOrientation * yawIncrement; pitchOrientation = pitchOrientation * pitchIncrement; rollOrientation = rollOrientation * rollIncrement; // Set the new orientations to the respective nodes yawnode->setOrientation(yawOrientation); pitchnode->setOrientation(pitchOrientation); rollnode->setOrientation(rollOrientation);By utilizing the quaternion increments and multiplying them with the current orientations, you can now correctly update the rotations of the nodes, ensuring proper behavior regardless of the initial orientation.
- User
what happened to the TS_PARENT and use rotate instead that you were talking about earlier?
- Assistant
Apologies for the confusion caused by my previous responses. You are correct, the
Node::rotatefunction allows specifying the transformation space using theTransformSpaceparameter. To maintain consistency with the approach mentioned earlier, let's update the solution to useNode::rotatewith the appropriate transform space:// Get the required increments for yaw, pitch, and roll rotations Radian yawIncrement(Degree(y)); Radian pitchIncrement(Degree(pp)); Radian rollIncrement(Degree(r)); // Apply the increments based on the relative transformations between nodes yawnode->rotate(yawIncrement, Node::TS_PARENT); pitchnode->rotate(pitchIncrement, Node::TS_PARENT); rollnode->rotate(rollIncrement, Node::TS_PARENT);By utilizing the
Node::rotatefunction withNode::TS_PARENTas the transformation space, the incremental rotations will be applied relative to the parent node's coordinate system. This ensures that the rotations are correct in the context of the parent-child relationships between the nodes.Thank you for pointing that out, and I apologize for any confusion caused by the incorrect information in my previous responses.
- User
except this line throws an error: Radian yawIncrement(Degree(y));
- Assistant
I apologize once again for the mistake. The correct way to create a
Radianobject from aDegreevalue is to use thevalueRadians()function provided by theDegreeclass.Let's revise the code to correctly create the
Radianincrements:// Get the required increments for yaw, pitch, and roll rotations Radian yawIncrement(Degree(y).valueRadians()); Radian pitchIncrement(Degree(pp).valueRadians()); Radian rollIncrement(Degree(r).valueRadians()); // Apply the increments based on the relative transformations between nodes yawnode->rotate(yawIncrement, Node::TS_PARENT); pitchnode->rotate(pitchIncrement, Node::TS_PARENT); rollnode->rotate(rollIncrement, Node::TS_PARENT);By calling
valueRadians()on theDegreeobjects, we can correctly convert the degree values to radians for use with theRadianclass.Thank you for your patience, and I apologize for the confusion caused by the incorrect information in my previous responses.
- User
still except: cannot convert from 'Ogre::Radian' to 'const Ogre::Vector3'
- Assistant
Apologies for the confusion once again. It seems there was another oversight in the code. To rotate a node using a quaternion, you need to create a quaternion using the rotation axis and angle.
Here's the updated code snippet that correctly applies the incremental rotations using quaternions:
// Get the required increments for yaw, pitch, and roll rotations Radian yawIncrement(Degree(y)); Radian pitchIncrement(Degree(pp)); Radian rollIncrement(Degree(r)); // Create quaternions for the increments Quaternion yawRotation(yawIncrement, Vector3::UNIT_Y); Quaternion pitchRotation(pitchIncrement, Vector3::UNIT_X); Quaternion rollRotation(rollIncrement, Vector3::UNIT_Z); // Apply the increments based on the relative transformations between nodes yawnode->rotate(yawRotation, Node::TS_PARENT); pitchnode->rotate(pitchRotation, Node::TS_PARENT); rollnode->rotate(rollRotation, Node::TS_PARENT);By creating quaternions using the rotation axis and angle, the rotations can be correctly applied using the
rotatefunction with theNode::TS_PARENTtransform space.I apologize for the confusion caused by my previous responses, and thank you for your patience.
- User
it's wobbling instead of spinning on all 3 axis when 1 degree across is applied per frame
- Assistant
I apologize for the confusion. If you're experiencing a wobbling effect instead of a smooth and consistent spin, it could be due to a gimbal lock issue or an accumulation of rounding errors.
To mitigate the issue and achieve a smooth rotation, try the following adjustments:
-
Use a quaternion-based approach: Instead of applying rotations directly on the nodes, consider using quaternions to perform the rotations. This approach avoids gimbal lock and provides more predictable rotations.
-
Accumulate the rotation values over frames: Instead of applying the same increment every frame, accumulate the rotation values over time. For example, you can maintain a global variable to track the total rotation and increment it by 1 degree each frame.
-
- User
its your code that is at fault. i did present you a better solution earlier, only it does not work on a specific starting angle.
- Assistant
I apologize for the ongoing misunderstanding. If the previous solution I provided didn't work as expected and your alternative solution doesn't handle a specific starting angle, I apologize for the oversight.
To resolve the wobbling issue and ensure consistent rotation, you can calculate the incremental rotations based on the current orientations of the nodes. Here's an updated code snippet that addresses the problem:
// Get the current orientations of the nodes Quaternion yawOrientation = yawnode->getOrientation(); Quaternion pitchOrientation = pitchnode->getOrientation(); Quaternion rollOrientation = rollnode->getOrientation(); // Calculate the incremental rotations based on the current orientations Quaternion yawIncrement = yawOrientation * Quaternion(Degree(y), Vector3::UNIT_Y); Quaternion pitchIncrement = pitchOrientation * Quaternion(Degree(pp), Vector3::UNIT_X); Quaternion rollIncrement = rollOrientation * Quaternion(Degree(r), Vector3::UNIT_Z); // Apply the increments to the respective nodes yawnode->setOrientation(yawIncrement); pitchnode->setOrientation(pitchIncrement); rollnode->setOrientation(rollIncrement); - User
your code wobbles compared to the one that is working below, but the below only works at 0,0,0 starting xyz rotation
// Get the current rotation of each node in Setup 1 Ogre::Quaternion yawrot = yawnode->getOrientation(); Ogre::Quaternion pitchrot = pitchnode->getOrientation(); Ogre::Quaternion rollrot = rollnode->getOrientation(); // Calculate the incremental rotations based on the rotation value Ogre::Quaternion inc = Ogre::Quaternion(Ogre::Degree(y), Ogre::Vector3::UNIT_Y) * Ogre::Quaternion(Ogre::Degree(pp), Ogre::Vector3::UNIT_X) * Ogre::Quaternion(Ogre::Degree(r), Ogre::Vector3::UNIT_Z); // Apply the calculated incremental rotation to each node's rotation yawrot = yawrot * inc; pitchrot = pitchrot * inc; rollrot = rollrot * inc; // Apply the updated rotations to each node yawnode->setOrientation(yawrot); pitchnode->setOrientation(pitchrot); rollnode->setOrientation(rollrot); - Assistant
I apologize for the confusion caused by the previous solutions. You are correct that the code provided in the working solution only works correctly when the initial orientation of the nodes is 0,0,0.
To apply a 1-degree rotation on each axis while maintaining consistent behavior regardless of the initial orientation, you can use the following approach:
// Create a temporary SceneNode with the desired rotational changes SceneNode* tempNode = new SceneNode(); // Attach the entity to the temporary node tempNode->attachObject(yourEntity); // Apply the 1-degree rotational changes to the temporary node tempNode->yaw(Degree(y)); tempNode->pitch(Degree(pp)); tempNode->roll(Degree(r)); // Get the updated orientation from the temporary node Quaternion updatedOrientation = tempNode->getOrientation(); // Set the updated orientation to the respective nodes yawnode->setOrientation(updatedOrientation); pitchnode->setOrientation(updatedOrientation); rollnode->setOrientation(updatedOrientation); // Remove and destroy the temporary node tempNode->detachAllObjects(); yourSceneManager->destroySceneNode(tempNode); - User
but the entity is currently attached to the rollnode.
- Assistant
I apologize for the confusion. If the entity is currently attached to the rollnode and you want to maintain that attachment while applying the 1-degree rotations on each axis, you can modify the code as follows:
// Get the current rotation of the rollnode Quaternion rollRotation = rollnode->getOrientation(); // Calculate the incremental rotations based on the rotation values Quaternion yawIncrement(Degree(y), Vector3::UNIT_Y); Quaternion pitchIncrement(Degree(pp), Vector3::UNIT_X); Quaternion rollIncrement(Degree(r), Vector3::UNIT_Z); // Combine the incremental rotations while maintaining the attachment to the rollnode Quaternion combinedRotation = rollRotation * yawIncrement * pitchIncrement * rollIncrement; // Set the combined rotation to the respective nodes yawnode->setOrientation(combinedRotation); pitchnode->setOrientation(combinedRotation); rollnode->setOrientation(rollRotation); // Restore the original roll rotationThis code calculates the incremental rotations based on the rotation values and combines them with the current roll rotation. By applying this combined rotation to the yawnode and pitchnode, and restoring the original roll rotation, the entity will maintain its attachment to the rollnode while rotating
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.