Merge branch 'salmon' of github.com:mephi1984/ZeptoLabTest1 into pavel
This commit is contained in:
commit
d79a684868
@ -1,5 +1,10 @@
|
|||||||
#include "Environment.h"
|
#include "Environment.h"
|
||||||
|
|
||||||
|
#include "RenderSystem.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "Inventory.h"
|
||||||
|
#include <GL/gl.h>
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
int Environment::windowHeaderHeight = 0;
|
int Environment::windowHeaderHeight = 0;
|
||||||
@ -15,6 +20,8 @@ bool Environment::downPressed = false;
|
|||||||
Vector3f Environment::cameraShift = {0, 0, 0};
|
Vector3f Environment::cameraShift = {0, 0, 0};
|
||||||
Vector3f Environment::characterPos = {0, 0, 0};
|
Vector3f Environment::characterPos = {0, 0, 0};
|
||||||
|
|
||||||
|
float Environment::cameraPhi = 0.f;
|
||||||
|
float Environment::cameraAlpha = 0.3*M_PI / 2.0;
|
||||||
|
|
||||||
float Environment::violaCurrentIdleFrame = 0.f;
|
float Environment::violaCurrentIdleFrame = 0.f;
|
||||||
int Environment::violaLastIdleFrame = -1;
|
int Environment::violaLastIdleFrame = -1;
|
||||||
@ -24,4 +31,13 @@ int Environment::violaLastWalkFrame = 0;
|
|||||||
int Environment::violaCurrentAnimation = 0;
|
int Environment::violaCurrentAnimation = 0;
|
||||||
float Environment::violaAngleAroundY = 0.f;
|
float Environment::violaAngleAroundY = 0.f;
|
||||||
|
|
||||||
|
bool Environment::settings_inverseVertical = true;
|
||||||
|
|
||||||
|
SDL_Window* Environment::window = nullptr;
|
||||||
|
|
||||||
|
float Environment::cameraDefaultVerticalShift = -150.f;
|
||||||
|
bool Environment::showMouse = false;
|
||||||
|
|
||||||
|
bool Environment::exitGameLoop = false;
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#endif
|
||||||
|
#include "OpenGlExtensions.h"
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
@ -17,6 +21,8 @@ public:
|
|||||||
|
|
||||||
static Vector3f cameraShift;
|
static Vector3f cameraShift;
|
||||||
static Vector3f characterPos;
|
static Vector3f characterPos;
|
||||||
|
static float cameraPhi;
|
||||||
|
static float cameraAlpha;
|
||||||
|
|
||||||
//Viola
|
//Viola
|
||||||
static float violaCurrentIdleFrame;
|
static float violaCurrentIdleFrame;
|
||||||
@ -29,6 +35,15 @@ public:
|
|||||||
|
|
||||||
static float violaAngleAroundY;
|
static float violaAngleAroundY;
|
||||||
|
|
||||||
|
static bool settings_inverseVertical;
|
||||||
|
|
||||||
|
static SDL_Window* window;
|
||||||
|
|
||||||
|
static float cameraDefaultVerticalShift;
|
||||||
|
|
||||||
|
static bool showMouse;
|
||||||
|
static bool exitGameLoop;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
5
Game.cpp
5
Game.cpp
@ -12,7 +12,6 @@ namespace ZL
|
|||||||
Game::Game()
|
Game::Game()
|
||||||
: window(nullptr)
|
: window(nullptr)
|
||||||
, glContext(nullptr)
|
, glContext(nullptr)
|
||||||
, exitGameLoop(false)
|
|
||||||
, newTickCount(0)
|
, newTickCount(0)
|
||||||
, lastTickCount(0)
|
, lastTickCount(0)
|
||||||
, renderer(renderSystem.getRenderer()) // Инициализация ссылки на renderer
|
, renderer(renderSystem.getRenderer()) // Инициализация ссылки на renderer
|
||||||
@ -41,6 +40,8 @@ void Game::setup() {
|
|||||||
|
|
||||||
window = SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
window = SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
Environment::width, Environment::height, SDL_WINDOW_OPENGL);
|
Environment::width, Environment::height, SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
|
Environment::window = window;
|
||||||
|
|
||||||
glContext = SDL_GL_CreateContext(window);
|
glContext = SDL_GL_CreateContext(window);
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ void Game::update() {
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
exitGameLoop = true;
|
Environment::exitGameLoop = true;
|
||||||
}
|
}
|
||||||
gameObjects.handleEvent(event);
|
gameObjects.handleEvent(event);
|
||||||
|
|
||||||
|
|||||||
3
Game.h
3
Game.h
@ -17,7 +17,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
bool shouldExit() const { return exitGameLoop; }
|
bool shouldExit() const { return Environment::exitGameLoop; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processTickCount();
|
void processTickCount();
|
||||||
@ -29,7 +29,6 @@ private:
|
|||||||
GameObjectManager gameObjects;
|
GameObjectManager gameObjects;
|
||||||
Renderer& renderer; // Ссылка на renderer из RenderSystem
|
Renderer& renderer; // Ссылка на renderer из RenderSystem
|
||||||
|
|
||||||
bool exitGameLoop;
|
|
||||||
size_t newTickCount;
|
size_t newTickCount;
|
||||||
size_t lastTickCount;
|
size_t lastTickCount;
|
||||||
|
|
||||||
|
|||||||
@ -107,6 +107,9 @@ void GameObjectManager::initialize() {
|
|||||||
inventoryIconMeshMutable.RefreshVBO();
|
inventoryIconMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||||
|
|
||||||
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameObjectManager::switch_room(int index){
|
void GameObjectManager::switch_room(int index){
|
||||||
@ -164,6 +167,25 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
else if (event.type == SDL_KEYDOWN) {
|
else if (event.type == SDL_KEYDOWN) {
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
|
case SDLK_SPACE:
|
||||||
|
Environment::showMouse = !Environment::showMouse;
|
||||||
|
|
||||||
|
if (Environment::showMouse)
|
||||||
|
{
|
||||||
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
|
lastMouseX = 0;
|
||||||
|
lastMouseY = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
case SDLK_q:
|
||||||
|
Environment::exitGameLoop = true;
|
||||||
|
break;
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
case SDLK_a:
|
case SDLK_a:
|
||||||
Environment::leftPressed = true;
|
Environment::leftPressed = true;
|
||||||
@ -268,15 +290,60 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEMOTION) {
|
if (event.type == SDL_MOUSEMOTION) {
|
||||||
// Сохраняем позицию мыши для последующей проверки
|
|
||||||
lastMouseX = event.motion.x;
|
if (Environment::showMouse == false)
|
||||||
lastMouseY = event.motion.y;
|
{
|
||||||
|
int mouseX, mouseY;
|
||||||
|
SDL_GetRelativeMouseState(&mouseX, &mouseY);
|
||||||
|
|
||||||
|
float diffX = 0.01f * mouseX;
|
||||||
|
|
||||||
|
float diffY = 0.01f * mouseY;
|
||||||
|
|
||||||
|
Environment::cameraPhi += diffX;
|
||||||
|
|
||||||
|
if (Environment::settings_inverseVertical)
|
||||||
|
{
|
||||||
|
Environment::cameraAlpha -= diffY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Environment::cameraAlpha += diffY;
|
||||||
|
}
|
||||||
|
if (Environment::cameraAlpha < 0.1 * M_PI / 2.0)
|
||||||
|
{
|
||||||
|
Environment::cameraAlpha = 0.1 * M_PI / 2.0;
|
||||||
|
}
|
||||||
|
else if (Environment::cameraAlpha > 0.9 * M_PI / 2.0)
|
||||||
|
{
|
||||||
|
Environment::cameraAlpha = 0.9 * M_PI / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastMouseX = event.motion.x;
|
||||||
|
lastMouseY = event.motion.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GameObjectManager::updateScene(size_t ms) {
|
void GameObjectManager::updateScene(size_t ms) {
|
||||||
const float SPEED = 0.1f;
|
const float SPEED = 0.1f;
|
||||||
|
|
||||||
|
Vector2f directionVector = { 0.f, SPEED }; //x and z
|
||||||
|
|
||||||
|
// Вычисляем новые координаты вектора
|
||||||
|
float x_new = directionVector.v[0] * cos(Environment::cameraPhi) - directionVector.v[1] * sin(Environment::cameraPhi);
|
||||||
|
float y_new = directionVector.v[0] * sin(Environment::cameraPhi) + directionVector.v[1] * cos(Environment::cameraPhi);
|
||||||
|
|
||||||
|
// Обновляем вектор
|
||||||
|
directionVector.v[0] = x_new;
|
||||||
|
directionVector.v[1] = y_new;
|
||||||
|
|
||||||
|
//Only forward is allowed
|
||||||
|
/*
|
||||||
if (Environment::leftPressed) {
|
if (Environment::leftPressed) {
|
||||||
Environment::cameraShift.v[0] += SPEED * ms;
|
Environment::cameraShift.v[0] += SPEED * ms;
|
||||||
}
|
}
|
||||||
@ -288,6 +355,11 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
}
|
}
|
||||||
if (Environment::downPressed) {
|
if (Environment::downPressed) {
|
||||||
Environment::cameraShift.v[2] -= SPEED * ms;
|
Environment::cameraShift.v[2] -= SPEED * ms;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (Environment::upPressed) {
|
||||||
|
Environment::cameraShift.v[0] += directionVector.v[0] * ms;
|
||||||
|
Environment::cameraShift.v[2] += directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment::characterPos.v[0] = -Environment::cameraShift.v[0];
|
Environment::characterPos.v[0] = -Environment::cameraShift.v[0];
|
||||||
@ -339,7 +411,6 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
|
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
|
||||||
|
|||||||
@ -62,13 +62,20 @@ void RenderSystem::drawViola(GameObjectManager& gameObjects)
|
|||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
||||||
|
|
||||||
float t = 0.3;
|
renderer.RotateMatrix(QuatFromRotateAroundX(Environment::cameraAlpha));
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
//renderer.RotateMatrix(QuatFromRotateAroundY(Environment::cameraPhi));
|
||||||
renderer.ScaleMatrix(10);
|
|
||||||
|
|
||||||
|
//Go a little bit up to make camera at the position of Viola
|
||||||
|
renderer.TranslateMatrix({ 0, Environment::cameraDefaultVerticalShift, 0 });
|
||||||
|
|
||||||
|
|
||||||
|
//Viola stuff
|
||||||
|
renderer.ScaleMatrix(10);
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (Environment::violaCurrentAnimation == 0)
|
if (Environment::violaCurrentAnimation == 0)
|
||||||
{
|
{
|
||||||
gameObjects.violaIdleModelMutable.AssignFrom(gameObjects.violaIdleModel.mesh);
|
gameObjects.violaIdleModelMutable.AssignFrom(gameObjects.violaIdleModel.mesh);
|
||||||
@ -130,11 +137,14 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
|||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
renderer.TranslateMatrix({ 0,0, -100 * Environment::zoom });
|
||||||
|
|
||||||
float t = 0.3;
|
renderer.RotateMatrix(QuatFromRotateAroundX(Environment::cameraAlpha));
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
renderer.RotateMatrix(QuatFromRotateAroundY(Environment::cameraPhi));
|
||||||
|
|
||||||
renderer.TranslateMatrix(Environment::cameraShift);
|
renderer.TranslateMatrix(Environment::cameraShift);
|
||||||
|
|
||||||
|
//Go a little bit up to make camera at the position of Viola
|
||||||
|
renderer.TranslateMatrix({ 0, Environment::cameraDefaultVerticalShift, 0 });
|
||||||
|
|
||||||
// Draw active objects
|
// Draw active objects
|
||||||
for (const auto& ao : gameObjects.activeObjects) {
|
for (const auto& ao : gameObjects.activeObjects) {
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
|
|||||||
@ -117,6 +117,7 @@
|
|||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>C:\Work\SDL2-2.28.3\include;C:\Work\Projects\lpng1645\build\install\include;C:\Work\OpenAL 1.1 SDK\include;C:\Work\Projects\libogg\include;C:\Work\Projects\vorbis\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\Work\SDL2-2.28.3\include;C:\Work\Projects\lpng1645\build\install\include;C:\Work\OpenAL 1.1 SDK\include;C:\Work\Projects\libogg\include;C:\Work\Projects\vorbis\include</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -158,6 +159,7 @@
|
|||||||
<ClCompile Include="ObjLoader.cpp" />
|
<ClCompile Include="ObjLoader.cpp" />
|
||||||
<ClCompile Include="OpenGlExtensions.cpp" />
|
<ClCompile Include="OpenGlExtensions.cpp" />
|
||||||
<ClCompile Include="Physics.cpp" />
|
<ClCompile Include="Physics.cpp" />
|
||||||
|
<ClCompile Include="QuestScripts.cpp" />
|
||||||
<ClCompile Include="Renderer.cpp" />
|
<ClCompile Include="Renderer.cpp" />
|
||||||
<ClCompile Include="RenderSystem.cpp" />
|
<ClCompile Include="RenderSystem.cpp" />
|
||||||
<ClCompile Include="ShaderManager.cpp" />
|
<ClCompile Include="ShaderManager.cpp" />
|
||||||
@ -180,6 +182,7 @@
|
|||||||
<ClInclude Include="ObjLoader.h" />
|
<ClInclude Include="ObjLoader.h" />
|
||||||
<ClInclude Include="OpenGlExtensions.h" />
|
<ClInclude Include="OpenGlExtensions.h" />
|
||||||
<ClInclude Include="Physics.h" />
|
<ClInclude Include="Physics.h" />
|
||||||
|
<ClInclude Include="QuestScripts.h" />
|
||||||
<ClInclude Include="Renderer.h" />
|
<ClInclude Include="Renderer.h" />
|
||||||
<ClInclude Include="RenderSystem.h" />
|
<ClInclude Include="RenderSystem.h" />
|
||||||
<ClInclude Include="ShaderManager.h" />
|
<ClInclude Include="ShaderManager.h" />
|
||||||
|
|||||||
@ -72,6 +72,9 @@
|
|||||||
<ClCompile Include="RenderSystem.cpp">
|
<ClCompile Include="RenderSystem.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="QuestScripts.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="TextureManager.h">
|
<ClInclude Include="TextureManager.h">
|
||||||
@ -134,5 +137,8 @@
|
|||||||
<ClInclude Include="RenderSystem.h">
|
<ClInclude Include="RenderSystem.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="QuestScripts.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
Reference in New Issue
Block a user