猫史档案馆


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

用户:迷失冷光迷失冷光查看:5 回复:8 评论:5 创建时间:2021-12-24T15:57:31


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,
        }));
    };
    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){
    var {angle,up} = joint;
    if(parent){
        //角度传承上一级
        angle += parent.angle;
        up += parent.up;
        //设置位置
        joint.position = point_in_ball(parent.position,angle,up,joint.radius);
        if(joint.lookable){
            joint.model.position.copy(joint.position);
        }
    }
    if(joint.lookable){
        //设置旋转
        joint.meshOrientation = Quat.rotateX(up).rotateY(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
    )
}

更新内容:

模型角度和仰角继承上一关节


回复

上一页1 页 / 共 1下一页
时当日色QWQ时当日色QWQ

沙发

点赞0


评论


时当日色QWQ时当日色QWQ

还有新坑吗

点赞0


评论


AlcalaAlcala

前排

点赞0


评论


星辰_零柒星辰_零柒

床()

点赞0


评论


浮生awa浮生awa

前排

点赞0


评论


风火年华4512风火年华4512

好家伙()

点赞0


评论


难起的名字难起的名字

ohhhhhhhhhhh)

点赞0


评论


YDS尹子YDS尹子

constructor是什么东东。? 是我落后于喵了?

点赞1


评论