class scena implements axon { private var obiecte:Array; private var poly:Array; private var i:Number; private var clip:MovieClip; private static var m = 1; public var f:Number; public var boundMax, boundMin:Number; private var quat:quaternion; // public var x,y,z,o:point; public var cameraPos,lookAt:point; public var u,v,w:point; public var angle; public var cam:camera; // public function scena() { obiecte = new Array(); f = 200; boundMax = 640; boundMin = 160; quat = new quaternion(); o = new point(0,0,0); x = new point(1,0,0); y = new point(0,1,0); z = new point(0,0,1); cameraPos = new point(500,500,500); lookAt = new point(0,0,0); w = new point(0,0,0); u = new point(0,0,0); v = new point(0,0,0); angle = 50; cam = new camera(); viewBase(); } public function set mc(a:MovieClip) { clip = a; } public function get _quat():quaternion { return quat; } public function adaugaObiect(a:axon) { obiecte.push(a); } public function addPoly(a:poligon):Void { poly.push(a); } public function camRotate(q:quaternion):Void { cam.rotate(q); } /////////////////////////////////////////////////////////////////// public function viewBase() { //calculeaza coordonatele sistemului de axe al camerei in functie de lookAt si camerPos, evident dependenet de coordonatele globale. w.x = cameraPos.x - lookAt.x; w.y = cameraPos.y - lookAt.y; w.z = cameraPos.z - lookAt.z; var ding = Math.sqrt(w.x*w.x + w.y * w.y + w.z * w.z); w.x /= ding; w.y /= ding; w.z/=ding; u.x = y.y * w.z - y.z * w.y; u.y = y.z * w.x - y.x * w.z; u.z = y.x * w.y - y.y * w.x; ding = Math.sqrt(u.x*u.x + u.y * u.y + u.z * u.z); u.x /= ding; u.y /= ding; u.z/=ding; v.x = w.y * u.z - w.z * u.y; v.y = w.z * u.x - w.x * u.z; v.z = w.x * u.y - w.y * u.x; cam.u = u; cam.v = v; cam.w = w; cam.c = cameraPos; } /////////////////////////////////////////////////////////////////// //creeaza mc-uri vide pentru poligoane. public function generateMC():MovieClip { var ret = _root.createEmptyMovieClip("mc" + m, m + 1); m++; return ret; } public function calcPoint():point { var t = new point(); //( A.x , A.y , A.z ) X ( B.x , B.y , B.z ) = ( A.y * B.z - A.z * B.y , A.z * B.x - A.x * B.z , A.x * B.y - A.y * B.x) //nu uita sa normalizezi altfel iese urat. //cross product intre view vector[w] = cameraPos - lookAt si (0,1,0); t.x = -w.z; t.y = 0; t.z = w.x; return t; } private function mInBounds():Boolean { if((_root._xmouse < boundMin)||(_root._xmouse > boundMax)||(_root.ymouse < boundMin) || (_root._ymouse > boundMax)) return false; return true; } public function deseneaza():Void { if(_root.mouseFeed) { if(mInBounds()){ cameraPos.x = 2*(_root._xmouse - 400); cameraPos.y = 2*(_root._ymouse - 400); }} _root.cpos.text = "Camera Position: x: " + Math.round(cameraPos.x) + ", y: " + Math.round(cameraPos.y) + ", z: " + Math.round(cameraPos.z); _root.lat.text = "Look At: x: " + lookAt.x + ", y: " + lookAt.y + ", z: " + lookAt.z; viewBase(); for (i = 0; i < obiecte.length; i++) { obiecte[i].deseneaza(); } } }