Adding walking animation, fixing minor bugs
This commit is contained in:
parent
d84e7904e6
commit
15697ebe67
@ -527,12 +527,13 @@ namespace ZL
|
|||||||
|
|
||||||
if (abs(finalPos.v[0] - originalPos.v[0]) > 1 || abs(finalPos.v[1] - originalPos.v[1]) > 1 || abs(finalPos.v[2] - originalPos.v[2]) > 1)
|
if (abs(finalPos.v[0] - originalPos.v[0]) > 1 || abs(finalPos.v[1] - originalPos.v[1]) > 1 || abs(finalPos.v[2] - originalPos.v[2]) > 1)
|
||||||
{
|
{
|
||||||
std::cout << "Hello!" << std::endl;
|
//std::cout << "Hello!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vMoved)
|
if (!vMoved)
|
||||||
{
|
{
|
||||||
std::cout << "Hello!" << std::endl;
|
//std::cout << "Hello!" << std::endl;
|
||||||
|
finalPos = originalPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.PositionData[i].v[0] = finalPos.v[0];
|
mesh.PositionData[i].v[0] = finalPos.v[0];
|
||||||
|
|||||||
@ -17,5 +17,11 @@ Vector3f Environment::characterPos = {0, 0, 0};
|
|||||||
|
|
||||||
|
|
||||||
float Environment::violaCurrentIdleFrame = 0.f;
|
float Environment::violaCurrentIdleFrame = 0.f;
|
||||||
|
int Environment::violaLastIdleFrame = -1;
|
||||||
|
float Environment::violaCurrentWalkFrame = 0.f;
|
||||||
|
int Environment::violaLastWalkFrame = 0;
|
||||||
|
|
||||||
|
int Environment::violaCurrentAnimation = 0;
|
||||||
|
float Environment::violaAngleAroundY = 0.f;
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
@ -18,7 +18,18 @@ public:
|
|||||||
static Vector3f cameraShift;
|
static Vector3f cameraShift;
|
||||||
static Vector3f characterPos;
|
static Vector3f characterPos;
|
||||||
|
|
||||||
|
//Viola
|
||||||
static float violaCurrentIdleFrame;
|
static float violaCurrentIdleFrame;
|
||||||
|
static float violaCurrentWalkFrame;
|
||||||
|
|
||||||
|
static int violaLastIdleFrame;
|
||||||
|
static int violaLastWalkFrame;
|
||||||
|
|
||||||
|
static int violaCurrentAnimation;
|
||||||
|
|
||||||
|
static float violaAngleAroundY;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
@ -49,9 +49,10 @@ void GameObjectManager::initialize() {
|
|||||||
|
|
||||||
// Load bone animations
|
// Load bone animations
|
||||||
//bx.LoadFromFile("./violetta001.txt");
|
//bx.LoadFromFile("./violetta001.txt");
|
||||||
bx.LoadFromFile("./idleviola001.txt");
|
violaIdleModel.LoadFromFile("./idleviola001.txt");
|
||||||
|
violaWalkModel.LoadFromFile("./walkviolla001.txt");
|
||||||
// Create active object
|
// Create active object
|
||||||
|
|
||||||
ActiveObject ao1;
|
ActiveObject ao1;
|
||||||
ao1.name = "book";
|
ao1.name = "book";
|
||||||
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
|
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
|
||||||
@ -65,9 +66,29 @@ void GameObjectManager::initialize() {
|
|||||||
ao1.activeObjectScreenMeshMutable.AssignFrom(ao1.activeObjectScreenMesh);
|
ao1.activeObjectScreenMeshMutable.AssignFrom(ao1.activeObjectScreenMesh);
|
||||||
ao1.activeObjectScreenMeshMutable.RefreshVBO();
|
ao1.activeObjectScreenMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
|
/*
|
||||||
|
ActiveObject ao2;
|
||||||
|
ao2.name = "superchair001";
|
||||||
|
ao2.activeObjectMesh = ZL::LoadFromTextFile("./superchair001.txt"); // Add ZL:: namespace
|
||||||
|
ao2.activeObjectMesh.Scale(400);
|
||||||
|
ao2.activeObjectMesh.SwapZandY();
|
||||||
|
ao2.activeObjectMeshMutable.AssignFrom(ao2.activeObjectMesh);
|
||||||
|
ao2.activeObjectMeshMutable.RefreshVBO();
|
||||||
|
ao2.objectPos = Vector3f{ 0, 0, 0 };
|
||||||
|
ao2.activeObjectTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./chair_01_Base_Color.bmp"));
|
||||||
|
|
||||||
|
ao2.activeObjectScreenTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./aoscreen01.bmp"));
|
||||||
|
ao2.activeObjectScreenMesh = CreateRect2D({ 0.f, 0.f }, { 64.f, 64.f }, 0.5);
|
||||||
|
ao2.activeObjectScreenMeshMutable.AssignFrom(ao2.activeObjectScreenMesh);
|
||||||
|
ao2.activeObjectScreenMeshMutable.RefreshVBO();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Room room_1;
|
Room room_1;
|
||||||
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||||
room_1.objects.push_back(ao1);
|
room_1.objects.push_back(ao1);
|
||||||
|
//room_1.objects.push_back(ao2);
|
||||||
room_1.sound_name = "file_example_OOG_5MG.ogg";
|
room_1.sound_name = "file_example_OOG_5MG.ogg";
|
||||||
rooms.push_back(room_1);
|
rooms.push_back(room_1);
|
||||||
|
|
||||||
@ -154,6 +175,11 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
if (audioPlayer) {
|
if (audioPlayer) {
|
||||||
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
||||||
}
|
}
|
||||||
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 1;
|
||||||
|
Environment::violaLastWalkFrame = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
@ -161,6 +187,11 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
if (audioPlayer) {
|
if (audioPlayer) {
|
||||||
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
||||||
}
|
}
|
||||||
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 1;
|
||||||
|
Environment::violaLastWalkFrame = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
case SDLK_w:
|
case SDLK_w:
|
||||||
@ -168,6 +199,11 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
if (audioPlayer) {
|
if (audioPlayer) {
|
||||||
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
||||||
}
|
}
|
||||||
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 1;
|
||||||
|
Environment::violaLastWalkFrame = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
case SDLK_s:
|
case SDLK_s:
|
||||||
@ -175,6 +211,11 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
if (audioPlayer) {
|
if (audioPlayer) {
|
||||||
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
audioPlayer->playSound("Звук-Идут-по-земле.ogg");
|
||||||
}
|
}
|
||||||
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 1;
|
||||||
|
Environment::violaLastWalkFrame = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
// ...handle other keys...
|
// ...handle other keys...
|
||||||
}
|
}
|
||||||
@ -184,18 +225,50 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
case SDLK_a:
|
case SDLK_a:
|
||||||
Environment::leftPressed = false;
|
Environment::leftPressed = false;
|
||||||
|
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false)
|
||||||
|
{
|
||||||
|
if (Environment::violaCurrentAnimation == 1)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 0;
|
||||||
|
Environment::violaCurrentIdleFrame = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
Environment::rightPressed = false;
|
Environment::rightPressed = false;
|
||||||
|
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false)
|
||||||
|
{
|
||||||
|
if (Environment::violaCurrentAnimation == 1)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 0;
|
||||||
|
Environment::violaCurrentIdleFrame = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
case SDLK_w:
|
case SDLK_w:
|
||||||
Environment::upPressed = false;
|
Environment::upPressed = false;
|
||||||
|
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false)
|
||||||
|
{
|
||||||
|
if (Environment::violaCurrentAnimation == 1)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 0;
|
||||||
|
Environment::violaCurrentIdleFrame = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
case SDLK_s:
|
case SDLK_s:
|
||||||
Environment::downPressed = false;
|
Environment::downPressed = false;
|
||||||
|
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false)
|
||||||
|
{
|
||||||
|
if (Environment::violaCurrentAnimation == 1)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentAnimation = 0;
|
||||||
|
Environment::violaCurrentIdleFrame = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,14 +309,37 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment::violaCurrentIdleFrame += ms / 24.f;
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
|
|
||||||
while (Environment::violaCurrentIdleFrame > 40)
|
|
||||||
{
|
{
|
||||||
Environment::violaCurrentIdleFrame -= 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
bx.Interpolate(int(Environment::violaCurrentIdleFrame));
|
Environment::violaCurrentIdleFrame += ms / 24.f;
|
||||||
|
|
||||||
|
while (Environment::violaCurrentIdleFrame >= 40)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentIdleFrame -= 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (int(Environment::violaCurrentIdleFrame) != Environment::violaLastIdleFrame)
|
||||||
|
{
|
||||||
|
violaIdleModel.Interpolate(int(Environment::violaCurrentIdleFrame));
|
||||||
|
Environment::violaLastIdleFrame = int(Environment::violaCurrentIdleFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Environment::violaCurrentAnimation == 1)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentWalkFrame += ms / 24.f;
|
||||||
|
|
||||||
|
while (Environment::violaCurrentWalkFrame >= 30)
|
||||||
|
{
|
||||||
|
Environment::violaCurrentWalkFrame -= 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (int(Environment::violaCurrentWalkFrame) != Environment::violaLastWalkFrame)
|
||||||
|
{
|
||||||
|
violaWalkModel.Interpolate(int(Environment::violaCurrentWalkFrame));
|
||||||
|
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,8 +33,11 @@ public:
|
|||||||
ZL::VertexDataStruct testObjMesh;
|
ZL::VertexDataStruct testObjMesh;
|
||||||
ZL::VertexRenderStruct testObjMeshMutable;
|
ZL::VertexRenderStruct testObjMeshMutable;
|
||||||
|
|
||||||
ZL::BoneSystem bx;
|
ZL::BoneSystem violaIdleModel;
|
||||||
ZL::VertexRenderStruct bxMutable;
|
ZL::VertexRenderStruct violaIdleModelMutable;
|
||||||
|
|
||||||
|
ZL::BoneSystem violaWalkModel;
|
||||||
|
ZL::VertexRenderStruct violaWalkModelMutable;
|
||||||
|
|
||||||
ZL::VertexDataStruct textMesh;
|
ZL::VertexDataStruct textMesh;
|
||||||
ZL::VertexRenderStruct textMeshMutable;
|
ZL::VertexRenderStruct textMeshMutable;
|
||||||
|
|||||||
@ -67,14 +67,20 @@ void RenderSystem::drawViola(GameObjectManager& gameObjects)
|
|||||||
renderer.ScaleMatrix(10);
|
renderer.ScaleMatrix(10);
|
||||||
|
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
||||||
//float t = 0.3;
|
|
||||||
|
|
||||||
//renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
|
||||||
|
|
||||||
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
gameObjects.bxMutable.AssignFrom(gameObjects.bx.mesh);
|
{
|
||||||
gameObjects.bxMutable.RefreshVBO();
|
gameObjects.violaIdleModelMutable.AssignFrom(gameObjects.violaIdleModel.mesh);
|
||||||
renderer.DrawVertexRenderStruct(gameObjects.bxMutable);
|
gameObjects.violaIdleModelMutable.RefreshVBO();
|
||||||
|
renderer.DrawVertexRenderStruct(gameObjects.violaIdleModelMutable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameObjects.violaWalkModelMutable.AssignFrom(gameObjects.violaWalkModel.mesh);
|
||||||
|
gameObjects.violaWalkModelMutable.RefreshVBO();
|
||||||
|
renderer.DrawVertexRenderStruct(gameObjects.violaWalkModelMutable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|||||||
18795
walkviolla001.txt
Normal file
18795
walkviolla001.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user