{"id":359,"date":"2009-07-27T11:58:14","date_gmt":"2009-07-27T18:58:14","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1854"},"modified":"2009-07-27T11:58:14","modified_gmt":"2009-07-27T18:58:14","slug":"spring-perspectiveprojection","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=359","title":{"rendered":"Spring PerspectiveProjection"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar pointNum:int = 3000;\r\nx = stage.stageWidth \/ 2;\r\ny = stage.stageHeight \/ 2;\r\n\r\nvar verts:Vector.&lt;Number&gt;  = new Vector.&lt;Number&gt;();\r\nvar tVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar uv:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar cmds:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();\r\n\r\nvar index:int = 0;\r\nvar half:Number = pointNum \/ 20000;\r\nfor (var i:int = 0; i&lt;pointNum; i+=3){\r\n\tverts&#x5B;i] = 0.08 * Math.cos(i * Math.PI \/ 180);\r\n\tverts&#x5B;i+1] = 0.08 * Math.sin(i * Math.PI \/ 180);\r\n\tverts&#x5B;i+2] =  i \/ 10000 - half;\r\n\tcmds&#x5B;index++] = 2;\r\n}\r\ncmds&#x5B;0] = 1;\r\n\r\nvar proj:PerspectiveProjection = new PerspectiveProjection();\r\nproj.fieldOfView = 45;\r\nvar projMat:Matrix3D = proj.toMatrix3D();\r\nvar m:Matrix3D = new Matrix3D();\r\nvar dx:Number = 0, dy:Number = 0;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n       m.identity();\r\n\t   dx += (mouseX - dx) \/ 4;\r\n\t   dy += (mouseY - dy) \/ 4;\r\n\t   m.appendRotation(dy,Vector3D.X_AXIS);\r\n\t   m.appendRotation(dx,Vector3D.Y_AXIS);\r\n\t   m.appendTranslation(0,0,0.5);\r\n\t   m.transformVectors(verts, tVerts);\r\n\t   Utils3D.projectVectors(projMat, tVerts, pVerts, uv);\r\n\t   graphics.clear();\r\n\t   graphics.lineStyle(3,0x000000);\r\n\t   graphics.drawPath(cmds, pVerts);\r\n}\r\n<\/pre>\n<p>This snippet draws a spring shape in 3D with perspective. This is the first snippet where I&#8217;ve made use of the PerspectiveProjection class. So if your wondering how to add perspective to your Utils3D.projectVectors code&#8230; this is one way to do it&#8230;<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/spring_perspective.html\" target=\"blank\"><br \/>\nHave a look at the swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/spring.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/spring_perspective.swf&quot;,&quot;title&quot;:&quot;spring perspective&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\">: spring perspective<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var pointNum:int = 3000; x = stage.stageWidth \/ 2; y = stage.stageHeight \/ 2; var verts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var tVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var uv:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var cmds:Vector.&lt;int&gt; = new Vector.&lt;int&gt;(); var index:int = 0; var half:Number = pointNum \/ 20000; for (var i:int = 0; i&lt;pointNum; [&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,118,96],"tags":[3,14,4],"class_list":["post-359","post","type-post","status-publish","format-standard","hentry","category-3d","category-graphics","category-matrix","category-video","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/359","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=359"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}