2D co-ords from 3D?

4 views
Skip to first unread message

voodoowizard

unread,
Jun 26, 2007, 1:24:21 PM6/26/07
to away3d.dev
I've had a look around but can't find any native function...

What I need is a way to get the 2D (i.e. screen) co-ordinates of an
Object3D without use of the mouse - any ideas?

Alexander Zadorozhny

unread,
Jun 27, 2007, 6:55:59 PM6/27/07
to away3...@googlegroups.com
Hi Voodoo

Yes, there's no easy default way.
However, something like

var v:Vertex2D = (new Vertex3D(0,0,0)).project(new
Projection(Matrix3D.multiply(camera.getView(), object.relative()),
camera.focus, camera.zoom));

should return object's center position on screen - probably should be
added to View3D's api.

wbr,
Alexander

george

unread,
Jun 29, 2007, 6:45:02 PM6/29/07
to away3d.dev
Is there a way to do the reverse? IE find a line representing the set
of all points that the user may have clicked on, disregarding what is
actually drawn?

What I'm trying to do is implement a trackball-type rotation.

On Jun 27, 3:55 pm, "Alexander Zadorozhny"


<alexander.zadoroz...@gmail.com> wrote:
> Hi Voodoo
>
> Yes, there's no easy default way.
> However, something like
>
> var v:Vertex2D = (new Vertex3D(0,0,0)).project(new
> Projection(Matrix3D.multiply(camera.getView(), object.relative()),
> camera.focus, camera.zoom));
>
> should return object's center position on screen - probably should be
> added to View3D's api.
>
> wbr,
> Alexander
>

Collin Cusce

unread,
Jun 29, 2007, 10:13:33 PM6/29/07
to away3...@googlegroups.com
I need the reverse as well. I need to return 3D coordinates based on a 2D screen point.

I have a fixed camera staring into the XY plane, a space ship in front of the camera which moves on this plane at a given Z value, and a set of crosshairs (which must be a 3D object) which is on another XY plane ahead of the spaceship.

I need to take the coordinates of the mouse and make the crosshairs stay on the mouse (kinda like a drag).

Peter Kapelyan

unread,
Jun 29, 2007, 10:25:49 PM6/29/07
to away3...@googlegroups.com
1. your camera is center
2. place crosshair at camera...
3. crosshair.lookAt();crosshair.moveBackward(somenum)
4. crosshair.moveLeft()/crosshair.moveRight() based off stage.mousex

This should work?
-Pete

Collin Cusce

unread,
Jun 29, 2007, 10:37:25 PM6/29/07
to away3...@googlegroups.com

Peter Kapelyan

unread,
Jun 29, 2007, 10:39:15 PM6/29/07
to away3...@googlegroups.com
Yes it works!
Now just shift mouse stage over - for the scene shift it on the X minus whole or half stage.width...
It look right to me

 

Collin Cusce

unread,
Jun 29, 2007, 11:01:17 PM6/29/07
to away3...@googlegroups.com
Nah, that's not the problem...

Notice as you move the mouse the distance between the target and the mouse becomes greater as the distance from the mouse to the origin becomes greater. It doesnt scale.

Collin Cusce

unread,
Jun 30, 2007, 1:15:58 PM6/30/07
to away3...@googlegroups.com
Still a problem. Any ideas?

joshstrike

unread,
Jul 1, 2007, 8:41:53 PM7/1/07
to away3d.dev
Umm, this is part of the FindHitTraverser code what I adapted for that
purpose, but no guarantees this is going to work perfectly, you'll
probably have to tweak it:

function 2Dto3D(view:View3D, screenX:Number, screenY:Number,
screenZ:Number = 10000) {
var persp:Number = zoom / (1 + screenZ /
view.camera.focus);
var inv:Matrix3D = Matrix3D.inverse(getView());

var worldX:Number;
var worldY:Number;
var worldZ:Number;

worldX = screenX / persp * inv.n11 + screenY / persp *
inv.n12 + screenZ * inv.n13 + inv.n14;
worldY = screenX / persp * inv.n21 + screenY / persp *
inv.n22 + screenZ * inv.n23 + inv.n24;
worldZ = screenX / persp * inv.n31 + screenY / persp *
inv.n32 + screenZ * inv.n33 + inv.n34;
return new Number3D(worldX,worldY,worldZ);
}

