質問

I have a program I'm writing based off of a tutorial:

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        # Load the environment model.
        self.environ = self.loader.loadModel("models/misc/rgbCube")
        # Reparent the model to render.
        self.environ.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.environ.setScale(10, 10, 10)
        self.environ.setPos(-8, 42, 0)



app = MyApp()
app.run()

And I want something like:

self.environ.rotate(axis to revolve on, rot in degrees)

I've searched extensively on google, and the only thing that even LOOKS like it will work was this: http://www.panda3d.org/manual/index.php/Position,_Rotation_and_Scale_Intervals And guess what! It didn't. Could you point me to a website that explaint Hpr in depth, or just explain it here? Thanks.

役に立ちましたか?

解決

Panda uses Euler angles (aka flight angles) to represent rotation. The angles passed to setHpr are yaw-pitch-roll angles (in degrees), except that Panda uses the term "heading" instead of "yaw" because the letter Y is already used for the Y position.

In your terms, the H angle is how the model rotates around the (0, 0, 1) axis, the P angle how much it rotates around the (1, 0, 0) axis, and the R angle how much it rotates around the (0, 1, 0) axis.

If you want to rotate a model in its own coordinate system, as you seem to want to do, you can pass the model as first argument to any of the setHpr functions so that Panda calculates the new rotation in the model's coordinate system:

# Rotates the model 90 degrees around its own up axis
model.setH(model, 90)

When you rotate a model, it will be rotated around its origin (its relative (0, 0, 0) point). If you want it to be rotated around a different point, the typical way to do this is to create a dummy intermediate node that is rotated instead:

pivotNode = render.attachNewNode("environ-pivot")
pivotNode.setPos(...) # Set location of pivot point
environ.wrtReparentTo(pivotNode) # Preserve absolute position
pivotNode.setHpr(...) # Rotates environ around pivot

I know you didn't ask for that but there it is just in case it is helpful.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top