I haven't debugged your code, (that would be your job :)) )
but made quick test class using latest 3.5 to test class itself, all seams fine 
to me.

I would check if the mouse coordinates are correct in your case.

Fabrice


package{
        import flash.display.*;
        import flash.events.*;
        import away3d.containers.Scene3D;
        import away3d.containers.View3D;
        import away3d.core.base.Object3D;
        import away3d.core.render.*;
        import away3d.cameras.HoverCamera3D;
        import away3d.events.MouseEvent3D;
        import away3d.primitives.Sphere;
         
        import away3d.tools.Drag3D;
         
        public class Drag3DTest extends Sprite
        {
                public var scene:Scene3D;
                private var view:View3D;
                private var drag3d:Drag3D;
                 
                private var cameraDistance:Number = 3000;
                private var Hcamera:HoverCamera3D;
                
                private var move:Boolean = false;
                private var lastPanAngle:Number;
                private var lastTiltAngle:Number;
                private var lastMouseX:Number;
                private var lastMouseY:Number;
                 
                public function Drag3DTest()
                {
                        addEventListener(Event.ADDED_TO_STAGE, init);
                }
                
                private function init(e:Event):void
                {
                        initSWFEnvironement();
                        populate();
                }
                 
                 private function initSWFEnvironement():void
                {
                        stage.align = StageAlign.TOP_LEFT;
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        stage.stageFocusRect = false;
                         
                        Hcamera = new HoverCamera3D();
                        view = new View3D({camera:Hcamera});
                        scene = view.scene;
                        view.x = stage.stageWidth * .5;
                        view.y = stage.stageHeight * .5;
                        Hcamera.distance = cameraDistance;
                        Hcamera.tiltAngle = Hcamera.panAngle = 45;
                         
                        addChild(view);
                        //scene.addChild(new Trident(1000, true));
                         
                        start();
                }
                
                public function start():void
                {
                        if(!hasEventListener(Event.ENTER_FRAME)){
                                addEventListener(Event.ENTER_FRAME, 
refreshScreen);
                                stage.addEventListener(MouseEvent.MOUSE_DOWN, 
onMouseIsDown);
                stage.addEventListener(MouseEvent.MOUSE_UP, onMouseIsUp);
                                stage.addEventListener(Event.RESIZE, onResize);
                        }
                }
                 
                
                private function populate():void
                {
                        var _debugPrimitive:Sphere = new Sphere({radius:50, 
material:null});
                        scene.addChild(_debugPrimitive);
                        
                        drag3d = new Drag3D(view);
                        drag3d.plane = "xz";
                        drag3d.debug = true;
                        drag3d.object3d = _debugPrimitive;
                        
                        Hcamera.hover(true);
                        
                }
                 
                private function refreshScreen(event:Event = null):void
                {
                         
                        if (move) {
                                Hcamera.panAngle = 0.7*(stage.mouseX - 
lastMouseX) + lastPanAngle;
                                Hcamera.tiltAngle = 0.7*(stage.mouseY - 
lastMouseY) + lastTiltAngle;
                        }
                        
                        Hcamera.hover();
                        
                        drag3d.updateDrag();
                         
                        view.render();
                                 
                }
                
                private function onResize(event:Event):void
                {
                        view.x = stage.stageWidth *.5;
                        view.y = stage.stageHeight *.5;
                }
                
                private function onMouseIsDown(event:MouseEvent):void
        {
                                lastPanAngle = Hcamera.panAngle;
                                lastTiltAngle = Hcamera.tiltAngle;
                                lastMouseX = stage.mouseX;
                                lastMouseY = stage.mouseY;
                                move = true;
                                stage.addEventListener(Event.MOUSE_LEAVE, 
onStageMouseLeave);
        }
         
        private function onMouseIsUp(event:MouseEvent):void
        {
            move = false;
            stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);    
 
        }
        
        private function onStageMouseLeave(event:Event):void
        {
            move = false;
            stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);    
 
        }
                
        }
}






On Jun 1, 2010, at 1:08 AM, abowman wrote:

> I tried calling the onResize function at the beginning of my init
> function and that didn't solve the problem.
> 
> 
> 
> On May 31, 4:54 pm, Fabrice3D <[email protected]> wrote:
>> looked very quickly at your code,
>> since class caches few values to spare calcs, try call resize(); before you 
>> do setup the class.
>> 
>> let me know how it goes, I will in case it doesn't fix your issue, try your 
>> class tomorrow.
>> 
>> also one detail, camera is standard of type Camera3D
>> so view.camera.x, y, z is enough, no need to declare one.
>> 
>> Fabrice
>> 
>> On May 31, 2010, at 6:09 PM, abowman wrote:
>> 
>>> Thanks for the class Fabrice.
>> 
>>> For some reason, when I move the mouse the sphere I'm dragging doesn't
>>> stay under the mouse.
>> 
>>> http://abowman.nozonenet.com/away3d/dragTest.swf
>>> http://abowman.nozonenet.com/away3d/DragTest.as
>> 
>>> What do I need to do to fix this?
>> 
>>> Thanks
>> 
>>> On May 21, 4:49 am, Fabrice3D <[email protected]> wrote:
>>>> Hi all,
>>>> I get many requests about this and I keep sending code...
>> 
>>>> So I've added a new class dedicated to this particular functionality.
>>>> Drag3D.  in tools.utils package
>> 
>>>> you can use it to drag an object or just to get the intersection back.
>> 
>>>> here an example of implementation
>> 
>>>>                 import away3d.tools.utils.Drag3D
>>>>                 [... usual away code...]
>>>>                 private var drag3d:Drag3D;
>> 
>>>>                  private function setUp():void
>>>>                 {
>>>>                         //the object you want to drag
>>>>                         var _debugPrimitive:Sphere = new 
>>>> Sphere({radius:50, material:null});
>>>>                         this.scene.addChild(_debugPrimitive);
>> 
>>>>                         //declare instance
>>>>                         drag3d = new Drag3D(this.view);
>>>>                         //which plane do you want to drag on
>>>>                         // note here that plane != Plane primitive!!
>>>>                         drag3d.plane = "xz";
>>>>                         // in case you want to check what you are doing
>>>>                         //drag3d.debug = true;
>>>>                         // to assign an object to be dragged
>>>>                         drag3d.object3d = _debugPrimitive;
>>>>                 }
>> 
>>>>                 private function myEnterFrame(event:Event = null):void
>>>>                 {
>>>>                         //will update the object automatically on mouse 
>>>> moves
>>>>                         drag3d.updateDrag();  // its is of course handy to 
>>>> couple this with mouseEvents, like "if mouseisdown --> drag"
>> 
>>>>                         // in case you want only the positionintersectback
>>>>                         varintersect:Number3D = drag3d.getIntersect();
>> 
>>>>                         this.view.render();
>>>>                 }
>> 
>>>> next to 0,0,0 default, there are also options for custom positions of 
>>>> plane, in case of AABB tests and even support for rotated planes
>>>> if you want object aligned calcs...
>> 
>>>> here a little tech demohttp://www.closier.nl/playground/drag/drag3d.swf
>> 
>>>> cheers,
>> 
>>>> Fabrice
>> 
>> 

Reply via email to