[solved]hprInterval() and setHpr()?

I just want to confirm something:

  1. [color=red]hprInterval() just soomthly rotate the object to a specific orientation but do not change the HPR value of that object.
  2. [color=red]setHpr() rotate the object and change the value of HPR.

Is that right? I get some strange results, so I want to make sure if what I think is right. If you do not understand what I mean, I’d like to paste my code and results.
Thanks a lot!

Any interval change objects’ properties.

import direct.directbase.DirectStart
from pandac.PandaModules import Vec3
from direct.task import Task

class World:
  def __init__(self):
      self.ax=loader.loadModelCopy('zup-axis')
      self.ax.reparentTo(render)
      self.ax.setScale(.1)
      self.ax.hprInterval(10,Vec3(360,0,0)).loop()

      base.cam.setPos(0,-3,5)
      base.cam.lookAt(render)
      taskMgr.add(self.gLoop,'gloop')

  def gLoop(self,task):
      print self.ax.getHpr()
      return Task.cont

World()
run()

What are you rotating ? Post your code.

Sorry, but this is wrong.
HPR == the rotation. you can’t set the rotation without setting hpr, and you can’t set the hpr without rotating it.
HprInterval smoothly adjusts the HPR (or rotation, just how you would like to call it) to the given value.

HPR === the rotation.
setHpr rotates the object to H,P,R. getHpr() returns the H,P,R of the rotation.

I just make some change to the ‘bvw’ example. There’s an event [color=darkred]turn, changing the Heading attribute of the panda when user press ‘arrow-left’ or ‘arrow-right’ key. I made two different turn() functions, one is using [color=darkred]hprInterval(), and the other is using [color=darkred]setH().
At run time, I pressed ‘arrow-right’ three times, then ‘arrow-left’ three times. The propmts below show different results corresponding to different turn() functions. Hope somebody can tell me how the difference comes?
Thank you so much!

hprInterval Version

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.actor.Actor import Actor

class PandaWorld(DirectObject):
    def genText(self, text, i):
        self.WD_font = loader.loadFont('waltDisneyFont.egg') 
        return OnscreenText(text = text, pos = (-1.3, .95-.05*i),
                            fg = (0, 1, 1, 1), align = TextNode.ALeft,
                            scale = .05, mayChange = 1,
                            font = self.WD_font)
                            
    def __init__(self):
        # Initialize the camera
        base.disableMouse()
        camera.setPosHpr( Vec3(0, -15, 7), Vec3(0, -15, 0) )
                
        self.event_arrow_left = self.genText('[ARROW_LEFT]: TURN LEFT', 0 )
        self.event_arrow_right = self.genText('[ARROW_RIGHT]: TURN RIGHT', 1 )
        
        self.LoadModels()
        print "ORIGINAL H: ", self.panda.getH()
        self.countInterval = 0
        self.accept("arrow_right", self.turn, [-1])
        self.accept("arrow_left", self.turn, [1])
        
    # Loads Models
    def LoadModels(self):
        # Loads up Actor
        self.panda = Actor("panda", {"walk":"panda-walk"})
        self.panda.reparentTo(render)
        self.panda.setScale(0.5)
    
    def turn(self, direction):
        self.countInterval = self.countInterval + 1
        print "Heading BEFORE", self.countInterval, "HPR INTERVAL: ", self.panda.getH()
        self.pandaTurn = self.panda.hprInterval(0.5, Vec3(self.panda.getH()-(10*direction),0,0))
        self.pandaTurn.start()
        print "Heading AFTER", self.countInterval, "HPR INTERVAL: ", self.panda.getH()

myWorld = PandaWorld()
run()

