<HTML> 
<HEAD>
<TITLE>DirectAnimation SDK, JScript Sample</TITLE>
<SCRIPT LANGUAGE="JScript">
<!--
if (window.top.frames.length!=0 && window.top.frames[0].ShowNoButtons!=null)
    window.top.frames[0].ShowNoButtons();
//-->
</SCRIPT>
</HEAD>	 

<BODY BGCOLOR=WHITE TOPMARGIN=15 LEFTMARGIN=20>
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2> 
<CENTER>
<H1>Perspective Images</H1>
</CENTER>
          
<OBJECT ID="DAControl"
  STYLE="position:relative; left:50; top:0;width:100%;height:100%" 
  CLASSID="CLSID:B6FFC24C-7E13-11D0-9B47-00C04FC2F51D">
</OBJECT>

<SCRIPT LANGUAGE="JScript">
<!--
m = DAControl.MeterLibrary;

// set the scale of the animation.
// 3 centimeters since in meter units.
dim = 0.03;  
dimNum = m.DANumber(dim);
zeroNum = m.DANumber(0);
oneNum = m.DANumber(1);
// a perspective camera
camera = m.PerspectiveCamera(3.5*dim, 2.9*dim);

// returns a rendering of a rotating image in 3D perspective, 
// the aspect ratios of the image are preserved.
function perspImg(img, offset, rotRate) {
  imgBBox = img.BoundingBox;
  urPt2 = imgBBox.Max;
  xNum = urPt2.X;
  yNum = urPt2.Y;
  // xscale and yscale are needed to preserve aspect ratio
  xScale = m.Cond(m.Gt(xNum, yNum), dimNum, 
                    m.Mul(m.Div(xNum, yNum), dimNum));
  yScale = m.Cond(m.Gt(yNum, xNum), dimNum, 
                    m.Mul(m.Div(yNum, xNum), dimNum));
  imgGeo = squareGeo.Texture(img.MapToUnitSquare());

  // scale, position and animating geometry. 
  // Transforms are composed from left to right order
  aniGeo = imgGeo.Transform(m.Compose3Array(new Array(
                // translate along X axis for positioning
                m.Translate3(offset, 0, 0),
                // rotate around X axis
                m.Rotate3RateDegrees(m.XVector3, rotRate),
                // translate up so bottom coincides with X axis
                m.Translate3Anim(zeroNum, yScale, zeroNum),
                // scale to preserve aspect ratio 
                m.Scale3Anim(xScale, yScale, oneNum))));

  // render the textured image with the light and camera
  return m.UnionGeometry(aniGeo, m.AmbientLight).Render(camera);
}

mediaBase = "..\\..\\..\\..\\media\\";
geoBase = mediaBase + "geometry\\";
imgBase = mediaBase + "image\\";
squareGeo = m.ImportGeometry(geoBase + "square.x");
horImg = m.ImportImage(imgBase + "foliageUtah.jpg");
verImg = m.ImportImage(imgBase + "kidsUtah.jpg");

finalImg = m.Overlay(perspImg(horImg, dim, 90), perspImg(verImg, -dim, 60));


DAControl.Image = finalImg;     
     
// start the animation       
DAControl.Start();

//-->
</SCRIPT>
</BODY>
</HTML>
