144 lines
8.6 KiB
C++
144 lines
8.6 KiB
C++
#include "stdafx.h"
|
|
#include "IResourceFactory.h"
|
|
#include "CommonObjectFactory.h"
|
|
#include "PingPongBuffer/PingPongBuffer.h"
|
|
|
|
|
|
CommonObjectFactory::CommonObjectFactory(IEngine& argEngine)
|
|
: m_Engine(argEngine)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
CommonObjectFactory::~CommonObjectFactory()
|
|
{
|
|
}
|
|
|
|
|
|
IPingPongBuffer* CommonObjectFactory::CreatePingPongBuffer(ITexture& argInputTexture, const PingPongBufferDescription& argDescriptor)
|
|
{
|
|
IPingPongBuffer* pingPongBuffer = new PingPongBuffer(m_Engine);
|
|
pingPongBuffer->set_InputTexture(argInputTexture);
|
|
pingPongBuffer->set_Descriptor(argDescriptor);
|
|
return pingPongBuffer;
|
|
}
|
|
|
|
|
|
IGeometryBuffer* CommonObjectFactory::CreateCube(float argWidth, float argHeight, float argDepth, bool argInverted, const string8& argName)
|
|
{
|
|
argWidth *= 0.5f;
|
|
argHeight *= 0.5f;
|
|
argDepth *= 0.5f;
|
|
|
|
float normal = argInverted ? -1.0f : 1.0f;
|
|
float tangent = 1.0;//argInverted ? -1.0f : 1.0f;
|
|
CommonCubeVertex vertices[] =
|
|
{
|
|
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
|
|
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
};
|
|
|
|
std::vector<VertexElement> vertexElements;
|
|
vertexElements.push_back(VertexElement(VertexElement::Position));
|
|
vertexElements.push_back(VertexElement(VertexElement::Normal));
|
|
vertexElements.push_back(VertexElement(VertexElement::Tangent));
|
|
vertexElements.push_back(VertexElement(VertexElement::Texture2D));
|
|
|
|
IGeometryBuffer* cubeBuffer = &m_Engine.get_ResourceFactory().CreateOrFindGeometryBuffer(argName);
|
|
cubeBuffer->SetVertexData(sizeof(vertices) / sizeof(CommonCubeVertex), sizeof(CommonCubeVertex), vertices, vertexElements, false);
|
|
|
|
uint32 invertedIndices[] = { 0,1,3, 3,1,2, 5,4,6, 6,4,7, 8,9,11, 11,9,10, 13,12,14, 14,12,15, 16,17,19, 19,17,18, 21,20,22, 22,20,23 };
|
|
uint32 normalIndices[] = { 3,1,0, 2,1,3, 6,4,5, 7,4,6, 11,9,8, 10,9,11, 14,12,13, 15,12,14, 19,17,16, 18,17,19, 22,20,21, 23,20,22 };
|
|
if (argInverted)
|
|
cubeBuffer->SetIndexData(sizeof(invertedIndices) / sizeof(uint32), invertedIndices, false);
|
|
else
|
|
cubeBuffer->SetIndexData(sizeof(normalIndices) / sizeof(uint32), normalIndices, false);
|
|
|
|
return cubeBuffer;
|
|
}
|
|
|
|
|
|
IGeometryBuffer* CommonObjectFactory::CreateQuad(float argWidth, float argHeight, bool argTwoSided, const string8& argName)
|
|
{
|
|
argWidth *= 0.5f;
|
|
argHeight *= 0.5f;
|
|
|
|
CommonQuadVertex quadOneSidedVertices[] =
|
|
{
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
};
|
|
|
|
CommonQuadVertex quadTwoSidedVertices[] =
|
|
{
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
|
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
|
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
|
};
|
|
|
|
std::vector<VertexElement> vertexElements;
|
|
vertexElements.push_back(VertexElement(VertexElement::Position));
|
|
vertexElements.push_back(VertexElement(VertexElement::Normal));
|
|
vertexElements.push_back(VertexElement(VertexElement::Texture2D));
|
|
|
|
uint32 oneSidedIndices[] = { 0,1,2, 3,4,5 };
|
|
uint32 twoSidedIndices[] = { 0,1,2,3,4,5, 11,10,9,8,7,6 };
|
|
|
|
IGeometryBuffer* quadBuffer = &m_Engine.get_ResourceFactory().CreateOrFindGeometryBuffer(argName);
|
|
if (!argTwoSided)
|
|
{
|
|
quadBuffer->SetVertexData(sizeof(quadOneSidedVertices) / sizeof(CommonQuadVertex), sizeof(CommonQuadVertex), quadOneSidedVertices, vertexElements, false);
|
|
quadBuffer->SetIndexData(sizeof(oneSidedIndices) / sizeof(uint32), oneSidedIndices, false);
|
|
}
|
|
else
|
|
{
|
|
quadBuffer->SetVertexData(sizeof(quadTwoSidedVertices) / sizeof(CommonQuadVertex), sizeof(CommonQuadVertex), quadTwoSidedVertices, vertexElements, false);
|
|
quadBuffer->SetIndexData(sizeof(twoSidedIndices) / sizeof(uint32), twoSidedIndices, false);
|
|
}
|
|
|
|
return quadBuffer;
|
|
}
|