Game Development Reference
In-Depth Information
The GetObject3dWindowCoords() function gets the window coordinates of a point on a menu
item object that can be offset by ObjOffset and that is displayed within the viewport defined by
ViewPortWidth and ViewPortHeight input parameters. (See Listing 9-2.)
Listing 9-2. Getting the Window Coordinates for the MenuItem Object
float[] GetObject3dWindowCoords(int ViewPortWidth,int ViewPortHeight,Vector3 ObjOffset)
{
float[] WindowCoords;
int[] View = new int[4];
View[0] = 0;
View[1] = 0;
View[2] = ViewPortWidth;
View[3] = ViewPortHeight;
WindowCoords = MapObjectCoordsToWindowCoords(View, 0, ObjOffset);
// Flip Y starting point so that 0 is at top of window
WindowCoords[1] = ViewPortHeight - WindowCoords[1];
return WindowCoords;
}
The function does the following:
Creates the View variable, which is a viewport window defined by the
coordinates (0,0) and ( ViewPortWidth, ViewPortHeight )
1.
Gets the window coordinates of the menu item object at ObjOffset offset
position by calling the MapObjectCoordsToWindowCoords() function
2.
3.
Converts the y component of the window coordinates to screen space from
OpenGL space
4. Returns the window coordinates
The Touched() function returns true if the input screen touch coordinates TouchX and TouchY map to
within this menu item. (See Listing 9-3.)
Listing 9-3. Testing for the User's Touch Input
boolean Touched(float TouchX, float TouchY,int ViewPortWidth,int ViewPortHeight)
{
boolean result = false;
float Radius = GetRadius();
Vector3 ObjCoordsUpperLeft = new Vector3(-Radius, Radius, 0);
Vector3 ObjCoordsUpperRight = new Vector3( Radius, Radius, 0);
Vector3 ObjCoordsLowerLeft = new Vector3(-Radius, -Radius, 0);
Search WWH ::




Custom Search