PDA

View Full Version : Spinning in papervision


kyma
06-23-2008, 11:09 AM
I'm playing around with papervision. When I create an object, for example a sphere and the use sphere.yaw to spin it around, it is consistently leaving the original where it is: ie spinning but leaving a copy. Can anyone explain this?

ASWC
06-23-2008, 11:34 AM
You need to clear the graphics object on each frames.

kyma
06-23-2008, 01:36 PM
Can you tell me how to do that?

Gibbah
06-23-2008, 01:45 PM
Perhaps you have created 2 spheres?

Are you rendering the scene, camera and viewport onEnterFrame?

kyma
06-23-2008, 02:49 PM
Here's the code. Ball.yaw() is called in processframe at the bottom. My baseclass uses on enterframe to call processframe :

package {
import flash.events.KeyboardEvent;

import org.papervision3d.cameras.FreeCamera3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Sphere;
public class Walkabout extends PaperBase {
public var upDown:Boolean = false;
public var downDown:Boolean = false;
public var leftDown:Boolean = false;
public var rightDown:Boolean = false;
public var camera:FreeCamera3D;
public var ball:Sphere;
public var wires:BitmapFileMaterial = new BitmapFileMaterial("Assets/MetalGrid.jpg");
public var box:Cube;
public var boxSkin:BitmapFileMaterial = new BitmapFileMaterial("Assets/fluffy.png");
public function Walkabout() {
init();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
public function onKeyDown( event:KeyboardEvent ):void {
// The keycodes for the W,A,S & D keys are:
// W: 87
// A: 65
// S: 83
// D: 68
// -------
switch(event.keyCode) {
case 38:
upDown = true;
break;
case 40:
downDown = true;
break;
case 37:
leftDown = true;
break;
case 39:
rightDown = true;
break;
}
}
public function onKeyUp( event:KeyboardEvent ):void {
switch(event.keyCode) {
case 38:
upDown = false;
break;
case 40:
downDown = false;
break;
case 37:
leftDown = false;
break;
case 39:
rightDown = false;
break;
}
}
override protected function init3d():void {
camera = new FreeCamera3D(1, 500);
camera.moveUp(200);
current_camera = camera;
for (var x:Number = 0; x <8; x++) {
for (var y:Number = 0; y <8; y++) {
var p:Plane = new Plane(new BitmapFileMaterial("Assets/texture.jpg"), 550, 405, 8, 8);
p.pitch(90);
p.x = (x * 550)-2200;
p.z = (y * 405)-1000;
default_scene.addChild(p);
}
ball = new Sphere(wires,100,16,16);
ball.y= 100;
default_scene.addChild(ball);

box = new Cube(new MaterialsList ({ all: boxSkin }),500,50, 50);
box.y =140;
box.x = -200;
box.roll(25);
default_scene.addChild(box);

}
}
override protected function processFrame():void {
if (upDown) {
camera.moveForward(60);
}
if (downDown) {
camera.moveBackward(60);
}
if (leftDown) {
camera.yaw( -8);
}
if (rightDown) {
camera.yaw( 8);
}

ball.yaw(6);
}
}
}

Gibbah
06-23-2008, 03:39 PM
I don't quite understand how you do it but I allways use a renderer.
Something like this:


import org.papervision3d.cameras.FreeCamera3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;


var scene = new Scene3D();
var camera = new FreeCamera3D();
var renderer = new BasicRenderEngine();

var viewport:Viewport3D = new Viewport3D( 800, 600, false, true );
addChild( viewport );

var mySphere:Sphere = new Sphere(null,500,15,15);
scene.addChild(mySphere);

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void{
mySphere.yaw(6);
renderer.renderScene(scene, camera, viewport);
}

kyma
06-23-2008, 04:05 PM
I've got a load of setup methods in a class: PaperBase. This contains:

protected function onEnterFrame( ThisEvent:Event ):void {
//We need to render the scene and update anything here.
processFrame();
renderer.renderScene(current_scene, current_camera, current_viewport);
}

current_scene is a variable holding the scene etc...

jbailey
06-23-2008, 04:07 PM
CS4 and FlashPlayer10.... just saying ;-)

kyma
06-23-2008, 04:45 PM
I'm using flex builder3, but what's the relevance of that?

jbailey
06-23-2008, 05:10 PM
I'm using flex builder3, but what's the relevance of that?

http://video.google.com/videosearch?q=Flash+Player+Astro&sitesearch=#

Take it from me, Flash CS4 combined with FP10 will provide us all with POWERFUL tools for the LONG, LONG anticipated and craved 3D.

For instance, .rotationY and .rotationX but more importantly .z and .rotationZ :) "native" for DisplayObjects!

http://labs.adobe.com/technologies/flashplayer10/

ASWC
06-23-2008, 05:37 PM
lol, I heard also that in about 20 years from now we'll code just by thinking of what we want and a program will write everything for us. So either kima can decide to finish what he's doing now or he can wait until the end of the year or why not 20 years!

jbailey
06-23-2008, 06:14 PM
lol, I heard also that in about 20 years from now we'll code just by thinking of what we want and a program will write everything for us. So either kima can decide to finish what he's doing now or he can wait until the end of the year or why not 20 years!

ok mr.insult, I am excited about the development that is just around the corner and many of us already have access to. It was a small insert that I'd anticipated would reciprocate mutual excitement, especially if that's what you're already using. Adobe makes great strides in building excitement for features that are responses from their user base (ie. us). Moreover, I thought it would encourage him/her to know that it will be much easier soon. I don't believe the forums are for snide remarks and appreciate your input but holding back on the all too infamous know-it-all attitude is more appreciated and appropriate, especially for forums where new comers often frequent.

Gibbah
06-24-2008, 09:32 AM
I've got a load of setup methods in a class: PaperBase. This contains:

current_scene is a variable holding the scene etc...

Ah, i see. I havnt used PaperBase myself but when I look at your code it looks like you are rendering current_scene but adding the sphere to default_scene. Perhaps that has something to do with it, I don't know, Im really guessing here :p