I have tried a new approach and it is looking better.
case1:
I am passing the 3D object to be dragged from DragTestCube into the
BasicDragging class which is the class where dragging is implemented.
Things are looking better now but there is always an offset. I am
using the Perspective lens.
These are the classes I am using. The ultimate purpose is drag objects
so in a room so the mouse positions and object must coincide.
case2:
Funniest thing is that when I am not using two classes and doing
everything in a single class there is no offset !!!!!!
Thats what puzzles me the most.
I am using Away3d 2.5.0. Drag3D class is in away3d.tools.utils.Drag3D
case1:
********************************************************************************************************************
package {
import away3d.cameras.*;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.*;
import away3d.core.base.Object3D;
import away3d.materials.*;
import away3d.primitives.*;
import away3d.tools.utils.Drag3D;
import flash.display.*;
import flash.events.*;
public class BasicDragging extends Sprite
{
protected var _camera : HoverCamera3D;
protected var _view : View3D;
protected var drag3d:Drag3D;
protected var sphere : Sphere = new Sphere();
protected var mouseDown:Boolean = false;
protected var obj:Object3D = new Object3D();
public function BasicDragging()
{
super();
_createView();
}
public function _createView() : void
{
_camera = new HoverCamera3D();
_camera.tiltAngle = 0;
_camera.panAngle = 180;
_view = new View3D();
_view.x = 400;
_view.y = 300;
_view.camera = _camera;
addChild(_view);
addEventListener(Event.ENTER_FRAME,
_onEnterFrame);
}
public function _createScene(object1:Object3D) : void
{
_camera.lens = new PerspectiveLens();
_camera.zoom = 2;
drag3d = new Drag3D(this._view);
drag3d.plane = "xy";
drag3d.debug = true;
drag3d.object3d = object1;
}
public function _onEnterFrame(ev : Event) : void
{
drag3d.updateDrag();
_camera.hover();
_view.render();
}
}
}
package {
import away3d.cameras.*;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.*;
import away3d.core.base.Object3D;
import away3d.events.MouseEvent3D;
import away3d.materials.*;
import away3d.primitives.*;
import flash.display.*;
import flash.events.*;
public class DragTestCube extends Sprite
{
protected var _camera : HoverCamera3D;
protected var _view : View3D;
protected var mat : WireColorMaterial = new
WireColorMaterial(0xcccccc);
protected var basicDrag:BasicDragging;
public function DragTestCube()
{
super();
_createView();
_createScene();
}
protected function _createView() : void
{
_camera = new HoverCamera3D();
_camera.distance = 1000;
_camera.tiltAngle = 0;
_camera.panAngle = 180;
_view = new View3D();
_view.x = 400;
_view.y = 300;
_view.camera = _camera;
addChild(_view);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
protected function _createScene() : void
{
var cube : Cube = new Cube();
cube.material = mat;
_view.scene.addChild(cube);
_camera.zoom = 2;
cube.addEventListener(MouseEvent3D.MOUSE_DOWN,onMouseDown);
}
protected function onMouseDown(event:MouseEvent3D):void
{
basicDrag = new BasicDragging();
basicDrag._createScene(event.target as Object3D);
}
protected function _onEnterFrame(ev : Event) : void
{
_camera.hover();
_view.render();
}
}
}
case 2:
HERE EVERYTHING SEEMS TO BE FINE. But since I have to use it many
objects and I am developing as a part of OOP architecture I need to do
it in two classes.
package {
import away3d.cameras.*;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.*;
import away3d.core.base.Object3D;
import away3d.events.MouseEvent3D;
import away3d.materials.*;
import away3d.primitives.*;
import away3d.tools.utils.Drag3D;
import flash.display.*;
import flash.events.*;
public class DraggingClassUsingDrag3D extends Sprite
{
protected var _camera : HoverCamera3D;
protected var _view : View3D;
protected var drag3d:Drag3D;
protected var sphere : Sphere = new Sphere();
protected var mouseDown:Boolean = false;
public function DraggingClassUsingDrag3D()
{
super();
_createView();
_createScene();
}
protected function _createView() : void
{
_camera = new HoverCamera3D();
_camera.distance = 1000;
_camera.tiltAngle = 5;
_camera.panAngle = 175;
_view = new View3D();
_view.x = 300;
_view.y = 300;
_view.camera = _camera;
addChild(_view);
addEventListener(Event.ENTER_FRAME,
_onEnterFrame);
}
protected function _createScene() : void
{
_camera.lens = new PerspectiveLens();
_camera.zoom = 2;
var mat : WireColorMaterial = new
WireColorMaterial(0xcccccc);
sphere.radius = 60;
sphere.material = mat;
_view.scene.addChild(sphere);
_camera.lens = new PerspectiveLens()
_camera.zoom = 2;
_camera.distance = 1000;
sphere.segmentsW = 20;
sphere.segmentsH = 20;
sphere.x -= 200;
sphere.y += 200;
drag3d = new Drag3D(this._view);
drag3d.plane = "xy";
drag3d.debug = true;
drag3d.object3d = sphere;
}
protected function _onEnterFrame(ev : Event) : void
{
drag3d.updateDrag();
_camera.hover();
_view.render();
}
}
}
GUYS PLEASE HELP ME!!!
Fabrice,Rob,Peter and all gurus please help.