⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgadem2.c

📁 MSC或BC开发的SVGA图形开发库(允许使用300x200,640x480,80x600,1024x768等多种模式) 此开发库特别适合嵌入式系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
	 
	  'SVGACC' A Super Vga Graphics Library for use with Microsoft and
	  Borland C/C++
	  Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill

	  GIF and 'Graphics Intechange Format' are trademarks (tm) of
	  Compuserve, Incorporated, an H&R Block Company.

	**************** UNREGISTERD SHAREWARE VERSION ***********************
	* FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
	* USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
	* OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
	**********************************************************************

	**************** NO WARRANTIES AND NO LIABILITY **********************
	* Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
	* expressed or implied, of merchantability, or fitness, for a        *
	* particular use or purpose of this SOFTWARE and documentation.      *
	* In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
	* liable for any damages resulting from the use or misuse of the     * 
	* SOFTWARE and documentation.                                        *
	**********************************************************************

	************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
	* Use, duplication, or disclosure of the SOFTWARE and documentation  *
	* by the U.S. Government is subject to the restictions as set forth  *
	* in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
	* Computer Software cluse at DFARS 252.227-7013.                     *
	* Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
	* P.O. Box 7704, Austin, Texas 78713-7704                            *
	**********************************************************************

	**********************************************************************
	* By using this SOFTWARE or documentation, you agree to the above    *
	* terms and conditions.                                              *
	**********************************************************************

 ***************************************************************************/

#define MODULE

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <string.h>
#include <dos.h>
#include <math.h>

#include "svgacc.h"

#include "svgademo.h"

char showgif(char fname[]);
void showhouse(D2Point *plotarray, D2Point *oplotarray);
void showstar(D2Point *plotarray, D2Point *oplotarray);


/********
 * DO2D *
 ********/

