mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 11:28:17 -04:00
Added ortho zoom support
This commit is contained in:
parent
f3812fd8dd
commit
4a85b07d0a
@ -97,8 +97,13 @@ class DirectCameraControl(DirectObject):
|
|||||||
# Record time of start of mouse interaction
|
# Record time of start of mouse interaction
|
||||||
self.startT= globalClock.getFrameTime()
|
self.startT= globalClock.getFrameTime()
|
||||||
self.startF = globalClock.getFrameCount()
|
self.startF = globalClock.getFrameCount()
|
||||||
# Start manipulation
|
# If the cam is orthogonal, spawn differentTask
|
||||||
self.spawnHPanYZoom()
|
if (hasattr(base.direct.cam.node(), "getLens") and
|
||||||
|
base.direct.cam.node().getLens().__class__.__name__ == "OrthographicLens"):
|
||||||
|
self.spawnOrthoZoom()
|
||||||
|
else:
|
||||||
|
# Start manipulation
|
||||||
|
self.spawnHPanYZoom()
|
||||||
|
|
||||||
def mouseDollyStop(self):
|
def mouseDollyStop(self):
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
@ -208,6 +213,13 @@ class DirectCameraControl(DirectObject):
|
|||||||
t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
||||||
taskMgr.add(t, 'manipulateCamera')
|
taskMgr.add(t, 'manipulateCamera')
|
||||||
|
|
||||||
|
def spawnOrthoZoom(self):
|
||||||
|
# Kill any existing tasks
|
||||||
|
taskMgr.remove('manipulateCamera')
|
||||||
|
# Spawn new task
|
||||||
|
t = Task.Task(self.OrthoZoomTask)
|
||||||
|
taskMgr.add(t, 'manipulateCamera')
|
||||||
|
|
||||||
def spawnHPPan(self):
|
def spawnHPPan(self):
|
||||||
# Kill any existing tasks
|
# Kill any existing tasks
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
@ -243,8 +255,8 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
def HPanYZoomTask(self, state):
|
def HPanYZoomTask(self, state):
|
||||||
# If the cam is orthogonal, don't rotate or zoom.
|
# If the cam is orthogonal, don't rotate or zoom.
|
||||||
if (hasattr(base.direct.camera.node(), "getLens") and
|
if (hasattr(base.direct.cam.node(), "getLens") and
|
||||||
base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
base.direct.cam.node().getLens().__class__.__name__ == "OrthographicLens"):
|
||||||
return
|
return
|
||||||
|
|
||||||
if base.direct.fControl:
|
if base.direct.fControl:
|
||||||
@ -280,6 +292,15 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
|
def OrthoZoomTask(self, state):
|
||||||
|
filmSize = base.direct.camNode.getLens().getFilmSize()
|
||||||
|
factor = (base.direct.dr.mouseDeltaX -1.0 * base.direct.dr.mouseDeltaY) * 0.1
|
||||||
|
x = base.direct.dr.getWidth()
|
||||||
|
y = base.direct.dr.getHeight()
|
||||||
|
base.direct.dr.orthoFactor -= factor
|
||||||
|
base.direct.dr.updateFilmSize(x, y)
|
||||||
|
return Task.cont
|
||||||
|
|
||||||
def HPPanTask(self, state):
|
def HPPanTask(self, state):
|
||||||
base.direct.camera.setHpr(base.direct.camera,
|
base.direct.camera.setHpr(base.direct.camera,
|
||||||
(0.5 * base.direct.dr.mouseDeltaX *
|
(0.5 * base.direct.dr.mouseDeltaX *
|
||||||
@ -304,8 +325,8 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
def mouseRotateTask(self, state):
|
def mouseRotateTask(self, state):
|
||||||
# If the cam is orthogonal, don't rotate.
|
# If the cam is orthogonal, don't rotate.
|
||||||
if (hasattr(base.direct.camera.node(), "getLens") and
|
if (hasattr(base.direct.cam.node(), "getLens") and
|
||||||
base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
base.direct.cam.node().getLens().__class__.__name__ == "OrthographicLens"):
|
||||||
return
|
return
|
||||||
# If moving outside of center, ignore motion perpendicular to edge
|
# If moving outside of center, ignore motion perpendicular to edge
|
||||||
if ((state.constrainedDir == 'y') and (abs(base.direct.dr.mouseX) > 0.9)):
|
if ((state.constrainedDir == 'y') and (abs(base.direct.dr.mouseX) > 0.9)):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user