Cleaning for mesh addition.

This commit is contained in:
James Grogan 2022-11-13 17:02:09 +00:00
parent 8e0ce22b57
commit 402f381d10
67 changed files with 655 additions and 456 deletions

View file

@ -3,32 +3,41 @@
#include "INativeDrawingContext.h"
#include "AbstractGeometricItem.h"
#include "MeshBuilder.h"
#include "TriMesh.h"
std::unique_ptr<DrawingContext> DrawingContext::Create()
{
return std::make_unique<DrawingContext>();
}
void DrawingContext::SetNativeContext(std::unique_ptr<INativeDrawingContext> context)
void DrawingContext::setNativeContext(std::unique_ptr<INativeDrawingContext> context)
{
mNativeDrawingContext = std::move(context);
}
INativeDrawingContext* DrawingContext::GetNativeContext()
INativeDrawingContext* DrawingContext::getNativeContext()
{
return mNativeDrawingContext.get();
}
void DrawingContext::AddDrawable(AbstractGeometricItemPtr item)
void DrawingContext::addDrawable(AbstractGeometricItemPtr item)
{
mItems.push_back(std::move(item));
}
unsigned DrawingContext::GetNumItems() const
unsigned DrawingContext::getNumItems() const
{
return mItems.size();
}
AbstractGeometricItem* DrawingContext::GetDrawable(unsigned idx) const
AbstractGeometricItem* DrawingContext::getDrawable(unsigned idx) const
{
return mItems[idx].get();
}
void DrawingContext::updateMesh()
{
}

View file

@ -7,6 +7,8 @@ class INativeDrawingContext;
class AbstractGeometricItem;
using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>;
class TriMesh;
class DrawingContext
{
public:
@ -14,18 +16,20 @@ public:
static std::unique_ptr<DrawingContext> Create();
void SetNativeContext(std::unique_ptr<INativeDrawingContext> context);
void setNativeContext(std::unique_ptr<INativeDrawingContext> context);
INativeDrawingContext* GetNativeContext();
INativeDrawingContext* getNativeContext();
unsigned GetNumItems() const;
unsigned getNumItems() const;
void AddDrawable(AbstractGeometricItemPtr item);
void addDrawable(AbstractGeometricItemPtr item);
AbstractGeometricItem* GetDrawable(unsigned idx) const;
AbstractGeometricItem* getDrawable(unsigned idx) const;
private:
void updateMesh();
std::unique_ptr<TriMesh> mMesh;
std::vector<std::unique_ptr<AbstractGeometricItem> > mItems;
std::unique_ptr<INativeDrawingContext> mNativeDrawingContext;
};

View file

@ -7,6 +7,7 @@
#include "Grid.h"
#include "Image.h"
#include "TriMesh.h"
DrawingManager::DrawingManager()
: mRasterizer(std::make_unique<Rasterizer>())
@ -30,7 +31,7 @@ void DrawingManager::InitializeContext()
mDrawingContext = DrawingContext::Create();
}
void DrawingManager::AddText(TextElement* text)
void DrawingManager::AddText(TextNode* text)
{
if (!mDrawingContext)
{

View file

@ -5,7 +5,7 @@
#include "INativeDrawingContext.h"
#include "INativeDrawingSurface.h"
class TextElement;
class TextNode;
class DrawingSurface;
using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
@ -21,7 +21,7 @@ public:
static std::unique_ptr<DrawingManager> Create();
void InitalizeSurface(unsigned width, unsigned height);
void InitializeContext();
void AddText(TextElement* text);
void AddText(TextNode* text);
void RenderToFile(const std::string& path);
private:

View file

@ -16,9 +16,9 @@ void Rasterizer::Paint(DrawingSurface* surface, DrawingContext* context)
const auto height = surface->GetHeight();
mGrid->ResetBounds(Rectangle(Point(0, 0), Point(width, height)));
for (unsigned idx=0; idx< context->GetNumItems(); idx++)
for (unsigned idx=0; idx< context->getNumItems(); idx++)
{
context->GetDrawable(idx)->Sample(mGrid.get());
context->getDrawable(idx)->Sample(mGrid.get());
}
surface->Paint(mGrid.get());

View file

@ -5,7 +5,7 @@
#include <GL/gl.h>
void OpenGlInterface::draw()
void OpenGlInterface::draw(TriMesh* mesh)
{
glClearColor(0.4, 0.4, 0.4, 0.4);
glClear(GL_COLOR_BUFFER_BIT);
@ -13,6 +13,8 @@ void OpenGlInterface::draw()
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.7, 0.7, 0);
glVertex3f(0.7, 0.7, 0);

View file

@ -1,10 +1,11 @@
#pragma once
class TriMesh;
class OpenGlInterface
{
public:
static void draw();
static void draw(TriMesh* mesh);
};