📄 svgacc.txt
字号:
proj.theta = 30;
proj.phi = 45;
for(i=0;i<=360;i+=2)
{
d3rotate(8,0,0,0,i,i,i,cube,rcube);
dummy = d3project(8,&proj,rcube,plot);
drwcube();
sdelay(2);
drwcube();
}
drwcube();
getch();
videomodeset(vmode);
}
void drwcube(void)
{
int j;
for(j=0;j<=2;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
drwline(2,10,plot[3].x,plot[3].y,plot[0].x,plot[0].y);
for(j=4;j<=6;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
drwline(2,10,plot[7].x,plot[7].y,plot[4].x,plot[4].y);
for(j=0;j<=3;j++)
31
drwline(2,10,plot[j].x,plot[j].y,plot[j+4].x,plot[j+4].y);
return;
}
32
D3SCALE
PROTOTYPE
extern void far d3scale (int points, int xscale, int yscale,
int zscale, D3Point far *inary, D3Point far *outary)
INPUT
numpoints - number of points to scale
xscale - scale factor along X axis
yscale - scale factor along Y axis
zscale - scale factor along Z axis
inary - D3Point pointer to array containing points to scale
OUTPUT
no value returned
outary - D3Point array of scaled values
USAGE
D3SCALE multiplies each coordinate in the three dimensional
array inary by the corresponding scale factor xscale, yscale
or zscale. The results are stored in outary which can be the
same as inary. A scale factor of 256 (100 hex) is considered
100 percent and results in no change. Therefore, 128 (80 hex)
reduces values by one half and 512 (200 hex) doubles values.
The function assumes space for outary has been properly
allocated.
SEE ALSO
D3PROJECT, D3ROTATE, D3TRANSLATE
EXAMPLE
/*
* shows d3scale works
*/
#include <stdlib.h>
#include <conio.h>
#include "svgacc.h"
D2Point plot[8];
void drwcube(void);
void main(void)
{
int vmode,i,dummy;
ProjParameters proj;
D3Point scube[8];
33
D3Point cube[8] = { { 100,-100, 100},
{ 100,-100,-100},
{ 100, 100,-100},
{ 100, 100, 100},
{-100,-100, 100},
{-100,-100,-100},
{-100, 100,-100},
{-100, 100, 100}};
vmode = videomodeget();
if (!whichvga() || (whichmem() < 512))
exit(1);
res640();
proj.eyex = -1040;
proj.eyey = -600;
proj.eyez = -1200;
proj.scrd = 1700;
proj.theta = 30;
proj.phi = 45;
for(i=256;i>=128;i-=4)
{
d3scale(8,i,i,i,cube,scube);
dummy = d3project(8,&proj,scube,plot);
drwcube();
sdelay(2);
drwcube();
}
for(i=132;i<=256;i+=4)
{
d3scale(8,i,i,i,cube,scube);
dummy = d3project(8,&proj,scube,plot);
drwcube();
sdelay(2);
drwcube();
}
drwcube();
getch();
videomodeset(vmode);
}
void drwcube(void)
{
int j;
for(j=0;j<=2;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
drwline(2,10,plot[3].x,plot[3].y,plot[0].x,plot[0].y);
for(j=4;j<=6;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
34
drwline(2,10,plot[7].x,plot[7].y,plot[4].x,plot[4].y);
for(j=0;j<=3;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+4].x,plot[j+4].y);
return;
}
35
D3TRANSLATE
PROTOTYPE
extern void far d3translate (int points, int xtrans, int
ytrans, int ztrans, D3Point far *inary, D3Point far *outary)
INPUT
numpoints - number of points to translate
xtrans - distance to translate along X axis
ytrans - distance to translate along Y axis
ztrans - distance to translate along Z axis
inary - D3Point pointer to array containing points to
translate
OUTPUT
no value returned
outary - D3Point array of translated points
USAGE
D3TRANSLATE takes the three dimensional points given in inary
and translates them by the specified number of pixels along
each axis. The results are returned in outary which can be
the same as inary. The function assumes space for outary has
been properly allocated.
SEE ALSO
D3PROJECT, D3ROTATE, D3SCALE
EXAMPLE
/*
* shows d3translate works
*/
#include <stdlib.h>
#include <conio.h>
#include "svgacc.h"
D2Point plot[8];
void drwcube(void);
void main(void)
{
int vmode,i,dummy;
ProjParameters proj;
D3Point tcube[8];
D3Point cube[8] = { { 100,-100, 100},
{ 100,-100,-100},
36
{ 100, 100,-100},
{ 100, 100, 100},
{-100,-100, 100},
{-100,-100,-100},
{-100, 100,-100},
{-100, 100, 100}};
vmode = videomodeget();
if (!whichvga() || (whichmem() < 512))
exit(1);
res640();
proj.eyex = -1040;
proj.eyey = -600;
proj.eyez = -1200;
proj.scrd = 1700;
proj.theta = 30;
proj.phi = 45;
for(i=0;i<=400;i+=8)
{
d3translate(8,i,i,i,cube,tcube);
dummy = d3project(8,&proj,tcube,plot);
drwcube();
sdelay(2);
drwcube();
}
for(i=400;i>=0;i-=8)
{
d3translate(8,i,i,i,cube,tcube);
dummy = d3project(8,&proj,tcube,plot);
drwcube();
sdelay(2);
drwcube();
}
drwcube();
getch();
videomodeset(vmode);
}
void drwcube(void)
{
int j;
for(j=0;j<=2;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
drwline(2,10,plot[3].x,plot[3].y,plot[0].x,plot[0].y);
for(j=4;j<=6;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+1].x,plot[j+1].y);
drwline(2,10,plot[7].x,plot[7].y,plot[4].x,plot[4].y);
37
for(j=0;j<=3;j++)
drwline(2,10,plot[j].x,plot[j].y,plot[j+4].x,plot[j+4].y);
return;
}
38
DRWALINE
PROTOTYPE
extern void far drwaline (colrbits, int colr, int x1, int y1,
int x2, int y2)
INPUT
colrbits - number of bits of color
colr - index to color in current palette
x1, y1 - location of one endpoint of line
x2, y2 - location of other endpoint of line
OUTPU
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -