_Clipper

裁剪面。此裁剪面为一个垂直于z轴的平面。 全部展开

构造方法展开

  • + function _Clipper() : _Clipper

公共方法展开

  • + function clipPlane(pos : _Vector3, dir : _Vector3)

    裁剪面。

    • 参数
    • pos:裁剪面的位置。
    • dir: 裁剪面方向

    • 示例

       pos = _Vector3.new(0, 0, 0)
      dir = _Vector3.new(0, 1, 0)
      clipper:clipPlane(pos, dir)
  • + function clipZNegative(clipz : number)

    裁剪面之下的物体被裁剪掉。

    • 参数
    • clipz:裁剪面的z坐标。
    • 示例

       clipper:clipZNegative(100)
  • + function clipZPositive(clipz : number)

    裁剪面之上的物体被裁剪掉。

    • 参数
    • clipz:裁剪面的z坐标。
    • 示例

       clipper:clipZPositive(100)
  • + function fadeZ(z1 : number, z2 : number, color : uint)

    从裁剪面开始渐入。

    • 参数
    • z1:开始渐入的平面z坐标。
    • z2:完全进入的平面z坐标。
    • color:渐入的颜色值。
      • 示例
    •  _dofile('cameracontrol.lua')
      _rd.camera.eye = _Vector3.new(30, 30, 30)
      _rd:useLight(_AmbientLight.new())
      _rd:useLight(_SkyLight.new())

      teapot = _mf:createTeapot()
      teapot.transform:setScaling(10, 10, 10)
      clicolor = _Color.DarkBlue
      clipper = _Clipper.new():fadeZ(0, 1, clicolor)
      _rd.bgColor = clicolor

      font = _Font.new('Arial', 10)
      font.textColor = _Color.Yellow

      z1 = -4
      z2 = 5

      _app:onKeyDown(function(key)
      if key == _System.KeyW then
      if z1 < 10 then
      z1 = z1 + 2
      clipper:fadeZ(z1, z2, clicolor)
      end
      elseif key == _System.KeyS then
      if z1 > -10 then
      z1 = z12
      clipper:fadeZ(z1, z2, clicolor)
      end
      elseif key == _System.KeyE then
      if z2 < 9 then
      z2 = z2 + 2
      clipper:fadeZ(z1, z2, clicolor)
      end
      elseif key == _System.KeyD then
      if z2 > -9 then
      z2 = z22
      clipper:fadeZ(z1, z2, clicolor)
      end
      end
      end)

      _app:onIdle(function(e)
      font:drawText(0, 0, 'Press WS to adjust fade begin')
      font:drawText(0, 14, 'Press ED to adjust fade end')
      _rd:useClipper(clipper)
      teapot:drawMesh()
      _rd:popClipper()
      end)

代码示例

    _dofile('cameracontrol.lua')

    clipz = 0
    pos = 1

    teapot, plane = _mf:createTeapot(), _mf:createPlane()
    plane.transform:setScaling(50, 50, 50)
    teapot.transform:setScaling(5, 5, 5)

    _rd.camera.eye = _Vector3.new(25, 25, 25)
    _rd:useLight(_AmbientLight.new())
    _rd:useLight(_SkyLight.new())
    mat = _Matrix3D.new()

    clipper = _Clipper.new():clipZNegative(0)

    font = _Font.new('Arial', 10)
    font.textColor = _Color.Yellow

    function newclipper()
        mat:setTranslation(0, 0, clipz)
        if pos == 0 then
            clipper:clipZPositive(clipz)
        else
            clipper:clipZNegative(clipz)
        end
    end

    _app:onKeyDown(function(key)
        if key == _System.KeyW then
            if clipz < 4 then
                clipz = clipz + 1
                newclipper()
            end
        elseif key == _System.KeyS then
            if clipz > -5 then
                clipz = clipz - 1
                newclipper()
            end
        elseif key == _System.Key1 then
            if pos == 0 then
                pos = 1
            elseif pos == 1 then
                pos = 0
            end
            newclipper()
        end
    end)

    _app:onIdle(function(e)
        font:drawText(0, 0, 'Press 1 to Switch Positive or Negative')
        font:drawText(0, 14, 'Press w to up')
        font:drawText(0, 28, 'Press s to down')

        _rd.wireframe = true
        _rd:pushMatrix3D(mat)
            plane:drawMesh()
        _rd:popMatrix3D()
        _rd.wireframe = false

        _rd:useClipper(clipper)
            teapot:drawMesh()
        _rd:popClipper()
    end)
问题反馈(登录才可以发表哦!)