home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- ADOBE SYSTEMS INCORPORATED
- Copyright 2002 Adobe Systems Incorporated
- All Rights Reserved
-
- NOTICE: Adobe permits you to use, modify, and distribute this
- file in accordance with the terms of the Adobe license agreement
- accompanying it. If you have received this file from a source
- other than Adobe, then your use, modification, or distribution
- of it requires the prior written permission of Adobe.
- ***************************************************************/
- /***************************************************************
- Author: Mary Obelnicki
- ***************************************************************/
-
- /***************************************************************
-
- This function creates the illusion of a simple camera with no
- concept of clipping. It sets up a pseudo-3d perception of 2-d
- objects. Object disapear behind the eye because the math works
- out to set their scales to negative numbers, which actually sets
- the scale to 0. The view plan is always at z=0;
-
- Functions:
-
- Camera.perspectiveSetup(object, forAnimation, oriZ)
- This function sets up an object to have perspective transforms
- applied to it. Basicly saving the scale of the object when z=0;
- this function does not perform the perspective transformation
- on the object.
-
- Arguments:
- <object> the object to setup.
- <forAnimation> boolean.
- true: perspective for animation, turn on relavant
- stopwatches
- false: no stopwatch changes. You can still
- set stop watches outside this function.
- <oriZ> the z coordinate for the objects current location,
- so that all objects do not have to start out at z=0.
- This is an optional argument. The assumed oriZ is 0.
-
- Camera.perspectiveTransform(object, pos3d)
- This changes the position and scale of <object> to reflect
- a perspective transform of <object> from <position3d> to the
- view plane of the camera.
-
- Arguments:
- <object> the object to be transformed
- <pos3d> a vector for the new 3d position of the object
-
- ***************************************************************/
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
-
- #include "Vector.js"
-
- function Camera(inEye)
- //inEye: a vector to the position of the eye
- {
- this.eye = inEye.copy();
- this.zs = 0;
- }
-
- new Camera(new Vector(0, 0, 0));
-
-
- Camera.prototype.perspectiveSetup =
- function(object, forAnimation, oriZ)
- //a function that sets up an object to have perspective transforms
- //applied to it. Basicly saving the scale of the object when z = 0;
- //this function does not do the perspective transformation on the
- //object.
-
- //object: the object to setup.
- //forAnimation: a bool, true: perspective for animation, turn on relavant stopwatches
- // false: no stopwatch changes. A convenience, you can set stop watches
- // out side this function.
- //oriZ: the z coordinate for the objects current location, so that
- // all objects do not have to start out at z = 0. If unprovied,
- // oriZ = 0;
- {
- if(forAnimation)
- {
- object.stopwatch.position = true;
- object.stopwatch.scale = true;
- }
-
- // test for the optional arguement
- if(arguments.length == 3)
- {
- var pScale = (oriZ-this.eye.z)/(this.zs-this.eye.z);
- }
- else
- {
- var pScale = 1;
- }
- object.oriScale = new Object();
- object.oriScale.x = pScale*(object.scale.x);
- object.oriScale.y = pScale*(object.scale.y);
- }
-
-
- Camera.prototype.perspectiveTransform =
- function(object, pos3d)
- //changes the position and scale of <object> to reflect a perspective
- //transform of <object> from <position3d> to the view plane of the
- //camera.
- //object: the object to be transformed
- //pos3d: a vector for the new 3d position of the object
- {
- if(pos3d.z > this.eye.z) // the object is in front of the eye
- {
- var xs = this.eye.x + ((pos3d.x-this.eye.x)*(this.zs-this.eye.z)/(pos3d.z-this.eye.z));
- var ys = this.eye.y + ((pos3d.y-this.eye.y)*(this.zs-this.eye.z)/(pos3d.z-this.eye.z));
-
- var pScale = (this.zs-this.eye.z)/(pos3d.z-this.eye.z);
-
- //into screen coordinates
- object.scale.x = object.oriScale.x * pScale;
- object.scale.y = object.oriScale.y * pScale;
- object.position.x = xs;
- object.position.y = ys;
- }
- else // the object is behind the eye... this should do something more than avoid the question.
- {
-
- }
-
-
- }
-
-
-
-
-