The example code above shows how to set the field of view (FOV) on a movie using the Direct Access API. Perspective and view settings can be applied to the root of a movie or on individual display objects. If an object returns a perspective FOV value of 0 then it will inherit the FOV value from its parent.
Perspective makes objects closer to the viewer appear larger and objects farther away appear smaller. By changing the field of view value, the strength of this effect can be controlled. The greater the value, the stronger the distortion applied to a display object moving along the z-axis. A low FOV value results in very little scaling and a high value gives the appearance of greater movement. The value must be greater than 0 and less than 180, where 1 gives almost no perspective distortion and 179 creates a distorted fish-eye lens effect.
Figure 2: Original (un-rotated) Flash image
Figure 3: With X rotation of -80 and default perspective (55 degrees)
Low FOV values (below 5) often result in a distorted effect. In order to remove the perspective effect completely, it may be better to set the object to use an orthographic projection. In ActionScript, this can be done by setting the property _perspfov to -1. In C++ it can be done two different ways using the Direct Access API:
Set Perspective FOV to -1
GFx::Value tmpVal; bool bOK = pMovie->GetVariable(&tmpVal, "root"); //”_root” for AS2 if (bOK) { GFx::Value::DisplayInfo dinfo; bOK = tmpVal.GetDisplayInfo(&dinfo); if (bOK) { dinfo.SetPerspFOV(-1); tmpVal.SetDisplayInfo(dinfo); } }
or, 2. Set the perspective matrix to an orthographic matrix
void MakeOrthogProj(const RectF &visFrameRectInTwips, Matrix4F *matPersp) { const float nearZ = 1; const float farZ = 100000; float DisplayHeight = fabsf(visFrameRectInTwips.Height()); float DisplayWidth = fabsf(visFrameRectInTwips.Width()); matPersp->OrthoRH(DisplayWidth, DisplayHeight, nearZ, farZ); } GFx::Value tmpVal; bool bOK = pMovie->GetVariable(&tmpVal, "root.mc"); if (bOK) { GFx::Value::DisplayInfo dinfo; bOK = tmpVal.GetDisplayInfo(&dinfo); if (bOK) { Matrix4F perspMat; MakeOrthogProj(PixelsToTwips (pMovie->GetVisibleFrameRect()), &perspMat); dinfo.SetProjectionMatrix3D(&perspMat); tmpVal.SetDisplayInfo(dinfo); } }
It can also be done by setting the Projection matrix directly on the movie object:
Ptr<Movie> pMovie = … // compute ortho matrix Render::Matrix4F ortho; const RectF &visFrameRectInTwips = PixelsToTwips(pMovie->GetVisibleFrameRect()); const float nearZ = 1; const float farZ = 100000; ortho.OrthoRH(fabs(visFrameRectInTwips.Width()), fabs(visFrameRectInTwips.Height()), nearZ, farZ); pMovie->SetProjectionMatrix3D(ortho);
In ActionScript 3 you can use a PerspectiveProjection object to adjust an object’s perspective.
Example:
import flash.display.Sprite; var par:Sprite = new Sprite(); par.graphics.beginFill(0xFFCC00); par.graphics.drawRect(0, 0, 100, 100); par.x = 100; par.y = 100; par.rotationX = 20; addChild(par); var chRed:Sprite = new Sprite(); chRed.graphics.beginFill(0xFF0000); chRed.graphics.drawRect(0, 0, 100, 100); chRed.x = 50; chRed.y = 50; chRed.z = 0; par.addChild(chRed); var pp3:PerspectiveProjection=new PerspectiveProjection(); pp3.fieldOfView=120; par.transform.perspectiveProjection = pp3;