Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need small update for new pyglet (v2.1) to use shapes.Line function in pymunk.pyglet_util #267

Closed
AkahoshiT opened this issue Jan 15, 2025 · 5 comments

Comments

@AkahoshiT
Copy link

width is disabled in new pyglet.shapes.Line and get warning if you run it.
So we need to replace width with thickness for newer version of pyglet.

l = pyglet.shapes.Line(
pos.x, pos.y, cc.x, cc.y, width=1, color=color, batch=self.batch, group=fg
)
self.draw_shapes.append(l)
def draw_segment(self, a: Vec2d, b: Vec2d, color: SpaceDebugColor) -> None:
c = color.as_int()
l = pyglet.shapes.Line(a.x, a.y, b.x, b.y, width=1, color=c, batch=self.batch)
self.draw_shapes.append(l)

        l = pyglet.shapes.Line(
            pos.x, pos.y, cc.x, cc.y, thickness=1, color=color, batch=self.batch, group=fg
        )
        self.draw_shapes.append(l)

    def draw_segment(self, a: Vec2d, b: Vec2d, color: SpaceDebugColor) -> None:
        c = color.as_int()
        l = pyglet.shapes.Line(a.x, a.y, b.x, b.y, thickness=1, color=c, batch=self.batch)
        self.draw_shapes.append(l)
@AkahoshiT AkahoshiT changed the title Need small update for new pyglet (v2.1) to use shapes.Line function in pymunk.pyglet_util. Need small update for new pyglet (v2.1) to use shapes.Line function in pymunk.pyglet_util Jan 15, 2025
@totex
Copy link

totex commented Jan 15, 2025

I had the same problem as @AkahoshiT, changing the "width" to "thickness" solved the problem.

But there is an another problem related to the problem above. If you create a DYNAMIC body, and add a shape to it:

circle_body = pymunk.Body(body_type=pymunk.Body.DYNAMIC)
circle_shape = pymunk.Circle(circle_body, radius=30)

This code results to the following error:
ValueError: cannot convert float NaN to integer

This error comes from the pyglet_util.DrawOptions

@viblo
Copy link
Owner

viblo commented Jan 15, 2025

Thanks for the report!

As for the thickness.. Its easy to fix, but that breaks pyglet 2.0.x.. And I have already fallback code for pyglet 1.5, Im not so much into having 2 different fallbacks. But I guess it should be ok to break it This is only relevant if you use pyglet for something complicated and at the same time use debug draw.

At the same time, I think I can remove support for 1.5 now. (But maybe in a separate release), now a long time passed since 2.0 were released, and its difficult to think of cases were you need to both use latest pymunk but at the same time such an old pyglet version.

@viblo
Copy link
Owner

viblo commented Jan 15, 2025

@totex Can you expand on your example? Both pyglet_util_demo and box2d_vertical_stack works so not sure what you do?

@totex
Copy link

totex commented Jan 15, 2025

@viblo Sorry, it looks like, I just forgot to create the body correctly.

I have created a DYNAMIC body without the mass and the moment, like this:
circle_body = pymunk.Body(body_type=pymunk.Body.DYNAMIC)

I tried it like this, and it works:
circle_body = pymunk.Body(1, 1666, body_type=pymunk.Body.DYNAMIC)

@viblo
Copy link
Owner

viblo commented Jan 17, 2025

@viblo Sorry, it looks like, I just forgot to create the body correctly.

I have created a DYNAMIC body without the mass and the moment, like this: circle_body = pymunk.Body(body_type=pymunk.Body.DYNAMIC)

I tried it like this, and it works: circle_body = pymunk.Body(1, 1666, body_type=pymunk.Body.DYNAMIC)

Ah, this error again. Not the first time it happens: #226 Now I suspect this is the most common mistake..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants