Apr 25, 2007
Leveraging existing 2D code in Papervision3D
It's truly a testament to Papervision3D's ease-of-use that developers can leverage existing routines from previous 2D projects by simply modifying Movieclip references to DisplayObject3D. I put this little demo together with a set of stacked Mistubishi logos reacting to some slinky physics I built for a 2D AS2 project.
Here's an excerpt from the frame code that reproduces the slinky effect. You'll probably recognize this as a fairly conventional method of producing the same result in 2D. The only major difference are the references to Decoration3D which is just a class I built to extend DisplayObject3D.
Actionscript:
-
//Spin the stack around slowly
-
__rootNode.rotationY += 1;
-
-
for( var i:Number = 0; i<__bubbleArray.length; i++){
-
var currentBubble:Decoration3D = __bubbleArray[i]; //Decoration3D extends DisplayObject3D
-
-
if( i == 0 ){
-
//Case of first logo in the stack
-
var dx:Number = currentBubble.x - __container.mouseX;
-
var dy:Number = currentBubble.y - __container.mouseY;
-
var angle:Number = Math.atan2(dy, dx);
-
var targetX : Number = __container.mouseX + Math.cos(angle) * __springLengthValue;
-
var targetY : Number = __container.mouseY + Math.sin(angle) * __springLengthValue;
-
} else {
-
//Case of every logo following the first
-
var lastBubble:Decoration3D = __bubbleArray[i-1]; //Decoration3D extends DisplayObject3D
-
-
var dx:Number = currentBubble.x - lastBubble.x;
-
var dy:Number = currentBubble.y - lastBubble.y;
-
var angle:Number = Math.atan2(dy, dx);
-
var targetX : Number = lastBubble.x + Math.cos(angle) * __springLengthValue;
-
var targetY : Number = lastBubble.y + Math.sin(angle) * __springLengthValue;
-
}
-
-
currentBubble.vx += ( targetX - currentBubble.x ) * __springValue;
-
currentBubble.vy += ( targetY - currentBubble.y ) * __springValue;
-
-
currentBubble.vy += __gravityValue;
-
currentBubble.vx *= __frictionValue;
-
currentBubble.vy *= __frictionValue;
-
currentBubble.x += currentBubble.vx;
-
currentBubble.y += currentBubble.vy;
-
-
currentBubble.rotationZ = currentBubble.vx * __frictionValue;
-
-
__scene.renderCamera( __camera );
-
}



