Finally animation
This commit is contained in:
parent
06cc639bb7
commit
064d446aea
@ -15,4 +15,7 @@ bool Environment::downPressed = false;
|
||||
Vector3f Environment::cameraShift = {0, 0, 0};
|
||||
Vector3f Environment::characterPos = {0, 0, 0};
|
||||
|
||||
|
||||
float Environment::violaCurrentIdleFrame = 0.f;
|
||||
|
||||
} // namespace ZL
|
||||
|
||||
@ -17,6 +17,8 @@ public:
|
||||
|
||||
static Vector3f cameraShift;
|
||||
static Vector3f characterPos;
|
||||
|
||||
static float violaCurrentIdleFrame;
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
|
||||
@ -47,7 +47,8 @@ void GameObjectManager::initialize() {
|
||||
|
||||
|
||||
// Load bone animations
|
||||
bx.LoadFromFile("mesh_armature_and_animation_data.txt");
|
||||
//bx.LoadFromFile("./violetta001.txt");
|
||||
bx.LoadFromFile("./idleviola001.txt");
|
||||
|
||||
// Create active object
|
||||
ActiveObject ao1;
|
||||
@ -102,8 +103,7 @@ void GameObjectManager::initialize() {
|
||||
|
||||
void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
bx.Interpolate(animationCounter);
|
||||
animationCounter += 2;
|
||||
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) {
|
||||
|
||||
@ -212,6 +212,16 @@ void GameObjectManager::updateScene(size_t ms) {
|
||||
ao.highlighted = (dist < 50.f);
|
||||
|
||||
}
|
||||
|
||||
Environment::violaCurrentIdleFrame += ms / 24.f;
|
||||
|
||||
while (Environment::violaCurrentIdleFrame > 40)
|
||||
{
|
||||
Environment::violaCurrentIdleFrame -= 40;
|
||||
}
|
||||
|
||||
bx.Interpolate(int(Environment::violaCurrentIdleFrame));
|
||||
|
||||
}
|
||||
|
||||
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
static const float INVENTORY_MARGIN;
|
||||
|
||||
private:
|
||||
int animationCounter = 0;
|
||||
//int animationCounter = 0;
|
||||
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
||||
int lastMouseY = 0;
|
||||
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
|
||||
|
||||
113
RenderSystem.cpp
113
RenderSystem.cpp
@ -4,6 +4,8 @@
|
||||
#include "Inventory.h"
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
||||
|
||||
namespace ZL {
|
||||
|
||||
void RenderSystem::initialize() {
|
||||
@ -12,7 +14,7 @@ void RenderSystem::initialize() {
|
||||
renderer.InitOpenGL();
|
||||
}
|
||||
|
||||
void RenderSystem::drawScene(const GameObjectManager& gameObjects) {
|
||||
void RenderSystem::drawScene(GameObjectManager& gameObjects) {
|
||||
static const std::string defaultShaderName = "default";
|
||||
static const std::string vPositionName = "vPosition";
|
||||
static const std::string vTexCoordName = "vTexCoord";
|
||||
@ -22,6 +24,90 @@ void RenderSystem::drawScene(const GameObjectManager& gameObjects) {
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glViewport(0, 0, Environment::width, Environment::height);
|
||||
/*
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
*/
|
||||
drawWorld(gameObjects);
|
||||
//drawUI(gameObjects);
|
||||
|
||||
/*renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
renderer.shaderManager.PopShader();*/
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
void RenderSystem::drawViola(GameObjectManager& gameObjects)
|
||||
{
|
||||
static const std::string defaultShaderName = "default";
|
||||
static const std::string colorShaderName = "defaultColor";
|
||||
|
||||
static const std::string vPositionName = "vPosition";
|
||||
static const std::string vTexCoordName = "vTexCoord";
|
||||
static const std::string vColorName = "vColor";
|
||||
static const std::string textureUniformName = "Texture";
|
||||
|
||||
renderer.shaderManager.PushShader(colorShaderName);
|
||||
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
50, 10000);
|
||||
renderer.PushMatrix();
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
||||
|
||||
float t = 0.3;
|
||||
renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
||||
renderer.ScaleMatrix(10);
|
||||
|
||||
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
||||
//float t = 0.3;
|
||||
|
||||
//renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
||||
|
||||
|
||||
gameObjects.bxMutable.AssignFrom(gameObjects.bx.mesh);
|
||||
gameObjects.bxMutable.RefreshVBO();
|
||||
renderer.DrawVertexRenderStruct(gameObjects.bxMutable);
|
||||
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.DisableVertexAttribArray(vPositionName);
|
||||
|
||||
renderer.shaderManager.PopShader();
|
||||
}
|
||||
|
||||
void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
||||
static const std::string defaultShaderName = "default";
|
||||
static const std::string colorShaderName = "defaultColor";
|
||||
|
||||
static const std::string vPositionName = "vPosition";
|
||||
static const std::string vTexCoordName = "vTexCoord";
|
||||
static const std::string vColorName = "vColor";
|
||||
static const std::string textureUniformName = "Texture";
|
||||
|
||||
/*
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// Draw cone
|
||||
//glBindTexture(GL_TEXTURE_2D, gameObjects.coneTexturePtr->getTexID());
|
||||
//renderer.DrawVertexRenderStruct(gameObjects.coneMeshMutable);
|
||||
|
||||
drawViola(gameObjects);
|
||||
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
@ -29,33 +115,18 @@ void RenderSystem::drawScene(const GameObjectManager& gameObjects) {
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
|
||||
drawWorld(gameObjects);
|
||||
drawUI(gameObjects);
|
||||
|
||||
renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
void RenderSystem::drawWorld(const GameObjectManager& gameObjects) {
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
50, 10000);
|
||||
renderer.PushMatrix();
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
||||
|
||||
|
||||
float t = 0.3;
|
||||
renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
||||
|
||||
|
||||
// Draw cone
|
||||
glBindTexture(GL_TEXTURE_2D, gameObjects.coneTexturePtr->getTexID());
|
||||
renderer.DrawVertexRenderStruct(gameObjects.coneMeshMutable);
|
||||
|
||||
renderer.TranslateMatrix(Environment::cameraShift);
|
||||
|
||||
// Draw active objects
|
||||
@ -80,6 +151,10 @@ void RenderSystem::drawWorld(const GameObjectManager& gameObjects) {
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
// Store matrix for UI rendering
|
||||
currentProjectionModelView = latestProjectionModelView;
|
||||
|
||||
@ -9,7 +9,7 @@ class RenderSystem {
|
||||
public:
|
||||
RenderSystem() = default;
|
||||
void initialize();
|
||||
void drawScene(const GameObjectManager& gameObjects);
|
||||
void drawScene(GameObjectManager& gameObjects);
|
||||
Renderer& getRenderer() { return renderer; }
|
||||
|
||||
void worldToScreenCoordinates(Vector3f objectPos,
|
||||
@ -18,8 +18,10 @@ public:
|
||||
int& screenX, int& screenY);
|
||||
|
||||
private:
|
||||
void drawWorld(const GameObjectManager& gameObjects);
|
||||
void drawWorld(GameObjectManager& gameObjects);
|
||||
void drawUI(const GameObjectManager& gameObjects);
|
||||
|
||||
void drawViola(GameObjectManager& gameObjects);
|
||||
|
||||
Renderer renderer;
|
||||
ShaderManager shaderManager;
|
||||
|
||||
17612
idleviola002.txt
Normal file
17612
idleviola002.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user