Screen Coordinates Broomstick

35 views
Skip to first unread message

kyma

unread,
Apr 8, 2011, 8:07:32 AM4/8/11
to Away3D.dev
In Broomstick, how can I get the screen coordinates of a
displayObject3d, for example, if I click on something?

John Brookes

unread,
Apr 8, 2011, 8:47:28 AM4/8/11
to away3...@googlegroups.com
private function initObjects():void
{
    var plane:Plane = new Plane(new ColorMaterial(0xff0000), 500, 500);
    plane.x = 200
    plane.rotationY = 45
    scene.addChild(plane)
   
    plane.mouseEnabled = true;
    plane.mouseDetails = true; //<-- needed for UV  and local XYZ position. If you dont need uv or local disable
   
    plane.addEventListener(MouseEvent3D.CLICK , click);
}

private function click(e:MouseEvent3D):void
{
    trace("you clicked");
    trace("Objects local position " + Object3D(e.target).position);
    trace("Objects world position " + ObjectContainer3D(e.target).scenePosition); //will be same as above as the plane is not parented
    trace("Stage Position" + e.screenX, e.screenY);
    trace("Objects UV position " + e.uv ); // needs mouseDetails
    trace("Click in Objects space" + e.localX, e.localY, e.localZ); // needs mouseDetails
}

kyma

unread,
Apr 8, 2011, 8:53:46 AM4/8/11
to Away3D.dev
That's great. Thanks a lot

Páll Zoltán

unread,
Apr 8, 2011, 8:55:39 AM4/8/11
to away3...@googlegroups.com
any idea how to do this without a MouseEvent?

Z.

John Brookes

unread,
Apr 8, 2011, 9:28:20 AM4/8/11
to away3...@googlegroups.com
If you mean stage coords.

Not sure, but a bit back I was playing about trying to get stage position of an object and this seemed to work. Haven't really tested it to much. So might be complete and utter  ...

If the veiw isnt same size as stage then obviously it fails.
Instead of passing an object I suppose you could make it into a vector3D and redo.

private function getStagePosition(cam:Camera3D, obj:ObjectContainer3D):Vector3D
{
    var camT:Matrix3D = cam.viewProjection.clone();
    var planT:Matrix3D = obj.sceneTransform.clone();
    camT.prepend(planT);
   
    var pv:Vector3D = Utils3D.projectVector(camT, new Vector3D());
    pv.x = (pv.x * stage.stageWidth / 2) + stage.stageWidth / 2
    pv.y  = (pv.y*-1 * stage.stageHeight / 2) + stage.stageHeight / 2
    return pv;
}

For uv. Then use plane3D and baryCentric
http://groups.google.com/group/away3d-dev/browse_thread/thread/5a008f433fda949b/828635f208f834d2?lnk=gst&q=baryCentric#828635f208f834d2

I think its still the same for broomstick

Páll Zoltán

unread,
Apr 8, 2011, 9:31:02 AM4/8/11
to away3...@googlegroups.com
alright, thanks :)
Z.

John Brookes

unread,
Apr 8, 2011, 11:13:42 AM4/8/11
to away3...@googlegroups.com
Bob sorry my comment was to Stephen about the 0,0,0 issue.
But then I think im wrong.

3.6 uses as3 pointAt which I thik is in stage coords. Anyhoo horrid thing

If you replace the lookAT function in Object3D.as (3.6 version) with the one from Broomstick with a slight modification

Just replace 3.6 version of object3D.as with attatched file


It "seems" to work, at least my little test did.

Object3D.as

John Brookes

unread,
Apr 8, 2011, 11:30:18 AM4/8/11
to away3...@googlegroups.com
eek edit the
*/
from line 1779

Stupidly made an edit before posting

Reply all
Reply to author
Forward
0 new messages