|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
Figure 3. The windowing transformation. Click on thumbnail to view full-sized image.
The window's edges are specified at x = wl, x = wr, y = wb, and y = wt. The corresponding viewport edges are located at x = vl, x = vr, y = vb, and y = vt. The following equations use this information to transform world point (xw, yw) to screen point (xs, ys):
xs = (vr - vl) / (wr - wl) * (xw - wl) + vl
ys = (vt - vb) / (wt - wb) * (yw - wb) + vb
These equations determine the position of point (xw, yw) within the window as a fraction of full displacement from the window's lower-left corner, and interpret this fraction as a fraction of full displacement across the viewport. The addition of the viewport's lower-left corner provides the (xs, ys) position on the screen.
Create a Display object by invoking the Display(double wl, double wb, double wr, double wt, int width, int height) constructor. The wl and wb values identify the lower-left corner of a window, whereas the wr and wt values identify the window's upper-right corner. These values are specified in world coordinates. The width and height values identify the extents of a viewport associated with the window. All of these values should be chosen so that the window
and viewport have the same shape. Otherwise, as Figure 3 reveals, you end up with distortion. Because I want the viewport
to occupy the entire component's drawing surface, there is no point in specifying the upper-left corner, which is (0, 0).
The following code fragment creates a window with a lower-left corner at (-100.0, -100.0) and upper-left corner at (100.0, 100.0). The extents are 50 pixels less than the width and height of the applet, to prevent distortion:
display = new Display (-100.0, -100.0, 100.0, 100.0, getWidth ()-50, getHeight ()-50);
After creating the Display object, your animation logic can call any of the following Display methods:
void clear() clears the display to black. Call this method at the beginning of each animation frame to erase previously drawn particles.
You normally do this before updating the particle system.
void drawLine(double x1, double y1, double x2, double y2, Color c) draws a line on the display from (x1, y1) to (x2, y2) and in the color specified by c. Values passed to x1, y1, x2, and y2 are specified in world coordinates. Call this method to draw any shapes (like a rocket ship) after updating the particle
system for the current animation frame.
void plot(double x, double y, Color c) draws a pixel on the display at (x, y) and in the color specified by c. Values passed to x and y are specified in world coordinates. Although the PS class calls this method to plot particles, you can also call this method to assist in drawing any shapes after updating the
particle system for the current animation frame.
Because the aforementioned methods produce output in a buffer (to eliminate one source of flicker), you need to call repaint() on the Display object to make the display's buffer visible.
You're probably wondering why I went to the trouble of creating a window and a viewport. In addition to extra code not necessary if integers were used instead of floating-point values, these floating-pointing values yield simulations that are slower than their integer-based counterparts. I had two reasons for doing what I did:
Archived Discussions (Read only)