February 29th, 2008Change a Papervision 3D object’s registration point / axis
Papervision rocks, that’s for sure! But trying to change a 3D Object’s registration or pivot point without any documentation doesn’t rock that hard (or maybe a little, because I was banging my head against the wall trying to do this).
If you are a developer and reading this post you probably want to do something like rotate an object around a world point instead of the local 3D Object’s registration point (which defaults at 0, 0, 0). Also, there aren’t any properties to change the default registration point so we have to create a new registration point that replaces our old registration point.
The solution is really easy as hell (look at the working example here), the only thing you have to do is put your object (let’s say you made a cube) in a new 3D object (the wrapper) and offset your cube x, y, z coordinates to something else than 0, 0, 0. After you placed your cube (or cubes in my example) in this new wrapper object, rotate the wrapper and it will look like the cube is rotation around a new registration point.
Just look at the code and everything will become clear:
// create the cubes
cube01 = new Cube(materialsList, 60, 60, 60, 1, 1, 1);
cube02 = new Cube(materialsList, 60, 60, 60, 1, 1, 1);
cube01.rotationY = 20;
cube01.rotationZ = 20;
cube01.x = 350;
cube02.rotationX = 20;
cube02.rotationY = 20;
cube02.x = 500;
// add the cubes to a new wrapper object
objectContainer = new DisplayObject3D();
objectContainer.addChild(cube01);
objectContainer.addChild(cube02);
scene.addChild(objectContainer);
onEnterFrame for updating the rotation:
// rotate the container
objectContainer.rotationY += 1;
// render the scene
scene.renderCamera(camera);
If you don’t like using a wrapper you can try to change multiple parameters at the same time to fake the effect that your cube has a new registration point. i.e.: you can change the Y rotation of the cube and move the X position at the same time. I can’t really give you a concrete mathematical calculation but I’m sure you’ll find this freaky things somewhere on the Internet.
This post relates to a previous article: “Change a Papervision cube its material at runtime”
Technorati Tags: 3d object, change axis, mathematical calculation, papervision, pivot point, registration point, rotation



