응애맘마조

230524 강의 본문

공부/3D강의

230524 강의

TH.Wert 2023. 5. 24. 18:27

UI를 만드는 것에 대해 강의를 했었습니다. 창던지기의 게이지바나 메뉴창 같이 가장 맨 위에 올라오고 카메라의 영향도 받지 않아야 되는 것입니다. 또한 UI에서는 어떤 값이 들어올지 모르고 주소를 미리 저장할 수 없기 때문에 함수 포인터를 사용했습니다. 게임을 구현하기 위한 것이 아니기 때문에 프레임워크에 따로 넣었습니다.

#pragma once
class UI : public Actor
{
public:
	Vector2			pivot;
	static UI* Create(string name = "UI");
	virtual void	Update() override;
	bool			Press = false;
	function<void()> mouseOver = nullptr; //마우스가 위에존재할떄
	function<void()> mouseDown = nullptr; // 위에서 눌렀을때 한번
	function<void()> mousePress = nullptr; // 누르고 있을때
	function<void()> mouseUp = nullptr; //누르고 떼었을때

	bool MouseOver();
	void	RenderDetail();
};
#include "framework.h"

UI* UI::Create(string name)
{
	UI* temp = new UI();
	temp->name = name;
	temp->type = ObType::UI;

	return temp;
}

void UI::Update()
{
	float left = GetWorldPos().x - S._11 * 0.5f;
	float right = GetWorldPos().x + S._11 * 0.5f;
	float top = GetWorldPos().y + S._22 * 0.5f;
	float bottom = GetWorldPos().y - S._22 * 0.5f;

	if (left < INPUT->NDCPosition.x and INPUT->NDCPosition.x < right
		and bottom < INPUT->NDCPosition.y and
		INPUT->NDCPosition.y < top)
	{
		//함수포인터가 할당 되었다면 실행
		if (mouseOver) mouseOver();

		if (INPUT->KeyDown(VK_LBUTTON))
		{
			Press = true;
			if (mouseDown) mouseDown();
		}

	}

	if (Press)
	{
		if (INPUT->KeyPress(VK_LBUTTON))
		{
			if (mousePress) mousePress();
		}
		if (INPUT->KeyUp(VK_LBUTTON))
		{
			Press = false;

			if (mouseUp) mouseUp();
		}
	}
	Matrix Pi;
	Pi = Matrix::CreateTranslation(pivot.x, pivot.y,0.0f);
	S = Matrix::CreateScale(scale.x, scale.y, scale.z);
	// Ry*Rx*Rz
	R = Matrix::CreateFromYawPitchRoll(rotation.y, rotation.x, rotation.z);
	T = Matrix::CreateTranslation(position.x, position.y, position.z);
	RT = R * T;
	W = Pi * S * RT;
	if (parent)
	{
		S *= parent->S;
		RT *= parent->RT;
		W *= parent->W;
	}

	for (auto it = children.begin(); it != children.end(); it++)
		it->second->Update();
}

bool UI::MouseOver()
{
	float left = GetWorldPos().x - S._11 * 0.5f;
	float right = GetWorldPos().x + S._11 * 0.5f;
	float top = GetWorldPos().y + S._22 * 0.5f;
	float bottom = GetWorldPos().y - S._22 * 0.5f;

	if (left < INPUT->NDCPosition.x and INPUT->NDCPosition.x < right
		and bottom < INPUT->NDCPosition.y and
		INPUT->NDCPosition.y < top)
	{
		return true;
	}
	return false;
}

헤더 파일과 cpp입니다.

오브젝트를 구현하기 위해 SRT를 하기 전에 형 변환을 먼저 해서 만들어준 뒤에 SRT를 연산합니다.

 

읽어주셔서 감사합니다.

'공부 > 3D강의' 카테고리의 다른 글

230526 강의  (0) 2023.05.29
230525 강의  (0) 2023.05.25
230523 강의  (0) 2023.05.23
230522 강의  (0) 2023.05.22
230519 강의  (0) 2023.05.19