Re: Vector3.Unproject - Incorrect return value
From: ZMan (news-replies_at_thezbuffer)
Date: 07/08/04
- Next message: Michel Walsh: "Re: stop texture from interpolating"
- Previous message: Michel Walsh: "Re: Creating Meshes Manually"
- In reply to: Tomasz: "Vector3.Unproject - Incorrect return value"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Michel Walsh: "Re: stop texture from interpolating"
- Previous message: Michel Walsh: "Re: Creating Meshes Manually"
- In reply to: Tomasz: "Vector3.Unproject - Incorrect return value"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|