Hello funk0xff0000,

if your intension is to rotate a cube, it’s better to use another
technique. HoverCamera3D consumes a lot of memory for this task…just
use it when you have to orbit around the objects or the scene. In this
case set the maxTitle/PanAngle and minTitle/PanAngle of your camera to
avoid this flip problems that you got. But I will still try to rotate
the cube instead of moving the camera (for performance reasons).
Something like this:

private var mouseDownX:Number = 0;
private var mouseDownY:Number = 0;
private var diffX:int = 0;
private var diffY:int = 0;
private var isMouseDown:Boolean = false;

private function init():void
{
        addEventListener(Event.ENTER_FRAME, renderScene);

        stage.addEventListener(MouseEvent.MOUSE_DOWN, stageMouseDown);
        stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
}

private function stageMouseDown(e:MouseEvent):void
{
        isMouseDown = true;
        mouseDownX = e.stageX;
        mouseDownY = e.stageY;
}

private function stageMouseUp(e:MouseEvent):void
{
        isMouseDown = false;
}

private function renderScene(e:Event = null):void
{
        var currentMouseX:Number = mouseX;
        var currentMouseY:Number = mouseY;

        if(isMouseDown)
        {
                if(Math.abs(mouseDownX - currentMouseX) > 1)
                {
                        diffX = (mouseDownX - currentMouseX) / 4;
                }
                diffY = (mouseDownY - currentMouseY) / 4;
        }

        cube.rotationY += diffX;

        cube.rotationX -= diffY;
        cube.rotationX = Math.min(89, cube.rotationX);
        cube.rotationX = Math.max(-89, cube.rotationX);

        diffX *= .98;
        diffY *= .68;

        mouseDownX = mouseX;
        mouseDownY = mouseY;

        view.render();
}

I hope this helps. ;)

Cheers,
Ivan Moreno
http://www.thefloatingwall.com/

Reply via email to