Ogre Version: 14.2.0
Operating System: Windows 10 Pro
Render System: OpenGL3+
Hello!
I am hammering the tutorials and would like to try out the code from samples inside my own basic application. This is more of a C++ question if any.
I did try to test a sample through this method: https://wiki.ogre3d.org/OgreBites
It gave me error that mWindow was nullptr and I guess part can be that the newer tutorials on OgreBites using ApplicationContext when setting up the application. Currently I have something simple like this:
Code: Select all
class BaseApplication : public ApplicationContext, public FrameListener, public InputListener
{
public:
BaseApplication();
virtual ~BaseApplication() {
}
void setup();
bool keyPressed(const KeyboardEvent& evt);
private:
SceneManager* _ScnMgr;
Root* _Root;
Camera* _Cam;
};
BaseApplication::BaseApplication() : ApplicationContext ("OGREsamples") {
_ScnMgr = nullptr;
_Root = nullptr;
_Cam = nullptr;
}
void BaseApplication::setup() {
// do not forget to call the base first
ApplicationContext::setup();
addInputListener(this);
// ...
}
int main(int argc, char** argv)
{
try
{
BaseApplication app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
}
catch (const std::exception& e)
{
std::cerr << "Error occurred during execution: " << e.what() << '\n';
return 1;
}
return 0;
}
My question is how I easily could use like the class SinbadCharacterController to set up a body, a cameraman to the entity and using the functions of inputhandling found in the class definitions. When testing other topics I have run into some access violations at times when my own application would try to use elsewhere defined variables in SDK like mTrayManager and mWindow, etc.
For testing I'd like some opinions in how to min-max using the most out of the sample code and run it in cohesion with my BaseApplication app.
One option is to pick in the codebase and grab what is needed and use it in my app, but I believe it can be tedious since the samples are already well written.
Example:
How would I go about if I'd like the InputListener to use the keyPressed functions defined in CharacterSample.h?
How would you go about to setupBody, setupCamera and setupAnimations for sinbad? My guess is that I would go about to let my BaseApplication inherit from SinbadCharacterController class, or use SinbadCharacterController::setupBody() inside my own BaseApplication::setup().
I am in the midst of coding and testing so I will use any input and tips you have. My initiative for this post is that I tend to get access violation at times and still have some confusion how the ApplicationContext sets up the application.
Cheers!
Code: Select all
class _OgreSampleClassExport Sample_Character : public SdkSample
{
public:
Sample_Character()
{
// ...
}
bool frameRenderingQueued(const FrameEvent& evt) override
{
// let character update animations and camera
mChara->addTime(evt.timeSinceLastFrame);
return SdkSample::frameRenderingQueued(evt);
}
bool keyPressed(const KeyboardEvent& evt) override
{
// relay input events to character controller
if (!mTrayMgr->isDialogVisible()) mChara->injectKeyDown(evt);
return SdkSample::keyPressed(evt);
}
// ...
};