Adventure of 빠타박스
article thumbnail
728x90
728x90
SMALL

ImGui 활용한 DirectX 11 3D를 이용한 2D를 만드는 내용입니다.
본 내용은 똑같이 사용할 수 없음을 알립니다. (참고 및 공부자료로 만들어진 내용임을 밝힙니다.)
전 과정에 대해 이해를 해야 다음 이 부분에 대한 이해를 할 수 있음을 밝힙니다

이전 자료)

21.12.02



각주 하단이동[footnote][/footnote]

 

 

Animaition 테스트 

상속 | 추상화 | 가상함수 | 함수포인터 | 동적 과 정적 | 애니메이션 이미지 


 

_Textrues / MetalSlug 폴더 만들어 주었음 

애니메이션 적용을 확인하기 위함임

 

이미지 테스트 

Stdafx.h 추가

 

 

STL이라는 곳

STL (Standard Table Library) 

stl요소에 다양한 여러가지가 들어가 있다. 

템플릿 라이브러리가 자료구조 를 다루는 내용이다.

 

크기가 정해진 경우 Array를 쓰면 편하다.

 

현재 아래 헤더와 cpp는 다 정의 하고 만들어진 경우 이다. 

 

 

Animation.h 

#pragma once

struct FAnimation
{
	Sprite* Image;
	float Time;

	FAnimation()
	{
		Image = NULL;
		Time = 1.0f;
	}

	FAnimation(Sprite* image, float time)
	{
		Image = image;
		Time = time;
	}
};

class Animation
{
public:
	void Position(float x, float y);
	void Position(D3DXVECTOR2 vec);
	void Position(D3DXVECTOR2* vec);

	void Scale(float x, float y);
	void Scale(D3DXVECTOR2 vec);

	void Color(float r, float g, float b, float a = 1.0f);
	void Color(D3DXCOLOR color);

public:
	Animation();
	~Animation();

	void Initialize(vector<FAnimation> animations);
	
	void Play(UINT frame = 0);
	void Pause();
	void Stop();

	void Update();
	void Render();

private:
	Vector2 position;
	Vector2 scale;
	Color4 color;

private:
	vector<FAnimation> frames;

private:
	bool bPlaying = false;
	UINT playFrameIndex = 0;
	float playTime = 0.0f;
};

 

Animation.cpp 

#include "stdafx.h"
#include "Animation.h"

Animation::Animation()
{

}

Animation::~Animation()
{
	for (FAnimation& frame : frames)
		SAFE_DELETE(frame.Image);
}

void Animation::Initialize(vector<FAnimation> animations)
{
	frames = animations;
}

void Animation::Play(UINT frame)
{
	bPlaying = true;

	playFrameIndex = frame;
	playTime = Time->Running();
}

void Animation::Pause()
{
	bPlaying = false;
}

void Animation::Stop()
{
	bPlaying = false;
	playFrameIndex = 0;
}

void Animation::Update()
{
	FAnimation& frame = frames[playFrameIndex];

	if (Time->Running() - playTime >= frame.Time)
	{
		playFrameIndex++;

		if (playFrameIndex >= frames.size())
			playFrameIndex = 0;

		playTime = Time->Running();
	}

	frames[playFrameIndex].Image->Update();
}

void Animation::Render()
{
	frames[playFrameIndex].Image->Render();
}

void Animation::Position(float x, float y)
{
	Position(Vector2(x, y));
}

void Animation::Position(D3DXVECTOR2 vec)
{
	position = vec;

	for (FAnimation& frame : frames)
		frame.Image->Position(vec);
}

void Animation::Position(D3DXVECTOR2 * vec)
{
	*vec = position;
}

void Animation::Scale(float x, float y)
{
	Scale(Vector2(x, y));
}

void Animation::Scale(D3DXVECTOR2 vec)
{
	scale = vec;

	for (FAnimation& frame : frames)
		frame.Image->Scale(vec);
}

void Animation::Color(float r, float g, float b, float a)
{
	Color(Color4(r, g, b, a));
}

void Animation::Color(D3DXCOLOR color)
{
	this->color = color;

	for (FAnimation& frame : frames)
		frame.Image->Color(color);
}

main.cpp

#include "stdafx.h"

