Added camera and scene, started adding input. MISSING FindOIS.cmake!

actorid
Nicolay Korslund 15 years ago
parent 4d8040f96c
commit 855ca8ee74

@ -12,7 +12,9 @@ set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.cpp)
set(TOOLS tools/stringops.cpp tools/fileops.cpp) set(TOOLS tools/stringops.cpp tools/fileops.cpp)
set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp) set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp)
set(OGRE ogre/renderer.cpp) set(OGRE ogre/renderer.cpp)
set(INPUT input/oismanager.cpp)
set(GAME game/main.cpp game/esm_store/store.cpp game/cell_store.cpp) set(GAME game/main.cpp game/esm_store/store.cpp game/cell_store.cpp)
set(GAMEREND game/render/mwscene.cpp)
# Platform specific # Platform specific
if (WIN32) if (WIN32)
@ -28,5 +30,5 @@ include_directories("." ${OGRE_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${PLATFORM_INCL
link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR}) link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR})
# Main executable # Main executable
add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${GAME}) add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${INPUT} ${GAME} ${GAMEREND})
target_link_libraries(openmw ${OGRE_LIBRARIES}) target_link_libraries(openmw ${OGRE_LIBRARIES})

@ -2,9 +2,11 @@
#include "cell_store.hpp" #include "cell_store.hpp"
#include "render/cell.hpp" #include "render/cell.hpp"
#include "render/mwscene.hpp"
#include "bsa/bsa_archive.hpp" #include "bsa/bsa_archive.hpp"
#include "ogre/renderer.hpp" #include "ogre/renderer.hpp"
#include "tools/fileops.hpp" #include "tools/fileops.hpp"
#include "input/oismanager.hpp"
using namespace std; using namespace std;
@ -40,6 +42,15 @@ void maintest()
ogre.createWindow("OpenMW"); ogre.createWindow("OpenMW");
Render::MWScene scene;
scene.setup(&ogre);
Input::OISManager input;
input.setup(&ogre);
// Add the frame listener
//root->addFrameListener(&mFrameListener);
cout << "\nThat's all for now!\n"; cout << "\nThat's all for now!\n";
} }

@ -0,0 +1,50 @@
#include "mwscene.hpp"
#include <assert.h>
using namespace Render;
using namespace Ogre;
void MWScene::setup(OgreRenderer *_rend)
{
rend = _rend;
assert(rend);
Root *root = rend->getRoot();
RenderWindow *window = rend->getWindow();
// Get the SceneManager, in this case a generic one
sceneMgr = root->createSceneManager(ST_GENERIC);
// Create the camera
camera = sceneMgr->createCamera("PlayerCam");
camera->setNearClipDistance(5);
// Create one viewport, entire window
vp = window->addViewport(camera);
// Give the backround a healthy shade of green
vp->setBackgroundColour(ColourValue(0,0.1,0));
// Alter the camera aspect ratio to match the viewport
camera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
camera->setFOVy(Degree(55));
// Set default mipmap level (NB some APIs ignore this)
TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Load resources
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Turn the entire scene (represented by the 'root' node) -90
// degrees around the x axis. This makes Z go upwards, and Y go into
// the screen (when x is to the right.) This is the orientation that
// Morrowind uses, and it automagically makes everything work as it
// should.
SceneNode *rt = sceneMgr->getRootSceneNode();
mwRoot = rt->createChildSceneNode();
mwRoot->pitch(Degree(-90));
// For testing
sceneMgr->setAmbientLight(ColourValue(1,1,1));
}

@ -0,0 +1,27 @@
#ifndef _GAME_RENDER_MWSCENE_H
#define _GAME_RENDER_MWSCENE_H
#include "ogre/renderer.hpp"
namespace Render
{
/** Class responsible for Morrowind-specific interfaces to OGRE.
*/
class MWScene
{
OgreRenderer *rend;
Ogre::SceneManager *sceneMgr;
Ogre::Camera *camera;
Ogre::Viewport *vp;
// Root node for all objects added to the scene. This is rotated so
// that the OGRE coordinate system matches that used internally in
// Morrowind.
Ogre::SceneNode *mwRoot;
public:
void setup(OgreRenderer *_rend);
};
}
#endif

@ -0,0 +1,83 @@
#include "oismanager.hpp"
#include <assert.h>
#include <string>
#include <sstream>
using namespace Input;
using namespace Ogre;
using namespace OIS;
#include <iostream>
using namespace std;
void OISManager::setup(Render::OgreRenderer *rend)
{
assert(rend);
RenderWindow *window = rend->getWindow();
assert(window);
size_t windowHnd;
window->getCustomAttribute("WINDOW", &windowHnd);
std::ostringstream windowHndStr;
ParamList pl;
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
// Non-exclusive mouse and keyboard input in debug mode
if(true)
{
#if defined OIS_WIN32_PLATFORM
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_FOREGROUND" )));
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_NONEXCLUSIVE")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_FOREGROUND")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM
pl.insert(std::make_pair(std::string("x11_mouse_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_mouse_hide"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_keyboard_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("XAutoRepeatOn"),
std::string("true")));
#endif
}
inputMgr = InputManager::createInputSystem( pl );
// Create all devices
keyboard = static_cast<Keyboard*>(inputMgr->createInputObject
( OISKeyboard, true ));
mouse = static_cast<Mouse*>(inputMgr->createInputObject
( OISMouse, true ));
// Set mouse region
const MouseState &ms = mouse->getMouseState();
ms.width = window->getWidth();
ms.height = window->getHeight();
/*
// Register the input listener
keyboard -> setEventCallback( &mInput );
mouse -> setEventCallback( &mInput );
*/
}
void OISManager::cleanup()
{
if(inputMgr == NULL) return;
// Kill the input systems. This will reset input options such as key
// repetition.
inputMgr->destroyInputObject(keyboard);
inputMgr->destroyInputObject(mouse);
InputManager::destroyInputSystem(inputMgr);
inputMgr = NULL;
}

@ -0,0 +1,20 @@
#ifndef _INPUT_OISMANAGER_H
#define _INPUT_OISMANAGER_H
#include "ogre/renderer.hpp"
#include <OIS/OIS.h>
namespace Input
{
class OISManager
{
OIS::InputManager *inputMgr;
OIS::Mouse *mouse;
OIS::Keyboard *keyboard;
public:
void setup(Render::OgreRenderer *rend);
void cleanup();
};
}
#endif

