Moreover, the disc model is parented to render.
It should be parented to render2d or aspect2d.
If it’s parented to aspect2d, you should convert the mouse XY coordinate from render2d coordinate space to aspect2d’s.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from direct.interval.IntervalGlobal import *
from direct.task import Task
class Application(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.disableMouse()
self.disc = self.loader.loadModel("disc")
self.disc.setScale(0.1)
self.disc.reparentTo(render)
self.cam.setPos(0, -10, 0)
base.setBackgroundColor(0,0,0)
taskMgr.add(self.mouse_pos, "my mouse updating task")
alight = AmbientLight('alight')
alnp = render.attachNewNode(alight)
alight.setColor(Vec4(0.2, 0.3, 0.4, 1))
render.setLight(alnp)
def mouse_pos(self, task):
if base.mouseWatcherNode.hasMouse():
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
self.disc.setX(x * 5)
self.disc.setZ(y * 3)
return Task.cont
The second reply gave me the idea to use the aspect2d to connect mouse coordinates to a point what drives a model in the 3d scene (need it, as I want use particle effects and layers later on). Still, both are relative to y in 3D and size of window.
Well, it is working for my purpose at the moment.
I will take a look at it again later in time, as a solution what keeps position of 2d mouse coords and xz position of 3d sync no matter what resolution you choose and no matter how far the model is away from the camera.