Simple dx render example.
This commit is contained in:
parent
36515556b8
commit
e0cad34d55
22 changed files with 339 additions and 60 deletions
|
@ -19,12 +19,12 @@ public:
|
|||
|
||||
AbstractApp* getMainApplication() const override;
|
||||
|
||||
void run();
|
||||
|
||||
AbstractUIInterface* getUiInterface() const override;
|
||||
|
||||
void setUiInterfaceBackend(UiInterfaceFactory::Backend backend);
|
||||
|
||||
void run();
|
||||
|
||||
protected:
|
||||
virtual void initializeViews();
|
||||
|
||||
|
|
|
@ -48,15 +48,18 @@ void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu
|
|||
FileLogger::GetInstance().Open();
|
||||
MLOG_INFO("Launched");
|
||||
|
||||
mDatabaseManager = DatabaseManager::Create();
|
||||
mDatabaseManager->openDatabase(launch_path + "/database.db");
|
||||
MLOG_INFO("Created DB");
|
||||
if (false)
|
||||
{
|
||||
mDatabaseManager = DatabaseManager::Create();
|
||||
mDatabaseManager->openDatabase(launch_path + "/database.db");
|
||||
MLOG_INFO("Created DB");
|
||||
|
||||
mNetworkManager = NetworkManager::Create();
|
||||
MLOG_INFO("Created Network Manager");
|
||||
mNetworkManager = NetworkManager::Create();
|
||||
MLOG_INFO("Created Network Manager");
|
||||
|
||||
mAudioManager = AudioManager::Create();
|
||||
MLOG_INFO("Created Audio Manager");
|
||||
mAudioManager = AudioManager::Create();
|
||||
MLOG_INFO("Created Audio Manager");
|
||||
}
|
||||
}
|
||||
|
||||
void MainApplication::run()
|
||||
|
@ -141,8 +144,16 @@ CommandLineArgs* MainApplication::getCommandLineArgs() const
|
|||
|
||||
void MainApplication::shutDown()
|
||||
{
|
||||
mDatabaseManager->onShutDown();
|
||||
mNetworkManager->ShutDown();
|
||||
if (mDatabaseManager)
|
||||
{
|
||||
mDatabaseManager->onShutDown();
|
||||
}
|
||||
|
||||
if (mNetworkManager)
|
||||
{
|
||||
mNetworkManager->ShutDown();
|
||||
}
|
||||
|
||||
MLOG_INFO("Shut down");
|
||||
FileLogger::GetInstance().Close();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ list(APPEND geometry_LIB_INCLUDES
|
|||
Grid.h
|
||||
Grid.cpp
|
||||
Line.h
|
||||
Linalg.h
|
||||
Linalg.cpp
|
||||
Line.cpp
|
||||
LineSegment.cpp
|
||||
Path.h
|
||||
|
@ -18,7 +20,9 @@ list(APPEND geometry_LIB_INCLUDES
|
|||
Rectangle.cpp
|
||||
Triangle.h
|
||||
Triangle.cpp
|
||||
Transform.cpp)
|
||||
Transform.cpp
|
||||
Vector.h
|
||||
Vector.cpp)
|
||||
|
||||
|
||||
# add the library
|
||||
|
|
11
src/geometry/Linalg.cpp
Normal file
11
src/geometry/Linalg.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "Linalg.h"
|
||||
|
||||
double Linalg::dotProduct(const Vector& v0, const Vector& v1)
|
||||
{
|
||||
return v0.dotProduct(v1);
|
||||
}
|
||||
|
||||
Vector Linalg::crossProduct(const Vector& v0, const Vector& v1)
|
||||
{
|
||||
return v0.crossProduct(v1);
|
||||
}
|
10
src/geometry/Linalg.h
Normal file
10
src/geometry/Linalg.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "Vector.h"
|
||||
|
||||
class Linalg
|
||||
{
|
||||
static double dotProduct(const Vector& v0, const Vector& v1);
|
||||
|
||||
static Vector crossProduct(const Vector& v0, const Vector& v1);
|
||||
};
|
|
@ -49,12 +49,15 @@ double Point::getZ() const
|
|||
|
||||
double Point::getDistance(const Point& point) const
|
||||
{
|
||||
return std::sqrt(mX*point.getX() + mY*point.getY() + mZ*point.getZ());
|
||||
const auto deltaX = getDeltaX(point);
|
||||
const auto deltaY = getDeltaY(point);
|
||||
const auto deltaZ = getDeltaZ(point);
|
||||
return std::sqrt(deltaX* deltaX + deltaY* deltaY + deltaZ* deltaZ);
|
||||
}
|
||||
|
||||
double Point::getDistance(Point* point) const
|
||||
Vector Point::getDelta(const Point& point) const
|
||||
{
|
||||
return std::sqrt(mX*point->getX() + mY*point->getY() + mZ*point->getZ());
|
||||
return Vector(point.mX - mX, point.mY - mY, point.mZ - mZ);
|
||||
}
|
||||
|
||||
double Point::getDeltaX(const Point& point) const
|
||||
|
@ -66,3 +69,22 @@ double Point::getDeltaY(const Point& point) const
|
|||
{
|
||||
return point.getY() - mY;
|
||||
}
|
||||
|
||||
double Point::getDeltaZ(const Point& point) const
|
||||
{
|
||||
return point.getZ() - mZ;
|
||||
}
|
||||
|
||||
void Point::scale(double x, double y, double z)
|
||||
{
|
||||
mX = x * mX;
|
||||
mY = y * mY;
|
||||
mZ = z * mZ;
|
||||
}
|
||||
|
||||
void Point::translate(double x, double y, double z)
|
||||
{
|
||||
mX += x;
|
||||
mY += y;
|
||||
mZ += z;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
|
@ -27,25 +28,17 @@ public:
|
|||
|
||||
double getDistance(const Point& point) const;
|
||||
|
||||
double getDistance(Point* point) const;
|
||||
|
||||
double getDeltaX(const Point& point) const;
|
||||
|
||||
double getDeltaY(const Point& point) const;
|
||||
|
||||
void scale(double x, double y, double z = 1.0)
|
||||
{
|
||||
mX = x*mX;
|
||||
mY = y*mY;
|
||||
mZ = z*mZ;
|
||||
}
|
||||
double getDeltaZ(const Point& point) const;
|
||||
|
||||
void translate(double x, double y, double z = 0.0)
|
||||
{
|
||||
mX += x;
|
||||
mY += y;
|
||||
mZ += z;
|
||||
}
|
||||
Vector getDelta(const Point& point) const;
|
||||
|
||||
void scale(double x, double y, double z = 1.0);
|
||||
|
||||
void translate(double x, double y, double z = 0.0);
|
||||
|
||||
bool operator==(const Point& rhs) const
|
||||
{
|
||||
|
|
61
src/geometry/Vector.cpp
Normal file
61
src/geometry/Vector.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "Vector.h"
|
||||
|
||||
Vector::Vector(double x, double y, double z)
|
||||
: mX(x),
|
||||
mY(y),
|
||||
mZ(z)
|
||||
{
|
||||
updateLength();
|
||||
}
|
||||
|
||||
Vector::~Vector()
|
||||
{
|
||||
};
|
||||
|
||||
double Vector::getX() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
double Vector::getY() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
double Vector::getZ() const
|
||||
{
|
||||
return mZ;
|
||||
}
|
||||
|
||||
double Vector::getLength() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
double Vector::dotProduct(const Vector& v) const
|
||||
{
|
||||
return mX * v.mX + mY * v.mY + mZ * v.mZ;
|
||||
}
|
||||
|
||||
Vector Vector::crossProduct(const Vector& v) const
|
||||
{
|
||||
return Vector(v.mY * mZ - v.mZ * mY, v.mZ * mX - v.mX * mZ, v.mX * mY - v.mY * mX);
|
||||
}
|
||||
|
||||
Vector Vector::getNormalized() const
|
||||
{
|
||||
return Vector(mX / mLength, mY / mLength, mZ / mLength);
|
||||
}
|
||||
|
||||
void Vector::scale(double x, double y, double z)
|
||||
{
|
||||
mX = x * mX;
|
||||
mY = y * mY;
|
||||
mZ = z * mZ;
|
||||
updateLength();
|
||||
}
|
||||
|
||||
void Vector::updateLength()
|
||||
{
|
||||
mLength = std::sqrt(mX * mX + mY * mY + mZ * mZ);
|
||||
}
|
48
src/geometry/Vector.h
Normal file
48
src/geometry/Vector.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
|
||||
class Vector
|
||||
{
|
||||
public:
|
||||
Vector(double x = 0, double y = 0, double z = 0);
|
||||
|
||||
~Vector();
|
||||
|
||||
double getX() const;
|
||||
|
||||
double getY() const;
|
||||
|
||||
double getZ() const;
|
||||
|
||||
double getLength() const;
|
||||
|
||||
Vector getNormalized() const;
|
||||
|
||||
void scale(double x, double y, double z = 1.0);
|
||||
|
||||
double dotProduct(const Vector& v) const;
|
||||
|
||||
Vector crossProduct(const Vector& v) const;
|
||||
|
||||
bool operator==(const Vector& rhs) const
|
||||
{
|
||||
return (mX == rhs.mX)
|
||||
&& (mY == rhs.mY)
|
||||
&& (mZ == rhs.mZ);
|
||||
}
|
||||
|
||||
bool operator!=(const Vector& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
void updateLength();
|
||||
|
||||
double mLength{ 0 };
|
||||
double mX{ 0 };
|
||||
double mY{ 0 };
|
||||
double mZ{ 0 };
|
||||
};
|
|
@ -5,6 +5,8 @@
|
|||
#include "DrawingSurface.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
#include "TriFace.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <directx/d3dx12.h>
|
||||
|
||||
|
@ -26,18 +28,45 @@ void DirectXMesh::update(DrawingContext* context, ID3D12Device* device)
|
|||
std::vector<float> color = { float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3]) };
|
||||
|
||||
auto transform = mModel->getTransform();
|
||||
|
||||
for (const auto& face : dynamic_cast<TriMesh*>(mModel->getMesh())->getFaces())
|
||||
{
|
||||
for (const auto& loc : face->getNodeLocations(AbstractFace::Orientation::CW))
|
||||
{
|
||||
auto x = loc.getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
auto y = loc.getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
x = 2 * x - 1;
|
||||
y = 2 * y - 1;
|
||||
|
||||
Vertex vert;
|
||||
vert.position = DirectX::XMFLOAT3(x, y, 0.0);
|
||||
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
||||
MLOG_INFO("Adding vert: " << x << " | " << y);
|
||||
mVertexBuffer.push_back(vert);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (const auto& node : mModel->getMesh()->getNodes())
|
||||
{
|
||||
auto x = node->getPoint().getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
x = 2 * x / width - 1.0;
|
||||
//x = 2 * x / width - 1.0;
|
||||
auto y = node->getPoint().getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
y = 2 * y / height;
|
||||
//y = 2 * y / height;
|
||||
Vertex vert;
|
||||
vert.position = DirectX::XMFLOAT3(x, y, 0.0);
|
||||
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
||||
MLOG_INFO("Adding vert: " << x << " | " << y);
|
||||
mVertexBuffer.push_back(vert);
|
||||
}
|
||||
mIndexBuffer = dynamic_cast<TriMesh*>(mModel->getMesh())->getFaceNodeIds();
|
||||
*/
|
||||
|
||||
//mIndexBuffer = dynamic_cast<TriMesh*>(mModel->getMesh())->getFaceNodeIds();
|
||||
mIndexBuffer = { 0, 1, 2 };
|
||||
for (auto id : mIndexBuffer)
|
||||
{
|
||||
MLOG_INFO("Adding id: " << id);
|
||||
}
|
||||
|
||||
createD3dVertexBuffer(device);
|
||||
createD3dIndexBuffer(device);
|
||||
|
@ -88,6 +117,7 @@ void DirectXMesh::createD3dIndexBuffer(ID3D12Device* device)
|
|||
|
||||
mIndexBufferView.BufferLocation = mD3dIndexBuffer->GetGPUVirtualAddress();
|
||||
mIndexBufferView.SizeInBytes = buffer_size;
|
||||
mIndexBufferView.Format = DXGI_FORMAT_R16_UINT;
|
||||
}
|
||||
|
||||
void DirectXMesh::uploadIndexBuffer(unsigned char* pBuffer) const
|
||||
|
|
|
@ -89,9 +89,10 @@ void DirectXMeshPainter::updateCommandList(ID3D12GraphicsCommandList* commandLis
|
|||
|
||||
for (const auto& mesh : mDxMeshes)
|
||||
{
|
||||
commandList->IASetVertexBuffers(0, 1, &mesh->getVertBufferView());
|
||||
commandList->IASetIndexBuffer(&mesh->getIndexBufferView());
|
||||
commandList->DrawInstanced(3, 1, 0, 0);
|
||||
commandList->IASetVertexBuffers(0, 1, &mesh->getVertBufferView());
|
||||
commandList->DrawInstanced(mesh->getVertBufferView().SizeInBytes/ mesh->getVertBufferView().StrideInBytes, 1, 0, 0);
|
||||
//commandList->DrawIndexedInstanced(3, 1, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,13 @@ class Edge;
|
|||
class AbstractFace
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Orientation
|
||||
{
|
||||
CW,
|
||||
CCW
|
||||
};
|
||||
|
||||
AbstractFace(unsigned id=0);
|
||||
|
||||
virtual ~AbstractFace();
|
||||
|
@ -32,7 +39,7 @@ public:
|
|||
|
||||
virtual std::vector<unsigned> getEdgeIds() const = 0;
|
||||
|
||||
virtual std::vector<Point> getNodeLocations() const = 0;
|
||||
virtual std::vector<Point> getNodeLocations(Orientation orientation = Orientation::CCW) const = 0;
|
||||
|
||||
protected:
|
||||
unsigned mId{0};
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
list(APPEND mesh_LIB_INCLUDES
|
||||
AbstractMesh.cpp
|
||||
AbstractMesh.h
|
||||
Edge.cpp
|
||||
Edge.h
|
||||
AbstractFace.cpp
|
||||
AbstractFace.h
|
||||
QuadFace.cpp
|
||||
QuadFace.h
|
||||
TriFace.cpp
|
||||
TriFace.h
|
||||
Node.cpp
|
||||
Node.h
|
||||
QuadMesh.cpp
|
||||
QuadMesh.h
|
||||
TriMesh.cpp
|
||||
TriMesh.h
|
||||
FaceMesh.cpp
|
||||
FaceMesh.h
|
||||
LineMesh.cpp
|
||||
LineMesh.h
|
||||
MeshPrimitives.cpp
|
||||
MeshBuilder.cpp)
|
||||
MeshPrimitives.h
|
||||
MeshBuilder.cpp
|
||||
MeshBuilder.h
|
||||
)
|
||||
|
||||
|
||||
# add the library
|
||||
|
|
|
@ -75,7 +75,34 @@ void TriFace::associateWidthEdges()
|
|||
mEdge2->associateFace(mId);
|
||||
}
|
||||
|
||||
std::vector<Point> TriFace::getNodeLocations() const
|
||||
std::vector<Point> TriFace::getNodeLocations(Orientation orientation) const
|
||||
{
|
||||
return {mEdge0->getNode0()->getPoint(), mEdge0->getNode1()->getPoint(), mEdge1->getNode1()->getPoint()};
|
||||
if (orientation != getOrientation())
|
||||
{
|
||||
return { mEdge0->getNode0()->getPoint(), mEdge0->getNode1()->getPoint(), mEdge1->getNode1()->getPoint() };
|
||||
}
|
||||
else
|
||||
{
|
||||
return { mEdge0->getNode0()->getPoint(), mEdge1->getNode1()->getPoint(), mEdge0->getNode1()->getPoint() };
|
||||
}
|
||||
}
|
||||
|
||||
Vector TriFace::getNormal() const
|
||||
{
|
||||
auto v0 = mEdge0->getNode0()->getPoint().getDelta(mEdge0->getNode1()->getPoint());
|
||||
auto v1 = mEdge0->getNode0()->getPoint().getDelta(mEdge1->getNode1()->getPoint());
|
||||
return v0.crossProduct(v1).getNormalized();
|
||||
}
|
||||
|
||||
AbstractFace::Orientation TriFace::getOrientation() const
|
||||
{
|
||||
Vector z_norm(0, 0, 1);
|
||||
if (z_norm.dotProduct(getNormal()) < 0.0)
|
||||
{
|
||||
return Orientation::CW;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Orientation::CCW;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractFace.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class Edge;
|
||||
|
||||
|
@ -26,7 +27,11 @@ public:
|
|||
unsigned getEdge2Id () const;
|
||||
std::vector<unsigned> getEdgeIds() const override;
|
||||
|
||||
std::vector<Point> getNodeLocations() const override;
|
||||
std::vector<Point> getNodeLocations(Orientation orientation = Orientation::CCW) const override;
|
||||
|
||||
Vector getNormal() const;
|
||||
|
||||
AbstractFace::Orientation getOrientation() const;
|
||||
|
||||
private:
|
||||
Edge* mEdge0{nullptr};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue