So, I have been in discussion with a couple others trying to perfect a code for my mouse movements on another forum topic. However, it has come to my attention that the code is simple and affective, but does not seem to work on my current device as it should.
As the topic notes, I am using a Macbook for my development process. When I sent the code to my desktop pc, it worked as expected. Additionally, other people on the forums also said that this code worked as expected. I will post the code below as well as the issue.
Here is the issue: When running this code, “XDiff” determines the displacement of X at every frame. However, on my Mac, even though I constantly move my mouse, it only recognizes that the mouse is moving about once every 15 frames. Otherwise, it states that the mouse is at position 0,0 at the center of the screen which is not the case, or rather should not be the case. The code never signifies that it loses the pass. Additionally, if I make an extra stipulation that I have to hold Right-Click to turn, it will still print the same results; therefore, the mouse is certainly being detected this entire time.
CODE
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
class Game(ShowBase):
def init(self):
ShowBase.init(self)
self.accept(“escape”, base.userExit)
self.disableMouse()
self.setFrameRateMeter(True)
self.environment = loader.loadModel("Environment/PracticeMap2")
self.environment.reparentTo(render)
self.environment.setPos(0,0,-2)
self.dummyNode = render.attachNewNode("dummyNode")
self.dummyNode.setPos(-2,-5,2)
self.cameraNode = base.camera.reparentTo(self.dummyNode)
self.camera.setPos(.5, -4, 5)
self.dummyNode.setP(30)
self.camera.setP(-35)
self.MouseSensitivity = 10
X = int(base.win.getXSize()/2)
Y = int(base.win.getYSize()/2)
base.win.movePointer(0, X, Y)
self.mouseCenter = [X,Y]
self.task_mgr.add(self.Look, "Look")
def Look(self,task):
if base.mouseWatcherNode.hasMouse():
XDiff = base.mouseWatcherNode.getMouseX()
base.win.movePointer(0, self.mouseCenter[0], self.mouseCenter[1])
else:
XDiff = 0
print(XDiff)
self.dummyNode.setH(self.dummyNode.getH() + 100*XDiff*-1)
return task.cont
app = Game()
app.run()
Example of return for printing XDiff (Note Even while restricting FPS to 60 in config)
0.1614062786102295
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0