[SOLVED] 2d rotate : changing the pivot of a sprite.


I want to rotate a sprite. The default seems to rotate around the center on the sprite. Which quite logical. But I want to rotate my sprite around another pivot, the middle of the left edge in my case.

what is the best solution ? I am new to panda3d so I am still diving into the documentation but at this time I did not find the good solution.

Do I need to create a new node and parent my sprite to it ?

Is there any good sample about it ?



Which sprites? Are you talking about particles? Or maybe billboards?

I talk about sprite I have loaded using loader.loadTexture or loader.loadModel (for egg file created with egg-texture-cards).

Is there another way to load texture to make sprites ?

Thats all gonna have to be done with geometry. Theres nothing in Panda3D to do that, in fact I’ve never heard of a game engine that offered such a feature.

@ov3rcl0ck you mean the pivot need to be setted outside of panda3D … I understand but when I create an egg file with egg-texture-cards (for exemple) I did not see how to modifye the geometry.

The only solution is to use a DCC (max, maya, …) to create a plan with the pivot where I want ?

Any advices ?

Are the sprites in 2D or 3D space? If they’re in 3D (billboards) then take a look at the code for controlling the camera in the panda3d tutorial. http://www.panda3d.org/manual/index.php/Controlling_the_Camera

sorry I did not specify …
so no it is not a bilboard.
I add my texture to “render2d”.

from what I understand and read, this should work:

    def spinObject(self, yourSprite, pivotPoint, distFromPoint, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        yourSprite.setPos((distFromPoint * sin(angleRadians))+pivotPoint.x, 0, (-distFromPoint * cos(angleRadians)) + pivotPoint.y)
        return Task.cont

//call this per spinning sprite where:
//yourSprite = object node of the sprite
//pivotPoint = Vec2 of location on screen where you want it
// distFromPoint = how far away from the point you want it to rotate
self.taskMgr.add(self.spinObject, "Spin Object", extraArgs = [yourSprite, pivotPoint, distFromPoint], appendTask=True)

Edit: Made a mistake, updated code should work.

thanks … I’ll try this.

edit: I did not try it yet but something I did not understand reading your code is your are only using setPos and not setHRP (or setR)

In general, the way to rotate an object about some point other than the origin is to parent it to another node, and rotate that other node instead.

Something like this:

newNode = render2d.attachNewNode('newNode')
sprite.setPos(1, 0, 0) # or whatever you want the rotate pivot to be


I guess the code i gave you is more of just an orbit code and not a rotation one. I dont know what the rotation value for panda2d is but you’d just add
yourSprite.setHpr(angleDegrees, 0, 0)
after setRot. Havent studied panda2d much so i dont know if its the H the P or the R value you’d set to angleDegrees.

@drwr … you are right … why I did not think about it before.