Cheers,
Josh

On Jun 30, 1:15 pm, "Collin Cusce" <rafaja...@gmail.com> wrote:
> Still a problem. Any ideas?
>

> On 6/29/07, Collin Cusce <rafaja...@gmail.com> wrote:
>
>
>
> > Nah, that's not the problem...
>
> > Notice as you move the mouse the distance between the target and the mouse
> > becomes greater as the distance from the mouse to the origin becomes
> > greater. It doesnt scale.
>

> > On 6/29/07, Peter Kapelyan <flashn...@gmail.com> wrote:
>
> > > Yes it works!
> > > Now just shift mouse stage over - for the scene shift it on the X minus
> > > whole or half stage.width...
> > > It look right to me
>

> > > On 6/29/07, Collin Cusce <rafaja...@gmail.com > wrote:
>
> > > > Doesnt work.
> > > > see?
>
> > > >http://larry.onlinekarma.net/Flex%20Builder%202/Stalaga/bin/Stalaga.swf
>

> > > > On 6/29/07, Peter Kapelyan <flashn...@gmail.com > wrote:
>
> > > > > 1. your camera is center
> > > > > 2. place crosshair at camera...
> > > > > 3. crosshair.lookAt();crosshair.moveBackward(somenum)
> > > > > 4. crosshair.moveLeft()/crosshair.moveRight() based off stage.mousex
>
> > > > > This should work?
> > > > > -Pete
>

Alexander Zadorozhny

unread,
Jul 16, 2007, 10:40:22 AM7/16/07
to away3...@googlegroups.com
Hi Voodoo

> I've had a look around but can't find any native function...

Function screen(object:Object3D, vertex:Vertex = null):ScreenVertex is
back at the Camera3D class.
camera.screen(mesh) returns mesh center on screen, and
camera.screen(mesh, vertex) returns vertex relative to the mesh on the
screen.

wbr,
Alexander

joshstrike

unread,
Sep 5, 2007, 3:42:52 PM9/5/07
to away3d.dev
To anyone who might have a use for it if you're stuck using the pre-
July revision...

public function screen(object:Object3D, vertex:Vertex3D =
null):Vertex2D {
if (vertex == null) vertex = new Vertex3D(0,0,0);
return vertex.project(new
Projection(Matrix3D.multiply(getView(), object.transform), focus,
zoom));
}

That's how the function should look in the old rev if you need to add
it to Camera3D ...Camera3D then needs to import Vertex3D, Vertex2D and
core.render.Projection.

Side note: I just spent an angst-ridden few hours trying to shoehorn
my code into the new revision -- it's a lot of code, hundreds and
hundreds of errors -- I finally just gave up and committed myself to
making modifications on an as-needed basis. I want to get onto the new
version for my next project, but is there word on the reunion with
PV3D? Is there going to be another major change to the code base
anytime soon?

Gabriel Jensen

unread,
Sep 6, 2007, 1:17:06 AM9/6/07
to away3d.dev
First off, props to the devs for all their hard work. I'm developing a
3D puzzle game for my site pizmogames.com, and Away3D is really
exciting to work with.

I'm confused about the Camera3D.screen method returning a
ScreenVertex, though, which has x,y,z. How is that converted to x,y on
screen?

Thanks,

-Gabriel


On Jul 16, 7:40 am, "Alexander Zadorozhny"


<alexander.zadoroz...@gmail.com> wrote:
> Hi Voodoo
>
> > I've had a look around but can't find any native function...
>
> Function screen(object:Object3D, vertex:Vertex = null):ScreenVertexis
> back at the Camera3D class.
> camera.screen(mesh) returns mesh center on screen, and
> camera.screen(mesh, vertex) returns vertex relative to the mesh on the
> screen.
>
> wbr,
> Alexander
>

joshstrike

unread,
Sep 6, 2007, 5:09:31 PM9/6/07
to away3d.dev
I don't know about the method in the new version that returns a
ScreenVertex, but in the form modified for the old version above,
there's no third dimension to the result (actually there is, but it's
zero). To get the depth of field too, I wrote this (probably horribly
inefficient) method:

