Camera Set takes effect in next frame

I define a task named spinCameraTask, in which I set camera pose. However I notice that the effect takes place in next iteration of this task-call. In other words the screenshot that i take is not at the position I just set, but is from a pos I set in the previous iteration.

Is it possible that the positions set take effect immediately? Or should I keep track of this myself?

class MyApp(ShowBase):
def spinCameraTask(self, task):
self.cam.setPos( Px, Py, Pz )

    # get screenshot. 
    tex = self.win.getScreenshot() 
    A = np.array(tex.getRamImageAs("RGB")).reshape(960,1280,3)


def __init__(self):
    ShowBase.__init__(self)
    self.taskMgr.add( self.spinCameraTask, "spinCameraTask" ) #changing camera poses

app = MyApp()
app.run()

Hi mpkuse, welcome to the Panda3D community :slight_smile: !

The call to self.win.getScreenshot() returns the previously rendered image, as you already noticed.
To get the image corresponding to the new camera pose, you could force Panda to render the new frame before you get the screenshot, using self.graphicsEngine.renderFrame():

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        self.taskMgr.add( self.spinCameraTask, "spinCameraTask" ) #changing camera poses

    def spinCameraTask(self, task):
        self.cam.setPos( Px, Py, Pz )

        # force a new render
        self.graphicsEngine.renderFrame()

        # get screenshot.
        tex = self.win.getScreenshot()
        A = np.array(tex.getRamImageAs("RGB")).reshape(960,1280,3)


app = MyApp()
app.run()

But if you want to do this continuously using a task, it might be better to create a second task for the screenshot and set the sort value of this task to something higher than 50 (which is the sort value of the task in which Panda does the rendering):

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        self.taskMgr.add( self.spinCameraTask, "spinCameraTask" ) #changing camera poses
        self.taskMgr.add( self.getScreenshot, "getScreenshot", sort=55 )

    def spinCameraTask(self, task):
        self.cam.setPos( Px, Py, Pz )
        return task.cont

    def getScreenshot(self, task):
        tex = self.win.getScreenshot()
        A = np.array(tex.getRamImageAs("RGB")).reshape(960,1280,3)
        return task.cont


app = MyApp()
app.run()