mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-21 10:49:23 +00:00
Mass code cleanup
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
CBasicModel::CBasicModel() : CResource()
|
||||
CBasicModel::CBasicModel()
|
||||
: CResource()
|
||||
, mVertexCount(0)
|
||||
, mTriangleCount(0)
|
||||
, mBuffered(false)
|
||||
, mHasOwnMaterials(false)
|
||||
, mHasOwnSurfaces(false)
|
||||
{
|
||||
mVertexCount = 0;
|
||||
mTriangleCount = 0;
|
||||
mBuffered = false;
|
||||
}
|
||||
|
||||
CBasicModel::~CBasicModel()
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
#include "Core/Render/CRenderer.h"
|
||||
#include "Core/OpenGL/GLCommon.h"
|
||||
|
||||
CModel::CModel() : CBasicModel()
|
||||
CModel::CModel()
|
||||
: CBasicModel()
|
||||
{
|
||||
mHasOwnMaterials = true;
|
||||
mHasOwnSurfaces = true;
|
||||
mVertexCount = 0;
|
||||
mTriangleCount = 0;
|
||||
}
|
||||
|
||||
CModel::CModel(CMaterialSet *pSet, bool ownsMatSet)
|
||||
CModel::CModel(CMaterialSet *pSet, bool OwnsMatSet)
|
||||
: CBasicModel()
|
||||
{
|
||||
mHasOwnMaterials = ownsMatSet;
|
||||
mHasOwnMaterials = OwnsMatSet;
|
||||
mHasOwnSurfaces = true;
|
||||
mVertexCount = 0;
|
||||
mTriangleCount = 0;
|
||||
|
||||
mMaterialSets.resize(1);
|
||||
mMaterialSets[0] = pSet;
|
||||
@@ -25,8 +23,8 @@ CModel::CModel(CMaterialSet *pSet, bool ownsMatSet)
|
||||
CModel::~CModel()
|
||||
{
|
||||
if (mHasOwnMaterials)
|
||||
for (u32 m = 0; m < mMaterialSets.size(); m++)
|
||||
delete mMaterialSets[m];
|
||||
for (u32 iMat = 0; iMat < mMaterialSets.size(); iMat++)
|
||||
delete mMaterialSets[iMat];
|
||||
}
|
||||
|
||||
void CModel::BufferGL()
|
||||
@@ -56,7 +54,8 @@ void CModel::BufferGL()
|
||||
Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset);
|
||||
|
||||
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
|
||||
switch (pPrim->Type) {
|
||||
switch (pPrim->Type)
|
||||
{
|
||||
case eGX_Triangles:
|
||||
pIBO->TrianglesToStrips(Indices.data(), Indices.size());
|
||||
break;
|
||||
@@ -147,7 +146,7 @@ void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::
|
||||
if (!mBuffered) BufferGL();
|
||||
|
||||
// Set up wireframe
|
||||
WireColor.a = 0;
|
||||
WireColor.A = 0;
|
||||
CDrawUtil::UseColorShader(WireColor);
|
||||
Options |= eNoMaterialSetup;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
@@ -19,7 +19,7 @@ class CModel : public CBasicModel
|
||||
|
||||
public:
|
||||
CModel();
|
||||
CModel(CMaterialSet *pSet, bool ownsMatSet);
|
||||
CModel(CMaterialSet *pSet, bool OwnsMatSet);
|
||||
~CModel();
|
||||
|
||||
void BufferGL();
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
#include "Core/Render/CRenderer.h"
|
||||
#include "Core/OpenGL/GLCommon.h"
|
||||
|
||||
CStaticModel::CStaticModel() : CBasicModel()
|
||||
CStaticModel::CStaticModel()
|
||||
: CBasicModel()
|
||||
, mpMaterial(nullptr)
|
||||
, mTransparent(false)
|
||||
{
|
||||
mpMaterial = nullptr;
|
||||
mTransparent = false;
|
||||
mHasOwnSurfaces = false;
|
||||
mHasOwnMaterials = false;
|
||||
}
|
||||
|
||||
CStaticModel::CStaticModel(CMaterial *pMat) : CBasicModel()
|
||||
CStaticModel::CStaticModel(CMaterial *pMat)
|
||||
: CBasicModel()
|
||||
, mpMaterial(pMat)
|
||||
, mTransparent((pMat->Options() & CMaterial::eTransparent) != 0)
|
||||
{
|
||||
mpMaterial = pMat;
|
||||
mTransparent = ((pMat->Options() & CMaterial::eTransparent) != 0);
|
||||
mHasOwnSurfaces = false;
|
||||
mHasOwnMaterials = false;
|
||||
}
|
||||
|
||||
CStaticModel::~CStaticModel()
|
||||
@@ -58,7 +56,8 @@ void CStaticModel::BufferGL()
|
||||
Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset);
|
||||
|
||||
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
|
||||
switch (pPrim->Type) {
|
||||
switch (pPrim->Type)
|
||||
{
|
||||
case eGX_Triangles:
|
||||
pIBO->TrianglesToStrips(Indices.data(), Indices.size());
|
||||
break;
|
||||
@@ -158,7 +157,7 @@ void CStaticModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CC
|
||||
if (!mBuffered) BufferGL();
|
||||
|
||||
// Set up wireframe
|
||||
WireColor.a = 0;
|
||||
WireColor.A = 0;
|
||||
CDrawUtil::UseColorShader(WireColor);
|
||||
Options |= eNoMaterialSetup;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
@@ -18,24 +18,24 @@ public:
|
||||
|
||||
CVertex() {}
|
||||
|
||||
CVertex(CVector3f& Pos)
|
||||
CVertex(CVector3f& rPos)
|
||||
{
|
||||
Position = Pos;
|
||||
Position = rPos;
|
||||
}
|
||||
|
||||
bool operator==(const CVertex& other) {
|
||||
return ((Position == other.Position) &&
|
||||
(Normal == other.Normal) &&
|
||||
(Color[0] == other.Color[0]) &&
|
||||
(Color[1] == other.Color[1]) &&
|
||||
(Tex[0] == other.Tex[0]) &&
|
||||
(Tex[1] == other.Tex[1]) &&
|
||||
(Tex[2] == other.Tex[2]) &&
|
||||
(Tex[3] == other.Tex[3]) &&
|
||||
(Tex[4] == other.Tex[4]) &&
|
||||
(Tex[5] == other.Tex[5]) &&
|
||||
(Tex[6] == other.Tex[6]) &&
|
||||
(Tex[7] == other.Tex[7]));
|
||||
bool operator==(const CVertex& rkOther) {
|
||||
return ((Position == rkOther.Position) &&
|
||||
(Normal == rkOther.Normal) &&
|
||||
(Color[0] == rkOther.Color[0]) &&
|
||||
(Color[1] == rkOther.Color[1]) &&
|
||||
(Tex[0] == rkOther.Tex[0]) &&
|
||||
(Tex[1] == rkOther.Tex[1]) &&
|
||||
(Tex[2] == rkOther.Tex[2]) &&
|
||||
(Tex[3] == rkOther.Tex[3]) &&
|
||||
(Tex[4] == rkOther.Tex[4]) &&
|
||||
(Tex[5] == rkOther.Tex[5]) &&
|
||||
(Tex[6] == rkOther.Tex[6]) &&
|
||||
(Tex[7] == rkOther.Tex[7]));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,27 +5,27 @@
|
||||
|
||||
enum EVertexAttribute
|
||||
{
|
||||
eNoAttributes = 0x0,
|
||||
ePosition = 0x3,
|
||||
eNormal = 0xC,
|
||||
eColor0 = 0x30,
|
||||
eColor1 = 0xC0,
|
||||
eTex0 = 0x300,
|
||||
eTex1 = 0xC00,
|
||||
eTex2 = 0x3000,
|
||||
eTex3 = 0xC000,
|
||||
eTex4 = 0x30000,
|
||||
eTex5 = 0xC0000,
|
||||
eTex6 = 0x300000,
|
||||
eTex7 = 0xC00000,
|
||||
ePosMtx = 0x1000000,
|
||||
eTex0Mtx = 0x2000000,
|
||||
eTex1Mtx = 0x4000000,
|
||||
eTex2Mtx = 0x8000000,
|
||||
eTex3Mtx = 0x10000000,
|
||||
eTex4Mtx = 0x20000000,
|
||||
eTex5Mtx = 0x40000000,
|
||||
eTex6Mtx = 0x80000000
|
||||
eNoAttributes = 0x0,
|
||||
ePosition = 0x3,
|
||||
eNormal = 0xC,
|
||||
eColor0 = 0x30,
|
||||
eColor1 = 0xC0,
|
||||
eTex0 = 0x300,
|
||||
eTex1 = 0xC00,
|
||||
eTex2 = 0x3000,
|
||||
eTex3 = 0xC000,
|
||||
eTex4 = 0x30000,
|
||||
eTex5 = 0xC0000,
|
||||
eTex6 = 0x300000,
|
||||
eTex7 = 0xC00000,
|
||||
ePosMtx = 0x1000000,
|
||||
eTex0Mtx = 0x2000000,
|
||||
eTex1Mtx = 0x4000000,
|
||||
eTex2Mtx = 0x8000000,
|
||||
eTex3Mtx = 0x10000000,
|
||||
eTex4Mtx = 0x20000000,
|
||||
eTex5Mtx = 0x40000000,
|
||||
eTex6Mtx = 0x80000000
|
||||
};
|
||||
DECLARE_FLAGS(EVertexAttribute, FVertexDescription)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Core/CRayCollisionTester.h"
|
||||
#include <Math/MathUtil.h>
|
||||
|
||||
std::pair<bool,float> SSurface::IntersectsRay(const CRay& Ray, bool allowBackfaces, float LineThreshold)
|
||||
std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackfaces, float LineThreshold)
|
||||
{
|
||||
bool Hit = false;
|
||||
float HitDist;
|
||||
@@ -25,43 +25,43 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& Ray, bool allowBackfac
|
||||
|
||||
for (u32 iTri = 0; iTri < NumTris; iTri++)
|
||||
{
|
||||
CVector3f vtxA, vtxB, vtxC;
|
||||
CVector3f VtxA, VtxB, VtxC;
|
||||
|
||||
// Get the three vertices that make up the current tri
|
||||
if (pPrim->Type == eGX_Triangles)
|
||||
{
|
||||
u32 VertIndex = iTri * 3;
|
||||
vtxA = pPrim->Vertices[VertIndex].Position;
|
||||
vtxB = pPrim->Vertices[VertIndex+1].Position;
|
||||
vtxC = pPrim->Vertices[VertIndex+2].Position;
|
||||
VtxA = pPrim->Vertices[VertIndex].Position;
|
||||
VtxB = pPrim->Vertices[VertIndex+1].Position;
|
||||
VtxC = pPrim->Vertices[VertIndex+2].Position;
|
||||
}
|
||||
|
||||
else if (pPrim->Type == eGX_TriangleFan)
|
||||
{
|
||||
vtxA = pPrim->Vertices[0].Position;
|
||||
vtxB = pPrim->Vertices[iTri+1].Position;
|
||||
vtxC = pPrim->Vertices[iTri+2].Position;
|
||||
VtxA = pPrim->Vertices[0].Position;
|
||||
VtxB = pPrim->Vertices[iTri+1].Position;
|
||||
VtxC = pPrim->Vertices[iTri+2].Position;
|
||||
}
|
||||
|
||||
else if (pPrim->Type = eGX_TriangleStrip)
|
||||
{
|
||||
if (iTri & 0x1)
|
||||
{
|
||||
vtxA = pPrim->Vertices[iTri+2].Position;
|
||||
vtxB = pPrim->Vertices[iTri+1].Position;
|
||||
vtxC = pPrim->Vertices[iTri].Position;
|
||||
VtxA = pPrim->Vertices[iTri+2].Position;
|
||||
VtxB = pPrim->Vertices[iTri+1].Position;
|
||||
VtxC = pPrim->Vertices[iTri].Position;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
vtxA = pPrim->Vertices[iTri].Position;
|
||||
vtxB = pPrim->Vertices[iTri+1].Position;
|
||||
vtxC = pPrim->Vertices[iTri+2].Position;
|
||||
VtxA = pPrim->Vertices[iTri].Position;
|
||||
VtxB = pPrim->Vertices[iTri+1].Position;
|
||||
VtxC = pPrim->Vertices[iTri+2].Position;
|
||||
}
|
||||
}
|
||||
|
||||
// Intersection test
|
||||
std::pair<bool,float> TriResult = Math::RayTriangleIntersection(Ray, vtxA, vtxB, vtxC, allowBackfaces);
|
||||
std::pair<bool,float> TriResult = Math::RayTriangleIntersection(rkRay, VtxA, VtxB, VtxC, AllowBackfaces);
|
||||
|
||||
if (TriResult.first)
|
||||
{
|
||||
@@ -86,22 +86,22 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& Ray, bool allowBackfac
|
||||
|
||||
for (u32 iLine = 0; iLine < NumLines; iLine++)
|
||||
{
|
||||
CVector3f vtxA, vtxB;
|
||||
CVector3f VtxA, VtxB;
|
||||
|
||||
// Get the two vertices that make up the current line
|
||||
u32 index = (pPrim->Type == eGX_Lines ? iLine * 2 : iLine);
|
||||
vtxA = pPrim->Vertices[index].Position;
|
||||
vtxB = pPrim->Vertices[index+1].Position;
|
||||
u32 Index = (pPrim->Type == eGX_Lines ? iLine * 2 : iLine);
|
||||
VtxA = pPrim->Vertices[Index].Position;
|
||||
VtxB = pPrim->Vertices[Index+1].Position;
|
||||
|
||||
// Intersection test
|
||||
std::pair<bool,float> result = Math::RayLineIntersection(Ray, vtxA, vtxB, LineThreshold);
|
||||
std::pair<bool,float> Result = Math::RayLineIntersection(rkRay, VtxA, VtxB, LineThreshold);
|
||||
|
||||
if (result.first)
|
||||
if (Result.first)
|
||||
{
|
||||
if ((!Hit) || (result.second < HitDist))
|
||||
if ((!Hit) || (Result.second < HitDist))
|
||||
{
|
||||
Hit = true;
|
||||
HitDist = result.second;
|
||||
HitDist = Result.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,13 @@ struct SSurface
|
||||
};
|
||||
std::vector<SPrimitive> Primitives;
|
||||
|
||||
SSurface() {
|
||||
SSurface()
|
||||
{
|
||||
VertexCount = 0;
|
||||
TriangleCount = 0;
|
||||
}
|
||||
|
||||
std::pair<bool,float> IntersectsRay(const CRay& Ray, bool allowBackfaces = false, float LineThreshold = 0.02f);
|
||||
std::pair<bool,float> IntersectsRay(const CRay& rkRay, bool AllowBackfaces = false, float LineThreshold = 0.02f);
|
||||
};
|
||||
|
||||
#endif // SSURFACE_H
|
||||
|
||||
Reference in New Issue
Block a user