Rotate an object from API

Typically: "How do I... ", "How can I... " questions
Post Reply
mohammadhosseink
Posts: 25
Joined: 11 Sep 2022, 06:48

Rotate an object from API

Post by mohammadhosseink »

Hello,

I want to rotate a shape (a mesh) from API (Zmq), just like the option provided by the Rotation tab in the Orientation dialogue in Coppeliasim. So I want to simply rotate the object around the z-axis for some value ( z-axis of world frame, but not around the world as the center ).

Cheers,

fferri
Posts: 1231
Joined: 09 Sep 2013, 19:28

Re: Rotate an object from API

Post by fferri »

Code: Select all

eulerAngles = sim.getObjectOrientation(shapeHandle, sim.handle_world)
eulerAngles[3] = eulerAngles[3] + amount
sim.setObjectOrientation(shapeHandle, eulerAngles, sim.handle_world)
Notes:
  • sim.handle_world is the default, so it is not required to specify it;
  • objects rotate around their origin. Arbitrary rotation centers can be obtained by temporarily reparenting to another object, e.g. a temporary dummy placed in the desired location of the rotation center, or the object reference frame can be changed (see the "relocate shape reference frame" family of functions).

mohammadhosseink
Posts: 25
Joined: 11 Sep 2022, 06:48

Re: Rotate an object from API

Post by mohammadhosseink »

Thank you. I am familiar with sim.SetObjectOrientation functionality. However, the alpha, beta, omega values that you wish to pass to the function do not work as you defined it, since the object's frame is oriented relative to the world frame, and it's not a general answer to this problem. However, I changed my scene in order to make such a definition work.

fferri
Posts: 1231
Joined: 09 Sep 2013, 19:28

Re: Rotate an object from API

Post by fferri »

Then you want to specify the frame relative to something else than sim.handle_world.
Simply change that parameter when calling sim.setObjectOrientation

coppelia
Site Admin
Posts: 10376
Joined: 14 Dec 2012, 00:25

Re: Rotate an object from API

Post by coppelia »

Have also a look at sim.rotateAroundAxis

Cheers

mohammadhosseink
Posts: 25
Joined: 11 Sep 2022, 06:48

Re: Rotate an object from API

Post by mohammadhosseink »

fferri wrote: 11 Apr 2024, 13:37 Then you want to specify the frame relative to something else than sim.handle_world.
Simply change that parameter when calling sim.setObjectOrientation
Thanks fferri! I didn't know it was possible to set orientation relative to the object's handle itself.

Post Reply