hiroalex, Newbie Posted: 19 July 2011 01:15 AM Total Posts: 15
Hi,
First of all I would like to congratulate you for the good job you do with Away3D, and particularly with the Broomstick version.
So, I am evaluating this broomstick version and I am trying to use the unproject method from the Camera3D class, but either I don’t understand how it works, either the results returned are weird.
Here is a code sample I try to run. The goal is to create a Sprite3D where the user doubleClick :
private function onDoubleClick(evt:MouseEvent):void
{
var p:Point = new Point(evt.localX-(uiComponent.width/2),evt.localY-(uiComponent.height/2));
//var p:Point = new Point(evt.localX,evt.localY);
I don’t understand where I am wrong, it would be great if you could give a hand for this.
Take care,
Alex
SasMaster, Sr. Member Posted: 19 July 2011 11:35 AM Total Posts: 127
[ # 1 ]
SO what is your result in this code?
In fact ,what I see in your code is that your uicomponent size is 100% that means it probably stretch across the full width/height of the application window which is at least 955/600,right?Now ,you view is only 500/500 ! That ,means that there is no way your screen point corresponds to its 3d counterpart because your screens (uicomp and view) have different dimensions.So if you want it work correctly ,make the size of view the same as of the container that contains it or pick the 2d point not on the container but on the view itself.
hiroalex, Newbie Posted: 25 July 2011 08:21 PM Total Posts: 15
[ # 2 ]
Actually I found out the problem. The unproject method accepts only values between -1 and +1 (with 0,0 the center of the view) for X and Y. That’s why it didnt work properly with real screen coordinates. I couldn’t see any documentation about this, that’s why I struggled a bit…
Alex
David Lenaerts, Administrator Posted: 25 July 2011 09:39 PM Total Posts: 80
[ # 3 ]
You should use _view.unproject if you’re working with view coordinates. Camera3D::project uses the only 2D coordinate system it knows as input: its own normalized projection plane. Otherwise, if a single camera is used for multiple views, the resulting unproject code is unpredictable (“which view coordinates are being passed?”)
SasMaster, Sr. Member Posted: 17 November 2011 02:42 PM Total Posts: 127
[ # 4 ]
@David ,it would be nice to get a short explanation how _view,unproject is supposed to work.The thing is that when doing something lile
_view.unproject(mouseX,mouseY) ;
while moving on top of a geometry,only z coordinate of the returned vector looks reasonable. X and Y return some weird numbers
David Lenaerts, Administrator Posted: 18 November 2011 11:29 AM Total Posts: 80
[ # 5 ]
_view.unproject(mouseX, mouseY); gives you the world-space coordinates of the point on the actual projection plane (the near plane of the camera - imagine the plane actually placed in the scene; you’re querying for the global position of specific points on that plane).
This point, in combination with the camera’s position, allows you to construct a world space view ray, as “ray = camera.position + (unprojection - camera.position)*t”, t >= 0
SasMaster, Sr. Member Posted: 18 November 2011 12:32 PM Total Posts: 127
[ # 6 ]
My understanding of away3d unproject was the point in the view frustum and not on the near plane surface. If I remember, in away 3x it returned this very type of coordinates .
But that is fine.Fabrice gave idea to look how it works in Drag3d.
Thanks David.