Files
dl_old/dl/render/dl_graphics.cpp
T
2023-10-31 03:10:55 +08:00

118 lines
2.2 KiB
C++

#include "dl_graphics.h"
#include "vk/dl_vk.h"
#include "math/dl_coor.h"
namespace dl
{
// 汉
void Graphics::Dot(const Position3& p)
{
std::array<VertexGfx, 1> v;
v[0]._color = _col[0];
if (_bUseCoor)
{
if (_coor)
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p)));
else
v[0]._pos = p;
}
else
assert(0);
g_vk->GfxPushDot(v[0]);
}
void Graphics::Line(const Position3& p0, const Position3& p1)
{
std::array<VertexGfx, 2> v;
v[0]._color = _col[0];
v[1]._color = _col[1];
if (_bUseCoor)
{
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p0)));
v[1]._pos = toLonger(_coor->ThisToWorld(toShorter(p1)));
}
else
assert(0);
g_vk->GfxPushLine(v[0], v[1]);
}
void Graphics::Triangle(const Position3& p0, const Position3& p1, const Position3& p2)
{
std::array<VertexGfx, 3> v;
v[0]._color = _col[0];
v[1]._color = _col[1];
v[2]._color = _col[2];
if (_bUseCoor)
{
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p0)));
v[1]._pos = toLonger(_coor->ThisToWorld(toShorter(p1)));
v[2]._pos = toLonger(_coor->ThisToWorld(toShorter(p2)));
}
else
assert(0);
g_vk->GfxPushTriangle(v[0], v[1], v[2]);
}
void Graphics::TriangleSolid(const Position3& p0, const Position3& p1, const Position3& p2)
{
std::array<VertexGfx, 3> v;
v[0]._color = _col[0];
v[1]._color = _col[1];
v[2]._color = _col[2];
if (_bUseCoor)
{
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p0)));
v[1]._pos = toLonger(_coor->ThisToWorld(toShorter(p1)));
v[2]._pos = toLonger(_coor->ThisToWorld(toShorter(p2)));
}
else
assert(0);
g_vk->GfxPushTriangleSolid(v[0], v[1], v[2]);
}
void Graphics::RenderCoor(Coor* coor, bool to_parent)
{
SetCoor(coor);
SetColor(ColorDef::RED);
Line({}, { 32, 0, 0 });
SetColor(ColorDef::GREEN);
Line({}, { 0, 32, 0 });
// 指向父节点
if (to_parent)
{
Coor* parent = coor->GetParent();
if (parent)
{
SetCoor(parent);
SetColor(ColorDef::GREEN);
Line(toLonger(coor->GetPosition()), {});
}
}
}
//void Graphics::SetMatrix(Coor* coor)
//{
// Matrix4 m_t = Mat::CreateTranslation(toLonger(coor->GetPosition()));
// Matrix4 m_r = Mat::CreateRotation({ 0, 0, 1 }, coor->GetRotate());
// Matrix4 m_s = Mat::CreateScaling(toLonger(coor->GetPosition(), 1.0_f));
// _mat = m_t * m_r * m_s;
//}
}