Tham khảo tài liệu 'c++ programming for games module ii phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Shape Primitives Drawing Lines Line drawing is done with two functions. The first function moves the virtual pen to the starting point of the line. The second function draws a line from the previously specified starting point to a newly specified second point Following two functions draws a line from startX startY to endX endY . MoveToEx hdc startX startY 0 LineTo hdc endX endY Both functions take a handle to the device context as all drawing must be done through the device context. The second and third parameters for both functions are the x- and y-coordinates of a point which is relative to the client area rectangle. For MoveToEx that point is the starting point of the line. For LineTo that point is the ending point of the line. The fourth parameter of MoveToEx returns a POINT object of the last start point that was specified via a pointer parameter. If this value is not needed you can specify null. The program we will write to illustrate line drawing allows the user to define the line s start point by pressing the left mouse button. The user holds the left mouse button down and moves the mouse to a new point. When the user has found the point where he she wants the line s end point to be the user raises the left mouse button up. Figure shows the program after some lines were drawn. Figure The line drawing program. Users can draw lines by holding the left mouse button down 131 As the user moves the mouse around looking for the end point he she will expect to see the new line being drawn in real-time. That is a line from the start point to the current mouse position should constantly be drawn and updated interactively. In this way the user can see exactly how the line will look before raising the left mouse button to make the line permanent. This functionality requires some special code. Let us get started. First we have the following global variables and also a structure definition struct Line POINT p0 POINT p1 vector Line gLines Line gLine