Updated.
This commit is contained in:
@@ -6,15 +6,28 @@
|
||||
#include "Ogre.h"
|
||||
#include "OgreApplicationContext.h"
|
||||
|
||||
class CharacterController {
|
||||
};
|
||||
|
||||
class App
|
||||
: public OgreBites::ApplicationContext
|
||||
{
|
||||
Ogre::SceneNode *mCameraNode;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
std::unique_ptr<CharacterController> mCharacter;
|
||||
public:
|
||||
App();
|
||||
virtual ~App();
|
||||
|
||||
void setup();
|
||||
void locateResources();
|
||||
void initCamera();
|
||||
Ogre::SceneManager *getSceneManager()
|
||||
{
|
||||
return mScnMgr;
|
||||
}
|
||||
void createContent();
|
||||
void createCharacter();
|
||||
};
|
||||
|
||||
App::App()
|
||||
@@ -24,6 +37,9 @@ App::App()
|
||||
void App::setup()
|
||||
{
|
||||
OgreBites::ApplicationContext::setup();
|
||||
Ogre::Root *root = getRoot();
|
||||
Ogre::SceneManager *scnMgr = root->createSceneManager();
|
||||
mScnMgr = scnMgr;
|
||||
}
|
||||
void App::locateResources()
|
||||
{
|
||||
@@ -32,7 +48,39 @@ void App::locateResources()
|
||||
App::~App()
|
||||
{
|
||||
}
|
||||
//! [key_handler]
|
||||
void App::initCamera()
|
||||
{
|
||||
// also need to tell where we are
|
||||
mCameraNode = mScnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
mCameraNode->setPosition(0, 2, 3);
|
||||
mCameraNode->lookAt(Ogre::Vector3(0, 1, -1), Ogre::Node::TS_PARENT);
|
||||
|
||||
// create the camera
|
||||
Ogre::Camera *cam = mScnMgr->createCamera("tps_camera");
|
||||
cam->setNearClipDistance(0.1f); // specific to this sample
|
||||
cam->setAutoAspectRatio(true);
|
||||
mCameraNode->attachObject(cam);
|
||||
|
||||
// and tell it to render into the main window
|
||||
getRenderWindow()->addViewport(cam);
|
||||
}
|
||||
void App::createCharacter()
|
||||
{
|
||||
|
||||
Ogre::Entity* ent = mScnMgr->createEntity("normal-male.glb");
|
||||
Ogre::SceneNode* node = mScnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
node->attachObject(ent);
|
||||
|
||||
}
|
||||
void App::createContent()
|
||||
{
|
||||
// without light we would just get a black screen
|
||||
Ogre::Light* light = mScnMgr->createLight("MainLight");
|
||||
Ogre::SceneNode* lightNode = mScnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
lightNode->setPosition(0, 10, 15);
|
||||
lightNode->attachObject(light);
|
||||
|
||||
}
|
||||
class KeyHandler : public OgreBites::InputListener
|
||||
{
|
||||
bool keyPressed(const OgreBites::KeyboardEvent& evt) override
|
||||
@@ -44,58 +92,27 @@ class KeyHandler : public OgreBites::InputListener
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//! [key_handler]
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//! [constructor]
|
||||
OgreBites::ApplicationContext ctx("OgreTutorialApp");
|
||||
App ctx;
|
||||
ctx.initApp();
|
||||
//! [constructor]
|
||||
|
||||
//! [setup]
|
||||
// get a pointer to the already created root
|
||||
Ogre::Root* root = ctx.getRoot();
|
||||
Ogre::SceneManager* scnMgr = root->createSceneManager();
|
||||
Ogre::SceneManager* scnMgr = ctx.getSceneManager();
|
||||
|
||||
// register our scene with the RTSS
|
||||
Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
|
||||
shadergen->addSceneManager(scnMgr);
|
||||
|
||||
// without light we would just get a black screen
|
||||
Ogre::Light* light = scnMgr->createLight("MainLight");
|
||||
Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
lightNode->setPosition(0, 10, 15);
|
||||
lightNode->attachObject(light);
|
||||
|
||||
// also need to tell where we are
|
||||
Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
camNode->setPosition(0, 0, 15);
|
||||
camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);
|
||||
|
||||
// create the camera
|
||||
Ogre::Camera* cam = scnMgr->createCamera("myCam");
|
||||
cam->setNearClipDistance(5); // specific to this sample
|
||||
cam->setAutoAspectRatio(true);
|
||||
camNode->attachObject(cam);
|
||||
|
||||
// and tell it to render into the main window
|
||||
ctx.getRenderWindow()->addViewport(cam);
|
||||
|
||||
// finally something to render
|
||||
// Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
|
||||
Ogre::Entity* ent = scnMgr->createEntity("normal-male.glb");
|
||||
Ogre::SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode();
|
||||
node->attachObject(ent);
|
||||
//! [setup]
|
||||
|
||||
//! [main]
|
||||
ctx.createContent();
|
||||
ctx.initCamera();
|
||||
ctx.createCharacter();
|
||||
// register for input events
|
||||
KeyHandler keyHandler;
|
||||
ctx.addInputListener(&keyHandler);
|
||||
|
||||
ctx.getRoot()->startRendering();
|
||||
ctx.closeApp();
|
||||
//! [main]
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user