MouseEngineLoopStrip Actionscript

Table of contents | Previous document | Download MouseEngineLoopStrip.as | SWF!T Homepage

RCSfile: MouseEngineLoopStrip.as,v  Revision: 1.1  Date: 2003/02/13 21:23:47  

Copyright 2003 Orgdot AS. All Rights Reserved. http://dev.swfit.com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


Generates several mouse xy values with delays and bounce. See MouseEngineInit for further information.
author      Olaf Havnes
version     Revision: 1.1  Date: 2003/02/13 21:23:47  
since       SWFIT1.0


Get the mouse x position.

The real mouse x position

old_x = x;
x = _x;

The clipped mouse x position

if (x < /:x_min) cl_x = /:x_min;
else if (x > /:x_max) cl_x = /:x_max;
else cl_x = x;

The delayed mouse x position

dc_x = (dc_x * /:delay + cl_x) / (/:delay + 1);

Repeat for y.

The real mouse y position

old_y = y;
y = _y;

The clipped mouse y position

if (y < /:y_min) cl_y = /:y_min;
else if (y > /:y_max) cl_y = /:y_max;
else cl_y = y;

The delayed mouse y position

dc_y = (dc_y * /:delay + cl_y) / (/:delay + 1);


The camera model uses the delayed-clipped mouse values, producing values between - 1 and 1 for camera-position, reversing the sign for the y-values (+ is now up).

cam_x =   dc_x / /:cw_2 + /:xwa;
cam_y = - dc_y / /:ch_2 + /:ywa;

Pre-compute

cam_x2 = cam_x * cam_x;
cam_y2 = cam_y * cam_y;
cam_z2 = cam_len_sq - cam_x2 - cam_y2;

Iterate just once through Newton's method. I doubt anybody is able to move the

mouse quick enough to produce a significant error on this value, especially since

the camera uses the delayed mouse values.

cam_z = (cam_z + cam_z2 / cam_z) / 2;

Store in _level0.

/:camera_x = cam_x;
/:camera_y = cam_y;
/:camera_z = cam_z;