Re: Vector3.Unproject - Incorrect return value

From: ZMan (news-replies_at_thezbuffer)
Date: 07/08/04


Date: Thu, 8 Jul 2004 13:20:45 -0700

I'm don't have access to my main computer right now but I seem to remember
having to transform my scrren pixel coordinates from 0<x<width, 0<y<height
into directx screen space 0.0<x<1.0, 0.0<y<1.0 ? i.e. divide x by the width
and y by the height. You may have to flip the sign too - I can't remember
where the origin is supposed to be.

I'll reply again later if thats not it.

ZMan

"Tomasz" <tomasz.babiak@gmail.com> wrote in message
news:ccjn6c$lb5$1@news01.cit.cornell.edu...
> Hello,
>
> I'm trying to write an application where I draw atoms on the screen and
> translate based on mouse movement. For instance, if the mouse moves 10
> pixels up, the atoms should move 10 pixels up. In order to do this, I
need
> to convert from screen to world coordinates. I am using
Vector3.Unproject,
> but I keep getting results that cannot possibly be correct. I define my
> device and transforms as follows:
>
> m_device = new Device(0,DeviceType.Hardware,this,
> CreateFlags.SoftwareVertexProcessing,presentParams);
>
> m_device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI /
4,
> this.Width / this.Height, 0, m_zfarPlane);
>
> m_device.Transform.View = Matrix.LookAtLH(new
> Vector3(0,0,-m_cameraDistance), new Vector3(0,0,1), new Vector3(0,1,0));
>
> m_device.Transform.World = Matrix.Identity;
>
> I capture the mouse position, which is in screen coordinates, and put it
> into a Vector3:
>
> Vector3 mouse1 = new Vector3(point1.X,point1.Y,1);
>
> and then unproject:
>
> mouse1.Unproject(m_device.Viewport,m_device.Transform.Projection,
> m_device.Transform.View,m_device.Transform.World);
>
> In a sample run, this converts (110,165,1) to (-0.24,-0.24,1). This has
to
> be incorrect because the screen coordinates (110,165,1) place the atoms
near
> the bottom left of the form, whereas the world coordinates (-0.24,-0.24,1)
> denote a point very close to the center of the form. What is strange is
> that no matter what the original screen coordinates are, the
> Vector3.Unproject always returns values very close to (-0.24,-0.24,1).
>
> I am sure that I initialized my device and transforms correctly. Is it
> possible that I am missing some important detail or that I am misusing
> Unproject?
>
> Thank-you very much for your time.
>
> Tomasz
>
>



Relevant Pages

  • Vector3.Unproject - Incorrect return value
    ... translate based on mouse movement. ... pixels up, the atoms should move 10 pixels up. ... I capture the mouse position, which is in screen coordinates, and put it ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Which free software could acquire 48 bits color depth pictures from a scanner ?
    ... Whining that PS cn't do 32-bit pixels for all functions is ... The point about data precision in PS is not about output. ... conserving information over a few to dozens of transforms ... of the data without introducing artifacts due to LSB losses or padding ...
    (rec.photo.digital)
  • Re: Which free software could acquire 48 bits color depth pictures from a scanner ?
    ... Whining that PS cn't do 32-bit pixels for all functions is ... It is about conserving information over a few to dozens of transforms of the data without introducing artifacts due to LSB losses or padding in each transform such that when the data is eventually reduced to the dynamic range of the output, all processing artifacts are lost in the truncated or rounded data only in that very last operation. ...
    (rec.photo.digital)
  • Re: How to find position of a MDI window frame in the main frame client coordinates?
    ... // convert screen coordinates to the main frame client area ... pixels to the right, ... http://www.chembuddy.com - chemical calculators for labs and education ...
    (microsoft.public.vc.mfc)
  • Re: Manual use of world/view/proj mats
    ... transforms your point into the unit cube (make sure to take the perspective ... division into account). ... If you want 2D screen coordinates, you have to apply the viewport ...
    (microsoft.public.win32.programmer.directx.graphics)