Very confuse about Hpr.

Hello everyone.
It is a simple question but I can’t find this problem in any forum or I am misunderstand something.
I read the manual that Hpr rotate around own axis.
But I wondering what kind of axis (global or local axis).
So I try this code.

from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
from direct.task.Task import Task
from import Actor

import sys

class Main(DirectObject):

 def __init__ (self):

  self.prevtime = 0

  self.keyMap = {"mouse1":0 , "mouse3":0 , "left":0 , "right":0 , "up":0 , "down":0}
  # ------------------ camera --------------------

  # ----------------- model ----------------------

  self.Direct = loader.loadModel("directXYZ.egg")   

  # ----------------- control --------------------
  self.accept("escape", sys.exit, [0])
  self.accept("mouse1", self.setKey, ["mouse1",1])
  self.accept("mouse1-up", self.setKey, ["mouse1",0])
  self.accept("mouse3", self.setKey, ["mouse3",1])
  self.accept("mouse3-up", self.setKey, ["mouse3",0])

  self.accept("a", self.setKey, ["left",1])
  self.accept("a-up", self.setKey, ["left",0])
  self.accept("d", self.setKey, ["right",1])
  self.accept("d-up", self.setKey, ["right",0])
  self.accept("s", self.setKey, ["down",1])
  self.accept("s-up", self.setKey, ["down",0])
  self.accept("w", self.setKey, ["up",1])
  self.accept("w-up", self.setKey, ["up",0])

 def setKey(self, key, value):
  self.keyMap[key] = value

 def move(self, task):
  elapsed = task.time - self.prevtime

  if (self.keyMap["up"]!=0):
   self.Direct.setP(self.Direct.getP() + 3)
  if (self.keyMap["down"]!=0):
   self.Direct.setP(self.Direct.getP() - 3)
  if (self.keyMap["left"]!=0):
   self.Direct.setR(self.Direct.getR() + 3)
  if (self.keyMap["right"]!=0):
   self.Direct.setR(self.Direct.getR() - 3)
  if (self.keyMap["mouse1"]!=0):
   self.Direct.setH(self.Direct.getH() + 3)
  if (self.keyMap["mouse3"]!=0):
   self.Direct.setH(self.Direct.getH() - 3)

  self.prevtime = task.time
  return Task.cont

a = Main()

I notice that when I change R, it rotate around “local” Y axis.
When I change H, it rotate around “global” Z axis.
When I change P, I cannot tell what axis is it rotate around.
Anyone please tell me what exactly each H,P and R do?

Thanks in advance.

H = Heading
P = Pitch
R = Roll

easy to remember: it you want to go to a local bar, you ahve to change your heading, once there you’ll get drunk you fall down foreward… that’s when you change your pitch… once you’r on the floor you can only roll around.

all transforms are local, unless you specify a nodepath as first parameter, then it will be in the coordinate system of the node you specified.

Thanks for your reply.

This is a good trick to remember.
I follow your trick and notice this Hpr rotate like an airplane.

Thank you very much. I am understand clearly now.


In my robotics clas it was called roll-pitch-yaw (RPY).

Anyway here’s a wikipedia article explaining it:

@ThomasEgi: lol, but true