Esempio n. 1
0
File: wicom.c Progetto: jemos/wicom
wstatus
draw_routine2(wvdraw_t draw,void *param)
{
	shape_t s;
	memset(&s,0,sizeof(s));

	if( draw.flags & WVDRAW_FLAG_ORTHOGONAL )
	{
		s.type = SHAPE_TEXT;
		s.data.text.content = "XPTO IN ORTHO!";
		s.data.text.position.x = 200.0;
		s.data.text.position.y = 200.0;
		s.data.text.position.z = 0;
		s.data.text.font = TEXT_FONT_SMALL;
		V3_SET(s.data.text.color,0,0,1);
		wview_draw_shape(s);
	}

	return WSTATUS_SUCCESS;
}
Esempio n. 2
0
File: wicom.c Progetto: jemos/wicom
wstatus
draw_routine(wvdraw_t draw,void *param)
{
	shape_t s;
	memset(&s,0,sizeof(s));

	if( draw.flags & WVDRAW_FLAG_ORTHOGONAL )
	{
		v3d_t plist[] = {
			{-50,50,0},
			{50,50,0},
			{50,-50,0},
			{-50,-50,0}
		};

		s.type = SHAPE_POLYGON;
		V3_SET(s.data.polygon.color,1.0,0,0)
		s.data.polygon.point_list = plist;
		s.data.polygon.point_count = 4;
		wview_draw_shape(s);

		s.type = SHAPE_LINE;
		s.data.line.color.x = 1.0; s.data.line.color.y = 1.0; s.data.line.color.z = 1.0;
		s.data.line.p1.x = -5.0+800.0/2; s.data.line.p1.y = 600/2; s.data.line.p1.z = 0;
		s.data.line.p2.x = +5.0+800.0/2; s.data.line.p2.y = 600/2; s.data.line.p2.z = 0;
		wview_draw_shape(s);

		s.type = SHAPE_LINE;
		s.data.line.color.x = 1.0; s.data.line.color.y = 1.0; s.data.line.color.z = 1.0;
		s.data.line.p1.x = 800/2; s.data.line.p1.y = -5.0+600.0/2.0; s.data.line.p1.z = 0;
		s.data.line.p2.x = 800/2; s.data.line.p2.y = +5.0+600.0/2.0; s.data.line.p2.z = 0;
		wview_draw_shape(s);

		s.type = SHAPE_POINT;
		V3_SET(s.data.point.p1,0,0,0);
		V3_SET(s.data.point.color,1,0,0);
		wview_draw_shape(s);

		s.type = SHAPE_TEXT;
		s.data.text.content = "XPTO IN ORTHO!";
		s.data.text.position.x = vtest;
		s.data.text.position.y = 50.0;
		s.data.text.position.z = 0;
		s.data.text.font = TEXT_FONT_SMALL;
		V3_SET(s.data.text.color,0,1,0);
		wview_draw_shape(s);
	} else if( draw.flags & WVDRAW_FLAG_PERSPECTIVE )
	{
		s.type = SHAPE_LINE;
		s.data.line.color.x = 1.0; s.data.line.color.y = 1.0; s.data.line.color.z = 1.0;
		s.data.line.p1.x = -5.0; s.data.line.p1.y = 0; s.data.line.p1.z = 0;
		s.data.line.p2.x = +5.0; s.data.line.p2.y = 0; s.data.line.p2.z = 0;
		wview_draw_shape(s);

		s.type = SHAPE_LINE;
		s.data.line.color.x = 1.0; s.data.line.color.y = 1.0; s.data.line.color.z = 1.0;
		s.data.line.p1.x = 0; s.data.line.p1.y = -5.0; s.data.line.p1.z = 0;
		s.data.line.p2.x = 0; s.data.line.p2.y = +5.0; s.data.line.p2.z = 0;
		wview_draw_shape(s);

		s.type = SHAPE_TEXT;
		s.data.text.content = "XPTO SMALL";
		s.data.text.position.x = 50.0;
		s.data.text.position.y = 50.0;
		s.data.text.position.z = 0;
		s.data.text.font = TEXT_FONT_SMALL;
		V3_SET(s.data.text.color,0,1,0);
		wview_draw_shape(s);

		s.type = SHAPE_TEXT;
		s.data.text.content = "XPTO-Z=20";
		s.data.text.position.x = 50.0;
		s.data.text.position.y = 50.0;
		s.data.text.position.z = 20.0;
		s.data.text.font = TEXT_FONT_SMALL;
		V3_SET(s.data.text.color,0,0.5,1);
		wview_draw_shape(s);
	}

	return WSTATUS_SUCCESS;
}
Esempio n. 3
0
File: wicom.c Progetto: jemos/wicom
int main(int argc,char *argv[])
{
	wstatus s;
	wview_load_t load;
	char buffer[32];

	req_validation_test();

	//request_test();

	//wchannel_test();

	//reqbuf_test();

	return EXIT_SUCCESS;

	wvctl_load_t wvctl_l;
	wvctl_l.exit_routine = 0;

	s = wvctl_load(wvctl_l);

	printf("wviewctl_load returned..");

	wvctl_register_mouse_cb(mouse_routine,(void*)123);
	wvctl_register_keyboard_cb(keyboard_routine,(void*)123);
	wvctl_register_draw_cb(draw_routine,(void*)456);
	wvctl_register_draw_cb(draw_routine2,(void*)456);

	fgets(buffer,sizeof(buffer),stdin);

	wvctl_unload();
	
	return EXIT_SUCCESS;

	/* load wview */
	s = wview_load(load);
	if( s != WSTATUS_SUCCESS )
		return EXIT_SUCCESS;


	wview_window_t window;
	window.width = 800;
	window.height = 600;
	window.draw_routine = draw_routine;
	window.keyboard_routine = keyboard_routine;
	window.mouse_routine = mouse_routine;
	wview_create_window(window);

	v3d_t v;
	V3_SET(v,10,0,-800.0);
	wview_set(WVOPTION_TRANSLATE_VECTOR,&v,sizeof(v));

	v4d_t v4;
	V4_SET(v4,0,0,1.0,45.0);
	wview_set(WVOPTION_ROTATE_VECTOR,&v4,sizeof(v4));

	int rt_order = WVIEW_TRANSLATE_ROTATE;
	wview_set(WVOPTION_TR_ORDER,&rt_order,sizeof(rt_order));

	/* enter draw loop */
	wview_process(WVIEW_SYNCHRONOUS);

	/* close window */
	wview_destroy_window();

	/* unload wview */
	s = wview_unload();
	return EXIT_SUCCESS;
}
Esempio n. 4
0
void BSDE_SolidHull_MakeHullFaces(BSDE_Solid *obj)
{
	static bsde_real vecbuf[64*64*3];
	static bsde_real pointbuf[64*3], pointbuf2[64*3];
	static int facebuf[64*64];
	static int facevbuf[64];
	int i, j, k, l, n, nf, nv;
	int p0, p1, p2;
	bsde_real *v0, *v1, *v2;
	bsde_real dv0[3], dv1[3], dv2[3];
	bsde_real f, g, h;

	n=0;
	nv=0;
	nf=0;

//	printf("build");
	for(i=0; i<obj->n_faces; i++)
	{
		BSDE_SolidHull_MakePlaneFace(obj->norms+(i*4), pointbuf);
		l=4;

		for(j=0; j<obj->n_faces; j++)
		{
			if(i==j)continue;

			l=BSDE_SolidHull_ClipFace(obj->norms+(j*4),
				pointbuf, pointbuf2, l);
			for(k=0; k<(l*3); k++)pointbuf[k]=pointbuf2[k];
		}
		if(!l)continue;

//		printf("%d:%d", i, l);

		for(j=0; j<l; j++)
		{
			for(k=0; k<nv; k++)
				if(V3_DIST(pointbuf+j*3,
					vecbuf+k*3)<0.00001)
						break;
			if(k==nv)
//			if(1)
			{
				V3_COPY(pointbuf+j*3, vecbuf+k*3);
				nv++;
			}

			facebuf[n++]=k;
		}

		facevbuf[nf]=l;
		nf++;
	}
//	printf("\n");

//	printf("facevecs");
//	for(i=0; i<nf; i++)printf(" %d:%d", i, facevbuf[i]);
//	printf("\n");

	if(nf<obj->n_faces)
	{
		printf("MakeHullFaces: %d faces clipped away\n",
			obj->faces-nf);
	}

//	obj->n_faces=nf;

	obj->n_vecs=nv;
	obj->vecs=(bsde_real *)malloc(nv*3*sizeof(bsde_real));
	memcpy(obj->vecs, vecbuf, nv*3*sizeof(bsde_real));

	obj->faces=(int *)malloc(n*sizeof(int));
	memcpy(obj->faces, facebuf, n*sizeof(int));

	obj->facevecs=(int *)malloc(nf*sizeof(int));
	memcpy(obj->facevecs, facevbuf, nf*sizeof(int));

	k=0;
	h=0;
	for(i=0; i<nf; i++)
	{
		l=facevbuf[i];
		for(j=1; j<(l-1); j++)
		{
			p0=facebuf[k];
			p1=facebuf[k+j];
			p2=facebuf[k+j+1];
			if((p0==p1) || (p1==p2) || (p2==p0))continue;

			v0=vecbuf+p0*3;
			v1=vecbuf+p1*3;
			v2=vecbuf+p2*3;

			V3_SUB(v1, v0, dv0);
			V3_SUB(v2, v0, dv1);

			V3_CROSS(dv0, dv1, dv2);
			f=V3_NORMALIZE(dv2, dv2);
			g=f*0.5;

			V3_CROSS(dv0, v0, dv2);
			f=V3_NORMALIZE(dv2, dv2);
			g*=f*0.5;

			V3_CROSS(dv1, v0, dv2);
			f=V3_NORMALIZE(dv2, dv2);
			g*=f*0.5;

			h+=g;
		}
		k+=l;
	}

	obj->volume=h;

	V3_SET(obj->mins, 999999, 999999, 999999);
	V3_SET(obj->maxs, -999999, -999999, -999999);
	for(i=0; i<nv; i++)
	{
		if(vecbuf[i*3+0]<obj->mins[0])obj->mins[0]=vecbuf[i*3+0];
		if(vecbuf[i*3+0]>obj->maxs[0])obj->maxs[0]=vecbuf[i*3+0];
		if(vecbuf[i*3+1]<obj->mins[1])obj->mins[1]=vecbuf[i*3+1];
		if(vecbuf[i*3+1]>obj->maxs[1])obj->maxs[1]=vecbuf[i*3+1];
		if(vecbuf[i*3+2]<obj->mins[2])obj->mins[2]=vecbuf[i*3+2];
		if(vecbuf[i*3+2]>obj->maxs[2])obj->maxs[2]=vecbuf[i*3+2];
	}

	f=0;
	for(i=0; i<nv; i++)
		{ g=V3_LEN(vecbuf+i*3); if(g>f)f=g; }
	obj->radius=f;

	obj->stateflags&=~BSDE_STATEFL_BBOX;
	if(obj->n_faces==6)
	{
		j=0;
		for(i=0; i<obj->n_faces; i++)
		{
			v0=obj->norms+i*4;
			if((v0[0]==1) && (v0[1]==0) && (v0[2]==0))j|=1;
			if((v0[0]==-1) && (v0[1]==0) && (v0[2]==0))j|=2;
			if((v0[0]==0) && (v0[1]==1) && (v0[2]==0))j|=4;
			if((v0[0]==0) && (v0[1]==-1) && (v0[2]==0))j|=8;
			if((v0[0]==0) && (v0[1]==0) && (v0[2]==1))j|=16;
			if((v0[0]==0) && (v0[1]==0) && (v0[2]==-1))j|=32;
		}

		if(j==63)obj->stateflags|=BSDE_STATEFL_BBOX;
	}
}