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 ?
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 ?
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)
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.reparentTo(newNode)
sprite.setPos(1, 0, 0) # or whatever you want the rotate pivot to be
newNode.setR(rotation)
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.