{"id":354,"date":"2009-07-22T06:41:14","date_gmt":"2009-07-22T13:41:14","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1818"},"modified":"2009-07-22T06:41:14","modified_gmt":"2009-07-22T13:41:14","slug":"transformvectors-and-drawpath","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=354","title":{"rendered":"transformVectors() and drawPath()"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar squareNum:int  = 100;\r\n\/\/ verts defines a single square\r\nvar verts:Vector.&lt;Number&gt; = Vector.&lt;Number&gt;(&#x5B;-20, 0, 0, 20, 0, 0, 20, 0, 40, -20, 0, 40, -20, 0, 0]);\r\nvar cmds:Vector.&lt;int&gt; = Vector.&lt;int&gt;(&#x5B;1,2,2,2,2]);\r\nvar tempVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar newVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(10 * squareNum);\r\nvar uv:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(15 * squareNum);\r\n\r\nvar m:Matrix3D = new Matrix3D();\r\n\r\n\/\/ duplicate the verts array a bunch of times\r\n\/\/ each time randomly rotating, scaling and translating it\r\nfor (var i:int = 0; i&lt;squareNum; i++){\r\n\tm.identity();\r\n\tm.appendRotation(Math.random()*360,Vector3D.X_AXIS);\r\n\tm.appendRotation(Math.random()*360,Vector3D.Y_AXIS);\r\n\tm.appendRotation(Math.random()*360,Vector3D.Z_AXIS);\r\n\tvar s:Number = Math.random()*2 + .1;\r\n    m.appendScale(s, s, s);\r\n\tm.appendTranslation(Math.random()*400 - 200, Math.random()*400 - 200, Math.random()*400 - 200);\r\n\tm.transformVectors(verts,tempVerts);\r\n\tnewVerts = newVerts.concat(tempVerts);\r\n\tcmds = cmds.concat(Vector.&lt;int&gt;(&#x5B;1,2,2,2,2]));\r\n}\r\nnewVerts.fixed = pVerts.fixed = uv.fixed = true;\r\n\r\nvar dx:Number = 0, dy:Number = 0;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n       dx += (mouseX - dx) \/ 4;\r\n\t   dy += (mouseY - dy) \/ 4;\r\n\t   \r\n       m.identity();\r\n       m.appendRotation(dx,Vector3D.Z_AXIS);\r\n       m.appendRotation(dy,Vector3D.X_AXIS);\r\n\t   m.appendTranslation(stage.stageWidth \/ 2,stage.stageHeight \/ 2, 0);\r\n\r\n       Utils3D.projectVectors(m, newVerts, pVerts, uv);\r\n\t   \r\n\t   graphics.clear();\r\n\t   graphics.lineStyle(0,0x000000);\r\n\t   graphics.drawPath(cmds, pVerts);\r\n}\r\n<\/pre>\n<p>This is a demo showing how to use transformVectors() and drawPath() together. It creates 100 wireframe squares in 3D:<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/drawpath_squares.html\" target=\"blank\"><br \/>\nHave a look at the swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/squares.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/drawpath_squares.swf&quot;,&quot;title&quot;:&quot;drawpath squares&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: drawpath squares<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var squareNum:int = 100; \/\/ verts defines a single square var verts:Vector.&lt;Number&gt; = Vector.&lt;Number&gt;(&#x5B;-20, 0, 0, 20, 0, 0, 20, 0, 40, -20, 0, 40, -20, 0, 0]); var cmds:Vector.&lt;int&gt; = Vector.&lt;int&gt;(&#x5B;1,2,2,2,2]); var tempVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var newVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(10 * squareNum); var uv:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(15 * [&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,33,79],"tags":[],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-3d","category-graphics","category-vector"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/354","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=354"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}