Animation* animation;
Sprite* sprite;
void InitScene()
{
	animation = new Animation();

	vector<FAnimation> frame(3);
	frame[0] = FAnimation(new Sprite(L"MetalSlug/Idle_1.png"), 0.1f);
	frame[1] = FAnimation(new Sprite(L"MetalSlug/Idle_2.png"), 0.1f);
	frame[2] = FAnimation(new Sprite(L"MetalSlug/Idle_3.png"), 0.1f);
	animation->Initialize(frame);

	animation->Position(500, 500);
	animation->Scale(100, 100);
	animation->Play();
}

void DestroyScene()
{
	SAFE_DELETE(animation);
}

void Update()
{
	animation->Update();
}

void Render()
{	
	animation->Render();
}

 

출력된 결과 애니메이션
animation 필기

 


 

 

_CPP/main.cpp  overflow가 어떻게 나는가?

#include <stdio.h>

void Test()
{
	static int a = 0;
	a++;

	printf("a = %d\n", a);

}

struct A
{
	float m[4][4];
};

void main()
{
	for (int i = 0; i < 5; i++)
		Test();

	//A matrix[1000][1000]; //Stack Overflow
}

/////
//정적이라는 의미 고정시킨다는 의미 static 
/////
////스택프레임 1mega  
//델리게이션
//팩토리 
//싱글톤
///////////////////

 

완전2진트리 

 

 

 

 

 

 

Class A
{
	static void B()
    {
    	a
        b //((X)접근불가)
    }
    void D()
    {
    	b //자기멤버 b 
        a //접근가능
    }
    /////////
//-사실 이렇게 쓰면 안된다 static은 외부에서 선언 아래 코드와 같다 예시로 보는것 
	static int a = 20;
    int b = 30;
}

1) static은 처음부터 만들어지기 때문에 static함수에서는 static 자기변수에 접근이 가능하다

그러나 일반 변수는 구역할당이 안되면 못만든다.(접근불가)

 

2) D에서는 멤버 함수 만들어진 시점에서 멤버 변수랑 같을테니까(같은구역) 

a의 static 변수는 이미 공통영역에서 먼저 선언 되어서 만들어졌으니까. 접근가능하다. 

 

* 멤버함수에서는 멤버변수 / static 변수 접근이 가능하다.

* static 함수는 자기 static변수만 접근가능하다. 

 

 

Static

Singleton / main.cpp 

#include <stdio.h>

class Singleton
{
public:
	static void Create() //이런식으로 생성시점을 정해준다. 
	{
		instance = new Singleton(); //Instance에 대한 생성시점 
	}

	static void Delete() //소멸 시점 
	{
		delete instance;
	}

public:
	static Singleton* Get()
	{
		//if (instance == NULL)
			//instance = new Singleton(); //1) 할당 위에 처음에 한번은 NULL이니까 

		return instance; //생성하고 리턴
	}//두번째 Get을 할때는 pass하고 만들어진것을 리턴한다. 
	//무조건 객체 하나만 유지 시킴
	//편하다고 남용하면 이 Get을 어디서 값이 바뀌었는지 찾기 힘들어짐 
	//그래서 생성시점을 결정하기 어렵다. 
private:
	static Singleton* instance; //클래스 외부에서 초기화 해줘야함 
	// Singleton * Instance 싱글톤 자료형에 대한 객체이니까

private: //이 안에 있는 멤버를 사용할 수 있게 될 것이다.  
	Singleton() //생성자
	{

	}

	~Singleton() //소멸자
	{

	}

public:
	int Add() { return ++val; }

private:
	int val = 0;
};

Singleton* Singleton::instance = NULL; //Get 할때 초기화 

void main() //접근할때 
{
	//Singleton::Get();
	Singleton::Create(); //생성시점을 정해준 후 Create로 어디선가 필요한 곳에 미리 만들어 놓고 
	
	printf("val = %d\n", Singleton::Get()->Add()); //이렇게 하면 value가 더해지면서 출력됨 
	printf("val = %d\n", Singleton::Get()->Add());
	printf("val = %d\n", Singleton::Get()->Add());

	Singleton::Delete(); //생성시점, 다 쓴다음 반드시 delete로 제거 

}

결과 값 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


각주)

 

 

 

 

 

728x90
728x90
LIST
profile

Adventure of 빠타박스

@PPATABOX

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!