So in my program I want the camera to be able to point at certain objects at the user’s request. I’ve got the camera positions working with self.camera.setPos() etc…, but unfortunately the camera angles don’t seem to be working, even though I am calculating values and calling the self.camera.Hpr() function, the camera itself doesn’t seem to want to change its angle. Any work-arounds/tips?
full code including where I work out the angles here:
def cameraTask(self,task):
if self.trackedObject !=None:
a = self.trackedObject.getTrackPos()
self.camera.setPos(a)
angleXYZ = self.getAxisAngles(self.trackedObject)
self.camera.setHpr(angleXYZ[0], angleXYZ[1], angleXYZ[2])
def getAxisAngles(self, obj):
angleXYZ = []
camera_pos = self.camera.getPos()
objectPos = obj.getPos()
cam_obj_vector = Vector(camera_pos[0] - objectPos[0], camera_pos[1] - objectPos[1], camera_pos[2] - objectPos[2])
cam_obj_vector_list = cam_obj_vector.getVectorList()
for i in range(3):
cos_angle_camToObj = cam_obj_vector_list[i]/(cam_obj_vector.getSpeed())
angleCamToObj = math.degrees(math.acos(cos_angle_camToObj))
angleXYZ.append(angleCamToObj)
return angleXYZ
Is it something to do with the getPos function I’m using to get the camera position?
I feel like the self.camera.getPos() isn’t recommended, purely because when I print that value out it eternally says 0, so idk if there is another function with similar purpose or not