demo map and weapon
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <renderer/3d/mesh/static/static_mesh.hpp>
|
||||
#include <renderer/3d/pipeline/static/stapip_options.hpp>
|
||||
#include <renderer/renderer.hpp>
|
||||
#include "states/game/renderer/renderer_static_pair.hpp"
|
||||
|
||||
using Tyra::Renderer;
|
||||
using Tyra::StaPipOptions;
|
||||
using Tyra::StaticMesh;
|
||||
using Tyra::TextureRepository;
|
||||
using Tyra::Vec4;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class DebugObject {
|
||||
public:
|
||||
DebugObject(TextureRepository* repo);
|
||||
~DebugObject();
|
||||
|
||||
StaticMesh* mesh;
|
||||
StaPipOptions* options;
|
||||
RendererStaticPair* pair;
|
||||
|
||||
void setPosition(const Vec4& v);
|
||||
|
||||
private:
|
||||
float rotator;
|
||||
void allocateOptions();
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
#include "state/state.hpp"
|
||||
#include "state/global_state_type.hpp"
|
||||
#include "./player/player.hpp"
|
||||
#include "./renderer/game_renderer.hpp"
|
||||
#include "./terrain/terrain.hpp"
|
||||
#include "./debug_object.hpp"
|
||||
|
||||
namespace Demo {
|
||||
|
||||
@@ -35,6 +39,12 @@ class GameState : public State<GlobalStateType> {
|
||||
GlobalStateType state;
|
||||
bool _wantFinish;
|
||||
bool initialized;
|
||||
u8 fpsChecker;
|
||||
|
||||
GameRenderer renderer;
|
||||
Player player;
|
||||
Terrain terrain;
|
||||
DebugObject dbgObj;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/vec4.hpp"
|
||||
#include "renderer/core/3d/camera_info_3d.hpp"
|
||||
#include "pad/pad.hpp"
|
||||
|
||||
using Tyra::CameraInfo3D;
|
||||
using Tyra::Pad;
|
||||
using Tyra::Vec4;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Camera(Pad* pad);
|
||||
~Camera();
|
||||
|
||||
Vec4 lookAt;
|
||||
Vec4 position;
|
||||
Vec4 unitCircle;
|
||||
|
||||
CameraInfo3D getCameraInfo() { return CameraInfo3D(&position, &lookAt); }
|
||||
|
||||
void update(const Vec4& playerPosition);
|
||||
|
||||
private:
|
||||
float circleRotation, lengthFromOrigin, height;
|
||||
|
||||
Pad* pad;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
||||
#include "states/game/renderer/renderer_static_pair.hpp"
|
||||
#include "./weapon.hpp"
|
||||
#include "./camera.hpp"
|
||||
#include <engine.hpp>
|
||||
|
||||
using Tyra::Engine;
|
||||
using Tyra::Pad;
|
||||
using Tyra::Vec4;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player(Engine* engine);
|
||||
~Player();
|
||||
|
||||
CameraInfo3D getCameraInfo() { return camera.getCameraInfo(); }
|
||||
|
||||
std::vector<RendererStaticPair*> staticPairs;
|
||||
std::vector<RendererDynamicPair*> dynamicPairs;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
void handlePlayerPosition();
|
||||
|
||||
float speed;
|
||||
Pad* pad;
|
||||
Vec4 position;
|
||||
Weapon weapon;
|
||||
Camera camera;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <renderer/3d/mesh/static/static_mesh.hpp>
|
||||
#include <renderer/3d/pipeline/static/stapip_options.hpp>
|
||||
#include <renderer/renderer.hpp>
|
||||
|
||||
using Tyra::Renderer;
|
||||
using Tyra::StaPipOptions;
|
||||
using Tyra::StaticMesh;
|
||||
using Tyra::TextureRepository;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class Weapon {
|
||||
public:
|
||||
Weapon(TextureRepository* repo);
|
||||
~Weapon();
|
||||
|
||||
StaticMesh* mesh;
|
||||
StaPipOptions* options;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
void allocateOptions();
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/renderer.hpp"
|
||||
#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp"
|
||||
#include "renderer/3d/pipeline/static/static_pipeline.hpp"
|
||||
#include "./renderer_dynamic_pair.hpp"
|
||||
#include "./renderer_static_pair.hpp"
|
||||
|
||||
using Tyra::DynamicPipeline;
|
||||
using Tyra::Renderer;
|
||||
using Tyra::StaticPipeline;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class GameRenderer {
|
||||
public:
|
||||
GameRenderer(Renderer* renderer);
|
||||
~GameRenderer();
|
||||
|
||||
void add(std::vector<RendererStaticPair*> staticPairs);
|
||||
void add(std::vector<RendererDynamicPair*> dynamicPairs);
|
||||
void add(RendererStaticPair* staticPair);
|
||||
void add(RendererDynamicPair* dynamicPair);
|
||||
|
||||
void clear();
|
||||
|
||||
void render();
|
||||
|
||||
private:
|
||||
Renderer* renderer;
|
||||
|
||||
StaticPipeline stpip;
|
||||
DynamicPipeline dypip;
|
||||
|
||||
std::vector<RendererStaticPair*> staticPairs;
|
||||
std::vector<RendererDynamicPair*> dynamicPairs;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/3d/pipeline/dynamic/dynamic_pipeline.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh.hpp"
|
||||
|
||||
using Tyra::DynamicMesh;
|
||||
using Tyra::DynPipOptions;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
struct RendererDynamicPair {
|
||||
DynamicMesh* mesh;
|
||||
DynPipOptions* options;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "renderer/3d/pipeline/static/static_pipeline.hpp"
|
||||
#include "renderer/3d/mesh/static/static_mesh.hpp"
|
||||
|
||||
using Tyra::StaPipOptions;
|
||||
using Tyra::StaticMesh;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
struct RendererStaticPair {
|
||||
StaticMesh* mesh;
|
||||
StaPipOptions* options;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <renderer/3d/mesh/static/static_mesh.hpp>
|
||||
#include <renderer/3d/pipeline/static/stapip_options.hpp>
|
||||
#include "states/game/renderer/renderer_static_pair.hpp"
|
||||
#include <renderer/renderer.hpp>
|
||||
|
||||
using Tyra::StaPipOptions;
|
||||
using Tyra::StaticMesh;
|
||||
using Tyra::TextureRepository;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
class Terrain {
|
||||
public:
|
||||
Terrain(TextureRepository* repo);
|
||||
~Terrain();
|
||||
|
||||
StaticMesh* mesh;
|
||||
StaPipOptions* options;
|
||||
RendererStaticPair* pair;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
void allocateOptions();
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
@@ -15,7 +15,7 @@
|
||||
namespace Demo {
|
||||
|
||||
DemoGame::DemoGame(Engine* t_engine)
|
||||
: engine(t_engine), stateManager(STATE_INTRO, STATE_EXIT) {}
|
||||
: engine(t_engine), stateManager(STATE_GAME, STATE_EXIT) {}
|
||||
DemoGame::~DemoGame() {}
|
||||
|
||||
void DemoGame::init() {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/debug_object.hpp"
|
||||
#include <loaders/3d/tyrobj/tyrobj_loader.hpp>
|
||||
#include <file/file_utils.hpp>
|
||||
|
||||
using Tyra::Color;
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::TyrobjLoader;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
DebugObject::DebugObject(TextureRepository* repo) {
|
||||
TyrobjLoader loader;
|
||||
auto* data =
|
||||
loader.load(FileUtils::fromCwd("game/models/debug.obj"), 1, .5F, true);
|
||||
data->normalsEnabled = false;
|
||||
data->textureCoordsEnabled = false;
|
||||
mesh = new StaticMesh(*data);
|
||||
delete data;
|
||||
mesh->getMaterial(0)->color = Color(192.0F, 32.0F, 32.0F, 128.0F);
|
||||
rotator = 0.0F;
|
||||
allocateOptions();
|
||||
|
||||
pair = new RendererStaticPair{mesh, options};
|
||||
}
|
||||
|
||||
void DebugObject::setPosition(const Vec4& v) {
|
||||
mesh->translation.identity();
|
||||
mesh->rotation.identity();
|
||||
mesh->translation.translate(v);
|
||||
mesh->rotation.rotateX(rotator);
|
||||
mesh->rotation.rotateY(rotator);
|
||||
mesh->rotation.rotateZ(rotator);
|
||||
|
||||
rotator += 0.05F;
|
||||
if (rotator >= 360.0F) rotator = 0.0F;
|
||||
}
|
||||
|
||||
DebugObject::~DebugObject() {
|
||||
delete mesh;
|
||||
delete options;
|
||||
delete pair;
|
||||
}
|
||||
|
||||
void DebugObject::allocateOptions() {
|
||||
options = new StaPipOptions();
|
||||
options->shadingType = Tyra::TyraShadingGouraud;
|
||||
options->blendingEnabled = false;
|
||||
options->antiAliasingEnabled = false;
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
@@ -9,19 +9,20 @@
|
||||
*/
|
||||
|
||||
#include "states/game/game_state.hpp"
|
||||
#include "file/file_utils.hpp"
|
||||
#include "thread/threading.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::Threading;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
GameState::GameState(Engine* t_engine) : State(t_engine) {
|
||||
GameState::GameState(Engine* t_engine)
|
||||
: State(t_engine),
|
||||
renderer(&t_engine->renderer),
|
||||
player(t_engine),
|
||||
terrain(&t_engine->renderer.core.texture.repository),
|
||||
dbgObj(&t_engine->renderer.core.texture.repository) {
|
||||
state = STATE_GAME;
|
||||
_wantFinish = false;
|
||||
initialized = false;
|
||||
fpsChecker = 0;
|
||||
}
|
||||
|
||||
GameState::~GameState() {}
|
||||
@@ -42,8 +43,26 @@ GlobalStateType GameState::onFinish() {
|
||||
}
|
||||
|
||||
void GameState::update() {
|
||||
engine->renderer.beginFrame();
|
||||
Threading::switchThread();
|
||||
if (fpsChecker++ > 100) {
|
||||
TYRA_LOG("FPS: ", engine->info.getFps());
|
||||
fpsChecker = 0;
|
||||
}
|
||||
|
||||
auto cameraInfo = player.getCameraInfo();
|
||||
engine->renderer.beginFrame(cameraInfo);
|
||||
|
||||
player.update();
|
||||
dbgObj.setPosition(*cameraInfo.looksAt);
|
||||
|
||||
renderer.clear();
|
||||
{
|
||||
renderer.add(player.staticPairs);
|
||||
renderer.add(player.dynamicPairs);
|
||||
renderer.add(terrain.pair);
|
||||
renderer.add(dbgObj.pair);
|
||||
}
|
||||
renderer.render();
|
||||
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/player/camera.hpp"
|
||||
#include "debug/debug.hpp"
|
||||
|
||||
namespace Demo {
|
||||
|
||||
Camera::Camera(Pad* t_pad) : lookAt(0.0F), position(0.0F), pad(t_pad) {
|
||||
lengthFromOrigin = 30.0F;
|
||||
circleRotation = -3.5F;
|
||||
height = 1.5F;
|
||||
}
|
||||
|
||||
Camera::~Camera() {}
|
||||
|
||||
void Camera::update(const Vec4& playerPosition) {
|
||||
const float rotationOffset = 0.03F;
|
||||
const float heightOffset = 0.5F;
|
||||
|
||||
const auto& rightJoy = pad->getRightJoyPad();
|
||||
|
||||
if (rightJoy.h <= 100) {
|
||||
circleRotation -= rotationOffset;
|
||||
} else if (rightJoy.h >= 200) {
|
||||
circleRotation += rotationOffset;
|
||||
}
|
||||
|
||||
if (rightJoy.v <= 100) {
|
||||
height -= heightOffset;
|
||||
} else if (rightJoy.v >= 200) {
|
||||
height += heightOffset;
|
||||
}
|
||||
|
||||
unitCircle.x = (sin(circleRotation) * lengthFromOrigin);
|
||||
unitCircle.y = height + playerPosition.y;
|
||||
unitCircle.z = (cos(circleRotation) * lengthFromOrigin);
|
||||
|
||||
lookAt = unitCircle + playerPosition;
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/player/player.hpp"
|
||||
|
||||
namespace Demo {
|
||||
|
||||
Player::Player(Engine* engine)
|
||||
: position(0.0F),
|
||||
weapon(&engine->renderer.core.texture.repository),
|
||||
camera(&engine->pad) {
|
||||
staticPairs.push_back(new RendererStaticPair{weapon.mesh, weapon.options});
|
||||
pad = &engine->pad;
|
||||
position = Vec4(3.0F, 3.0F, 0.0F);
|
||||
camera.lookAt = Vec4(0.0F, 0.0F, -30.0F);
|
||||
speed = 0.5F;
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
for (auto pair : staticPairs) {
|
||||
delete pair;
|
||||
}
|
||||
for (auto pair : dynamicPairs) {
|
||||
delete pair;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
handlePlayerPosition();
|
||||
camera.update(position);
|
||||
weapon.update();
|
||||
}
|
||||
|
||||
void Player::handlePlayerPosition() {
|
||||
const auto& leftJoy = pad->getLeftJoyPad();
|
||||
|
||||
auto normalizedCamera = Vec4(camera.unitCircle);
|
||||
normalizedCamera.normalize();
|
||||
normalizedCamera *= speed;
|
||||
|
||||
Vec4 nextPosition(position);
|
||||
|
||||
if (leftJoy.v <= 100) {
|
||||
nextPosition.x += normalizedCamera.x;
|
||||
nextPosition.z += normalizedCamera.z;
|
||||
} else if (leftJoy.v >= 200) {
|
||||
nextPosition.x += -normalizedCamera.x;
|
||||
nextPosition.z += -normalizedCamera.z;
|
||||
}
|
||||
if (leftJoy.h <= 100) {
|
||||
nextPosition.x += normalizedCamera.z;
|
||||
nextPosition.z += -normalizedCamera.x;
|
||||
} else if (leftJoy.h >= 200) {
|
||||
nextPosition.x += -normalizedCamera.z;
|
||||
nextPosition.z += normalizedCamera.x;
|
||||
}
|
||||
|
||||
position = nextPosition;
|
||||
|
||||
camera.position = position;
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/player/weapon.hpp"
|
||||
#include <loaders/3d/tyrobj/tyrobj_loader.hpp>
|
||||
#include <file/file_utils.hpp>
|
||||
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::TyrobjLoader;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
Weapon::Weapon(TextureRepository* repo) {
|
||||
TyrobjLoader loader;
|
||||
auto* data = loader.load(FileUtils::fromCwd("game/models/ak47/ak47.obj"), 1,
|
||||
1.0F, true);
|
||||
data->normalsEnabled = false;
|
||||
mesh = new StaticMesh(*data);
|
||||
delete data;
|
||||
|
||||
mesh->translation.translateZ(-50.0F);
|
||||
|
||||
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/ak47/"), "png");
|
||||
|
||||
allocateOptions();
|
||||
}
|
||||
|
||||
// float testRotation = 0.0F;
|
||||
|
||||
void Weapon::update() {
|
||||
// testRotation += 0.001F;
|
||||
mesh->rotation.identity();
|
||||
mesh->rotation.rotateZ(0.1F);
|
||||
mesh->rotation.rotateY(-4.3F);
|
||||
// TYRA_LOG(testRotation);
|
||||
}
|
||||
|
||||
Weapon::~Weapon() {
|
||||
delete mesh;
|
||||
delete options;
|
||||
}
|
||||
|
||||
void Weapon::allocateOptions() {
|
||||
options = new StaPipOptions();
|
||||
options->shadingType = Tyra::TyraShadingGouraud;
|
||||
options->blendingEnabled = false;
|
||||
options->antiAliasingEnabled = false;
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/renderer/game_renderer.hpp"
|
||||
#include "thread/threading.hpp"
|
||||
|
||||
using Tyra::Threading;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
GameRenderer::GameRenderer(Renderer* t_renderer) {
|
||||
renderer = t_renderer;
|
||||
|
||||
stpip.setRenderer(&renderer->core);
|
||||
dypip.setRenderer(&renderer->core);
|
||||
}
|
||||
|
||||
GameRenderer::~GameRenderer() {}
|
||||
|
||||
void GameRenderer::add(std::vector<RendererStaticPair*> t_staticPairs) {
|
||||
staticPairs.insert(staticPairs.end(), t_staticPairs.begin(),
|
||||
t_staticPairs.end());
|
||||
}
|
||||
|
||||
void GameRenderer::add(std::vector<RendererDynamicPair*> t_dynamicPairs) {
|
||||
dynamicPairs.insert(dynamicPairs.end(), t_dynamicPairs.begin(),
|
||||
t_dynamicPairs.end());
|
||||
}
|
||||
|
||||
void GameRenderer::add(RendererStaticPair* staticPair) {
|
||||
staticPairs.push_back(staticPair);
|
||||
}
|
||||
|
||||
void GameRenderer::add(RendererDynamicPair* dynamicPair) {
|
||||
dynamicPairs.push_back(dynamicPair);
|
||||
}
|
||||
|
||||
void GameRenderer::clear() {
|
||||
staticPairs.clear();
|
||||
dynamicPairs.clear();
|
||||
}
|
||||
|
||||
void GameRenderer::render() {
|
||||
if (staticPairs.size()) {
|
||||
renderer->renderer3D.usePipeline(&stpip);
|
||||
|
||||
for (auto& pair : staticPairs) {
|
||||
stpip.render(pair->mesh, pair->options);
|
||||
}
|
||||
}
|
||||
|
||||
Threading::switchThread();
|
||||
|
||||
if (dynamicPairs.size()) {
|
||||
renderer->renderer3D.usePipeline(&dypip);
|
||||
|
||||
for (auto& pair : dynamicPairs) {
|
||||
dypip.render(pair->mesh, pair->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "states/game/terrain/terrain.hpp"
|
||||
#include <loaders/3d/tyrobj/tyrobj_loader.hpp>
|
||||
#include <file/file_utils.hpp>
|
||||
|
||||
using Tyra::FileUtils;
|
||||
using Tyra::TyrobjLoader;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
Terrain::Terrain(TextureRepository* repo) {
|
||||
TyrobjLoader loader;
|
||||
auto* data = loader.load(
|
||||
FileUtils::fromCwd("game/models/terrain/terrain.obj"), 1, 5.0F, true);
|
||||
data->normalsEnabled = false;
|
||||
mesh = new StaticMesh(*data);
|
||||
mesh->getMaterial(0)->color.r = 96.0F;
|
||||
mesh->getMaterial(0)->color.g = 96.0F;
|
||||
mesh->getMaterial(0)->color.b = 96.0F;
|
||||
delete data;
|
||||
|
||||
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
||||
|
||||
allocateOptions();
|
||||
|
||||
pair = new RendererStaticPair{mesh, options};
|
||||
}
|
||||
|
||||
// float testRotation = 0.0F;
|
||||
|
||||
void Terrain::update() {
|
||||
// testRotation += 0.001F;
|
||||
mesh->rotation.identity();
|
||||
mesh->rotation.rotateZ(0.1F);
|
||||
mesh->rotation.rotateY(-4.3F);
|
||||
// TYRA_LOG(testRotation);
|
||||
}
|
||||
|
||||
Terrain::~Terrain() {
|
||||
delete mesh;
|
||||
delete options;
|
||||
delete pair;
|
||||
}
|
||||
|
||||
void Terrain::allocateOptions() {
|
||||
options = new StaPipOptions();
|
||||
options->shadingType = Tyra::TyraShadingGouraud;
|
||||
options->blendingEnabled = true;
|
||||
options->antiAliasingEnabled = false;
|
||||
}
|
||||
|
||||
} // namespace Demo
|
||||
Reference in New Issue
Block a user