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


C++ Chunk::Draw方法代码示例

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


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

示例1: DrawLandscapeTopDown

void DrawLandscapeTopDown(StageOneShader *shader, int width, int height, bool forceload, DL_Type dlType) {
	if (!Model::gPlayer.KnownPosition())
		return;
	ChunkCoord player_cc;
	Model::gPlayer.GetChunkCoord(&player_cc);

	int verticallimit = (height+CHUNK_SIZE-1)/CHUNK_SIZE/2;
	int horisontallimit = (width+CHUNK_SIZE-1)/CHUNK_SIZE/2;

	// Draw all visible chunks. Chunks that are not loaded will trigger a reload from the server. The top chunks
	// should be loaded first, as they affect the lighting on the chunks below.
	for (int dz = verticallimit; dz >= -verticallimit; dz--) for (int dx = -horisontallimit; dx <= horisontallimit; dx++) for (int dy = -horisontallimit; dy <= horisontallimit; dy++) {
				glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(dx*CHUNK_SIZE, dz*CHUNK_SIZE, -dy*CHUNK_SIZE));

				ChunkCoord cc;
				cc.x = player_cc.x + dx;
				cc.y = player_cc.y + dy;
				cc.z = player_cc.z + dz;
				Chunk *cp = ChunkFind(&cc, forceload);
				if (cp == 0)
					continue;

				shader->Model(modelMatrix);

				// Draw the chunk
				if (!cp->IsDirty() && cp->fChunkObject && cp->fChunkObject->Empty()) {
					// This chunk exists, is updated, but contains nothing.
					continue;
				}
				cp->Draw(shader, 0, dlType);
				cp->DrawObjects(shader, dx, dy, dz, true);
			}
}
开发者ID:myk45,项目名称:ephenation-client,代码行数:33,代码来源:render.cpp

示例2: DrawLandscape

// TODO: This function should be split into a separate function for picking mode.
void DrawLandscape(StageOneShader *shader, DL_Type dlType) {
	if (!Model::gPlayer.KnownPosition())
		return;
	if (dlType == DL_NoTransparent) {
		// The lits of chunks used for shadowing is computed below, when in non-transparent mode.
		// Start the list empty.
		sShadowChunks.clear();
	}

	FindAllNearChunks(sChunkDistances);
	ChunkCoord player_cc;
	Model::gPlayer.GetChunkCoord(&player_cc);

	// Draw all visible chunks. Chunks that are not loaded will trigger a reload from the server. The top chunks
	// should be loaded first, as they affect the lighting on the chunks below.
	int chunkHor = (int)(maxRenderDistance / CHUNK_SIZE + 1);

	// At 80m viewing distance, there are 895 chunks. Using various filters, the actual chunks that can be seen are
	// much fewer. Save the filtered list, to speed up the drawing.
	int listOfVisibleChunks[sMaxVolume];
	int src, dst;
	// Create list of visible chunks. This check is faster than using queries, so it is a good filter to
	// start with.
	for (src=0, dst=0; sChunkDistances[src].distance < chunkHor; src++) {
		if (src > sMaxVolume)
			break; // Just a safety precaution, should never happen
		Chunk *cp = sListOfNearChunks[src];
		if (cp) {
			if (cp->fScheduledForLoading)
				continue; // Chunk doesn't exist yet
			// Do not ignore the chunk just because it doesn't have any data yet, as the data update is triggered
			// by the drawing function.
			if (!cp->IsDirty() && cp->fChunkObject && cp->fChunkObject->Empty()) {
				// This chunk exists, is updated, but contains nothing.
				continue;
			}
		}
		int dx = sChunkDistances[src].dx;
		int dy = sChunkDistances[src].dy;
		int dz = sChunkDistances[src].dz;
		glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(dx*CHUNK_SIZE, dz*CHUNK_SIZE, -dy*CHUNK_SIZE));
		if (Outside(dx, dy , dz, modelMatrix)) {
			continue; // Go to next chunk
		}
		listOfVisibleChunks[dst++] = src;
	}
	int visibleChunklistLength = dst;
	// printf("DrawLandscape: listOfVisibleChunks %d\n", visibleChunklistLength);
	bool insideAnyTeleport = false;

	// We need to know which TP is the nearest.
	float distanceToNearTP2 = 1000.0f*1000.0f; // Distance^2 to the nearest TP, initialized to something big.
	glm::vec3 TPPosition;
	for (int i=0; i<visibleChunklistLength; i++) {
		if (i%NUMQUERIES == 0 && dlType == DL_NoTransparent) {
			// Request NUMQUERIES queries, every NUMQUERIES chunk.
			// The chunks that are tested is not the same ones that will be drawn,
			// to allow the reading of the query result to be with a delay.
			// The first NUMQUERIES chunks are not tested. The occlusion test using queries is most effective
			// for long viewing distances, where there is a high chance of chunks not being visible.
			// TODO: The test could also be used for transparent objects, if it wasn't that QuerySetup() enables depth update again.
			int from = i+NUMQUERIES;
			int to = i+NUMQUERIES*2;
			if (to > visibleChunklistLength)
				to = visibleChunklistLength;
			if (to > from)
				QuerySetup(shader, from, to, listOfVisibleChunks); // Initiate the query for a group of chunks
		}
		int ind = listOfVisibleChunks[i];
		if (dlType == DL_OnlyTransparent)
			ind = listOfVisibleChunks[visibleChunklistLength-i-1]; // Read chunks in reverse order for transparent objects
		if (i >= NUMQUERIES && dlType == DL_NoTransparent) { // There is no query initiated for the first NUMQUERIES chunks.
			GLuint numSamples = 1;
			glGetQueryObjectuiv(sQueryId[i%(NUMQUERIES*2)], GL_QUERY_RESULT, &numSamples);
			if (numSamples == 0)
				continue; // No pixels changed by this chunk, skip it!
		}
		int dx = sChunkDistances[ind].dx;
		int dy = sChunkDistances[ind].dy;
		int dz = sChunkDistances[ind].dz;
		glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(dx*CHUNK_SIZE, dz*CHUNK_SIZE, -dy*CHUNK_SIZE));

		// Don't allow picking outside of near chunks.
		if (dlType == DL_Picking && (dx < -1 || dx > 1 || dy < -1 || dy > 1 || dz < -1 || dz > 1))
			break;

		ChunkCoord cc;
		cc.x = player_cc.x + dx;
		cc.y = player_cc.y + dy;
		cc.z = player_cc.z + dz;
		// If we have come this far, a null pointer is no longer accepted. The chunk is needed. Either we get
		// the real chunk, or an empty one.
		Chunk *cp = ChunkFind(&cc, true);

		if (dlType == DL_Picking) {
			// Picking mode. Throw away the previous triangles, and replace it with special triangles used
			// for the picking mode. These contain colour information to allow identification of cubes.
			cp->fChunkBlocks->TestJellyBlockTimeout(true);
			cp->PushTriangles(ChunkObject::Make(cp, true, dx, dy, dz)); // Stash away the old triangles for quick restore
//.........这里部分代码省略.........
开发者ID:myk45,项目名称:ephenation-client,代码行数:101,代码来源:render.cpp


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