猫史档案馆


【神奇代码岛】动作模拟器文档V3

用户:迷失冷光迷失冷光查看:2 回复:12 评论:2 创建时间:2021-12-25T10:40:48


const Quat = new Box3Quaternion(0,0,0,1);
const host = [];
class Joint{
    constructor(lookable,model,position = null,children = [],property = {angle: 0,up: 0,radius: 1}){
        host.push(Object.assign(this,{
            lookable,
            model,
            position,
            children,
            property,
            angle: 0,
            up: 0,
        }));
    };
    addChildren(...joints){
        this.children.push(...joints);
    };
    removeChild(joint){
        this.children.splice(this.children.indexOf(joint));
    };
    changeChild(joint,target){
        this.children.splice(this.children.indexOf(joint));
        target.children.push(joint);
    };
    destroy(){
        if(host.includes(this)){
            host.splice(host.indexOf(this),1);
            return true;
        }else return false;
    };
}
global.Joint = Joint;
world.onTick(()=>{
    for(const e of host){
        single(e);
    }
})
function single(joint,parent = null){
    if(parent){
        //角度传承上一级
        joint.angle = joint.property.angle + parent.angle;
        joint.up = joint.property.up + parent.up;
        //设置位置
        joint.position = point_in_ball(parent.position,joint.angle,joint.up,joint.property.radius);
        if(joint.lookable){
            joint.model.position.copy(joint.position);
        }
    }
    if(joint.lookable){
        //设置旋转
        joint.meshOrientation = Quat.rotateX(joint.up).rotateY(joint.angle);
    }
    //下一级旋转
    for(const e of joint.children){
        single(e,joint);
    }
}
function point_in_ball(origin,angle,up,radius){
    return new Box3Vector3(
        origin.x + Math.cos(angle) * Math.cos(up) * radius,
        origin.y + Math.sin(up) * radius,
        origin.z + Math.sin(angle) * Math.cos(up) * radius
    )
}

本次更新修复了一些bug以及旋转参数无法隔代遗传的bug


回复

上一页1 页 / 共 1下一页
梦里觅深海梦里觅深海

沙发

点赞0


评论


星星上的雪花星星上的雪花

那个host里面要放的是些什么呢?

点赞0


评论


持剑人持剑人

报错()()

点赞0


评论


银狐残影银狐残影

求哥斯拉皮肤代码

点赞0


评论


BOTPLAYBOTPLAY

怎么用

效果是怎么样的

点赞0


评论


被遗忘的屑被遗忘的屑

挖老帖

点赞0


评论


未名用户未名用户

👀👀👀

点赞0


评论


guxia666guxia666

这个怎么用

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

挖~

点赞0


评论


egg鸡蛋蛋egg鸡蛋蛋

收藏

点赞0


评论


SCS_user_Avgdttb9eiSCS_user_Avgdttb9ei

。。。不行了,我落伍了。。这东西咋用。。?

点赞0


评论


全能代码师全能代码师

不错不错。来我收藏夹吃灰罢(喜)

点赞0


评论