{"id":250,"date":"2009-04-12T20:23:25","date_gmt":"2009-04-13T03:23:25","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1154"},"modified":"2009-04-12T20:23:25","modified_gmt":"2009-04-13T03:23:25","slug":"utils3dprojectvectors-100000-pixels","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=250","title":{"rendered":"Utils3D.projectVectors() &#038; 100,000 pixels"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar matrix:Matrix3D = new Matrix3D();\r\n\r\nconst PARTICLE_NUM:int = 100000;\r\nvar verts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar uvts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\n\r\nfor (var i:int = 0; i&lt;PARTICLE_NUM; i++){\r\n\tverts.push(Math.random()*250 - 125);\r\n\tverts.push(Math.random()*250 - 125);\r\n\tverts.push(Math.random()*250 - 125);\r\n\t\r\n\tpVerts.push(0), pVerts.push(0);\r\n\tuvts.push(0), uvts.push(0), uvts.push(0);\r\n}\r\n\r\nvar canvas:BitmapData = new BitmapData(400,400,false, 0x000000);\r\naddChild(new Bitmap(canvas));\r\nvar dx:Number=0;\r\nvar dy:Number=0;\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\r\n\tdx += (mouseX - dx)\/4;\r\n\tdy += (mouseY - dy)\/4;\r\n\t\r\n\tmatrix.identity();\r\n\tmatrix.appendRotation(dy,Vector3D.X_AXIS);\r\n\tmatrix.appendRotation(dx,Vector3D.Y_AXIS);\r\n\tmatrix.appendTranslation(200, 200, 0);\r\n\t\r\n\tUtils3D.projectVectors(matrix, verts, pVerts, uvts);\r\n\t\r\n\tcanvas.lock();\r\n\tcanvas.fillRect(canvas.rect, 0x000000);\r\n        var leng:int = pVerts.length;\r\n\tfor (var i:int = 0; i&lt;leng; i+=2){\r\n\t\tcanvas.setPixel( pVerts&#x5B;i], pVerts&#x5B;i + 1], 0xFFFFFF);\r\n\t}\r\n\tcanvas.unlock();\r\n}\r\n<\/pre>\n<p>The above shows an easy way to use Utils3D.projectVectors() to move some pixels around in 3D. Since the 3D math is done behind the scenes by the flash player it runs quite fast&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var matrix:Matrix3D = new Matrix3D(); const PARTICLE_NUM:int = 100000; var verts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var uvts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); for (var i:int = 0; i&lt;PARTICLE_NUM; i++){ verts.push(Math.random()*250 &#8211; 125); verts.push(Math.random()*250 &#8211; 125); verts.push(Math.random()*250 &#8211; 125); pVerts.push(0), pVerts.push(0); uvts.push(0), uvts.push(0), uvts.push(0); } var canvas:BitmapData = new BitmapData(400,400,false, 0x000000); addChild(new Bitmap(canvas)); var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,24,118,26,79],"tags":[3,4],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-3d","category-bitmapdata","category-matrix","category-setpixel","category-vector","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}