mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Enabled to change controlled camera
This commit is contained in:
parent
2ea87673aa
commit
b42af781bd
@ -15,6 +15,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
notify = DirectNotifyGlobal.directNotify.newCategory('DirectCameraControl')
|
notify = DirectNotifyGlobal.directNotify.newCategory('DirectCameraControl')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.camera = base.direct.camera # [gjeon] initially it will control base.direct.camera
|
||||||
# Create the grid
|
# Create the grid
|
||||||
self.startT = 0.0
|
self.startT = 0.0
|
||||||
self.startF = 0
|
self.startF = 0
|
||||||
@ -74,6 +75,10 @@ class DirectCameraControl(DirectObject):
|
|||||||
self.useMayaCamControls = 0
|
self.useMayaCamControls = 0
|
||||||
self.altDown = 0
|
self.altDown = 0
|
||||||
|
|
||||||
|
# [gjeon] you can change which camera will be controlled
|
||||||
|
def setCamera(self, camera):
|
||||||
|
self.camera = camera
|
||||||
|
|
||||||
def toggleMarkerVis(self):
|
def toggleMarkerVis(self):
|
||||||
## if base.direct.cameraControl.coaMarker.isHidden():
|
## if base.direct.cameraControl.coaMarker.isHidden():
|
||||||
## base.direct.cameraControl.coaMarker.show()
|
## base.direct.cameraControl.coaMarker.show()
|
||||||
@ -116,6 +121,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
self.spawnXZTranslate()
|
self.spawnXZTranslate()
|
||||||
self.altDown = 1
|
self.altDown = 1
|
||||||
elif not self.useMayaCamControls:
|
elif not self.useMayaCamControls:
|
||||||
|
print base.direct.dr.mouseX
|
||||||
# Where are we in the display region?
|
# Where are we in the display region?
|
||||||
if ((abs(base.direct.dr.mouseX) < 0.9) and (abs(base.direct.dr.mouseY) < 0.9)):
|
if ((abs(base.direct.dr.mouseX) < 0.9) and (abs(base.direct.dr.mouseY) < 0.9)):
|
||||||
# MOUSE IS IN CENTRAL REGION
|
# MOUSE IS IN CENTRAL REGION
|
||||||
@ -184,7 +190,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
# Spawn the new task
|
# Spawn the new task
|
||||||
t = Task.Task(self.XZTranslateOrHPanYZoomTask)
|
t = Task.Task(self.XZTranslateOrHPanYZoomTask)
|
||||||
# For HPanYZoom
|
# For HPanYZoom
|
||||||
t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
t.zoomSF = Vec3(self.coaMarker.getPos(self.camera)).length()
|
||||||
taskMgr.add(t, 'manipulateCamera')
|
taskMgr.add(t, 'manipulateCamera')
|
||||||
|
|
||||||
def spawnXZTranslateOrHPPan(self):
|
def spawnXZTranslateOrHPPan(self):
|
||||||
@ -205,7 +211,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Spawn new task
|
# Spawn new task
|
||||||
t = Task.Task(self.HPanYZoomTask)
|
t = Task.Task(self.HPanYZoomTask)
|
||||||
t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
t.zoomSF = Vec3(self.coaMarker.getPos(self.camera)).length()
|
||||||
taskMgr.add(t, 'manipulateCamera')
|
taskMgr.add(t, 'manipulateCamera')
|
||||||
|
|
||||||
def spawnHPPan(self):
|
def spawnHPPan(self):
|
||||||
@ -229,9 +235,9 @@ class DirectCameraControl(DirectObject):
|
|||||||
return self.XZTranslateTask(state)
|
return self.XZTranslateTask(state)
|
||||||
|
|
||||||
def XZTranslateTask(self, state):
|
def XZTranslateTask(self, state):
|
||||||
coaDist = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
coaDist = Vec3(self.coaMarker.getPos(self.camera)).length()
|
||||||
xlateSF = (coaDist / base.direct.dr.near)
|
xlateSF = (coaDist / base.direct.dr.near)
|
||||||
base.direct.camera.setPos(base.direct.camera,
|
self.camera.setPos(self.camera,
|
||||||
(-0.5 * base.direct.dr.mouseDeltaX *
|
(-0.5 * base.direct.dr.mouseDeltaX *
|
||||||
base.direct.dr.nearWidth *
|
base.direct.dr.nearWidth *
|
||||||
xlateSF),
|
xlateSF),
|
||||||
@ -243,12 +249,13 @@ 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(self.camera.node(), "getLens") and
|
||||||
base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
self.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
||||||
|
print "Currently, ortho can't zoom either"
|
||||||
return
|
return
|
||||||
|
|
||||||
if base.direct.fControl:
|
if base.direct.fControl:
|
||||||
moveDir = Vec3(self.coaMarker.getPos(base.direct.camera))
|
moveDir = Vec3(self.coaMarker.getPos(self.camera))
|
||||||
# If marker is behind camera invert vector
|
# If marker is behind camera invert vector
|
||||||
if moveDir[1] < 0.0:
|
if moveDir[1] < 0.0:
|
||||||
moveDir.assign(moveDir * -1)
|
moveDir.assign(moveDir * -1)
|
||||||
@ -268,7 +275,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
hVal = 0.5 * base.direct.dr.mouseDeltaX * base.direct.dr.fovH
|
hVal = 0.5 * base.direct.dr.mouseDeltaX * base.direct.dr.fovH
|
||||||
|
|
||||||
base.direct.camera.setPosHpr(base.direct.camera,
|
self.camera.setPosHpr(self.camera,
|
||||||
moveDir[0],
|
moveDir[0],
|
||||||
moveDir[1],
|
moveDir[1],
|
||||||
moveDir[2],
|
moveDir[2],
|
||||||
@ -276,12 +283,12 @@ class DirectCameraControl(DirectObject):
|
|||||||
0.0, 0.0)
|
0.0, 0.0)
|
||||||
if (self.lockRoll == True):
|
if (self.lockRoll == True):
|
||||||
# flatten roll
|
# flatten roll
|
||||||
base.direct.camera.setR(0)
|
self.camera.setR(0)
|
||||||
|
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
def HPPanTask(self, state):
|
def HPPanTask(self, state):
|
||||||
base.direct.camera.setHpr(base.direct.camera,
|
self.camera.setHpr(self.camera,
|
||||||
(0.5 * base.direct.dr.mouseDeltaX *
|
(0.5 * base.direct.dr.mouseDeltaX *
|
||||||
base.direct.dr.fovH),
|
base.direct.dr.fovH),
|
||||||
(-0.5 * base.direct.dr.mouseDeltaY *
|
(-0.5 * base.direct.dr.mouseDeltaY *
|
||||||
@ -294,7 +301,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Set at markers position in render coordinates
|
# Set at markers position in render coordinates
|
||||||
self.camManipRef.setPos(self.coaMarkerPos)
|
self.camManipRef.setPos(self.coaMarkerPos)
|
||||||
self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
||||||
t = Task.Task(self.mouseRotateTask)
|
t = Task.Task(self.mouseRotateTask)
|
||||||
if abs(base.direct.dr.mouseX) > 0.9:
|
if abs(base.direct.dr.mouseX) > 0.9:
|
||||||
t.constrainedDir = 'y'
|
t.constrainedDir = 'y'
|
||||||
@ -304,8 +311,9 @@ 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(self.camera.node(), "getLens") and
|
||||||
base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
self.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
||||||
|
print "orthogonal don't rotate"
|
||||||
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)):
|
||||||
@ -318,17 +326,17 @@ class DirectCameraControl(DirectObject):
|
|||||||
deltaX = base.direct.dr.mouseDeltaX
|
deltaX = base.direct.dr.mouseDeltaX
|
||||||
deltaY = base.direct.dr.mouseDeltaY
|
deltaY = base.direct.dr.mouseDeltaY
|
||||||
if base.direct.fShift:
|
if base.direct.fShift:
|
||||||
base.direct.camera.setHpr(base.direct.camera,
|
self.camera.setHpr(self.camera,
|
||||||
(deltaX * base.direct.dr.fovH),
|
(deltaX * base.direct.dr.fovH),
|
||||||
(-deltaY * base.direct.dr.fovV),
|
(-deltaY * base.direct.dr.fovV),
|
||||||
0.0)
|
0.0)
|
||||||
if (self.lockRoll == True):
|
if (self.lockRoll == True):
|
||||||
# flatten roll
|
# flatten roll
|
||||||
base.direct.camera.setR(0)
|
self.camera.setR(0)
|
||||||
self.camManipRef.setPos(self.coaMarkerPos)
|
self.camManipRef.setPos(self.coaMarkerPos)
|
||||||
self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
||||||
else:
|
else:
|
||||||
wrt = base.direct.camera.getTransform(self.camManipRef)
|
wrt = self.camera.getTransform(self.camManipRef)
|
||||||
self.camManipRef.setHpr(self.camManipRef,
|
self.camManipRef.setHpr(self.camManipRef,
|
||||||
(-1 * deltaX * 180.0),
|
(-1 * deltaX * 180.0),
|
||||||
(deltaY * 180.0),
|
(deltaY * 180.0),
|
||||||
@ -336,7 +344,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
if (self.lockRoll == True):
|
if (self.lockRoll == True):
|
||||||
# flatten roll
|
# flatten roll
|
||||||
self.camManipRef.setR(0)
|
self.camManipRef.setR(0)
|
||||||
base.direct.camera.setTransform(self.camManipRef, wrt)
|
self.camera.setTransform(self.camManipRef, wrt)
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
def spawnMouseRollTask(self):
|
def spawnMouseRollTask(self):
|
||||||
@ -344,12 +352,12 @@ class DirectCameraControl(DirectObject):
|
|||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Set at markers position in render coordinates
|
# Set at markers position in render coordinates
|
||||||
self.camManipRef.setPos(self.coaMarkerPos)
|
self.camManipRef.setPos(self.coaMarkerPos)
|
||||||
self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
||||||
t = Task.Task(self.mouseRollTask)
|
t = Task.Task(self.mouseRollTask)
|
||||||
t.coaCenter = getScreenXY(self.coaMarker)
|
t.coaCenter = getScreenXY(self.coaMarker)
|
||||||
t.lastAngle = getCrankAngle(t.coaCenter)
|
t.lastAngle = getCrankAngle(t.coaCenter)
|
||||||
# Store the camera/manipRef offset transform
|
# Store the camera/manipRef offset transform
|
||||||
t.wrt = base.direct.camera.getTransform(self.camManipRef)
|
t.wrt = self.camera.getTransform(self.camManipRef)
|
||||||
taskMgr.add(t, 'manipulateCamera')
|
taskMgr.add(t, 'manipulateCamera')
|
||||||
|
|
||||||
def mouseRollTask(self, state):
|
def mouseRollTask(self, state):
|
||||||
@ -361,7 +369,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
if (self.lockRoll == True):
|
if (self.lockRoll == True):
|
||||||
# flatten roll
|
# flatten roll
|
||||||
self.camManipRef.setR(0)
|
self.camManipRef.setR(0)
|
||||||
base.direct.camera.setTransform(self.camManipRef, wrt)
|
self.camera.setTransform(self.camManipRef, wrt)
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
def lockCOA(self):
|
def lockCOA(self):
|
||||||
@ -387,7 +395,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
self.cqEntries = self.cqEntries[1:] + self.cqEntries[:1]
|
self.cqEntries = self.cqEntries[1:] + self.cqEntries[:1]
|
||||||
# Filter out object's under camera
|
# Filter out object's under camera
|
||||||
nodePath = entry.getIntoNodePath()
|
nodePath = entry.getIntoNodePath()
|
||||||
if base.direct.camera not in nodePath.getAncestors():
|
if self.camera not in nodePath.getAncestors():
|
||||||
# Compute new hit point
|
# Compute new hit point
|
||||||
hitPt = entry.getSurfacePoint(entry.getFromNodePath())
|
hitPt = entry.getSurfacePoint(entry.getFromNodePath())
|
||||||
# Move coa marker to new point
|
# Move coa marker to new point
|
||||||
@ -403,7 +411,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
if self.fLockCOA:
|
if self.fLockCOA:
|
||||||
# COA is locked, use existing point
|
# COA is locked, use existing point
|
||||||
# Use existing point
|
# Use existing point
|
||||||
coa.assign(self.coaMarker.getPos(base.direct.camera))
|
coa.assign(self.coaMarker.getPos(self.camera))
|
||||||
# Reset hit point count
|
# Reset hit point count
|
||||||
self.nullHitPointCount = 0
|
self.nullHitPointCount = 0
|
||||||
elif entry:
|
elif entry:
|
||||||
@ -416,7 +424,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
if ((hitPtDist < (1.1 * dr.near)) or
|
if ((hitPtDist < (1.1 * dr.near)) or
|
||||||
(hitPtDist > dr.far)):
|
(hitPtDist > dr.far)):
|
||||||
# Just use existing point
|
# Just use existing point
|
||||||
coa.assign(self.coaMarker.getPos(base.direct.camera))
|
coa.assign(self.coaMarker.getPos(self.camera))
|
||||||
# Reset hit point count
|
# Reset hit point count
|
||||||
self.nullHitPointCount = 0
|
self.nullHitPointCount = 0
|
||||||
else:
|
else:
|
||||||
@ -461,7 +469,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
def updateCoaMarkerSize(self, coaDist = None):
|
def updateCoaMarkerSize(self, coaDist = None):
|
||||||
if not coaDist:
|
if not coaDist:
|
||||||
coaDist = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
coaDist = Vec3(self.coaMarker.getPos(self.camera)).length()
|
||||||
# Nominal size based on default 30 degree vertical FOV
|
# Nominal size based on default 30 degree vertical FOV
|
||||||
# Need to adjust size based on distance and current FOV
|
# Need to adjust size based on distance and current FOV
|
||||||
sf = COA_MARKER_SF * coaDist * (base.direct.drList.getCurrentDr().fovV/30.0)
|
sf = COA_MARKER_SF * coaDist * (base.direct.drList.getCurrentDr().fovV/30.0)
|
||||||
@ -482,19 +490,19 @@ class DirectCameraControl(DirectObject):
|
|||||||
|
|
||||||
def homeCam(self):
|
def homeCam(self):
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
base.direct.camera.reparentTo(render)
|
self.camera.reparentTo(render)
|
||||||
base.direct.camera.clearMat()
|
self.camera.clearMat()
|
||||||
# Resize coa marker
|
# Resize coa marker
|
||||||
self.updateCoaMarkerSize()
|
self.updateCoaMarkerSize()
|
||||||
|
|
||||||
def uprightCam(self):
|
def uprightCam(self):
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
# Pitch camera till upright
|
# Pitch camera till upright
|
||||||
currH = base.direct.camera.getH()
|
currH = self.camera.getH()
|
||||||
base.direct.camera.lerpHpr(currH, 0, 0,
|
self.camera.lerpHpr(currH, 0, 0,
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
other = render,
|
other = render,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
@ -503,10 +511,10 @@ class DirectCameraControl(DirectObject):
|
|||||||
def orbitUprightCam(self):
|
def orbitUprightCam(self):
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
# Transform camera z axis to render space
|
# Transform camera z axis to render space
|
||||||
mCam2Render = Mat4(Mat4.identMat()) # [gjeon] fixed to give required argument
|
mCam2Render = Mat4(Mat4.identMat()) # [gjeon] fixed to give required argument
|
||||||
mCam2Render.assign(base.direct.camera.getMat(render))
|
mCam2Render.assign(self.camera.getMat(render))
|
||||||
zAxis = Vec3(mCam2Render.xformVec(Z_AXIS))
|
zAxis = Vec3(mCam2Render.xformVec(Z_AXIS))
|
||||||
zAxis.normalize()
|
zAxis.normalize()
|
||||||
# Compute rotation angle needed to upright cam
|
# Compute rotation angle needed to upright cam
|
||||||
@ -527,8 +535,8 @@ class DirectCameraControl(DirectObject):
|
|||||||
self.camManipRef.setPos(self.coaMarker, Vec3(0))
|
self.camManipRef.setPos(self.coaMarker, Vec3(0))
|
||||||
self.camManipRef.setHpr(render, rotAngle, 0, 0)
|
self.camManipRef.setHpr(render, rotAngle, 0, 0)
|
||||||
# Reparent Cam to ref Coordinate system
|
# Reparent Cam to ref Coordinate system
|
||||||
parent = base.direct.camera.getParent()
|
parent = self.camera.getParent()
|
||||||
base.direct.camera.wrtReparentTo(self.camManipRef)
|
self.camera.wrtReparentTo(self.camManipRef)
|
||||||
# Rotate ref CS to final orientation
|
# Rotate ref CS to final orientation
|
||||||
t = self.camManipRef.lerpHpr(rotAngle, orbitAngle, 0,
|
t = self.camManipRef.lerpHpr(rotAngle, orbitAngle, 0,
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
@ -548,14 +556,14 @@ class DirectCameraControl(DirectObject):
|
|||||||
def centerCamIn(self, t):
|
def centerCamIn(self, t):
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
# Determine marker location
|
# Determine marker location
|
||||||
markerToCam = self.coaMarker.getPos(base.direct.camera)
|
markerToCam = self.coaMarker.getPos(self.camera)
|
||||||
dist = Vec3(markerToCam - ZERO_POINT).length()
|
dist = Vec3(markerToCam - ZERO_POINT).length()
|
||||||
scaledCenterVec = Y_AXIS * dist
|
scaledCenterVec = Y_AXIS * dist
|
||||||
delta = markerToCam - scaledCenterVec
|
delta = markerToCam - scaledCenterVec
|
||||||
self.camManipRef.setPosHpr(base.direct.camera, Point3(0), Point3(0))
|
self.camManipRef.setPosHpr(self.camera, Point3(0), Point3(0))
|
||||||
t = base.direct.camera.lerpPos(Point3(delta),
|
t = self.camera.lerpPos(Point3(delta),
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
other = self.camManipRef,
|
other = self.camManipRef,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
@ -565,14 +573,14 @@ class DirectCameraControl(DirectObject):
|
|||||||
def zoomCam(self, zoomFactor, t):
|
def zoomCam(self, zoomFactor, t):
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
# Find a point zoom factor times the current separation
|
# Find a point zoom factor times the current separation
|
||||||
# of the widget and cam
|
# of the widget and cam
|
||||||
zoomPtToCam = self.coaMarker.getPos(base.direct.camera) * zoomFactor
|
zoomPtToCam = self.coaMarker.getPos(self.camera) * zoomFactor
|
||||||
# Put a target nodePath there
|
# Put a target nodePath there
|
||||||
self.camManipRef.setPos(base.direct.camera, zoomPtToCam)
|
self.camManipRef.setPos(self.camera, zoomPtToCam)
|
||||||
# Move to that point
|
# Move to that point
|
||||||
t = base.direct.camera.lerpPos(ZERO_POINT,
|
t = self.camera.lerpPos(ZERO_POINT,
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
other = self.camManipRef,
|
other = self.camManipRef,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
@ -583,7 +591,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
# Kill any existing tasks
|
# Kill any existing tasks
|
||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
# Calc hprOffset
|
# Calc hprOffset
|
||||||
hprOffset = VBase3()
|
hprOffset = VBase3()
|
||||||
if view == 8:
|
if view == 8:
|
||||||
@ -612,7 +620,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
self.camManipRef.setPosHpr(self.coaMarker, ZERO_VEC,
|
self.camManipRef.setPosHpr(self.coaMarker, ZERO_VEC,
|
||||||
hprOffset)
|
hprOffset)
|
||||||
# Scale center vec by current distance to target
|
# Scale center vec by current distance to target
|
||||||
offsetDistance = Vec3(base.direct.camera.getPos(self.camManipRef) -
|
offsetDistance = Vec3(self.camera.getPos(self.camManipRef) -
|
||||||
ZERO_POINT).length()
|
ZERO_POINT).length()
|
||||||
scaledCenterVec = Y_AXIS * (-1.0 * offsetDistance)
|
scaledCenterVec = Y_AXIS * (-1.0 * offsetDistance)
|
||||||
# Now put the camManipRef at that point
|
# Now put the camManipRef at that point
|
||||||
@ -621,7 +629,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
ZERO_VEC)
|
ZERO_VEC)
|
||||||
# Record view for next time around
|
# Record view for next time around
|
||||||
self.lastView = view
|
self.lastView = view
|
||||||
t = base.direct.camera.lerpPosHpr(ZERO_POINT,
|
t = self.camera.lerpPosHpr(ZERO_POINT,
|
||||||
VBase3(0, 0, self.orthoViewRoll),
|
VBase3(0, 0, self.orthoViewRoll),
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
other = self.camManipRef,
|
other = self.camManipRef,
|
||||||
@ -635,15 +643,15 @@ class DirectCameraControl(DirectObject):
|
|||||||
taskMgr.remove('manipulateCamera')
|
taskMgr.remove('manipulateCamera')
|
||||||
|
|
||||||
# Record undo point
|
# Record undo point
|
||||||
base.direct.pushUndo([base.direct.camera])
|
base.direct.pushUndo([self.camera])
|
||||||
|
|
||||||
# Coincident with widget
|
# Coincident with widget
|
||||||
self.camManipRef.setPos(self.coaMarker, ZERO_POINT)
|
self.camManipRef.setPos(self.coaMarker, ZERO_POINT)
|
||||||
# But aligned with render space
|
# But aligned with render space
|
||||||
self.camManipRef.setHpr(ZERO_POINT)
|
self.camManipRef.setHpr(ZERO_POINT)
|
||||||
|
|
||||||
parent = base.direct.camera.getParent()
|
parent = self.camera.getParent()
|
||||||
base.direct.camera.wrtReparentTo(self.camManipRef)
|
self.camera.wrtReparentTo(self.camManipRef)
|
||||||
|
|
||||||
manipTask = self.camManipRef.lerpHpr(VBase3(degrees, 0, 0),
|
manipTask = self.camManipRef.lerpHpr(VBase3(degrees, 0, 0),
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
@ -654,7 +662,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
manipTask.setUponDeath(self.reparentCam)
|
manipTask.setUponDeath(self.reparentCam)
|
||||||
|
|
||||||
def reparentCam(self, state):
|
def reparentCam(self, state):
|
||||||
base.direct.camera.wrtReparentTo(state.parent)
|
self.camera.wrtReparentTo(state.parent)
|
||||||
self.updateCoaMarkerSize()
|
self.updateCoaMarkerSize()
|
||||||
|
|
||||||
def fitOnWidget(self, nodePath = 'None Given'):
|
def fitOnWidget(self, nodePath = 'None Given'):
|
||||||
@ -674,20 +682,20 @@ class DirectCameraControl(DirectObject):
|
|||||||
centerVec = Y_AXIS * camY
|
centerVec = Y_AXIS * camY
|
||||||
|
|
||||||
# Where is the node relative to the viewpoint
|
# Where is the node relative to the viewpoint
|
||||||
vWidget2Camera = base.direct.widget.getPos(base.direct.camera)
|
vWidget2Camera = base.direct.widget.getPos(self.camera)
|
||||||
|
|
||||||
# How far do you move the camera to be this distance from the node?
|
# How far do you move the camera to be this distance from the node?
|
||||||
deltaMove = vWidget2Camera - centerVec
|
deltaMove = vWidget2Camera - centerVec
|
||||||
|
|
||||||
# Move a target there
|
# Move a target there
|
||||||
try:
|
try:
|
||||||
self.camManipRef.setPos(base.direct.camera, deltaMove)
|
self.camManipRef.setPos(self.camera, deltaMove)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.notify.debug
|
self.notify.debug
|
||||||
|
|
||||||
parent = base.direct.camera.getParent()
|
parent = self.camera.getParent()
|
||||||
base.direct.camera.wrtReparentTo(self.camManipRef)
|
self.camera.wrtReparentTo(self.camManipRef)
|
||||||
fitTask = base.direct.camera.lerpPos(Point3(0, 0, 0),
|
fitTask = self.camera.lerpPos(Point3(0, 0, 0),
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
task = 'manipulateCamera')
|
task = 'manipulateCamera')
|
||||||
@ -717,7 +725,7 @@ class DirectCameraControl(DirectObject):
|
|||||||
# Spawn a task to move the widget
|
# Spawn a task to move the widget
|
||||||
t = base.direct.widget.lerpPos(Point3(centerVec),
|
t = base.direct.widget.lerpPos(Point3(centerVec),
|
||||||
CAM_MOVE_DURATION,
|
CAM_MOVE_DURATION,
|
||||||
other = base.direct.camera,
|
other = self.camera,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
task = 'moveToFitTask')
|
task = 'moveToFitTask')
|
||||||
t.setUponDeath(lambda state: taskMgr.remove('stickToWidget'))
|
t.setUponDeath(lambda state: taskMgr.remove('stickToWidget'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user