Skip to content

Instantly share code, notes, and snippets.

@msjang
Last active January 27, 2023 01:46
Show Gist options
  • Save msjang/e30f71fc6cdfd0d27e3c to your computer and use it in GitHub Desktop.
Save msjang/e30f71fc6cdfd0d27e3c to your computer and use it in GitHub Desktop.
GitHub Gist 소개

GitHub Gist 소개

GitHub Gist는 GitHub과는 달리, private도 무료입니다. 저는 주로 코드조각(Code Snippet), 로그, 메모 등을 남기는데 사용합니다.

@koreangameboss
Copy link

#include "Precompiled.h"
#include "SoftRenderer.h"
#include
using namespace CK::DD;

// 격자를 그리는 함수
void SoftRenderer::DrawGizmo2D()
{
auto& r = GetRenderer();
const auto& g = Get2DGameEngine();

// 그리드 색상
LinearColor gridColor(LinearColor(0.8f, 0.8f, 0.8f, 0.3f));

// 뷰의 영역 계산
Vector2 viewPos = g.GetMainCamera().GetTransform().GetPosition();
Vector2 extent = Vector2(_ScreenSize.X * 0.5f, _ScreenSize.Y * 0.5f);

// 좌측 하단에서부터 격자 그리기
int xGridCount = _ScreenSize.X / _Grid2DUnit;
int yGridCount = _ScreenSize.Y / _Grid2DUnit;

// 그리드가 시작되는 좌하단 좌표 값 계산
Vector2 minPos = viewPos - extent;
Vector2 minGridPos = Vector2(ceilf(minPos.X / (float)_Grid2DUnit), ceilf(minPos.Y / (float)_Grid2DUnit)) * (float)_Grid2DUnit;
ScreenPoint gridBottomLeft = ScreenPoint::ToScreenCoordinate(_ScreenSize, minGridPos - viewPos);

for (int ix = 0; ix < xGridCount; ++ix)
{
	r.DrawFullVerticalLine(gridBottomLeft.X + ix * _Grid2DUnit, gridColor);
}

for (int iy = 0; iy < yGridCount; ++iy)
{
	r.DrawFullHorizontalLine(gridBottomLeft.Y - iy * _Grid2DUnit, gridColor);
}

ScreenPoint worldOrigin = ScreenPoint::ToScreenCoordinate(_ScreenSize, -viewPos);
r.DrawFullHorizontalLine(worldOrigin.Y, LinearColor::Red);
r.DrawFullVerticalLine(worldOrigin.X, LinearColor::Green);

}

// 게임 오브젝트 목록

// 최초 씬 로딩을 담당하는 함수
void SoftRenderer::LoadScene2D()
{
// 최초 씬 로딩에서 사용하는 모듈 내 주요 레퍼런스
auto& g = Get2DGameEngine();

}

// 게임 로직과 렌더링 로직이 공유하는 변수
Vector2 currentPosition(0.0f, 0.0f);

// 게임 로직을 담당하는 함수
void SoftRenderer::Update2D(float InDeltaSeconds)
{
// 게임 로직에서 사용하는 모듈 내 주요 레퍼런스
auto& g = Get2DGameEngine();
const InputManager& input = g.GetInputManager();

// 게임 로직의 로컬 변수
static float moveSpeed = 100.f;

Vector2 inputVector = Vector2(input.GetAxis(InputAxis::XAxis), input.GetAxis(InputAxis::YAxis));
Vector2 deltaPosition = inputVector * moveSpeed * InDeltaSeconds;

// 물체의 최종 상태 설정
currentPosition += deltaPosition;

}

// 렌더링 로직을 담당하는 함수
void SoftRenderer::Render2D()
{
// 렌더링 로직에서 사용하는 모듈 내 주요 레퍼런스
auto& r = GetRenderer();
const auto& g = Get2DGameEngine();

// 배경에 격자 그리기
DrawGizmo2D();

// 렌더링 로직의 로컬 변수
static float radius = 50.f;
static std::vector<Vector2> circles;

// 밝은 회색의 선을 사용해 벡터의 선형성을 표현
static float lineLength = 10.0f;
Vector2 lineStart = currentPosition * lineLength;
Vector2 lineEnd = currentPosition * -lineLength;
r.DrawLine(lineStart, lineEnd, LinearColor::LightGray);

// 최초에 한번 반지름보다 긴 벡터를 모아 컨테이너에 담는다
if (circles.empty())
{
	for (int i = -50; i < 50; ++i)
	{
		for (int j = -50; j < 50; ++j)
		{
			circles.push_back(Vector2(j, i));
		}
	}
	// 여기에 코드 추가
	// circles.push_back(Vector2(x, y));
}

Vector2 vTmp(0.0f, 0.0f);
// 원을 구성하는 벡터를 모두 붉은 색으로 표시한다. 
for (auto const& v : circles)
{ 
	vTmp = (v + currentPosition) - currentPosition;
	if (vTmp.SizeSquared() <= 2500.0f)
	{
		r.DrawPoint(v + currentPosition, LinearColor::Red);
	}
}

// 원의 중심 좌표를 우상단에 출력
r.PushStatisticText("Coordinate : " + currentPosition.ToString());

}

// 메시를 그리는 함수
void SoftRenderer::DrawMesh2D(const class DD::Mesh& InMesh, const Matrix3x3& InMatrix, const LinearColor& InColor)
{
}

// 삼각형을 그리는 함수
void SoftRenderer::DrawTriangle2D(std::vectorDD::Vertex2D& InVertices, const LinearColor& InColor, FillMode InFillMode)
{
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment