this is portable

Papervision3D – cubes in white void-like motion (almost)

UPDATE – Thanks to the Papervsion3D list, I found a better approach, see this post.

This is a quick Papervsion3D 2.0 thing I’ve been working. The white void app is still one of my favourite Papervision sites, and I thought trying to build something similar would make a good a first Papervision project.

So far it’s only a small step towards the finished product.  It’s based on BasicView which is so helpful in getting you started with Papervision3D because it saves a whole lot of set up.

I have an outer cube that contains the two inner “cubes” and I’m moving that outer cube in response to the mouse movment.  Right now the closer your mouse is to the x and y coordinates of the outer cube, the less movement there is.

The two green lines you see intersect at the x=0, y=0 point of the outer cube just to help give some reference.  If you download the source files (a FlexiBuilder project) you can uncomment a line to wireframe the entire outer cube.

Oh, and if you like BasicView, check out Seb Lee-Delisle’s ReflectionView class.

Here’s the source of the CubeCamera class (aka the class that’s doing most of the work here).  Pardon the terrible appearance, it seems that my code highlighting plug-in has crapped out on me today.  The Source is here if you’re not into scrolling lots of un-highlighted code.

This experiment could  be done in Flash instead of FlexBuilder just as easily, if you’re wondering.
[as]
package {
import flash.events.Event;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;

public class CubeCamera extends BasicView
{
private var bigBox:Cube;
private var cube1:Cube;
private var cube2:Cube;
private var line1:Plane;
private var line2:Plane;

public function CubeCamera() {
super(1,1,true,true);
initScene();
startRendering();
}

private function initScene():void {

//Set the background
opaqueBackground = 0×000000;

//use this line for visible wireframe on the outter cube
//var wireFrameMaterial:WireframeMaterial = new WireframeMaterial(0×999999, 1, 2);
//use this line for an invisible outter cube
var wireFrameMaterial:WireframeMaterial = new WireframeMaterial(0×999999, 0, 0);
var wml:MaterialsList = new MaterialsList({all:wireFrameMaterial});

//create the main 3D container
bigBox = new Cube(wml, 400,200,400, 3,3,3);

//cube 1
var cubeMaterial:ColorMaterial = new ColorMaterial(0xcecece,1,true);
cubeMaterial.doubleSided = true;
cubeMaterial.interactive = true;
var ml:MaterialsList = new MaterialsList({all:cubeMaterial});

cube1 = new Cube(ml,100,50,100,1,1,1);
bigBox.addChild(cube1);
cube1.x = -100;
cube1.y = 0;
cube1.z = 0;

//cube2
cube2 = new Cube(ml,100,50,100,1,1,1);
bigBox.addChild(cube2);
cube2.x = cube1.x + 200;
cube2.y = 0;
cube2.z = 0;

//add the container object to the stage
scene.addChild(bigBox);
bigBox.visible = true;

//set up the camera
camera.zoom = 10;
camera.lookAt(bigBox);

//add a plane to show where bigBox zero point is
var lineMaterial:ColorMaterial = new ColorMaterial(0x00ff00,1,false);
line1 = new Plane(lineMaterial, 1,500,1,1);
line2 = new Plane(lineMaterial, 500, 1, 1,1);
bigBox.addChild(line1);
bigBox.addChild(line2);
line1.x = line2.x = 0;
line1.y = line2.y = 0;
}

override protected function onRenderTick(event:Event = null):void
{
//changing the amount of pitch on bigBox (the outter cue) based on how close mouseY is to bigBox.y
if (viewport.mouseY-bigBox.y >1) {
bigBox.pitch( -((viewport.mouseY – (stage.stageHeight / 2)) / stage.stageHeight)*4);
} else if ( viewport.mouseY – bigBox.y < 1) {
bigBox.pitch(0);
}

//changing the amount of yaw on bigBox (the outter cue) based on how close mouseX is to bigBox.X
if (viewport.mouseX-bigBox.x > 1) {
bigBox.yaw( -((viewport.mouseX – (stage.stageWidth / 2)) / stage.stageWidth)*4);
}else if(viewport.mouseX – bigBox.x < 1) {
bigBox.yaw(0);
}

super.onRenderTick(event);
}

}
}
[/as]

Flashpitt2008 tickets on sale

Flashpitt2008 tickets are now on sale. Tickets start at $110 for the Early Bird rate and there’s still some Early Bird tickets left. Check out the ticket price listing, including a nice and cheap student rate.

We’ve started announcing our speaker line up, too.  Confirmed speakers include: Big Spaceship, John Lindquist, Julian Dolce, Stacey Mulcahy, Ben Pritchard, Jose Rodriguez, and Craig Swann. The speakers page has all the details.