⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cacti.cpp

📁 小型的3D游戏引擎
💻 CPP
字号:
#include "cacti.h"

GcTexture	GcCacti::m_tex;
bool		GcCacti::m_isLoaded = false;

///////////////////////////////////////////////////////////////////////////

bool GcCacti::Load(char *filename, GcPoint3 pos)
{
	if(m_isLoaded == false)
	{
		// Load the texture
		if(!m_tex.Create(filename)) {
			return false;
		}

		// Save the position
		m_position = pos;

		// The cactie object is loaded
		m_isLoaded = true;
	}

	return true;
}

///////////////////////////////////////////////////////////////////////////

void GcCacti::Render()
{
	GLfloat		viewMatrix[16];
	GcVector3	right;
	GcVector3	up;

	// Get the view matrix
	glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);

	// Extract the two position vectors
	right = GcVector3(viewMatrix[0], viewMatrix[4], viewMatrix[8]);
	up = GcVector3(viewMatrix[1], viewMatrix[5], viewMatrix[9]);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0);

	// Set the correct texture
	m_tex.Bind();

	// Draw the bilboarded cacti
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3fv((m_position + (right + up) * -m_size).array);
		glTexCoord2f(1.0f, 0.0f); glVertex3fv((m_position + (right - up) * m_size).array);
		glTexCoord2f(1.0f, 1.0f); glVertex3fv((m_position + (right + up) * m_size).array);
		glTexCoord2f(0.0f, 1.0f); glVertex3fv((m_position + (up - right) * m_size).array);
	glEnd();

	glDisable(GL_ALPHA);
	glDisable(GL_BLEND);
}

///////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -