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
72
65-03.html
72
65-03.html
|
|
@ -52,13 +52,13 @@ int ClipToPlane(polygon_t *pin, plane_t *pplane, polygon_t *pout)
|
|||
curdot = DotProduct(pinvert, &pplane->normal);
|
||||
curin = (curdot >= pplane->distance);
|
||||
|
||||
for (i=0 ; i<pin->numverts ; i++)
|
||||
for (i=0 ; i<pin->numverts ; i++)
|
||||
{
|
||||
nextvert = (i + 1) % pin->numverts;
|
||||
nextvert = (i + 1) % pin->numverts;
|
||||
|
||||
// Keep the current vertex if it’s inside the plane
|
||||
// Keep the current vertex if it’s inside the plane
|
||||
if (curin)
|
||||
*poutvert++ = *pinvert;
|
||||
*poutvert++ = *pinvert;
|
||||
|
||||
nextdot = DotProduct(&pin->verts[nextvert], &pplane->normal);
|
||||
nextin = (nextdot >= pplane->distance);
|
||||
|
|
@ -69,18 +69,18 @@ int ClipToPlane(polygon_t *pin, plane_t *pplane, polygon_t *pout)
|
|||
{
|
||||
scale = (pplane->distance - curdot) /
|
||||
(nextdot - curdot);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
poutvert->v[j] = pinvert->v[j] +
|
||||
poutvert->v[j] = pinvert->v[j] +
|
||||
((pin->verts[nextvert].v[j] - pinvert->v[j]) *
|
||||
scale);
|
||||
}
|
||||
poutvert++;
|
||||
poutvert++;
|
||||
}
|
||||
|
||||
curdot = nextdot;
|
||||
curin = nextin;
|
||||
pinvert++;
|
||||
pinvert++;
|
||||
}
|
||||
|
||||
pout->numverts = poutvert - pout->verts;
|
||||
|
|
@ -92,11 +92,11 @@ int ClipToPlane(polygon_t *pin, plane_t *pplane, polygon_t *pout)
|
|||
}
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
<P>Believe it or not, this technique, applied in turn to each edge, is all that’s needed to clip a polygon to a plane. Better yet, a polygon can be clipped to multiple planes by repeating the above process once for each clip plane, with each interation trimming away any part of the polygon that’s clipped by that particular plane.
|
||||
<P>Believe it or not, this technique, applied in turn to each edge, is all that’s needed to clip a polygon to a plane. Better yet, a polygon can be clipped to multiple planes by repeating the above process once for each clip plane, with each interation trimming away any part of the polygon that’s clipped by that particular plane.
|
||||
</P>
|
||||
<P>One particularly useful aspect of 3-D clipping is that if you’re drawing texture mapped polygons, texture coordinates can be clipped in exactly the same way as (x,y,z) coordinates. In fact, the very same fraction that’s used to advance x, y, and z from the inside point to the point of intersection with the clip plane can be used to advance the texture coordinates as well, so only one extra multiply and one extra add are required for each texture coordinate.</P>
|
||||
<P>One particularly useful aspect of 3-D clipping is that if you’re drawing texture mapped polygons, texture coordinates can be clipped in exactly the same way as (x,y,z) coordinates. In fact, the very same fraction that’s used to advance x, y, and z from the inside point to the point of intersection with the clip plane can be used to advance the texture coordinates as well, so only one extra multiply and one extra add are required for each texture coordinate.</P>
|
||||
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Clipping to the Frustum</FONT></H4>
|
||||
<P>Given a polygon-clipping function, it’s easy to clip to the frustum: set up the four planes for the sides of the frustum, with another one or two planes for near and far clipping, if desired; next, clip each potentially visible polygon to each plane in turn; then draw whatever polygons emerge from the clipping process. Listing 65.3 is the core code for a simple 3-D clipping example that allows you to move around and look at polygonal models from any angle. The full code for this program is available on the CD-ROM in the file DDJCLIP.ZIP.
|
||||
<P>Given a polygon-clipping function, it’s easy to clip to the frustum: set up the four planes for the sides of the frustum, with another one or two planes for near and far clipping, if desired; next, clip each potentially visible polygon to each plane in turn; then draw whatever polygons emerge from the clipping process. Listing 65.3 is the core code for a simple 3-D clipping example that allows you to move around and look at polygonal models from any angle. The full code for this program is available on the CD-ROM in the file DDJCLIP.ZIP.
|
||||
</P>
|
||||
<P><A NAME="Fig3"><!-- </A><A HREF="javascript:displayWindow('images/65-03.jpg',408,197 )"> --><IMG SRC="images/65-03.jpg"><BR><!-- </A>
|
||||
<BR><A HREF="javascript:displayWindow('images/65-03.jpg',408,197)"> --><FONT COLOR="#000077"><B>Figure 65.3</B></FONT></A> <I>Clipping a polygon edge.</I>
|
||||
|
|
@ -130,13 +130,13 @@ void ProjectPolygon (polygon_t *ppoly, polygon2D_t *ppoly2D)
|
|||
int i;
|
||||
double zrecip;
|
||||
|
||||
for (i=0 ; i<ppoly->numverts ; i++)
|
||||
for (i=0 ; i<ppoly->numverts ; i++)
|
||||
{
|
||||
zrecip = 1.0 / ppoly->verts[i].v[2];
|
||||
ppoly2D->verts[i].x =
|
||||
ppoly->verts[i].v[0] * zrecip * maxscale + xcenter;
|
||||
ppoly->verts[i].v[0] * zrecip * maxscale + xcenter;
|
||||
ppoly2D->verts[i].y = DIBHeight -
|
||||
(ppoly->verts[i].v[1] * zrecip * maxscale + ycenter);
|
||||
(ppoly->verts[i].v[1] * zrecip * maxscale + ycenter);
|
||||
}
|
||||
ppoly2D->color = ppoly->color;
|
||||
ppoly2D->numverts = ppoly->numverts;
|
||||
|
|
@ -151,12 +151,12 @@ void ZSortObjects(void)
|
|||
point_t dist;
|
||||
|
||||
objecthead.pnext = &objecthead;
|
||||
for (i=0 ; i<numobjects ; i++)
|
||||
for (i=0 ; i<numobjects ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
for (j=0 ; j<3 ; j++)
|
||||
dist.v[j] = objects[i].center.v[j] - currentpos.v[j];
|
||||
objects[i].vdist = sqrt(dist.v[0] * dist.v[0] +
|
||||
dist.v[1] * dist.v[1] +
|
||||
objects[i].vdist = sqrt(dist.v[0] * dist.v[0] +
|
||||
dist.v[1] * dist.v[1] +
|
||||
dist.v[2] * dist.v[2]);
|
||||
pobject = &objecthead;
|
||||
vdist = objects[i].vdist;
|
||||
|
|
@ -182,9 +182,9 @@ void UpdateViewPos()
|
|||
motionvec.v[0] = DotProduct(&vpn, &xaxis);
|
||||
motionvec.v[1] = 0.0;
|
||||
motionvec.v[2] = DotProduct(&vpn, &zaxis);
|
||||
for (i=0 ; i<3 ; i++)
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
currentpos.v[i] += motionvec.v[i] * currentspeed;
|
||||
currentpos.v[i] += motionvec.v[i] * currentspeed;
|
||||
if (currentpos.v[i] > MAX_COORD)
|
||||
currentpos.v[i] = MAX_COORD;
|
||||
if (currentpos.v[i] < -MAX_COORD)
|
||||
|
|
@ -218,7 +218,7 @@ void UpdateViewPos()
|
|||
// Break out the rotation matrix into vright, vup, and vpn.
|
||||
// We could work directly with the matrix; breaking it out
|
||||
// into three vectors is just to make things clearer
|
||||
for (i=0 ; i<3 ; i++)
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
vright.v[i] = mtemp2[0][i];
|
||||
vup.v[i] = mtemp2[1][i];
|
||||
|
|
@ -228,7 +228,7 @@ void UpdateViewPos()
|
|||
if (currentspeed > (MOVEMENT_SPEED * speedscale / 2.0))
|
||||
currentspeed -= MOVEMENT_SPEED * speedscale / 2.0;
|
||||
else if (currentspeed < -(MOVEMENT_SPEED * speedscale / 2.0))
|
||||
currentspeed += MOVEMENT_SPEED * speedscale / 2.0;
|
||||
currentspeed += MOVEMENT_SPEED * speedscale / 2.0;
|
||||
else
|
||||
currentspeed = 0.0;
|
||||
}
|
||||
|
|
@ -239,9 +239,9 @@ void BackRotateVector(point_t *pin, point_t *pout)
|
|||
int i;
|
||||
|
||||
// Rotate into the world orientation
|
||||
for (i=0 ; i<3 ; i++)
|
||||
pout->v[i] = pin->v[0] * vright.v[i] +
|
||||
pin->v[1] * vup.v[i] +
|
||||
for (i=0 ; i<3 ; i++)
|
||||
pout->v[i] = pin->v[0] * vright.v[i] +
|
||||
pin->v[1] * vup.v[i] +
|
||||
pin->v[2] * vpn.v[i];
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ void TransformPoint(point_t *pin, point_t *pout)
|
|||
point_t tvert;
|
||||
|
||||
// Translate into a viewpoint-relative coordinate
|
||||
for (i=0 ; i<3 ; i++)
|
||||
for (i=0 ; i<3 ; i++)
|
||||
tvert.v[i] = pin->v[i] - currentpos.v[i];
|
||||
// Rotate into the view orientation
|
||||
pout->v[0] = DotProduct(&tvert, &vright);
|
||||
|
|
@ -265,7 +265,7 @@ void TransformPolygon(polygon_t *pinpoly, polygon_t *poutpoly)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<pinpoly->numverts ; i++)
|
||||
for (i=0 ; i<pinpoly->numverts ; i++)
|
||||
TransformPoint(&pinpoly->verts[i], &poutpoly->verts[i]);
|
||||
poutpoly->color = pinpoly->color;
|
||||
poutpoly->numverts = pinpoly->numverts;
|
||||
|
|
@ -278,7 +278,7 @@ int PolyFacesViewer(polygon_t *ppoly)
|
|||
int i;
|
||||
point_t viewvec, edge1, edge2, normal;
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
viewvec.v[i] = ppoly->verts[0].v[i] - currentpos.v[i];
|
||||
edge1.v[i] = ppoly->verts[0].v[i] - ppoly->verts[1].v[i];
|
||||
|
|
@ -297,7 +297,7 @@ void SetWorldspaceClipPlane(point_t *normal, plane_t *plane)
|
|||
|
||||
// Rotate the plane normal into worldspace
|
||||
BackRotateVector(normal, &plane->normal);
|
||||
plane->distance = DotProduct(&currentpos, &plane->normal) +
|
||||
plane->distance = DotProduct(&currentpos, &plane->normal) +
|
||||
CLIP_PLANE_EPSILON;
|
||||
}
|
||||
|
||||
|
|
@ -339,7 +339,7 @@ int ClipToFrustum(polygon_t *pin, polygon_t *pout)
|
|||
|
||||
curpoly = 0;
|
||||
ppoly = pin;
|
||||
for (i=0 ; i<(NUM_FRUSTUM_PLANES-1); i++)
|
||||
for (i=0 ; i<(NUM_FRUSTUM_PLANES-1); i++)
|
||||
{
|
||||
if (!ClipToPlane(ppoly,
|
||||
&frustumplanes[i],
|
||||
|
|
@ -373,15 +373,15 @@ void UpdateWorld()
|
|||
while (pobject != &objecthead)
|
||||
{
|
||||
ppoly = pobject->ppoly;
|
||||
for (i=0 ; i<pobject->numpolys ; i++)
|
||||
for (i=0 ; i<pobject->numpolys ; i++)
|
||||
{
|
||||
// Move the polygon relative to the object center
|
||||
tpoly0.color = ppoly->color;
|
||||
tpoly0.numverts = ppoly->numverts;
|
||||
for (j=0 ; j<tpoly0.numverts ; j++)
|
||||
for (j=0 ; j<tpoly0.numverts ; j++)
|
||||
{
|
||||
for (k=0 ; k<3 ; k++)
|
||||
tpoly0.verts[j].v[k] = ppoly->verts[j].v[k] +
|
||||
for (k=0 ; k<3 ; k++)
|
||||
tpoly0.verts[j].v[k] = ppoly->verts[j].v[k] +
|
||||
pobject->center.v[k];
|
||||
}
|
||||
if (PolyFacesViewer(&tpoly0))
|
||||
|
|
@ -393,11 +393,11 @@ void UpdateWorld()
|
|||
FillPolygon2D (&screenpoly);
|
||||
}
|
||||
}
|
||||
ppoly++;
|
||||
ppoly++;
|
||||
}
|
||||
pobject = pobject->pnext;
|
||||
}
|
||||
// We’ve drawn the frame; copy it to the screen
|
||||
// We’ve drawn the frame; copy it to the screen
|
||||
hdcScreen = GetDC(hwndOutput);
|
||||
holdpal = SelectPalette(hdcScreen, hpalDIB, FALSE);
|
||||
RealizePalette(hdcScreen);
|
||||
|
|
|
|||
Loading…
Reference in a new issue