微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

空心圆盘的角速度 MatterJS

如何解决空心圆盘的角速度 MatterJS

我想在 MatterJS 中围绕其中心旋转一个空心的圆盘状圆。我使用下面的代码创建了这样一个空心体,基本上组合了无数的矩形。它看起来像这样:

enter image description here

function containerpolygon(
    x,y,sides,radius,color
) {
    const width = 2;
    const extraLength = 1.15;
    const initialRotation = 0;
    const theta = (2 * Math.PI) / sides;
    const sideLength = ((2 * radius * theta) / 2) * extraLength;
    const parts = [];

    for (let i = 0; i < sides; i++) {
        // We'll build thin sides and then translate + rotate them appropriately.
        const body = Bodies.rectangle(0,sideLength,width,{
            render: {
                fillStyle: color,},});
        Body.rotate(body,i * theta);
        Body.translate(body,{
            x: radius * Math.sin(i * theta),y: -radius * Math.cos(i * theta),});
        parts.push(body);
    }

    const ret = Body.create({
        isstatic: true,// frictionAir: 0,friction: 1,// // frictionStatic: 0,// inertia: Infinity,// setting inertia to infinty will prevent rotation upon collision
        rotationSpeed: -2.5,restitution: ball_restitution,});

    Body.setParts(ret,parts);
    Body.translate(ret,{ x: x,y: y });
    return ret;
}

我使用以下代码调用函数

let rotating_circle = containerpolygon(
    window.innerWidth / 2,window.innerHeight / 2,50,radius + object_radius,outter_circle_color
);

我想设置它的角速度,使其绕其中心旋转,但我尝试使用下面的这种方法,它甚至没有旋转。

Body.setAngularVeLocity(rotating_cicle,Math.PI/6);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。