Result:( Sorry for inconvenience, cannot load up the screen shot!)
[color=green]ORIGINAL H: 0.0
:util(warning): Adjusting global clock’s real time by -4.33819 seconds.
Heading BEFORE 1 HPR INTERVAL: 0.0
Heading AFTER 1 HPR INTERVAL: 0.0
Heading BEFORE 2 HPR INTERVAL: 10.0
Heading AFTER 2 HPR INTERVAL: 10.0
Heading BEFORE 3 HPR INTERVAL: 20.0
Heading AFTER 3 HPR INTERVAL: 20.0
Heading BEFORE 4 HPR INTERVAL: 30.0
Heading AFTER 4 HPR INTERVAL: 30.0
Heading BEFORE 5 HPR INTERVAL: 20.0
Heading AFTER 5 HPR INTERVAL: 20.0
Heading BEFORE 6 HPR INTERVAL: 10.0
Heading AFTER 6 HPR INTERVAL: 10.0

setH Version

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.actor.Actor import Actor

class PandaWorld(DirectObject):
    def genText(self, text, i):
        self.WD_font = loader.loadFont('waltDisneyFont.egg') 
        return OnscreenText(text = text, pos = (-1.3, .95-.05*i),
                            fg = (0, 1, 1, 1), align = TextNode.ALeft,
                            scale = .05, mayChange = 1,
                            font = self.WD_font)
                            
    def __init__(self):
        # Initialize the camera
        base.disableMouse()
        camera.setPosHpr( Vec3(0, -15, 7), Vec3(0, -15, 0) )
                
        self.event_arrow_left = self.genText('[ARROW_LEFT]: TURN LEFT', 0 )
        self.event_arrow_right = self.genText('[ARROW_RIGHT]: TURN RIGHT', 1 )
        
        self.LoadModels()
        print "ORIGINAL H: ", self.panda.getH()
        self.countInterval = 0
        self.accept("arrow_right", self.turn, [-1])
        self.accept("arrow_left", self.turn, [1])
        
    # Loads Models
    def LoadModels(self):
        # Loads up Actor
        self.panda = Actor("panda", {"walk":"panda-walk"})
        self.panda.reparentTo(render)
        self.panda.setScale(0.5)
    
    def turn(self, direction):
        self.countInterval = self.countInterval + 1
        print "Heading BEFORE", self.countInterval, "setH(): ", self.panda.getH()
        # self.pandaTurn = self.panda.hprInterval(0.5, Vec3(self.panda.getH()-(10*direction),0,0))
        # self.pandaTurn.start()
        self.panda.setH(self.panda.getH()-(10*direction))
        # print "NEW: ", self.panda.getH()-(10*direction)
        print "Heading AFTER", self.countInterval, "setH():", self.panda.getH()
        

myWorld = PandaWorld()
run()

Result:
[color=green]ORIGINAL H: 0.0
:util(warning): Adjusting global clock’s real time by -6.40946 seconds.
Heading BEFORE 1 setH(): 0.0
Heading AFTER 1 setH(): 10.0
Heading BEFORE 2 setH(): 10.0
Heading AFTER 2 setH(): 20.0
Heading BEFORE 3 setH(): 20.0
Heading AFTER 3 setH(): 30.0
Heading BEFORE 4 setH(): 30.0
Heading AFTER 4 setH(): 20.0
Heading BEFORE 5 setH(): 20.0
Heading AFTER 5 setH(): 10.0
Heading BEFORE 6 setH(): 10.0
Heading AFTER 6 setH(): 0.0

def turn(self, direction):
    self.countInterval = self.countInterval + 1
    print "Heading BEFORE", self.countInterval, "HPR INTERVAL: ", self.panda.getH()
    self.pandaTurn = self.panda.hprInterval(0.5, Vec3(self.panda.getH()-(10*direction),0,0))
    self.pandaTurn.start()
    print "Heading AFTER", self.countInterval, "HPR INTERVAL: ", self.panda.getH()

Intervals’ lifetime span across the time (frames), for your code above, it’s 0.5 second. It will end completely 0.5 seconds from that time.
You print the before & after rotation at the same frame, exactly when the interval get started. Of course panda’s heading was just the same, because the interval hasn’t change it’s heading yet !
What do you want to do with the queried heading exactly ?

Thanks so much! ynjh_jo!
I’m still on the newbie level of Panda3D, so I’m unsure about how the HPR coordinate lays. What I did is just an experiment.
Thanks again!