Difference between base.cam & base.camera

Hi,

I have a question : What is the difference between base.cam and base.camera ?

I made a FPSCamera (first person shooter) and when i change base.cam by base.camera, my framerate diminishes (60 -> 30 fps)

KeyListener is a class used to know if the specified key is pressed or not
MouseListene is a class who tells me the movement made by the mouse in the last frame

I post ce code :

class MyCam(DirectObject.DirectObject):
	def __init__(self):		
		self.vitesse = 40
		self.RotVitesse = 45
		
		self.w = KeyListener("w")
		self.s = KeyListener("s")
		self.a = KeyListener("a")
		self.d = KeyListener("d")
		
		self.mouse = MouseListener()
		
		taskMgr.add(self.move, "movingCam")
		
		self.previous = 0
		
	def move(self, task):
		x,y,z = base.cam.getPos()
		orient = base.cam.getHpr()
		elapsed = task.time-self.previous
		radX = (orient.getX()+90) / 180.0 * math.pi
		radY = orient.getY() / 180.0 * math.pi
		
		update = False
		
		if(self.w.isPressed()):
			#raison inconnu on intervertit les axe x et y 
			x = x + math.cos(radX)*math.cos(radY) * self.vitesse * elapsed
			y = y + math.sin(radX)*math.cos(radY) * self.vitesse * elapsed
			z = z + math.sin(radY) * self.vitesse * elapsed
			update = True
		if(self.s.isPressed()):
			x = x - math.cos(radX)*math.cos(radY) * self.vitesse * elapsed
			y = y - math.sin(radX)*math.cos(radY) * self.vitesse * elapsed
			z = z - math.sin(radY) * self.vitesse * elapsed
			update = True
		if(self.a.isPressed()):
			x = x - math.sin(radX)*math.cos(radY) * self.vitesse * elapsed
			y = y + math.cos(radX)*math.cos(radY) * self.vitesse * elapsed
			#z = z + math.sin(radY) * self.vitesse * elapsed
			update = True
		if(self.d.isPressed()):
			x = x + math.sin(radX)*math.cos(radY) * self.vitesse * elapsed
			y = y - math.cos(radX)*math.cos(radY) * self.vitesse * elapsed
			#z = z + math.sin(radY) * self.vitesse * elapsed
			update = True
		
		base.cam.setHpr(orient.getX() - self.mouse.getDirX()*self.RotVitesse, orient.getY() + self.mouse.getDirY()*self.RotVitesse, 0)
		if update :
			base.cam.setPos(x,y,z)
		
		#on enregistre le temps actuel pour un dt
		self.previous = task.time
		
		return task.cont

THx for help

Icare

P.S : Code is only here to have comment i don’t think the framelose came from here

I don’t know about your frame rate change; it’s likely just changing because you’re changing the view and seeing different objects. If it’s dropping from 60 to 30, you probably have video sync on, which makes it difficult to come to meaningful conclusions about frame rate. Turn it off with:

sync-video 0

in your Config.prc file, and you’ll probably see the frame rate drop from 65 to 55 instead or something more reasonable.

As to the difference between base.cam and base.camera, they exist as a convenience. base.cam is a child of base.camera, that’s the only difference. If you move base.camera, base.cam comes with it.

The reason they exist is so you can have multiple cameras attached to the same node (base.camera) and move them all as a unit, like for instance a front view and a rear-view mirror view or something. That’s why we recommend moving base.camera around whenever you want to move the camera, it gives you the power to do this.

If you move base.cam instead, though, nothing bad will happen to you. It certainly won’t have any negative effect on your frame rate. If you’re seeing a negative effect, it’s not because of this.

David

i add :

Now my framerate reach 600 fps but when i push w or s to move my framerate decrease downto 100 sometimes.

So how can i do an efficient FPSCamera ?

first off. the difference in computation time spend is rather tiny.
it’s still in the millisecond range.
you still can speed it up.
you’r using a lot of low-level math function such as pi, sin ,cos etc.
if you use them in panda, you’r most likely doing something wrong.
if you want to move your camera forewards, you can just set the position relative to itself. like

base.cam.setPos(base.cam , elapsed*speedX,0,0 )

same works for y and z.
there are a big number of conventient functions like this to avoid low-level math in python aswell as headaches.