/* ** Copyright (C) 2005 Antonin Stefanutti ** ** 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. */ ///////////////////////////////////////////////////////////////////////////////////////// //an instance of this class is an object and a MovieClip to handle the mouse events class Object3D extends MovieClip { //vertices array public var node:Array; //faces array (convex polygons) public var poly:Array; //object color public var color:Number; //ambient, diffuse & specular coefficients public var Ka:Number; public var Kd:Number; public var Ks:Number; //backface culing status public var bfc:Boolean; ///////////////////////////////////////////////////////////////////////////////////////// //constructor function Object3D() { } ///////////////////////////////////////////////////////////////////////////////////////// //render function i.e. render all the faces of this object public function render():Void { for (var i in poly) poly[i].render(); } ///////////////////////////////////////////////////////////////////////////////////////// //scale this object by scale factors (sx,sy,sz) with pivot = point(0) //(sx,sy,sz) = (1,1,1) <=> identity public function sclx0(sx:Number, sy:Number, sz:Number):Void { for (var i in node) { node[i].x *= sx; node[i].y *= sy; node[i].z *= sz; } for (var i in poly) { poly[i].P.sclx0(sx,sy,sz); } } ///////////////////////////////////////////////////////////////////////////////////////// //rotate this object around the 3 reference axis (i,j,k) by angles (a,b,c) public function rotEx0(a:Number, b:Number, c:Number):Void { var ca:Number = Math.cos(a); var sa:Number = Math.sin(a); var cb:Number = Math.cos(b); var sb:Number = Math.sin(b); var cc:Number = Math.cos(c); var sc:Number = Math.sin(c); for (var i in node) { node[i].rotmEx0(ca, sa, cb, sb, cc, sc); } for (var i in poly) { poly[i].P.rotmEx0(ca, sa, cb, sb, cc, sc); } } ///////////////////////////////////////////////////////////////////////////////////////// //spin this point of angle w (radian) around affine axis defined by point(0) + vector(q) public function rotQx0(w:Number, q:Point3D):Void { var sw:Number = Math.sin(w/2); var cw:Number = Math.cos(w/2); var cx:Number = sw*q.x; var cy:Number = sw*q.y; var cz:Number = sw*q.z; for (var i in node) { node[i].rotmQx0(sw,cw,cx,cy,cz); } for (var i in poly) { poly[i].P.rotmQx0(sw,cw,cx,cy,cz); } } ///////////////////////////////////////////////////////////////////////////////////////// }