Updates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
project(gamedata)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
add_library(GameData STATIC GameData.cpp CharacterModule.cpp WaterModule.cpp)
|
||||
target_link_libraries(GameData PUBLIC OgreMain OgreBullet flecs::flecs_static)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain Overlay CONFIG)
|
||||
add_library(GameData STATIC GameData.cpp CharacterModule.cpp WaterModule.cpp SunModule.cpp TerrainModule.cpp GUIModule.cpp)
|
||||
target_link_libraries(GameData PUBLIC OgreMain OgreBites OgreBullet OgrePaging OgreTerrain OgreOverlay flecs::flecs_static)
|
||||
target_include_directories(GameData PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -216,7 +216,6 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
body.gvelocity += (gravity + b) * delta;
|
||||
body.gvelocity.y = Ogre::Math::Clamp(
|
||||
body.gvelocity.y, -2.5f, 2.5f);
|
||||
std::cout << "InWater!!!!!!!\n";
|
||||
} else
|
||||
body.gvelocity += gravity * delta;
|
||||
body.gvelocity *= 0.99;
|
||||
@@ -518,6 +517,7 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
ch.mBodyNode->_getDerivedPosition().y > 0.05f)
|
||||
e.remove<InWater>();
|
||||
});
|
||||
#if 0
|
||||
ecs.system<const EngineData, CharacterBase, CharacterBody>(
|
||||
"DisplayPlayerPos")
|
||||
.kind(flecs::OnUpdate)
|
||||
@@ -528,6 +528,7 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
std::cout << "player: " << ch.mBodyNode->getPosition()
|
||||
<< "\n";
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void CharacterModule::setAnimation(AnimationControl &anim)
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
#define COMPONENTS_H_
|
||||
#include <Ogre.h>
|
||||
#include <OgreBullet.h>
|
||||
namespace OgreBites
|
||||
{
|
||||
class ApplicationContextSDL;
|
||||
class InputListenerChain;
|
||||
class InputListener;
|
||||
}
|
||||
namespace ECS
|
||||
{
|
||||
struct GameData {
|
||||
@@ -46,6 +52,15 @@ struct Camera {
|
||||
Ogre::SceneNode *mCameraGoal;
|
||||
Ogre::Real mPivotPitch;
|
||||
};
|
||||
struct RenderWindow {
|
||||
Ogre::RenderWindow *window;
|
||||
float dpi;
|
||||
};
|
||||
struct App {
|
||||
OgreBites::ApplicationContextSDL *app;
|
||||
OgreBites::InputListenerChain *mInput;
|
||||
std::vector<OgreBites::InputListener *> listeners;
|
||||
};
|
||||
struct InWater {};
|
||||
}
|
||||
#endif
|
||||
314
src/gamedata/GUIModule.cpp
Normal file
314
src/gamedata/GUIModule.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
#include <iostream>
|
||||
#include <OgreOverlaySystem.h>
|
||||
#include <OgreOverlayManager.h>
|
||||
#include <OgreImGuiOverlay.h>
|
||||
#include <OgreImGuiInputListener.h>
|
||||
#include <OgreRenderTargetListener.h>
|
||||
#include <OgreSceneNode.h>
|
||||
#include <OgreApplicationContext.h>
|
||||
#include <OgreImGuiInputListener.h>
|
||||
#include "GameData.h"
|
||||
#include "Components.h"
|
||||
#include "GUIModule.h"
|
||||
namespace ECS
|
||||
{
|
||||
struct GUIListener;
|
||||
struct GUIData {
|
||||
Ogre::ImGuiOverlay *mGuiOverlay;
|
||||
std::vector<Ogre::String> glb_names;
|
||||
GUIListener *mGUIListener;
|
||||
};
|
||||
struct GUIListener : public Ogre::RenderTargetListener {
|
||||
float panel_width;
|
||||
void
|
||||
preViewportUpdate(const Ogre::RenderTargetViewportEvent &evt) override
|
||||
{
|
||||
preview(evt);
|
||||
}
|
||||
void buttons_panel()
|
||||
{
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5f - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, size.y * 0.5f + 20),
|
||||
ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height),
|
||||
ImGuiCond_Always);
|
||||
ImGui::Begin("Dumb and Stupid");
|
||||
// if (ECS::get().get<GUI>().enabled)
|
||||
// ECS::get().get<App>().app->setWindowGrab(true);
|
||||
if (ImGui::Button("Shitty Quit button"))
|
||||
Ogre::Root::getSingleton().queueEndRendering();
|
||||
if (ImGui::Button("Chick-chick")) {
|
||||
ECS::get().get_mut<GUI>().enabled = false;
|
||||
ECS::get().modified<GUI>();
|
||||
// ECS::get().get<App>().app->setWindowGrab(true);
|
||||
}
|
||||
ImGui::Text("We do stoopid...");
|
||||
ImGui::End();
|
||||
}
|
||||
void create_entity_node(const Ogre::String &name, int key)
|
||||
{
|
||||
Ogre::Entity *ent =
|
||||
ECS::get().get<EngineData>().mScnMgr->createEntity(
|
||||
name);
|
||||
Ogre::SceneNode *pnode =
|
||||
ECS::get()
|
||||
.get<EngineData>()
|
||||
.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode(
|
||||
"ent:" + name +
|
||||
Ogre::StringConverter::toString(
|
||||
key),
|
||||
ECS::get()
|
||||
.get<Camera>()
|
||||
.mCameraPivot->getPosition(),
|
||||
ECS::get()
|
||||
.get<Camera>()
|
||||
.mCameraPivot->getOrientation());
|
||||
pnode->attachObject(ent);
|
||||
Ogre::Quaternion q = pnode->getOrientation();
|
||||
Ogre::Radian yaw = q.getYaw();
|
||||
Ogre::Quaternion nq(yaw, Ogre::Vector3(0, 1, 0));
|
||||
pnode->setOrientation(nq);
|
||||
|
||||
// ECS::get().get<App>().app->setWindowGrab(true);
|
||||
}
|
||||
void buildings_editor()
|
||||
{
|
||||
int i;
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5 - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height),
|
||||
ImGuiCond_Always);
|
||||
ImGui::Begin("Droppings...");
|
||||
for (i = 0; i < ECS::get().get<GUIData>().glb_names.size();
|
||||
i++) {
|
||||
Ogre::String id_button =
|
||||
"Create entity: " +
|
||||
ECS::get().get<GUIData>().glb_names[i] +
|
||||
"##ent:" +
|
||||
ECS::get().get<GUIData>().glb_names[i];
|
||||
if (ImGui::Button(id_button.c_str())) {
|
||||
create_entity_node(
|
||||
ECS::get().get<GUIData>().glb_names[i],
|
||||
i);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void position_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
Ogre::Vector3 position = node->getPosition();
|
||||
float v[3] = { position.x, position.y, position.z };
|
||||
ImGui::InputFloat3("position", v);
|
||||
position.x = v[0];
|
||||
position.y = v[1];
|
||||
position.z = v[2];
|
||||
node->setPosition(position);
|
||||
}
|
||||
void orientation_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
Ogre::Quaternion q = node->getOrientation();
|
||||
float yaw = Ogre::Radian(q.getYaw()).valueDegrees();
|
||||
float pitch = Ogre::Radian(q.getPitch()).valueDegrees();
|
||||
float roll = Ogre::Radian(q.getRoll()).valueDegrees();
|
||||
bool m1 = ImGui::InputFloat("yaw", &yaw);
|
||||
bool m2 = ImGui::InputFloat("pitch", &pitch);
|
||||
bool m3 = ImGui::InputFloat("roll", &roll);
|
||||
if (m1 || m2 || m3) {
|
||||
Ogre::Quaternion q1(Ogre::Radian(Ogre::Degree(yaw)),
|
||||
Ogre::Vector3::UNIT_Y);
|
||||
Ogre::Quaternion q2(Ogre::Degree(pitch),
|
||||
Ogre::Vector3::UNIT_X);
|
||||
Ogre::Quaternion q3(Ogre::Degree(roll),
|
||||
Ogre::Vector3::UNIT_Z);
|
||||
node->setOrientation(q1 * q2 * q3);
|
||||
}
|
||||
}
|
||||
void attachments_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
const Ogre::SceneNode::ObjectMap &pmap =
|
||||
node->getAttachedObjects();
|
||||
int i;
|
||||
for (i = 0; i < pmap.size(); i++) {
|
||||
const Ogre::MovableObject *mobj = pmap[i];
|
||||
const Ogre::String &pname = mobj->getName();
|
||||
ImGui::Text("Name: %s", pname.c_str());
|
||||
}
|
||||
}
|
||||
void preview(const Ogre::RenderTargetViewportEvent &evt)
|
||||
{
|
||||
int i;
|
||||
Ogre::ImGuiOverlay::NewFrame();
|
||||
if (ECS::get().get<GUI>().enabled) {
|
||||
buttons_panel();
|
||||
buildings_editor();
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5f - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(size.x - window_width,
|
||||
size.y * 0.5f + 20),
|
||||
ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width,
|
||||
window_height),
|
||||
ImGuiCond_Always);
|
||||
// ImGui::Begin("Dumb and Stupid", &mKbd.gui_active);
|
||||
ImGui::Begin("Panel...");
|
||||
std::deque<Ogre::SceneNode *> tree_input_queue,
|
||||
tree_output_queue;
|
||||
std::vector<Ogre::SceneNode *> tree_list;
|
||||
tree_input_queue.push_back(
|
||||
ECS::get()
|
||||
.get<EngineData>()
|
||||
.mScnMgr->getRootSceneNode());
|
||||
tree_input_queue.push_back(nullptr);
|
||||
std::set<Ogre::SceneNode *> visited;
|
||||
while (true) {
|
||||
int new_nodes_count = 0;
|
||||
while (!tree_input_queue.empty()) {
|
||||
int child;
|
||||
Ogre::SceneNode *item =
|
||||
tree_input_queue.front();
|
||||
tree_input_queue.pop_front();
|
||||
if (item &&
|
||||
visited.find(item) ==
|
||||
visited.end()) { // new node
|
||||
new_nodes_count++;
|
||||
tree_output_queue.push_back(
|
||||
item);
|
||||
visited.insert(item);
|
||||
const Ogre::Node::ChildNodeMap
|
||||
&children =
|
||||
item->getChildren();
|
||||
for (child = 0;
|
||||
child < children.size();
|
||||
child++) {
|
||||
tree_output_queue.push_back(
|
||||
static_cast<
|
||||
Ogre::SceneNode
|
||||
*>(
|
||||
children[child]));
|
||||
tree_output_queue
|
||||
.push_back(
|
||||
nullptr);
|
||||
}
|
||||
} else
|
||||
tree_output_queue.push_back(
|
||||
item);
|
||||
}
|
||||
if (new_nodes_count == 0)
|
||||
break;
|
||||
tree_input_queue = tree_output_queue;
|
||||
tree_output_queue.clear();
|
||||
}
|
||||
tree_list.insert(tree_list.begin(),
|
||||
tree_output_queue.begin(),
|
||||
tree_output_queue.end());
|
||||
int count = 0;
|
||||
int depth = 0;
|
||||
std::vector<int> check_depth;
|
||||
int max_depth = 0;
|
||||
check_depth.push_back(0);
|
||||
for (count = 0; count < tree_list.size(); count++) {
|
||||
int t;
|
||||
|
||||
Ogre::SceneNode *node = tree_list[count];
|
||||
if (node && max_depth >= depth) {
|
||||
Ogre::String name = node->getName();
|
||||
if (name.length() == 0) {
|
||||
name = "Node #" +
|
||||
Ogre::StringConverter::
|
||||
toString(count);
|
||||
}
|
||||
if (ImGui::TreeNode(name.c_str())) {
|
||||
check_depth.push_back(
|
||||
max_depth);
|
||||
max_depth++;
|
||||
ImGui::Text("%s",
|
||||
(name + "##caption")
|
||||
.c_str());
|
||||
position_editor(node);
|
||||
ImGui::Separator();
|
||||
orientation_editor(node);
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Attachments");
|
||||
attachments_editor(node);
|
||||
}
|
||||
} else if (!node && max_depth >= depth) {
|
||||
max_depth = check_depth.back();
|
||||
check_depth.pop_back();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
if (tree_list[count])
|
||||
depth++;
|
||||
else
|
||||
depth--;
|
||||
}
|
||||
ImGui::Spacing();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GUIModule::GUIModule(flecs::world &ecs)
|
||||
{
|
||||
ecs.component<GUI>().add(flecs::Singleton);
|
||||
ecs.component<GUIData>().add(flecs::Singleton);
|
||||
ecs.set<GUI>({ false, true, false, nullptr });
|
||||
ecs.set<GUIData>({ nullptr, {}, nullptr });
|
||||
ui_wait =
|
||||
ecs.system<const RenderWindow, App, GUIData>("SetupGUI")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([this](const RenderWindow &window, App &app,
|
||||
GUIData &gui) {
|
||||
if (!gui.mGuiOverlay) {
|
||||
float vpScale =
|
||||
window.dpi / 96 *
|
||||
window.window->getWidth() /
|
||||
1600.0f;
|
||||
Ogre::OverlayManager::getSingleton()
|
||||
.setPixelRatio(vpScale);
|
||||
std::cout << "GUI configure\n";
|
||||
gui.mGuiOverlay =
|
||||
app.app->initialiseImGui();
|
||||
gui.mGuiOverlay->setZOrder(300);
|
||||
gui.mGuiOverlay->show();
|
||||
gui.mGUIListener = new GUIListener();
|
||||
window.window->addListener(
|
||||
gui.mGUIListener);
|
||||
int i;
|
||||
|
||||
const std::vector<Ogre::String> &groups =
|
||||
Ogre::ResourceGroupManager::
|
||||
getSingleton()
|
||||
.getResourceGroups();
|
||||
for (i = 0; i < groups.size(); i++) {
|
||||
std::vector<Ogre::String> names =
|
||||
*Ogre::ResourceGroupManager::getSingleton()
|
||||
.findResourceNames(
|
||||
groups[i],
|
||||
"*.glb");
|
||||
gui.glb_names.insert(
|
||||
gui.glb_names.end(),
|
||||
names.begin(),
|
||||
names.end());
|
||||
}
|
||||
ECS::get_mut<ECS::GUI>()
|
||||
.mGuiInpitListener =
|
||||
new OgreBites::
|
||||
ImGuiInputListener();
|
||||
ECS::modified<ECS::GUI>();
|
||||
std::cout << "GUI configure finished\n";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
30
src/gamedata/GUIModule.h
Normal file
30
src/gamedata/GUIModule.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef GUI_MODULE_H_
|
||||
#define GUI_MODULE_H_
|
||||
#include <flecs.h>
|
||||
namespace OgreBites
|
||||
{
|
||||
class InputListener;
|
||||
}
|
||||
namespace ECS
|
||||
{
|
||||
struct GUI {
|
||||
bool enabled;
|
||||
bool grab;
|
||||
bool grabChanged;
|
||||
OgreBites::InputListener *mGuiInpitListener;
|
||||
static void setWindowGrab(bool g = true)
|
||||
{
|
||||
ECS::GUI &gui = ECS::get().get_mut<ECS::GUI>();
|
||||
if (gui.grab != g) {
|
||||
gui.grab = g;
|
||||
gui.grabChanged = true;
|
||||
ECS::get().modified<ECS::GUI>();
|
||||
}
|
||||
}
|
||||
};
|
||||
struct GUIModule {
|
||||
flecs::entity ui_wait;
|
||||
GUIModule(flecs::world &ecs);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "Components.h"
|
||||
#include "CharacterModule.h"
|
||||
#include "WaterModule.h"
|
||||
#include "TerrainModule.h"
|
||||
#include "SunModule.h"
|
||||
#include "GUIModule.h"
|
||||
|
||||
namespace ECS
|
||||
{
|
||||
@@ -11,22 +14,38 @@ static flecs::world ecs;
|
||||
void setup(Ogre::SceneManager *scnMgr, Ogre::Bullet::DynamicsWorld *world,
|
||||
Ogre::SceneNode *cameraNode, Ogre::Camera *camera)
|
||||
{
|
||||
std::cout << "Setup GameData\n";
|
||||
ecs.component<EngineData>().add(flecs::Singleton);
|
||||
ecs.component<GameData>().add(flecs::Singleton);
|
||||
ecs.component<Input>().add(flecs::Singleton);
|
||||
ecs.component<Camera>().add(flecs::Singleton);
|
||||
ecs.component<InWater>();
|
||||
ecs.set<EngineData>({ scnMgr, world, 0.0f });
|
||||
ecs.set<Camera>({ cameraNode, camera, false });
|
||||
ecs.add<GameData>();
|
||||
ecs.add<Input>();
|
||||
ecs.component<App>().add(flecs::Singleton);
|
||||
ecs.import <WaterModule>();
|
||||
ecs.import <CharacterModule>();
|
||||
ecs.import <SunModule>();
|
||||
ecs.import <TerrainModule>();
|
||||
ecs.import <GUIModule>();
|
||||
ecs.system<EngineData>("UpdateDelta")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([](EngineData &eng) {
|
||||
eng.delta = ECS::get().delta_time();
|
||||
});
|
||||
ecs.import <WaterModule>();
|
||||
ecs.import <CharacterModule>();
|
||||
ecs.set<EngineData>({ scnMgr, world, 0.0f });
|
||||
ecs.set<Camera>({ cameraNode, camera, false });
|
||||
ecs.add<GameData>();
|
||||
ecs.add<Input>();
|
||||
ecs.set<WaterSurface>({ nullptr, nullptr, nullptr });
|
||||
ecs.set<WaterBody>({ nullptr });
|
||||
ecs.set<Terrain>({ nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
false,
|
||||
{ 0, 0, 0 } });
|
||||
std::cout << "Setup GameData done\n";
|
||||
}
|
||||
void update(float delta)
|
||||
{
|
||||
|
||||
@@ -8,5 +8,17 @@ void setup(Ogre::SceneManager *scnMgr, Ogre::Bullet::DynamicsWorld *world,
|
||||
Ogre::SceneNode *cameraNode, Ogre::Camera *camera);
|
||||
void update(float delta);
|
||||
flecs::world get();
|
||||
template <class T> const T &get()
|
||||
{
|
||||
return ECS::get().get<T>();
|
||||
}
|
||||
template <class T> T &get_mut()
|
||||
{
|
||||
return ECS::get().get_mut<T>();
|
||||
}
|
||||
template <class T> void modified()
|
||||
{
|
||||
ECS::get().modified<T>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
53
src/gamedata/SunModule.cpp
Normal file
53
src/gamedata/SunModule.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <Ogre.h>
|
||||
#include "Components.h"
|
||||
#include "SunModule.h"
|
||||
|
||||
namespace ECS
|
||||
{
|
||||
SunModule::SunModule(flecs::world &ecs)
|
||||
{
|
||||
ecs.component<Sun>().add(flecs::Singleton);
|
||||
ecs.set<Sun>({ nullptr, nullptr, nullptr, nullptr });
|
||||
ecs.system<const EngineData, Sun>("UpdateSetupSun")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([](const EngineData &eng, Sun &sun) {
|
||||
if (!sun.mSun) {
|
||||
Ogre::Light *light =
|
||||
eng.mScnMgr->createLight("Sun");
|
||||
sun.mSunNode = eng.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode(
|
||||
"SunPivot");
|
||||
sun.mSunGoal = eng.mScnMgr->getRootSceneNode()
|
||||
->createChildSceneNode(
|
||||
"SunGoal");
|
||||
sun.mSunTarget =
|
||||
sun.mSunGoal->createChildSceneNode(
|
||||
"SunGoalTarget",
|
||||
Ogre::Vector3(100.0f, -400.0f,
|
||||
-400.0f),
|
||||
Ogre::Quaternion::IDENTITY);
|
||||
sun.mSunNode->attachObject(light);
|
||||
light->setType(Ogre::Light::LT_DIRECTIONAL);
|
||||
light->setDiffuseColour(
|
||||
Ogre::ColourValue::White);
|
||||
light->setSpecularColour(
|
||||
Ogre::ColourValue(0.4, 0.4, 0.4));
|
||||
sun.mSunNode->setDirection(
|
||||
Ogre::Vector3(100.0f, -400.0f, -400.f));
|
||||
sun.mSun = light;
|
||||
}
|
||||
static const float sun_speed = 1.0f;
|
||||
float uangle = M_PI * 2.0f / 24.0f / 60.0f;
|
||||
sun.mSunNode->pitch(Ogre::Radian(uangle) * sun_speed *
|
||||
eng.delta);
|
||||
if (sun.mSunNode->getOrientation()
|
||||
.getPitch()
|
||||
.valueRadians() > 0)
|
||||
eng.mScnMgr->setAmbientLight(Ogre::ColourValue(
|
||||
0.1f, 0.1f, 0.4f, 1.0f));
|
||||
else
|
||||
eng.mScnMgr->setAmbientLight(Ogre::ColourValue(
|
||||
0.2f, 0.2f, 0.2f, 1.0f));
|
||||
});
|
||||
}
|
||||
}
|
||||
20
src/gamedata/SunModule.h
Normal file
20
src/gamedata/SunModule.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef SUN_MODULE_H_
|
||||
#define SUN_MODULE_H_
|
||||
#include <flecs.h>
|
||||
namespace Ogre
|
||||
{
|
||||
class Light;
|
||||
}
|
||||
namespace ECS
|
||||
{
|
||||
struct Sun {
|
||||
Ogre::SceneNode *mSunGoal;
|
||||
Ogre::SceneNode *mSunNode;
|
||||
Ogre::SceneNode *mSunTarget;
|
||||
Ogre::Light *mSun;
|
||||
};
|
||||
struct SunModule {
|
||||
SunModule(flecs::world &ecs);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
475
src/gamedata/TerrainModule.cpp
Normal file
475
src/gamedata/TerrainModule.cpp
Normal file
@@ -0,0 +1,475 @@
|
||||
#include <unordered_set>
|
||||
#include <iostream>
|
||||
#include <Ogre.h>
|
||||
#include <OgreBullet.h>
|
||||
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
|
||||
#include <OgreTerrain.h>
|
||||
#include <OgreTerrainGroup.h>
|
||||
#include <OgrePageManager.h>
|
||||
#include <OgreTerrainPagedWorldSection.h>
|
||||
#include <OgrePage.h>
|
||||
#include <OgreTerrainPaging.h>
|
||||
|
||||
#include "GameData.h"
|
||||
#include "Components.h"
|
||||
#include "CharacterModule.h"
|
||||
#include "SunModule.h"
|
||||
#include "TerrainModule.h"
|
||||
|
||||
#define TERRAIN_SIZE 129
|
||||
#define TERRAIN_WORLD_SIZE 4000.0f
|
||||
#define ENDLESS_TERRAIN_FILE_PREFIX Ogre::String("EndlessWorldTerrain")
|
||||
#define ENDLESS_TERRAIN_FILE_SUFFIX Ogre::String("dat")
|
||||
|
||||
#define ENDLESS_PAGING
|
||||
|
||||
// max range for a int16
|
||||
#define ENDLESS_PAGE_MIN_X (-0x7FFF)
|
||||
#define ENDLESS_PAGE_MIN_Y (-0x7FFF)
|
||||
#define ENDLESS_PAGE_MAX_X 0x7FFF
|
||||
#define ENDLESS_PAGE_MAX_Y 0x7FFF
|
||||
namespace ECS
|
||||
{
|
||||
|
||||
class FlatTerrainDefiner
|
||||
: public Ogre::TerrainPagedWorldSection::TerrainDefiner,
|
||||
public Ogre::FrameListener {
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
Ogre::Bullet::DynamicsWorld *mWorld;
|
||||
struct gen_collider {
|
||||
Ogre::TerrainGroup *group;
|
||||
long x;
|
||||
long y;
|
||||
};
|
||||
std::deque<struct gen_collider> collider_queue;
|
||||
Ogre::Image img, img_noise, img_brushes;
|
||||
|
||||
public:
|
||||
FlatTerrainDefiner(Ogre::SceneManager *scm,
|
||||
Ogre::Bullet::DynamicsWorld *world)
|
||||
: Ogre::TerrainPagedWorldSection::TerrainDefiner()
|
||||
, Ogre::FrameListener()
|
||||
, mScnMgr(scm)
|
||||
, mWorld(world)
|
||||
{
|
||||
Ogre::Root::getSingleton().addFrameListener(this);
|
||||
img.load(
|
||||
"world_map.png",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
||||
img_noise.load(
|
||||
"terrain.png",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
||||
img_brushes.load(
|
||||
"brushes.png",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
||||
}
|
||||
|
||||
private:
|
||||
float get_noise_height(const Ogre::Vector2 &worldOffset, int x, int y)
|
||||
{
|
||||
int h;
|
||||
Ogre::Vector2 noisePoint;
|
||||
|
||||
struct noise_types {
|
||||
Ogre::Vector2 noiseOfft;
|
||||
float noiseMul;
|
||||
float noiseBias;
|
||||
float noiseAmp;
|
||||
};
|
||||
static struct noise_types noise_pass[] = {
|
||||
{ { -100.0f, 70.0f }, 10.2f, -0.55f, 5.0f },
|
||||
{ { -130.0f, 55.0f }, 5.35f, -0.55f, 1.0f }
|
||||
};
|
||||
static float noise_values[] = { 0.0f, 0.0f };
|
||||
for (h = 0; h < (int)sizeof(noise_values) /
|
||||
(int)sizeof(noise_values[0]);
|
||||
h++) {
|
||||
noisePoint = (worldOffset + Ogre::Vector2(x, y) +
|
||||
noise_pass[h].noiseOfft) *
|
||||
noise_pass[h].noiseMul;
|
||||
int noise_x =
|
||||
(int)(noisePoint.x + img_noise.getWidth() / 2) %
|
||||
img_noise.getWidth();
|
||||
int noise_y = (int)(noisePoint.y +
|
||||
img_noise.getHeight() / 2) %
|
||||
img_noise.getHeight();
|
||||
Ogre::ColourValue noise_color =
|
||||
img_noise.getColourAt(noise_x, noise_y, 0);
|
||||
noise_values[h] =
|
||||
(noise_color.r + noise_pass[h].noiseBias) *
|
||||
noise_pass[h].noiseAmp;
|
||||
}
|
||||
return noise_values[0] + noise_values[1];
|
||||
}
|
||||
#define BRUSH_SIZE 64
|
||||
float get_brush_height(int id, int x, int y)
|
||||
{
|
||||
int m = 0;
|
||||
switch (id) {
|
||||
case 0:
|
||||
m = 0;
|
||||
break;
|
||||
case 1:
|
||||
m = BRUSH_SIZE;
|
||||
break;
|
||||
default:
|
||||
OgreAssert(false, "bad brush id");
|
||||
break;
|
||||
}
|
||||
return img_brushes.getColourAt(x, y + m, 0).r;
|
||||
}
|
||||
float get_base_height(const Ogre::Vector2 &worldOffset, int x, int y)
|
||||
{
|
||||
float height = 0.0f;
|
||||
int world_x = worldOffset.x + x;
|
||||
int world_y = worldOffset.y + y;
|
||||
int world_img_x =
|
||||
world_x + (int)img.getWidth() * BRUSH_SIZE / 2;
|
||||
int world_img_y =
|
||||
world_y + (int)img.getHeight() * BRUSH_SIZE / 2;
|
||||
Ogre::ColourValue color, colorb1, colorb2;
|
||||
// float d;
|
||||
int map_img_x = world_img_x / (BRUSH_SIZE);
|
||||
int map_img_y = world_img_y / (BRUSH_SIZE);
|
||||
int brush_img_x = world_img_x % BRUSH_SIZE;
|
||||
int brush_img_y = world_img_y % BRUSH_SIZE;
|
||||
if (world_img_x < 0 ||
|
||||
world_img_x >= img.getWidth() * BRUSH_SIZE ||
|
||||
world_img_y < 0 ||
|
||||
world_img_y >= img.getWidth() * BRUSH_SIZE) {
|
||||
height = -1.0f;
|
||||
goto out;
|
||||
}
|
||||
color = img.getColourAt(map_img_x, map_img_y, 0);
|
||||
colorb1 = img_brushes.getColourAt(brush_img_x,
|
||||
brush_img_y + BRUSH_SIZE, 0);
|
||||
colorb2 = img_brushes.getColourAt(brush_img_x, brush_img_y, 0);
|
||||
// d = Ogre::Math::saturate(color.r - 0.05f);
|
||||
height = color.r;
|
||||
out:
|
||||
return height;
|
||||
}
|
||||
|
||||
public:
|
||||
void define(Ogre::TerrainGroup *terrainGroup, long x, long y) override
|
||||
{
|
||||
uint16_t terrainSize = terrainGroup->getTerrainSize();
|
||||
float *heightMap = OGRE_ALLOC_T(float, terrainSize *terrainSize,
|
||||
MEMCATEGORY_GEOMETRY);
|
||||
// float *heightMapCollider = OGRE_ALLOC_T(
|
||||
// float, terrainSize *terrainSize, MEMCATEGORY_GEOMETRY);
|
||||
Ogre::Vector2 worldOffset(Ogre::Real(x * (terrainSize - 1)),
|
||||
Ogre::Real(y * (terrainSize - 1)));
|
||||
Ogre::Vector2 worldOrigin =
|
||||
Ogre::Vector2(img.getWidth(), img.getHeight()) * 0.5f;
|
||||
float chunk = 128.0f;
|
||||
Ogre::Vector2 revisedValuePoint;
|
||||
for (int i = 0; i < terrainSize; i++)
|
||||
for (int j = 0; j < terrainSize; j++) {
|
||||
float brush_height0 =
|
||||
get_brush_height(0, j % BRUSH_SIZE,
|
||||
i % BRUSH_SIZE) -
|
||||
0.55f;
|
||||
float brush_height1 =
|
||||
get_brush_height(1, j % BRUSH_SIZE,
|
||||
i % BRUSH_SIZE) -
|
||||
0.55f;
|
||||
float mheight =
|
||||
Ogre::Math::lerp(
|
||||
brush_height1, brush_height0,
|
||||
get_base_height(worldOffset, j,
|
||||
i)) *
|
||||
120.0f;
|
||||
float height = mheight;
|
||||
if (mheight > 0.5f)
|
||||
height += 2.0f +
|
||||
get_noise_height(worldOffset,
|
||||
j, i);
|
||||
else if (mheight < -0.5f)
|
||||
height -= 2.0f +
|
||||
get_noise_height(worldOffset,
|
||||
j, i);
|
||||
|
||||
// height = -2.0f;
|
||||
heightMap[i * terrainSize + j] = height;
|
||||
// heightMapCollider[(terrainSize - i - 1) *
|
||||
// terrainSize +
|
||||
// j] = height;
|
||||
}
|
||||
terrainGroup->defineTerrain(x, y, heightMap);
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"defined terrain at " +
|
||||
Ogre::StringConverter::toString(x) + " " +
|
||||
Ogre::StringConverter::toString(y));
|
||||
// collider_queue.push_back(
|
||||
// { terrainGroup, x, y, heightMapCollider });
|
||||
delete[] heightMap;
|
||||
collider_queue.push_back({ terrainGroup, x, y });
|
||||
}
|
||||
bool frameStarted(const Ogre::FrameEvent &evt) override
|
||||
{
|
||||
(void)evt;
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
void update()
|
||||
{
|
||||
static bool created = false;
|
||||
std::deque<struct gen_collider> output;
|
||||
while (!collider_queue.empty()) {
|
||||
Ogre::TerrainGroup *group =
|
||||
collider_queue.front().group;
|
||||
long x = collider_queue.front().x;
|
||||
long y = collider_queue.front().y;
|
||||
Ogre::Terrain *terrain = group->getTerrain(x, y);
|
||||
Ogre::Vector3 worldPos;
|
||||
group->convertTerrainSlotToWorldPosition(x, y,
|
||||
&worldPos);
|
||||
if (terrain && terrain->getHeightData() &&
|
||||
terrain->isLoaded() &&
|
||||
!terrain->isDerivedDataUpdateInProgress()) {
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"can create collider for " +
|
||||
Ogre::StringConverter::toString(x) +
|
||||
" " +
|
||||
Ogre::StringConverter::toString(y));
|
||||
float minH = terrain->getMinHeight();
|
||||
float maxH = terrain->getMaxHeight();
|
||||
int size = terrain->getSize();
|
||||
float worldSize = terrain->getWorldSize();
|
||||
if (!created || true) {
|
||||
btRigidBody *body =
|
||||
mWorld->addTerrainRigidBody(
|
||||
group, x, y, 2,
|
||||
0x7ffffffd & (~16));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"created rigid body " +
|
||||
Ogre::StringConverter::toString(
|
||||
Ogre::Bullet::convert(
|
||||
body->getWorldTransform()
|
||||
.getOrigin())));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"minHeight " +
|
||||
Ogre::StringConverter::toString(
|
||||
minH));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"maxHeight " +
|
||||
Ogre::StringConverter::toString(
|
||||
maxH));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"size " +
|
||||
Ogre::StringConverter::toString(
|
||||
size));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"world size " +
|
||||
Ogre::StringConverter::toString(
|
||||
worldSize));
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"created collider for " +
|
||||
Ogre::StringConverter::toString(
|
||||
x) +
|
||||
" " +
|
||||
Ogre::StringConverter::toString(
|
||||
y));
|
||||
created = true;
|
||||
}
|
||||
collider_queue.pop_front();
|
||||
} else {
|
||||
output.push_back(collider_queue.front());
|
||||
collider_queue.pop_front();
|
||||
}
|
||||
}
|
||||
collider_queue = output;
|
||||
}
|
||||
};
|
||||
class DummyPageProvider : public Ogre::PageProvider {
|
||||
public:
|
||||
DummyPageProvider(btDynamicsWorld *world)
|
||||
: Ogre::PageProvider()
|
||||
, mBtWorld(world)
|
||||
{
|
||||
}
|
||||
std::unordered_map<Ogre::PageID, btRigidBody *> body;
|
||||
btDynamicsWorld *mBtWorld;
|
||||
bool prepareProceduralPage(Ogre::Page *page,
|
||||
Ogre::PagedWorldSection *section)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool loadProceduralPage(Ogre::Page *page,
|
||||
Ogre::PagedWorldSection *section)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool unloadProceduralPage(Ogre::Page *page,
|
||||
Ogre::PagedWorldSection *section)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool unprepareProceduralPage(Ogre::Page *page,
|
||||
Ogre::PagedWorldSection *section)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct TerrainPrivate {
|
||||
DummyPageProvider *mDummyPageProvider;
|
||||
Ogre::Timer mSunUpdate;
|
||||
};
|
||||
|
||||
TerrainModule::TerrainModule(flecs::world &ecs)
|
||||
{
|
||||
ecs.component<Terrain>().add(flecs::Singleton);
|
||||
ecs.component<TerrainPrivate>().add(flecs::Singleton);
|
||||
ecs.set<TerrainPrivate>({ nullptr, {} });
|
||||
ecs.system<const EngineData, const Camera, const Sun, Terrain,
|
||||
TerrainPrivate>("SetupUpdateTerrain")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([](const EngineData &eng, const Camera &camera,
|
||||
const Sun &sun, Terrain &terrain,
|
||||
TerrainPrivate &priv) {
|
||||
if (!terrain.mTerrainGroup) {
|
||||
std::cout << "Terrain setup\n";
|
||||
if (!priv.mDummyPageProvider)
|
||||
priv.mDummyPageProvider =
|
||||
new DummyPageProvider(
|
||||
eng.mWorld
|
||||
->getBtWorld());
|
||||
terrain.mTerrainGlobals =
|
||||
OGRE_NEW Ogre::TerrainGlobalOptions();
|
||||
|
||||
Ogre::LogManager::getSingleton().setMinLogLevel(
|
||||
Ogre::LML_TRIVIAL);
|
||||
|
||||
terrain.mTerrainGroup =
|
||||
OGRE_NEW Ogre::TerrainGroup(
|
||||
eng.mScnMgr,
|
||||
Ogre::Terrain::ALIGN_X_Z,
|
||||
TERRAIN_SIZE,
|
||||
TERRAIN_WORLD_SIZE);
|
||||
terrain.mTerrainGroup->setFilenameConvention(
|
||||
ENDLESS_TERRAIN_FILE_PREFIX,
|
||||
ENDLESS_TERRAIN_FILE_SUFFIX);
|
||||
terrain.mTerrainGroup->setOrigin(
|
||||
terrain.mTerrainPos);
|
||||
// Configure global
|
||||
terrain.mTerrainGlobals->setMaxPixelError(0);
|
||||
// testing composite map
|
||||
// mTerrainGlobals->setCompositeMapDistance(30);
|
||||
terrain.mTerrainGlobals->setCompositeMapDistance(
|
||||
500);
|
||||
//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
|
||||
terrain.mTerrainGlobals
|
||||
->getDefaultMaterialGenerator()
|
||||
->setLightmapEnabled(false);
|
||||
|
||||
terrain.mTerrainGlobals->setCompositeMapAmbient(
|
||||
eng.mScnMgr->getAmbientLight());
|
||||
terrain.mTerrainGlobals->setCompositeMapDiffuse(
|
||||
sun.mSun->getDiffuseColour());
|
||||
terrain.mTerrainGlobals->setLightMapDirection(
|
||||
sun.mSun->getDerivedDirection());
|
||||
|
||||
// Configure default import settings for if we use imported image
|
||||
Ogre::Terrain::ImportData &defaultimp =
|
||||
terrain.mTerrainGroup
|
||||
->getDefaultImportSettings();
|
||||
defaultimp.terrainSize = TERRAIN_SIZE;
|
||||
defaultimp.worldSize = TERRAIN_WORLD_SIZE;
|
||||
defaultimp.inputScale = 1.0f;
|
||||
defaultimp.minBatchSize = 33;
|
||||
defaultimp.maxBatchSize = 65;
|
||||
Ogre::Image combined;
|
||||
combined.loadTwoImagesAsRGBA(
|
||||
"Ground23_col.jpg", "Ground23_spec.png",
|
||||
"General");
|
||||
Ogre::TextureManager::getSingleton().loadImage(
|
||||
"Ground23_diffspec", "General",
|
||||
combined);
|
||||
defaultimp.layerList.resize(1);
|
||||
|
||||
defaultimp.layerList[0].worldSize = 60;
|
||||
defaultimp.layerList[0].textureNames.push_back(
|
||||
"Ground23_diffspec");
|
||||
// Paging setup
|
||||
terrain.mPageManager =
|
||||
OGRE_NEW Ogre::PageManager();
|
||||
// Since we're not loading any pages from .page files, we need a way just
|
||||
// to say we've loaded them without them actually being loaded
|
||||
terrain.mPageManager->setPageProvider(
|
||||
priv.mDummyPageProvider);
|
||||
terrain.mPageManager->addCamera(camera.mCamera);
|
||||
terrain.mPageManager->setDebugDisplayLevel(0);
|
||||
terrain.mTerrainPaging =
|
||||
OGRE_NEW Ogre::TerrainPaging(
|
||||
terrain.mPageManager);
|
||||
terrain.mPagedWorld =
|
||||
terrain.mPageManager->createWorld();
|
||||
terrain.mTerrainPagedWorldSection =
|
||||
terrain.mTerrainPaging
|
||||
->createWorldSection(
|
||||
terrain.mPagedWorld,
|
||||
terrain.mTerrainGroup,
|
||||
300, 800,
|
||||
ENDLESS_PAGE_MIN_X,
|
||||
ENDLESS_PAGE_MIN_Y,
|
||||
ENDLESS_PAGE_MAX_X,
|
||||
ENDLESS_PAGE_MAX_Y);
|
||||
|
||||
terrain.mTerrainPagedWorldSection->setDefiner(
|
||||
OGRE_NEW FlatTerrainDefiner(
|
||||
eng.mScnMgr, eng.mWorld));
|
||||
|
||||
terrain.mTerrainGroup->freeTemporaryResources();
|
||||
std::cout << "Terrain setup done\n";
|
||||
}
|
||||
bool playerCheck = false;
|
||||
ECS::get()
|
||||
.query_builder<CharacterBase, CharacterBody>()
|
||||
.with<Character>()
|
||||
.with<Player>()
|
||||
.each([&playerCheck,
|
||||
terrain](flecs::entity e,
|
||||
CharacterBase &ch,
|
||||
CharacterBody &body) {
|
||||
if (!body.checkGround)
|
||||
body.checkGround = true;
|
||||
if (ch.mBodyNode &&
|
||||
body.checkGroundResult) {
|
||||
long x, y;
|
||||
Ogre::Vector3 pos =
|
||||
ch.mBodyNode
|
||||
->getPosition();
|
||||
terrain.mTerrainGroup
|
||||
->convertWorldPositionToTerrainSlot(
|
||||
pos, &x, &y);
|
||||
if (terrain.mTerrainGroup
|
||||
->getTerrain(x,
|
||||
y) &&
|
||||
terrain.mTerrainGroup
|
||||
->getTerrain(x, y)
|
||||
->isLoaded())
|
||||
playerCheck = true;
|
||||
}
|
||||
});
|
||||
if (playerCheck)
|
||||
terrain.mTerrainReady = true;
|
||||
if (priv.mSunUpdate.getMilliseconds() > 1000) {
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapAmbient(
|
||||
eng.mScnMgr->getAmbientLight());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapDiffuse(
|
||||
sun.mSun->getDiffuseColour());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setLightMapDirection(
|
||||
sun.mSun->getDerivedDirection());
|
||||
std::cout << "sun pitch: "
|
||||
<< sun.mSunNode->getOrientation()
|
||||
.getPitch()
|
||||
<< "\n";
|
||||
priv.mSunUpdate.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
30
src/gamedata/TerrainModule.h
Normal file
30
src/gamedata/TerrainModule.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef TERRAIN_MODULE_H_
|
||||
#define TERRAIN_MODULE_H
|
||||
#include <flecs.h>
|
||||
namespace Ogre
|
||||
{
|
||||
class TerrainGlobalOptions;
|
||||
class TerrainGroup;
|
||||
class TerrainPaging;
|
||||
class PageManager;
|
||||
class PagedWorld;
|
||||
class TerrainPagedWorldSection;
|
||||
}
|
||||
namespace ECS
|
||||
{
|
||||
struct Terrain {
|
||||
Ogre::TerrainGlobalOptions *mTerrainGlobals;
|
||||
Ogre::TerrainGroup *mTerrainGroup;
|
||||
Ogre::TerrainPaging *mTerrainPaging;
|
||||
Ogre::PageManager *mPageManager;
|
||||
Ogre::PagedWorld *mPagedWorld;
|
||||
Ogre::TerrainPagedWorldSection *mTerrainPagedWorldSection;
|
||||
bool mTerrainReady;
|
||||
|
||||
Ogre::Vector3 mTerrainPos;
|
||||
};
|
||||
struct TerrainModule {
|
||||
TerrainModule(flecs::world &ecs);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -15,14 +15,13 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
ecs.module<WaterModule>();
|
||||
ecs.component<WaterSurface>().add(flecs::Singleton);
|
||||
ecs.component<WaterBody>().add(flecs::Singleton);
|
||||
ecs.set<WaterSurface>({ nullptr, nullptr, nullptr });
|
||||
ecs.set<WaterBody>({ nullptr });
|
||||
ecs.system<const EngineData, const Camera, WaterSurface>("UpdateWater")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([](const EngineData &eng, const Camera &camera,
|
||||
WaterSurface &water) {
|
||||
float delta = eng.delta;
|
||||
if (!water.mWaterEnt || !water.mWaterNode) {
|
||||
std::cout << "Water setup\n";
|
||||
water.mAbove = false;
|
||||
water.mInRefTexUpdate = false;
|
||||
water.mRenderTargetListener.mSurface = &water;
|
||||
@@ -273,6 +272,7 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
refractionViewport->setSkiesEnabled(false);
|
||||
refractionViewport->setAutoUpdated(false);
|
||||
water.mViewports[1] = refractionViewport;
|
||||
std::cout << "Water setup done\n";
|
||||
}
|
||||
Ogre::Vector3 mCameraPos =
|
||||
camera.mCameraNode->_getDerivedPosition();
|
||||
@@ -347,24 +347,10 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
waterBodyPos.y = 0;
|
||||
Ogre::Vector3 d = waterPos - waterBodyPos;
|
||||
d.y = 0;
|
||||
std::cout << "aabb: "
|
||||
<< Ogre::Bullet::convert(body.mShapeAabbMin)
|
||||
<< " "
|
||||
<< Ogre::Bullet::convert(body.mShapeAabbMax)
|
||||
<< "\n";
|
||||
// Ogre::Vector3 waterPosition = mCameraPos;
|
||||
// mWaterNode->setPosition(waterPosition);
|
||||
if (d.squaredLength() > 10.0f * 10.0f)
|
||||
body.mWaterBody->getWorldTransform().setOrigin(
|
||||
Ogre::Bullet::convert(waterBodyPos +
|
||||
d));
|
||||
std::cout
|
||||
<< "node: " << water.mWaterNode->getPosition()
|
||||
<< " body: "
|
||||
<< Ogre::Bullet::convert(
|
||||
body.mWaterBody->getWorldTransform()
|
||||
.getOrigin())
|
||||
<< "\n";
|
||||
btCompoundShape *mshape =
|
||||
static_cast<btCompoundShape *>(
|
||||
body.mWaterBody->getCollisionShape());
|
||||
@@ -376,12 +362,6 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
body.mWaterBody->getWorldTransform()
|
||||
.getOrigin() +
|
||||
btVector3(1000, -0.2, 1000);
|
||||
#if 0
|
||||
mshape->getChildShape(0)->getAabb(
|
||||
body.mWaterBody->getWorldTransform() *
|
||||
mshape->getChildTransform(0),
|
||||
body.mShapeAabbMin, body.mShapeAabbMax);
|
||||
#endif
|
||||
btDispatcher *dispatch =
|
||||
eng.mWorld->getBtWorld()->getDispatcher();
|
||||
eng.mWorld->getBtWorld()->getBroadphase()->setAabb(
|
||||
@@ -435,21 +415,6 @@ WaterModule::WaterModule(flecs::world &ecs)
|
||||
float dist = pt.getDistance();
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
std::cout
|
||||
<< " distance: "
|
||||
<< dist << "\n";
|
||||
contactPosA = Ogre::Bullet::convert(
|
||||
pt.getPositionWorldOnA());
|
||||
contactPosB = Ogre::Bullet::convert(
|
||||
pt.getPositionWorldOnB());
|
||||
std::cout
|
||||
<< "positionA: "
|
||||
<< contactPosA
|
||||
<< "\n";
|
||||
std::cout
|
||||
<< "positionB: "
|
||||
<< contactPosA
|
||||
<< "\n";
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,10 +302,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void TerrainSetup::setupTerrain(Ogre::Camera *camera, Ogre::Light *sun,
|
||||
void TerrainSetup::setupTerrain(Ogre::Camera *camera,
|
||||
Ogre::Bullet::DynamicsWorld *dynamicsWorld,
|
||||
Ogre::Bullet::DebugDrawer *dbgDraw)
|
||||
{
|
||||
Ogre::Light *sun = ECS::get<ECS::Sun>().mSun;
|
||||
mDynWorld.reset(dynamicsWorld);
|
||||
mDbgDraw.reset(dbgDraw);
|
||||
mScnMgr = camera->getSceneManager();
|
||||
|
||||
Reference in New Issue
Block a user