11 input
->destroyInputObject(keyboard
);
14 input
->destroyInputObject(mouse
);
16 input
->destroyInputSystem(input
);
20 void Game::init(Root
*root
, RenderWindow
*win
, bool buf
) {
21 sceneMgr
= root
->createSceneManager(ST_GENERIC
);
27 OverlayManager
*overlay
= OverlayManager::getSingletonPtr();
28 overlay
->getByName("PanelOverlay")->show();
30 // FontManager::getSingleton().getByName("kkt")->load();
32 cam_pos
= static_cast<OverlayElement
*>(overlay
->getOverlayElement("CamPos"));
33 cam_pos
->setCaption("cam: "+StringConverter::toString(cam
->getPosition()));
38 void Game::initInput(RenderWindow
*win
, bool buf
) {
40 win
->getCustomAttribute("WINDOW",&handle
);
42 input
= OIS::InputManager::createInputSystem(handle
);
44 keyboard
= static_cast<OIS::Keyboard
*>(input
->createInputObject(OIS::OISKeyboard
, buf
));
45 keyboard
->setEventCallback(this);
47 mouse
= static_cast<OIS::Mouse
*>(input
->createInputObject(OIS::OISMouse
, buf
));
48 mouse
->setEventCallback(this);
52 win
->getMetrics(w
,h
,d
,t
,l
);
56 void Game::initCamera() {
57 cam
= sceneMgr
->createCamera("cam1");
58 cam
->setNearClipDistance(5.0f
);
59 cam
->setFarClipDistance(1000.0f
);
61 cam
->setPosition(Vector3(0,110,44)); // 106.5, 49
62 cam
->lookAt(Vector3(0,0,0));
65 void Game::initViewport(RenderWindow
*win
) {
66 vp
= win
->addViewport(cam
);
67 vp
->setBackgroundColour(ColourValue::Black
);
68 vp
->setDimensions(0.0f
,0.0f
,1.0f
,1.0f
);
69 vp
->setSkiesEnabled(false);
70 cam
->setAspectRatio(Real(vp
->getActualWidth())/Real(vp
->getActualHeight()));
73 void Game::setMouseArea(int w
, int h
) {
74 const OIS::MouseState
&ms
= mouse
->getMouseState();
79 void Game::setWinSize(int w
, int h
) {
81 cam
->setAspectRatio(Real(vp
->getActualWidth())/Real(vp
->getActualHeight()));
84 void Game::capture() {
89 void Game::update(unsigned long time
) {
90 if (keyboard
->isKeyDown(OIS::KC_W
))
91 cam
->moveRelative(Vector3(0,0,-0.1));
92 if (keyboard
->isKeyDown(OIS::KC_S
))
93 cam
->moveRelative(Vector3(0,0,0.1));
94 if (keyboard
->isKeyDown(OIS::KC_A
))
95 cam
->moveRelative(Vector3(0,-0.1,0));
96 if (keyboard
->isKeyDown(OIS::KC_D
))
97 cam
->moveRelative(Vector3(0,0.1,0));
99 cam_pos
->setCaption("cam: "+StringConverter::toString(cam
->getPosition()));
106 bool Game::loadLevel(const std::string
&name
) {
108 if ((fr
= fopen("data/levels/level01.map", "r")) == NULL
) {
109 std::cerr
<< "Chyba: nelze otevrit soubor data/levels/level01.map\n";
114 for (int y
= 0; y
< MAP_SIZE
; y
++) {
115 for (int x
= 0; x
< MAP_SIZE
; x
++) {
117 map
[x
][y
] = tmp
- '0';
123 sceneMgr
->setAmbientLight(ColourValue(0.25,0.25,0.25));
125 Light
*l
= sceneMgr
->createLight("light1");
126 l
->setPosition(0,200,0);
127 //l->setDiffuseColour(ColourValue::White);
128 //l->setSpecularColour(ColourValue::White);
130 Plane
ground(Vector3::UNIT_Y
, 0);
131 MeshManager::getSingleton().createPlane("ground_mesh",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
,ground
,100,100,10,10,true,1,1,1,Vector3::UNIT_Z
);
132 Entity
*ground_ent
= sceneMgr
->createEntity("ground_ent","ground_mesh");
133 ground_ent
->setMaterialName("Green");
134 sceneMgr
->getRootSceneNode()->createChildSceneNode()->attachObject(ground_ent
);
136 MeshPtr cube_mesh
= createCubeMesh(sceneMgr
, "cube_mesh", "Yellow", CUBE_SIZE
);
137 // Entity *cube_ent;// = sceneMgr->createEntity("cube_ent1", "cube_mesh");
139 map_node
= sceneMgr
->getRootSceneNode()->createChildSceneNode("map_node");
140 map_node
->setPosition(-50,0,-50);
143 std::string
cube_name("cube_ent");
144 for (int y
= 0; y
< MAP_SIZE
; y
++)
145 for (int x
= 0; x
< MAP_SIZE
; x
++)
146 if (map
[x
][y
] != 0) {
147 cube
= map_node
->createChildSceneNode();
149 cube
->attachObject(sceneMgr
->createEntity(cube_name
,"cube_mesh"));
150 cube
->setPosition(x
*CUBE_SIZE
,0,y
*CUBE_SIZE
);
156 bool Game::keyPressed(const OIS::KeyEvent
&e
) {
160 bool Game::keyReleased(const OIS::KeyEvent
&e
) {
162 case OIS::KC_Q
: quit();
170 bool Game::mouseMoved(const OIS::MouseEvent
&e
) {
174 bool Game::mousePressed(const OIS::MouseEvent
&e
, OIS::MouseButtonID id
) {
178 bool Game::mouseReleased(const OIS::MouseEvent
&e
, OIS::MouseButtonID id
) {