I wrote a simple code to rotate the camera but it only works with yaw. When I use the exact same code to rotate the pitch, it gets wrong (it seems to run from -90 to 90).

Here is the code:

from panda3d.core import GeomVertexFormat,

GeomVertexData, GeomVertexWriter, Geom, GeomNode, GeomLinesfrom direct.showbase.ShowBase import ShowBase

from direct.task import Task

import numpy as np

import math

from pdb import set_trace as bpdef make_axes():

vformat = GeomVertexFormat.get_v3c4()

vdata = GeomVertexData(âvdataâ, vformat, Geom.UHStatic)

vdata.uncleanSetNumRows(6)`vertex = GeomVertexWriter(vdata, 'vertex') color = GeomVertexWriter(vdata, 'color') for x, y, z in np.eye(3): vertex.addData3(0, 0, 0) color.addData4(x, y, z, 1) vertex.addData3(x, y, z) color.addData4(x, y, z, 1) prim = GeomLines(Geom.UHStatic) prim.addNextVertices(6) geom = Geom(vdata) geom.addPrimitive(prim) return geom`

def euler_to_xyz(roll, pitch, yaw, distance):

`roll_rad = math.radians(roll) pitch_rad = math.radians(pitch) yaw_rad = math.radians(yaw) x = distance * math.cos(yaw_rad) * math.cos(pitch_rad) y = distance * math.sin(yaw_rad) * math.cos(pitch_rad) z = distance * math.sin(pitch_rad) return x, y, z`

class MyApp(ShowBase):

`def __init__(self): ShowBase.__init__(self) geom_axis = make_axes() geom_axis_node = GeomNode('axis') geom_axis_node.addGeom(geom_axis) self.render.attachNewNode(geom_axis_node) self.taskMgr.add(self.spinYawCameraTask, "spinYawCameraTask") self.taskMgr.add(self.spinPitchCameraTask, "spinPitchCameraTask") def spinYawCameraTask(self, task): angleDegrees = task.time * 40.0 # roll, pitch, yaw x,y,z = euler_to_xyz(0, angleDegrees, 20, 30) self.camera.setPos(x,y,z) self.camera.lookAt(0, 0, 0) x,y,z = self.camera.getPos() return Task.cont def spinPitchCameraTask(self, task): angleDegrees = task.time * 40.0 # roll, pitch, yaw x,y,z = euler_to_xyz(0, angleDegrees, 10, 30) self.camera.setPos(x,y,z) self.camera.lookAt(0, 0, 0) x,y,z = self.camera.getPos() return Task.cont`

app = MyApp()

app.run()