PDA

View Full Version : Papervision: restrict rotation of a plane



johnnymeerkat
January 11th, 2009, 11:54 AM
Hey guys

A longtime AS2 developer finally making the transition to AS3 and Papervision all in one big leap.

Working from Lee Brimelow's awesome pv2 tutorial as a base I've been able to create a plane with a movieclip mapped to it. What I'd ideally like to do is limit the rotation of the plane to maximum of -45 to 45 degrees on the X and Y. Here's my code:



import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.*;
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
viewport.buttonMode = true;
var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100;

var jar:MovieAssetMaterial = new MovieAssetMaterial("jar");
jar.oneSide = false;
jar.smooth = true;

var p:Plane = new Plane(jar,510,286,2,2);

scene.addChild(p);

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void {
var xDist:Number = mouseX - stage.stageWidth * 0.5;
var yDist:Number = mouseY - stage.stageHeight * 0.5;
p.rotationY += xDist * 0.05;
p.rotationX += yDist * 0.05;
renderer.renderScene(scene,camera,viewport);
}


I've tried using basic conditionals to restrict p.rotationX and p.rotationY but they seem to be ignored.

Ideally I'd like an eased, restrcted rotation. Does anybody have any tips? Thanks!

scottc
January 11th, 2009, 12:28 PM
I think it's because of the internal workings of papervision, the rotationX is relative to it's own orientation, so if you tried to trace it... it would always be 0.

try replace it with localRotationX. (i had a quick look at the pv api)

johnnymeerkat
January 11th, 2009, 12:34 PM
Thanks Scott - I shall have a go with localRotationX when I next load up the IDE.

Since it didn't seem to be working when I first tried it, I did trace the plane's rotationX and rotationY, but it appeared to be unending - if I set the thing spinning in one direction it wouldn't cycle through 360 or -180 to 180 degress; it just keeps going and going. I had it tracing a rotation of 7,500 on the Y axis, and then swung it back through to -3000 after several revolutions... 0_o

scottc
January 11th, 2009, 12:50 PM
so if you tried to trace it... it would always be 0.

So i was wrong...:P
Was only a guess, i've only used pv once for like 30 mins. :D

Anyway check out the pv docs, it should come with it in the folder:
/papervision3d/as3/trunk/docs/index.html
/papervision3d/as3/trunk/docs/org/papervision3d/objects/DisplayObject3D.html

If it doesn't work you could try use:


plane.sceneX = 123; //reletive to the scene's cords
//or
plane.roll(123); //rolls the object by 123, pretty much the same as rotationX?

johnnymeerkat
January 11th, 2009, 02:44 PM
You know what? I just upgraded from Papervision 1.5, and for the first time ever I downloaded the latest version via an SVN client. I had no idea that help files came with it! That might help to explain the 15mb disparity between the SVN download and the 494k .zip file you can get via direct download!

bripungir
September 18th, 2009, 05:32 AM
Hi all, I am a new member of forum
__________________

Electric adjustable beds prices and reviews (http://adjustablebedsprices.org)

johnnymeerkat
September 18th, 2009, 06:57 AM
Hi all, I am a new member of forum
__________________

Electric adjustable beds prices and reviews (http://spammityspamspam.spm/)

Spam about adjustable beds on a Papervision thread? Maybe this SEO company needs to rethink its strategy a little.