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

📄 staticgeometry.cpp

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


GcStaticGeometry::GcStaticGeometry()
{
	m_type = TRIANGLES;
}

GcStaticGeometry::~GcStaticGeometry()
{
	if( m_vertices )
		delete [] m_vertices;

	if( m_indices )
		delete [] m_indices;

	m_totalVertices = 0;
	m_totalIndices = 0;
}

void GcStaticGeometry::ReadVertices( const GcVector3 * vertices, int num )
{

}

void GcStaticGeometry::ReadVertices( const float * vertices, int num )
{
	if( m_vertices )
		delete [] m_vertices;
	
	m_totalVertices = num;

	m_vertices = new float[num];

	memcpy( m_vertices, vertices, num * sizeof(float) );
}

void GcStaticGeometry::ClearVertices()
{
	if( m_vertices )
		delete [] m_vertices;
}

void GcStaticGeometry::ReadIndices( const int * indices, int num )
{
	if( m_indices )
		delete [] m_indices;
	
	m_totalIndices = num;

	m_indices = new int[num];

	memcpy( m_indices, indices, num * sizeof(int) );

}

void GcStaticGeometry::ClearIndices()
{
	if( m_indices )
		delete [] m_indices;
}

void GcStaticGeometry::Prepare()
{
	g_Debug->Log("Num vertices: %d\n", m_totalVertices);
	g_DebugConsole->Write("Num indices: %d\n", m_totalIndices);

	int i;
	for( i = 0; i < m_totalVertices; i += 3 )
	{
		g_DebugConsole->Write("V %d --- X: %4f - Y: %4f - Z: %4f -\n", i, m_vertices[i], m_vertices[i + 1], m_vertices[i + 2]);
	}

	for( i = 0; i < m_totalIndices; ++i )
	{
		g_DebugConsole->Write("I %d --- %d\n", i, m_indices[i]);
	}
}

void GcStaticGeometry::Render()
{
	if( m_type == TRIANGLES )
	{
		glBegin(GL_TRIANGLES);
			for( int i = 0; i < m_totalIndices; ++i )
			{
				int & v = m_indices[i];
				
				glVertex3f( m_vertices[v], m_vertices[v + 1], m_vertices[v + 2] );
			}
		glEnd();
	}
}

⌨️ 快捷键说明

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