mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Added feature to scale widget by distance from the camera
This commit is contained in:
parent
5b19635da9
commit
b0ce0f70a3
@ -38,6 +38,7 @@ class DirectSession(DirectObject):
|
|||||||
self.font = TextNode.getDefaultFont()
|
self.font = TextNode.getDefaultFont()
|
||||||
self.fEnabled = 0
|
self.fEnabled = 0
|
||||||
self.fEnabledLight = 0
|
self.fEnabledLight = 0
|
||||||
|
self.fScaleWidgetByCam = 0 # [gjeon] flag for scaling widget by distance from the camera
|
||||||
self.drList = DisplayRegionList()
|
self.drList = DisplayRegionList()
|
||||||
self.iRayList = map(lambda x: x.iRay, self.drList)
|
self.iRayList = map(lambda x: x.iRay, self.drList)
|
||||||
self.dr = self.drList[0]
|
self.dr = self.drList[0]
|
||||||
@ -198,6 +199,7 @@ class DirectSession(DirectObject):
|
|||||||
self.cluster = DummyClusterClient()
|
self.cluster = DummyClusterClient()
|
||||||
__builtins__['cluster'] = self.cluster
|
__builtins__['cluster'] = self.cluster
|
||||||
|
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
# don't enable DIRECT if someone has posted DIRECTdisablePost
|
# don't enable DIRECT if someone has posted DIRECTdisablePost
|
||||||
if bboard.has(DirectSession.DIRECTdisablePost):
|
if bboard.has(DirectSession.DIRECTdisablePost):
|
||||||
@ -469,6 +471,9 @@ class DirectSession(DirectObject):
|
|||||||
def gotAlt(self, modifiers):
|
def gotAlt(self, modifiers):
|
||||||
return modifiers & DIRECT_ALT_MOD
|
return modifiers & DIRECT_ALT_MOD
|
||||||
|
|
||||||
|
def setFScaleWidgetByCam(self, flag):
|
||||||
|
self.fScaleWidgetByCam = flag
|
||||||
|
|
||||||
def select(self, nodePath, fMultiSelect = 0,
|
def select(self, nodePath, fMultiSelect = 0,
|
||||||
fSelectTag = 1, fResetAncestry = 1):
|
fSelectTag = 1, fResetAncestry = 1):
|
||||||
dnp = self.selected.select(nodePath, fMultiSelect, fSelectTag)
|
dnp = self.selected.select(nodePath, fMultiSelect, fSelectTag)
|
||||||
@ -494,7 +499,14 @@ class DirectSession(DirectObject):
|
|||||||
# Adjust widgets size
|
# Adjust widgets size
|
||||||
# This uses the additional scaling factor used to grow and
|
# This uses the additional scaling factor used to grow and
|
||||||
# shrink the widget
|
# shrink the widget
|
||||||
self.widget.setScalingFactor(dnp.getRadius())
|
if self.fScaleWidgetByCam: # [gjeon] for scaling widget by distance from camera
|
||||||
|
nodeCamDist = Vec3(dnp.getPos(direct.camera)).length()
|
||||||
|
sf = 0.075 * nodeCamDist * math.tan(deg2Rad(direct.drList.getCurrentDr().fovV))
|
||||||
|
sf = max(1.0,sf)
|
||||||
|
self.widget.setScalingFactor(sf)
|
||||||
|
else:
|
||||||
|
self.widget.setScalingFactor(dnp.getRadius())
|
||||||
|
|
||||||
# Spawn task to have object handles follow the selected object
|
# Spawn task to have object handles follow the selected object
|
||||||
taskMgr.remove('followSelectedNodePath')
|
taskMgr.remove('followSelectedNodePath')
|
||||||
t = Task.Task(self.followSelectedNodePathTask)
|
t = Task.Task(self.followSelectedNodePathTask)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user