Graphics Reference
In-Depth Information
void UWBD3D _ WindowHandler::DeviceToWorld( int dcX, int dcY, vec3 & wcPt, vec3 & wcRay) const {
.
Source file.
uwbgl _ D3DWindowHandler6.cpp
file in the D3D Files/ Win-
dowHandler subfolder of the
UWBGL _ D3D _ Lib14 project.
This is avirtual function de-
fined in the API-independent
UWB _ WindowHandler class.
// viewMat is M w 2 e
A:
ComputeViewMatrix(viewMat);
// invView is M e 2 w
D3DXMatrixInverse(&invView ... &viewMat);
// device size: W dc and H dc
B:
GetDeviceSize(deviceW, deviceH);
// get camera vertical fov
m _ Camera.GetViewVolumeFOVInRadian(fov);
// compute tan ( α )
tanAlpha = tanf((fov/2.0f));
// Refer to Equation 14
C:
W dc
.
1 , tan
( β )=
H dc ×
tan
( α )
tanBeta = (deviceW/deviceH) * tanAlpha;
// Compute p e (of Equation 15 . 10 ):
( dcX , dcY )
is
( x dc , y dc )
D:
ecPt.x = (((2.0f * dcX)/deviceW)-1) * tanBeta;
ecPt.y = (((2.0f * dcY)/deviceH)-1) * tanAlpha;
ecPt.z = -1;
// wcRayPtD3D is p w
E:
D3DXVec3TransformCoord(&wcRayPtD3D,&ecPt,&invView);
// wcPt is p wc
wcPt.x = invView. _ 41;
F:
// this is the camera position
wcPt.y = invView. _ 42;
// which is the 4 th row of M e 2 w
wcPt.z = invView. _ 43;
// wcRay is the projection ray direction
G:
wcRay = wcRayPtD3D - wcPt;
}
Listing 15.19. DC point to WC projection ray transform.
device coordinate system,
. At label B, the DeviceToWorld()
function is called to transform the device position to the projection ray where
pt is the origin and ray is the projection ray direction. Listing 15.19 shows the
DeviceToWorld() function. We can see that at:
(
deviceX
,
deviceY
)
.
1. Label A. Compute inverse viewing transformation matrix M e 2 w
2. Label B. Extract display width ( deviceW ) and height ( deviceH ).
3. Label C. Compute half of the horizontal and vertical field-of-view angles,
α
and
β
.
Search WWH ::




Custom Search