Sunday, October 26, 2008

Papervision Tutorial - Mouse Interaction.

This Papervision Tutorial for Flash show you how to do some movement in the scene by using the mouse.

Here is the source code:

package {
import PaperBase;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Collada;
public class Main extends PaperBase {
public var cow:DisplayObject3D;
public var distance:Number = 1000; //Distance the camera should be from the model
public function Main() {
init();
}
override protected function init3d():void {
cow = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
cow.moveDown(100);
cow.scale = 3;
default_scene.addChild(cow);
}
override protected function processFrame():void {
// The next line is a bit of a mouthful, but it's quite simple really.
// It just gets the Y position of your mouse, and sets the camera.y to a
// value between -800 and 800, depending on the Y position of your mouse
// (If mouseY = 0 then camera.y = 800. If mouseY = stage.height, camera.y = -800)
default_camera.y = -(((mouseY - (stage.height / 2)) / stage.height) * 1600);
// We don't want the camera to move further away from the model, so we do this:
default_camera.moveForward(default_camera.distanceTo(cow) - distance);
// We now want to rotate the object depending on
// the Xmouse position. This is really simple.
cow.rotationY = -((mouseX / stage.width) * 360) //Rotation
// NOTE: This will only work if you only have one object in your scene.
// I'll write a more advanced movement tutorial soon
}
}
}

1 comment:

  1. kailangan mo ng Papervision 1.5 or later paramagamit ang code na yan..

    PaperBase is a class.
    Kailangan mo pa i-import ang Codebase/Folder sa ActionScript ng Flash^_^

    Kung wala ang mga yun, d mo magagamit yan..

    ~~Chx

    ReplyDelete

What can you say about this post? Would you like to subscribe to this blog? If so, click here. Thanks to you!