猫史档案馆


【box3】更简单的旋转

用户:小苏打_小苏打_查看:22 回复:10 评论:22 创建时间:2023-02-04T22:37:30


center_image


回复

上一页1 页 / 共 1下一页
yee剑走天下yee剑走天下

Nb()

点赞0


评论


若潇羽少若潇羽少

wow

点赞0


评论


yee剑走天下yee剑走天下

所以在另外那个脚本需要写什么()我个lj萌新没看懂晕了()

点赞0


评论


小苏打_小苏打_

function dsin(n) {
    return Math.sin(Math.PI * n / 180);
}
function dcos(n) {
    return Math.cos(Math.PI * n / 180);
}
var vector3 = /** @class */ (function () {
    function vector3(x, y, z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    vector3.prototype.add = function (v) {
        return new vector3(this.x + v.x, this.y + v.y, this.z + v.z);
    };
    vector3.prototype.reduce = function (v) {
        return new vector3(this.x - v.x, this.y - v.y, this.z - v.z);
    };
    vector3.prototype.mul = function (n) {
        return new vector3(this.x * n, this.y * n, this.z * n);
    };
    return vector3;
}());
var matrix3 = /** @class */ (function () {
    function matrix3(ihat, jhat, khat) {
        this.ihat = ihat;
        this.jhat = jhat;
        this.khat = khat;
    }
    matrix3.prototype.linearTransformation = function (v) {
        return new vector3(0, 0, 0)
            .add(this.ihat.mul(v.x))
            .add(this.jhat.mul(v.y))
            .add(this.khat.mul(v.z));
    };
    matrix3.prototype.mul = function (m) {
        return new matrix3(m.linearTransformation(this.ihat), m.linearTransformation(this.jhat), m.linearTransformation(this.khat));
    };
    matrix3.prototype.rotate = function (x, y, z) {
        return this
            .mul(new matrix3(new vector3(1, 0, 0), new vector3(0, dcos(x), dsin(x)), new vector3(0, -dsin(x), dcos(x))))
            .mul(new matrix3(new vector3(dcos(y), 0, dsin(y)), new vector3(0, 1, 0), new vector3(-dsin(y), 0, dcos(y))))
            .mul(new matrix3(new vector3(dcos(z), dsin(z), 0), new vector3(-dsin(z), dcos(z), 0), new vector3(0, 0, 1)));
    };
    return matrix3;
}());
var BASE_MATRIX = new matrix3(new vector3(1, 0, 0), new vector3(0, 1, 0), new vector3(0, 0, 1));
let ezRouteEntityTemplate = {
    TEMPLATE_ROATITION: new Box3Quaternion(0, 1, 0, 0),

    /**
     * 设置模型旋转
     * @param x{Number} x轴
     * @param y{Number} y轴
     * @param z{Number} z轴
     */
    setRotation(x, y, z) {
        this.meshOrientation = this.TEMPLATE_ROATITION
            .rotateX(x * Math.PI / 180)
            .rotateY(y * Math.PI / 180)
            .rotateZ(z * Math.PI / 180);
    },
    /**
     * 添加模型旋转
     * @param x{Number} x轴
     * @param y{Number} y轴
     * @param z{Number} z轴
     */
    addRotation(x, y, z) {
        this.meshOrientation = this.meshOrientation
            .rotateX(x * Math.PI / 180)
            .rotateY(y * Math.PI / 180)
            .rotateZ(z * Math.PI / 180);
    },
    /**
     * 带有动画效果的模型旋转
     * @param x{Number} x轴
     * @param y{Number} y轴
     * @param z{Number} z轴
     * @param duringMs{Number} 持续时间
     */
    async showRotation(x, y, z, duringMs, ease=Box3Easing.SINE) {
        return new Promise((reslove, rej)=>{
            let last = this.meshOrientation
                .rotateX(x * Math.PI / 180)
                .rotateY(y * Math.PI / 180)
                .rotateZ(z * Math.PI / 180);
            let animation = this.animate([
                { meshOrientation: last, duration: 1, easeIn:ease},
                { meshOrientation: this.meshOrientation, duration: 0 },
            ]);
            animation.play({
                duration: 16 * duringMs / 1000,
                iterations: 1,
                direction: Box3AnimationDirection.WRAP_REVERSE
            });
            animation.onFinish(() => {
                reslove()
            });
        })
    }
}
/**
 * 为实体添加一些好东西
 */
function bind(entity) {
    Object.assign(entity, ezRouteEntityTemplate);
    
    entity.setRotation(0, 0, 0);
}
/**
 * 旋转建筑 
 * 注意: start的每一项都要比end的**数值小**,并且copyto**不能位于**即将旋转的区域内。造成一切建筑的毁坏作者概不负责。
 * @param start{Box3Vector3} 区域开始
 * @param end{Box3Vector3} 区域结束
 * @param origin{Box3Vector3} 区域原点
 * @param copyto{Box3Vector3} 旋转后的新原点
 * @param x{Number} x轴旋转角
 * @param y{Number} y轴旋转角
 * @param z{Number} z轴旋转角
 */
function rotateConstructor(start, end, origin, copyto, x, y, z){
    let ro = new vector3(origin.x, origin.y, origin.z);
    let rc = new vector3(copyto.x, copyto.y, copyto.z);
    let rm = BASE_MATRIX.rotate(x, y, z);
    for(let x=start.x; x<=end.x; x++){
        for(let y=start.y; y<=end.y; y++){
            for(let z=start.z; z<end.z; z++){
                let tmp = rm.linearTransformation(new vector3(x, y, z).reduce(ro)).add(rc);
                voxels.setVoxelId(tmp.x, tmp.y, tmp.z, voxels.getVoxelId(x, y, z));
            }
        }
    }
}
module.exports = {
    bind,
    rotateConstructor
}

 

点赞1


评论


GZ006GZ006

先来收藏夹吃灰吧

点赞0


评论


小树同学小树同学

万岁!

点赞0


评论


传说之下ULB--sans传说之下ULB--sans

夹吃灰~

点赞0


评论


宽容的彗星猫ybDX宽容的彗星猫ybDX

动画它不香吗

点赞0


评论


仙之鹤仙之鹤

dddd,你怎么不更新()

点赞0


评论


编程小鸡编程小鸡

小苏打,你好呀。我还和你合作过呢?迷宫的程序。

点赞0


评论