/usr/include/OGRE/SdkSample.h is in libogre-dev 1.7.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | /*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2011 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __SdkSample_H__
#define __SdkSample_H__
#include "Sample.h"
#include "SdkTrays.h"
#include "SdkCameraMan.h"
#ifdef USE_RTSHADER_SYSTEM
#include "OgreRTShaderSystem.h"
#endif
namespace OgreBites
{
/*=============================================================================
// Base SDK sample class. Includes default player camera and SDK trays.
=============================================================================*/
class SdkSample : public Sample, public SdkTrayListener
{
public:
SdkSample()
{
// so we don't have to worry about checking if these keys exist later
mInfo["Title"] = "Untitled";
mInfo["Description"] = "";
mInfo["Category"] = "Unsorted";
mInfo["Thumbnail"] = "";
mInfo["Help"] = "";
mTrayMgr = 0;
mCameraMan = 0;
mCamera = 0;
mViewport = 0;
mDetailsPanel = 0;
mCursorWasVisible = false;
mDragLook = false;
}
virtual ~SdkSample() {}
/*-----------------------------------------------------------------------------
| Manually update the cursor position after being unpaused.
-----------------------------------------------------------------------------*/
virtual void unpaused()
{
mTrayMgr->refreshCursor();
}
/*-----------------------------------------------------------------------------
| Automatically saves position and orientation for free-look cameras.
-----------------------------------------------------------------------------*/
virtual void saveState(Ogre::NameValuePairList& state)
{
if (mCameraMan->getStyle() == CS_FREELOOK)
{
state["CameraPosition"] = Ogre::StringConverter::toString(mCamera->getPosition());
state["CameraOrientation"] = Ogre::StringConverter::toString(mCamera->getOrientation());
}
}
/*-----------------------------------------------------------------------------
| Automatically restores position and orientation for free-look cameras.
-----------------------------------------------------------------------------*/
virtual void restoreState(Ogre::NameValuePairList& state)
{
if (state.find("CameraPosition") != state.end() && state.find("CameraOrientation") != state.end())
{
mCameraMan->setStyle(CS_FREELOOK);
mCamera->setPosition(Ogre::StringConverter::parseVector3(state["CameraPosition"]));
mCamera->setOrientation(Ogre::StringConverter::parseQuaternion(state["CameraOrientation"]));
}
}
virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt)
{
mTrayMgr->frameRenderingQueued(evt);
if (!mTrayMgr->isDialogVisible())
{
mCameraMan->frameRenderingQueued(evt); // if dialog isn't up, then update the camera
if (mDetailsPanel->isVisible()) // if details panel is visible, then update its contents
{
mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));
mDetailsPanel->setParamValue(1, Ogre::StringConverter::toString(mCamera->getDerivedPosition().y));
mDetailsPanel->setParamValue(2, Ogre::StringConverter::toString(mCamera->getDerivedPosition().z));
mDetailsPanel->setParamValue(4, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().w));
mDetailsPanel->setParamValue(5, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().x));
mDetailsPanel->setParamValue(6, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().y));
mDetailsPanel->setParamValue(7, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().z));
#ifdef USE_RTSHADER_SYSTEM
mDetailsPanel->setParamValue(14, Ogre::StringConverter::toString(mShaderGenerator->getVertexShaderCount()));
mDetailsPanel->setParamValue(15, Ogre::StringConverter::toString(mShaderGenerator->getFragmentShaderCount()));
#endif
}
}
return true;
}
virtual void windowResized(Ogre::RenderWindow* rw)
{
mCamera->setAspectRatio((Ogre::Real)mViewport->getActualWidth() / (Ogre::Real)mViewport->getActualHeight());
}
virtual bool keyPressed(const OIS::KeyEvent& evt)
{
if (evt.key == OIS::KC_H || evt.key == OIS::KC_F1) // toggle visibility of help dialog
{
if (!mTrayMgr->isDialogVisible() && mInfo["Help"] != "") mTrayMgr->showOkDialog("Help", mInfo["Help"]);
else mTrayMgr->closeDialog();
}
if (mTrayMgr->isDialogVisible()) return true; // don't process any more keys if dialog is up
if (evt.key == OIS::KC_F) // toggle visibility of advanced frame stats
{
mTrayMgr->toggleAdvancedFrameStats();
}
else if (evt.key == OIS::KC_G) // toggle visibility of even rarer debugging details
{
if (mDetailsPanel->getTrayLocation() == TL_NONE)
{
mTrayMgr->moveWidgetToTray(mDetailsPanel, TL_TOPRIGHT, 0);
mDetailsPanel->show();
}
else
{
mTrayMgr->removeWidgetFromTray(mDetailsPanel);
mDetailsPanel->hide();
}
}
else if (evt.key == OIS::KC_T) // cycle polygon rendering mode
{
Ogre::String newVal;
Ogre::TextureFilterOptions tfo;
unsigned int aniso;
switch (mDetailsPanel->getParamValue(9).asUTF8()[0])
{
case 'B':
newVal = "Trilinear";
tfo = Ogre::TFO_TRILINEAR;
aniso = 1;
break;
case 'T':
newVal = "Anisotropic";
tfo = Ogre::TFO_ANISOTROPIC;
aniso = 8;
break;
case 'A':
newVal = "None";
tfo = Ogre::TFO_NONE;
aniso = 1;
break;
default:
newVal = "Bilinear";
tfo = Ogre::TFO_BILINEAR;
aniso = 1;
}
Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(aniso);
mDetailsPanel->setParamValue(9, newVal);
}
else if (evt.key == OIS::KC_R) // cycle polygon rendering mode
{
Ogre::String newVal;
Ogre::PolygonMode pm;
switch (mCamera->getPolygonMode())
{
case Ogre::PM_SOLID:
newVal = "Wireframe";
pm = Ogre::PM_WIREFRAME;
break;
case Ogre::PM_WIREFRAME:
newVal = "Points";
pm = Ogre::PM_POINTS;
break;
default:
newVal = "Solid";
pm = Ogre::PM_SOLID;
}
mCamera->setPolygonMode(pm);
mDetailsPanel->setParamValue(10, newVal);
}
else if(evt.key == OIS::KC_F5) // refresh all textures
{
Ogre::TextureManager::getSingleton().reloadAll();
}
else if (evt.key == OIS::KC_SYSRQ) // take a screenshot
{
mWindow->writeContentsToTimestampedFile("screenshot", ".png");
}
#ifdef USE_RTSHADER_SYSTEM
// Toggle schemes.
else if (evt.key == OIS::KC_F2)
{
Ogre::Viewport* mainVP = mCamera->getViewport();
const Ogre::String& curMaterialScheme = mainVP->getMaterialScheme();
if (curMaterialScheme == Ogre::MaterialManager::DEFAULT_SCHEME_NAME)
{
mainVP->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
mDetailsPanel->setParamValue(11, "On");
}
else if (curMaterialScheme == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
{
mainVP->setMaterialScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
mDetailsPanel->setParamValue(11, "Off");
}
}
#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
// Toggles per pixel per light model.
else if (evt.key == OIS::KC_F3)
{
static bool usePerPixelLighting = true;
// Grab the scheme render state.
Ogre::RTShader::RenderState* schemRenderState = mShaderGenerator->getRenderState(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
// Add per pixel lighting sub render state to the global scheme render state.
// It will override the default FFP lighting sub render state.
if (usePerPixelLighting)
{
Ogre::RTShader::SubRenderState* perPixelLightModel = mShaderGenerator->createSubRenderState(Ogre::RTShader::PerPixelLighting::Type);
schemRenderState->addTemplateSubRenderState(perPixelLightModel);
}
// Search the per pixel sub render state and remove it.
else
{
const Ogre::RTShader::SubRenderStateList& subRenderStateList = schemRenderState->getTemplateSubRenderStateList();
Ogre::RTShader::SubRenderStateListConstIterator it = subRenderStateList.begin();
Ogre::RTShader::SubRenderStateListConstIterator itEnd = subRenderStateList.end();
for (; it != itEnd; ++it)
{
Ogre::RTShader::SubRenderState* curSubRenderState = *it;
// This is the per pixel sub render state -> remove it.
if (curSubRenderState->getType() == Ogre::RTShader::PerPixelLighting::Type)
{
schemRenderState->removeTemplateSubRenderState(*it);
break;
}
}
}
// Invalidate the scheme in order to re-generate all shaders based technique related to this scheme.
mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
// Update UI.
if (usePerPixelLighting)
mDetailsPanel->setParamValue(12, "Pixel");
else
mDetailsPanel->setParamValue(12, "Vertex");
usePerPixelLighting = !usePerPixelLighting;
}
#endif
// Switch vertex shader outputs compaction policy.
else if (evt.key == OIS::KC_F4)
{
switch (mShaderGenerator->getVertexShaderOutputsCompactPolicy())
{
case Ogre::RTShader::VSOCP_LOW:
mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_MEDIUM);
mDetailsPanel->setParamValue(13, "Medium");
break;
case Ogre::RTShader::VSOCP_MEDIUM:
mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_HIGH);
mDetailsPanel->setParamValue(13, "High");
break;
case Ogre::RTShader::VSOCP_HIGH:
mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_LOW);
mDetailsPanel->setParamValue(13, "Low");
break;
}
// Invalidate the scheme in order to re-generate all shaders based technique related to this scheme.
mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
}
#endif
mCameraMan->injectKeyDown(evt);
return true;
}
virtual bool keyReleased(const OIS::KeyEvent& evt)
{
mCameraMan->injectKeyUp(evt);
return true;
}
/* IMPORTANT: When overriding these following handlers, remember to allow the tray manager
to filter out any interface-related mouse events before processing them in your scene.
If the tray manager handler returns true, the event was meant for the trays, not you. */
#if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
virtual bool touchMoved(const OIS::MultiTouchEvent& evt)
#else
virtual bool mouseMoved(const OIS::MouseEvent& evt)
#endif
{
if (mTrayMgr->injectMouseMove(evt)) return true;
mCameraMan->injectMouseMove(evt);
return true;
}
#if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
virtual bool touchPressed(const OIS::MultiTouchEvent& evt)
{
if (mTrayMgr->injectMouseDown(evt)) return true;
if (mDragLook)
{
mCameraMan->setStyle(CS_FREELOOK);
mTrayMgr->hideCursor();
}
mCameraMan->injectMouseDown(evt);
return true;
}
#else
virtual bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
if (mTrayMgr->injectMouseDown(evt, id)) return true;
if (mDragLook && id == OIS::MB_Left)
{
mCameraMan->setStyle(CS_FREELOOK);
mTrayMgr->hideCursor();
}
mCameraMan->injectMouseDown(evt, id);
return true;
}
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
virtual bool touchReleased(const OIS::MultiTouchEvent& evt)
{
if (mTrayMgr->injectMouseUp(evt)) return true;
if (mDragLook)
{
mCameraMan->setStyle(CS_MANUAL);
mTrayMgr->showCursor();
}
mCameraMan->injectMouseUp(evt);
return true;
}
#else
virtual bool mouseReleased(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
if (mTrayMgr->injectMouseUp(evt, id)) return true;
if (mDragLook && id == OIS::MB_Left)
{
mCameraMan->setStyle(CS_MANUAL);
mTrayMgr->showCursor();
}
mCameraMan->injectMouseUp(evt, id);
return true;
}
#endif
/*-----------------------------------------------------------------------------
| Extended to setup a default tray interface and camera controller.
-----------------------------------------------------------------------------*/
#if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
virtual void _setup(Ogre::RenderWindow* window, OIS::MultiTouch* mouse, FileSystemLayer* fsLayer)
#else
virtual void _setup(Ogre::RenderWindow* window, OIS::Keyboard* keyboard, OIS::Mouse* mouse, FileSystemLayer* fsLayer)
#endif
{
// assign mRoot here in case Root was initialised after the Sample's constructor ran.
mRoot = Ogre::Root::getSingletonPtr();
mWindow = window;
#if OGRE_PLATFORM != OGRE_PLATFORM_IPHONE
mKeyboard = keyboard;
#endif
mMouse = mouse;
mFSLayer = fsLayer;
locateResources();
createSceneManager();
setupView();
mTrayMgr = new SdkTrayManager("SampleControls", window, mouse, this); // create a tray interface
#ifdef USE_RTSHADER_SYSTEM
// Initialize shader generator.
// Must be before resource loading in order to allow parsing extended material attributes.
bool success = initializeRTShaderSystem(mSceneMgr);
if (!success)
{
OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
"Shader Generator Initialization failed - Core shader libs path not found",
"SdkSample::_setup");
}
#endif
loadResources();
mResourcesLoaded = true;
// show stats and logo and hide the cursor
mTrayMgr->showFrameStats(TL_BOTTOMLEFT);
mTrayMgr->showLogo(TL_BOTTOMRIGHT);
mTrayMgr->hideCursor();
// create a params panel for displaying sample details
Ogre::StringVector items;
items.push_back("cam.pX");
items.push_back("cam.pY");
items.push_back("cam.pZ");
items.push_back("");
items.push_back("cam.oW");
items.push_back("cam.oX");
items.push_back("cam.oY");
items.push_back("cam.oZ");
items.push_back("");
items.push_back("Filtering");
items.push_back("Poly Mode");
#ifdef USE_RTSHADER_SYSTEM
items.push_back("RT Shaders");
items.push_back("Lighting Model");
items.push_back("Compact Policy");
items.push_back("Generated VS");
items.push_back("Generated FS");
#endif
mDetailsPanel = mTrayMgr->createParamsPanel(TL_NONE, "DetailsPanel", 200, items);
mDetailsPanel->hide();
mDetailsPanel->setParamValue(9, "Bilinear");
mDetailsPanel->setParamValue(10, "Solid");
#ifdef USE_RTSHADER_SYSTEM
mDetailsPanel->setParamValue(11, "Off");
mDetailsPanel->setParamValue(12, "Vertex");
mDetailsPanel->setParamValue(13, "Low");
mDetailsPanel->setParamValue(14, "0");
mDetailsPanel->setParamValue(15, "0");
#endif
setupContent();
mContentSetup = true;
mDone = false;
}
virtual void _shutdown()
{
Sample::_shutdown();
if (mTrayMgr) delete mTrayMgr;
if (mCameraMan) delete mCameraMan;
// restore settings we may have changed, so as not to affect other samples
Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_BILINEAR);
Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(1);
}
protected:
virtual void setupView()
{
// setup default viewport layout and camera
mCamera = mSceneMgr->createCamera("MainCamera");
mViewport = mWindow->addViewport(mCamera);
mCamera->setAspectRatio((Ogre::Real)mViewport->getActualWidth() / (Ogre::Real)mViewport->getActualHeight());
mCamera->setNearClipDistance(5);
mCameraMan = new SdkCameraMan(mCamera); // create a default camera controller
}
virtual void setDragLook(bool enabled)
{
if (enabled)
{
mCameraMan->setStyle(CS_MANUAL);
mTrayMgr->showCursor();
mDragLook = true;
}
else
{
mCameraMan->setStyle(CS_FREELOOK);
mTrayMgr->hideCursor();
mDragLook = false;
}
}
Ogre::Viewport* mViewport; // main viewport
Ogre::Camera* mCamera; // main camera
SdkTrayManager* mTrayMgr; // tray interface manager
SdkCameraMan* mCameraMan; // basic camera controller
ParamsPanel* mDetailsPanel; // sample details panel
bool mCursorWasVisible; // was cursor visible before dialog appeared
bool mDragLook; // click and drag to free-look
};
}
#endif
|