_Orbit

轨迹模块,表示若干点组成的一条轨迹,提供方法获得轨迹上的任意点。 全部展开

属性展开

  • + backward : bool

    轨迹是否反向,默认值为false。

    示例

        orb.backward = true
  • + cubicSpline : bool

    是否使用曲线插值来计算轨迹上的点,默认值为true。

    示例

        orb.cubicSpline = true
  • + current : uint

    轨迹的当前时间,单位毫秒。

    示例

        orb.current = 1500
  • + finish : uint

    轨迹的结束时间,单位毫秒。

    示例

        orb.finish = 5000
  • + name : string

    轨迹的名称。

    示例

        orb.name = 'This is a orbit.'
  • + start : uint

    轨迹的开始时间,单位毫秒。

    示例

        orb.start = 1000

只读属性展开

  • + isFinished : bool
    over : bool

    判断当前轨迹是否运行结束,current == finish;或者对于backward的轨迹,current == start。

    示例

        print(orb.isFinished)
  • + points : array

    得到轨迹的顶点数组,每个元素是一个_Vector3,表示轨迹上的一个关键点。

    示例

        print(#orb.points)
  • + pos : _Vector3

    轨迹的当前位置,由当前时间插值得到。

    示例

        print(orb.pos.x, orb.pos.y, orb.pos.z)

构造方法展开

  • + function _Orbit() : _Orbit

    构造一个轨迹。

    • 返回
    • 新构造的轨迹,没有任何关键点,name默认值为空字符串。
      • 示例
    •  orb = _Orbit.new()
  • + function _Orbit(orb : _Orbit) : _Orbit

    从源轨迹构造一个轨迹。

    • 参数
    • orb : 源轨迹。
    • 返回
    • 新构造的轨迹,所有属性和源轨迹相同。
      • 示例
    •  orb = _Orbit.new(srcorb)
  • + function _Orbit(points : array) : _Orbit

    从数组创建轨迹。

    示例

        orb = _Orbit.new(pt)
    等价于
    orb = _Orbit.new()
    orb:create(pt)

公共方法展开

  • + function clear()

    清空轨迹上的关键点。

    示例

        orb:clear()
  • + function create(points : array)

    从数组创建轨迹。

    • 参数
    • points : 用于创建轨迹的数组,每个元素由time和pos组成,其中time表示毫秒为单位的关键点时间,pos为_Vector3表示的关键点。
      • 示例
    •  local pt = {}
      pt[1] = {time = 100, pos = _Vector3.new(10, 10, 0)}
      pt[2] = {time = 200, pos = _Vector3.new(20, 20, 0)}
      pt[3] = {time = 200, pos = _Vector3.new(20, 20, 0)}
      orb:create(pt)
  • + function draw(color:uint)

    绘制轨迹。

    • 参数
    • color : 绘制轨迹所使用的颜色。
      • 示例
    •   orb:draw(_Color.Green)
  • + function getKeyframes() : array

    得到轨迹上的关键点数值。

    • 返回
    • 关键点数组,每个关键点由time和pos组成,time类型为uint,表示毫秒为单位的关键点时间;pos为_Vector3表示的关键点。
      • 示例
    •  frames = orb:getKeyframes()
      print(frames[1].time, frames[1].pos.x, frames[1].pos.y, frames[1].pos.z)
  • + function reset()

    重置运动轨迹。

    示例

        orb:reset()
  • + function update(elapse: uint)

    更新轨迹,current和pos属性会随之变化。

    • 参数
    • elapse : 时间间隔,单位为毫秒。
    • 说明
    • current会增加elapse毫秒直到finish为止,或者对于backward的轨迹,减少elapse毫秒直到start为止。pos会变为current所对应的顶点坐标,由前后关键点插值得到。
      • 示例
    •  orb:update(10)

代码示例

    o  = _Orbit.new()

    pt = {}
    pt[1] = {time = 0 ,pos = _Vector3.new(0, 0, 0)}
    pt[2] = {time = 1000 ,pos = _Vector3.new(50, 30, 20)}
    pt[3] = {time = 2000 ,pos = _Vector3.new(-15, -15, 0)}
    o:create(pt)
    temp = false

    msh = _mf:createCube()
    mat = _Matrix3D.new()
    pos1 = msh.transform:getTranslation();

    function render(e)
    _rd:drawAxis(100)
    msh.transform:setTranslation(pos1.x,pos1.y,o.pos.z)
    msh:drawMesh()     
    if temp == true then
    o:update(e)
    end
    if temp38 == true then
    msh.transform:mulTranslationRight(0.01, 0, 0);
    elseif temp40 == true then
    msh.transform:mulTranslationRight(- 0.01, 0, 0);
    elseif temp37 == true then
    msh.transform:mulTranslationRight(0, 0.01, 0);
    elseif temp39 == true then
    msh.transform:mulTranslationRight(0, - 0.01, 0);
    end
    if o.over == true then
    o:create(pt)
    temp = false
    end
    pos1 = msh.transform:getTranslation();
    end

    _app:onIdle(render)

    function keyDown(x)
    if x == _System.KeySpace then
    temp=true
    elseif x == _System.KeyUp then
    temp38 = true;
    elseif x == _System.KeyDown then
    temp40 = true;
    elseif x == _System.KeyLeft then
    temp37 = true;
    elseif x == _System.KeyRight then
    temp39=true;
    end    
    end

    _app:onKeyDown(keyDown)

    function keyUp(x)
    if x == _System.KeyUp then
    temp38 = false
    elseif x == _System.KeyDown then
    temp40 = false
    elseif x == _System.KeyLeft then
    temp37 = false
    elseif x == _System.KeyRight then
    temp39 = false
    end
    end
    _app:onKeyUp(keyUp)
问题反馈(登录才可以发表哦!)