I am trying to rotate Graphics to an angle. I have tried the SetGraphicRotation. But my issue is to turn the Graphic twice( Turn it to an angle, for example, 45° along the X-Axis in the first call and turn it x° in the Z-Axis in the next call). When the second rotation is called, I want the new rotation to be added to the previous rotaion. Unfortunately, the previous rotation is not taken. I am using the command SetGraphicRotation. It is just setting another Rotation to the Graphic and not adding another Rotation.
When doing it manually,all I have to do is to set the first rotation, and click on Add Rotation> Define Angle> Define Axes, it works perfectly as desired but not through Simtalk. Since it is not an object but a Graphic, I cannot use the "_3d.Rotation" command too. Is there a way to do this over Simtalk?
Thank you so much.
EDIT: I am looking for a command to Add Rotation and not SetRotation.
Solved! Go to Solution.
This is the more general method which allows you to add a translation as well. In your case you just use a zero translation.
Thank you for your reply. However, the previous rotation is not taken in the succeeding rotation. I have attached a test model if it helps. During the second call of the method, I want the previous rotation of 60° to also be taken into account when calcualting the new Rotation. I can do this manually by setting the first rotation, opening the 3D properties> Add Rotation as shown in the picture attached. I would like to know if a new rotation can be added by code. Could you please take a look into it? Thank you so much for your time.
I'd like to add one final suggestion:
With _3D.set/addGraphicRotation, you cut the graphic inheritance (if it isn't already cut). If you actually wanted to modify your graphics for a particular object, that's alright.
But if you actually just wanted to accumulate rotations of an entire object (for instance a whole SingleProc), typically, you would have just assigned a new value to the _3D.Rotation attribute. To add a rotation in such a case, you can use the helper function basis.~._3D.concatenateRotations.
This function allows you to calculate a value that you can assign to e.g. _3D.Rotation:
-- Example 1: Two "anonymous" rotations var r := basis.~._3D.concatenateRotations(makeArray(45, 0, 0, -1), makeArray(45, 0, 0, -1)) -- The result will be [90, 0, 0, -1] or [-90, 0, 0, 1]. -- This also works with different rotation axes but with the same axis I can write the example without a calculator. myObject._3D.Rotation := r -- Example 2: "Add Rotation" var r := basis.~._3D.concatenateRotations(myObject._3D.Rotation, makeArray(10, 1, 0, 0)) -- The result will be the same as "Add Rotation" with 10 degrees around the X axis myObject._3D.Rotation := r
You can also use the calculation result for _3D.setGraphicRotation, of course.
I know you wrote that you are working on a graphic instead of on an object but I frequently saw that as a workaround for actually transformating the object visually...