Game Development Reference
InDepth Information
sx
=
ax
/
az
sy
=
ay
/
az
We actually need to make the origin the centre of screen space rather
than the top left corner, but to make for easy equations we will ignore that
for now. If you look through the code for this chapter you will see the
actual factors we need to consider. To go from screen space to world
space we manipulate the function to give
ax
=
sx
*
az
ay
=
sy
*
az
Expanding the equation for
a
we get:
ax
=
Px
+
u
*
Mx
+
v
*
Nx
ay
=
Py
+
u
*
My
+
v
*
Ny
az
=
Pz
+
u
*
Mz
+
v
*
Nz
Now if we substitute these values into
ax
=
sx
*
az
ay
=
sy
*
az
we get
Px
+
u
*
Mx
+
v
*
Nx
=
sx
*
[
Pz
+
u
*
Mz
+
v
*
Nz
]
Py
+
u
*
My
+
v
*
Ny
=
sy
*
[
Pz
+
u
*
Mz
+
v
*
Nz
]
With some careful algebra, we can transform these equations into
sx
*
(
Nz
*
Py

Ny
*
Pz
)+
sy
*
(
Nx
*
Pz

Nz
*
Px
)+(
Ny
*
Px

Nx
*
Py
)
sx
*
(
Ny
*
Mz

Nz
*
My
)+
sy
*
(
Nz
*
Mx

Nx
*
Mz
)+(
Nx
*
My

Ny
*
Mx
)
u
=
sx
*
(
My
*
Pz

Mz
*
Py
)+
sy
*
(
Mz
*
Px

Mx
*
Pz
)+(
Mx
*
Py

My
*
Px
)
sx
*
(
Ny
*
Mz

Nz
*
My
)+
sy
*
(
Nz
*
Mx

Nx
*
Mz
)+(
Nx
*
My

Ny
*
Mx
)
v
=
If we define three vectors
A
,
B
and
C
as the cross products of
P
×
N
,
M
×
P
and
N
×
M
respectively, then the equations simplify further:
Search Nedrilad ::
Custom Search