Rectangles 用边界矩形所包围的屏幕对象,贯穿在Direct3D和窗口编程中。边界矩形的边往往平行
于屏幕的边,因此矩形能被两个点所描述,即左上角和右下角。大多数应用程序在把位块传
输到屏幕或碰撞检测的时候用使用RECT结构体去描述边界矩形。 在C++中,RECT结构体像下面这样被定义: typedef struct tagRECT { LONG left; // This is the upper-left corner x-coordinate. LONG top; // The upper-left corner y-coordinate. LONG right; // The lower-right corner x-coordinate. LONG bottom; // The lower-right corner y-coordinate.} RECT 在上面的例子中,left和top成员是边界矩形左上角的x,y坐标,同样 ,right和
bottom成员是右下角坐标。下图说明你该怎样理解这些值。 图见相应DX文档 右边的像素列和下边的像素行不被包含在RECT中。例如,用{10,10,138,138}来定义
RECT,结果这个RECT对象在屏幕上的宽高只有128像素。 出于性能、一致性和易用性方面的考虑,所有Direct3D的显示函数都使用了矩形。
原文
Throughout Direct3D and Window programming, objects on the screen are referred to in terms of bounding rectangles. The sides of a bounding rectangle are always parallel to the sides of the screen, so the rectangle can be described by two points, the upper-left corner and lower-right corner. Most applications use the RECT structure to carry information about a bounding rectangle to use when blitting to the screen or performing hit detection.
In C++, the RECT structure has the following definition.
typedef struct tagRECT { LONG left; // This is the upper-left corner x-coordinate. LONG top; // The upper-left corner y-coordinate. LONG right; // The lower-right corner x-coordinate. LONG bottom; // The lower-right corner y-coordinate. } RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;In the preceding example, the left and top members are the x- and y-coordinates of a bounding rectangle's upper-left corner. Similarly, the right and bottom members make up the coordinates of the lower-right corner. The following diagram illustrates how you can visualize these values.
图见相应DX文档
The column of pixels at the right edge and the row of pixels at the bottom edge are not included in the RECT. For example, locking a RECT with members {10, 10, 138, 138} results in an object 128 pixels in width and height.
In the interest of efficiency, consistency, and ease of use, all Direct3D presentation functions work with rectangles.