codesamples >>
crossplatform geometry triangles class
Crossplatform: Geometry Triangles class
Project:
Crossplatform application (Windows & PS3)
Engine:
Custom
Code language:
C++
Class description:
The geometry triangles class for Windows and PS3.
GeometryTriangles.cpp
#include "GeometryTriangles.h"
bool GeometryTriangles::AddTriangle(float x0, float y0,float z0, float x1, float y1,
float z1, float x2, float y2,float z2)
{
int currentIndice = m_VertexList.size();
// Add 3 new Vertices
m_VertexList.push_back(Vertex(x0,y0,z0));
m_VertexList.push_back(Vertex(x1,y1,z1));
m_VertexList.push_back(Vertex(x2,y2,z2));
// Add 3 new Indices
m_IndiceList.push_back(currentIndice);
m_IndiceList.push_back(currentIndice+1);
m_IndiceList.push_back(currentIndice+2);
return true;
}
bool GeometryTriangles::AddTriangle(int index0, int index1, int index2)
{
// Add new Indices
m_IndiceList.push_back(index0);
m_IndiceList.push_back(index1);
m_IndiceList.push_back(index2);
return true;
}
int GeometryTriangles::AddVertex(float x0, float y0,float z0)
{
int currentIndice = m_VertexList.size();
m_VertexList.push_back(Vertex(x0, y0, z0));
return currentIndice;
}
Vertex* GeometryTriangles::GetVertexAtIndex(int index)
{
return &m_VertexList[index];
}
GeometryTriangles.h
#ifndef _GEOMETRYTRIANGLES_H
#define _GEOMETRYTRIANGLES_H
#if defined(WIN32)
#define INDEX WORD
#elif(PS3)
#define INDEX unsigned int
#endif
#include <vector>
#include "Structs.h"
struct Vertex
{
// Position parameters
float m_x, m_y, m_z;
// Constructor without arguments
Vertex():m_x(0), m_y(0), m_z(0)
{
}
// Constructor with arguments
Vertex(float x, float y, float z):m_x(x), m_y(y), m_z(z)
{
}
};
class GeometryTriangles
{
public:
bool AddTriangle(float x0, float y0,float z0, float x1, float y1,float z1, float x2, float y2,float z2);
bool AddTriangle(int index0, int index1, int index2);
int AddVertex(float x0, float y0,float z0);
Vertex* GetVertexAtIndex(int index);
std::vector<Vertex>& GetVertices(){return m_VertexList;}
std::vector<INDEX>& GetIndices(){return m_IndiceList;}
private:
std::vector<Vertex> m_VertexList;
std::vector<INDEX> m_IndiceList;
};
#endif