Archive for the tag 'Snippets'
Posted by Riccardo on February 7, 2011 under Actionscript 3, Flash, Papervision 3D, Snippets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| package com.rblab.framework.papervision { import org.papervision3d.cameras.Camera3D; import org.papervision3d.cameras.CameraType; import org.papervision3d.cameras.DebugCamera3D; import org.papervision3d.cameras.SpringCamera3D; import org.papervision3d.core.proto.CameraObject3D; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import flash.display.Sprite; /** * @author Riccardo Bartoli */ public class PapervisionView extends Sprite { //-------------------------------------------------------------------------- // // Private properties // //-------------------------------------------------------------------------- private var _viewportWidth : Number; private var _viewportHeight : Number; private var _scaleToStage : Boolean; private var _interactive : Boolean; private var _cameraType : String; //-------------------------------------------------------------------------- // // Protected properties // //-------------------------------------------------------------------------- protected var scene : Scene3D; protected var viewport : Viewport3D; protected var renderer : BasicRenderEngine; protected var camera : CameraObject3D; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- public function PapervisionView(viewportWidth : Number, viewportHeight : Number, scaleToStage : Boolean, interactive : Boolean, cameraType : String) { this._viewportWidth = viewportWidth; this._viewportHeight = viewportHeight; this._scaleToStage = scaleToStage; this._interactive = interactive; this._cameraType = cameraType; init(); } //-------------------------------------------------------------------------- // // Private methods // //-------------------------------------------------------------------------- private function init() : void { setupScene(); setupCamera(_cameraType); setupPapervision(); } private function setupScene() : void { scene = new Scene3D(); viewport = new Viewport3D(_viewportWidth, _viewportHeight, _scaleToStage, _interactive); addChild(viewport); renderer = new BasicRenderEngine(); } private function setupCamera(cameraType : String) : void { switch(cameraType) { case CameraType.DEBUG: camera = new DebugCamera3D(viewport); break; case CameraType.TARGET: camera = new Camera3D(60); camera.target = DisplayObject3D.ZERO; break; case CameraType.SPRING: camera = new SpringCamera3D(); camera.target = DisplayObject3D.ZERO; break; case CameraType.FREE: default: camera = new Camera3D(60); break; } camera.focus = 100; camera.z = -1000; camera.zoom = 10; } private function setupPapervision() : void { viewport.buttonMode = _interactive; viewport.interactive = _interactive; } //-------------------------------------------------------------------------- // // Protected methods // //-------------------------------------------------------------------------- protected function render() : void { renderer.renderScene(scene, camera, viewport); } } } |
Tags: Actionscript 3, as3, as3 flash, papervision, snippet, Snippets
Posted by Riccardo on February 2, 2011 under Actionscript 3, Flash, Snippets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| /** Distribute the points clockwise around the circle. */ public static const CLOCKWISE : String = "clockwise"; /** Distribute the points counterclockwise around the circle. */ public static const COUNTERCLOCKWISE : String = "counterclockwise"; /** * This method accepts arguments based on the size and position of your circle * along with the amount of points to distribute around the circle, * what angle to start the first point, which direction to plot the points, * how much of the circumference to use for the distribution, and which direction * around the circle to plot the points. * @example example: * * @param centerx The center x position of the circle to place the points around. * @param centery The center y position of the circle to place the points around. * @param radi The radius of the circle to distribute the points around. * @param total The total amount of point to distribute around the circle. * @param startangle [Optional] The starting angle of the first point. This is based on the 0-360 range. * @param arc [Optional] The length of distribution around the circle to evenly distribute the points. This is based on 0-360. * @param dir [Optional] This determines the direction that the points will distribute around the circle. * @param evenDist [Optional] If set to true, AND if you're arc angle is less than 360, this will evently distribute the points around the circle.<br/>If set to true, the points are visually arranged in this manner POINT-SPACE-POINT-SPACE-POINT, if set to false, an extra space will be added after the last point: POINT-SPACE-POINT-SPACE-POINT-SPACE * * @return Returns an Array containing Points. */ public static function getPointsAroundCircumference(centerx : Number, centery : Number, circleradius : Number, totalpoints : int, startangle : Number = 0, arc : int = 360, pointdirection : String = "clockwise", evendistribution : Boolean = true) : Array { var mpi : Number = Math.PI / 180; var startRadians : Number = startangle * mpi; var incrementAngle : Number = arc / totalpoints; var incrementRadians : Number = incrementAngle * mpi; if(arc < 360) { // this spreads the points out evenly across the arc if(evendistribution) { incrementAngle = arc / (totalpoints - 1); incrementRadians = incrementAngle * mpi; } else { incrementAngle = arc / totalpoints; incrementRadians = incrementAngle * mpi; } } var pts : Array = []; while(totalpoints--) { var xp : Number = centerx + Math.sin(startRadians) * circleradius; var yp : Number = centery + Math.cos(startRadians) * circleradius; var pt : Object = new Object(); pt.x = xp; pt.y = yp; pt.angle = startRadians; pts.push(pt); if(pointdirection == COUNTERCLOCKWISE) { startRadians += incrementRadians; } else { startRadians -= incrementRadians; } } return pts; } |
Tags: Actionscript 3, as3, Flash, snippet, Snippets
Posted by Riccardo on February 2, 2011 under Actionscript 3, Flash, Snippets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public static function grid(columns : int, rows : int, xSpacing : int, ySpacing : int, xPadding : int, yPadding : int, leftToRight : Boolean = true) : Vector.<Point> { var points : Vector.<Point> = new Vector.<Point>(); var pt : Point; var row : Number; var col : Number; var num : int = (columns * rows); for (var i : int = 0;i < num;i++) { pt = new Point(); if (leftToRight) { row = (i % columns); col = Math.floor(i / columns); pt.x = (row * (xSpacing + xPadding)); pt.y = (col * (ySpacing + yPadding)); } else { row = (i % rows); col = Math.floor(i / rows); pt.x = (col * (xSpacing + xPadding)); pt.y = (row * (ySpacing + yPadding)); } points.push(pt); } return points; } |
Tags: Actionscript 3, as3, as3 flash, Flash, snippet, Snippets
« Previous Page — Next Page »