[Papervision3D] camera position inside a ring of planes
Aurelplouf
aurelplouf at gmail.com
Mon Oct 13 02:10:43 PDT 2008
Hello everyone,
I am currently creating a sort of ring with 5 planes, and based on the mouse
position, the camera moves around the ring.
My problem right now is that my camera is outside of the ring and I wish to
put the camera inside the ring instead.
Thank you for your help
my code :
package {
import flash.display.*;
import flash.display.Sprite;
import flash.net.*;
import flash.events.Event;
import flash.events.MouseEvent;
import gs.TweenMax;
import gs.easing.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.materials.*;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.core.proto.*;
import org.papervision3d.events.InteractiveScene3DEvent;
public class planeTest extends Sprite{
public var scene:Scene3D;
public var camera:Camera3D;
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var planeA:Plane;
public var planeB:Plane;
public var planeC:Plane;
public var planeD:Plane;
public var planeE:Plane;
private var planeContainer:DisplayObject3D;
public var materialA:MovieMaterial;
public var mcAsset:mcContainer;
//Spiral properties
public var num:int = 5;
public var numOfRotations:Number = 1;
public var anglePer:Number = ((Math.PI*2)*numOfRotations) / num;
public var yPos:Number = 0;
// spiral movement properties
public var angle:Number = 0;
public var dist:Number;
// create camera center
public var pc:Plane;
public function planeTest() {
init();
}
private function init(vpWidth:Number = 1440, vpHeight:Number = 750):void {
initPapervision(vpWidth,vpHeight);
initMaterials();
initObjects();
initListeners();
}
private function initPapervision(vpWidth:Number, vpHeight:Number):void {
// setting up cameras, viewport, scenes, render engine and others for
papervision
// Viewport3D( width, height, autoScaleToStage, interactive)
viewport = new Viewport3D( vpWidth, vpHeight, false, true );
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
camera.zoom = 1;
camera.focus = 600;
pc = new Plane();
pc.visible = false;
camera.target = pc;
renderer = new BasicRenderEngine();
}
private function initMaterials():void {
mcAsset = new mcContainer();
materialA = new MovieMaterial(mcAsset);
materialA.animated = true;
materialA.interactive = true;
materialA.doubleSided = true;
}
private function initObjects():void {
// setting up planes and other objects
planeContainer = new DisplayObject3D();
planeA = new Plane( materialA, 300, 189.2, 10, 10 );
planeA.x = Math.cos(1* anglePer)* 500;
planeA.z = Math.sin(1* anglePer)* 500;
planeA.y = yPos;
planeA.rotationY = (-1*anglePer)*(180/Math.PI) + 270;
planeContainer.addChild(planeA);
planeB = new Plane( materialA, 300, 189.2, 10, 10 );
planeB.x = Math.cos(2* anglePer)* 500;
planeB.z = Math.sin(2* anglePer)* 500;
planeB.y = yPos;
planeB.rotationY = (-2*anglePer)*(180/Math.PI) + 270;
planeContainer.addChild(planeB);
planeC = new Plane( materialA, 300, 189.2, 10, 10 );
planeC.x = Math.cos(3* anglePer)* 500;
planeC.z = Math.sin(3* anglePer)* 500;
planeC.y = yPos;
planeC.rotationY = (-3*anglePer)*(180/Math.PI) + 270;
planeContainer.addChild(planeC);
planeD = new Plane( materialA, 300, 189.2, 10, 10);
planeD.x = Math.cos(4* anglePer)* 500;
planeD.z = Math.sin(4* anglePer)* 500;
planeD.y = yPos;
planeD.rotationY = (-4*anglePer)*(180/Math.PI) + 270;
planeContainer.addChild(planeD);
planeE = new Plane( materialA, 300, 189.2, 10, 10);
planeE.x = Math.cos(5* anglePer)* 500;
planeE.z = Math.sin(5* anglePer)* 500;
planeE.y = yPos;
planeE.rotationY = (-5*anglePer)*(180/Math.PI) + 270;
planeContainer.addChild(planeE);
scene.addChild(planeContainer);
}
private function initListeners():void {
//setting up listeners
addEventListener(Event.ENTER_FRAME, render);
}
private function processFrame():void {
// process any movements of animations here
planeA.pitch(1);
dist = ((stage.mouseX) - stage.stageWidth * 0.5) * 0.00005;
angle += dist;
camera.x = Math.cos(angle) * 1000;
camera.z = Math.sin(angle) * 1000;
}
private function render( ThisEvent:Event ):void {
// renders & process frame
processFrame();
renderer.renderScene( scene,camera,viewport );
}
}
}
http://www.nabble.com/file/p19951200/planeTest.swf planeTest.swf
--
View this message in context: http://www.nabble.com/camera-position-inside-a-ring-of-planes-tp19951200p19951200.html
Sent from the Papervision3D mailing list archive at Nabble.com.
More information about the Papervision3D
mailing list