Arcball Implementation for Papervision3D

1.3k views Asked by At

Is there an arcball implementation for Papervision3D?

There are many arcball implementations for Flash/ActionScript but none specifically for Papervision3D.

Here's an example of an arcball implementation for flash:

http://www.unitzeroone.com/blog/2009/09/08/source-better-flash-10-3d-interaction-arcball/

I have taken to writing my own implementation based on the DirectX ArcBall class.

It does not work correctly, however, and I am at a loss as to why.

From the cubes initial position I can click and drag the arcball as one would expect.

However, if I start accumulating the axis/angles in a quaternion, the directions reverse when the cube is rotated enough. There should be no reversing of the directions of rotation or any other weird behaviour.

I have scoured the internet and found nothing directly related to Papervision3D and arcballs. (Perhaps there is an arcball implementation for another 3D Flash engine?)

Any help in this matter would be greatly appreciated.

** EDIT ** Added a 500 point bounty for an answer with a working arcball implementation for Papervision3D (must have at least 1 object (i.e.) cube in the scene).

4

There are 4 answers

1
Red33mer On
1
sharvey On

This is what you are looking for:Dragging an object to rotate ?

here's the interesting part:

    var currentMousePoint:Point = new Point(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY);

    if(isMouseDown)
    {
        var difference:Point = currentMousePoint.subtract(previousMousePoint);
        var vector:Number3D = new Number3D(difference.x, difference.y, 0);

        var rotationAxis:Number3D = Number3D.cross(vector, FORWARD);
        rotationAxis.normalize();

        var distance:Number = Point.distance(currentMousePoint, previousMousePoint);
        var rotationMatrix:Matrix3D = Matrix3D.rotationMatrix(rotationAxis.x, -rotationAxis.y, rotationAxis.z, distance/250);

        sphere.transform.calculateMultiply3x3(rotationMatrix, sphere.transform);
    }

    previousMousePoint = currentMousePoint;
2
davek On

Not at all sure if this is what you want, but this project is basically a Flash implementation, with some elements aimed at papervision3D:

http://code.google.com/p/spinnyglobe/

particularly:

http://code.google.com/p/spinnyglobe/source/browse/trunk/flash/org/makerlab/ArcBall.as?r=122

4
godel On

The page mentioned by Dave K earlier has a number of arcball examples, here is one that conforms to the typical physics expected out of a trackball. However you may want to broaden your search a bit and look for quaternions and papervision.

If you are unfamiliar with quaternions, they are an element of a 4 dimensional vector-space and the basis behind the arcball effect you are looking for. This tutorial will get you up to speed on quaternion math that is fairly easy to understand.

Quaternions are handled natively by Papervision so tutorials are not that hard to find. A quick look at google produced the following results.

Quaternions in Papervision3D

A conversation on papervision3d and the dreaded Gimbal lock

Finally, a list of wordpress blogs discussing the topic (not all flash related)