Exemple #1
0
//put a cube on the screen
draw_cube()
{
	int i,sn;
	short cube_vert_nums[9];

	//find 8 free vertices

	for (i=0;i<9;i++) {
		int vn;

		vn = cube_vert_nums[i] = alloc_vert();

		vm_vec_add(&Vertices[vn],&cube_position,&cube_coords[i]);
	}

	g3_rotate_list(9,cube_vert_nums);

	//fudge perspecive by using z value from cube center for all verts

	for (i=0;i<8;i++)
		Segment_points[cube_vert_nums[i]].z = Segment_points[cube_vert_nums[8]].z;
	
	//draw six sides

	for (sn=0;sn<6;sn++) {
		short side_vert_nums[4];

		for (i=0;i<4;i++) side_vert_nums[3-i] = cube_vert_nums[Side_to_verts[sn][i]];

//		gr_setcolor(sn+1);
//		g3_check_and_draw_poly(4,side_vert_nums,NULL);

		g3_check_and_draw_tmap(4,side_vert_nums,cube_uvls,Texture[39+sn]->bitmap,NULL);
	}

	//free 8 free vertices

	for (i=0;i<8;i++) free_vert(cube_vert_nums[i]);

}
Exemple #2
0
//alternate interpreter for morphing object
bool g3_draw_morphing_model(ubyte *p,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,g3s_lrgb model_light,vms_vector *new_points)
{
	fix *glow_values = NULL;

	glow_num = -1;		//glow off by default

	while (w(p) != OP_EOF)

		switch (w(p)) {

			case OP_DEFPOINTS: {
				int n = w(p+2);

				rotate_point_list(Interp_point_list,new_points,n);
				p += n*sizeof(struct vms_vector) + 4;

				break;
			}

			case OP_DEFP_START: {
				int n = w(p+2);
				int s = w(p+4);

				rotate_point_list(&Interp_point_list[s],new_points,n);
				p += n*sizeof(struct vms_vector) + 8;

				break;
			}

			case OP_FLATPOLY: {
				int nv = w(p+2);
				int i,ntris;

				gr_setcolor(w(p+28));
				
				for (i=0;i<2;i++)
					point_list[i] = Interp_point_list + wp(p+30)[i];

				for (ntris=nv-2;ntris;ntris--) {

					point_list[2] = Interp_point_list + wp(p+30)[i++];

					g3_check_and_draw_poly(3,point_list,NULL,NULL);

					point_list[1] = point_list[2];

				}

				p += 30 + ((nv&~1)+1)*2;
					
				break;
			}

			case OP_TMAPPOLY: {
				int nv = w(p+2);
				g3s_uvl *uvl_list;
				g3s_lrgb light, *lrgb_list;
				g3s_uvl morph_uvls[3];
				int i,ntris;

				MALLOC(lrgb_list, g3s_lrgb, nv);

				//calculate light from surface normal
				if (glow_num < 0) //no glow
				{
					light.r = light.g = light.b = -vm_vec_dot(&View_matrix.fvec,vp(p+16));
					light.r = f1_0/4 + (light.r*3)/4;
					light.r = fixmul(light.r,model_light.r);
					light.g = f1_0/4 + (light.g*3)/4;
					light.g = fixmul(light.g,model_light.g);
					light.b = f1_0/4 + (light.b*3)/4;
					light.b = fixmul(light.b,model_light.b);
				}
				else //yes glow
				{
					light.r = light.g = light.b = glow_values[glow_num];
					glow_num = -1;
				}

				//now poke light into l values
				uvl_list = (g3s_uvl *) (p+30+((nv&~1)+1)*2);

				for (i=0;i<nv;i++)
				{
					lrgb_list[i].r = light.r;
					lrgb_list[i].g = light.g;
					lrgb_list[i].b = light.b;
				}

				for (i=0;i<3;i++)
					morph_uvls[i].l = (light.r+light.g+light.b)/3;

				for (i=0;i<2;i++) {
					point_list[i] = Interp_point_list + wp(p+30)[i];

					morph_uvls[i].u = uvl_list[i].u;
					morph_uvls[i].v = uvl_list[i].v;
				}

				for (ntris=nv-2;ntris;ntris--) {

					point_list[2] = Interp_point_list + wp(p+30)[i];
					morph_uvls[2].u = uvl_list[i].u;
					morph_uvls[2].v = uvl_list[i].v;
					i++;

					g3_check_and_draw_tmap(3,point_list,uvl_list,lrgb_list,model_bitmaps[w(p+28)],NULL,NULL);

					point_list[1] = point_list[2];
					morph_uvls[1].u = morph_uvls[2].u;
					morph_uvls[1].v = morph_uvls[2].v;

				}

				p += 30 + ((nv&~1)+1)*2 + nv*12;
				d_free(lrgb_list);

				break;
			}

			case OP_SORTNORM:

				if (g3_check_normal_facing(vp(p+16),vp(p+4)) > 0) {		//facing

					//draw back then front

					g3_draw_morphing_model(p+w(p+30),model_bitmaps,anim_angles,model_light,new_points);
					g3_draw_morphing_model(p+w(p+28),model_bitmaps,anim_angles,model_light,new_points);

				}
				else {			//not facing.  draw front then back

					g3_draw_morphing_model(p+w(p+28),model_bitmaps,anim_angles,model_light,new_points);
					g3_draw_morphing_model(p+w(p+30),model_bitmaps,anim_angles,model_light,new_points);
				}

				p += 32;

				break;


			case OP_RODBM: {
				g3s_point rod_bot_p,rod_top_p;
				g3s_lrgb rodbm_light = { f1_0, f1_0, f1_0 };

				g3_rotate_point(&rod_bot_p,vp(p+20));
				g3_rotate_point(&rod_top_p,vp(p+4));

				g3_draw_rod_tmap(model_bitmaps[w(p+2)],&rod_bot_p,w(p+16),&rod_top_p,w(p+32),rodbm_light);

				p+=36;
				break;
			}

			case OP_SUBCALL: {
				vms_angvec *a;

				if (anim_angles)
					a = &anim_angles[w(p+2)];
				else
					a = &zero_angles;

				g3_start_instance_angles(vp(p+4),a);

				g3_draw_polygon_model(p+w(p+16),model_bitmaps,anim_angles,model_light,glow_values);

				g3_done_instance();

				p += 20;

				break;

			}

			case OP_GLOW:

				if (glow_values)
					glow_num = w(p+2);
				p += 4;
				break;
		}

	return 1;
}