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

endless rotation bug caused by applyTransform #3

Open
pavel-b-kr12 opened this issue Jan 10, 2020 · 2 comments
Open

endless rotation bug caused by applyTransform #3

pavel-b-kr12 opened this issue Jan 10, 2020 · 2 comments

Comments

@pavel-b-kr12
Copy link

pavel-b-kr12 commented Jan 10, 2020

processing 3.5.3
open any example with

DwWorld world
world.applyTransform(this.g); 

see endless rotation of body visual (after move it a bit).

If use USE_DEBUG_DRAW - all work as it should

@OWilliam
Copy link

OWilliam commented Mar 5, 2021

I see this, too, on Windows with processing 3.5.4. Visual bodies spin while the debug physical bodies don't.

It looks like it could be an angle conversion issue: small angular changes in the physical bodies are converted to large angular changes in the visual body. Is there radians <-> degrees conversion bug somewhere?

@MadMontanaMax
Copy link

MadMontanaMax commented Sep 28, 2024

there is a problem with PShape.resetMatrix() not resetting rotation in P2D
(https://discourse.processing.org/t/pshape-resetmatrix-not-resetting-rotation-in-p2d/8508)

the workaround suggested there works.
in DwWorld class change updateBodies() :
instead of applying the rotation to the shapeMatrix, apply it to a new PMatrix2D, which can be resetted.
then apply that matrix to the shape.

public void updateBodies(){
    PMatrix2D matrix = new PMatrix2D();
    for (Body body = super.getBodyList(); body != null; body = body.getNext()) {
      Transform xf = body.getTransform();
      
      DwBody dwbody = getShape(body);
      if(dwbody != null){
        float angle=(float)xf.q.getAngle();
        
        matrix.reset();
        matrix.rotate(angle);
        
        dwbody.shape.resetMatrix();
        dwbody.shape.applyMatrix(matrix);
        //dwbody.shape.rotate(angle);
        
        dwbody.shape.translate(xf.p.x, xf.p.y);
 }

same with updateLineShapes()

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