当前位置: 首页>>代码示例>>C++>>正文


C++ StreamReader::Read方法代码示例

本文整理汇总了C++中StreamReader::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamReader::Read方法的具体用法?C++ StreamReader::Read怎么用?C++ StreamReader::Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StreamReader的用法示例。


在下文中一共展示了StreamReader::Read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadVertexData

//=================================================================================================
// Wczytuje dane wierzcho³ków z modelu (na razie dzia³a tylko dla Vec3)
//=================================================================================================
void Mesh::LoadVertexData(VertexData* vd, StreamReader& stream)
{
	// read and check header
	Header head;
	if(!stream.Read(head))
		throw "Failed to read file header.";
	if(memcmp(head.format, "QMSH", 4) != 0)
		throw Format("Invalid file signature '%.4s'.", head.format);
	if(head.version != 20)
		throw Format("Invalid file version '%d'.", head.version);
	if(head.flags != F_PHYSICS)
		throw Format("Invalid mesh flags '%d'.", head.flags);
	vd->radius = head.radius;

	// read vertices
	uint size = sizeof(Vec3) * head.n_verts;
	if(!stream.Ensure(size))
		throw "Failed to read vertex data.";
	vd->verts.resize(head.n_verts);
	stream.Read(vd->verts.data(), size);

	// read faces
	size = sizeof(Face) * head.n_tris;
	if(!stream.Ensure(size))
		throw "Failed to read triangle data.";
	vd->faces.resize(head.n_tris);
	stream.Read(vd->faces.data(), size);
}
开发者ID:lcs2,项目名称:carpg,代码行数:31,代码来源:Mesh.cpp

示例2: PngReaderCallback

static void PngReaderCallback(png_structp pPngStruct, png_bytep pData, png_size_t nSize)
{
	StreamReader* pStream = (StreamReader*)png_get_io_ptr(pPngStruct);

	if (!pStream->Read(pData, nSize))
	{
		png_error(pPngStruct,"pngReaderCallback failed");
	}
}
开发者ID:mshandle,项目名称:spank,代码行数:9,代码来源:Image.cpp

示例3: LoadPoints

void Mesh::LoadPoints(StreamReader& stream)
{
	uint size = Point::MIN_SIZE * head.n_points;
	if(!stream.Ensure(size))
		throw "Failed to read points.";
	attach_points.clear();
	attach_points.resize(head.n_points);
	for(word i = 0; i < head.n_points; ++i)
	{
		Point& p = attach_points[i];

		stream.Read(p.name);
		stream.Read(p.mat);
		stream.Read(p.bone);
		stream.Read(p.type);
		stream.Read(p.size);
		stream.Read(p.rot);
		p.rot.y = Clip(-p.rot.y);
	}
}
开发者ID:lcs2,项目名称:carpg,代码行数:20,代码来源:Mesh.cpp

示例4: LoadHeader

//=================================================================================================
void Mesh::LoadHeader(StreamReader& stream)
{
	// head
	if(!stream.Read(head))
		throw "Failed to read file header.";
	if(memcmp(head.format, "QMSH", 4) != 0)
		throw Format("Invalid file signature '%.4s'.", head.format);
	if(head.version < 12 || head.version > 20)
		throw Format("Invalid file version '%u'.", head.version);
	if(head.version < 20)
		throw Format("Unsupported file version '%u'.", head.version);
	if(head.n_bones >= 32)
		throw Format("Too many bones (%u).", head.n_bones);
	if(head.n_subs == 0)
		throw "Missing model mesh!";
	if(IS_SET(head.flags, F_ANIMATED) && !IS_SET(head.flags, F_STATIC))
	{
		if(head.n_bones == 0)
			throw "No bones.";
		if(head.n_groups == 0)
			throw "No bone groups.";
	}
}
开发者ID:lcs2,项目名称:carpg,代码行数:24,代码来源:Mesh.cpp

示例5: Load

//=================================================================================================
// Wczytywanie modelu z pliku
//=================================================================================================
void Mesh::Load(StreamReader& stream, IDirect3DDevice9* device)
{
	assert(device);

	LoadHeader(stream);
	SetVertexSizeDecl();

	// ------ vertices
	// ensure size
	uint size = vertex_size * head.n_verts;
	if(!stream.Ensure(size))
		throw "Failed to read vertex buffer.";

	// create vertex buffer
	HRESULT hr = device->CreateVertexBuffer(size, 0, 0, D3DPOOL_MANAGED, &vb, nullptr);
	if(FAILED(hr))
		throw Format("Failed to create vertex buffer (%d).", hr);

	// read
	void* ptr;
	V(vb->Lock(0, size, &ptr, 0));
	stream.Read(ptr, size);
	V(vb->Unlock());

	// ----- triangles
	// ensure size
	size = sizeof(word) * head.n_tris * 3;
	if(!stream.Ensure(size))
		throw "Failed to read index buffer.";

	// create index buffer
	hr = device->CreateIndexBuffer(size, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib, nullptr);
	if(FAILED(hr))
		throw Format("Failed to create index buffer (%d).", hr);

	// read
	V(ib->Lock(0, size, &ptr, 0));
	stream.Read(ptr, size);
	V(ib->Unlock());

	// ----- submeshes
	size = Submesh::MIN_SIZE * head.n_subs;
	if(!stream.Ensure(size))
		throw "Failed to read submesh data.";
	subs.resize(head.n_subs);

	for(word i = 0; i < head.n_subs; ++i)
	{
		Submesh& sub = subs[i];

		stream.Read(sub.first);
		stream.Read(sub.tris);
		stream.Read(sub.min_ind);
		stream.Read(sub.n_ind);
		stream.Read(sub.name);
		stream.ReadString1();

		if(BUF[0])
			sub.tex = ResourceManager::Get<Texture>().GetLoaded(BUF);
		else
			sub.tex = nullptr;

		// specular value
		stream.Read(sub.specular_color);
		stream.Read(sub.specular_intensity);
		stream.Read(sub.specular_hardness);

		// normalmap
		if(IS_SET(head.flags, F_TANGENTS))
		{
			stream.ReadString1();
			if(BUF[0])
			{
				sub.tex_normal = ResourceManager::Get<Texture>().GetLoaded(BUF);
				stream.Read(sub.normal_factor);
			}
			else
				sub.tex_normal = nullptr;
		}
		else
			sub.tex_normal = nullptr;

		// specular map
		stream.ReadString1();
		if(BUF[0])
		{
			sub.tex_specular = ResourceManager::Get<Texture>().GetLoaded(BUF);
			stream.Read(sub.specular_factor);
			stream.Read(sub.specular_color_factor);
		}
		else
			sub.tex_specular = nullptr;

		if(!stream)
			throw Format("Failed to read submesh %u.", i);
	}

//.........这里部分代码省略.........
开发者ID:lcs2,项目名称:carpg,代码行数:101,代码来源:Mesh.cpp


注:本文中的StreamReader::Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。