当前位置: 首页>>代码示例>>Python>>正文


Python Fog.getExpDensity方法代码示例

本文整理汇总了Python中panda3d.core.Fog.getExpDensity方法的典型用法代码示例。如果您正苦于以下问题:Python Fog.getExpDensity方法的具体用法?Python Fog.getExpDensity怎么用?Python Fog.getExpDensity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.Fog的用法示例。


在下文中一共展示了Fog.getExpDensity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FogDemo

# 需要导入模块: from panda3d.core import Fog [as 别名]
# 或者: from panda3d.core.Fog import getExpDensity [as 别名]
class FogDemo(ShowBase):

    # Macro-like function used to reduce the amount to code needed to create the
    # on screen instructions
    def genLabelText(self, i, text):
        return OnscreenText(text=text, parent=base.a2dTopLeft, scale=.05,
                            pos=(0.06, -.065 * i), fg=(1, 1, 1, 1),
                            align=TextNode.ALeft)

    def __init__(self):
        # Initialize the ShowBase class from which we inherit, which will
        # create a window and set up everything we need for rendering into it.
        ShowBase.__init__(self)

        # Standard initialization stuff
        # Standard title that's on screen in every tutorial
        self.title = OnscreenText(text="Panda3D: Tutorial - Fog", style=1,
            fg=(1, 1, 1, 1), shadow=(0, 0, 0, .5), parent=base.a2dBottomRight,
            align=TextNode.ARight, pos=(-0.1, 0.1), scale=.08)

        # Code to generate the on screen instructions
        self.escapeEventText = self.genLabelText(1, "ESC: Quit")
        self.pkeyEventText = self.genLabelText(2, "[P]: Pause")
        self.tkeyEventText = self.genLabelText(3, "[T]: Toggle Fog")
        self.dkeyEventText = self.genLabelText(4, "[D]: Make fog color black")
        self.sdkeyEventText = self.genLabelText(5, "[SHIFT+D]: Make background color black")
        self.rkeyEventText = self.genLabelText(6, "[R]: Make fog color red")
        self.srkeyEventText = self.genLabelText(7, "[SHIFT+R]: Make background color red")
        self.bkeyEventText = self.genLabelText(8, "[B]: Make fog color blue")
        self.sbkeyEventText = self.genLabelText(9, "[SHIFT+B]: Make background color blue")
        self.gkeyEventText = self.genLabelText(10, "[G]: Make fog color green")
        self.sgkeyEventText = self.genLabelText(11, "[SHIFT+G]: Make background color green")
        self.lkeyEventText = self.genLabelText(12, "[L]: Make fog color light grey")
        self.slkeyEventText = self.genLabelText(13, "[SHIFT+L]: Make background color light grey")
        self.pluskeyEventText = self.genLabelText(14, "[+]: Increase fog density")
        self.minuskeyEventText = self.genLabelText(15, "[-]: Decrease fog density")

        # disable mouse control so that we can place the camera
        base.disableMouse()
        camera.setPosHpr(0, 0, 10, 0, -90, 0)
        base.setBackgroundColor(0, 0, 0)  # set the background color to black

        # World specific-code

        # Create an instance of fog called 'distanceFog'.
        #'distanceFog' is just a name for our fog, not a specific type of fog.
        self.fog = Fog('distanceFog')
        # Set the initial color of our fog to black.
        self.fog.setColor(0, 0, 0)
        # Set the density/falloff of the fog.  The range is 0-1.
        # The higher the numer, the "bigger" the fog effect.
        self.fog.setExpDensity(.08)
        # We will set fog on render which means that everything in our scene will
        # be affected by fog. Alternatively, you could only set fog on a specific
        # object/node and only it and the nodes below it would be affected by
        # the fog.
        render.setFog(self.fog)

        # Define the keyboard input
        # Escape closes the demo
        self.accept('escape', sys.exit)
        # Handle pausing the tunnel
        self.accept('p', self.handlePause)
        # Handle turning the fog on and off
        self.accept('t', toggleFog, [render, self.fog])
        # Sets keys to set the fog to various colors
        self.accept('r', self.fog.setColor, [1, 0, 0])
        self.accept('g', self.fog.setColor, [0, 1, 0])
        self.accept('b', self.fog.setColor, [0, 0, 1])
        self.accept('l', self.fog.setColor, [.7, .7, .7])
        self.accept('d', self.fog.setColor, [0, 0, 0])
        # Sets keys to change the background colors
        self.accept('shift-r', base.setBackgroundColor, [1, 0, 0])
        self.accept('shift-g', base.setBackgroundColor, [0, 1, 0])
        self.accept('shift-b', base.setBackgroundColor, [0, 0, 1])
        self.accept('shift-l', base.setBackgroundColor, [.7, .7, .7])
        self.accept('shift-d', base.setBackgroundColor, [0, 0, 0])
        # Increases the fog density when "+" key is pressed
        self.accept('+', self.addFogDensity, [.01])
        # This is to handle the other "+" key (it's over = on the keyboard)
        self.accept('=', self.addFogDensity, [.01])
        self.accept('shift-=', self.addFogDensity, [.01])
        # Decreases the fog density when the "-" key is pressed
        self.accept('-', self.addFogDensity, [-.01])

        # Load the tunel and start the tunnel
        self.initTunnel()
        self.contTunnel()

    # This function will change the fog density by the amount passed into it
    # This function is needed so that it can look up the current value and
    # change it when the key is pressed. If you wanted to bind a key to set it
    # at a given value you could call self.fog.setExpDensity directly
    def addFogDensity(self, change):
        # The min() statement makes sure the density is never over 1
        # The max() statement makes sure the density is never below 0
        self.fog.setExpDensity(
            min(1, max(0, self.fog.getExpDensity() + change)))

    # Code to initialize the tunnel
#.........这里部分代码省略.........
开发者ID:AdrianF98,项目名称:Toontown-2-Revised,代码行数:103,代码来源:main.py


注:本文中的panda3d.core.Fog.getExpDensity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。