Files
dl_old/dl/render/dl_graphics.cpp
T
2024-05-07 19:00:18 +08:00

114 lines
2.1 KiB
C++

#include "dl_graphics.h"
#ifndef DL_DISABLE_RENDER
#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[_colIndex[0]];
if (_bUseCoor)
{
if (_coor)
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p)), _z);
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[_colIndex[0]];
v[1]._color = _col[_colIndex[1]];
if (_bUseCoor)
{
if (_coor)
{
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p0)), _z);
v[1]._pos = toLonger(_coor->ThisToWorld(toShorter(p1)), _z);
}
else
{
v[0]._pos = p0;
v[1]._pos = p1;
}
}
else
assert(0);
g_vk->GfxPushLine(v[0], v[1]);
}
void Graphics::TriangleSolid(const Position3& p0, const Position3& p1, const Position3& p2)
{
std::array<VertexGfx, 3> v;
v[0]._color = _col[_colIndex[0]];
v[1]._color = _col[_colIndex[1]];
v[2]._color = _col[_colIndex[2]];
if (_bUseCoor)
{
if (_coor)
{
v[0]._pos = toLonger(_coor->ThisToWorld(toShorter(p0)), _z);
v[1]._pos = toLonger(_coor->ThisToWorld(toShorter(p1)), _z);
v[2]._pos = toLonger(_coor->ThisToWorld(toShorter(p2)), _z);
}
else
{
v[0]._pos = p0;
v[1]._pos = p1;
v[2]._pos = p2;
}
}
else
assert(0);
g_vk->GfxPushTriangle(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;
//}
}
#endif