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