Physaxe questions

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Physaxe questions

justin_mills
Hi

using Physaxe and not sure why the collisions with the floor are not
working when I change to polygon so I can have a bumpy floor and get
more interesting bounces. ( I am using haxelib version, is it upto date ? ).

         _floor = new phx.Body(0,0);
         _floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, 0));
         //_floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, h - 30));
         var points: Array<Vector> = new Array();
         var dx = 0.0;
         points.push(  new Vector(0, 0) );
          do {
                 points.push( new phx.Vector( dx, h - 30 + 10*(
Std.random(2) - 4 )  ));
         } while ( (dx += 100) < w * 100 );
         points.push( new Vector( w * 100,   h  ));
         points.push(  new Vector(0, h ) );
         _floor.addShape( new phx.Polygon( points, new phx.Vector(0, 0),
mat )  );
         //floor.addShape(phx.Shape.makeBox(30,h,0,0));
         //floor.addShape(phx.Shape.makeBox(30,h,w-30,0));
         _floor.isStatic = true;
         _world.addBody(_floor);

Also I am not yet sure how I use a bitmapData as a fill for a shape, so
like if I wanted a footballs rather than random shapes how do I spec the
material?  Other issues I am having is - I am moving the holder sideways
as movement happens and  sometimes the particles are dissappearing, also
not sure I understand why the particles are greyed and then go solid
later and then can't be picked.  I have experimented with trying to
change bounce but it does not seem to be like say a tween bounce.  
Lastly if I wanted to use with 3d engine are there any physaxe in 3d and
if I use but only use it for 2d how would I mix it?

Is there any code to slow rather than collide, so like a car could pass
through a mud shape rather than bounce off... is friction etc only
linked to collision off an object rather than also passing through say
water?

Sorry lots of questions, not found lots of examples of physaxe so guess
I am wondering how much it is capable of and if its overkill for my
simple needs, it might be better to code from scratch or maybe take a
look at bit101's books rather than use an engine i don't know well.

Cheers

;j

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

justin_mills
Looking through the code it looks like to change the fill to a bitmap I
need to modify the FlashDraw class, maybe by modifying the Color Typedef?


Le 13/01/2011 17:24, justin_mills a écrit :

> Hi
>
> using Physaxe and not sure why the collisions with the floor are not
> working when I change to polygon so I can have a bumpy floor and get
> more interesting bounces. ( I am using haxelib version, is it upto
> date ? ).
>
>         _floor = new phx.Body(0,0);
>         _floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, 0));
>         //_floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, h - 30));
>         var points: Array<Vector> = new Array();
>         var dx = 0.0;
>         points.push(  new Vector(0, 0) );
>          do {
>                 points.push( new phx.Vector( dx, h - 30 + 10*(
> Std.random(2) - 4 )  ));
>         } while ( (dx += 100) < w * 100 );
>         points.push( new Vector( w * 100,   h  ));
>         points.push(  new Vector(0, h ) );
>         _floor.addShape( new phx.Polygon( points, new phx.Vector(0,
> 0), mat )  );
>         //floor.addShape(phx.Shape.makeBox(30,h,0,0));
>         //floor.addShape(phx.Shape.makeBox(30,h,w-30,0));
>         _floor.isStatic = true;
>         _world.addBody(_floor);
>
> Also I am not yet sure how I use a bitmapData as a fill for a shape,
> so like if I wanted a footballs rather than random shapes how do I
> spec the material?  Other issues I am having is - I am moving the
> holder sideways as movement happens and  sometimes the particles are
> dissappearing, also not sure I understand why the particles are greyed
> and then go solid later and then can't be picked.  I have experimented
> with trying to change bounce but it does not seem to be like say a
> tween bounce.  Lastly if I wanted to use with 3d engine are there any
> physaxe in 3d and if I use but only use it for 2d how would I mix it?
>
> Is there any code to slow rather than collide, so like a car could
> pass through a mud shape rather than bounce off... is friction etc
> only linked to collision off an object rather than also passing
> through say water?
>
> Sorry lots of questions, not found lots of examples of physaxe so
> guess I am wondering how much it is capable of and if its overkill for
> my simple needs, it might be better to code from scratch or maybe take
> a look at bit101's books rather than use an engine i don't know well.
>
> Cheers
>
> ;j
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

Andy Li
I believe the FlashDraw class only serve as a debug/learning helper.
You normally have to write you own code to link up the physic bodies and graphic objects.
So if you want to have a physics enabled football, you can write something similar to:

class Football {
    public function new() { /*...*/ }
    public var body:phx.Body;
    public function draw():Void { /* draw the football to the screen base on the property of body */ }
}

And in the main loop, you step() the world and call draw() on every Football.

Hope it helps.

Andy



On Fri, Jan 14, 2011 at 12:56 AM, justin_mills <[hidden email]> wrote:
Looking through the code it looks like to change the fill to a bitmap I need to modify the FlashDraw class, maybe by modifying the Color Typedef?


Le 13/01/2011 17:24, justin_mills a écrit :

Hi

using Physaxe and not sure why the collisions with the floor are not working when I change to polygon so I can have a bumpy floor and get more interesting bounces. ( I am using haxelib version, is it upto date ? ).

       _floor = new phx.Body(0,0);
       _floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, 0));
       //_floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, h - 30));
       var points: Array<Vector> = new Array();
       var dx = 0.0;
       points.push(  new Vector(0, 0) );
        do {
               points.push( new phx.Vector( dx, h - 30 + 10*( Std.random(2) - 4 )  ));
       } while ( (dx += 100) < w * 100 );
       points.push( new Vector( w * 100,   h  ));
       points.push(  new Vector(0, h ) );
       _floor.addShape( new phx.Polygon( points, new phx.Vector(0, 0), mat )  );
       //floor.addShape(phx.Shape.makeBox(30,h,0,0));
       //floor.addShape(phx.Shape.makeBox(30,h,w-30,0));
       _floor.isStatic = true;
       _world.addBody(_floor);

Also I am not yet sure how I use a bitmapData as a fill for a shape, so like if I wanted a footballs rather than random shapes how do I spec the material?  Other issues I am having is - I am moving the holder sideways as movement happens and  sometimes the particles are dissappearing, also not sure I understand why the particles are greyed and then go solid later and then can't be picked.  I have experimented with trying to change bounce but it does not seem to be like say a tween bounce.  Lastly if I wanted to use with 3d engine are there any physaxe in 3d and if I use but only use it for 2d how would I mix it?

Is there any code to slow rather than collide, so like a car could pass through a mud shape rather than bounce off... is friction etc only linked to collision off an object rather than also passing through say water?

Sorry lots of questions, not found lots of examples of physaxe so guess I am wondering how much it is capable of and if its overkill for my simple needs, it might be better to code from scratch or maybe take a look at bit101's books rather than use an engine i don't know well.

Cheers

;j



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

justin_mills
Andy

I was thinking of changing FlashDraw so that I could put a check in that checks for a skin, and if there is one uses  beginBitmapFill instead of beginFill.

Not fully following your example, but it has given me insight.

Cheers

;j

 
Le 14/01/2011 10:32, Andy Li a écrit :
I believe the FlashDraw class only serve as a debug/learning helper.
You normally have to write you own code to link up the physic bodies and graphic objects.
So if you want to have a physics enabled football, you can write something similar to:

class Football {
    public function new() { /*...*/ }
    public var body:phx.Body;
    public function draw():Void { /* draw the football to the screen base on the property of body */ }
}

And in the main loop, you step() the world and call draw() on every Football.

Hope it helps.

Andy



On Fri, Jan 14, 2011 at 12:56 AM, justin_mills <[hidden email]> wrote:
Looking through the code it looks like to change the fill to a bitmap I need to modify the FlashDraw class, maybe by modifying the Color Typedef?


Le 13/01/2011 17:24, justin_mills a écrit :

Hi

using Physaxe and not sure why the collisions with the floor are not working when I change to polygon so I can have a bumpy floor and get more interesting bounces. ( I am using haxelib version, is it upto date ? ).

       _floor = new phx.Body(0,0);
       _floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, 0));
       //_floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, h - 30));
       var points: Array<Vector> = new Array();
       var dx = 0.0;
       points.push(  new Vector(0, 0) );
        do {
               points.push( new phx.Vector( dx, h - 30 + 10*( Std.random(2) - 4 )  ));
       } while ( (dx += 100) < w * 100 );
       points.push( new Vector( w * 100,   h  ));
       points.push(  new Vector(0, h ) );
       _floor.addShape( new phx.Polygon( points, new phx.Vector(0, 0), mat )  );
       //floor.addShape(phx.Shape.makeBox(30,h,0,0));
       //floor.addShape(phx.Shape.makeBox(30,h,w-30,0));
       _floor.isStatic = true;
       _world.addBody(_floor);

Also I am not yet sure how I use a bitmapData as a fill for a shape, so like if I wanted a footballs rather than random shapes how do I spec the material?  Other issues I am having is - I am moving the holder sideways as movement happens and  sometimes the particles are dissappearing, also not sure I understand why the particles are greyed and then go solid later and then can't be picked.  I have experimented with trying to change bounce but it does not seem to be like say a tween bounce.  Lastly if I wanted to use with 3d engine are there any physaxe in 3d and if I use but only use it for 2d how would I mix it?

Is there any code to slow rather than collide, so like a car could pass through a mud shape rather than bounce off... is friction etc only linked to collision off an object rather than also passing through say water?

Sorry lots of questions, not found lots of examples of physaxe so guess I am wondering how much it is capable of and if its overkill for my simple needs, it might be better to code from scratch or maybe take a look at bit101's books rather than use an engine i don't know well.

Cheers

;j



--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

justin_mills
I have extended several classes so that I can BeginBitmapFill, but I am having trouble with updating the matrix so the material is rotated properly, I had assumed that a in body could be changed to update my texture.

    override public function setAngle( a : Float )
    {
       
        super.setAngle(a);
       
        trace( 'set angle ');
        for ( s in shapes )
        {
            trace( s );
            if ( Reflect.hasField( s, '_texture' ) )
            {
                trace( 'adjusting texture' );
                untyped s._texture.angle( a );
            }
        }
    }

But it does not seem to be being set when the Polygon rotates?



Le 14/01/2011 11:13, justin_mills a écrit :
Andy

I was thinking of changing FlashDraw so that I could put a check in that checks for a skin, and if there is one uses  beginBitmapFill instead of beginFill.

Not fully following your example, but it has given me insight.

Cheers

;j

 
Le 14/01/2011 10:32, Andy Li a écrit :
I believe the FlashDraw class only serve as a debug/learning helper.
You normally have to write you own code to link up the physic bodies and graphic objects.
So if you want to have a physics enabled football, you can write something similar to:

class Football {
    public function new() { /*...*/ }
    public var body:phx.Body;
    public function draw():Void { /* draw the football to the screen base on the property of body */ }
}

And in the main loop, you step() the world and call draw() on every Football.

Hope it helps.

Andy



On Fri, Jan 14, 2011 at 12:56 AM, justin_mills <[hidden email]> wrote:
Looking through the code it looks like to change the fill to a bitmap I need to modify the FlashDraw class, maybe by modifying the Color Typedef?


Le 13/01/2011 17:24, justin_mills a écrit :

Hi

using Physaxe and not sure why the collisions with the floor are not working when I change to polygon so I can have a bumpy floor and get more interesting bounces. ( I am using haxelib version, is it upto date ? ).

       _floor = new phx.Body(0,0);
       _floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, 0));
       //_floor.addShape(phx.Shape.makeBox(w * 100, 30, 0, h - 30));
       var points: Array<Vector> = new Array();
       var dx = 0.0;
       points.push(  new Vector(0, 0) );
        do {
               points.push( new phx.Vector( dx, h - 30 + 10*( Std.random(2) - 4 )  ));
       } while ( (dx += 100) < w * 100 );
       points.push( new Vector( w * 100,   h  ));
       points.push(  new Vector(0, h ) );
       _floor.addShape( new phx.Polygon( points, new phx.Vector(0, 0), mat )  );
       //floor.addShape(phx.Shape.makeBox(30,h,0,0));
       //floor.addShape(phx.Shape.makeBox(30,h,w-30,0));
       _floor.isStatic = true;
       _world.addBody(_floor);

Also I am not yet sure how I use a bitmapData as a fill for a shape, so like if I wanted a footballs rather than random shapes how do I spec the material?  Other issues I am having is - I am moving the holder sideways as movement happens and  sometimes the particles are dissappearing, also not sure I understand why the particles are greyed and then go solid later and then can't be picked.  I have experimented with trying to change bounce but it does not seem to be like say a tween bounce.  Lastly if I wanted to use with 3d engine are there any physaxe in 3d and if I use but only use it for 2d how would I mix it?

Is there any code to slow rather than collide, so like a car could pass through a mud shape rather than bounce off... is friction etc only linked to collision off an object rather than also passing through say water?

Sorry lots of questions, not found lots of examples of physaxe so guess I am wondering how much it is capable of and if its overkill for my simple needs, it might be better to code from scratch or maybe take a look at bit101's books rather than use an engine i don't know well.

Cheers

;j



--
haXe - an open source web programming language
http://haxe.org




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

justin_mills
Ok here is my rough approximation to skinning physaxe shapes without
modifying the haXeLib, maybe this could be integrated into Physaxe or
improved, suggestions welcome.


package physaxeExtensions;
//import flash.Vector;
import flash.display.BitmapData;
import phx.Material;
import phx.Polygon;
import phx.Shape;
import phx.Vector;

/**
  * ...
  * @author JLM at justinfront dot net
  */

class PolygonTexture extends Polygon
{

     public var _texture: Texture;
     public function new( vl : Array<Vector>, offset : Vector, ?material
: Material, ?texture_: Texture = null )
     {
         _texture = texture_;
         super( vl, offset, material );

     }

}


package physaxeExtensions;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Matrix;

/**
  * ...
  * @author JLM at justinfront dot net
  */

class Texture
{

     public var _matrix:     Matrix;
     private var mc:         MovieClip;
     public var _source:    BitmapData;

     public function new( ?sourceMc: MovieClip, ?sourceBitmap: Bitmap,
?sourceBitmapData:BitmapData )
     {

         _matrix         = new Matrix();
         if ( sourceMc != null )
         {

             _source = new BitmapData( Std.int( mc.width ), Std.int(
mc.height ) );
             sourceMc.addEventListener( Event.ENTER_FRAME, updateTexture );

         }
         else if( sourceBitmap != null )
         {

             _source = sourceBitmap.bitmapData;

         }
         else if ( sourceBitmapData != null )
         {

             _source = sourceBitmapData;

         }

     }


     public function setMatrix( a_: Float, x_: Float, y_: Float, rw_:
Float, rh_: Float )
     {

         //this.a = -a_;-rh_-rw_
         _matrix = new Matrix();
         _matrix.translate(  -_source.width/2 , -_source.height/2 );
         _matrix.rotate( a_ );
         _matrix.translate(  x_ ,  y_);

     }


     private function updateTexture( e: Event )
     {
         if ( mc != null )
         {
             _source.draw( mc );
         }
     }

}

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
  * ...
  * @author JLM at justinfront dot net
  */

class FlashDrawTexture extends FlashDraw
{

     public function new( g )
     {

         super( g );

     }

     function beginAdvanced(  ?c : Color= null, ?t: Texture = null): Bool
     {

         if ( t != null )
         {
             //trace( t._matrix );
             g.beginBitmapFill( t._source, t._matrix, false, true );
             return true;

         }
         else
         {
             try
             {
                 return begin( c );
             }
             catch ( e: Dynamic )
             {
                 trace( 'begin fail' );
                 return false;
             }
         }
     }

     function endAdvanced( ?c : Color, ?t:Texture )
     {
         if ( t != null )
         {
             g.endFill();
         }
         else
         {
             end( c );
         }
     }

     override public function drawShape( s : Shape )
     {
         var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped
s._texture: null;

         if ( beginAdvanced( selectColor(s), t ) )
         {
             switch( s.type ) {
             case Shape.CIRCLE: drawCircle(s.circle);
             case Shape.POLYGON: drawPoly(s.polygon);
             case Shape.SEGMENT: drawSegment(s.segment);
             }
             endAdvanced( selectColor(s), t  );
         }
         if( beginAdvanced(boundingBox) ) {
             g.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l,
s.aabb.b - s.aabb.t);
             endAdvanced(boundingBox);
         }

     }

     override public function drawBody( b : Body) {
         var b2 = b;
         var rw: Float;
         var rh: Float;
         for( s in b.shapes ) {
             var b = s.aabb;
             if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
                 continue;
             if ( Reflect.hasField( s, '_texture' ) )
             {
                 rw = (b.r - b.l) / 2;
                 rh = ( b.b - b.t) / 2;
                 untyped s._texture.setMatrix( b2.a, b.l + rw, b.t + rh,
rw, rh );
             }
             drawShape(s);
         }
     }

}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

fintan boyle
have a look at this repository for reference:
http://code.google.com/p/touchmypixel/

Box2d is used in this library but it is utilized in the way that Andy describes in his response.  The debug draw mode is useful for checking the collidable shape (which can tend to be different to the dimensions of the avatar associated with the b2body object).

For example, have a look at how the collidable shapes differ from the graphics in the illustrations of this article:
http://www.huesforalice.com/project/40

I haven't played around with Physaxe much but I think the same applies for it.

Fintan

On Fri, Jan 14, 2011 at 5:09 PM, justin_mills <[hidden email]> wrote:
Ok here is my rough approximation to skinning physaxe shapes without modifying the haXeLib, maybe this could be integrated into Physaxe or improved, suggestions welcome.


package physaxeExtensions;
//import flash.Vector;
import flash.display.BitmapData;
import phx.Material;
import phx.Polygon;
import phx.Shape;
import phx.Vector;

/**
 * ...
 * @author JLM at justinfront dot net
 */

class PolygonTexture extends Polygon
{

   public var _texture: Texture;
   public function new( vl : Array<Vector>, offset : Vector, ?material : Material, ?texture_: Texture = null )
   {
       _texture = texture_;
       super( vl, offset, material );

   }

}


package physaxeExtensions;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Matrix;

/**
 * ...
 * @author JLM at justinfront dot net
 */

class Texture
{

   public var _matrix:     Matrix;
   private var mc:         MovieClip;
   public var _source:    BitmapData;

   public function new( ?sourceMc: MovieClip, ?sourceBitmap: Bitmap, ?sourceBitmapData:BitmapData )
   {

       _matrix         = new Matrix();
       if ( sourceMc != null )
       {

           _source = new BitmapData( Std.int( mc.width ), Std.int( mc.height ) );
           sourceMc.addEventListener( Event.ENTER_FRAME, updateTexture );

       }
       else if( sourceBitmap != null )
       {

           _source = sourceBitmap.bitmapData;

       }
       else if ( sourceBitmapData != null )
       {

           _source = sourceBitmapData;

       }

   }


   public function setMatrix( a_: Float, x_: Float, y_: Float, rw_: Float, rh_: Float )
   {

       //this.a = -a_;-rh_-rw_
       _matrix = new Matrix();
       _matrix.translate(  -_source.width/2 , -_source.height/2 );
       _matrix.rotate( a_ );
       _matrix.translate(  x_ ,  y_);

   }


   private function updateTexture( e: Event )
   {
       if ( mc != null )
       {
           _source.draw( mc );
       }
   }

}

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 * @author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   public function new( g )
   {

       super( g );

   }

   function beginAdvanced(  ?c : Color= null, ?t: Texture = null): Bool
   {

       if ( t != null )
       {
           //trace( t._matrix );
           g.beginBitmapFill( t._source, t._matrix, false, true );
           return true;

       }
       else
       {
           try
           {
               return begin( c );
           }
           catch ( e: Dynamic )
           {
               trace( 'begin fail' );
               return false;
           }
       }
   }

   function endAdvanced( ?c : Color, ?t:Texture )
   {
       if ( t != null )
       {
           g.endFill();
       }
       else
       {
           end( c );
       }
   }

   override public function drawShape( s : Shape )
   {
       var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped s._texture: null;

       if ( beginAdvanced( selectColor(s), t ) )
       {
           switch( s.type ) {
           case Shape.CIRCLE: drawCircle(s.circle);
           case Shape.POLYGON: drawPoly(s.polygon);
           case Shape.SEGMENT: drawSegment(s.segment);
           }
           endAdvanced( selectColor(s), t  );
       }
       if( beginAdvanced(boundingBox) ) {
           g.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
           endAdvanced(boundingBox);
       }

   }

   override public function drawBody( b : Body) {
       var b2 = b;
       var rw: Float;
       var rh: Float;
       for( s in b.shapes ) {
           var b = s.aabb;
           if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               continue;

           if ( Reflect.hasField( s, '_texture' ) )
           {
               rw = (b.r - b.l) / 2;
               rh = ( b.b - b.t) / 2;
               untyped s._texture.setMatrix( b2.a, b.l + rw, b.t + rh, rw, rh );
           }
           drawShape(s);

       }
   }

}

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

jlm@justinfront.net
I understand the point being made, but was happy with my fill approach... if I could get it working, besides I have got some stuff working with physaxe so loathed to change engines.

I am still not getting far with applying the bitmap texture in physaxe to a polygon.  I did some experiments with rotating and found putting the shape in the center of a square in my texture greatly simplifies and it allows me to rotate the bitmap without cropping issues.

    public function createSource( bitmap_: Bitmap )
    {
        
        var w       = bitmap_.width;
        var h       = bitmap_.height;
        _d          = Std.int( w /Math.sin( Math.atan2( w, h) ));
        _source     = new BitmapData(  _d, _d, true, 0x00000000 );
        _dx = ( _d - w )/2;
        _dy = ( _d - h )/2;
        _source.copyPixels( bitmap_.bitmapData, new Rectangle( 0, 0, w, h ), new Point( _dx, _dy ) );
        
    }

The matrix transform is not far off...

public function setMatrix( a_: Float, x_: Float, y_: Float )
{
var r = _d/2;
_matrix = new Matrix();
    _matrix.translate( -r, -r );
_matrix.rotate( a_ );
_matrix.translate(  x_,  y_ );
}

but for some reason the fill centre is not in the centre of the shape and so it drifts around the centre, I think it is because the original x_ and y_ despite being the centre of the physics and the original bitmap are not the centre of the fill.

I presume I need to calculate the fill centre from the vectors as they are rotated by taking the average x and average y and then work out the offset from the assumed centre, this will give m the fill centre which I presume changes as it rotates? 

From my rotation experiments, I think the vector order needs to be rearranged to display on all flash 10 players, I guess its an early flash 10 beginBitmapFill bug where if you define the vectors not from the right corner and not in the correct clock direction it messes up, but this is a guess, while I suppose I don't need to support old flash10 it could be an issue :(.

Another issue is the hittest between bodies is it seems to be the centre not the edge points, but edge points are working with the walls.



On 14 Jan 2011, at 18:26, fintan boyle wrote:

have a look at this repository for reference:
http://code.google.com/p/touchmypixel/

Box2d is used in this library but it is utilized in the way that Andy describes in his response.  The debug draw mode is useful for checking the collidable shape (which can tend to be different to the dimensions of the avatar associated with the b2body object).

For example, have a look at how the collidable shapes differ from the graphics in the illustrations of this article:
http://www.huesforalice.com/project/40

I haven't played around with Physaxe much but I think the same applies for it.

Fintan

On Fri, Jan 14, 2011 at 5:09 PM, justin_mills <[hidden email]> wrote:
Ok here is my rough approximation to skinning physaxe shapes without modifying the haXeLib, maybe this could be integrated into Physaxe or improved, suggestions welcome.


package physaxeExtensions;
//import flash.Vector;
import flash.display.BitmapData;
import phx.Material;
import phx.Polygon;
import phx.Shape;
import phx.Vector;

/**
 * ...
 * @author JLM at justinfront dot net
 */

class PolygonTexture extends Polygon
{

   public var _texture: Texture;
   public function new( vl : Array<Vector>, offset : Vector, ?material : Material, ?texture_: Texture = null )
   {
       _texture = texture_;
       super( vl, offset, material );

   }

}


package physaxeExtensions;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Matrix;

/**
 * ...
 * @author JLM at justinfront dot net
 */

class Texture
{

   public var _matrix:     Matrix;
   private var mc:         MovieClip;
   public var _source:    BitmapData;

   public function new( ?sourceMc: MovieClip, ?sourceBitmap: Bitmap, ?sourceBitmapData:BitmapData )
   {

       _matrix         = new Matrix();
       if ( sourceMc != null )
       {

           _source = new BitmapData( Std.int( mc.width ), Std.int( mc.height ) );
           sourceMc.addEventListener( Event.ENTER_FRAME, updateTexture );

       }
       else if( sourceBitmap != null )
       {

           _source = sourceBitmap.bitmapData;

       }
       else if ( sourceBitmapData != null )
       {

           _source = sourceBitmapData;

       }

   }


   public function setMatrix( a_: Float, x_: Float, y_: Float, rw_: Float, rh_: Float )
   {

       //this.a = -a_;-rh_-rw_
       _matrix = new Matrix();
       _matrix.translate(  -_source.width/2 , -_source.height/2 );
       _matrix.rotate( a_ );
       _matrix.translate(  x_ ,  y_);

   }


   private function updateTexture( e: Event )
   {
       if ( mc != null )
       {
           _source.draw( mc );
       }
   }

}

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 * @author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   public function new( g )
   {

       super( g );

   }

   function beginAdvanced(  ?c : Color= null, ?t: Texture = null): Bool
   {

       if ( t != null )
       {
           //trace( t._matrix );
           g.beginBitmapFill( t._source, t._matrix, false, true );
           return true;

       }
       else
       {
           try
           {
               return begin( c );
           }
           catch ( e: Dynamic )
           {
               trace( 'begin fail' );
               return false;
           }
       }
   }

   function endAdvanced( ?c : Color, ?t:Texture )
   {
       if ( t != null )
       {
           g.endFill();
       }
       else
       {
           end( c );
       }
   }

   override public function drawShape( s : Shape )
   {
       var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped s._texture: null;

       if ( beginAdvanced( selectColor(s), t ) )
       {
           switch( s.type ) {
           case Shape.CIRCLE: drawCircle(s.circle);
           case Shape.POLYGON: drawPoly(s.polygon);
           case Shape.SEGMENT: drawSegment(s.segment);
           }
           endAdvanced( selectColor(s), t  );
       }
       if( beginAdvanced(boundingBox) ) {
           g.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
           endAdvanced(boundingBox);
       }

   }

   override public function drawBody( b : Body) {
       var b2 = b;
       var rw: Float;
       var rh: Float;
       for( s in b.shapes ) {
           var b = s.aabb;
           if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               continue;

           if ( Reflect.hasField( s, '_texture' ) )
           {
               rw = (b.r - b.l) / 2;
               rh = ( b.b - b.t) / 2;
               untyped s._texture.setMatrix( b2.a, b.l + rw, b.t + rh, rw, rh );
           }
           drawShape(s);

       }
   }

}

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

jlm@justinfront.net
Ok I seem to have got it working, so since I bothered the the list I will post solution.

Nicolas could you consider integrating this into your engine probably in a cleaner fashion, at the moment the code is separate to avoid polluting the haxelib but ideally it would be more integrated?

So for anyone wanting to try this, here are some instructions...

With flash IDE, you need to define your vector points by putting a bitmap ( transparent png ) as a guide aligned so it is centred in a test movie ( rather than aligned top corner ), the test movie is because it's more of a pain to do it from the stage.  Add movieClips as position holders in an anticlockwise direction and then trace them out from flash IDE ( no need to name them let flash assume order and naming ) to copy into your haXe.

// as3 timeline code inside a test movieclip
var here: flash.display.MovieClip = this;
var mc: flash.display.MovieClip;
for( var i: int = 0; i < here.numChildren; i++ )
{
mc = here.getChildAt(i) as MovieClip;
trace( 'points.push(new phx.Vector(' + mc.x + ' ,' + mc.y + ' ));' );
}

( If you define them in the wrong direction, or nothing show as I did just use points.reverse() in your haxe )

Now to get the Bitmap fill working you need these three classes and a bitmap (I load mine at runtime), I won't post code as you just need to hack the standard example, but instead use my extended classes.

package physaxeExtensions;
import phx.Material;
import phx.Polygon;
import phx.Vector;

/**
 *
@author JLM at justinfront dot net
 */

class PolygonTexture extends Polygon
{
   
   
public var _texture: Texture;
   
public function new( vl : Array<Vector>, offset : Vector, ?material : Material, ?texture_: Texture = null
    {
       
_texture = texture_;
       
super( vl, offset, material );     
       
    }
   
}

______________________

package physaxeExtensions;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.BitmapData;
import flash.events.Event;

/**
 * ...
 *
@author JLM at justinfront dot net
 */

class Texture
{
   
   
public var _matrix:     Matrix;
   
public var _source:     BitmapData;
   
private var _r:         Float;
   
   
public function new( sourceBitmap: Bitmap )
    {
       
       
_matrix         = new Matrix();
        createSource( sourceBitmap )
;
       
    }
   
   
   
public function createSource( bitmap_: Bitmap )
    {
       
       
var w           = bitmap_.width;
       
var h           = bitmap_.height;
       
var d           = w /Math.sin( Math.atan2( w, h) );
       
var di          = Std.int( d );
       
_source         = new BitmapData( di, di, true, 0x00000000 );
       
_r              = d/2;
       
       
_source.copyPixels( bitmap_.bitmapData, new Rectangle( 0, 0, w, h ), new Point( ( d - w )/2, ( d - h )/2 ) );
       
    }
   
   
   
public function setMatrix( a_: Float, x_: Float, y_: Float )
    {
       
       
_matrix = new Matrix();
       
_matrix.translate( -_r, -_r );
       
_matrix.rotate( a_ );
       
_matrix.translate(  x_  ,  y_ );
   
    }
   
}

______________________

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 *
@author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   
public function new( g )
    {
       
       
super( g );
       
    }
   
   
function beginAdvanced?c : Color= null, ?t: Texture = null): Bool
    {
       
       
if ( t != null )
        {
           
            g
.beginBitmapFill( t._source, t._matrix, true, true );
           
return true;
           
        }
       
else
        {
           
try
            {
               
return begin( c );
            }
           
catch ( e: Dynamic )
            {
               
return false;
            }
        }
    }
   
   
function endAdvanced( ?c : Color, ?t:Texture )
    {
       
if ( t != null )
        {
            g
.endFill();
        }
       
else
        {
           
end( c );
        }
    }
   
   
override public function drawShape( s : Shape )
    {
       
var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped s._texture: null;
       
       
if ( beginAdvanced( selectColor(s), t ) )
        {
           
switch( s.type ) {
           
case Shape.CIRCLE: drawCircle(s.circle);
           
case Shape.POLYGON: drawPoly(s.polygon);
           
case Shape.SEGMENT: drawSegment(s.segment);
            }
            endAdvanced( selectColor(s), t  )
;
        }
       
if( beginAdvanced(boundingBox) ) {
            g
.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
            endAdvanced(boundingBox)
;
        }
       
    }
   
   
override public function drawBody( b : Body) 
    {
       
var b2 = b;
       
for( s in b.shapes ) {
           
var b = s.aabb;
           
if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               
continue;
           
if ( Reflect.hasField( s, '_texture' ) )
            {

                untyped s
._texture.setMatrix( b2.a, b2.x, b2.y );
            }
            drawShape(s)
;
        }
    }
   
}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

jlm@justinfront.net
Sorry to bother the list further, for thread completeness I noticed that in some older flash10 players it was not working, seems Reflection hasField was not checking properly ( should I submit a compiler bug or is this expected? ), instead I found out that  Std.is( instance, myclass ) works much more reliably and allows me to cast safely without using dangerous untyped. So FlashDrawTexture is amended, the main down side is that it is now limited to PolygonTexture which limits to my current use.
But it made me think, it would be really useful to be able to define a multi type ie    
function beginAdvanced( c: MultiType<Color, Texture> ){ 
MultiTypeSwitch c
case: Color
//
case: Texture
//
}
I don't know just can be tricky when you really want to work with limited types, so not dynamic but not a single type either, specifically I think about XML and XMLlist but there are more examples.
Anyway my amended code.

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 *
@author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   
public function new( g )
    {
       
       
super( g );
       
    }
   
   
function beginAdvanced?c : Color= null, ?t: Texture = null): Bool
    {
       
if ( t != null )
        {
           
            g
.beginBitmapFill( t._source, t._matrix, true, true );
           
return true;
           
        }
       
else
        {
           
try
            {
               
return begin( c );
            }
           
catch ( e: Dynamic )
            {
               
return false;
            }
        }
       
    }
   
   
function endAdvanced( ?c : Color, ?t:Texture )
    {
       
if ( t != null )
        {
            g
.endFill();
        }
       
else
        {
           
end( c );
        }
    }
   
   
override public function drawShape( s : Shape )
    {
       
       
var t: Texture = Std.is( s, PolygonTexture )?cast( s, PolygonTexture )._texture: null;
       
if ( beginAdvanced( selectColor( s ), t ) )
        {
           
switch( s.type ) {
           
case Shape.CIRCLE: drawCircle(s.circle);
           
case Shape.POLYGON: drawPoly(s.polygon);
           
case Shape.SEGMENT: drawSegment(s.segment);
            }
            endAdvanced( selectColor(s), t  )
;
        }
       
if( beginAdvanced(boundingBox) )
        {
            g
.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
            endAdvanced(boundingBox)
;
        }
       
    }
   
   
override public function drawBody( b : Body) 
    {
       
var b2 = b;
       
var rw: Float;
       
var rh: Float;
       
for( s in b.shapes ) {
           
var b = s.aabb;
           
if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               
continue;
           
if( Std.is( s, PolygonTexture ) )
            {
                rw
= (b.r - b.l) / 2;
                rh
= ( b.b - b.t) / 2;
                cast( s, PolygonTexture )
._texture.setMatrix( b2.a, b2.x, b2.y );
            }
            drawShape( s )
;
        }
    }


_________________
    On 16 Jan 2011, at 17:39, [hidden email] wrote:

Ok I seem to have got it working, so since I bothered the the list I will post solution.

Nicolas could you consider integrating this into your engine probably in a cleaner fashion, at the moment the code is separate to avoid polluting the haxelib but ideally it would be more integrated?

So for anyone wanting to try this, here are some instructions...

With flash IDE, you need to define your vector points by putting a bitmap ( transparent png ) as a guide aligned so it is centred in a test movie ( rather than aligned top corner ), the test movie is because it's more of a pain to do it from the stage.  Add movieClips as position holders in an anticlockwise direction and then trace them out from flash IDE ( no need to name them let flash assume order and naming ) to copy into your haXe.

// as3 timeline code inside a test movieclip
var here: flash.display.MovieClip = this;
var mc: flash.display.MovieClip;
for( var i: int = 0; i < here.numChildren; i++ )
{
mc = here.getChildAt(i) as MovieClip;
trace( 'points.push(new phx.Vector(' + mc.x + ' ,' + mc.y + ' ));' );
}

( If you define them in the wrong direction, or nothing show as I did just use points.reverse() in your haxe )

Now to get the Bitmap fill working you need these three classes and a bitmap (I load mine at runtime), I won't post code as you just need to hack the standard example, but instead use my extended classes.

package physaxeExtensions;
import phx.Material;
import phx.Polygon;
import phx.Vector;

/**
 *
@author JLM at justinfront dot net
 */

class PolygonTexture extends Polygon
{
   
   
public var _texture: Texture;
   
public function new( vl : Array<Vector>, offset : Vector, ?material : Material, ?texture_: Texture = null
    {
       
_texture = texture_;
       
super( vl, offset, material );     
       
    }
   
}

______________________

package physaxeExtensions;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.BitmapData;
import flash.events.Event;

/**
 * ...
 *
@author JLM at justinfront dot net
 */

class Texture
{
   
   
public var _matrix:     Matrix;
   
public var _source:     BitmapData;
   
private var _r:         Float;
   
   
public function new( sourceBitmap: Bitmap )
    {
       
       
_matrix         = new Matrix();
        createSource( sourceBitmap )
;
       
    }
   
   
   
public function createSource( bitmap_: Bitmap )
    {
       
       
var w           = bitmap_.width;
       
var h           = bitmap_.height;
       
var d           = w /Math.sin( Math.atan2( w, h) );
       
var di          = Std.int( d );
       
_source         = new BitmapData( di, di, true, 0x00000000 );
       
_r              = d/2;
       
       
_source.copyPixels( bitmap_.bitmapData, new Rectangle( 0, 0, w, h ), new Point( ( d - w )/2, ( d - h )/2 ) );
       
    }
   
   
   
public function setMatrix( a_: Float, x_: Float, y_: Float )
    {
       
       
_matrix = new Matrix();
       
_matrix.translate( -_r, -_r );
       
_matrix.rotate( a_ );
       
_matrix.translate(  x_  ,  y_ );
   
    }
   
}

______________________

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 *
@author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   
public function new( g )
    {
       
       
super( g );
       
    }
   
   
function beginAdvanced?c : Color= null, ?t: Texture = null): Bool
    {
       
       
if ( t != null )
        {
           
            g
.beginBitmapFill( t._source, t._matrix, true, true );
           
return true;
           
        }
       
else
        {
           
try
            {
               
return begin( c );
            }
           
catch ( e: Dynamic )
            {
               
return false;
            }
        }
    }
   
   
function endAdvanced( ?c : Color, ?t:Texture )
    {
       
if ( t != null )
        {
            g
.endFill();
        }
       
else
        {
           
end( c );
        }
    }
   
   
override public function drawShape( s : Shape )
    {
       
var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped s._texture: null;
       
       
if ( beginAdvanced( selectColor(s), t ) )
        {
           
switch( s.type ) {
           
case Shape.CIRCLE: drawCircle(s.circle);
           
case Shape.POLYGON: drawPoly(s.polygon);
           
case Shape.SEGMENT: drawSegment(s.segment);
            }
            endAdvanced( selectColor(s), t  )
;
        }
       
if( beginAdvanced(boundingBox) ) {
            g
.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
            endAdvanced(boundingBox)
;
        }
       
    }
   
   
override public function drawBody( b : Body) 
    {
       
var b2 = b;
       
for( s in b.shapes ) {
           
var b = s.aabb;
           
if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               
continue;
           
if ( Reflect.hasField( s, '_texture' ) )
            {

                untyped s
._texture.setMatrix( b2.a, b2.x, b2.y );
            }
            drawShape(s)
;
        }
    }
   
}
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Physaxe questions

Tony Polinelli

I havent read your whole post but maybe this helps: Reflection hasField(instance)  works only for properties on instances and dynamics. Type.getInstanceFields(Type.getClass(instance)) checks methods too



On Mon, Jan 17, 2011 at 12:09 PM, [hidden email] <[hidden email]> wrote:
Sorry to bother the list further, for thread completeness I noticed that in some older flash10 players it was not working, seems Reflection hasField was not checking properly ( should I submit a compiler bug or is this expected? ), instead I found out that  Std.is( instance, myclass ) works much more reliably and allows me to cast safely without using dangerous untyped. So FlashDrawTexture is amended, the main down side is that it is now limited to PolygonTexture which limits to my current use.
But it made me think, it would be really useful to be able to define a multi type ie    
function beginAdvanced( c: MultiType<Color, Texture> ){ 
MultiTypeSwitch c
case: Color
//
case: Texture
//
}
I don't know just can be tricky when you really want to work with limited types, so not dynamic but not a single type either, specifically I think about XML and XMLlist but there are more examples.
Anyway my amended code.

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 *
@author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   
public function new( g )
    {
       
       
super( g );
       
    }
   
   
function beginAdvanced?c : Color= null, ?t: Texture = null): Bool
    {
       
if ( t != null )
        {
           
            g
.beginBitmapFill( t._source, t._matrix, true, true );
           
return true;
           
        }
       
else
        {
           
try
            {
               
return begin( c );
            }
           
catch ( e: Dynamic )
            {
               
return false;
            }
        }
       
    }
   
   
function endAdvanced( ?c : Color, ?t:Texture )
    {
       
if ( t != null )
        {
            g
.endFill();
        }
       
else
        {
           
end( c );
        }
    }
   
   
override public function drawShape( s : Shape )
    {
       
       
var t: Texture = Std.is( s, PolygonTexture )?cast( s, PolygonTexture )._texture: null;
       
if ( beginAdvanced( selectColor( s ), t ) )
        {
           
switch( s.type ) {
           
case Shape.CIRCLE: drawCircle(s.circle);
           
case Shape.POLYGON: drawPoly(s.polygon);
           
case Shape.SEGMENT: drawSegment(s.segment);
            }
            endAdvanced( selectColor(s), t  )
;
        }
       
if( beginAdvanced(boundingBox) )
        {
            g
.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
            endAdvanced(boundingBox)
;
        }
       
    }
   
   
override public function drawBody( b : Body) 
    {
       
var b2 = b;
       
var rw: Float;
       
var rh: Float;
       
for( s in b.shapes ) {
           
var b = s.aabb;
           
if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               
continue;
           
if( Std.is( s, PolygonTexture ) )
            {
                rw
= (b.r - b.l) / 2;
                rh
= ( b.b - b.t) / 2;
                cast( s, PolygonTexture )
._texture.setMatrix( b2.a, b2.x, b2.y );
            }
            drawShape( s )
;
        }
    }


_________________
    On 16 Jan 2011, at 17:39, [hidden email] wrote:

Ok I seem to have got it working, so since I bothered the the list I will post solution.

Nicolas could you consider integrating this into your engine probably in a cleaner fashion, at the moment the code is separate to avoid polluting the haxelib but ideally it would be more integrated?

So for anyone wanting to try this, here are some instructions...

With flash IDE, you need to define your vector points by putting a bitmap ( transparent png ) as a guide aligned so it is centred in a test movie ( rather than aligned top corner ), the test movie is because it's more of a pain to do it from the stage.  Add movieClips as position holders in an anticlockwise direction and then trace them out from flash IDE ( no need to name them let flash assume order and naming ) to copy into your haXe.

// as3 timeline code inside a test movieclip
var here: flash.display.MovieClip = this;
var mc: flash.display.MovieClip;
for( var i: int = 0; i < here.numChildren; i++ )
{
mc = here.getChildAt(i) as MovieClip;
trace( 'points.push(new phx.Vector(' + mc.x + ' ,' + mc.y + ' ));' );
}

( If you define them in the wrong direction, or nothing show as I did just use points.reverse() in your haxe )

Now to get the Bitmap fill working you need these three classes and a bitmap (I load mine at runtime), I won't post code as you just need to hack the standard example, but instead use my extended classes.

package physaxeExtensions;
import phx.Material;
import phx.Polygon;
import phx.Vector;

/**
 *
@author JLM at justinfront dot net
 */

class PolygonTexture extends Polygon
{
   
   
public var _texture: Texture;
   
public function new( vl : Array<Vector>, offset : Vector, ?material : Material, ?texture_: Texture = null
    {
       
_texture = texture_;
       
super( vl, offset, material );     
       
    }
   
}

______________________

package physaxeExtensions;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.BitmapData;
import flash.events.Event;

/**
 * ...
 *
@author JLM at justinfront dot net
 */

class Texture
{
   
   
public var _matrix:     Matrix;
   
public var _source:     BitmapData;
   
private var _r:         Float;
   
   
public function new( sourceBitmap: Bitmap )
    {
       
       
_matrix         = new Matrix();
        createSource( sourceBitmap )
;
       
    }
   
   
   
public function createSource( bitmap_: Bitmap )
    {
       
       
var w           = bitmap_.width;
       
var h           = bitmap_.height;
       
var d           = w /Math.sin( Math.atan2( w, h) );
       
var di          = Std.int( d );
       
_source         = new BitmapData( di, di, true, 0x00000000 );
       
_r              = d/2;
       
       
_source.copyPixels( bitmap_.bitmapData, new Rectangle( 0, 0, w, h ), new Point( ( d - w )/2, ( d - h )/2 ) );
       
    }
   
   
   
public function setMatrix( a_: Float, x_: Float, y_: Float )
    {
       
       
_matrix = new Matrix();
       
_matrix.translate( -_r, -_r );
       
_matrix.rotate( a_ );
       
_matrix.translate(  x_  ,  y_ );
   
    }
   
}

______________________

package physaxeExtensions;
import phx.Body;
import phx.FlashDraw;
import phx.Shape;
/**
 * ...
 *
@author JLM at justinfront dot net
 */

class FlashDrawTexture extends FlashDraw
{

   
public function new( g )
    {
       
       
super( g );
       
    }
   
   
function beginAdvanced?c : Color= null, ?t: Texture = null): Bool
    {
       
       
if ( t != null )
        {
           
            g
.beginBitmapFill( t._source, t._matrix, true, true );
           
return true;
           
        }
       
else
        {
           
try
            {
               
return begin( c );
            }
           
catch ( e: Dynamic )
            {
               
return false;
            }
        }
    }
   
   
function endAdvanced( ?c : Color, ?t:Texture )
    {
       
if ( t != null )
        {
            g
.endFill();
        }
       
else
        {
           
end( c );
        }
    }
   
   
override public function drawShape( s : Shape )
    {
       
var t = ( Reflect.hasField( s, '_texture' ) == true )? untyped s._texture: null;
       
       
if ( beginAdvanced( selectColor(s), t ) )
        {
           
switch( s.type ) {
           
case Shape.CIRCLE: drawCircle(s.circle);
           
case Shape.POLYGON: drawPoly(s.polygon);
           
case Shape.SEGMENT: drawSegment(s.segment);
            }
            endAdvanced( selectColor(s), t  )
;
        }
       
if( beginAdvanced(boundingBox) ) {
            g
.drawRect(s.aabb.l, s.aabb.t, s.aabb.r - s.aabb.l, s.aabb.b - s.aabb.t);
            endAdvanced(boundingBox)
;
        }
       
    }
   
   
override public function drawBody( b : Body) 
    {
       
var b2 = b;
       
for( s in b.shapes ) {
           
var b = s.aabb;
           
if( b.r < xmin || b.b < ymin || b.l > xmax || b.t > ymax )
               
continue;
           
if ( Reflect.hasField( s, '_texture' ) )
            {

                untyped s
._texture.setMatrix( b2.a, b2.x, b2.y );
            }
            drawShape(s)
;
        }
    }
   
}
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org