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

📄 irisglcdt.c

📁 关于限制性四叉树实现算法的
💻 C
字号:
/********************************************************************************* irisglCDT.c: a simple Iris GL test program for constructing CDTs.**** Copyright (C) 1995 by Dani Lischinski **** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.********************************************************************************/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <gl.h>#include <device.h>#include "cdt.h"void getArguments(int, char**, int*);void InsertPoints(void*, int);void display(void*, double, double, double, double);char *program;double points[100] = {0, 0,                      0.3, 0,                      0.8, 0,                      1, 0,                      1, 0.1,                      1, 0.7,                      1, 1,                      0.5, 1,                      0, 1};main(int argc, char** argv){	int num = 20;	void *mesh;	getArguments(argc, argv, &num);	mesh = create_mesh(9, points);	InsertPoints(mesh, num);	display(mesh, 0.0, 0.0, 1.0, 1.0);}static void usage(){	fprintf(stderr, "usage: %s [ -n number_of_points ]\n", program);}static void errmsg(char *msg){	fprintf(stderr, "%s: %s\n", program, msg);	usage();	exit(1);}void getArguments(int argc, char** argv, int *num){	int i;	program = argv[0];	if (argc == 2 && strcmp(argv[1], "-h") == 0) {		usage();		exit(0);	}	for (i = 1; i < argc && argv[i][0] == '-'; i++)		if (strcmp(argv[i], "-n") == 0) {			if(++i < argc)				*num = atoi(argv[i]);			else				errmsg("option ``-n'': missing parameter");		} else			errmsg("unknown option");		if(argc - i > 0)		errmsg("too many parameters");}extern double drand48(void);void InsertPoints(void *mesh, int num){	int i;	if (num % 2) {		for (i = 0; i < num; i++) {			insert_vertex(mesh, drand48(), drand48());		}	} else {		for (i = 0; i < num/2; i += 2) {			insert_edge(mesh, drand48(),drand48(), drand48(), drand48());		}	}}long createWindow(char *title){	long wid;	prefsize(500, 500);	wid = winopen(title);	doublebuffer();	RGBmode();	gconfig();	return wid;}void meshDraw(void *mesh){	cpack(0);	clear();	draw_mesh(mesh, 0);	swapbuffers();}void setView(float cx, float cy, float xsize, float ysize){	float dx = 0.5 * xsize;	float dy = 0.5 * ysize;	ortho2(cx - dx, cx + dx, cy - dy, cy + dy);}void printHelp(){	fprintf(stderr, "\n");	fprintf(stderr, " <h>       print this message\n");	fprintf(stderr, " <q>       quit program\n");	fprintf(stderr, " <left>    insert a new point\n");	fprintf(stderr, " <right>   insert a constrained edge\n");}void getMouse (		float cx, float cy,		float xsize, float ysize,		float* x, float* y){	long sx, sy, ox, oy, sxsize, sysize;	Coord p[3], v[3];	sx = getvaluator(MOUSEX);	sy = getvaluator(MOUSEY);	getorigin(&ox, &oy);	sx -= ox;	sy -= oy;	getsize(&sxsize, &sysize);	*x = (((float)sx) / ((float)sxsize)) * xsize - 0.5 * xsize + cx;	*y = (((float)sy) / ((float)sysize)) * ysize - 0.5 * ysize + cy;	*x = (*x < 0) ? 0 : (*x > 1) ? 1 : *x;	*y = (*y < 0) ? 0 : (*y > 1) ? 1 : *y;}void display(void *mesh, double left, double bottom, double right, double top){	float cx, cy, xsize, ysize, x, y, xprev, yprev;	int done;	long wid = createWindow(program);	cx = 0.5 * (left + right);	cy = 0.5 * (bottom + top);	xsize = 1.1 * (right - left);	ysize = 1.1 * (top - bottom);	setView(cx, cy, xsize, ysize);	qdevice(HKEY);	qdevice(QKEY);	qdevice(LEFTMOUSE);	qdevice(RIGHTMOUSE);	qreset();	qenter(REDRAW, (short)wid);	for (done = FALSE; !done; ) {		short val;		switch(qread(&val)) {		case REDRAW:			winset(wid);			reshapeviewport();			setView(cx, cy, xsize, ysize);			meshDraw(mesh);			break;		case HKEY:			if(val)				printHelp();			break;		case QKEY:			if(val)				done = TRUE;			break;		case LEFTMOUSE:			if(val) {				getMouse(cx, cy, xsize, ysize, &x, &y);				insert_vertex(mesh, x, y);				xprev = x, yprev = y;				qreset();				meshDraw(mesh);			}			break;		case RIGHTMOUSE:			if(val) {				getMouse(cx, cy, xsize, ysize, &x, &y);				insert_edge(mesh, xprev, yprev, x, y);				xprev = x, yprev = y;				qreset();				meshDraw(mesh);			}			break;		}	}	winclose(wid);	gexit();}

⌨️ 快捷键说明

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