public function screenZ(object:Object3D, vertex:Vertex3D =


null):Vertex2D {
if (vertex == null) {
vertex = new Vertex3D(0,0,0);
}

moveForward(focus);
rotationX -= 90;
moveBackward(focus);
var v2:Vertex2D = vertex.project(new
Projection(Matrix3D.multiply(getView(), object.transform), focus,
zoom));
moveForward(focus);
rotationY += 90;
moveBackward(focus);
return v2.x;
}

...but it works...

Rob Bateman

unread,
Sep 7, 2007, 10:26:00 AM9/7/07
to away3...@googlegroups.com
holy crap!

yes, the new ScreenVertex removes the need for this... terrible thing! depth of field is set as a z property. I guess it would also make sense to have a scaling value carried inside, because at present you'd have to do perspScale = camera.zoom/(1+sVertex.z/camera.focus) which is a little incovenient...

Rob




> > camera.screen (mesh, vertex) returns vertex relative to the mesh on the

> > screen.
>
> > wbr,
> > Alexander
>
> > On 6/26/07, voodoowizard <kyom...@googlemail.com > wrote:
>
> > > I've had a look around but can't find any native function...
>
> > > What I need is a way to get the 2D (i.e. screen) co-ordinates of an
> > > Object3D without use of the mouse - any ide




--
Rob Bateman
Flash Development & Consultancy

Work: 0207 4823328
Mobile: 07714 329 073

rob.b...@gmail.com

joshstrike

unread,
Sep 7, 2007, 8:55:17 PM9/7/07
to away3d.dev
eep. Good point. I knew there was a reason some of the results were a
bit weird. =\ Also, that first rotationX should be a rotationY, above.
The only reason I'm using that function is to compare two views and
see if one should be "behind" the other; the cameras in the views are
synced up, so using that check I can swap their indices in 2D space,
and it works passably well...
I can't wait to finish this project and get into the new revision!
(But really, what's up with the pv3d merge? It scares me; I don't like
that community nearly as much, either...)
Cheers,
Josh

On Sep 7, 10:26 am, "Rob Bateman" <rob.bate...@gmail.com> wrote:
> holy crap!
>
> yes, the new ScreenVertex removes the need for this... terrible thing! depth
> of field is set as a z property. I guess it would also make sense to have a
> scaling value carried inside, because at present you'd have to do perspScale
> = camera.zoom/(1+sVertex.z/camera.focus) which is a little incovenient...
>
> Rob
>

> > > > camera.screen(mesh, vertex) returns vertex relative to the mesh on the


> > > > screen.
>
> > > > wbr,
> > > > Alexander
>
> > > > On 6/26/07, voodoowizard <kyom...@googlemail.com> wrote:
>
> > > > > I've had a look around but can't find any native function...
>
> > > > > What I need is a way to get the 2D (i.e. screen) co-ordinates of an
> > > > > Object3D without use of the mouse - any ide
>
> --
> Rob Bateman
> Flash Development & Consultancy
>
> Work: 0207 4823328
> Mobile: 07714 329 073
>

> rob.bate...@gmail.com

Rob Bateman

unread,
Sep 8, 2007, 11:43:41 AM9/8/07
to away3...@googlegroups.com
Hey Josh

I think that away3d and pv3d offer alternative ways of doing things, and there's no reason to see either merge into the other for now. Both engines are free to borrow features from each other, like you saw recently with the perspective correcting precisebitmapmaterial in pv3d. A port of interactivescenemanager is currently being done for away3d, so it works both ways. Having two different teams is actually quite healthy for developing new features, because if something is seen as a success in one, it can be ported to the other. The decision can be made from two points of view, and as it is hard to guess what will be the most popular feature before development begins, the difference in perspective is invaluable. Plus from a developer's point of view, choice is a good thing! So i wouldn't worry about away3d disappearing in the future. Whoever said "two heads are better than one" knew what they were talking about!


atb


Rob


> > Projection(Matrix3D.multiply (getView(), object.transform), focus,

> > zoom));
> >                         moveForward(focus);
> >                         rotationY += 90;
> >                         moveBackward(focus);
> >                         return v2.x;
> >                 }
>
> > ...but it works...
>
> > On Sep 6, 1:17 am, Gabriel Jensen < gabr...@pizmogames.com> wrote:
> > > First off, props to the devs for all their hard work. I'm developing a
> > > 3D puzzle game for my site pizmogames.com , and Away3D is really
rob.b...@gmail.com
Reply all
Reply to author
Forward
0 new messages