Hi there,
I have a scene in which the camera is above looking directly down at the scene, and I want to be able to drag a couple of objects, but constrain their movement to either up or down, or left and right (As you look at the screen, so in 3d terms, along the z axis, or along the X axis)
I thought that I should be able to do
(_view, ObjectContainer3D(_sphere),Drag3D.PLANE_XY)
but if I do that, the object does not drag.
If I try it with a slightly modified version of the Dragtest.as code if I set the camera rotationX to 89, it works, albeit obviously dropping up and down quite drasticly as youd expect if you move the mouse up and down:
package
{
[SWF(width="1168", height="630", frameRate="60")]
import away3d.cameras.Camera3D;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.ObjectContainer3D;
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.loaders.parsers.data.DefaultBitmapData;
import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.primitives.PlaneGeometry;
import away3d.primitives.SphereGeometry;
//import away3d.tools.MeshHelper;
import away3d.tools.utils.Drag3D;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
public class DragTest extends Sprite
{
private var _view : View3D;
var _sphere:Mesh
private var _sphereGeom : SphereGeometry;
private var _drag3D:Drag3D;
public function DragTest()
{
_view = new View3D();
_view.antiAlias = 2;
_view.backgroundColor = 0xCCCCCC;
var camera:Camera3D = _view.camera;
camera.lens = new PerspectiveLens();
//var eps:Number = 0.00000001;
camera.x = 0;
camera.y = 500;
camera.z = 0;
camera.rotationX = 89
addChild(_view);
populate();
initDrag();
}
private function populate() : void
{
var pmaterial:ColorMaterial = new ColorMaterial (0x5555ff);
var PlaneGeom = new PlaneGeometry(10, 10);
var plane:Mesh= new Mesh(PlaneGeom, pmaterial);
_view.scene.addChild(plane);
//var map:BitmapData = new BitmapData(256,256,true, 0x80FF0000);
_sphereGeom = new SphereGeometry();
var smaterial:ColorMaterial = new ColorMaterial (0x555555);
_sphere = new Mesh (_sphereGeom, smaterial);
_view.scene.addChild(_sphere);
//var radiusObject:Number = MeshHelper.boundingRadius(plane);
//_view.camera.lookAt(plane.position);
_view.camera.moveBackward(100);
_view.camera.lens.near = 10;
_view.camera.lens.far = 60000;
this.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function initDrag() : void
{
_drag3D = new Drag3D(_view, ObjectContainer3D(_sphere),Drag3D.PLANE_XY); //third param optional default plane = xz plane
//_drag3D.offsetCenter = true;// offsets mouse if true or drag sticks to object center
}
private function handleEnterFrame(e:Event) : void
{
//updating the dragged object on screen
_drag3D.updateDrag();
_view.render();
}
}
}
If you try the above code, you’ll see that the sphere is consrained along the x axis, as desired, but obviously as the camera is not totally facing downwards, if you mofe the mouse up or down from the plane, which is a good indication of zero on the y plane, the sphere moves up or down along the y plane.
However, if you change
camera.rotationX = 89
to
camera.rotationX = 90
you’ll see that the sphere isn’t even drawn..
In my projest, where the item to be dragged has an event listener to start the drag when clicked, the object stays at its original location when clicked. If a plane to constrain to is not specified (which, I believe defaults to the XZ plane) then the object can be dragged as expected.
I could possibly kludge this, by making an invisible plane above the one I actually want to drag, and updating the the plane to be dragged’s x value to equal the one that is actuaklly being dragged, but I just wanted to make sure I wasn’t doing anything wrong initally..
Seems like a bug…