this was the start of a project, which I cannot really
give the final code out for, but it was in a previous version
of Papervision anyway - so I have just made it compile as
some of the methods and classes have changed - hack away and
make it something more interesting.
gingerman
/**
* Copyright gingerman ( http://wonderfl.net/user/gingerman )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/srJ0
*/
// forked from gingerman's flash on 2010-4-8
// this was the start of a project, which I cannot really
// give the final code out for, but it was in a previous version
// of Papervision anyway - so I have just made it compile as
// some of the methods and classes have changed - hack away and
// make it something more interesting.
// gingerman
package {
//import flash.display.BitmapData;
import flash.display.*;
import flash.events.*;
// Import Papervision3D
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Max3DS;
import org.papervision3d.cameras.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.utils.*;
//import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
// this is all very distorted - I cannot help thinking some numbers are too big :)
public class Main extends Sprite {
//private var container :Sprite;
private var oViewport:Viewport3D;
private var oFcamera:Camera3D;
private var renderer:BasicRenderEngine = new BasicRenderEngine();
private var oScene:Scene3D;
private var oContainer:DisplayObject3D=new DisplayObject3D("oCont");
private var num:Number=0;
private var oPlane:Plane;
public var points:Number;
public var paperSize:Number=10;
//
private var nRotationSpeed:Number=5;
public function Main() {
trace("Main");
stage.quality=StageQuality.BEST;
init3D();
}
public function init3D():void {
trace( "init3D v1" );
oViewport=new Viewport3D(200,200,true,false);
addChild( oViewport );
var renderer:BasicRenderEngine = new BasicRenderEngine();
oScene = new Scene3D();
oFcamera=new Camera3D(-80);
///
//var mat:ColorMaterial=new ColorMaterial(700000,0.5,true);
//mat.doubleSided= false;
//mat.updateBitmap();
makeCyinderOutOfPlanes( 8, 10, 40000 );
oScene.addChild( oContainer );
oFcamera.x= 0;
oFcamera.y= 0;
oFcamera.z= -60000;
///oFcamera.rotationX=-25;//10;
//Then, when you want to render:
oContainer.z=0;
oContainer.y=0;
this.addEventListener( Event.ENTER_FRAME, loop );
}
public function get randomAlpha():Number{
var randomAlpha:Number = Math.random(); return randomAlpha;
}
public function get randomColour():Number{
var randomCol:Number = Math.round( Math.random() * 0xFFFFFF );
return randomCol;
}
public function makeRandomColouredMat( alpha:Number = 0.5 ):ColorMaterial
{
var mat:ColorMaterial=new ColorMaterial( randomColour ,randomAlpha,true); mat.doubleSided=true; mat.updateBitmap();
return mat;
}
public function makeCyinderOutOfPlanes( numberOfPlanes:Number, yPos:Number, rad:Number ):void {
for (var p:Number = 0; p < numberOfPlanes; p++) {
var oThisPlaneObject:Plane=new Plane( makeRandomColouredMat( 0.5 ) ,55,0,4,4);
//
var planesProps:Array=calculatePlaneProperties(p,numberOfPlanes,rad);
//
oThisPlaneObject.x=planesProps[0];
oThisPlaneObject.y=yPos;
oThisPlaneObject.z=planesProps[1];
var newRotY:Number = ( ( 360 / numberOfPlanes ) * p ) ;
oThisPlaneObject.rotationY = newRotY + 90;
oThisPlaneObject.rotationX = 10;
// add plane to container
oContainer.addChild( oThisPlaneObject );
}
}
public function calculatePlaneProperties( planeNumber:Number, totalPlanes:Number, nRadius:Number ):Array {
var planePropsArray:Array = new Array();
var rotscaler:Number=2;// could not think of a better variable name =D steve
var qAngle:Number= ( Math.PI*rotscaler/totalPlanes ) ;
// translate the circular motion and position of the clip in question into distance
var newx:Number = - ( nRadius * Math.cos( qAngle * planeNumber ) );
var newz:Number=nRadius*Math.sin(qAngle*planeNumber);
// to do
// calc newx and newy's position in relation
// to x= 0 and y = 0 to get a preoper rotation value
//var newr = calculateRotationOfClip( newx, newz );
//trace( "\n >newx = " + newx + " >newz = " + newz + " >newr = " + newr );
planePropsArray=new Array(newx,newz);//, newr );
return planePropsArray;
}
private function loop(event:Event):void {
num = num + 1;
//oContainer.rotationZ = oContainer.rotationZ+ 3; //
oContainer.rotationY=oContainer.rotationY+nRotationSpeed;
renderer.renderScene(oScene, oFcamera, oViewport);
//oContainer.rotationZ=oContainer.rotationZ+4
}
// gitters n sitters
public function set rotationSpeed( rs:Number ):void {
nRotationSpeed=rs;
}
public function get rotationSpeed():Number {
return nRotationSpeed;
}
// end of class
}
// end of package
}