2021SC@SDUSC ClayGL Camera类分析(四)

2021SC@SDUSC ClayGL Camera类分析(四)
接上文

Members

1.scale

相对于其父节点缩放,初始值为 NULL.
类型:
clay.Vector3(3维向量)

    scale: null,

2.viewMatrix

视图矩阵,等于相机世界矩阵的反函数
类型:
clay.Matrix4(4维矩阵)

        viewMatrix: new Matrix4(),

3.worldTransform

世界仿射变换矩阵相对于其根场景,初始值为NULL。
类型:
clay.Matrix4(4维矩阵)

    worldTransform: null,

Methods

1.add(node)

添加一个子节点

    add: function (node) {
        var originalParent = node._parent;
        if (originalParent === this) {
            return;
        }
        if (originalParent) {
            originalParent.remove(node);
        }
        node._parent = this;
        this._children.push(node);
        var scene = this._scene;
        if (scene && scene !== node.scene) {
            node.traverse(this._addSelfToScene, this);
        }
        // Mark children needs update transform
        // In case child are remove and added again after parent moved
        node._needsUpdateWorldTransform = true;
    },

参数:

NameType
nodeclay.Node

2. after(name, action, contextopt)

on函数的一个别名(‘after’ + name)

    after: function(name, action, context) {
        if (!name || !action) {
            return;
        }
        name = 'after' + name;
        return this.on(name, action, context);
    },

参数:

名称类型属性
namestring
actionfunction
contextObject可选

3.before(name, action, contextopt)

on函数的另一个别名(‘before’ + name)

    before: function(name, action, context) {
        if (!name || !action) {
            return;
        }
        name = 'before' + name;
        return this.on(name, action, context);
    },

参数:

名称类型属性
namestring
actionfunction
contextObject可选

4.castRay(ndc, outopt) → {clay.Ray}

将追踪光线从近平面的相机投射到远平面

参数:

名称类型属性
ndcclay.Vector2
outclay.Ray可选

返回值:clay.Ray

    castRay: (function () {
        var v4 = vec4.create();
        return function (ndc, out) {
            var ray = out !== undefined ? out : new Ray();
            var x = ndc.array[0];
            var y = ndc.array[1];
            vec4.set(v4, x, y, -1, 1);
            vec4.transformMat4(v4, v4, this.invProjectionMatrix.array);
            vec4.transformMat4(v4, v4, this.worldTransform.array);
            vec3.scale(ray.origin.array, v4, 1 / v4[3]);
            vec4.set(v4, x, y, 1, 1);
            vec4.transformMat4(v4, v4, this.invProjectionMatrix.array);
            vec4.transformMat4(v4, v4, this.worldTransform.array);
            vec3.scale(v4, v4, 1 / v4[3]);
            vec3.sub(ray.direction.array, v4, ray.origin.array);
            vec3.normalize(ray.direction.array, ray.direction.array);
            ray.direction._dirty = true;
            ray.origin._dirty = true;
            return ray;
        };
    })(),

5.childAt(idx) → {clay.Node}

获取给定索引处的子场景节点。
参数:

名称类型
idxnumber
outclay.Ray

返回值: clay.Node

    childAt: function (idx) {
        return this._children[idx];
    },

6.children() → {Array.<clay.Node>}

获取包含所有子节点的新创建数组
返回值: clay.Node[]

    children: function () {
        return this._children.slice();
    },

7.clone() → {Node}

克隆新节点
返回值: Node

    clone: function () {
        var node = new this.constructor();
        var children = this._children;
        node.setName(this.name);
        node.position.copy(this.position);
        node.rotation.copy(this.rotation);
        node.scale.copy(this.scale);
        for (var i = 0; i < children.length; i++) {
            node.add(children[i].clone());
        }
        return node;
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值