응애맘마조
걷기 모션 본문
사람 모형을 만들어서 걷는 모션을 만드는 것이 과제였습니다. 저는 구르기가 되었습니다.
//Cubeman.h
pragma once
class Cubeman : public Actor
{
public:
static Cubeman* Create(string name = "Cubeman");
bool rotationturn;
bool rotationturn2;
bool rotationturn3;
bool rotationturn4;
private:
Cubeman();
virtual ~Cubeman();
public:
void Update() override;
void Release() override;
};
//Cubeman.cpp
#include "stdafx.h"
#include "Cubeman.h"
Cubeman* Cubeman::Create(string name)
{
Cubeman* cubeman = new Cubeman();
cubeman->mesh = make_shared<Mesh>();
cubeman->mesh->LoadFile("1.Cube.mesh");
cubeman->name = name;
cubeman->SetWorldPos(Vector3(0, 0, 0));
cubeman->Actor::Update();
cubeman->AddChild(Camera::main);
Camera::main->SetLocalPos(Vector3(0, 10, -40));
{
GameObject* temp = GameObject::Create("Body");
temp->mesh = make_shared<Mesh>();
temp->mesh->LoadFile("1.Cube.mesh");
temp->SetLocalPos(Vector3(0, 0, 0));
temp->scale = Vector3(1, 2, 1);
GameObject* temp2 = GameObject::Create("BodyRender");
cubeman->AddChild(temp2);
temp2->AddChild(temp);
GameObject* temp3 = GameObject::Create("Head");
temp3->mesh = make_shared<Mesh>();
temp3->mesh->LoadFile("1.Cube.mesh");
temp3->SetLocalPos(Vector3(0, 2, 0));
temp3->scale = Vector3(0.5, 1, 1);
GameObject* temp4 = GameObject::Create("HeadRender");
cubeman->AddChild(temp4);
temp4->AddChild(temp3);
}
{
GameObject* temp = GameObject::Create("LeftArm");
temp->mesh = make_shared<Mesh>();
temp->mesh->LoadFile("1.Cube.mesh");
temp->SetLocalPos(Vector3(-1.5, 0, 0));
temp->scale = Vector3(0.3, 1.5, 1);
GameObject* temp2 = GameObject::Create("LeftArmRender");
cubeman->AddChild(temp2);
temp2->AddChild(temp);
GameObject* temp3 = GameObject::Create("RightArm");
temp3->mesh = make_shared<Mesh>();
temp3->mesh->LoadFile("1.Cube.mesh");
temp3->SetLocalPos(Vector3(1.5, 0, 0));
temp3->scale = Vector3(0.3, 1.5, 1);
GameObject* temp4 = GameObject::Create("RightArmRender");
cubeman->AddChild(temp4);
temp4->AddChild(temp3);
}
{
GameObject* temp = GameObject::Create("LeftLeg");
temp->mesh = make_shared<Mesh>();
temp->mesh->LoadFile("1.Cube.mesh");
temp->SetLocalPos(Vector3(-0.5, -3, 0));
temp->scale = Vector3(0.3, 1.5, 1);
GameObject* temp2 = GameObject::Create("LeftLegRender");
cubeman->AddChild(temp2);
temp2->AddChild(temp);
GameObject* temp3 = GameObject::Create("RightLeg");
temp3->mesh = make_shared<Mesh>();
temp3->mesh->LoadFile("1.Cube.mesh");
temp3->SetLocalPos(Vector3(0.5, -3, 0));
temp3->scale = Vector3(0.3, 1.5, 1);
GameObject* temp4 = GameObject::Create("RightLegRender");
cubeman->AddChild(temp4);
temp4->AddChild(temp3);
}
return cubeman;
}
Cubeman::Cubeman()
{
}
Cubeman::~Cubeman()
{
}
void Cubeman::Update()
{
if (INPUT->KeyPress(VK_UP))
{
MoveWorldPos(GetForward() * 3 * DELTA);
if (GameObject* p = Find("HeadRender"))
{
p->rotation.x += 8 * DELTA;
}
if (GameObject* p = Find("BodyRender"))
{
p->rotation.x += 8 * DELTA;
}
if (GameObject* p = Find("LeftArmRender"))
{
p->rotation.x += 8 * DELTA;
}
if (GameObject* p = Find("RightArmRender"))
{
p->rotation.x += 8 * DELTA;
}
if (GameObject* p = Find("LeftLegRender"))
{
p->rotation.x += 8 * DELTA;
}
if (GameObject* p = Find("RightLegRender"))
{
p->rotation.x += 8 * DELTA;
}
}
if (INPUT->KeyPress(VK_DOWN))
{
MoveWorldPos(GetForward() * -3 * DELTA);
if (GameObject* p = Find("HeadRender"))
{
p->rotation.x -= 8 * DELTA;
}
if (GameObject* p = Find("BodyRender"))
{
p->rotation.x -= 8 * DELTA;
}
if (GameObject* p = Find("LeftArmRender"))
{
p->rotation.x -= 8 * DELTA;
}
if (GameObject* p = Find("RightArmRender"))
{
p->rotation.x -= 8 * DELTA;
}
if (GameObject* p = Find("LeftLegRender"))
{
p->rotation.x -= 8 * DELTA;
}
if (GameObject* p = Find("RightLegRender"))
{
p->rotation.x -= 8 * DELTA;
}
}
if (INPUT->KeyPress(VK_LEFT))
{
MoveWorldPos(-GetRight() * 3 * DELTA);
if (GameObject* p = Find("HeadRender"))
{
p->rotation.y -= 8 * DELTA;
}
if (GameObject* p = Find("BodyRender"))
{
p->rotation.y -= 8 * DELTA;
}
if (GameObject* p = Find("LeftArmRender"))
{
p->rotation.y -= 8 * DELTA;
}
if (GameObject* p = Find("RightArmRender"))
{
p->rotation.y -= 8 * DELTA;
}
if (GameObject* p = Find("LeftLegRender"))
{
p->rotation.y -= 8 * DELTA;
}
if (GameObject* p = Find("RightLegRender"))
{
p->rotation.y -= 8 * DELTA;
}
}
if (INPUT->KeyPress(VK_RIGHT))
{
MoveWorldPos(GetRight() * 3 * DELTA);
if (GameObject* p = Find("HeadRender"))
{
p->rotation.y += 8 * DELTA;
}
if (GameObject* p = Find("BodyRender"))
{
p->rotation.y += 8 * DELTA;
}
if (GameObject* p = Find("LeftArmRender"))
{
p->rotation.y += 8 * DELTA;
}
if (GameObject* p = Find("RightArmRender"))
{
p->rotation.y += 8 * DELTA;
}
if (GameObject* p = Find("LeftLegRender"))
{
p->rotation.y += 8 * DELTA;
}
if (GameObject* p = Find("RightLegRender"))
{
p->rotation.y += 8 * DELTA;
}
}
if (INPUT->KeyDown('1'))
{
Camera::main->SetLocalPos(Vector3(-25, 7, 0));
Camera::main->rotation.y = 1.5;
}
if (INPUT->KeyDown('2'))
{
Camera::main->SetLocalPos(Vector3(25, 7, 0));
Camera::main->rotation.y = -1.5;
}
if (INPUT->KeyDown('3'))
{
Camera::main->SetLocalPos(Vector3(0, 30, 0));
Camera::main->rotation.x = 1.5;
}
if (INPUT->KeyDown('4'))
{
Camera::main->SetLocalPos(Vector3(0, -30, 0));
Camera::main->rotation.x = -1.5;
}
Actor::Update();
}
void Cubeman::Release()
{
for (auto it = children.begin(); it != children.end(); it++)
{
SafeRelease(it->second);
}
delete this;
}
헤더 파일과 cpp 파일입니다.
실행 영상입니다.
읽어주셔서 감사합니다.