-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from kimkulling/kimkulling/prepare_terrain_re…
…ndering Kimkulling/prepare terrain rendering
- Loading branch information
Showing
22 changed files
with
360 additions
and
935 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule cppcore
updated
3 files
+2 −2 | contrib/googletest-1.10.x/googletest/src/gtest-death-test.cc | |
+1 −0 | doc/index.md | |
+59 −59 | include/cppcore/Container/TArray.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
## Terrain renderer | ||
![A simple model](../../assets/Images/01_box.png) | ||
This sample shows how to import a model using Assimp. | ||
|
||
```cpp | ||
#include <osre/App/AppBase.h> | ||
#include <osre/App/Entity.h> | ||
#include <osre/Properties/Settings.h> | ||
#include <osre/Scene/Stage.h> | ||
#include <osre/Scene/Node.h> | ||
#include <osre/Scene/View.h> | ||
#include <osre/App/World.h> | ||
#include <osre/App/AssetRegistry.h> | ||
#include <osre/App/AssimpWrapper.h> | ||
#include <osre/App/Component.h> | ||
#include <osre/IO/Uri.h> | ||
#include <osre/Platform/AbstractWindow.h> | ||
#include <osre/RenderBackend/RenderCommon.h> | ||
#include <osre/RenderBackend/RenderBackendService.h> | ||
#include <osre/Scene/GeometryBuilder.h> | ||
#include <osre/Scene/DbgRenderer.h> | ||
#include <osre/Math/BaseMath.h> | ||
|
||
using namespace ::OSRE; | ||
using namespace ::OSRE::App; | ||
using namespace ::OSRE::Common; | ||
using namespace ::OSRE::RenderBackend; | ||
using namespace ::OSRE::Scene; | ||
|
||
// To identify local log entries | ||
static const c8 *Tag = "ModelLoadingApp"; | ||
|
||
// The file to load | ||
static const char *ModelPath = "file://assets/Models/Obj/spider.obj"; | ||
|
||
static const char *AssetFolderArg = "asset_folder"; | ||
|
||
static const char* ModelArg = "model"; | ||
|
||
/// The example application, will create the render environment and render a simple triangle onto it | ||
class ModelLoadingApp : public App::AppBase { | ||
String m_assetFolder; | ||
Scene::Stage *m_stage; | ||
Scene::View *m_view; | ||
f32 m_angle; | ||
glm::mat4 m_model; | ||
TransformMatrixBlock m_transformMatrix; | ||
Node::NodePtr m_modelNode; | ||
|
||
public: | ||
ModelLoadingApp( int argc, char *argv[] ) | ||
: AppBase( argc, (const char**) argv, "api:model", "The render API:The model to load") | ||
, m_assetFolder("") | ||
, m_stage( nullptr ) | ||
, m_view( nullptr ) | ||
, m_angle( 0.0f ) | ||
, m_model() | ||
, m_transformMatrix() | ||
, m_modelNode() { | ||
// empty | ||
} | ||
|
||
virtual ~ModelLoadingApp() { | ||
// empty | ||
} | ||
|
||
protected: | ||
bool onCreate() override { | ||
if ( !AppBase::onCreate() ) { | ||
return false; | ||
} | ||
AppBase::setWindowsTitle("ModelLoader sample!"); | ||
|
||
const Common::ArgumentParser &parser = AppBase::getArgumentParser(); | ||
if ( parser.hasArgument( AssetFolderArg ) ) { | ||
m_assetFolder = parser.getArgument( AssetFolderArg ); | ||
} | ||
|
||
IO::Uri modelLoc(ModelPath); | ||
if (parser.hasArgument(ModelArg)) { | ||
String modelArg = parser.getArgument(ModelArg); | ||
String model = "file://assets/" + modelArg; | ||
modelLoc.setPath(model); | ||
} | ||
|
||
#ifdef OSRE_WINDOWS | ||
AssetRegistry::registerAssetPath( "assets", "../../assets" ); | ||
#else | ||
AssetRegistry::registerAssetPath( "assets", "../assets" ); | ||
#endif | ||
AssimpWrapper assimpWrapper(*getIdContainer()); | ||
if ( assimpWrapper.importAsset( modelLoc, 0 ) ) { | ||
RenderBackendService *rbSrv( getRenderBackendService() ); | ||
if (nullptr == rbSrv) { | ||
return false; | ||
} | ||
Platform::AbstractWindow *rootWindow(getRootWindow()); | ||
if (nullptr == rootWindow) { | ||
return false; | ||
} | ||
|
||
m_stage = AppBase::createStage("ModelLoading"); | ||
AppBase::setActiveStage(m_stage); | ||
Scene::View *view = m_stage->addView("default_view", nullptr); | ||
AppBase::setActiveView(view); | ||
|
||
const Rect2ui &windowsRect = rootWindow->getWindowsRect(); | ||
view->setProjectionParameters( 60.f, (f32) windowsRect.m_width, (f32) windowsRect.m_height, 0.01f, 1000.f ); | ||
Entity *entity = assimpWrapper.getEntity(); | ||
World *world = getActiveWorld(); | ||
world->addEntity( entity ); | ||
view->observeBoundingBox( entity->getAABB() ); | ||
m_modelNode = entity->getNode(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void onUpdate() override { | ||
// Rotate the model | ||
glm::mat4 rot( 1.0 ); | ||
m_transformMatrix.m_model = glm::rotate( rot, m_angle, glm::vec3( 0, 1, 1 ) ); | ||
|
||
m_angle += 0.01f; | ||
RenderBackendService *rbSrv( getRenderBackendService() ); | ||
|
||
rbSrv->beginPass(PipelinePass::getPassNameById(RenderPassId)); | ||
rbSrv->beginRenderBatch("b1"); | ||
|
||
rbSrv->setMatrix( MatrixType::Model, m_transformMatrix.m_model); | ||
|
||
rbSrv->endRenderBatch(); | ||
rbSrv->endPass(); | ||
|
||
Scene::DbgRenderer::getInstance()->renderDbgText(-1, -1, 2U, "XXX"); | ||
|
||
AppBase::onUpdate(); | ||
} | ||
}; | ||
|
||
OSRE_MAIN( ModelLoadingApp ) | ||
``` | ||
At first we are generating our render window as usual. In the onCreate-Method we will generate the | ||
assimp-wrapper and import a model with it. | ||
In the onUpdate-callback the model will be rotated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include <osre/App/AppBase.h> | ||
#include <osre/App/CameraComponent.h> | ||
#include <osre/App/Entity.h> | ||
#include <osre/App/World.h> | ||
#include <osre/App/Stage.h> | ||
#include <osre/App/ServiceProvider.h> | ||
#include <osre/App/TransformController.h> | ||
#include <osre/RenderBackend/RenderBackendService.h> | ||
#include <osre/RenderBackend/MeshBuilder.h> | ||
#include <osre/RenderBackend/TransformMatrixBlock.h> | ||
|
||
using namespace ::OSRE; | ||
using namespace ::OSRE::RenderBackend; | ||
using namespace ::OSRE::App; | ||
|
||
// To identify local log entries we will define this tag. | ||
static constexpr c8 Tag[] = "TerrainRenderingApp"; | ||
|
||
class TerrainRenderingApp : public App::AppBase { | ||
/// The transform block, contains the model-, view- and projection-matrix | ||
TransformMatrixBlock mTransformMatrix; | ||
/// The entity to render | ||
Entity *mEntity; | ||
/// The keyboard controller instance. | ||
Animation::AnimationControllerBase *mKeyboardTransCtrl; | ||
|
||
public: | ||
TerrainRenderingApp(int argc, char *argv[]) : | ||
AppBase(argc, (const char **)argv), | ||
mTransformMatrix(), | ||
mEntity(nullptr), | ||
mKeyboardTransCtrl(nullptr) { | ||
// empty | ||
} | ||
|
||
~TerrainRenderingApp() override { | ||
delete mEntity; | ||
} | ||
|
||
protected: | ||
bool loadHeightMap(const String &filename) { | ||
if (filename.empty()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
Camera *setupCamera(World *world) { | ||
Entity *camEntity = new Entity("camera", *getIdContainer(), world); | ||
world->addEntity(camEntity); | ||
Camera *camera =(Camera*) camEntity->createComponent(ComponentType::CameraComponentType); | ||
world->setActiveCamera(camera); | ||
ui32 w, h; | ||
AppBase::getResolution(w, h); | ||
camera->setProjectionParameters(60.f, (f32)w, (f32)h, 0.001f, 1000.f); | ||
|
||
return camera; | ||
} | ||
|
||
bool onCreate() override { | ||
if (!AppBase::onCreate()) { | ||
return false; | ||
} | ||
|
||
AppBase::setWindowsTitle("Terrain sample! Rotate with keyboard: w, a, s, d, scroll with q, e"); | ||
World *world = getStage()->addActiveWorld("hello_world"); | ||
mEntity = new Entity("entity", *AppBase::getIdContainer(), world); | ||
Camera *camera = setupCamera(world); | ||
|
||
|
||
MeshBuilder meshBuilder; | ||
RenderBackend::Mesh *mesh = meshBuilder.createCube(VertexType::ColorVertex, .5,.5,.5,BufferAccessType::ReadOnly).getMesh(); | ||
if (nullptr != mesh) { | ||
RenderComponent *rc = (RenderComponent*) mEntity->getComponent(ComponentType::RenderComponentType); | ||
rc->addStaticMesh(mesh); | ||
|
||
Time dt; | ||
world->update(dt); | ||
camera->observeBoundingBox(mEntity->getAABB()); | ||
} | ||
mKeyboardTransCtrl = AppBase::getTransformController(mTransformMatrix); | ||
|
||
osre_info(Tag, "Creation finished."); | ||
|
||
return true; | ||
} | ||
|
||
void onUpdate() override { | ||
Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey(); | ||
mKeyboardTransCtrl->update(TransformController::getKeyBinding(key)); | ||
|
||
RenderBackendService *rbSrv = ServiceProvider::getService<RenderBackendService>(ServiceType::RenderService); | ||
rbSrv->beginPass(RenderPass::getPassNameById(RenderPassId)); | ||
rbSrv->beginRenderBatch("b1"); | ||
|
||
rbSrv->setMatrix(MatrixType::Model, mTransformMatrix.m_model); | ||
|
||
rbSrv->endRenderBatch(); | ||
rbSrv->endPass(); | ||
|
||
AppBase::onUpdate(); | ||
} | ||
}; | ||
|
||
int main(int argc, char *argv[]) { | ||
TerrainRenderingApp myApp(argc, argv); | ||
if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) { | ||
return 1; | ||
} | ||
|
||
while (myApp.handleEvents()) { | ||
myApp.update(); | ||
myApp.requestNextFrame(); | ||
} | ||
|
||
myApp.destroy(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.