سؤال

I am writing my own renderer for box2dweb and I decided I would like to use pixi.js.

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): http://scr.hu/0ozr/o552x

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.

I guess I need to use contact constraint of some form, but how do I access it?

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).

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 < 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;
}
هل كانت مفيدة؟

المحلول

Allright, I got it. It seems that PIXI changes point in which it start rendering when you change pivot (it affected object position even without changing the rotation). Also, box2d rotation rotates around center of the body.

So now I can use box2d body position without translating to upper left corner to start rendering.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top