示例#1
0
void RenderUntextured(unsigned int offset, unsigned char *data, vector3d obj_center)
{
	BSP_BlockHeader blkhdr;
	unsigned char *curpos = data + offset;
	blkhdr.Read((char *) curpos);

#if defined(__BSP_DEBUG_DRAWNORMS_)
	BSP_FlatPoly fpoly;
	fpoly.Read((char *) curpos + blkhdr.MySize(), blkhdr);

	// just rendering a point a line along the norm for now - just need center and normal
	glColor3f(0.5, 0.5, 1.0);
	vector3d point = POFTranslate(fpoly.center);
	vector3d norm = point+(POFTranslate(fpoly.normal)*5);

	glBegin(GL_POINTS);	
		glVertex3fv((float *)&point);
	glEnd();

	glBegin(GL_LINE_STRIP);	
		glVertex3fv((float *)&point);
		glVertex3fv((float *)&norm);
	glEnd();
	// tail recurse
	fpoly.Destroy();
#endif
	RenderBSP(offset + blkhdr.size, data, obj_center);
}
示例#2
0
void TranslateFPoly(unsigned int offset, unsigned char *data, 
				 BSP_DefPoints &points, std::vector<pcs_polygon> &polygons,
				 unsigned int &upolys)
{
	BSP_BlockHeader blkhdr;
	unsigned char *curpos = data + offset;
	blkhdr.Read((char *) curpos);

	vector3d point, norm;
	pcs_polygon temp_poly;

	BSP_FlatPoly fpoly;
	fpoly.Read((char *) curpos + blkhdr.MySize(), blkhdr);

	
	temp_poly.norm = POFTranslate(fpoly.normal);
	temp_poly.texture_id = -1;
	temp_poly.verts.resize(fpoly.nverts);

	
	for (int i = 0; i < fpoly.nverts; i++)
	{
		temp_poly.verts[i].point = POFTranslate(points.vertex_data[fpoly.verts[i].vertnum].vertex);
		temp_poly.verts[i].norm = POFTranslate(points.normals[fpoly.verts[i].normnum]);

		temp_poly.verts[i].u = 0;
		temp_poly.verts[i].v = 0;

	}

	if (upolys >= polygons.size())
	{
		polygons.resize(polygons.size() * 2);
	}
	polygons[upolys] = temp_poly;
	upolys++;

	BSPTransPMF(offset + blkhdr.size, data, points, polygons, upolys); // continue traversal
}
示例#3
0
std::string BSP::DataIn(char *buffer, int size)
{
	std::string stats;
	char *localptr = buffer;
	char cstemp[64];
	bool go = true;
	BSP_BoundBox	bnd;
	BSP_DefPoints	pnt;
	BSP_FlatPoly	fpol;
	BSP_SortNorm	snrm;
	BSP_TmapPoly	tpol;

	BSP_BlockHeader head;

	stats = "";
	//0 - EOF, 1 - DEFPOINTS, 2 - FLATPOLY, 3 - IMAPPOLY, 4- SHORNORM, 5- BOUNDBOX
	while (go)
	{


		head.Read(localptr);
		localptr += 8;


		if (localptr - buffer >= size)
		{
			go = false;
			break;
		}
		switch (head.id)
		{
			case 0:
				//stats += "EOF\n";
				//stats += "\n";
				//go = false;
				break;

			case 1:

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - pnt.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header

				//stats += "DEFPOINTS ";
				//stats += cstemp;
				//stats += "\n";

				/*
				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.n_norms);
				stats += "     +n_norms: ";
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.n_verts);
				stats += "     +n_verts: ";
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d", pnt.offset);
				stats += "     +offset: +";
				stats += cstemp;
				stats += "\n";

				Collector = 0;
				for (i = 0; i < pnt.n_verts; i++)
				{
					if (i < pnt.n_norms)
						Collector += int(unsigned char(pnt.norm_counts[i]));
				}

				memset(cstemp, 0, 64);
				sprintf(cstemp, "%d bytes", sizeof(vector) * (Collector + pnt.n_verts));
				stats += "     +vertex data size: ";
				stats += cstemp;
				stats += "\n";*/
				//stats += "\n";

				Add_DefPoints(pnt);
				break;

			case 2:
				//stats += "FLATPOLY  ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - fpol.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header

				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Red: %d, Green: %d, Blue: %d, Pad: %d", fpol.red, fpol.green, fpol.blue, fpol.pad);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Normal: (%f, %f, %f), Radius %f", fpol.normal.x, fpol.normal.y, fpol.normal.z, fpol.radius);
				stats += cstemp;
				stats += "\n";

				for (i = 0; i < fpol.nverts; i++)
				{

					memset(cstemp, 0, 64);
					sprintf(cstemp, "   @+ Point: (%f, %f, %f),",
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.x,
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.y,
							points[0].vertex_data[fpol.verts[i].vertnum].vertex.z);
					stats += cstemp;

					memset(cstemp, 0, 64);
					sprintf(cstemp, "  Normal: (%f, %f, %f),",
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].x,
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].y,
							points[0].vertex_data[fpol.verts[i].vertnum].norms[fpol.verts[i].normnum].z);
					stats += cstemp;

					stats += "\n";


				}*/

				//stats += "\n";

				Add_FlatPoly(fpol);
				break;

			case 3:
			//	stats += "IMAPPOLY ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - tpol.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				//stats += cstemp;
				//stats += "\n";



				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Normal: (%f, %f, %f), Radius %f", tpol.normal.x, tpol.normal.y, tpol.normal.z, tpol.radius);
				stats += cstemp;
				stats += "\n";

				for (i = 0; i < tpol.nverts; i++)
				{

					memset(cstemp, 0, 64);
					sprintf(cstemp, "   @+ Point: (%f, %f, %f),",
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.x,
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.y,
							points[0].vertex_data[tpol.verts[i].vertnum].vertex.z);
					stats += cstemp;

					memset(cstemp, 0, 64);
					sprintf(cstemp, "  Normal: (%f, %f, %f),",
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].x,
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].y,
							points[0].vertex_data[tpol.verts[i].vertnum].norms[tpol.verts[i].normnum].z);
					stats += cstemp;

					stats += "\n";


				}*/

				//stats += "\n";

				Add_TmapPoly(tpol);
				break;

			case 4:
				stats += "SORTNORM ";


				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)] ", head.size, head.size - snrm.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				//stats += cstemp;
				//stats += "\n";

				/*memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BackOffset: %d, FrontOffset: %d, OnlineOffset: %d, ",
						snrm.back_offset, snrm.front_offset, snrm.online_offset);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ PostListOffset: %d, PreListOffset: %d, ",
						snrm.back_offset, snrm.front_offset, snrm.online_offset);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Plane_Normal: (%f, %f, %f)",
						snrm.plane_normal.x, snrm.plane_normal.y, snrm.plane_normal.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ Plane_Point: (%f, %f, %f)",
						snrm.plane_point.x, snrm.plane_point.y, snrm.plane_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMin: (%f, %f, %f)",
						snrm.min_bounding_box_point.x, snrm.min_bounding_box_point.y, snrm.min_bounding_box_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMax: (%f, %f, %f)",
						snrm.max_bounding_box_point.x, snrm.max_bounding_box_point.y, snrm.max_bounding_box_point.z);
				stats += cstemp;
				stats += "\n";
				stats += "\n";*/

				Add_SortNorm(snrm);
				break;

			case 5:
				//stats += "BOUNDBOX ";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "[%d bytes (%d bytes unused)]", head.size, head.size - bnd.Read(localptr, head));
				localptr += (head.size - 8);//8 for the already added header
				/*stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMin: (%f, %f, %f)", bnd.min_point.x, bnd.min_point.y, bnd.min_point.z);
				stats += cstemp;
				stats += "\n";

				memset(cstemp, 0, 64);
				sprintf(cstemp, "   @+ BoundBoxMax: (%f, %f, %f)", bnd.max_point.x, bnd.max_point.y, bnd.max_point.z);
				stats += cstemp;
				stats += "\n";
				stats += "\n";*/


				Add_BoundBox(bnd);
				break;

			default:
				stats += "WARNING: Encountered UNKNOWN: Check data format and/or pointer alignment!\n";
				go = false;
				break;

		}
	}

	return stats;
}