Replace invalid characters with HTML entities
— with — ’ with ’ + with + × with x ç with ç “ with “ ” with ” ‘ with ‘ • with • – with - µ with µ † with † Fix C++ θ with θ Yen symbol instead of times Fix broken apos Bullet again E-circumflex
This commit is contained in:
parent
9e52de9586
commit
500e7f5654
353 changed files with 5091 additions and 5091 deletions
60
49-04.html
60
49-04.html
|
|
@ -37,11 +37,11 @@
|
|||
</CENTER>
|
||||
<P><BR></P>
|
||||
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Animation</FONT></H3>
|
||||
<P>Gosh. There’s just no way I can discuss high-level animation fundamentals in any detail here; I could spend an entire (and entirely separate) book on animation techniques alone. You might want to have a look at Chapters 43 through 46 before attacking the code in this chapter; that will have to do us for the present volume. (I will return to <I>3-D</I> animation in the next chapter.)</P>
|
||||
<P>Basically, I’m going to perform page flipped animation, in which one page (that is, a bitmap large enough to hold a full screen) of display memory is displayed while another page is drawn to. When the drawing is finished, the newly modified page is displayed, and the other—now invisible—page is drawn to. The process repeats ad infinitum. For further information, some good places to start are <I>Computer Graphics</I>, by Foley and van Dam (Addison-Wesley); <I>Principles of Interactive Computer Graphics</I>, by Newman and Sproull (McGraw Hill); and “Real-Time Animation” by Rahner James (January 1990, <I>Dr. Dobb’s Journal</I>).</P>
|
||||
<P>Some of the code in this chapter was adapted for Mode X from the code in Chapter 44—yet another reason to read that chapter before finishing this one.</P>
|
||||
<P>Gosh. There’s just no way I can discuss high-level animation fundamentals in any detail here; I could spend an entire (and entirely separate) book on animation techniques alone. You might want to have a look at Chapters 43 through 46 before attacking the code in this chapter; that will have to do us for the present volume. (I will return to <I>3-D</I> animation in the next chapter.)</P>
|
||||
<P>Basically, I’m going to perform page flipped animation, in which one page (that is, a bitmap large enough to hold a full screen) of display memory is displayed while another page is drawn to. When the drawing is finished, the newly modified page is displayed, and the other—now invisible—page is drawn to. The process repeats ad infinitum. For further information, some good places to start are <I>Computer Graphics</I>, by Foley and van Dam (Addison-Wesley); <I>Principles of Interactive Computer Graphics</I>, by Newman and Sproull (McGraw Hill); and “Real-Time Animation” by Rahner James (January 1990, <I>Dr. Dobb’s Journal</I>).</P>
|
||||
<P>Some of the code in this chapter was adapted for Mode X from the code in Chapter 44—yet another reason to read that chapter before finishing this one.</P>
|
||||
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Mode X Animation in Action</FONT></H3>
|
||||
<P>Listing 49.5 ties together everything I’ve discussed about Mode X so far in a compact but surprisingly powerful animation package. Listing 49.5 first uses solid and patterned fills and system-memory-to-screen-memory masked copying to draw a static background containing a mountain, a sun, a plain, water, and a house with puffs of smoke coming out of the chimney, and sets up the four alignments of a masked kite image. The background is transferred to both display pages, and drawing of 20 kite images in the nondisplayed page using fast masked copying begins. After all images have been drawn, the page is flipped to show the newly updated screen, and the kites are moved and drawn in the other page, which is no longer displayed. Kites are erased at their old positions in the nondisplayed page by block copying from the background page. (See the discussion in the previous chapter for the display memory organization used by Listing 49.5.) So far as the displayed image is concerned, there is never any hint of flicker or disturbance of the background. This continues at a rate of up to 60 times a second until Esc is pressed to exit the program. See Figure 49.1 for a screen shot of the resulting image—add the animation in your imagination.
|
||||
<P>Listing 49.5 ties together everything I’ve discussed about Mode X so far in a compact but surprisingly powerful animation package. Listing 49.5 first uses solid and patterned fills and system-memory-to-screen-memory masked copying to draw a static background containing a mountain, a sun, a plain, water, and a house with puffs of smoke coming out of the chimney, and sets up the four alignments of a masked kite image. The background is transferred to both display pages, and drawing of 20 kite images in the nondisplayed page using fast masked copying begins. After all images have been drawn, the page is flipped to show the newly updated screen, and the kites are moved and drawn in the other page, which is no longer displayed. Kites are erased at their old positions in the nondisplayed page by block copying from the background page. (See the discussion in the previous chapter for the display memory organization used by Listing 49.5.) So far as the displayed image is concerned, there is never any hint of flicker or disturbance of the background. This continues at a rate of up to 60 times a second until Esc is pressed to exit the program. See Figure 49.1 for a screen shot of the resulting image—add the animation in your imagination.
|
||||
</P>
|
||||
<P><A NAME="Fig1"><!-- </A><A HREF="javascript:displayWindow('images/49-01.jpg',227,175 )"> --><IMG SRC="images/49-01.jpg"><BR><!-- </A>
|
||||
<BR><A HREF="javascript:displayWindow('images/49-01.jpg',227,175)"> --><FONT COLOR="#000077"><B>Figure 49.1</B></FONT></A> <I>An animated Mode X screen.</I>
|
||||
|
|
@ -50,13 +50,13 @@
|
|||
<!-- CODE //-->
|
||||
<PRE>
|
||||
/* Sample mode X VGA animation program. Portions of this code first appeared
|
||||
in PC Techniques. Compiled with Borland C++ 2.0 in C compilation mode. */
|
||||
in PC Techniques. Compiled with Borland C++ 2.0 in C compilation mode. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <dos.h>
|
||||
#include <math.h>
|
||||
#include “maskim.h”
|
||||
#include “maskim.h”
|
||||
|
||||
#define SCREEN_SEG 0xA000
|
||||
#define SCREEN_WIDTH 320
|
||||
|
|
@ -180,7 +180,7 @@ void main()
|
|||
if (CreateAlignedMaskedImage(&KiteImage, DOWNLOAD_START_OFFSET,
|
||||
KitePixels, KITE_WIDTH, KITE_HEIGHT, KiteMask) == 0) {
|
||||
regset.x.ax = 0x0003; int86(0x10, &regset, &regset);
|
||||
printf(“Couldn’t get memory\n”); exit();
|
||||
printf(“Couldn’t get memory\n”); exit();
|
||||
}
|
||||
/* Draw the background to the background page. */
|
||||
DrawBackground(BG_START_OFFSET);
|
||||
|
|
@ -196,19 +196,19 @@ void main()
|
|||
NonDisplayedPage = DisplayedPage ^ 1;
|
||||
/* Erase each object in nondisplayed page by copying block from
|
||||
background page at last location in that page. */
|
||||
for (i=0; i<NUM_OBJECTS; i++) {
|
||||
for (i=0; i<NUM_OBJECTS; i++) {
|
||||
CopyScreenToScreenX(AnimatedObjects[i].XOtherPage,
|
||||
AnimatedObjects[i].YOtherPage,
|
||||
AnimatedObjects[i].XOtherPage +
|
||||
AnimatedObjects[i].XOtherPage +
|
||||
AnimatedObjects[i].Width,
|
||||
AnimatedObjects[i].YOtherPage +
|
||||
AnimatedObjects[i].YOtherPage +
|
||||
AnimatedObjects[i].Height,
|
||||
AnimatedObjects[i].XOtherPage,
|
||||
AnimatedObjects[i].YOtherPage, BG_START_OFFSET,
|
||||
PageStartOffsets[NonDisplayedPage], SCREEN_WIDTH, SCREEN_WIDTH);
|
||||
}
|
||||
/* Move and draw each object in the nondisplayed page. */
|
||||
for (i=0; i<NUM_OBJECTS; i++) {
|
||||
for (i=0; i<NUM_OBJECTS; i++) {
|
||||
MoveObject(&AnimatedObjects[i]);
|
||||
/* Draw object into nondisplayed page at new location */
|
||||
CopyScreenToScreenMaskedX(0, 0, AnimatedObjects[i].Width,
|
||||
|
|
@ -218,7 +218,7 @@ void main()
|
|||
}
|
||||
/* Flip to the page into which we just drew. */
|
||||
ShowPage(PageStartOffsets[DisplayedPage = NonDisplayedPage]);
|
||||
/* See if it’s time to end. */
|
||||
/* See if it’s time to end. */
|
||||
if (kbhit()) {
|
||||
if (getch() == 0x1B) Done = 1; /* Esc to end */
|
||||
}
|
||||
|
|
@ -238,27 +238,27 @@ void DrawBackground(unsigned int PageStart)
|
|||
FillRectangleX(0, SCREEN_HEIGHT-30, SCREEN_WIDTH, SCREEN_HEIGHT,
|
||||
PageStart, 1);
|
||||
/* Draw a brown mountain rising out of the plain. */
|
||||
for (i=0; i<120; i++)
|
||||
FillRectangleX(SCREEN_WIDTH/2-30-i, 51+i, SCREEN_WIDTH/2-30+i+1,
|
||||
51+i+1, PageStart, 6);
|
||||
for (i=0; i<120; i++)
|
||||
FillRectangleX(SCREEN_WIDTH/2-30-i, 51+i, SCREEN_WIDTH/2-30+i+1,
|
||||
51+i+1, PageStart, 6);
|
||||
/* Draw a yellow sun by overlapping rects of various shapes. */
|
||||
for (i=0; i<=20; i++) {
|
||||
Temp = (int)(sqrt(20.0*20.0 - (float)i*(float)i) + 0.5);
|
||||
FillRectangleX(SCREEN_WIDTH-25-i, 30-Temp, SCREEN_WIDTH-25+i+1,
|
||||
30+Temp+1, PageStart, 14);
|
||||
for (i=0; i<=20; i++) {
|
||||
Temp = (int)(sqrt(20.0*20.0 - (float)i*(float)i) + 0.5);
|
||||
FillRectangleX(SCREEN_WIDTH-25-i, 30-Temp, SCREEN_WIDTH-25+i+1,
|
||||
30+Temp+1, PageStart, 14);
|
||||
}
|
||||
/* Draw green trees down the side of the mountain. */
|
||||
for (i=10; i<90; i += 15)
|
||||
for (j=0; j<20; j++)
|
||||
FillPatternX(SCREEN_WIDTH/2+i-j/3-15, i+j+51,SCREEN_WIDTH/2+i+j/3-15+1,
|
||||
i+j+51+1, PageStart, PineTreePattern);
|
||||
for (i=10; i<90; i += 15)
|
||||
for (j=0; j<20; j++)
|
||||
FillPatternX(SCREEN_WIDTH/2+i-j/3-15, i+j+51,SCREEN_WIDTH/2+i+j/3-15+1,
|
||||
i+j+51+1, PageStart, PineTreePattern);
|
||||
/* Draw a house on the plain. */
|
||||
FillPatternX(265, 150, 295, 170, PageStart, BrickPattern);
|
||||
FillPatternX(265, 130, 270, 150, PageStart, BrickPattern);
|
||||
for (i=0; i<12; i++)
|
||||
FillPatternX(280-i*2, 138+i, 280+i*2+1, 138+i+1, PageStart, RoofPattern);
|
||||
for (i=0; i<12; i++)
|
||||
FillPatternX(280-i*2, 138+i, 280+i*2+1, 138+i+1, PageStart, RoofPattern);
|
||||
/* Finally, draw puffs of smoke rising from the chimney. */
|
||||
for (i=0; i<4; i++)
|
||||
for (i=0; i<4; i++)
|
||||
CopySystemToScreenMaskedX(0, 0, SMOKE_WIDTH, SMOKE_HEIGHT, 264,
|
||||
110-i*20, SmokePixels, PageStart, SMOKE_WIDTH,SCREEN_WIDTH, SmokeMask);
|
||||
}
|
||||
|
|
@ -266,15 +266,15 @@ void DrawBackground(unsigned int PageStart)
|
|||
remembering where the object was before the move for erasing next time. */
|
||||
void MoveObject(AnimatedObject * ObjectToMove) {
|
||||
int X, Y;
|
||||
X = ObjectToMove->X + ObjectToMove->XDir;
|
||||
Y = ObjectToMove->Y + ObjectToMove->YDir;
|
||||
X = ObjectToMove->X + ObjectToMove->XDir;
|
||||
Y = ObjectToMove->Y + ObjectToMove->YDir;
|
||||
if ((X < 0) || (X > (SCREEN_WIDTH - ObjectToMove->Width))) {
|
||||
ObjectToMove->XDir = -ObjectToMove->XDir;
|
||||
X = ObjectToMove->X + ObjectToMove->XDir;
|
||||
X = ObjectToMove->X + ObjectToMove->XDir;
|
||||
}
|
||||
if ((Y < 0) || (Y > (SCREEN_HEIGHT - ObjectToMove->Height))) {
|
||||
ObjectToMove->YDir = -ObjectToMove->YDir;
|
||||
Y = ObjectToMove->Y + ObjectToMove->YDir;
|
||||
Y = ObjectToMove->Y + ObjectToMove->YDir;
|
||||
}
|
||||
/* Remember previous location for erasing purposes. */
|
||||
ObjectToMove->XOtherPage = ObjectToMove->X;
|
||||
|
|
|
|||
Loading…
Reference in a new issue