Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling authored Jan 6, 2025
1 parent 34cb7ce commit 2dd9ae1
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions samples/00_HelloWorld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,130 @@ At first we are including all needed dependecies, use the OSRE namespace and the
The we will generate our simple model-, view- and projection-matrix.

```cpp
#include "App/App.h"
#include "RenderBackend/RenderCommon.h"
#include "RenderBackend/MeshBuilder.h"
#include "RenderBackend/RenderBackendService.h"
#include "RenderBackend/TransformMatrixBlock.h"
#include "Animation/AnimatorComponent.h"
#include "App/Entity.h"
#include "Platform/AbstractWindow.h"
#include "Common/glm_common.h"

// We want to use the App component and the render backend, so use these namespaces
using namespace ::OSRE;
using namespace ::OSRE::App;
using namespace ::OSRE::RenderBackend;

class HelloWorldApp : 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;
Animation::AnimationTrack mTrack;
f32 mAngle;

public:
/// The class constructor with the incoming arguments from the command line.
HelloWorldApp(int argc, char *argv[]) :
AppBase(argc, (const char **)argv),
mTransformMatrix(),
mEntity(nullptr),
mKeyboardTransCtrl(nullptr),
mAngle(1.0f) {
// empty
}

/// The class destructor.
~HelloWorldApp() override = default;

protected:
CameraComponent *setupCamera(World *world) {
Entity *camEntity = new Entity("camera", *getIdContainer(), world);
world->addEntity(camEntity);
CameraComponent *camera =(CameraComponent*) camEntity->createComponent(ComponentType::CameraComponentType);
world->setActiveCamera(camera);
Animation::AnimatorComponent *animator = (Animation::AnimatorComponent *)camEntity->createComponent(ComponentType::AnimationComponentType);
mTrack.NumVectorChannels = 1;
mTrack.AnimationChannels = new Animation::AnimationChannel[mTrack.NumVectorChannels];
mTrack.Duration = 1.0f;
Animation::AnimationChannel channel;
Animation::RotationKey rot;
rot.Quad = glm::angleAxis(glm::radians(mAngle), glm::vec3(0.f, 1.f, 0.f));
rot.Time = 1.0f;
mTrack.AnimationChannels[0].RotationKeys.add(rot);
animator->addTrack(&mTrack);

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("Hello-World 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);
MeshBuilder meshBuilder;
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);

CameraComponent *camera = setupCamera(world);
world->init();
camera->observeBoundingBox(mEntity->getAABB());
}
mKeyboardTransCtrl = AppBase::getTransformController(mTransformMatrix);

osre_info(Tag, "Creation finished.");

return true;
}

void onUpdate() override {
Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey();
if (key != Platform::KEY_UNKNOWN) {
mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key));
}

RenderBackendService *rbSrv = ServiceProvider::getService<RenderBackendService>(ServiceType::RenderService);
rbSrv->beginPass(RenderPass::getPassNameById(RenderPassId));
{
rbSrv->beginRenderBatch("b1");
rbSrv->setMatrix(MatrixType::Model, mTransformMatrix.mModel);

rbSrv->endRenderBatch();
}
rbSrv->endPass();

AppBase::onUpdate();
}
};

int main( int argc, char *argv[] ) {
HelloWorldApp myApp( argc, argv );
if ( !myApp.create() ) {
return 1;
}
while ( myApp.handleEvents() ) {
myApp.update();
myApp.requestNextFrame();
}
myApp.destroy();
return 0;
}


#include <osre/App/AppBase.h>
#include <osre/App/Component.h>
#include <osre/App/Entity.h>
Expand Down

0 comments on commit 2dd9ae1

Please sign in to comment.