Game Development Reference
In-Depth Information
The inal rendering is done using the
BoxR()
function, which is implemented in the
main.
cpp
ile.
A modiication to the carousel code is needed to support selection. We add the
GeomUtil.h
ile with a few methods of intersection testing. Similar, to the
RenderFlow()
procedure, we
iterate over visible images, and for each of those, we intersect the ray from the tap location
through the image plane:
int clFlowUI::GetImageUnderCursor( float mx, float my ) const
{
if ( FNumImg < 1 ) { return -1; }
Map the 2D screen touch point to a 3D point and a ray:
vec3 Pt, Dir;
MouseCoordsToWorldPointAndRay( FProjection, FView,
mx, my, Pt, Dir );
int CurImg = GetCurrentImage();
int ImgOrder[] = { CurImg, CurImg - 1, CurImg + 1, CurImg - 2,
CurImg + 2, CurImg - 3, CurImg + 3 };
Iterate over the current image quads:
for ( int cnt = 0 ; cnt < countof( ImgOrder ) ; cnt++ )
{
int i = ImgOrder[cnt];
if ( i < 0 || i >= (int)FNumImg ) { continue; }
Transform the quad coordinates into the world space:
vec3 Coords[4];
QuadCoords( Coords, FFlinger->GetValue() -
( float )(i) * OneImageSize );
Intersect the ray with two triangles:
vec3 ISect;
if ( IntersectRayToTriangle( Pt, Dir,
Coords[0], Coords[1], Coords[2], ISect ) ||
( IntersectRayToTriangle( Pt, Dir,
Coords[0], Coords[2], Coords[3], ISect ) ) )
return i;
}
return -1;
}