@ -48,146 +48,6 @@ extern "C"
// E X P O R T E D F U N C T I O N S // E X P O R T E D F U N C T I O N S
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
extern "C" void ogre_cleanup()
{
// Kill the input systems. This will reset input options such as key
// repetition.
mInputManager->destroyInputObject(mKeyboard);
mInputManager->destroyInputObject(mMouse);
OIS::InputManager::destroyInputSystem(mInputManager);
// Code killing ogre has been ported already
}
// Initialize window. This will create and show the actual window.
extern "C" void ogre_initWindow()
{
TRACE("ogre_initWindow");
// Initialize OGRE.
mWindow = mRoot->initialise(true, "OpenMW", "");
// Set up the input system
using namespace OIS;
size_t windowHnd;
mWindow->getCustomAttribute("WINDOW", &windowHnd);
std::ostringstream windowHndStr;
ParamList pl;
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
// Non-exclusive mouse and keyboard input in debug mode
if(g_isDebug)
{
#if defined OIS_WIN32_PLATFORM
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_FOREGROUND" )));
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_NONEXCLUSIVE")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_FOREGROUND")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM
pl.insert(std::make_pair(std::string("x11_mouse_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_mouse_hide"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_keyboard_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("XAutoRepeatOn"),
std::string("true")));
#endif
}
mInputManager = InputManager::createInputSystem( pl );
const bool bufferedKeys = true;
const bool bufferedMouse = true;
// Create all devices
mKeyboard = static_cast<Keyboard*>(mInputManager->createInputObject
( OISKeyboard, bufferedKeys ));
mMouse = static_cast<Mouse*>(mInputManager->createInputObject
( OISMouse, bufferedMouse ));
// Set mouse region
const MouseState &ms = mMouse->getMouseState();
ms.width = mWindow->getWidth();
ms.height = mWindow->getHeight();
// Register the input listener
mKeyboard -> setEventCallback( &mInput );
mMouse -> setEventCallback( &mInput );
}
// Make a scene
extern "C" void ogre_makeScene()
{
// Get the SceneManager, in this case a generic one
mSceneMgr = mRoot->createSceneManager(ST_GENERIC);
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setNearClipDistance(5);
// Create one viewport, entire window
vp = mWindow->addViewport(mCamera);
// Give the backround a healthy shade of green
vp->setBackgroundColour(ColourValue(0,0.1,0));
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
mCamera->setFOVy(Degree(55));
// Set default mipmap level (NB some APIs ignore this)
TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Load resources
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Add the frame listener
mRoot->addFrameListener(&mFrameListener);
// Turn the entire scene (represented by the 'root' node) -90
// degrees around the x axis. This makes Z go upwards, and Y go into
// the screen (when x is to the right.) This is the orientation that
// Morrowind uses, and it automagically makes everything work as it
// should.
SceneNode *rt = mSceneMgr->getRootSceneNode();
mwRoot = rt->createChildSceneNode();
mwRoot->pitch(Degree(-90));
/*
g_light = mSceneMgr->createLight("carry");
g_light->setDiffuseColour(1,0.7,0.3);
g_light->setAttenuation(2000, 0, 0.008, 0);
*/
}
/*
// Toggle carryable light
extern "C" void ogre_toggleCarryLight()
{
if(g_spotOn == 0)
{
g_light->setVisible(true);
g_spotOn = 1;
}
else
{
g_light->setVisible(false);
g_spotOn = 0;
}
}
*/
// Toggle ambient light // Toggle ambient light
extern "C" void ogre_toggleLight() extern "C" void ogre_toggleLight()
{ {
@ -212,13 +72,6 @@ extern "C" void ogre_toggleLight()
} }
} }
// Create a sky dome. Currently disabled since we aren't including the
// Ogre example data (which has the sky material.)
extern "C" void ogre_makeSky()
{
//mSceneMgr->setSkyDome( true, "Examples/CloudySky", 5, 8 );
}
extern "C" Light* ogre_attachLight(char *name, SceneNode* base, extern "C" Light* ogre_attachLight(char *name, SceneNode* base,
float r, float g, float b, float r, float g, float b,
float radius) float radius)

@ -31,35 +31,18 @@
#include <OgreArchive.h> #include <OgreArchive.h>
#include <OgreArchiveFactory.h> #include <OgreArchiveFactory.h>
#include <OIS/OIS.h>
#include <MyGUI.h> #include <MyGUI.h>
#include "../util/dbg.h" #include "../util/dbg.h"
using namespace Ogre; using namespace Ogre;
RenderWindow* mWindow;
Root *mRoot;
SceneManager *mSceneMgr;
Camera *mCamera;
Viewport *vp;
ColourValue g_ambient; ColourValue g_ambient;
int g_lightOn = 0; int g_lightOn = 0;
/*
int g_spotOn = 0;
Light *g_light;
*/
// Set to nonzero if debug mode is enabled // Set to nonzero if debug mode is enabled
int g_isDebug = 0; int g_isDebug = 0;
OIS::InputManager *mInputManager;
OIS::Mouse *mMouse;
OIS::Keyboard *mKeyboard;
// The global GUI object // The global GUI object
MyGUI::Gui *mGUI; MyGUI::Gui *mGUI;
@ -68,11 +51,6 @@ MyGUI::Gui *mGUI;
// input into MyGUI. // input into MyGUI.
int32_t guiMode = 0; int32_t guiMode = 0;
// Root node for all objects added to the scene. This is rotated so
// that the OGRE coordinate system matches that used internally in
// Morrowind.
SceneNode *mwRoot;
// Include the other parts of the code, and make one big happy object // Include the other parts of the code, and make one big happy object
// file. This is extremely against the grain of C++ "recomended // file. This is extremely against the grain of C++ "recomended
// practice", but I don't care. // practice", but I don't care.

Loading…
Cancel
Save