Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering rotated rectangles from box2dweb in pixi.js
    primarykey
    data
    text
    <p>I am writing my own renderer for box2dweb and I decided I would like to use pixi.js.</p> <p>I am able to render rectangles, but only if they aren't rotated - if they are, the animation is messed up. It looks like this (one on the left is debug renderer from box2d, one on the right is mine): <a href="http://scr.hu/0ozr/o552x" rel="nofollow">http://scr.hu/0ozr/o552x</a></p> <p>I know that I need to set up the pivot for graphics object in pixi, but I don't know how to access coordinates of the point that box is rotated around from box2d.</p> <p>I guess I need to use contact constraint of some form, but how do I access it?</p> <p>This is part of the code that creates pixi graphic object for the polygon: (I need to translate all vertices to coordinate system with start in left upper corner of the polygon bounding box, because PIXI uses this kind of coordinate system).</p> <pre><code>getModel : function(body) { var that = this; var model = new PIXI.Graphics(); model.beginFill(0xFFFFFF); var box = physHelpers.getBoundingBox(body); model.position.x = box.x * that.scale; model.position.y = box.y * that.scale; var vertices = physHelpers.getTranslatedVertices(body); model.moveTo(vertices[0].x * that.scale, vertices[0].y * that.scale); for(var i = 1 ; i &lt; vertices.length ; i++){ model.lineTo(vertices[i].x*that.scale, vertices[i].y*that.scale); } model.pivot = new PIXI.Point(box.width/2,model.height/2); model.rotation = body.GetBody().GetAngle(); model.endFill(); return model; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload