Perspective Projection

I would like to reuse an AS3 class called Perspective Sprite…and it does, what it says: transform the 3D matrix of a sprite.

The class PerspectiveSprite extends Sprite
Here is the part that I can´t get converted:

var pp:PerspectiveProjection = new PerspectiveProjection();
pp.projectionCenter = new Point (640, 400);
transform.perspectiveProjection = pp;

var v:Array<Float> = _container3d.transform.matrix3D.rawData;

var cx:Float = transform.perspectiveProjection.projectionCenter.x;
var cy:Float = transform.perspectiveProjection.projectionCenter.y;
var cz:Float = transform.perspectiveProjection.focalLength;

The Error Message is the following
src/PerspectiveSprite.hx:59: characters 3-46 : openfl.geom.Transform has no field perspectiveProjection

The OpenFL documentation says:
…Or, apply different perspective
projection properties to a display object by setting the perspective
projection properties of the display object’s parent. The child display
object inherits the new properties. Specifically, create a
PerspectiveProjection object and set its properties, then assign the
PerspectiveProjection object to the perspectiveProjection
property of the parent display object’s transform property.
The specified projection transformation then applies to all the display
object’s three-dimensional children.

see here: http://www.openfl.org/documentation/api/openfl/geom/Transform.html

I do not really understand this.
Is the “perspectiveProjection” property supported? Do I have to use it like this ? "parent.transform.perspectiveProjection"
Nothing seems to work for me. Any idea?

It’s not in the doc (the link you included) so it’s not supported.

Thanks for the reply.
Any suggestions how to go on with this?
Is it possible to put it on the wishlist? And is there any?
What could be an alternative? I guess using awayJS is a big overload for transforming a 4 corner plane. That´s all I need.

Can this be done with a 2D transform? GL view?

Can’t be done with 2D transform, but with 3D transform it’s possible (at least for flash because it seems the native and html5 renderers don’t use it, right?). So I guess for native and html5, we should use GLView but I don’t know how to do it yet.

Here is an example of a perspective projection for matrix 3D working in flash :

`
sprite.transform.matrix3D = new Matrix3D();
sprite.transform.matrix3D.appendTranslation( -sprite.width / 2, -sprite.height / 2, 0);
sprite.transform.matrix3D.appendRotation(-45, Vector3D.X_AXIS);

//your sprite will have a perspective like this:

   ______

 __________

`

Missing PerspectiveProjection class is the reason I had to rewrite my code from Haxe-OpenFL back to pure AS3.

Vote for adding this class to the library (only for flash compatibility) sometime in the future. Without it you cannot avoid some flash engine bugs with 3D rotation (like image deformation).

You can split code into 2 Viewer Classes to avoid backporting all,
i only use Lime GL last years for such stuff, but why not Stage3D for flashcompatibility…(or is it for hardware without 3d-accelerated-gpu support?)

opengl includes all that matrix-ops to be happy for a long time :slight_smile:

I would love to see PerspectiveProjection with all methods, if you see anything that is unimplemented, don’t assume it’s because we don’t want it – it just hasn’t happened yet

I want to focus more deeply on the Flash 3D APIs

How do you do that?

It is now present in OpenFL 4.0 (http://api.openfl.org/openfl/geom/PerspectiveProjection.html)?

you can write MyView.hx wrapper like:

package;

#if flash
      typedef MyView = flash.MyView;
#else
      typedef MyView = noflash.MyView;
#end

and 2 MyView Classes with same named public methods() and properties
in subfolders: flash/MyView.hx and noflash/MyView.hx

1 Like