Discussion:
ArcBall ScreenToVector function
(too old to reply)
John Xie
2008-03-18 21:36:00 UTC
Permalink
Hi all,

I am using directx 9 sample frame work as the start point of my 3D project.
In the source code to convert screen point to vector function as following:

public Vector3 ScreenToVector(float screenPointX, float screenPointY)
{
float x = -(screenPointX - width / 2.0f) / (radius * width/2.0f);
float y = (screenPointY - height / 2.0f) / (radius * height/2.0f);
float z = 0.0f;
float mag = (x*x) + (y*y);

if (mag > 1.0f)
{
float scale = 1.0f / (float)Math.Sqrt(mag);
x *= scale;
y *= scale;
}
else
z = (float)Math.Sqrt(1.0f - mag);

return new Vector3(x,y,z)
}

My question is why there is negative x not y?

According the link
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=48, y should be
negative and x is positive.

Any explanation?


Thanks
Geoffrey Summerhayes
2008-03-28 18:36:55 UTC
Permalink
Post by John Xie
Hi all,
I am using directx 9 sample frame work as the start point of my 3D project.
<*SNIP*>
Post by John Xie
My question is why there is negative x not y?
Maybe...

Because the two algorithms are calculating vectors
that are going in opposite directions.

----
Geoff

Loading...