char do2d(void)
{
	int i, trans;
	int spcing, cntx, cnty;
	D2Point pointarray[9];
	D2Point plotarray[9];
	D2Point oplotarray[9];
	char ret;
	char title[TITLEN];
	char buf[TITLEN];
	char buf2[TITLEN];

	/*
	 * Set up the Title
	 */
	sprintf(title,"DEMO 11: 2D functions");
	palset(pal,0,255);

	/*
	 * Set up the star patter of points
	 */
	cntx = maxx / 2;
	cnty = (maxy - 32) / 2 + 32;
	spcing = maxx / 15;
	pointarray[0].x = 0;
	pointarray[0].y = -spcing * 3;
	pointarray[1].x = spcing;
	pointarray[1].y = -spcing;
	pointarray[2].x = spcing * 3;
	pointarray[2].y = 0;
	pointarray[3].x = spcing;
	pointarray[3].y = spcing;
	pointarray[4].x = 0;
	pointarray[4].y = spcing * 3;
	pointarray[5].x = -spcing;
	pointarray[5].y = spcing;
	pointarray[6].x = -spcing * 3;
	pointarray[6].y = 0;
	pointarray[7].x = -spcing;
	pointarray[7].y = -spcing;
	pointarray[8].x = 0;
	pointarray[8].y = -spcing * 3;

	/*
	 * Show d2translate
	 */
	fillscreen(0);
	setview(0,0,maxx,maxy);
	drwstring(1,7,0,title,10,0);
	sprintf(buf,"d2translate(point,xtrans,ytrans,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	setview(0,32,maxx,maxy);
	d2translate(9,cntx,cnty,pointarray,plotarray);
	showstar(plotarray,oplotarray);
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}
	trans = 0;
	for(i=0;i<spcing;i++) {
		trans+=2;
		d2translate(9,cntx+trans,cnty+trans,pointarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=0;i<spcing;i++) {
		trans-=2;
		d2translate(9,cntx+trans,cnty+trans,pointarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}

	/*
	 * Show d2scale
	 */
	setview(0,16,maxx,31);
	fillview(0);
	setview(0,16,maxx,maxy);
	sprintf(buf,"d2scale(points,xscale,yscale,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	setview(0,32,maxx,maxy);
	d2translate(9,cntx,cnty,pointarray,plotarray);
	showstar(plotarray,oplotarray);
	for(i=256;i<=380;i+=4) {
		d2scale(9,i,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=384;i>=128;i-=4) {
		d2scale(9,i,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=124;i<=256;i+=4) {
		d2scale(9,i,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}

	/*
	 * Show d2rotate
	 */
	setview(0,16,maxx,31);
	fillview(0);
	setview(0,16,maxx,maxy);
	sprintf(buf,"d2rotate(points,xorigin,yorigin,angle,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	sprintf(buf2,"Let's do it about the center of the object.");
	drwstring(1,7,0,buf2,10,32);
	setview(0,48,maxx,maxy);
	d2translate(9,cntx,cnty,pointarray,plotarray);
	showstar(plotarray,oplotarray);
	for(i=0;i<=180;i++) {
		d2rotate(9,0,0,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=180;i>=0;i-=2) {
		d2rotate(9,0,0,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}

	/*
	 * Show d2rotate (about an arbitrary point)
	 */
	setview(0,16,maxx,48);
	fillview(0);
	setview(0,16,maxx,maxy);
	sprintf(buf,"d2rotate(points,xorigin,yorigin,angle,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	sprintf(buf2,"Let's do it about an arbitrary point.");
	drwstring(1,7,0,buf2,10,32);
	setview(0,48,maxx,maxy);
	d2translate(9,cntx,cnty,pointarray,plotarray);
	showstar(plotarray,oplotarray);
	for(i=0;i<=360;i+=2) {
		d2rotate(9,0,spcing*3,i,pointarray,plotarray);
		d2translate(9,cntx,cnty,plotarray,plotarray);
		showstar(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	
	fillscreen(0);
	setview(0,0,maxx,maxy);
	
	return(ret);

}

/********
 * DO3D *
 ********/

char do3d(void)
{
	float pi;
	int i;
	float height, radius;
	int spcing;
	D3Point pointarray[14];
	D3Point playarray[14];
	D2Point plotarray[14];
	D2Point oplotarray[14];
	ProjParameters proj;
	char ret;
	char title[TITLEN];
	char buf[TITLEN];
	

	/*
	 * Set up the Title
	 */
	sprintf(title,"DEMO 12: 3D functions");
	palset(pal,0,255);

	/*
	 * Set up the house pattern of points
	 */
	spcing = maxx / 6;
	pointarray[0].x = -spcing;
	pointarray[0].y = -spcing * 2;
	pointarray[0].z = 0;
	pointarray[1].x = spcing;
	pointarray[1].y = -spcing * 2;
	pointarray[1].z = 0;
	pointarray[2].x = spcing;
	pointarray[2].y = -spcing * 2;
	pointarray[2].z = spcing * 2;
	pointarray[3].x = -spcing;
	pointarray[3].y = -spcing * 2;
	pointarray[3].z = spcing * 2;
	pointarray[4].x = -spcing;
	pointarray[4].y = spcing * 2;
	pointarray[4].z = 0;
	pointarray[5].x = spcing;
	pointarray[5].y = spcing * 2;
	pointarray[5].z = 0;
	pointarray[6].x = spcing;
	pointarray[6].y = spcing * 2;
	pointarray[6].z = spcing * 2;
	pointarray[7].x = -spcing;
	pointarray[7].y = spcing * 2;
	pointarray[7].z = spcing * 2;
	pointarray[8].x = 0;
	pointarray[8].y = -spcing * 2;
	pointarray[8].z = spcing * 3;
	pointarray[9].x = 0;
	pointarray[9].y = spcing * 2;
	pointarray[9].z = spcing * 3;
	pointarray[10].x = 0;
	pointarray[10].y = 0;
	pointarray[10].z = 0;
	pointarray[11].x = spcing * 4;
	pointarray[11].y = 0;
	pointarray[11].z = 0;
	pointarray[12].x = 0;
	pointarray[12].y = 0;
	pointarray[12].z = spcing * 4;
	pointarray[13].x = 0;
	pointarray[13].y = spcing * 4;
	pointarray[13].z = 0;
	bytecopy(pointarray,playarray,sizeof(pointarray));

	/*
	 * Show d3project
	 */
	setview(0,0,maxx,maxy);
	pi = (float)(4. * atan(1) / 180.);
	fillscreen(0);
	drwstring(1,7,0,title,10,0);
	sprintf(buf,"d3project(points,projparams,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	setview(0,32,maxx,maxy);
	height = (float)(maxy * 8);
	radius = (float)(maxx * 30);
	proj.scrd = (int)(sqrt(radius * radius + height * height) / 2.);
	proj.theta = 110;
	proj.phi = (int)(atan(height / -radius) / pi);
	proj.eyex = (int)(-radius * cos(proj.theta * pi));
	proj.eyey = (int)(-radius * sin(proj.theta * pi));
	proj.eyez = (int)height;
	d3project(14,&proj,playarray,plotarray);
	for(i=0;i<14;i++) {
		oplotarray[i].x = plotarray[i].x;
		oplotarray[i].y = plotarray[i].y;
	}
	showhouse(plotarray,oplotarray);
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}
	for(i=112;i<=470;i+=3) {
		proj.theta = i;
		proj.eyex = (int)(-radius * cos(proj.theta * pi));
		proj.eyey = (int)(-radius * sin(proj.theta * pi));
		d3project(14,&proj,playarray,plotarray);
		showhouse(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}

	/*
	 * Show d3translate
	 */
	setview(0,16,maxx,31);
	fillview(0);
	sprintf(buf,"d3translate(points,xtrans,ytrans,ztrans,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	setview(0,32,maxx,maxy);
	for(i=2;i<=300;i+=6) {
		d3translate(10,i,i,0,pointarray,playarray);
		d3project(10,&proj,playarray,plotarray);
		showhouse(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=302;i>=2;i-=6) {
		d3translate(10,i,i,0,pointarray,playarray);
		d3project(10,&proj,playarray,plotarray);
		showhouse(plotarray,oplotarray);
		sdelay(2);
	}
	ret = getkey();
	if ((ret=='s') || (ret=='q')) {
		fillscreen(0);
		setview(0,0,maxx,maxy);
		return(ret);
	}

	/*
	 * Show d3scale
	 */
	setview(0,16,maxx,31);
	fillview(0);
	sprintf(buf,"d3scale(points,xscale,yscale,zscale,inarray,outarray);");
	drwstring(1,7,0,buf,10,16);
	setview(0,32,maxx,maxy);
	for(i=256;i<=380;i+=4) {
		d3scale(10,i,i,i,pointarray,playarray);
		d3project(10,&proj,playarray,plotarray);
		showhouse(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=384;i>=128;i-=4) {
		d3scale(10,i,i,i,pointarray,playarray);
		d3project(10,&proj,playarray,plotarray);
		showhouse(plotarray,oplotarray);
		sdelay(2);
	}
	for(i=124;i<=256;i+=4) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -