pastebin

Paste #Be5 -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
position = eye = (0.75*sqrt2, 1, -0.75*sqrt2)

target = (0,0,0)

upVector = (0,1,0)

zaxis = normalize(target - position)
      = normalize(-0.75*sqrt2, -1, 0.75*sqrt2)
      = (-0.75*sqrt2, -1, 0.75*sqrt2)/sqrt(3.25)
      = (-0.75*sqrt(2/3.25), -1/sqrt(3.25), 0.75*sqrt(2/3.25))
      = (-1.5/sqrt(6.5), -1/sqrt(3.25), 1.5/sqrt(6.5))

xaxis = normalize(cross(upVector, zaxis))
      = normalize(1.5/sqrt(6.5), 0, 1.5/sqrt(6.5))
      = (1/sqrt(2), 0, 1/sqrt(2))

yaxis = cross(zaxis, xaxis)
      = (-1/sqrt(3.25) * 1/sqrt(2),
         2 * 1.5/sqrt(6.5) * 1/sqrt(2),
         1/sqrt(3.25) * 1/sqrt(2))
      = (-1/sqrt(6.5), 3/sqrt(13), 1/sqrt(6.5))

pw = 1.65  (width of view volume)
ph = 1.65  (height of view volume)

view to world:
    [ xaxis.x  xaxis.y  xaxis.z 0 ]
T = [ yaxis.x  yaxis.y  yaxis.z 0 ]
    [ zaxis.x  zaxis.y  zaxis.z 0 ]
    [   eye.x    eye.y    eye.z 1 ]

projection to view:
    [ pw/2    0 0 0 ]
P = [    0 ph/2 0 0 ]
    [    0    0 1 0 ]
    [    0    0 0 1 ]

projection to world:
      [ pw/2*xaxis.x  pw/2*xaxis.y  pw/2*xaxis.z 0 ]
P*T = [ ph/2*yaxis.x  ph/2*yaxis.y  ph/2*yaxis.z 0 ]
      [      zaxis.x       zaxis.y       zaxis.z 0 ]
      [        eye.x         eye.y         eye.z 1 ]


projection space: (px,py,pz,1), px,py = pixel coordinates, pz = unknown
world space: (wx,wy,wz,1)

(px,py,pz,1)*P*T = (wx,wy,wz,1)

wx = px*pw/2*xaxis.x + py*ph/2*yaxis.x + pz*zaxis.x + eye.x
wy = px*pw/2*xaxis.y + py*ph/2*yaxis.y + pz*zaxis.y + eye.y
wz = px*pw/2*xaxis.z + py*ph/2*yaxis.z + pz*zaxis.z + eye.z


top face (wy=1):
 1 = px*pw/2*xaxis.y + py*ph/2*yaxis.y + pz*zaxis.y + eye.y
=> pz = (1 - px*pw/2*xaxis.y - py*ph/2*yaxis.y - eye.y) / zaxis.y
=> pz = (-pw/2*xaxis.y/zaxis.y) * px + (-ph/2*yaxis.y/zaxis.y) * py + (1 - eye.y) / zaxis.y

left face (wz=-1):
-1 = px*pw/2*xaxis.z + py*ph/2*yaxis.z + pz*zaxis.z + eye.z
=> pz = (-1 - px*pw/2*xaxis.z - py*ph/2*yaxis.z - eye.z) / zaxis.z
=> pz = (-pw/2*xaxis.z/zaxis.z) * px + (-ph/2*yaxis.z/zaxis.z) * py + (-1 - eye.z) / zaxis.z

right face (wx=-1):
-1 = px*pw/2*xaxis.x + py*ph/2*yaxis.x + pz*zaxis.x + eye.x
=> pz = (-1 - px*pw/2*xaxis.x - py*ph/2*yaxis.x - eye.x) / zaxis.x
=> pz = (-pw/2*xaxis.x/zaxis.x) * px + (-ph/2*yaxis.x/zaxis.x) * py + (-1 - eye.x) / zaxis.x