1 /*
2   -----------------------------------------------------------------------------
3   This source file is part of OGRE
4   (Object-oriented Graphics Rendering Engine)
5   For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9   Permission is hereby granted, free of charge, to any person obtaining a copy
10   of this software and associated documentation files (the "Software"), to deal
11   in the Software without restriction, including without limitation the rights
12   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13   copies of the Software, and to permit persons to whom the Software is
14   furnished to do so, subject to the following conditions:
15 
16   The above copyright notice and this permission notice shall be included in
17   all copies or substantial portions of the Software.
18 
19   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25   THE SOFTWARE.
26   -----------------------------------------------------------------------------
27 */
28 
29 #include "PlayPenTests.h"
30 #include "OgreResourceGroupManager.h"
31 #include "OgreCodec.h"
32 #include "OgreFileSystemLayer.h"
33 #include "OgreLodConfig.h"
34 #include "OgreMovablePlane.h"
35 #include "OgreRectangle2D.h"
36 #include "OgreMovableObject.h"
37 #include "OgreBillboard.h"
38 #include "OgreParticleSystem.h"
39 
40 #ifdef OGRE_BUILD_COMPONENT_MESHLODGENERATOR
41 #include "OgreMeshLodGenerator.h"
42 #endif
43 
44 using namespace Ogre;
45 
46 static void createRandomEntityClones(Entity* ent, size_t cloneCount,
47     const Vector3& min, const Vector3& max, SceneManager* mgr);
48 
49 #ifdef OGRE_BUILD_COMPONENT_MESHLODGENERATOR
PlayPen_ManualLOD()50 PlayPen_ManualLOD::PlayPen_ManualLOD()
51 {
52     mInfo["Title"] = "PlayPen_ManualLOD";
53     mInfo["Description"] = "Testing meshes with manual LODs assigned";
54     addScreenshotFrame(75);
55 }
56 //---------------------------------------------------------------------------
57 
setupContent()58 void PlayPen_ManualLOD::setupContent()
59 {
60     String meshName = getLODMesh();
61 
62     Entity *ent;
63     for (int i = 0; i < 5; ++i)
64     {
65         ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), meshName);
66         // Add entity to the scene node
67         SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(
68             Vector3(0, 0, (i * 50) - (5 * 50 / 2)));
69         n->setScale(0.2, 0.2, 0.2);
70         n->attachObject(ent);
71     }
72 
73     mAnimation = ent->getAnimationState("Walk");
74     mAnimation->setEnabled(true);
75 
76     // Give it a little ambience with lights
77     Light* l;
78     l = mSceneMgr->createLight("BlueLight");
79     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200,-80,-100))->attachObject(l);
80     l->setDiffuseColour(0.5, 0.5, 1.0);
81 
82     l = mSceneMgr->createLight("GreenLight");
83     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,-100))->attachObject(l);
84     l->setDiffuseColour(0.5, 1.0, 0.5);
85 
86     // Position the camera
87     mCameraNode->setPosition(100,25,100);
88     mCameraNode->lookAt(Vector3(-50, 0, -25), Node::TS_PARENT);
89 
90     mSceneMgr->setAmbientLight(ColourValue::White);
91 }
92 //---------------------------------------------------------------------------
93 
frameStarted(const FrameEvent & evt)94 bool PlayPen_ManualLOD::frameStarted(const FrameEvent& evt)
95 {
96     mAnimation->addTime(evt.timeSinceLastFrame);
97     return true;
98 }
99 //-----------------------------------------------------------------------
100 
getLODMesh()101 String PlayPen_ManualLOD::getLODMesh()
102 {
103     MeshPtr msh1 = MeshManager::getSingleton().load("robot.mesh", ASSETS_RESOURCE_GROUP);
104 
105     LodConfig lodConfig(msh1);
106     lodConfig.createManualLodLevel(136, "razor.mesh");
107     lodConfig.createManualLodLevel(211, "sphere.mesh");
108     MeshLodGenerator().generateLodLevels(lodConfig);
109 
110     return msh1->getName();
111 }
112 //---------------------------------------------------------------------------
113 //---------------------------------------------------------------------------
114 
PlayPen_ManualLODFromFile()115 PlayPen_ManualLODFromFile::PlayPen_ManualLODFromFile()
116 {
117     mInfo["Title"] = "PlayPen_ManualLOD_File";
118     mInfo["Description"] = "Testing meshes with manual LODs assigned, loaded from a file";
119     addScreenshotFrame(75);
120 }
121 //---------------------------------------------------------------------
122 
getLODMesh()123 String PlayPen_ManualLODFromFile::getLODMesh()
124 {
125     MeshPtr msh1 = MeshManager::getSingleton().load("robot.mesh", ASSETS_RESOURCE_GROUP);
126 
127     LodConfig lodConfig(msh1);
128     lodConfig.createManualLodLevel(136, "razor.mesh");
129     lodConfig.createManualLodLevel(211, "sphere.mesh");
130     MeshLodGenerator().generateLodLevels(lodConfig);
131 
132     // this time, we save this data to a file and re-load it
133 
134     MeshSerializer ser;
135     const ResourceGroupManager::LocationList& ll =
136         ResourceGroupManager::getSingleton().getResourceLocationList("Tests");
137     String prefix;
138     for (ResourceGroupManager::LocationList::const_iterator i = ll.begin(); i != ll.end(); ++i)
139     {
140         if (StringUtil::endsWith(i->archive->getName(), "media"))
141         {
142             prefix = i->archive->getName();
143         }
144     }
145     ser.exportMesh(msh1.get(), prefix + "/testlod.mesh");
146 
147     MeshManager::getSingleton().removeAll();
148 
149     return "testlod.mesh";
150 }
151 #endif
152 //---------------------------------------------------------------------------
153 //---------------------------------------------------------------------------
154 
PlayPen_ManualBlend()155 PlayPen_ManualBlend::PlayPen_ManualBlend()
156 {
157     mInfo["Title"] = "PlayPen_ManualBlending";
158     mInfo["Description"] = "Manual blending";
159     addScreenshotFrame(10);
160 }
161 //---------------------------------------------------------------------------
162 
setupContent()163 void PlayPen_ManualBlend::setupContent()
164 {
165     // create material
166     MaterialPtr mat = MaterialManager::getSingleton().create("TestMat",
167                                                              TRANSIENT_RESOURCE_GROUP);
168     Pass * p = mat->getTechnique(0)->getPass(0);
169     p->setLightingEnabled(false);
170     p->createTextureUnitState("Dirt.jpg");
171     TextureUnitState* t = p->createTextureUnitState("ogrelogo.png");
172     t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT,
173                             ColourValue::White, ColourValue::White, 0.75);
174 
175     Entity *planeEnt = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
176     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt);
177     planeEnt->setMaterialName("TestMat");
178 
179     mCameraNode->setPosition(0,0,600);
180     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
181 }
182 //---------------------------------------------------------------------
183 //---------------------------------------------------------------------
184 
PlayPen_ProjectSphere()185 PlayPen_ProjectSphere::PlayPen_ProjectSphere()
186 {
187     mInfo["Title"] = "PlayPen_ProjectSphere";
188     mInfo["Description"] = "Projecting a sphere's bounds onto the camera.";
189     addScreenshotFrame(10);
190 }
191 //---------------------------------------------------------------------------
192 
setupContent()193 void PlayPen_ProjectSphere::setupContent()
194 {
195     mSceneMgr->setAmbientLight(ColourValue::White);
196 
197     Plane plane;
198     plane.normal = Vector3::UNIT_Y;
199     plane.d = 0;
200     MeshManager::getSingleton().createPlane("Myplane",
201                                             TRANSIENT_RESOURCE_GROUP, plane,
202                                             4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
203     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
204     pPlaneEnt->setMaterialName("Examples/GrassFloor");
205     pPlaneEnt->setCastShadows(false);
206     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
207 
208     mProjectionSphere = new Sphere(Vector3(0, 2000, 0), 1500.0);
209 
210     ManualObject* debugSphere = mSceneMgr->createManualObject("debugSphere");
211     debugSphere->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
212 
213     for (int i = 0; i <= 20; ++i)
214     {
215         Vector3 basePos(mProjectionSphere->getRadius(), 0, 0);
216         Quaternion quat;
217         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y);
218         basePos = quat * basePos;
219         debugSphere->position(basePos);
220     }
221     for (int i = 0; i <= 20; ++i)
222     {
223         Vector3 basePos(mProjectionSphere->getRadius(), 0, 0);
224         Quaternion quat;
225         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Z);
226         basePos = quat * basePos;
227         debugSphere->position(basePos);
228     }
229 
230     debugSphere->end();
231 
232     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,2000,0))->attachObject(debugSphere);
233 
234     MaterialPtr mat = MaterialManager::getSingleton().create(
235         "scissormat", TRANSIENT_RESOURCE_GROUP);
236     Pass* p = mat->getTechnique(0)->getPass(0);
237     p->setDepthWriteEnabled(false);
238     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
239     TextureUnitState* t = p->createTextureUnitState();
240     t->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT,
241                             ColourValue::Red);
242     t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 0.5f);
243 
244 
245     mScissorRect = mSceneMgr->createManualObject("mScissorRect");
246     mScissorRect->setUseIdentityProjection(true);
247     mScissorRect->setUseIdentityView(true);
248     AxisAlignedBox aabb;
249     aabb.setInfinite();
250     mScissorRect->setBoundingBox(aabb);
251     mScissorRect->begin(mat->getName());
252     mScissorRect->position(Vector3::ZERO);
253     mScissorRect->position(Vector3::ZERO);
254     mScissorRect->position(Vector3::ZERO);
255     mScissorRect->quad(0, 1, 2, 3);
256     mScissorRect->end();
257     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mScissorRect);
258 
259     mCameraNode->setPosition(0,3000,5000);
260     mCameraNode->lookAt(mProjectionSphere->getCenter(), Node::TS_PARENT);
261 
262 }
263 //---------------------------------------------------------------------------
264 
frameStarted(const FrameEvent & evt)265 bool PlayPen_ProjectSphere::frameStarted(const FrameEvent& evt)
266 {
267     Real left, top, right, bottom;
268     mCamera->projectSphere(*mProjectionSphere, &left, &top, &right, &bottom);
269 
270     mScissorRect->beginUpdate(0);
271     mScissorRect->position(left, top, 0);
272     mScissorRect->position(left, bottom, 0);
273     mScissorRect->position(right, bottom, 0);
274     mScissorRect->position(right, top, 0);
275     mScissorRect->quad(0,1,2,3);
276     mScissorRect->end();
277     return true;
278 }
279 //---------------------------------------------------------------------
280 //---------------------------------------------------------------------
281 
PlayPen_CameraSetDirection()282 PlayPen_CameraSetDirection::PlayPen_CameraSetDirection()
283     : mUseParentNode(false)
284     , mUseFixedYaw(true)
285     , mFocus(100,200,-300)
286 {
287     mInfo["Title"] = "PlayPen_CameraSetDirection";
288     mInfo["Description"] = "Testing various settings for Camera::setDirection";
289     addScreenshotFrame(10);
290 }
291 //---------------------------------------------------------------------
292 
setupContent()293 void PlayPen_CameraSetDirection::setupContent()
294 {
295     mSceneMgr->setAmbientLight(ColourValue::White);
296 
297     Entity* e = mSceneMgr->createEntity("1", "knot.mesh");
298     mSceneMgr->getRootSceneNode()->createChildSceneNode(mFocus)->attachObject(e);
299 
300 
301     mCameraNode->setPosition(200,1000,1000);
302     mCameraNode->lookAt(mFocus, Node::TS_PARENT);
303 
304     //mTrayMgr->createButton(OgreBites::TL_BOTTOM, "Look At", "Look At");
305     //mTrayMgr->createCheckBox(OgreBites::TL_BOTTOM, "tglParent", "Use Parent Node");
306     //OgreBites::CheckBox* chk = mTrayMgr->createCheckBox(OgreBites::TL_BOTTOM, "tglFixedYaw", "Use Fixed Yaw");
307     //chk->setChecked(true, false);
308     //mTrayMgr->showCursor();
309     //setDragLook(true);
310 
311     mParentNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(1000, 2000, -1000));
312 
313 }
314 //---------------------------------------------------------------------
315 
buttonHit(OgreBites::Button * button)316 void PlayPen_CameraSetDirection::buttonHit(OgreBites::Button* button)
317 {
318     mCameraNode->lookAt(mFocus, Node::TS_PARENT);
319 }
320 //---------------------------------------------------------------------
321 
checkBoxToggled(OgreBites::CheckBox * box)322 void PlayPen_CameraSetDirection::checkBoxToggled(OgreBites::CheckBox* box)
323 {
324     if (box->getName() == "tglParent")
325     {
326         mUseParentNode = !mUseParentNode;
327 
328         if (mUseParentNode)
329             mParentNode->attachObject(mCamera);
330         else
331             mParentNode->detachAllObjects();
332     }
333     else if (box->getName() == "tglFixedYaw")
334     {
335         mUseFixedYaw = !mUseFixedYaw;
336         if (mUseFixedYaw)
337             mCameraNode->setFixedYawAxis(true);
338         else
339             mCameraNode->setFixedYawAxis(false);
340 
341     }
342 }
343 //---------------------------------------------------------------------
344 //---------------------------------------------------------------------
345 
PlayPen_MorphAnimationWithNormals()346 PlayPen_MorphAnimationWithNormals::PlayPen_MorphAnimationWithNormals()
347 {
348     mInfo["Title"] = "PlayPen_MorphAnimNormals";
349     mInfo["Description"] = "Testing morph animation with normals";
350     addScreenshotFrame(200);
351 }
352 //---------------------------------------------------------------------
353 
setupContent()354 void PlayPen_MorphAnimationWithNormals::setupContent()
355 {
356     // explicitly disable stencil volume prep
357     MeshManager::getSingleton().setPrepareAllMeshesForShadowVolumes(false);
358 
359     // Cannot change this to true, not possible to use software morph
360     // animation + normals with stencil shadows because the former
361     // requires pos & normals to be in the same buffer, and the latter
362     // requires positions to be on their own.
363     // bool testStencil = false;
364 
365     //if (testStencil)
366     //  mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
367 
368     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
369     Vector3 dir(-1, -1, 0.5);
370     dir.normalise();
371     Light* l = mSceneMgr->createLight("light1");
372     l->setType(Light::LT_DIRECTIONAL);
373     l->setDirection(dir);
374 
375     MeshPtr mesh = MeshManager::getSingleton().load("sphere.mesh", ASSETS_RESOURCE_GROUP);
376 
377     String morphName = "testmorphwithnormals.mesh";
378     mesh = mesh->clone(morphName);
379 
380     SubMesh* sm = mesh->getSubMesh(0);
381     // Re-organise geometry since this mesh has no animation and all
382     // vertex elements are packed into one buffer
383     VertexDeclaration* newDecl =
384         sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, true);
385     sm->vertexData->reorganiseBuffers(newDecl);
386     //if (testStencil)
387     //  sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised
388     // get the position buffer (which should now be separate);
389     const VertexElement* posElem =
390         sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
391     HardwareVertexBufferSharedPtr origbuf =
392         sm->vertexData->vertexBufferBinding->getBuffer(
393             posElem->getSource());
394 
395     // Create a new position & normal buffer with updated values
396     HardwareVertexBufferSharedPtr newbuf =
397         HardwareBufferManager::getSingleton().createVertexBuffer(
398             VertexElement::getTypeSize(VET_FLOAT3) * 2,
399             sm->vertexData->vertexCount,
400             HardwareBuffer::HBU_STATIC, true);
401     float* pSrc = static_cast<float*>(origbuf->lock(HardwareBuffer::HBL_READ_ONLY));
402     float* pDst = static_cast<float*>(newbuf->lock(HardwareBuffer::HBL_DISCARD));
403 
404     // Make the sphere turn into a cube
405     // Do this just by clamping each of the directions (we shrink it)
406     float cubeDimension = 0.3f * mesh->getBoundingSphereRadius();
407     size_t srcSkip = origbuf->getVertexSize() / sizeof(float) - 3;
408     for (size_t v = 0; v < sm->vertexData->vertexCount; ++v)
409     {
410         // x/y/z position
411         Vector3 pos;
412         for (int d = 0; d < 3; ++d)
413         {
414             if (*pSrc >= 0)
415             {
416                 pos.ptr()[d] = std::min(cubeDimension, *pSrc++);
417             }
418             else
419             {
420                 pos.ptr()[d] = std::max(-cubeDimension, *pSrc++);
421             }
422             *pDst++ = pos.ptr()[d];
423         }
424 
425         // normal
426         // this should point along the major axis
427         // unfortunately since vertices are not duplicated at edges there will be
428         // some inaccuracy here but the most important thing is to add sharp edges
429         Vector3 norm = pos.normalisedCopy();
430         norm = norm.primaryAxis();
431         *pDst++ = norm.x;
432         *pDst++ = norm.y;
433         *pDst++ = norm.z;
434 
435         pSrc += srcSkip;
436 
437     }
438 
439     origbuf->unlock();
440     newbuf->unlock();
441 
442     // create a morph animation
443     Animation* anim = mesh->createAnimation("testAnim", 10.0f);
444     VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_MORPH);
445     // re-use start positions for frame 0
446     VertexMorphKeyFrame* kf = vt->createVertexMorphKeyFrame(0);
447     kf->setVertexBuffer(origbuf);
448 
449     // Use translated buffer for mid frame
450     kf = vt->createVertexMorphKeyFrame(4.0f);
451     kf->setVertexBuffer(newbuf);
452 
453     // Pause there
454     kf = vt->createVertexMorphKeyFrame(6.0f);
455     kf->setVertexBuffer(newbuf);
456 
457     // re-use start positions for final frame
458     kf = vt->createVertexMorphKeyFrame(10.0f);
459     kf->setVertexBuffer(origbuf);
460 
461     // Export the mesh
462     String outPath, baseName;
463     String exportName = mFSLayer->getWritablePath(morphName);
464     StringUtil::splitFilename(exportName, baseName, outPath);
465     Ogre::ResourceGroupManager& resMgr = Ogre::ResourceGroupManager::getSingleton();
466     resMgr.addResourceLocation(outPath, "FileSystem", TRANSIENT_RESOURCE_GROUP, false, false);
467 
468     DataStreamPtr stream = resMgr.createResource(morphName, TRANSIENT_RESOURCE_GROUP);
469     MeshSerializer ser;
470     ser.exportMesh(mesh.get(), stream);
471     stream->close();
472 
473     // Unload old mesh to force reload
474     MeshManager::getSingleton().remove(mesh->getHandle());
475     mesh->unload();
476     mesh.reset();
477 
478     Entity* e = mSceneMgr->createEntity("test", morphName);
479     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
480     AnimationState* animState = e->getAnimationState("testAnim");
481     animState->setEnabled(true);
482     animState->setWeight(1.0f);
483     mAnimations[0] = animState;
484 
485     e = mSceneMgr->createEntity("test2", morphName);
486     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(200,0,0))->attachObject(e);
487     // test hardware morph
488     e->setMaterialName("Examples/HardwareMorphAnimationWithNormals");
489     animState = e->getAnimationState("testAnim");
490     animState->setEnabled(true);
491     animState->setWeight(1.0f);
492     mAnimations[1] = animState;
493 
494     resMgr.deleteResource(morphName, TRANSIENT_RESOURCE_GROUP);
495 
496     mCamera->setNearClipDistance(0.5);
497     mCameraNode->setPosition(0,100,-400);
498     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
499     //mSceneMgr->setShowDebugShadows(true);
500 
501     Plane plane;
502     plane.normal = Vector3::UNIT_Y;
503     plane.d = 200;
504     MeshManager::getSingleton().createPlane("Myplane",
505                                             TRANSIENT_RESOURCE_GROUP, plane,
506                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
507     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
508     pPlaneEnt->setMaterialName("2 - Default");
509     pPlaneEnt->setCastShadows(false);
510     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
511 }
512 
frameStarted(const FrameEvent & evt)513 bool PlayPen_MorphAnimationWithNormals::frameStarted(const FrameEvent& evt)
514 {
515     mAnimations[0]->addTime(evt.timeSinceLastFrame);
516     mAnimations[1]->addTime(evt.timeSinceLastFrame);
517     return true;
518 }
519 //---------------------------------------------------------------------
520 //---------------------------------------------------------------------
521 
PlayPen_MorphAnimationWithoutNormals()522 PlayPen_MorphAnimationWithoutNormals::PlayPen_MorphAnimationWithoutNormals()
523 {
524     mInfo["Title"] = "PlayPen_MorphAnimNoNormals";
525     mInfo["Description"] = "Testing morph animation without normals";
526     addScreenshotFrame(200);
527 }
528 //---------------------------------------------------------------------
529 
setupContent()530 void PlayPen_MorphAnimationWithoutNormals::setupContent()
531 {
532     //bool testStencil = false;
533 
534     //if (testStencil)
535     //    mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
536 
537     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
538     Vector3 dir(-1, -1, 0.5);
539     dir.normalise();
540     Light* l = mSceneMgr->createLight("light1");
541     l->setType(Light::LT_DIRECTIONAL);
542     l->setDirection(dir);
543 
544 
545     MeshPtr mesh = MeshManager::getSingleton().load("sphere.mesh",
546                                                     ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
547 
548     String morphName = "testmorphnonormals.mesh";
549     mesh = mesh->clone(morphName);
550 
551     SubMesh* sm = mesh->getSubMesh(0);
552     // Re-organise geometry since this mesh has no animation and all
553     // vertex elements are packed into one buffer
554     VertexDeclaration* newDecl =
555         sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, false);
556     sm->vertexData->reorganiseBuffers(newDecl);
557     //if (testStencil)
558     //    sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised
559     // get the position buffer (which should now be separate);
560     const VertexElement* posElem =
561         sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
562     HardwareVertexBufferSharedPtr origbuf =
563         sm->vertexData->vertexBufferBinding->getBuffer(
564             posElem->getSource());
565 
566     // Create a new position & normal buffer with updated values
567     HardwareVertexBufferSharedPtr newbuf =
568         HardwareBufferManager::getSingleton().createVertexBuffer(
569             VertexElement::getTypeSize(VET_FLOAT3),
570             sm->vertexData->vertexCount,
571             HardwareBuffer::HBU_STATIC, true);
572     float* pSrc = static_cast<float*>(origbuf->lock(HardwareBuffer::HBL_READ_ONLY));
573     float* pDst = static_cast<float*>(newbuf->lock(HardwareBuffer::HBL_DISCARD));
574 
575     // Make the sphere turn into a cube
576     // Do this just by clamping each of the directions (we shrink it)
577     float cubeDimension = 0.3f * mesh->getBoundingSphereRadius();
578     for (size_t v = 0; v < sm->vertexData->vertexCount; ++v)
579     {
580         // x/y/z position
581         Vector3 pos;
582         for (int d = 0; d < 3; ++d)
583         {
584             if (*pSrc >= 0)
585             {
586                 pos.ptr()[d] = std::min(cubeDimension, *pSrc++);
587             }
588             else
589             {
590                 pos.ptr()[d] = std::max(-cubeDimension, *pSrc++);
591             }
592             *pDst++ = pos.ptr()[d];
593         }
594 
595     }
596 
597     origbuf->unlock();
598     newbuf->unlock();
599 
600     // create a morph animation
601     Animation* anim = mesh->createAnimation("testAnim", 10.0f);
602     VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_MORPH);
603     // re-use start positions for frame 0
604     VertexMorphKeyFrame* kf = vt->createVertexMorphKeyFrame(0);
605     kf->setVertexBuffer(origbuf);
606 
607     // Use translated buffer for mid frame
608     kf = vt->createVertexMorphKeyFrame(4.0f);
609     kf->setVertexBuffer(newbuf);
610 
611     // Pause there
612     kf = vt->createVertexMorphKeyFrame(6.0f);
613     kf->setVertexBuffer(newbuf);
614 
615     // re-use start positions for final frame
616     kf = vt->createVertexMorphKeyFrame(10.0f);
617     kf->setVertexBuffer(origbuf);
618 
619     // Add resource location for exported mesh
620     String exportName = mFSLayer->getWritablePath(morphName);
621     String path;
622     StringUtil::splitFilename(exportName, morphName, path);
623     ResourceGroupManager::getSingleton().addResourceLocation(path, "FileSystem", TRANSIENT_RESOURCE_GROUP, false, false);
624 
625     // Export the mesh
626     DataStreamPtr stream = ResourceGroupManager::getSingleton().createResource(morphName, TRANSIENT_RESOURCE_GROUP);
627     MeshSerializer ser;
628     ser.exportMesh(mesh.get(), stream);
629     stream->close();
630 
631 
632     // Unload old mesh to force reload
633     MeshManager::getSingleton().remove(mesh->getHandle());
634     mesh->unload();
635     mesh.reset();
636 
637     Entity* e = mSceneMgr->createEntity("test", morphName);
638     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
639     AnimationState* animState = e->getAnimationState("testAnim");
640     animState->setEnabled(true);
641     animState->setWeight(1.0f);
642     mAnimations[0] = animState;
643 
644     e = mSceneMgr->createEntity("test2", morphName);
645     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(200,0,0))->attachObject(e);
646     // test hardware morph
647     e->setMaterialName("Examples/HardwareMorphAnimation");
648     animState = e->getAnimationState("testAnim");
649     animState->setEnabled(true);
650     animState->setWeight(1.0f);
651     mAnimations[1] = animState;
652 
653     ResourceGroupManager::getSingleton().deleteResource(morphName, TRANSIENT_RESOURCE_GROUP);
654 
655     mCamera->setNearClipDistance(0.5);
656     mCameraNode->setPosition(0,100,-400);
657     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
658     // mSceneMgr->setShowDebugShadows(true);
659 
660     Plane plane;
661     plane.normal = Vector3::UNIT_Y;
662     plane.d = 200;
663     MeshManager::getSingleton().createPlane("Myplane",
664                                             TRANSIENT_RESOURCE_GROUP, plane,
665                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
666     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
667     pPlaneEnt->setMaterialName("2 - Default");
668     pPlaneEnt->setCastShadows(false);
669     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
670 
671 }
672 
frameStarted(const FrameEvent & evt)673 bool PlayPen_MorphAnimationWithoutNormals::frameStarted(const FrameEvent& evt)
674 {
675     mAnimations[0]->addTime(evt.timeSinceLastFrame);
676     mAnimations[1]->addTime(evt.timeSinceLastFrame);
677     return true;
678 }
679 //---------------------------------------------------------------------
680 //---------------------------------------------------------------------
681 
PlayPen_PoseAnimationWithNormals()682 PlayPen_PoseAnimationWithNormals::PlayPen_PoseAnimationWithNormals()
683 {
684     mInfo["Title"] = "PlayPen_PoseAnimNormals";
685     mInfo["Description"] = "Testing pose animation with normals";
686     addScreenshotFrame(200);
687 }
688 //---------------------------------------------------------------------
689 
setupContent()690 void PlayPen_PoseAnimationWithNormals::setupContent()
691 {
692     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
693     Vector3 dir(-1, -1, 0.5);
694     dir.normalise();
695     Light* l = mSceneMgr->createLight("light1");
696     l->setType(Light::LT_DIRECTIONAL);
697     l->setDirection(dir);
698 
699     MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", ASSETS_RESOURCE_GROUP);
700 
701     String newName = "testposewithnormals.mesh";
702     mesh = mesh->clone(newName);
703 
704 
705     SubMesh* sm = mesh->getSubMesh(0);
706     // Re-organise geometry since this mesh has no animation and all
707     // vertex elements are packed into one buffer
708     VertexDeclaration* newDecl =
709         sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, true);
710     sm->vertexData->reorganiseBuffers(newDecl);
711 
712     // create 2 poses
713     Pose* pose = mesh->createPose(1, "pose1");
714     // Pose1 moves vertices 0, 1, 2 and 3 upward and pushes normals left
715     Vector3 offset1(0, 50, 0);
716     pose->addVertex(0, offset1, Vector3::NEGATIVE_UNIT_X);
717     pose->addVertex(1, offset1, Vector3::NEGATIVE_UNIT_X);
718     pose->addVertex(2, offset1, Vector3::NEGATIVE_UNIT_X);
719     pose->addVertex(3, offset1, Vector3::NEGATIVE_UNIT_X);
720 
721     pose = mesh->createPose(1, "pose2");
722     // Pose2 moves vertices 3, 4, and 5 to the right and pushes normals right
723     // Note 3 gets affected by both
724     Vector3 offset2(100, 0, 0);
725     pose->addVertex(3, offset2, Vector3::UNIT_X);
726     pose->addVertex(4, offset2, Vector3::UNIT_X);
727     pose->addVertex(5, offset2, Vector3::UNIT_X);
728 
729 
730     Animation* anim = mesh->createAnimation("poseanim", 20.0f);
731     VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE);
732 
733     // Frame 0 - no effect
734     vt->createVertexPoseKeyFrame(0);
735 
736     // Frame 1 - bring in pose 1 (index 0)
737     VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(3);
738     kf->addPoseReference(0, 1.0f);
739 
740     // Frame 2 - remove all
741     vt->createVertexPoseKeyFrame(6);
742 
743     // Frame 3 - bring in pose 2 (index 1)
744     kf = vt->createVertexPoseKeyFrame(9);
745     kf->addPoseReference(1, 1.0f);
746 
747     // Frame 4 - remove all
748     vt->createVertexPoseKeyFrame(12);
749 
750 
751     // Frame 5 - bring in pose 1 at 50%, pose 2 at 100%
752     kf = vt->createVertexPoseKeyFrame(15);
753     kf->addPoseReference(0, 0.5f);
754     kf->addPoseReference(1, 1.0f);
755 
756     // Frame 6 - bring in pose 1 at 100%, pose 2 at 50%
757     kf = vt->createVertexPoseKeyFrame(18);
758     kf->addPoseReference(0, 1.0f);
759     kf->addPoseReference(1, 0.5f);
760 
761     // Frame 7 - reset
762     vt->createVertexPoseKeyFrame(20);
763 
764 
765     // Export the mesh
766     String exportName = mFSLayer->getWritablePath(newName);
767     String outPath, baseName;
768     StringUtil::splitFilename(exportName, baseName, outPath);
769     Ogre::ResourceGroupManager& resMgr = Ogre::ResourceGroupManager::getSingleton();
770     resMgr.addResourceLocation(outPath, "FileSystem", TRANSIENT_RESOURCE_GROUP, false, false);
771     DataStreamPtr stream = resMgr.createResource(newName, TRANSIENT_RESOURCE_GROUP);
772     MeshSerializer ser;
773     ser.exportMesh(mesh.get(), stream);
774     stream->close();
775 
776     // Unload old mesh to force reload
777     MeshManager::getSingleton().remove(mesh->getHandle());
778     mesh->unload();
779     mesh.reset();
780 
781     Entity*  e;
782     AnimationState* animState;
783     // software pose
784     e = mSceneMgr->createEntity("test2", newName);
785     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
786     animState = e->getAnimationState("poseanim");
787     animState->setEnabled(true);
788     animState->setWeight(1.0f);
789     mAnimations[0] = animState;
790 
791     // test hardware pose
792     e = mSceneMgr->createEntity("test", newName);
793     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
794     e->setMaterialName("Examples/HardwarePoseAnimationWithNormals");
795     animState = e->getAnimationState("poseanim");
796     animState->setEnabled(true);
797     animState->setWeight(1.0f);
798     mAnimations[1] = animState;
799 
800     resMgr.deleteResource(newName, TRANSIENT_RESOURCE_GROUP);
801 
802     mCamera->setNearClipDistance(0.5);
803     mSceneMgr->setShowDebugShadows(true);
804 
805     Plane plane;
806     plane.normal = Vector3::UNIT_Y;
807     plane.d = 200;
808     MeshManager::getSingleton().createPlane("Myplane",
809                                             TRANSIENT_RESOURCE_GROUP, plane,
810                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
811     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
812     pPlaneEnt->setMaterialName("2 - Default");
813     pPlaneEnt->setCastShadows(false);
814     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
815 
816     mCameraNode->setPosition(0,-200,-300);
817     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
818 
819 }
820 //---------------------------------------------------------------------
821 
frameStarted(const FrameEvent & evt)822 bool PlayPen_PoseAnimationWithNormals::frameStarted(const FrameEvent& evt)
823 {
824     mAnimations[0]->addTime(evt.timeSinceLastFrame);
825     mAnimations[1]->addTime(evt.timeSinceLastFrame);
826     return true;
827 }
828 //---------------------------------------------------------------------
829 //---------------------------------------------------------------------
830 
PlayPen_PoseAnimationWithoutNormals()831 PlayPen_PoseAnimationWithoutNormals::PlayPen_PoseAnimationWithoutNormals()
832 {
833     mInfo["Title"] = "PlayPen_PoseAnimNoNormals";
834     mInfo["Description"] = "Testing pose animation without normals";
835     addScreenshotFrame(200);
836 }
837 //---------------------------------------------------------------------
838 
setupContent()839 void PlayPen_PoseAnimationWithoutNormals::setupContent()
840 {
841     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
842     Vector3 dir(-1, -1, 0.5);
843     dir.normalise();
844     Light* l = mSceneMgr->createLight("light1");
845     l->setType(Light::LT_DIRECTIONAL);
846     l->setDirection(dir);
847 
848     MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", ASSETS_RESOURCE_GROUP);
849 
850     String newName = "testposenonormals.mesh";
851     mesh = mesh->clone(newName);
852 
853 
854     SubMesh* sm = mesh->getSubMesh(0);
855     // Re-organise geometry since this mesh has no animation and all
856     // vertex elements are packed into one buffer
857     VertexDeclaration* newDecl =
858         sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, false);
859     sm->vertexData->reorganiseBuffers(newDecl);
860 
861     // create 2 poses
862     Pose* pose = mesh->createPose(1, "pose1");
863     // Pose1 moves vertices 0, 1, 2 and 3 upward
864     Vector3 offset1(0, 50, 0);
865     pose->addVertex(0, offset1);
866     pose->addVertex(1, offset1);
867     pose->addVertex(2, offset1);
868     pose->addVertex(3, offset1);
869 
870     pose = mesh->createPose(1, "pose2");
871     // Pose2 moves vertices 3, 4, and 5 to the right
872     // Note 3 gets affected by both
873     Vector3 offset2(100, 0, 0);
874     pose->addVertex(3, offset2);
875     pose->addVertex(4, offset2);
876     pose->addVertex(5, offset2);
877 
878 
879     Animation* anim = mesh->createAnimation("poseanim", 20.0f);
880     VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE);
881 
882     // Frame 0 - no effect
883     vt->createVertexPoseKeyFrame(0);
884 
885     // Frame 1 - bring in pose 1 (index 0)
886     VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(3);
887     kf->addPoseReference(0, 1.0f);
888 
889     // Frame 2 - remove all
890     vt->createVertexPoseKeyFrame(6);
891 
892     // Frame 3 - bring in pose 2 (index 1)
893     kf = vt->createVertexPoseKeyFrame(9);
894     kf->addPoseReference(1, 1.0f);
895 
896     // Frame 4 - remove all
897     vt->createVertexPoseKeyFrame(12);
898 
899 
900     // Frame 5 - bring in pose 1 at 50%, pose 2 at 100%
901     kf = vt->createVertexPoseKeyFrame(15);
902     kf->addPoseReference(0, 0.5f);
903     kf->addPoseReference(1, 1.0f);
904 
905     // Frame 6 - bring in pose 1 at 100%, pose 2 at 50%
906     kf = vt->createVertexPoseKeyFrame(18);
907     kf->addPoseReference(0, 1.0f);
908     kf->addPoseReference(1, 0.5f);
909 
910     // Frame 7 - reset
911     vt->createVertexPoseKeyFrame(20);
912 
913     // Export the mesh
914     String outPath, baseName;
915     String exportName = mFSLayer->getWritablePath(newName);
916     StringUtil::splitFilename(exportName, baseName, outPath);
917     Ogre::ResourceGroupManager& resMgr = Ogre::ResourceGroupManager::getSingleton();
918     resMgr.addResourceLocation(outPath, "FileSystem", TRANSIENT_RESOURCE_GROUP, false, false);
919 
920     DataStreamPtr stream = resMgr.createResource(newName, TRANSIENT_RESOURCE_GROUP);
921     MeshSerializer ser;
922     ser.exportMesh(mesh.get(), stream);
923     stream->close();
924 
925     // Unload old mesh to force reload
926     MeshManager::getSingleton().remove(mesh->getHandle());
927     mesh->unload();
928     mesh.reset();
929 
930     Entity*  e;
931     AnimationState* animState;
932     // software pose
933     e = mSceneMgr->createEntity("test2", newName);
934     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
935     animState = e->getAnimationState("poseanim");
936     animState->setEnabled(true);
937     animState->setWeight(1.0f);
938     mAnimations[0] = animState;
939 
940     // test hardware pose
941     e = mSceneMgr->createEntity("test", newName);
942     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
943     e->setMaterialName("Examples/HardwarePoseAnimation");
944     animState = e->getAnimationState("poseanim");
945     animState->setEnabled(true);
946     animState->setWeight(1.0f);
947     mAnimations[1] = animState;
948 
949     resMgr.deleteResource(newName, TRANSIENT_RESOURCE_GROUP);
950 
951     mCamera->setNearClipDistance(0.5);
952 
953     Plane plane;
954     plane.normal = Vector3::UNIT_Y;
955     plane.d = 200;
956     MeshManager::getSingleton().createPlane("Myplane",
957                                             TRANSIENT_RESOURCE_GROUP, plane,
958                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
959     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
960     pPlaneEnt->setMaterialName("2 - Default");
961     pPlaneEnt->setCastShadows(false);
962     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
963 
964     mCameraNode->setPosition(0,-200,-300);
965     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
966 }
967 //---------------------------------------------------------------------------
968 
frameStarted(const FrameEvent & evt)969 bool PlayPen_PoseAnimationWithoutNormals::frameStarted(const FrameEvent& evt)
970 {
971     mAnimations[0]->addTime(evt.timeSinceLastFrame);
972     mAnimations[1]->addTime(evt.timeSinceLastFrame);
973     return true;
974 }
975 //---------------------------------------------------------------------------
976 
PlayPen_SceneNodeTracking()977 PlayPen_SceneNodeTracking::PlayPen_SceneNodeTracking()
978 {
979     mInfo["Title"] = "PlayPen_SceneNodeTracking";
980     mInfo["Description"] = "Testing scenenode tracking.";
981     addScreenshotFrame(200);
982 }
983 //-----------------------------------------------------------------------
984 
frameStarted(const FrameEvent & evt)985 bool PlayPen_SceneNodeTracking::frameStarted(const FrameEvent& evt)
986 {
987     mAnimState->addTime(evt.timeSinceLastFrame);
988     return true;
989 }
990 //-----------------------------------------------------------------------
991 
setupContent()992 void PlayPen_SceneNodeTracking::setupContent()
993 {
994     // Set ambient light
995     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
996 
997     // Create a skydome
998     mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
999 
1000     // Create a light
1001     Light* l = mSceneMgr->createLight("MainLight");
1002     // Accept default settings: point light, white diffuse, just set position
1003     // NB I could attach the light to a SceneNode if I wanted it to move automatically with
1004     //  other objects, but I don't
1005     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(20,80,50))->attachObject(l);
1006 
1007     Entity *ent;
1008 
1009     // Define a floor plane mesh
1010     Plane p;
1011     p.normal = Vector3::UNIT_Y;
1012     p.d = 200;
1013     MeshManager::getSingleton().createPlane("FloorPlane",
1014                                             TRANSIENT_RESOURCE_GROUP,
1015                                             p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
1016 
1017     // Create an entity (the floor)
1018     ent = mSceneMgr->createEntity("floor", "FloorPlane");
1019     ent->setMaterialName("Examples/RustySteel");
1020     // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
1021     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
1022 
1023     // Add a head, give it it's own node
1024     SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1025     ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
1026     headNode->attachObject(ent);
1027 
1028     // Add another head, give it it's own node
1029     SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1030     ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
1031     headNode2->attachObject(ent);
1032 
1033     // Make sure the head node tracks the root
1034     headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z);
1035     //headNode->setFixedYawAxis(true);
1036 
1037     // Create the camera node & attach camera
1038     //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1039     //camNode->attachObject(mCamera);
1040 
1041     // set up spline animation of node
1042     Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
1043     // Spline it for nice curves
1044     anim->setInterpolationMode(Animation::IM_SPLINE);
1045     // Create a track to animate the head's node
1046     NodeAnimationTrack* track = anim->createNodeTrack(0, headNode);
1047     // Setup keyframes
1048     track->createNodeKeyFrame(0); // startposition
1049     TransformKeyFrame* key = track->createNodeKeyFrame(2.5);
1050     key->setTranslate(Vector3(500,500,-1000));
1051     key = track->createNodeKeyFrame(5);
1052     key->setTranslate(Vector3(-1500,1000,-600));
1053     key = track->createNodeKeyFrame(7.5);
1054     key->setTranslate(Vector3(0,-100,0));
1055     key = track->createNodeKeyFrame(10);
1056     key->setTranslate(Vector3(0,0,0));
1057     // Create a track to animate the second head's node
1058     track = anim->createNodeTrack(1, headNode2);
1059     // Setup keyframes
1060     track->createNodeKeyFrame(0); // startposition
1061     key = track->createNodeKeyFrame(2.5);
1062     key->setTranslate(Vector3(-500,600,-100));
1063     key = track->createNodeKeyFrame(5);
1064     key->setTranslate(Vector3(800,200,-600));
1065     key = track->createNodeKeyFrame(7.5);
1066     key->setTranslate(Vector3(200,-1000,0));
1067     key = track->createNodeKeyFrame(10);
1068     key->setTranslate(Vector3(30,70,110));
1069     // Create a new animation state to track this
1070     mAnimState = mSceneMgr->createAnimationState("CameraTrack");
1071     mAnimState->setEnabled(true);
1072 
1073     // Put in a bit of fog for the hell of it
1074     //mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);
1075 
1076     mCameraNode->setPosition(-300,600,2000);
1077 }
1078 //-----------------------------------------------------------------------
1079 //-----------------------------------------------------------------------
PlayPen_NonUniqueResourceNames()1080 PlayPen_NonUniqueResourceNames::PlayPen_NonUniqueResourceNames()
1081 {
1082     mInfo["Title"] = "PlayPen_NonUniqueResourceNames";
1083     mInfo["Description"] = "Testing resources without unique names (in different resource groups).";
1084     addScreenshotFrame(50);
1085 }
1086 //-----------------------------------------------------------------------
1087 
setupContent()1088 void PlayPen_NonUniqueResourceNames::setupContent()
1089 {
1090     // Set ambient light
1091     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
1092 
1093     // Define the required skyplane
1094     Plane plane;
1095     // 5000 world units from the camera
1096     plane.d = 5000;
1097     // Above the camera, facing down
1098     plane.normal = -Vector3::UNIT_Y;
1099     // Create the plane 10000 units wide, tile the texture 3 times
1100     mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane",10000,3);
1101 
1102     // Create a light
1103     Light* l = mSceneMgr->createLight("MainLight");
1104     // Accept default settings: point light, white diffuse, just set position
1105     // NB I could attach the light to a SceneNode if I wanted it to move automatically with
1106     //  other objects, but I don't
1107     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(20,80,50))->attachObject(l);
1108 
1109     createMeshEntity("Model1", Vector3(10, 10, 10));
1110     createMeshEntity("Model2", Vector3(-10, -10, -10));
1111 
1112     mCameraNode->setPosition(100,0,-100);
1113     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
1114 }
1115 //-----------------------------------------------------------------------
1116 
createMeshEntity(String group,Vector3 pos)1117 void PlayPen_NonUniqueResourceNames::createMeshEntity(String group, Vector3 pos)
1118 {
1119     // Get path to test resources (ugly, but the only way I can think
1120     // of to consistently get the right path (since it's determined by
1121     // cmake build location) without explicitly defining the groups in
1122     // resources.cfg).
1123     const Ogre::ResourceGroupManager::LocationList& ll = Ogre::ResourceGroupManager::getSingleton().getResourceLocationList("Tests");
1124     const Ogre::ResourceGroupManager::ResourceLocation* loc = &ll.front();
1125     Ogre::String testResourcePath = loc->archive->getName();
1126 
1127     Ogre::String meshFilePath = testResourcePath + "/" + group;
1128 
1129     Ogre::ResourceGroupManager& resMgr = Ogre::ResourceGroupManager::getSingleton();
1130     String newGroup = meshFilePath;
1131     resMgr.createResourceGroup(group, false);
1132     resMgr.addResourceLocation(meshFilePath, "FileSystem", group);
1133     resMgr.initialiseResourceGroup(group);
1134 
1135     Ogre::MeshPtr newMesh = Ogre::MeshManager::getSingleton().load("UniqueModel.MESH", group);
1136     Entity *newEnt = mSceneMgr->createEntity(group, "UniqueModel.MESH", group);
1137 
1138     SceneNode* newNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1139     newNode->attachObject(newEnt);
1140     newNode->setPosition(pos);
1141 
1142     // I was getting an assertion on some part of the skeleton loading
1143     //AnimationState* aniState =newEnt->getAnimationState(newEnt->getMesh()->getSkeleton()->getAnimation(0)->getName());
1144     //mAnimStateList.push_back(aniState);
1145     //aniState->setEnabled(true);
1146     //aniState->setLoop(true);
1147 }
1148 //-----------------------------------------------------------------------
1149 //-----------------------------------------------------------------------
1150 
PlayPen_16Textures()1151 PlayPen_16Textures::PlayPen_16Textures()
1152 {
1153     mInfo["Title"] = "PlayPen_16Textures";
1154     mInfo["Description"] = "Tests applying 16 textures in a single material.";
1155     addScreenshotFrame(10);
1156 }
1157 //----------------------------------------------------------------------------
1158 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)1159 void PlayPen_16Textures::testCapabilities(const Ogre::RenderSystemCapabilities* caps) {
1160     if(caps->getNumTextureUnits() < 16)
1161         throw Ogre::Exception(999, "Needs 16 Texture Units to run", "testCapabilities");
1162 }
1163 
setupContent()1164 void PlayPen_16Textures::setupContent()
1165 {
1166 
1167     HighLevelGpuProgramPtr frag;
1168     if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL 3+*"))
1169     {
1170         frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", TRANSIENT_RESOURCE_GROUP,
1171                                                                         "glsl", GPT_FRAGMENT_PROGRAM);
1172         String source = " \
1173         #version 130\n \
1174         uniform sampler2D tex0; \
1175         uniform sampler2D tex1; \
1176         uniform sampler2D tex2; \
1177         uniform sampler2D tex3; \
1178         uniform sampler2D tex4; \
1179         uniform sampler2D tex5; \
1180         uniform sampler2D tex6; \
1181         uniform sampler2D tex7; \
1182         uniform sampler2D tex8; \
1183         uniform sampler2D tex9; \
1184         uniform sampler2D tex10; \
1185         uniform sampler2D tex11; \
1186         uniform sampler2D tex12; \
1187         uniform sampler2D tex13; \
1188         uniform sampler2D tex14; \
1189         uniform sampler2D tex15; \
1190         in vec4 ambientUV; \
1191         out vec4 fragColour; \
1192         void main() \
1193         { \
1194         fragColour = texture(tex15, ambientUV.xy); \
1195         } \
1196         ";
1197         frag->setSource(source);
1198     }
1199     else if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL ES 2*"))
1200     {
1201         frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", TRANSIENT_RESOURCE_GROUP,
1202                                                                         "glsles", GPT_FRAGMENT_PROGRAM);
1203         frag->setSource(" \
1204                         #version 100\n \
1205                         precision highp float; \
1206                         precision highp int; \
1207                         uniform sampler2D tex0; \
1208                         uniform sampler2D tex1; \
1209                         uniform sampler2D tex2; \
1210                         uniform sampler2D tex3; \
1211                         uniform sampler2D tex4; \
1212                         uniform sampler2D tex5; \
1213                         uniform sampler2D tex6; \
1214                         uniform sampler2D tex7; \
1215                         uniform sampler2D tex8; \
1216                         uniform sampler2D tex9; \
1217                         uniform sampler2D tex10; \
1218                         uniform sampler2D tex11; \
1219                         uniform sampler2D tex12; \
1220                         uniform sampler2D tex13; \
1221                         uniform sampler2D tex14; \
1222                         uniform sampler2D tex15; \
1223                         varying vec4 ambientUV; \
1224                         void main() \
1225                         { \
1226                         gl_FragColor = texture2D(tex15, ambientUV.xy); \
1227                         } \
1228                         ");
1229     }
1230     else if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL*"))
1231     {
1232         frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", TRANSIENT_RESOURCE_GROUP,
1233                                                                         "glsl", GPT_FRAGMENT_PROGRAM);
1234         frag->setSource(" \
1235                         uniform sampler2D tex0; \
1236                         uniform sampler2D tex1; \
1237                         uniform sampler2D tex2; \
1238                         uniform sampler2D tex3; \
1239                         uniform sampler2D tex4; \
1240                         uniform sampler2D tex5; \
1241                         uniform sampler2D tex6; \
1242                         uniform sampler2D tex7; \
1243                         uniform sampler2D tex8; \
1244                         uniform sampler2D tex9; \
1245                         uniform sampler2D tex10; \
1246                         uniform sampler2D tex11; \
1247                         uniform sampler2D tex12; \
1248                         uniform sampler2D tex13; \
1249                         uniform sampler2D tex14; \
1250                         uniform sampler2D tex15; \
1251                         void main() \
1252                         { \
1253                         gl_FragColor = texture2D(tex15, gl_TexCoord[0].xy); \
1254                         } \
1255                         ");
1256     }
1257     else // DirectX
1258     {
1259         frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", TRANSIENT_RESOURCE_GROUP,
1260                                                                         "hlsl", GPT_FRAGMENT_PROGRAM);
1261         frag->setParameter("target", "ps_2_0");
1262         frag->setParameter("entry_point", "main");
1263         frag->setSource(" \
1264         float4 main( \
1265         float2 uv : TEXCOORD0, \
1266         uniform sampler2D tex0 : register(s0), \
1267         uniform sampler2D tex1 : register(s1), \
1268         uniform sampler2D tex2 : register(s2), \
1269         uniform sampler2D tex3 : register(s3), \
1270         uniform sampler2D tex4 : register(s4), \
1271         uniform sampler2D tex5 : register(s5), \
1272         uniform sampler2D tex6 : register(s6), \
1273         uniform sampler2D tex7 : register(s7), \
1274         uniform sampler2D tex8 : register(s8), \
1275         uniform sampler2D tex9 : register(s9), \
1276         uniform sampler2D tex10 : register(s10), \
1277         uniform sampler2D tex11 : register(s11), \
1278         uniform sampler2D tex12 : register(s12), \
1279         uniform sampler2D tex13 : register(s13), \
1280         uniform sampler2D tex14 : register(s14), \
1281         uniform sampler2D tex15 : register(s15) \
1282         ) : COLOR \
1283         { \
1284             return tex2D(tex15, uv); \
1285         } \
1286         ");
1287     }
1288     frag->load();
1289 
1290     MaterialPtr mat = MaterialManager::getSingleton().create("test16", TRANSIENT_RESOURCE_GROUP);
1291     Pass* p = mat->getTechnique(0)->getPass(0);
1292     p->setVertexProgram("Ogre/BasicVertexPrograms/AmbientOneTextureWithUV");
1293     p->setFragmentProgram(frag->getName());
1294     // create 15 textures the same
1295     for (int i = 0; i < 15; ++i)
1296     {
1297         p->createTextureUnitState("Dirt.jpg");
1298     }
1299     // create 16th texture differently
1300     p->createTextureUnitState("ogrelogo.png");
1301     if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL*"))
1302     {
1303         // map samplers
1304         GpuProgramParametersSharedPtr params = p->getFragmentProgramParameters();
1305         for (int i = 0; i < 16; ++i)
1306         {
1307             params->setNamedConstant(String("tex") + StringConverter::toString(i), i);
1308         }
1309 
1310     }
1311 
1312     mat->load();
1313 
1314     Entity* e = mSceneMgr->createEntity("1", "knot.mesh");
1315     e->setMaterialName(mat->getName());
1316     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
1317 
1318     mCameraNode->setPosition(0,0,250);
1319     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
1320 
1321 
1322 }
1323 //----------------------------------------------------------------------------
1324 //----------------------------------------------------------------------------
1325 
PlayPen_2bppAlphaPVR()1326 PlayPen_2bppAlphaPVR::PlayPen_2bppAlphaPVR()
1327 {
1328     mInfo["Title"] = "PlayPen_2bppAlphaPVR";
1329     mInfo["Description"] = "Tests 2bpp pvr w/ alpha.";
1330     addScreenshotFrame(10);
1331 }
1332 //----------------------------------------------------------------------------
1333 
setupContent()1334 void PlayPen_2bppAlphaPVR::setupContent()
1335 {
1336     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
1337 
1338     MaterialPtr mat = MaterialManager::getSingleton().create("testpvr",
1339                                                              TRANSIENT_RESOURCE_GROUP);
1340     Pass* p = mat->getTechnique(0)->getPass(0);
1341     p->setLightingEnabled(false);
1342     p->setCullingMode(CULL_NONE);
1343     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
1344     p->createTextureUnitState("ogreborderUp_pvr2a.pvr");
1345     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
1346     e->setMaterialName(mat->getName());
1347     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
1348     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
1349 
1350     mCameraNode->setPosition(0,0,300);
1351     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
1352 }
1353 //----------------------------------------------------------------------------
1354 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)1355 void PlayPen_2bppAlphaPVR::testCapabilities(const Ogre::RenderSystemCapabilities* caps)
1356 {
1357     Codec* codec = Codec::getCodec("pvr");
1358     if (!codec)
1359         throw Ogre::Exception(999, "No support for PVR textures.", "testCapabilities");
1360 }
1361 //----------------------------------------------------------------------------
1362 //----------------------------------------------------------------------------
1363 
PlayPen_2bppPVR()1364 PlayPen_2bppPVR::PlayPen_2bppPVR()
1365 {
1366     mInfo["Title"] = "PlayPen_2bppPVR";
1367     mInfo["Description"] = "Tests 2 bpp pvr.";
1368     addScreenshotFrame(10);
1369 }
1370 //----------------------------------------------------------------------------
1371 
setupContent()1372 void PlayPen_2bppPVR::setupContent()
1373 {
1374     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
1375 
1376     MaterialPtr mat = MaterialManager::getSingleton().create("testpvr",
1377                                                              TRANSIENT_RESOURCE_GROUP);
1378     Pass* p = mat->getTechnique(0)->getPass(0);
1379     p->setLightingEnabled(false);
1380     p->setCullingMode(CULL_NONE);
1381     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
1382     p->createTextureUnitState("ogreborderUp_pvr2.pvr");
1383     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
1384     e->setMaterialName(mat->getName());
1385     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
1386     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
1387 
1388     mCameraNode->setPosition(0,0,300);
1389     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
1390 }
1391 //----------------------------------------------------------------------------
1392 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)1393 void PlayPen_2bppPVR::testCapabilities(const Ogre::RenderSystemCapabilities* caps)
1394 {
1395     Codec* codec = Codec::getCodec("pvr");
1396     if (!codec)
1397         throw Ogre::Exception(999, "No support for PVR textures.", "testCapabilities");
1398 }
1399 //----------------------------------------------------------------------------
1400 //----------------------------------------------------------------------------
1401 
PlayPen_2Spotlights()1402 PlayPen_2Spotlights::PlayPen_2Spotlights()
1403 {
1404     mInfo["Title"] = "PlayPen_2Spotlights";
1405     mInfo["Description"] = "Tests 2 spotlights on one mesh.";
1406     addScreenshotFrame(10);
1407 }
1408 //----------------------------------------------------------------------------
1409 
setupContent()1410 void PlayPen_2Spotlights::setupContent()
1411 {
1412     SceneNode* mTestNode[5];
1413     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
1414 
1415     Light* mLight = mSceneMgr->createLight("MainLight");
1416     // Spotlight test
1417     mLight->setType(Light::LT_SPOTLIGHT);
1418     mLight->setDiffuseColour(1.0, 0.0, 0.8);
1419     mLight->setSpotlightRange(Degree(30), Degree(40));
1420     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1421     mTestNode[0]->setPosition(800,600,0);
1422     mTestNode[0]->lookAt(Vector3(800,0,0), Node::TS_WORLD);
1423     mTestNode[0]->attachObject(mLight);
1424 
1425     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1426     mLight = mSceneMgr->createLight("AnotherLight");
1427     // Spotlight test
1428     mLight->setType(Light::LT_SPOTLIGHT);
1429     mLight->setDiffuseColour(0, 1.0, 0.8);
1430     mLight->setSpotlightRange(Degree(30), Degree(40));
1431     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
1432     mTestNode[1]->setPosition(0,600,800);
1433     mTestNode[1]->lookAt(Vector3(0,0,800), Node::TS_WORLD);
1434     mTestNode[1]->attachObject(mLight);
1435 
1436     Plane plane( Vector3::UNIT_Y, -100);
1437     MeshManager::getSingleton().createPlane("Myplane",
1438                                             TRANSIENT_RESOURCE_GROUP, plane,
1439                                             3500,3500,100,100,true,1,5,5,Vector3::UNIT_Z);
1440     Entity* pPlaneEnt;
1441     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
1442     pPlaneEnt->setMaterialName("2 - Default");
1443     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
1444 
1445     mCameraNode->setPosition(-600,300,-600);
1446     mCameraNode->lookAt(Vector3(300, 0, 300), Node::TS_PARENT);
1447 
1448 }
1449 //----------------------------------------------------------------------------
1450 //----------------------------------------------------------------------------
1451 
PlayPen_4bppAlphaPVR()1452 PlayPen_4bppAlphaPVR::PlayPen_4bppAlphaPVR()
1453 {
1454     mInfo["Title"] = "PlayPen_4bppAlphaPVR";
1455     mInfo["Description"] = "Tests 4bpp pvr with alpha.";
1456     addScreenshotFrame(10);
1457 }
1458 //----------------------------------------------------------------------------
1459 
setupContent()1460 void PlayPen_4bppAlphaPVR::setupContent()
1461 {
1462     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
1463 
1464     MaterialPtr mat = MaterialManager::getSingleton().create("testpvr",
1465                                                              TRANSIENT_RESOURCE_GROUP);
1466     Pass* p = mat->getTechnique(0)->getPass(0);
1467     p->setLightingEnabled(false);
1468     p->setCullingMode(CULL_NONE);
1469     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
1470     p->createTextureUnitState("ogreborderUp_pvr4a.pvr");
1471     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
1472     e->setMaterialName(mat->getName());
1473     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
1474     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
1475 
1476     mCameraNode->setPosition(0,0,300);
1477     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
1478 }
1479 //----------------------------------------------------------------------------
1480 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)1481 void PlayPen_4bppAlphaPVR::testCapabilities(const Ogre::RenderSystemCapabilities* caps)
1482 {
1483     Codec* codec = Codec::getCodec("pvr");
1484     if (!codec)
1485         throw Ogre::Exception(999, "No support for PVR textures.", "testCapabilities");
1486 }
1487 //----------------------------------------------------------------------------
1488 //----------------------------------------------------------------------------
1489 
PlayPen_4bppPVR()1490 PlayPen_4bppPVR::PlayPen_4bppPVR()
1491 {
1492     mInfo["Title"] = "PlayPen_4bppPVR";
1493     mInfo["Description"] = "Tests 4bpp pvr.";
1494     addScreenshotFrame(10);
1495 }
1496 //----------------------------------------------------------------------------
1497 
setupContent()1498 void PlayPen_4bppPVR::setupContent()
1499 {
1500     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
1501 
1502     MaterialPtr mat = MaterialManager::getSingleton().create("testpvr",
1503                                                              TRANSIENT_RESOURCE_GROUP);
1504     Pass* p = mat->getTechnique(0)->getPass(0);
1505     p->setLightingEnabled(false);
1506     p->setCullingMode(CULL_NONE);
1507     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
1508     p->createTextureUnitState("ogreborderUp_pvr4.pvr");
1509     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
1510     e->setMaterialName(mat->getName());
1511     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
1512     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
1513 
1514     mCameraNode->setPosition(0,0,300);
1515     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
1516 }
1517 //----------------------------------------------------------------------------
1518 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)1519 void PlayPen_4bppPVR::testCapabilities(const Ogre::RenderSystemCapabilities* caps)
1520 {
1521     Codec* codec = Codec::getCodec("pvr");
1522     if (!codec)
1523         throw Ogre::Exception(999, "No support for PVR textures.", "testCapabilities");
1524 }
1525 //----------------------------------------------------------------------------
1526 //----------------------------------------------------------------------------
1527 
PlayPen_AlphaToCoverage()1528 PlayPen_AlphaToCoverage::PlayPen_AlphaToCoverage()
1529 {
1530     mInfo["Title"] = "PlayPen_AlphaToCoverage";
1531     mInfo["Description"] = "Tests alpha to coverage support.";
1532     addScreenshotFrame(10);
1533 }
1534 //----------------------------------------------------------------------------
1535 
setupContent()1536 void PlayPen_AlphaToCoverage::setupContent()
1537 {
1538 
1539     MaterialPtr mat = MaterialManager::getSingleton().create(
1540         "testa2c",
1541         TRANSIENT_RESOURCE_GROUP);
1542     Pass* p = mat->getTechnique(0)->getPass(0);
1543     p->setAlphaRejectSettings(CMPF_GREATER, 96);
1544     p->setLightingEnabled(false);
1545     p->setCullingMode(CULL_NONE);
1546     p->setAlphaToCoverageEnabled(true);
1547     TextureUnitState* t = p->createTextureUnitState("leaf.png");
1548     t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
1549     t->setColourOperation(LBO_ALPHA_BLEND);
1550     Entity *e = mSceneMgr->createEntity("PlaneA2C", SceneManager::PT_PLANE);
1551     e->setMaterialName(mat->getName());
1552     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 0))->attachObject(e);
1553 
1554 
1555     mat = MaterialManager::getSingleton().create(
1556         "testnoa2c",
1557         TRANSIENT_RESOURCE_GROUP);
1558     p = mat->getTechnique(0)->getPass(0);
1559     p->setAlphaRejectSettings(CMPF_GREATER, 96);
1560     p->setLightingEnabled(false);
1561     p->setCullingMode(CULL_NONE);
1562     p->setAlphaToCoverageEnabled(false);
1563     t = p->createTextureUnitState("leaf.png");
1564     t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
1565     t->setColourOperation(LBO_ALPHA_BLEND);
1566     e = mSceneMgr->createEntity("PlaneNoA2C", SceneManager::PT_PLANE);
1567     e->setMaterialName(mat->getName());
1568     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-100, 0, 0))->attachObject(e);
1569 
1570     mat = MaterialManager::getSingleton().create(
1571         "bg",
1572         TRANSIENT_RESOURCE_GROUP);
1573     p = mat->getTechnique(0)->getPass(0);
1574     p->setLightingEnabled(false);
1575     p->setCullingMode(CULL_NONE);
1576     t = p->createTextureUnitState();
1577     t->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue::White);
1578     e = mSceneMgr->createEntity("PlaneBg", SceneManager::PT_PLANE);
1579     e->setMaterialName(mat->getName());
1580     e->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
1581     SceneNode* s = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 0, -10));
1582     s->setScale(5,5,5);
1583     s->attachObject(e);
1584 
1585     mCameraNode->setPosition(0,0,300);
1586     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
1587 
1588 }
1589 //----------------------------------------------------------------------------
1590 //----------------------------------------------------------------------------
1591 
PlayPen_AttachObjectsToBones()1592 PlayPen_AttachObjectsToBones::PlayPen_AttachObjectsToBones()
1593 {
1594     mInfo["Title"] = "PlayPen_AttachObjectsToBones";
1595     mInfo["Description"] = "Tests attaching objectes to bones.";
1596     addScreenshotFrame(120);
1597 }
1598 //----------------------------------------------------------------------------
1599 
setupContent()1600 void PlayPen_AttachObjectsToBones::setupContent()
1601 {
1602     Entity *ent;
1603     for (int i = 0; i < 12; ++i)
1604     {
1605         ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
1606         if (i % 2)
1607         {
1608             Entity* ent2 = mSceneMgr->createEntity("plane" + StringConverter::toString(i), "razor.mesh");
1609             ent->attachObjectToBone("Joint8", ent2);
1610         }
1611         else
1612         {
1613             ParticleSystem* psys = mSceneMgr->createParticleSystem("psys" + StringConverter::toString(i), "Examples/PurpleFountain");
1614             psys->getEmitter(0)->setTimeToLive(0.2);
1615             ent->attachObjectToBone("Joint15", psys);
1616         }
1617         // Add entity to the scene node
1618         mSceneMgr->getRootSceneNode()->createChildSceneNode(
1619             Vector3(0,0,(i*200)-(12*200/2)))->attachObject(ent);
1620 
1621         ent->getParentNode()->yaw(Degree(i * 45));
1622 
1623         AnimationState* animState = ent->getAnimationState("Walk");
1624         animState->setEnabled(true);
1625         mAnimStateList.push_back(animState);
1626     }
1627 
1628 
1629 
1630     // Give it a little ambience with lights
1631     Light* l;
1632     l = mSceneMgr->createLight("BlueLight");
1633     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200,-80,-100))->attachObject(l);
1634     l->setDiffuseColour(0.5, 0.5, 1.0);
1635 
1636     l = mSceneMgr->createLight("GreenLight");
1637     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,-100))->attachObject(l);
1638     l->setDiffuseColour(0.5, 1.0, 0.5);
1639 
1640     // Position the camera
1641     mCameraNode->setPosition(400,120,500);
1642     mCameraNode->lookAt(Vector3(-50, 50, 0), Node::TS_PARENT);
1643 
1644     mSceneMgr->setAmbientLight(ColourValue(1,1,1,1));
1645     //mSceneMgr->showBoundingBoxes(true);
1646 
1647 }
1648 //----------------------------------------------------------------------------
1649 //----------------------------------------------------------------------------
1650 
PlayPen_BasicPlane()1651 PlayPen_BasicPlane::PlayPen_BasicPlane()
1652 {
1653     mInfo["Title"] = "PlayPen_BasicPlane";
1654     mInfo["Description"] = "Tests basic planes.";
1655     addScreenshotFrame(10);
1656 }
1657 //----------------------------------------------------------------------------
1658 
setupContent()1659 void PlayPen_BasicPlane::setupContent()
1660 {
1661     // Create a point light
1662     Light* l = mSceneMgr->createLight("MainLight");
1663     l->setType(Light::LT_DIRECTIONAL);
1664     l->setDirection(-Vector3::UNIT_Y);
1665     Entity *ent;
1666 
1667     // Define a floor plane mesh
1668     Plane p(Vector3::UNIT_Y, -200);
1669     MeshManager::getSingleton().createPlane(
1670         "FloorPlane",
1671         TRANSIENT_RESOURCE_GROUP,
1672         p, 2000, 2000, 1, 1, true, 1, 5, 5, Vector3::UNIT_Z);
1673 
1674     // Create an entity (the floor)
1675     ent = mSceneMgr->createEntity("floor", "FloorPlane");
1676     ent->setMaterialName("Examples/RustySteel");
1677     // ent->setMaterialName("BaseWhiteNoLighting");
1678     // ent->setMaterialName("BaseWhite");
1679 
1680     mSceneMgr->getRootSceneNode()->attachObject(ent);
1681 
1682     Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh");
1683 
1684     SceneNode* mRootNode = mSceneMgr->getRootSceneNode();
1685     SceneNode* node = mSceneMgr->createSceneNode();
1686     node->attachObject(sphereEnt);
1687     mRootNode->addChild(node);
1688 
1689     //mCameraNode->lookAt(Vector3(1, 1, 1), Node::TS_PARENT);
1690 }
1691 //----------------------------------------------------------------------------
1692 //----------------------------------------------------------------------------
1693 
PlayPen_BillboardAccurateFacing()1694 PlayPen_BillboardAccurateFacing::PlayPen_BillboardAccurateFacing()
1695 {
1696     mInfo["Title"] = "PlayPen_BillboardAccurateFacing";
1697     mInfo["Description"] = "Tests billboard facing.";
1698     addScreenshotFrame(10);
1699 }
1700 //----------------------------------------------------------------------------
1701 
setupContent()1702 void PlayPen_BillboardAccurateFacing::setupContent()
1703 {
1704     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
1705     Light* l = mSceneMgr->createLight("light1");
1706     l->setType(Light::LT_DIRECTIONAL);
1707     l->setDirection(Vector3(-1, -1, 0.5).normalisedCopy());
1708 
1709     Plane plane(Vector3::UNIT_Y, -100);
1710     MeshManager::getSingleton().createPlane(
1711         "Myplane",
1712         TRANSIENT_RESOURCE_GROUP, plane,
1713         1500, 1500, 10, 10, true, 1, 5, 5, Vector3::UNIT_Z);
1714     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
1715     pPlaneEnt->setMaterialName("2 - Default");
1716     pPlaneEnt->setCastShadows(false);
1717     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
1718 
1719     BillboardSet* bbs = mSceneMgr->createBillboardSet("1");
1720     bbs->setDefaultDimensions(50, 50);
1721     bbs->createBillboard(-100, 25, 0);
1722     bbs->setBillboardType(BBT_ORIENTED_COMMON);
1723     bbs->setCommonDirection(Vector3::UNIT_Y);
1724     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1725 
1726     bbs = mSceneMgr->createBillboardSet("2");
1727     bbs->setDefaultDimensions(50, 50);
1728     bbs->createBillboard(100, 25, 0);
1729     bbs->setUseAccurateFacing(true);
1730     bbs->setBillboardType(BBT_ORIENTED_COMMON);
1731     bbs->setCommonDirection(Vector3::UNIT_Y);
1732     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1733 
1734     mCameraNode->setPosition(200,120,300);
1735     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
1736 }
1737 //----------------------------------------------------------------------------
1738 //----------------------------------------------------------------------------
1739 
PlayPen_BillboardChain()1740 PlayPen_BillboardChain::PlayPen_BillboardChain()
1741 {
1742     mInfo["Title"] = "PlayPen_BillboardChain";
1743     mInfo["Description"] = "Tests billboard chains.";
1744     addScreenshotFrame(10);
1745 }
1746 //----------------------------------------------------------------------------
1747 
setupContent()1748 void PlayPen_BillboardChain::setupContent()
1749 {
1750     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
1751     Vector3 dir(-1, -1, 0.5);
1752     dir.normalise();
1753     Light* l = mSceneMgr->createLight("light1");
1754     l->setType(Light::LT_DIRECTIONAL);
1755     l->setDirection(dir);
1756 
1757     Plane plane;
1758     plane.normal = Vector3::UNIT_Y;
1759     plane.d = 100;
1760     MeshManager::getSingleton().createPlane(
1761         "Myplane",
1762         TRANSIENT_RESOURCE_GROUP, plane,
1763         1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
1764     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
1765     pPlaneEnt->setMaterialName("2 - Default");
1766     pPlaneEnt->setCastShadows(false);
1767     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
1768 
1769     BillboardChain* chain = static_cast<BillboardChain*>(
1770         mSceneMgr->createMovableObject("1", "BillboardChain"));
1771     chain->setUseTextureCoords(true);
1772     chain->setUseVertexColours(false);
1773 
1774     BillboardChain::Element elem;
1775     elem.width = 10;
1776     elem.texCoord = 0;
1777     elem.position = Vector3(0,20,0);
1778     chain->addChainElement(0, elem);
1779     elem.position = Vector3(20,0,0);
1780     elem.texCoord = 1.0;
1781     chain->addChainElement(0, elem);
1782     elem.position = Vector3(40,10,0);
1783     elem.texCoord = 2.0;
1784     chain->addChainElement(0, elem);
1785     elem.position = Vector3(60,20,0);
1786     elem.texCoord = 3.0;
1787     chain->addChainElement(0, elem);
1788     elem.position = Vector3(80,40,0);
1789     elem.texCoord = 4.0;
1790     chain->addChainElement(0, elem);
1791     elem.position = Vector3(100,70,0);
1792     elem.texCoord = 5.0;
1793     chain->addChainElement(0, elem);
1794 
1795     // BillboardChain does not calculate normals, so result will be inconsistent.
1796     //chain->setMaterialName("Examples/ShowNormals");
1797     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(chain);
1798 
1799     mSceneMgr->showBoundingBoxes(true);
1800 
1801     mCameraNode->setPosition(-20,60,200);
1802     mCameraNode->lookAt(Vector3(60, 40, 0), Node::TS_PARENT);
1803 }
1804 //----------------------------------------------------------------------------
1805 //----------------------------------------------------------------------------
1806 
PlayPen_BillboardOrigins()1807 PlayPen_BillboardOrigins::PlayPen_BillboardOrigins()
1808 {
1809     mInfo["Title"] = "PlayPen_BillboardOrigins";
1810     mInfo["Description"] = "Tests setting billboard origins.";
1811     addScreenshotFrame(10);
1812 }
1813 //----------------------------------------------------------------------------
1814 
setupContent()1815 void PlayPen_BillboardOrigins::setupContent()
1816 {
1817     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
1818 
1819     // Billboards currently have no normals.
1820     // Vector3 dir(-1, -1, 0.5);
1821     // dir.normalise();
1822     // Light* l = mSceneMgr->createLight("light1");
1823     // l->setType(Light::LT_DIRECTIONAL);
1824     // l->setDirection(dir);
1825 
1826     BillboardSet* bbs = mSceneMgr->createBillboardSet("1");
1827     bbs->setDefaultDimensions(50,50);
1828     bbs->createBillboard(0, 0, 0);
1829     bbs->setBillboardOrigin(BBO_TOP_LEFT);
1830     bbs->setMaterialName("2 - Default");
1831     // bbs->setBillboardType(BBT_ORIENTED_COMMON);
1832     bbs->setCommonDirection(Vector3::UNIT_Y);
1833     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1834 
1835     bbs = mSceneMgr->createBillboardSet("2");
1836     bbs->setDefaultDimensions(50,50);
1837     bbs->createBillboard(0, -10, 0);
1838     bbs->setBillboardOrigin(BBO_CENTER);
1839     bbs->setMaterialName("Examples/RustySteel");
1840     // bbs->setBillboardType(BBT_ORIENTED_COMMON);
1841     bbs->setCommonDirection(Vector3::UNIT_Y);
1842     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1843 
1844     bbs = mSceneMgr->createBillboardSet("3");
1845     bbs->setDefaultDimensions(50,50);
1846     bbs->createBillboard(0, -20, 0);
1847     bbs->setBillboardOrigin(BBO_BOTTOM_RIGHT);
1848     bbs->setMaterialName("Examples/OgreLogo");
1849     // bbs->setBillboardType(BBT_ORIENTED_COMMON);
1850     bbs->setCommonDirection(Vector3::UNIT_Y);
1851     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1852 
1853     mCameraNode->setPosition(0,160,1);
1854     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
1855 }
1856 //----------------------------------------------------------------------------
1857 //----------------------------------------------------------------------------
1858 
PlayPen_BillboardTextureCoords()1859 PlayPen_BillboardTextureCoords::PlayPen_BillboardTextureCoords()
1860 {
1861     mInfo["Title"] = "PlayPen_BillboardTextureCoords";
1862     mInfo["Description"] = "Tests setting billboard texture coordinates.";
1863     addScreenshotFrame(10);
1864 }
1865 //----------------------------------------------------------------------------
1866 
setupContent()1867 void PlayPen_BillboardTextureCoords::setupContent()
1868 {
1869     mSceneMgr->setAmbientLight(ColourValue::White);
1870 
1871     BillboardSet* bbs = mSceneMgr->createBillboardSet("test");
1872     BillboardSet* bbs2 = mSceneMgr->createBillboardSet("test2");
1873     float xsegs = 3;
1874     float ysegs = 3;
1875     float width = 300;
1876     float height = 300;
1877     float gap = 20;
1878 
1879     // set up texture coords
1880     bbs->setTextureStacksAndSlices(ysegs, xsegs);
1881     bbs->setDefaultDimensions(width/xsegs, height/xsegs);
1882     bbs2->setDefaultDimensions(width/xsegs, height/xsegs);
1883 
1884     for (float y = 0; y < ysegs; ++y)
1885     {
1886         for (float x = 0; x < xsegs; ++x)
1887         {
1888             Vector3 midPoint;
1889             midPoint.x = (x * width / xsegs) + ((x-1) * gap);
1890             midPoint.y = (y * height / ysegs) + ((y-1) * gap);
1891             midPoint.z = 0;
1892             Billboard* bb = bbs->createBillboard(midPoint);
1893             bb->setTexcoordIndex((ysegs - y - 1)*xsegs + x);
1894             Billboard* bb2 = bbs2->createBillboard(midPoint);
1895             bb2->setTexcoordRect(
1896                 FloatRect((x + 0) / xsegs, (ysegs - y - 1) / ysegs,
1897                           (x + 1) / xsegs, (ysegs - y - 0) / ysegs));
1898         }
1899     }
1900 
1901     bbs->setMaterialName("Examples/OgreLogo");
1902     bbs2->setMaterialName("Examples/OgreLogo");
1903     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
1904     mSceneMgr->getRootSceneNode()
1905         ->createChildSceneNode(Vector3(- (width + xsegs * gap), 0, 0))
1906         ->attachObject(bbs2);
1907 
1908     mCameraNode->setPosition(-100,150,900);
1909 }
1910 //----------------------------------------------------------------------------
1911 //----------------------------------------------------------------------------
1912 
PlayPen_BlendDiffuseColour()1913 PlayPen_BlendDiffuseColour::PlayPen_BlendDiffuseColour()
1914 {
1915     mInfo["Title"] = "PlayPen_BlendDiffuseColour";
1916     mInfo["Description"] = "Tests diffuse blending.";
1917     addScreenshotFrame(10);
1918 }
1919 //----------------------------------------------------------------------------
1920 
setupContent()1921 void PlayPen_BlendDiffuseColour::setupContent()
1922 {
1923     MaterialPtr mat = MaterialManager::getSingleton().create(
1924         "testBlendDiffuseColour", TRANSIENT_RESOURCE_GROUP);
1925     Pass* pass = mat->getTechnique(0)->getPass(0);
1926     // no lighting, it will mess up vertex colours
1927     pass->setLightingEnabled(false);
1928     // Make sure we pull in vertex colour as diffuse
1929     pass->setVertexColourTracking(TVC_DIFFUSE);
1930     // Base layer
1931     TextureUnitState* t = pass->createTextureUnitState("BeachStones.jpg");
1932     // don't want to bring in vertex diffuse on base layer
1933     t->setColourOperation(LBO_REPLACE);
1934     // Second layer (lerp based on colour)
1935     t = pass->createTextureUnitState("terr_dirt-grass.jpg");
1936     t->setColourOperationEx(LBX_BLEND_DIFFUSE_COLOUR);
1937     // third layer (lerp based on alpha)
1938     ManualObject* man = mSceneMgr->createManualObject("quad");
1939     man->begin("testBlendDiffuseColour");
1940     man->position(-100, 100, 0);
1941     man->textureCoord(0,0);
1942     man->colour(0, 0, 0);
1943     man->position(-100, -100, 0);
1944     man->textureCoord(0,1);
1945     man->colour(0.5, 0.5, 0.5);
1946     man->position(100, -100, 0);
1947     man->textureCoord(1,1);
1948     man->colour(1, 1, 1);
1949     man->position(100, 100, 0);
1950     man->textureCoord(1,0);
1951     man->colour(0.5, 0.5, 0.5);
1952     man->quad(0, 1, 2, 3);
1953     man->end();
1954 
1955     mSceneMgr->getRootSceneNode()->attachObject(man);
1956 
1957     mCameraNode->setPosition(0,0,250);
1958 
1959 }
1960 //----------------------------------------------------------------------------
1961 //----------------------------------------------------------------------------
1962 
PlayPen_BlitSubTextures()1963 PlayPen_BlitSubTextures::PlayPen_BlitSubTextures()
1964 {
1965     mInfo["Title"] = "PlayPen_BlitSubTextures";
1966     mInfo["Description"] = "Tests blitting textures onto on another.";
1967     addScreenshotFrame(10);
1968 }
1969 //----------------------------------------------------------------------------
1970 
setupContent()1971 void PlayPen_BlitSubTextures::setupContent()
1972 {
1973     Image img;
1974     img.load("ogrelogo.png", ASSETS_RESOURCE_GROUP);
1975 
1976     TexturePtr tex = TextureManager::getSingleton().createManual(
1977         "testblitdst",
1978         TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D, 1024, 1024, 1, 0, img.getFormat());
1979 
1980     PixelBox srcBox;
1981     // This box should select from halfway through the head, to the
1982     // 'OG' part of the logo.
1983     srcBox.left = 376;
1984     srcBox.top = 379;
1985     srcBox.right = 376 + 224;
1986     srcBox.bottom = 379 + 278;
1987     srcBox.back = 1;
1988     srcBox.front = 0;
1989     srcBox.format = img.getFormat();
1990     srcBox.data = img.getData();
1991     srcBox.rowPitch = img.getWidth();
1992     srcBox.slicePitch = img.getWidth() * img.getHeight();
1993 
1994     Box dstBox;
1995     dstBox.left = srcBox.left;
1996     dstBox.top = srcBox.top;
1997     dstBox.right = srcBox.right;
1998     dstBox.bottom = srcBox.bottom;
1999     dstBox.back = 1;
2000     dstBox.front = 0;
2001 
2002     // I was getting uninitialized memory written to the texture
2003     // buffer, so clear it explicitly.
2004     memset(tex->getBuffer()->lock(
2005         0, tex->getBuffer()->getSizeInBytes(),
2006         HardwareBuffer::HBL_NORMAL), 0, tex->getBuffer()->getSizeInBytes());
2007     tex->getBuffer()->unlock();
2008 
2009     tex->getBuffer()->blitFromMemory(srcBox, dstBox);
2010 
2011     MaterialPtr mat = MaterialManager::getSingleton().create(
2012         "testblit",
2013         TRANSIENT_RESOURCE_GROUP);
2014 
2015     Pass* p = mat->getTechnique(0)->getPass(0);
2016     p->setLightingEnabled(false);
2017     p->setCullingMode(CULL_NONE);
2018     p->createTextureUnitState(tex->getName());
2019     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2020     e->setMaterialName(mat->getName());
2021     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2022 
2023     mCameraNode->setPosition(0,0,300);
2024     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2025 
2026     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Green);
2027 
2028 }
2029 //----------------------------------------------------------------------------
2030 //----------------------------------------------------------------------------
2031 
PlayPen_HardwareScaleBlit()2032 PlayPen_HardwareScaleBlit::PlayPen_HardwareScaleBlit()
2033 {
2034     mInfo["Title"] = "PlayPen_HardwareScaleBlit";
2035     mInfo["Description"] = "Tests blitting texture with hardware scaling.";
2036     addScreenshotFrame(10);
2037 }
2038 //----------------------------------------------------------------------------
2039 
setupContent()2040 void PlayPen_HardwareScaleBlit::setupContent()
2041 {
2042     Image img;
2043     img.load("ogrelogo.png", ASSETS_RESOURCE_GROUP);
2044 
2045     TexturePtr tex = TextureManager::getSingleton().createManual(
2046         "testblitdst",
2047         TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D, 64, 64, 1, 0, img.getFormat());
2048 
2049     Box dstBox(0, 0, 64, 64);
2050     tex->getBuffer()->blitFromMemory(img.getPixelBox(), dstBox);
2051 
2052     MaterialPtr mat = MaterialManager::getSingleton().create(
2053         "testblit",
2054         TRANSIENT_RESOURCE_GROUP);
2055 
2056     Pass* p = mat->getTechnique(0)->getPass(0);
2057     p->setLightingEnabled(false);
2058     p->setCullingMode(CULL_NONE);
2059     p->createTextureUnitState(tex->getName());
2060     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2061     e->setMaterialName(mat->getName());
2062     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2063 
2064     mCameraNode->setPosition(0,0,300);
2065     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2066 
2067     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Green);
2068 }
2069 //----------------------------------------------------------------------------
2070 //----------------------------------------------------------------------------
2071 
PlayPen_Bsp()2072 PlayPen_Bsp::PlayPen_Bsp()
2073 {
2074     mInfo["Title"] = "PlayPen_Bsp";
2075     mInfo["Description"] = "Tests BSP plugin.";
2076     addScreenshotFrame(10);
2077 }
2078 //----------------------------------------------------------------------------
2079 
setupContent()2080 void PlayPen_Bsp::setupContent()
2081 {
2082     // Load Quake3 locations from a file
2083     ConfigFile cf;
2084 
2085     cf.load(mFSLayer->getConfigFilePath("quakemap.cfg"));
2086 
2087     String quakePk3 = cf.getSetting("Archive");
2088     String quakeLevel = cf.getSetting("Map");
2089 
2090     //ResourceGroupManager::getSingleton().addResourceLocation(quakePk3, "Zip");
2091 
2092     ResourceGroupManager::getSingleton().addResourceLocation(
2093         quakePk3, "Zip",
2094         ResourceGroupManager::getSingleton().getWorldResourceGroupName(), true);
2095 
2096     // Load world geometry
2097     //mSceneMgr->setWorldGeometry(quakeLevel);
2098 
2099     ResourceGroupManager& rgm = ResourceGroupManager::getSingleton();
2100     rgm.linkWorldGeometryToResourceGroup(rgm.getWorldResourceGroupName(), quakeLevel, mSceneMgr);
2101     rgm.initialiseResourceGroup(rgm.getWorldResourceGroupName());
2102     rgm.loadResourceGroup(rgm.getWorldResourceGroupName(), false);
2103 
2104     // modify camera for close work
2105     mCamera->setNearClipDistance(4);
2106     mCamera->setFarClipDistance(4000);
2107 
2108     // Also change position, and set Quake-type orientation
2109     // Get random player start point
2110     ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true);
2111     mCameraNode->setPosition(vp.position);
2112     mCameraNode->pitch(Degree(90)); // Quake uses X/Y horizon, Z up
2113     mCameraNode->rotate(vp.orientation);
2114     // Don't yaw along variable axis, causes leaning
2115     mCameraNode->setFixedYawAxis(true, Vector3::UNIT_Z);
2116 
2117     mCameraNode->yaw(Ogre::Degree(-90.f));
2118 }
2119 //----------------------------------------------------------------------------
2120 //----------------------------------------------------------------------------
2121 
PlayPen_BuildTangentOnAnimatedMesh()2122 PlayPen_BuildTangentOnAnimatedMesh::PlayPen_BuildTangentOnAnimatedMesh()
2123 {
2124     mInfo["Title"] = "PlayPen_BuildTangentOnAnimatedMesh";
2125     mInfo["Description"] = "Tests building tangents for an animated mesh.";
2126     addScreenshotFrame(50);
2127 }
2128 //----------------------------------------------------------------------------
2129 
setupContent()2130 void PlayPen_BuildTangentOnAnimatedMesh::setupContent()
2131 {
2132     SceneNode* mTestNode[2];
2133     Light* mLight = 0;
2134     //mSceneMgr->setShadowTextureSize(512);
2135     //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
2136     //mSceneMgr->setShadowFarDistance(1500);
2137     //mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
2138     //mSceneMgr->setShadowFarDistance(800);
2139     // Set ambient light
2140     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
2141 
2142     mLight = mSceneMgr->createLight("MainLight");
2143 
2144     /*/
2145     // Directional test
2146     mLight->setType(Light::LT_DIRECTIONAL);
2147     Vector3 vec(-1,-1,0);
2148     vec.normalise();
2149     mLight->setDirection(vec);
2150     /*/
2151     // Point test
2152     mLight->setType(Light::LT_POINT);
2153     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 200, 0))->attachObject(mLight);
2154     //*/
2155     MeshPtr pMesh = MeshManager::getSingleton().load("ninja.mesh", ASSETS_RESOURCE_GROUP/*,
2156                                                                                HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
2157                                                                                HardwareBuffer::HBU_STATIC_WRITE_ONLY,
2158                                                                                true, true*/); //so we can still read it
2159     // Build tangent vectors, all our meshes use only 1 texture coordset
2160     unsigned short src, dest;
2161     if (!pMesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
2162     {
2163         pMesh->buildTangentVectors(VES_TANGENT, src, dest);
2164     }
2165 
2166     Entity* pEnt = mSceneMgr->createEntity("Ninja", "ninja.mesh");
2167     pEnt->getAnimationState("Walk")->setEnabled(true);
2168     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2169     mTestNode[1]->attachObject( pEnt );
2170     mTestNode[1]->translate(-100,-100,0);
2171 
2172 
2173     Plane plane(Vector3::UNIT_Y, -100);
2174     MeshManager::getSingleton().createPlane("Myplane",
2175                                             TRANSIENT_RESOURCE_GROUP, plane,
2176                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
2177     Entity* pPlaneEnt;
2178     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
2179     pPlaneEnt->setMaterialName("2 - Default");
2180     pPlaneEnt->setCastShadows(false);
2181     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
2182 
2183     mCameraNode->setPosition(0,0,400);
2184 }
2185 //----------------------------------------------------------------------------
2186 //----------------------------------------------------------------------------
2187 
PlayPen_ClearScene()2188 PlayPen_ClearScene::PlayPen_ClearScene()
2189 {
2190     mInfo["Title"] = "PlayPen_ClearScene";
2191     mInfo["Description"] = "Tests clearing a running scene.";
2192     addScreenshotFrame(25);
2193 }
2194 //----------------------------------------------------------------------------
2195 
isScreenshotFrame(unsigned int frame)2196 bool PlayPen_ClearScene::isScreenshotFrame(unsigned int frame)
2197 {
2198     if(frame == 20)
2199         mSceneMgr->clearScene();
2200     return VisualTest::isScreenshotFrame(frame);
2201 }
2202 //----------------------------------------------------------------------------
2203 
setupContent()2204 void PlayPen_ClearScene::setupContent()
2205 {
2206     mSceneMgr->setAmbientLight(ColourValue::White);
2207 
2208     // Define a floor plane mesh
2209     Plane p(Vector3::UNIT_Y, -200);
2210     MeshManager::getSingleton().createPlane("FloorPlane",
2211                                             TRANSIENT_RESOURCE_GROUP,
2212                                             p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
2213 
2214     Entity* planeEnt;
2215     planeEnt = mSceneMgr->createEntity( "plane", "FloorPlane" );
2216     planeEnt->setMaterialName("Examples/Rockwall");
2217     mSceneMgr->getRootSceneNode()->attachObject(planeEnt);
2218 
2219     mCameraNode->setPosition(0,500,100);
2220     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
2221 }
2222 //----------------------------------------------------------------------------
2223 //----------------------------------------------------------------------------
2224 
PlayPen_CompositorTechniqueSwitch()2225 PlayPen_CompositorTechniqueSwitch::PlayPen_CompositorTechniqueSwitch()
2226 {
2227     mInfo["Title"] = "PlayPen_CompositorTechniqueSwitch";
2228     mInfo["Description"] = "Tests switching compositor techniques rapidly.";
2229     addScreenshotFrame(15);
2230 }
2231 //----------------------------------------------------------------------------
2232 
cleanupContent()2233 void PlayPen_CompositorTechniqueSwitch::cleanupContent()
2234 {
2235     CompositorManager::getSingleton().removeCompositorChain(mViewport);
2236 }
2237 //----------------------------------------------------------------------------
2238 
frameStarted(const FrameEvent & evt)2239 bool PlayPen_CompositorTechniqueSwitch::frameStarted(const FrameEvent& evt)
2240 {
2241     mTimeUntilNextToggle -= evt.timeSinceLastFrame;
2242 
2243     if(mTimeUntilNextToggle <= 0.f)
2244     {
2245         ++mCompositorIndex;
2246         mCompositorIndex = mCompositorIndex % mCompositorSchemeList.size();
2247         mCompositorToSwitch->setScheme(mCompositorSchemeList[mCompositorIndex]);
2248         mTimeUntilNextToggle = 0.1;
2249     }
2250 
2251     return true;
2252 }
2253 //----------------------------------------------------------------------------
2254 
setupContent()2255 void PlayPen_CompositorTechniqueSwitch::setupContent()
2256 {
2257     mTimeUntilNextToggle = 0.1f;// swap compositors every 10 frames
2258     CompositorManager& cmgr = CompositorManager::getSingleton();
2259     CompositorPtr compositor = cmgr.create("testtechswitch", TRANSIENT_RESOURCE_GROUP);
2260     // technique 1 (Invert)
2261     CompositionTechnique* ctech1 = compositor->createTechnique();
2262     CompositionTechnique::TextureDefinition* tdef =    ctech1->createTextureDefinition("rt0");
2263     tdef->formatList.push_back(PF_A8B8G8R8);
2264     tdef->width = tdef->height = 0;
2265     tdef->pooled = true;
2266 
2267     CompositionTargetPass* tpass = ctech1->createTargetPass();
2268     tpass->setOutputName("rt0");
2269     tpass->setInputMode(CompositionTargetPass::IM_PREVIOUS);
2270     CompositionTargetPass* tout = ctech1->getOutputTargetPass();
2271     tout->setInputMode(CompositionTargetPass::IM_NONE);
2272     CompositionPass* pass = tout->createPass(CompositionPass::PT_RENDERQUAD);
2273     pass->setMaterialName("Ogre/Compositor/Invert");
2274     pass->setInput(0, "rt0");
2275 
2276     // technique 2 (Tiling)
2277     ctech1 = compositor->createTechnique();
2278     ctech1->setSchemeName("Tiling");
2279     tdef =    ctech1->createTextureDefinition("rt0");
2280     tdef->formatList.push_back(PF_A8B8G8R8);
2281     tdef->width = tdef->height = 0;
2282     tdef->pooled = true;
2283 
2284     tpass = ctech1->createTargetPass();
2285     tpass->setOutputName("rt0");
2286     tpass->setInputMode(CompositionTargetPass::IM_PREVIOUS);
2287     tout = ctech1->getOutputTargetPass();
2288     tout->setInputMode(CompositionTargetPass::IM_NONE);
2289     pass = tout->createPass(CompositionPass::PT_RENDERQUAD);
2290     pass->setMaterialName("Ogre/Compositor/Tiling");
2291     pass->setInput(0, "rt0");
2292 
2293     compositor->load();
2294 
2295     Entity* e = mSceneMgr->createEntity("1", "knot.mesh");
2296     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2297     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 1000);
2298 
2299     // enable compositor (should pick first technique)
2300     Viewport* vp = mWindow->getViewport(0);
2301 
2302     mCompositorToSwitch = cmgr.addCompositor(vp, compositor->getName());
2303     mCompositorSchemeList.push_back("");
2304     mCompositorSchemeList.push_back("Tiling");
2305 
2306     cmgr.setCompositorEnabled(vp, compositor->getName(), true);
2307 
2308     mCameraNode->setPosition(0, 0, -300);
2309     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2310 
2311     mCompositorIndex = 0;
2312 
2313 }
2314 //----------------------------------------------------------------------------
2315 //----------------------------------------------------------------------------
2316 
PlayPen_CompositorTextureShadows()2317 PlayPen_CompositorTextureShadows::PlayPen_CompositorTextureShadows()
2318 {
2319     mInfo["Title"] = "PlayPen_CompositorTextureShadows";
2320     mInfo["Description"] = "Tests applying a compositor to a texture shadow manager.";
2321     addScreenshotFrame(10);
2322 }
2323 //----------------------------------------------------------------------------
2324 
cleanupContent()2325 void PlayPen_CompositorTextureShadows::cleanupContent()
2326 {
2327     TexturePtr shadowTex = mSceneMgr->getShadowTexture(0);
2328     RenderTarget* shadowRtt = shadowTex->getBuffer()->getRenderTarget();
2329     Viewport* vp = shadowRtt->getViewport(0);
2330     CompositorManager::getSingleton().removeCompositorChain(vp);
2331     clearDebugTextureOverlays();
2332 }
2333 //----------------------------------------------------------------------------
2334 
setupContent()2335 void PlayPen_CompositorTextureShadows::setupContent()
2336 {
2337     SceneNode* mTestNode[10];
2338 
2339     mSceneMgr->setShadowTextureSize(512);
2340     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
2341     mSceneMgr->setShadowFarDistance(1500);
2342     mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
2343     //mSceneMgr->setShadowFarDistance(800);
2344     // Set ambient light
2345     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
2346 
2347     Light* mLight = mSceneMgr->createLight("MainLight");
2348 
2349     /*
2350     // Directional test
2351     mLight->setType(Light::LT_DIRECTIONAL);
2352     Vector3 vec(-1,-1,0);
2353     vec.normalise();
2354     mLight->setDirection(vec);
2355 
2356     */
2357     // Spotlight test
2358     mLight->setType(Light::LT_SPOTLIGHT);
2359     mLight->setDiffuseColour(1.0, 1.0, 0.8);
2360     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2361     mTestNode[0]->setPosition(800,600,0);
2362     mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD);
2363     mTestNode[0]->attachObject(mLight);
2364 
2365 
2366     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2367 
2368 
2369     Entity* pEnt;
2370     pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
2371     //pEnt->setRenderingDistance(100);
2372     AnimationState* mAnimState = pEnt->getAnimationState("Walk");
2373     mAnimState->setEnabled(true);
2374     mAnimStateList.push_back(mAnimState);
2375     //pEnt->setMaterialName("2 - Default");
2376     mTestNode[1]->attachObject( pEnt );
2377     mTestNode[1]->translate(0,-100,0);
2378 
2379     pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
2380     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
2381     mTestNode[2]->attachObject( pEnt );
2382 
2383     // Transparent object (can force cast shadows)
2384     pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
2385     MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency",
2386                                                               TRANSIENT_RESOURCE_GROUP);
2387     tmat->setTransparencyCastsShadows(true);
2388     Pass* tpass = tmat->getTechnique(0)->getPass(0);
2389     tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
2390     tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2391     tpass->createTextureUnitState("gras_02.png");
2392     tpass->setCullingMode(CULL_NONE);
2393 
2394     pEnt->setMaterialName("TestAlphaTransparency");
2395     mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
2396     mTestNode[3]->attachObject( pEnt );
2397 
2398     pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
2399     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
2400     mTestNode[2]->attachObject( pEnt );
2401 
2402     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
2403 
2404 
2405     Plane plane;
2406     plane.normal = Vector3::UNIT_Y;
2407     plane.d = 100;
2408     MeshManager::getSingleton().createPlane("Myplane",
2409                                             TRANSIENT_RESOURCE_GROUP, plane,
2410                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
2411     Entity* pPlaneEnt;
2412     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
2413     pPlaneEnt->setMaterialName("2 - Default");
2414     pPlaneEnt->setCastShadows(false);
2415     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
2416 
2417     // Set up a debug panel to display the shadow
2418     addTextureShadowDebugOverlay(1, mSceneMgr);
2419 
2420 
2421 
2422     ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
2423                                                             "Examples/Smoke");
2424     mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
2425     mTestNode[4]->attachObject(pSys2);
2426 
2427     TexturePtr shadowTex = mSceneMgr->getShadowTexture(0);
2428     RenderTarget* shadowRtt = shadowTex->getBuffer()->getRenderTarget();
2429     Viewport* vp = shadowRtt->getViewport(0);
2430     // This originally used gaussian blur, but since compositor logic stuff has changed since the test
2431     // was originally written and I'm not especially familiar with it, I just swapped to a random
2432     // compositor (it still tests the required functionality)
2433     CompositorManager::getSingleton().addCompositor(vp, "Laplace");
2434     CompositorManager::getSingleton().setCompositorEnabled(
2435         vp, "Laplace", true);
2436 
2437     mCameraNode->setPosition(400, 250, 350);
2438     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
2439 }
2440 //----------------------------------------------------------------------------
2441 //----------------------------------------------------------------------------
2442 
PlayPen_CubeDDS()2443 PlayPen_CubeDDS::PlayPen_CubeDDS()
2444 {
2445     mInfo["Title"] = "PlayPen_CubeDDS";
2446     mInfo["Description"] = "Tests DDS cubemaps.";
2447     addScreenshotFrame(10);
2448 }
2449 //----------------------------------------------------------------------------
2450 
setupContent()2451 void PlayPen_CubeDDS::setupContent()
2452 {
2453     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2454 
2455     MaterialPtr mat = MaterialManager::getSingleton().create("testcube",
2456                                                              TRANSIENT_RESOURCE_GROUP);
2457     Pass* p = mat->getTechnique(0)->getPass(0);
2458     p->setLightingEnabled(false);
2459     TextureUnitState* t = p->createTextureUnitState();
2460     t->setTextureName("grace_cube.dds", TEX_TYPE_CUBE_MAP);
2461     t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
2462     t->setEnvironmentMap(true, TextureUnitState::ENV_REFLECTION);
2463     Entity* e = mSceneMgr->createEntity("1", "sphere.mesh");
2464     e->setMaterialName(mat->getName());
2465     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2466 
2467     mCameraNode->setPosition(300,0,0);
2468     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2469 
2470 }
2471 //----------------------------------------------------------------------------
2472 //----------------------------------------------------------------------------
2473 
PlayPen_CustomProjectionMatrix()2474 PlayPen_CustomProjectionMatrix::PlayPen_CustomProjectionMatrix()
2475 {
2476     mInfo["Title"] = "PlayPen_CustomProjectionMatrix";
2477     mInfo["Description"] = "Tests custom projection matrix.";
2478 }
2479 //----------------------------------------------------------------------------
2480 
setupContent()2481 void PlayPen_CustomProjectionMatrix::setupContent()
2482 {
2483     PlayPen_LotsAndLotsOfEntities::setupContent();
2484     Matrix4 mat = mCamera->getProjectionMatrix();
2485     mCamera->setCustomProjectionMatrix(true, mat);
2486     mat = mCamera->getProjectionMatrix();
2487 
2488 }
2489 //----------------------------------------------------------------------------
2490 //----------------------------------------------------------------------------
2491 
PlayPen_DepthBias()2492 PlayPen_DepthBias::PlayPen_DepthBias()
2493 {
2494     mInfo["Title"] = "PlayPen_DepthBias";
2495     mInfo["Description"] = "Tests depth biasing.";
2496     addScreenshotFrame(10);
2497 }
2498 //----------------------------------------------------------------------------
2499 
setupContent()2500 void PlayPen_DepthBias::setupContent()
2501 {
2502     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2503 
2504     mSceneMgr->setAmbientLight(ColourValue::White);
2505 
2506     MaterialPtr mat = MaterialManager::getSingleton().create("mat1",
2507                                                              TRANSIENT_RESOURCE_GROUP);
2508     // mat->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2509     Pass* p = mat->getTechnique(0)->getPass(0);
2510     p->setLightingEnabled(false);
2511     p->createTextureUnitState("BumpyMetal.jpg");
2512     // t->setColourOperation(LBO_ALPHA_BLEND);
2513 
2514     const String meshName("cube.mesh");
2515     Entity* entity = mSceneMgr->createEntity("base", meshName);
2516     entity->setMaterialName("mat1");
2517     mSceneMgr->getRootSceneNode()->attachObject(entity);
2518 
2519     entity = mSceneMgr->createEntity("base2", meshName);
2520     entity->setMaterialName("Examples/SphereMappedRustySteel");
2521     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2522     n->setPosition(-30, 0, 0);
2523     n->yaw(Degree(45));
2524     n->attachObject(entity);
2525 
2526     // for (size_t i = 0; i <= 6; ++i)
2527     for (size_t i = 0; i <= 3; ++i)
2528     {
2529         String name("decal");
2530         name += StringConverter::toString(i);
2531 
2532         MaterialPtr pMat = MaterialManager::getSingleton().create(name, TRANSIENT_RESOURCE_GROUP);
2533 
2534         p = pMat->getTechnique(0)->getPass(0);
2535         p->setLightingEnabled(false);
2536         p->setAlphaRejectSettings(CMPF_GREATER_EQUAL, 128);
2537         p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2538         p->setDepthBias(i);
2539         p->createTextureUnitState(name + ".png");
2540         // t->setColourOperation(LBO_ALPHA_BLEND);
2541 
2542         entity = mSceneMgr->createEntity(name, meshName);
2543         entity->setMaterialName(name);
2544         mSceneMgr->getRootSceneNode()->attachObject(entity);
2545     }
2546 
2547     mCameraNode->setPosition(0,0,200);
2548     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2549 
2550 }
2551 //----------------------------------------------------------------------------
2552 //----------------------------------------------------------------------------
2553 
PlayPen_DepthShadowMap()2554 PlayPen_DepthShadowMap::PlayPen_DepthShadowMap()
2555 {
2556     mInfo["Title"] = "PlayPen_DepthShadowMap";
2557     mInfo["Description"] = "Tests depth shadowmapping.";
2558     addScreenshotFrame(10);
2559 }
2560 //----------------------------------------------------------------------------
2561 
setupContent()2562 void PlayPen_DepthShadowMap::setupContent()
2563 {
2564     mSceneMgr->setShadowTextureCount(1);
2565     mSceneMgr->setShadowTextureConfig(0, 1024, 1024, PF_FLOAT32_R);
2566     mSceneMgr->setShadowTextureSelfShadow(true);
2567     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
2568     mSceneMgr->setShadowCasterRenderBackFaces(false);
2569 
2570     mSceneMgr->setShadowTextureCasterMaterial(
2571         MaterialManager::getSingleton().getByName("Ogre/DepthShadowmap/Caster/Float", "General"));
2572 
2573     //mLiSPSMSetup->setUseAggressiveFocusRegion(false);
2574     //PlaneOptimalShadowCameraSetup(mPlane);
2575     mSceneMgr->setShadowCameraSetup(FocusedShadowCameraSetup::create());
2576 
2577     // Single light
2578     Light* l = mSceneMgr->createLight("l1");
2579     l->setType(Light::LT_SPOTLIGHT);
2580     //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(500, 500, -100))->attachObject(l);
2581     Vector3 pos(0, 300, 0);
2582     mSceneMgr->getRootSceneNode()->createChildSceneNode(pos)->attachObject(l);
2583     l->setDirection(-pos.normalisedCopy());
2584     l->setSpotlightOuterAngle(Degree(40));
2585     l->setSpotlightInnerAngle(Degree(35));
2586 
2587     // ground plane
2588     MovablePlane movablePlane = MovablePlane(Vector3::UNIT_Y, 0.f);
2589 
2590     MeshManager::getSingleton().createPlane("Myplane",
2591                                             TRANSIENT_RESOURCE_GROUP, movablePlane,
2592                                             500,500,10,10,true,1,5,5,Vector3::UNIT_Z);
2593     Entity* pPlaneEnt;
2594     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
2595     pPlaneEnt->setMaterialName("Ogre/DepthShadowmap/Receiver/RockWall");
2596     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
2597 
2598     // box
2599     ManualObject* man = mSceneMgr->createManualObject("box");
2600     Real boxsize = 50;
2601     Real boxsizehalf = boxsize / 2.0;
2602     man->begin("Ogre/DepthShadowmap/Receiver/Float");
2603     man->position(-boxsizehalf, 0, boxsizehalf);
2604     man->position(boxsizehalf, 0, boxsizehalf);
2605     man->position(boxsizehalf, 0, -boxsizehalf);
2606     man->position(-boxsizehalf, 0, -boxsizehalf);
2607     man->position(-boxsizehalf, boxsize, boxsizehalf);
2608     man->position(boxsizehalf, boxsize, boxsizehalf);
2609     man->position(boxsizehalf, boxsize, -boxsizehalf);
2610     man->position(-boxsizehalf, boxsize, -boxsizehalf);
2611     man->quad(3, 2, 1, 0);
2612     man->quad(4, 5, 6, 7);
2613     man->quad(0, 1, 5, 4);
2614     man->quad(1, 2, 6, 5);
2615     man->quad(2, 3, 7, 6);
2616     man->quad(3, 0, 4, 7);
2617     man->end();
2618 
2619     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
2620 
2621     mCameraNode->setPosition(150, 100, 150);
2622     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2623 
2624     // Create RTT
2625     //TexturePtr rtt = TextureManager::getSingleton().createManual("rtt1", TRANSIENT_RESOURCE_GROUP,
2626     //    TEX_TYPE_2D, 1024, 1024, 1, 0, PF_FLOAT32_R);
2627 
2628 }
2629 //----------------------------------------------------------------------------
2630 //----------------------------------------------------------------------------
2631 
2632 Entity* pTexListenerPlaneEnt = 0;// yucky global...
2633 Camera* theCam = 0;
2634 
2635 class RefractionTextureListener : public RenderTargetListener
2636 {
2637 public:
preRenderTargetUpdate(const RenderTargetEvent & evt)2638     void preRenderTargetUpdate(const RenderTargetEvent& evt)
2639     {
2640         pTexListenerPlaneEnt->setVisible(false);
2641 
2642     }
postRenderTargetUpdate(const RenderTargetEvent & evt)2643     void postRenderTargetUpdate(const RenderTargetEvent& evt)
2644     {
2645         pTexListenerPlaneEnt->setVisible(true);
2646     }
2647 
2648 };
2649 
2650 class ReflectionTextureListener : public RenderTargetListener
2651 {
2652 public:
preRenderTargetUpdate(const RenderTargetEvent & evt)2653     void preRenderTargetUpdate(const RenderTargetEvent& evt)
2654     {
2655         static Plane reflectPlane(Vector3::UNIT_Y, -100);
2656         pTexListenerPlaneEnt->setVisible(false);
2657         theCam->enableReflection(reflectPlane);
2658 
2659     }
postRenderTargetUpdate(const RenderTargetEvent & evt)2660     void postRenderTargetUpdate(const RenderTargetEvent& evt)
2661     {
2662         pTexListenerPlaneEnt->setVisible(true);
2663         theCam->disableReflection();
2664     }
2665 
2666 };
2667 
PlayPen_Distortion()2668 PlayPen_Distortion::PlayPen_Distortion()
2669 {
2670     mInfo["Title"] = "PlayPen_Distortion";
2671     mInfo["Description"] = "Tests distortion.";
2672     addScreenshotFrame(15);
2673 
2674     mRefractionListener = new RefractionTextureListener();
2675     mReflectionListener = new ReflectionTextureListener();
2676 }
2677 //----------------------------------------------------------------------------
2678 
~PlayPen_Distortion()2679 PlayPen_Distortion::~PlayPen_Distortion()
2680 {
2681     delete mRefractionListener;
2682     delete mReflectionListener;
2683 }
2684 //----------------------------------------------------------------------------
2685 
cleanupContent()2686 void PlayPen_Distortion::cleanupContent()
2687 {
2688     TexturePtr rttTex = TextureManager::getSingleton().getByName("Refraction", TRANSIENT_RESOURCE_GROUP);
2689     rttTex->getBuffer()->getRenderTarget()->removeAllListeners();
2690     rttTex->unload();
2691     rttTex = TextureManager::getSingleton().getByName("Reflection", TRANSIENT_RESOURCE_GROUP);
2692     rttTex->getBuffer()->getRenderTarget()->removeAllListeners();
2693     rttTex->unload();
2694 }
2695 //----------------------------------------------------------------------------
2696 
setupContent()2697 void PlayPen_Distortion::setupContent()
2698 {
2699     theCam = mCamera;
2700     // Set ambient light
2701     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
2702 
2703     // Create a point light
2704     Light* l = mSceneMgr->createLight("MainLight");
2705     l->setType(Light::LT_DIRECTIONAL);
2706     l->setDirection(-Vector3::UNIT_Y);
2707 
2708     Entity* pEnt;
2709 
2710     TexturePtr rttTex = TextureManager::getSingleton().createManual("Refraction",
2711                                                                     TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
2712                                                                     512, 512, 1, 0, PF_R8G8B8, TU_RENDERTARGET);
2713     {
2714         Viewport *v = rttTex->getBuffer()->getRenderTarget()->addViewport( mCamera );
2715         MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
2716         mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction");
2717         v->setOverlaysEnabled(false);
2718         rttTex->getBuffer()->getRenderTarget()->addListener(mRefractionListener);
2719     }
2720 
2721     rttTex = TextureManager::getSingleton().createManual("Reflection",
2722                                                          TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
2723                                                          512, 512, 1, 0, PF_R8G8B8, TU_RENDERTARGET);
2724     {
2725         Viewport *v = rttTex->getBuffer()->getRenderTarget()->addViewport( mCamera );
2726         MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
2727         mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection");
2728         v->setOverlaysEnabled(false);
2729         rttTex->getBuffer()->getRenderTarget()->addListener(mReflectionListener);
2730     }
2731     // Define a floor plane mesh
2732     Plane p(Vector3::UNIT_Y, -100);
2733     MeshManager::getSingleton().createPlane("WallPlane",
2734                                             TRANSIENT_RESOURCE_GROUP,
2735                                             p,1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
2736     pTexListenerPlaneEnt = mSceneMgr->createEntity( "5", "WallPlane" );
2737     pTexListenerPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction");
2738     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pTexListenerPlaneEnt);
2739 
2740     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
2741 
2742     for (int i = 0; i < 10; ++i)
2743     {
2744         pEnt = mSceneMgr->createEntity( "ogre" + StringConverter::toString(i), "ogrehead.mesh" );
2745         mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, -75, 0))->attachObject(pEnt);
2746         pEnt = mSceneMgr->createEntity( "knot" + StringConverter::toString(i), "knot.mesh" );
2747         mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, 140, 0))->attachObject(pEnt);
2748     }
2749 
2750     mCameraNode->setPosition(100,200,300);
2751     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
2752 
2753 }
2754 //----------------------------------------------------------------------------
2755 //----------------------------------------------------------------------------
2756 
PlayPen_Dxt1Alpha()2757 PlayPen_Dxt1Alpha::PlayPen_Dxt1Alpha()
2758 {
2759     mInfo["Title"] = "PlayPen_Dxt1Alpha";
2760     mInfo["Description"] = "Tests dxt1 loading with alpha.";
2761     addScreenshotFrame(10);
2762 }
2763 //----------------------------------------------------------------------------
2764 
setupContent()2765 void PlayPen_Dxt1Alpha::setupContent()
2766 {
2767     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2768 
2769     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2770                                                              TRANSIENT_RESOURCE_GROUP);
2771     Pass* p = mat->getTechnique(0)->getPass(0);
2772     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2773     p->setAlphaRejectSettings(CMPF_GREATER, 128);
2774     p->setLightingEnabled(false);
2775     p->setCullingMode(CULL_NONE);
2776     p->createTextureUnitState("gras_02_dxt1.dds");
2777     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2778     e->setMaterialName(mat->getName());
2779     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2780 
2781     mCameraNode->setPosition(0,0,300);
2782     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2783 
2784 }
2785 //----------------------------------------------------------------------------
2786 //----------------------------------------------------------------------------
2787 
PlayPen_Dxt1()2788 PlayPen_Dxt1::PlayPen_Dxt1()
2789 {
2790     mInfo["Title"] = "PlayPen_Dxt1";
2791     mInfo["Description"] = "Tests dxt1 loading.";
2792     addScreenshotFrame(10);
2793 }
2794 //----------------------------------------------------------------------------
2795 
setupContent()2796 void PlayPen_Dxt1::setupContent()
2797 {
2798     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2799 
2800     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2801                                                              TRANSIENT_RESOURCE_GROUP);
2802     Pass* p = mat->getTechnique(0)->getPass(0);
2803     p->setLightingEnabled(false);
2804     p->setCullingMode(CULL_NONE);
2805     p->createTextureUnitState("BumpyMetal_dxt1.dds");
2806     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2807     e->setMaterialName(mat->getName());
2808     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2809 
2810     mCameraNode->setPosition(0,0,-300);
2811     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2812 
2813 }
2814 //----------------------------------------------------------------------------
2815 //----------------------------------------------------------------------------
2816 
PlayPen_Dxt1FromMemory()2817 PlayPen_Dxt1FromMemory::PlayPen_Dxt1FromMemory()
2818 {
2819     mInfo["Title"] = "PlayPen_Dxt1FromMemory";
2820     mInfo["Description"] = "Tests dxt1 loading from memory.";
2821     addScreenshotFrame(10);
2822 }
2823 //----------------------------------------------------------------------------
2824 
setupContent()2825 void PlayPen_Dxt1FromMemory::setupContent()
2826 {
2827     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2828 
2829     DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource("BumpyMetal_dxt1.dds", "Tests");
2830     // manually load into image
2831     Image img;
2832     img.load(stream, "dds");
2833     TextureManager::getSingleton().loadImage("testdxtfrommem", TRANSIENT_RESOURCE_GROUP, img);
2834 
2835 
2836 
2837     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2838                                                              TRANSIENT_RESOURCE_GROUP);
2839     Pass* p = mat->getTechnique(0)->getPass(0);
2840     p->setLightingEnabled(false);
2841     p->setCullingMode(CULL_NONE);
2842     p->createTextureUnitState("testdxtfrommem");
2843     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2844     e->setMaterialName(mat->getName());
2845     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2846 
2847     mCameraNode->setPosition(0,0,-300);
2848     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2849 
2850 }
2851 //----------------------------------------------------------------------------
2852 //----------------------------------------------------------------------------
2853 
PlayPen_Dxt3()2854 PlayPen_Dxt3::PlayPen_Dxt3()
2855 {
2856     mInfo["Title"] = "PlayPen_Dxt3";
2857     mInfo["Description"] = "Tests dxt3 loading.";
2858     addScreenshotFrame(10);
2859 }
2860 //----------------------------------------------------------------------------
2861 
setupContent()2862 void PlayPen_Dxt3::setupContent()
2863 {
2864     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2865 
2866     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2867                                                              TRANSIENT_RESOURCE_GROUP);
2868     Pass* p = mat->getTechnique(0)->getPass(0);
2869     p->setLightingEnabled(false);
2870     p->setCullingMode(CULL_NONE);
2871     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2872     p->createTextureUnitState("ogreborderUp_dxt3.dds");
2873     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2874     e->setMaterialName(mat->getName());
2875     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2876     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
2877 
2878     mCameraNode->setPosition(0,0,300);
2879     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2880 
2881 }
2882 //----------------------------------------------------------------------------
2883 //----------------------------------------------------------------------------
2884 
PlayPen_Dxt3FromMemory()2885 PlayPen_Dxt3FromMemory::PlayPen_Dxt3FromMemory()
2886 {
2887     mInfo["Title"] = "PlayPen_Dxt3FromMemory";
2888     mInfo["Description"] = "Tests dxt3 loading from memory.";
2889     addScreenshotFrame(10);
2890 }
2891 //----------------------------------------------------------------------------
2892 
setupContent()2893 void PlayPen_Dxt3FromMemory::setupContent()
2894 {
2895     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2896 
2897     DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource("ogreborderUp_dxt3.dds", "Tests");
2898     // manually load into image
2899     Image img;
2900     img.load(stream, "dds");
2901     TextureManager::getSingleton().loadImage("testdxtfrommem", TRANSIENT_RESOURCE_GROUP, img);
2902 
2903     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2904                                                              TRANSIENT_RESOURCE_GROUP);
2905 
2906     Pass* p = mat->getTechnique(0)->getPass(0);
2907     p->setLightingEnabled(false);
2908     p->setCullingMode(CULL_NONE);
2909     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2910     p->setAlphaRejectSettings(CMPF_GREATER, 128);
2911     mat->setReceiveShadows(false);
2912     TextureUnitState* t = p->createTextureUnitState("testdxtfrommem");
2913     t->setTextureScale(0.5,0.5);
2914     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2915     e->setMaterialName(mat->getName());
2916     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2917     n->setPosition(-50, 0, 35);
2918     n->yaw(Degree(90));
2919     n->attachObject(e);
2920     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
2921 
2922     mCameraNode->setPosition(0,0,300);
2923     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2924 
2925 }
2926 //----------------------------------------------------------------------------
2927 //----------------------------------------------------------------------------
2928 
PlayPen_Dxt5()2929 PlayPen_Dxt5::PlayPen_Dxt5()
2930 {
2931     mInfo["Title"] = "PlayPen_Dxt5";
2932     mInfo["Description"] = "Tests dxt5 loading.";
2933     addScreenshotFrame(10);
2934 }
2935 //----------------------------------------------------------------------------
2936 
setupContent()2937 void PlayPen_Dxt5::setupContent()
2938 {
2939     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
2940 
2941     MaterialPtr mat = MaterialManager::getSingleton().create("testdxt",
2942                                                              TRANSIENT_RESOURCE_GROUP);
2943     Pass* p = mat->getTechnique(0)->getPass(0);
2944     p->setLightingEnabled(false);
2945     p->setCullingMode(CULL_NONE);
2946     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
2947     p->createTextureUnitState("ogreborderUp_dxt5.dds");
2948     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
2949     e->setMaterialName(mat->getName());
2950     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
2951     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
2952 
2953     mCameraNode->setPosition(0,0,300);
2954     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
2955 
2956 }
2957 //----------------------------------------------------------------------------
2958 //----------------------------------------------------------------------------
2959 
PlayPen_FarFromOrigin()2960 PlayPen_FarFromOrigin::PlayPen_FarFromOrigin()
2961 {
2962     mInfo["Title"] = "PlayPen_FarFromOrigin";
2963     mInfo["Description"] = "Tests rending far from the origin.";
2964     addScreenshotFrame(10);
2965 }
2966 //----------------------------------------------------------------------------
2967 
cleanupContent()2968 void PlayPen_FarFromOrigin::cleanupContent()
2969 {
2970     //clearDebugTextureOverlays();
2971 }
2972 
setupContent()2973 void PlayPen_FarFromOrigin::setupContent()
2974 {
2975     SceneNode* mTestNode[5];
2976     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
2977     mSceneMgr->setShadowTextureSettings(1024, 2);
2978 
2979     Vector3 offset(100000, 0, 100000);
2980     //Vector3 offset(0, 0, 0);
2981 
2982     mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
2983 
2984     // Directional test
2985     Light* mLight = mSceneMgr->createLight("MainLight");
2986     mLight->setType(Light::LT_DIRECTIONAL);
2987     Vector3 vec(-1,-1,0);
2988     vec.normalise();
2989     mLight->setDirection(vec);
2990     mLight->setDiffuseColour(ColourValue(0.5, 0.5, 1.0));
2991 
2992     // Spotlight test
2993     mLight = mSceneMgr->createLight("SpotLight");
2994     mLight->setType(Light::LT_SPOTLIGHT);
2995     mLight->setAttenuation(10000, 1, 0, 0);
2996     mLight->setDiffuseColour(1.0, 1.0, 0.5);
2997 
2998     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
2999     mTestNode[0]->setPosition(offset + Vector3(-400,300,1000));
3000     mTestNode[0]->lookAt(offset, Node::TS_WORLD);
3001     mTestNode[0]->attachObject(mLight);
3002 
3003 
3004     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
3005     mTestNode[1]->setPosition(offset);
3006 
3007     Entity* pEnt;
3008     pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
3009     mTestNode[1]->attachObject( pEnt );
3010 
3011 
3012     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
3013 
3014 
3015     Plane plane;
3016     plane.normal = Vector3::UNIT_Y;
3017     plane.d = 100;
3018     MeshManager::getSingleton().createPlane("Myplane",
3019                                             TRANSIENT_RESOURCE_GROUP, plane,
3020                                             2500,2500,10,10,true,1,5,5,Vector3::UNIT_Z);
3021     Entity* pPlaneEnt;
3022     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3023     pPlaneEnt->setMaterialName("2 - Default");
3024     pPlaneEnt->setCastShadows(false);
3025     mSceneMgr->getRootSceneNode()->createChildSceneNode(offset)->attachObject(pPlaneEnt);
3026 
3027     ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
3028                                                             "Examples/Smoke");
3029     mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(offset + Vector3(-300, -100, 200));
3030     mTestNode[4]->attachObject(pSys2);
3031 
3032     mCameraNode->setPosition(offset + Vector3(0, 1000, 500));
3033     mCameraNode->lookAt(offset, Node::TS_PARENT);
3034     mCamera->setFarClipDistance(10000);
3035 
3036     mSceneMgr->setCameraRelativeRendering(true);
3037 
3038     mSceneMgr->setShadowCameraSetup(FocusedShadowCameraSetup::create());
3039     //addTextureShadowDebugOverlay(1, mSceneMgr);
3040 
3041 }
3042 //----------------------------------------------------------------------------
3043 //----------------------------------------------------------------------------
3044 
PlayPen_Float128DDS()3045 PlayPen_Float128DDS::PlayPen_Float128DDS()
3046 {
3047     mInfo["Title"] = "PlayPen_Float128DDS";
3048     mInfo["Description"] = "Tests 128bit floating point dds textures.";
3049     addScreenshotFrame(250);
3050 }
3051 //----------------------------------------------------------------------------
3052 
setupContent()3053 void PlayPen_Float128DDS::setupContent()
3054 {
3055     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
3056 
3057     MaterialPtr mat = MaterialManager::getSingleton().create("testdds",
3058                                                              TRANSIENT_RESOURCE_GROUP);
3059     Pass* p = mat->getTechnique(0)->getPass(0);
3060     p->setLightingEnabled(false);
3061     p->setCullingMode(CULL_NONE);
3062     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
3063     p->createTextureUnitState("ogreborderUp_float128.dds");
3064     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
3065     e->setMaterialName(mat->getName());
3066     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
3067     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
3068 
3069     mCameraNode->setPosition(0,0,300);
3070     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3071 
3072 }
3073 //----------------------------------------------------------------------------
3074 //----------------------------------------------------------------------------
3075 
PlayPen_Float16DDS()3076 PlayPen_Float16DDS::PlayPen_Float16DDS()
3077 {
3078     mInfo["Title"] = "PlayPen_Float16DDS";
3079     mInfo["Description"] = "Tests 16bit floating point dds textures.";
3080     addScreenshotFrame(250);
3081 }
3082 //----------------------------------------------------------------------------
3083 
setupContent()3084 void PlayPen_Float16DDS::setupContent()
3085 {
3086     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
3087 
3088     MaterialPtr mat = MaterialManager::getSingleton().create("testdds",
3089                                                              TRANSIENT_RESOURCE_GROUP);
3090     Pass* p = mat->getTechnique(0)->getPass(0);
3091     p->setLightingEnabled(false);
3092     p->setCullingMode(CULL_NONE);
3093     p->createTextureUnitState("BumpyMetal_float16.dds");
3094     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
3095     e->setMaterialName(mat->getName());
3096     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
3097     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
3098 
3099     mCameraNode->setPosition(0,0,300);
3100     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3101 
3102 }
3103 //----------------------------------------------------------------------------
3104 //----------------------------------------------------------------------------
3105 
PlayPen_Float32DDS()3106 PlayPen_Float32DDS::PlayPen_Float32DDS()
3107 {
3108     mInfo["Title"] = "PlayPen_Float32DDS";
3109     mInfo["Description"] = "Tests 32bit floating point dds textures.";
3110     addScreenshotFrame(250);
3111 }
3112 //----------------------------------------------------------------------------
3113 
setupContent()3114 void PlayPen_Float32DDS::setupContent()
3115 {
3116     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
3117 
3118     MaterialPtr mat = MaterialManager::getSingleton().create("testdds",
3119                                                              TRANSIENT_RESOURCE_GROUP);
3120     Pass* p = mat->getTechnique(0)->getPass(0);
3121     p->setLightingEnabled(false);
3122     p->setCullingMode(CULL_NONE);
3123     p->createTextureUnitState("BumpyMetal_float32.dds");
3124     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
3125     e->setMaterialName(mat->getName());
3126     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
3127     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
3128 
3129     mCameraNode->setPosition(0,0,300);
3130     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3131 }
3132 //----------------------------------------------------------------------------
3133 //----------------------------------------------------------------------------
3134 
PlayPen_Float64DDS()3135 PlayPen_Float64DDS::PlayPen_Float64DDS()
3136 {
3137     mInfo["Title"] = "PlayPen_Float64DDS";
3138     mInfo["Description"] = "Tests 64bit floating point dds textures.";
3139     addScreenshotFrame(250);
3140 }
3141 //----------------------------------------------------------------------------
3142 
setupContent()3143 void PlayPen_Float64DDS::setupContent()
3144 {
3145     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
3146 
3147     MaterialPtr mat = MaterialManager::getSingleton().create("testdds",
3148                                                              TRANSIENT_RESOURCE_GROUP);
3149     Pass* p = mat->getTechnique(0)->getPass(0);
3150     p->setLightingEnabled(false);
3151     p->setCullingMode(CULL_NONE);
3152     p->setSceneBlending(SBT_TRANSPARENT_ALPHA);
3153     p->createTextureUnitState("ogreborderUp_float64.dds");
3154     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
3155     e->setMaterialName(mat->getName());
3156     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
3157     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
3158 
3159     mCameraNode->setPosition(0,0,300);
3160     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3161 
3162 }
3163 //----------------------------------------------------------------------------
3164 //----------------------------------------------------------------------------
3165 
PlayPen_GeometryShaders()3166 PlayPen_GeometryShaders::PlayPen_GeometryShaders()
3167 {
3168     mInfo["Title"] = "PlayPen_GeometryShaders";
3169     mInfo["Description"] = "Tests geometry shaders.";
3170     addScreenshotFrame(10);
3171 }
3172 //----------------------------------------------------------------------------
3173 
testCapabilities(const Ogre::RenderSystemCapabilities * caps)3174 void PlayPen_GeometryShaders::testCapabilities(const Ogre::RenderSystemCapabilities* caps)
3175 {
3176     if(!caps->hasCapability(RSC_GEOMETRY_PROGRAM))
3177         throw Ogre::Exception(999, "Video card doesn't support geometry shaders.", "testCapabilities");
3178 }
3179 //----------------------------------------------------------------------------
3180 
setupContent()3181 void PlayPen_GeometryShaders::setupContent()
3182 {
3183     // Check capabilities
3184     const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();
3185     if (!caps->hasCapability(RSC_GEOMETRY_PROGRAM))
3186     {
3187         OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED,
3188                     "Your card does not support geometry programs, so cannot "
3189                     "run this demo. Sorry!",
3190                     "GeometryShading::createScene");
3191     }
3192 
3193     int maxOutputVertices = caps->getGeometryProgramNumOutputVertices();
3194     Ogre::LogManager::getSingleton().getDefaultLog()->stream() <<
3195         "Num output vertices per geometry shader run : " << maxOutputVertices;
3196 
3197     Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
3198 
3199     // Set all of the material's sub entities to use the new material
3200     for (unsigned int i = 0; i < ent->getNumSubEntities(); i++)
3201     {
3202         ent->getSubEntity(i)->setMaterialName("Ogre/GPTest/Swizzle");
3203     }
3204 
3205     // Add entity to the root scene node
3206     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
3207 
3208     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Green);
3209 
3210     mCameraNode->setPosition(20, 0, 100);
3211     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
3212 }
3213 //----------------------------------------------------------------------------
3214 //----------------------------------------------------------------------------
3215 
PlayPen_ImageCombine()3216 PlayPen_ImageCombine::PlayPen_ImageCombine()
3217 {
3218     mInfo["Title"] = "PlayPen_ImageCombine";
3219     mInfo["Description"] = "Tests image combining.";
3220     addScreenshotFrame(10);
3221 }
3222 //----------------------------------------------------------------------------
3223 
setupContent()3224 void PlayPen_ImageCombine::setupContent()
3225 {
3226     Image combined;
3227 
3228     // pick 2 files that are the same size, alpha texture will be made greyscale
3229     combined.loadTwoImagesAsRGBA("rockwall.tga", "flare.png", ASSETS_RESOURCE_GROUP, PF_BYTE_RGBA);
3230 
3231     TexturePtr tex = TextureManager::getSingleton().createManual("1", TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D, 256, 256, 1, 0, PF_BYTE_RGBA);
3232     tex->loadImage(combined);
3233 
3234     MaterialManager& mmgr = MaterialManager::getSingleton();
3235     MaterialPtr mat = mmgr.create("m1", TRANSIENT_RESOURCE_GROUP);
3236     Pass* pass = mat->getTechnique(0)->getPass(0);
3237     pass->setLightingEnabled(false);
3238     pass->setCullingMode(CULL_NONE);
3239     pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
3240     pass->setDepthWriteEnabled(false);
3241     pass->createTextureUnitState(tex->getName());
3242 
3243     Entity *e = mSceneMgr->createEntity("test", SceneManager::PT_PLANE);
3244     e->setMaterialName(mat->getName());
3245     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
3246 
3247     mCameraNode->setPosition(0, 0, 200);
3248     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3249 
3250     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Blue);
3251 
3252 }
3253 //----------------------------------------------------------------------------
3254 //----------------------------------------------------------------------------
3255 
PlayPen_InfiniteAAB()3256 PlayPen_InfiniteAAB::PlayPen_InfiniteAAB()
3257 {
3258     mInfo["Title"] = "PlayPen_InfiniteAAB";
3259     mInfo["Description"] = "Tests finite/infinite AABBs.";
3260     addScreenshotFrame(15);
3261 }
3262 //----------------------------------------------------------------------------
3263 
setupContent()3264 void PlayPen_InfiniteAAB::setupContent()
3265 {
3266     // When using the BspSceneManager
3267     mSceneMgr->setWorldGeometry("ogretestmap.bsp");
3268 
3269     // When using the TerrainSceneManager
3270     //mSceneMgr->setWorldGeometry("terrain.cfg");
3271 
3272     AxisAlignedBox b1; // null
3273     assert( b1.isNull() );
3274 
3275     AxisAlignedBox b2(Vector3::ZERO, 5.0 * Vector3::UNIT_SCALE); // finite
3276     assert( b2.isFinite() );
3277 
3278     AxisAlignedBox b3;
3279     b3.setInfinite();
3280     assert( b3.isInfinite() );
3281 
3282     {
3283         // Create background material
3284         MaterialPtr material = MaterialManager::getSingleton().create("Background", "General");
3285         material->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga");
3286         material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
3287         material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
3288         material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
3289 
3290         // Create left background rectangle
3291         // NOTE: Uses finite aab
3292         Rectangle2D* rect1 = new Rectangle2D(true);
3293         rect1->setCorners(-0.5, 0.1, -0.1, -0.1);
3294         // Hacky, set small bounding box, to show problem
3295         rect1->setBoundingBox(AxisAlignedBox(-10.0*Vector3::UNIT_SCALE, 10.0*Vector3::UNIT_SCALE));
3296         rect1->setMaterial(material);
3297         rect1->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1);
3298         SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background1");
3299         node->attachObject(rect1);
3300 
3301         // Create right background rectangle
3302         // NOTE: Uses infinite aab
3303         Rectangle2D* rect2 = new Rectangle2D(true);
3304         rect2->setCorners(0.1, 0.1, 0.5, -0.1);
3305         AxisAlignedBox aabInf; aabInf.setInfinite();
3306         rect2->setBoundingBox(aabInf);
3307         rect2->setMaterial(material);
3308         rect2->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1);
3309         node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background2");
3310         node->attachObject(rect2);
3311 
3312         // Create a manual object for 2D
3313         ManualObject* manual = mSceneMgr->createManualObject("manual");
3314         manual->setUseIdentityProjection(true);
3315         manual->setUseIdentityView(true);
3316         manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
3317         manual->position(-0.2, -0.2, 0.0);
3318         manual->position( 0.2, -0.2, 0.0);
3319         manual->position( 0.2,  0.2, 0.0);
3320         manual->position(-0.2,  0.2, 0.0);
3321         manual->index(0);
3322         manual->index(1);
3323         manual->index(2);
3324         manual->index(3);
3325         manual->index(0);
3326         manual->end();
3327         manual->setBoundingBox(aabInf); // Use infinite aab to always stay visible
3328         rect2->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1);
3329         mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
3330     }
3331 
3332     mSceneMgr->showBoundingBoxes(true);
3333 
3334     Entity* ent = mSceneMgr->createEntity("test", "ogrehead.mesh");
3335     mSceneMgr->getRootSceneNode()->createChildSceneNode(
3336         "test", 50.0 * Vector3::UNIT_X)->attachObject(ent);
3337 
3338     mCameraNode->setPosition(100,50,350);
3339     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
3340 }
3341 //----------------------------------------------------------------------------
3342 //----------------------------------------------------------------------------
3343 
PlayPen_LightClipPlanes()3344 PlayPen_LightClipPlanes::PlayPen_LightClipPlanes()
3345 {
3346     mInfo["Title"] = "PlayPen_LightClipPlanes";
3347     mInfo["Description"] = "Tests light clipping planes.";
3348     addScreenshotFrame(10);
3349 }
3350 //----------------------------------------------------------------------------
3351 
setupContent()3352 void PlayPen_LightClipPlanes::setupContent()
3353 {
3354     mSceneMgr->setAmbientLight(ColourValue::White);
3355 
3356 
3357     Plane plane;
3358     plane.normal = Vector3::UNIT_Y;
3359     plane.d = 0;
3360     MeshManager::getSingleton().createPlane("Myplane",
3361                                             TRANSIENT_RESOURCE_GROUP, plane,
3362                                             4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
3363     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3364     pPlaneEnt->setMaterialName("Examples/GrassFloor");
3365     pPlaneEnt->setCastShadows(false);
3366     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,100))->attachObject(pPlaneEnt);
3367 
3368     Real lightRange = 1000;
3369     Real spotWidth = 300;
3370 
3371     ManualObject* debugSphere = mSceneMgr->createManualObject("debugSphere");
3372     debugSphere->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
3373     for (int i = 0; i <= 20; ++i)
3374     {
3375         Vector3 basePos(spotWidth, 0, 0);
3376         Quaternion quat;
3377         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y);
3378         basePos = quat * basePos;
3379         debugSphere->position(basePos);
3380     }
3381     debugSphere->end();
3382 
3383     Light* l = mSceneMgr->createLight("l1");
3384     l->setAttenuation(lightRange, 1, 0, 0);
3385     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0));
3386     n->attachObject(debugSphere);
3387     /* SPOT LIGHT
3388      */
3389     // match spot width to groud
3390     Real spotHeight = lightRange * 0.5;
3391     n = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,spotHeight,0));
3392     l->setType(Light::LT_SPOTLIGHT);
3393     Radian spotAngle = Math::ATan(spotWidth / spotHeight) * 2;
3394     l->setSpotlightOuterAngle(spotAngle);
3395     l->setSpotlightInnerAngle(spotAngle * 0.75);
3396     Vector3 dir(0, -1, 0);
3397     dir.normalise();
3398     l->setDirection(dir);
3399 
3400     /* END SPOT LIGHT */
3401     n->attachObject(l);
3402 
3403     // Modify the plane material so that it clips to the light
3404     // Normally you'd only clip a secondary pass but this is engineered so you
3405     // can actually see the scissoring effect
3406     MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/GrassFloor");
3407     Pass* p = mat->getTechnique(0)->getPass(0);
3408     p->setLightClipPlanesEnabled(true);
3409     //if (scissortoo)
3410     //p->setLightScissoringEnabled(true);
3411 
3412     mCameraNode->setPosition(0, 200, 300);
3413     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3414 
3415 
3416 
3417 }
3418 //----------------------------------------------------------------------------
3419 //----------------------------------------------------------------------------
3420 
PlayPen_LightClipPlanesMoreLights()3421 PlayPen_LightClipPlanesMoreLights::PlayPen_LightClipPlanesMoreLights()
3422 {
3423     mInfo["Title"] = "PlayPen_LightClipPlanesMoreLights";
3424     mInfo["Description"] = "Tests light clip planes with more lights.";
3425     addScreenshotFrame(10);
3426 }
3427 //----------------------------------------------------------------------------
3428 
setupContent()3429 void PlayPen_LightClipPlanesMoreLights::setupContent()
3430 {
3431     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.25, 0.2, 0));
3432     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
3433     mSceneMgr->setShadowTextureCount(3);
3434 
3435     Plane plane;
3436     plane.normal = Vector3::UNIT_Y;
3437     plane.d = 0;
3438     MeshManager::getSingleton().createPlane(
3439         "Myplane",
3440         TRANSIENT_RESOURCE_GROUP, plane,
3441         4500, 4500, 100, 100, true, 1, 5, 5, Vector3::UNIT_Z);
3442     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3443     pPlaneEnt->setMaterialName("Examples/GrassFloor");
3444     pPlaneEnt->setCastShadows(false);
3445     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
3446 
3447     Real lightRange = 1000;
3448     Real spotWidth = 300;
3449 
3450     int numLights = 8;
3451     Real xoff = -numLights * spotWidth * 0.5;
3452 
3453     for (int i = 0; i < numLights; ++i)
3454     {
3455         Light* l = mSceneMgr->createLight("l" + StringConverter::toString(i));
3456         l->setAttenuation(lightRange, 1, 0, 0);
3457         /* SPOT LIGHT
3458          */
3459         // match spot width to groud
3460         Real spotHeight = lightRange * 0.5;
3461         SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3((spotWidth+50)*i + xoff,spotHeight,0));
3462         l->setType(Light::LT_SPOTLIGHT);
3463         Radian spotAngle = Math::ATan(spotWidth / spotHeight) * 2;
3464         l->setSpotlightOuterAngle(spotAngle);
3465         l->setSpotlightInnerAngle(spotAngle * 0.75);
3466         Vector3 dir(0, -1, 0);
3467         dir.normalise();
3468         l->setDirection(dir);
3469 
3470         /* END SPOT LIGHT */
3471         n->attachObject(l);
3472 
3473         Entity* e = mSceneMgr->createEntity("e" + StringConverter::toString(i), "robot.mesh");
3474         SceneNode* en = n->createChildSceneNode(Vector3(0, -200, 0));
3475         en->attachObject(e);
3476     }
3477 
3478     // Modify the plane material so that it clips to the light on the second pass, post ambient
3479     MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/GrassFloor");
3480     Pass* p = mat->getTechnique(0)->getPass(0);
3481     String texname = p->getTextureUnitState(0)->getTextureName();
3482     p->removeAllTextureUnitStates();
3483     p->setIlluminationStage(IS_AMBIENT);
3484     p->setDiffuse(ColourValue::Black);
3485     p = mat->getTechnique(0)->createPass();
3486     p->setIlluminationStage(IS_PER_LIGHT);
3487     p->setIteratePerLight(true, true);
3488     //TODO Shouldn't the case below also be tested?
3489     // p->setIteratePerLight(true, false);
3490     p->setAmbient(ColourValue::Black);
3491     p->setLightClipPlanesEnabled(true);
3492     p->setSceneBlending(SBT_ADD);
3493     //if (scissortoo)
3494     p->setLightScissoringEnabled(true);
3495     p = mat->getTechnique(0)->createPass();
3496     p->setIlluminationStage(IS_DECAL);
3497     p->createTextureUnitState(texname);
3498     p->setLightingEnabled(false);
3499     p->setSceneBlending(SBT_MODULATE);
3500 
3501     mCameraNode->setPosition(0, 200, 300);
3502     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3503 
3504 }
3505 //----------------------------------------------------------------------------
3506 //----------------------------------------------------------------------------
3507 
PlayPen_LightScissoring()3508 PlayPen_LightScissoring::PlayPen_LightScissoring()
3509 {
3510     mInfo["Title"] = "PlayPen_LightScissoring";
3511     mInfo["Description"] = "Tests light scissoring.";
3512     addScreenshotFrame(10);
3513 }
3514 //----------------------------------------------------------------------------
3515 
setupContent()3516 void PlayPen_LightScissoring::setupContent()
3517 {
3518     mSceneMgr->setAmbientLight(ColourValue::White);
3519 
3520 
3521     Plane plane;
3522     plane.normal = Vector3::UNIT_Y;
3523     plane.d = 0;
3524     MeshManager::getSingleton().createPlane("Myplane",
3525                                             TRANSIENT_RESOURCE_GROUP, plane,
3526                                             4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
3527     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3528     pPlaneEnt->setMaterialName("Examples/GrassFloor");
3529     pPlaneEnt->setCastShadows(false);
3530     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
3531 
3532     Real lightRange = 100;
3533 
3534     ManualObject* debugSphere = mSceneMgr->createManualObject("debugSphere");
3535     debugSphere->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
3536     for (int i = 0; i <= 20; ++i)
3537     {
3538         Vector3 basePos(lightRange, 0, 0);
3539         Quaternion quat;
3540         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y);
3541         basePos = quat * basePos;
3542         debugSphere->position(basePos);
3543     }
3544     for (int i = 0; i <= 20; ++i)
3545     {
3546         Vector3 basePos(lightRange, 0, 0);
3547         Quaternion quat;
3548         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Z);
3549         basePos = quat * basePos;
3550         debugSphere->position(basePos);
3551     }
3552     debugSphere->end();
3553 
3554     ManualObject* debugSphere2 = mSceneMgr->createManualObject("debugSphere2");
3555     debugSphere2->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
3556     for (int i = 0; i <= 20; ++i)
3557     {
3558         Vector3 basePos(lightRange, 0, 0);
3559         Quaternion quat;
3560         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y);
3561         basePos = quat * basePos;
3562         debugSphere2->position(basePos);
3563     }
3564     for (int i = 0; i <= 20; ++i)
3565     {
3566         Vector3 basePos(lightRange, 0, 0);
3567         Quaternion quat;
3568         quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Z);
3569         basePos = quat * basePos;
3570         debugSphere2->position(basePos);
3571     }
3572     debugSphere2->end();
3573 
3574     Light* l = mSceneMgr->createLight("l1");
3575     l->setAttenuation(lightRange, 1, 0, 0);
3576     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,95,0));
3577     n->attachObject(debugSphere);
3578     n->attachObject(l);
3579 
3580     Light* l2 = mSceneMgr->createLight("l2");
3581     l2->setAttenuation(lightRange, 1, 0, 0);
3582     SceneNode* n2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,50,0));
3583     n2->attachObject(debugSphere2);
3584     n2->attachObject(l2);
3585 
3586     // Modify the plane material so that it clips to the light
3587     // Normally you'd only clip a secondary pass but this is engineered so you
3588     // can actually see the scissoring effect
3589     MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/GrassFloor");
3590     Pass* p = mat->getTechnique(0)->getPass(0);
3591     p->setLightScissoringEnabled(true);
3592     //if (cliptoo)
3593     p->setLightClipPlanesEnabled(true);
3594 
3595 
3596     mCameraNode->setPosition(0, 200, 300);
3597     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3598 
3599 }
3600 //----------------------------------------------------------------------------
3601 //----------------------------------------------------------------------------
3602 
PlayPen_LiSPSM()3603 PlayPen_LiSPSM::PlayPen_LiSPSM()
3604 {
3605     mInfo["Title"] = "PlayPen_LiSPSM";
3606     mInfo["Description"] = "Tests light-space shadow mapping camera setup.";
3607     addScreenshotFrame(10);
3608 }
3609 //----------------------------------------------------------------------------
3610 
cleanupContent()3611 void PlayPen_LiSPSM::cleanupContent()
3612 {
3613     clearDebugTextureOverlays();
3614 }
3615 //----------------------------------------------------------------------------
3616 
setupContent()3617 void PlayPen_LiSPSM::setupContent()
3618 {
3619     SceneNode* mTestNode[10];
3620 
3621     mSceneMgr->setShadowTextureSize(1024);
3622     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
3623 
3624     //FocusedShadowCameraSetup* lispsmSetup = new FocusedShadowCameraSetup();
3625     LiSPSMShadowCameraSetup* lispsmSetup = new LiSPSMShadowCameraSetup();
3626     lispsmSetup->setOptimalAdjustFactor(2);
3627     mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(lispsmSetup));
3628 
3629     mSceneMgr->setShadowFarDistance(3000);
3630     mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
3631     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
3632 
3633     Light* mLight = mSceneMgr->createLight("MainLight");
3634     mLight->setType(Light::LT_DIRECTIONAL);
3635     Vector3 vec(-1,-1,0);
3636     vec.normalise();
3637     mLight->setDirection(vec);
3638 
3639     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
3640 
3641 
3642     Entity* pEnt;
3643     pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
3644     //pEnt->setRenderingDistance(100);
3645     AnimationState* mAnimState = pEnt->getAnimationState("Walk");
3646     mAnimState->setEnabled(true);
3647     mAnimStateList.push_back(mAnimState);
3648     //pEnt->setMaterialName("2 - Default");
3649     mTestNode[1]->attachObject( pEnt );
3650     mTestNode[1]->translate(0,-100,0);
3651 
3652     pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
3653     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
3654     mTestNode[2]->attachObject( pEnt );
3655 
3656     createRandomEntityClones(pEnt, 20, Vector3(-1000,0,-1000), Vector3(1000,0,1000), mSceneMgr);
3657 
3658     // Transparent object (can force cast shadows)
3659     pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
3660     MaterialPtr tmat = MaterialManager::getSingleton().create(
3661         "TestAlphaTransparency",
3662         TRANSIENT_RESOURCE_GROUP);
3663     tmat->setTransparencyCastsShadows(true);
3664     Pass* tpass = tmat->getTechnique(0)->getPass(0);
3665     tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
3666     tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
3667     tpass->createTextureUnitState("gras_02.png");
3668     tpass->setCullingMode(CULL_NONE);
3669 
3670     pEnt->setMaterialName("TestAlphaTransparency");
3671     mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
3672     mTestNode[3]->attachObject( pEnt );
3673 
3674     pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
3675     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
3676     mTestNode[2]->attachObject( pEnt );
3677 
3678     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
3679 
3680     MovablePlane movablePlane = MovablePlane(Vector3::UNIT_Y, 100);
3681     MeshManager::getSingleton().createPlane("Myplane",
3682                                             TRANSIENT_RESOURCE_GROUP, movablePlane,
3683                                             2500,2500,10,10,true,1,5,5,Vector3::UNIT_Z);
3684     Entity* pPlaneEnt;
3685     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3686     pPlaneEnt->setMaterialName("2 - Default");
3687     pPlaneEnt->setCastShadows(false);
3688     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
3689 
3690     addTextureShadowDebugOverlay(1, mSceneMgr);
3691 
3692 
3693     mCameraNode->setPosition(0, 1000, 500);
3694     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
3695     mCamera->setFarClipDistance(10000);
3696 
3697 
3698 }
3699 //----------------------------------------------------------------------------
3700 //----------------------------------------------------------------------------
3701 
3702 
createRandomEntityClones(Entity * ent,size_t cloneCount,const Vector3 & min,const Vector3 & max,SceneManager * mgr)3703 static void createRandomEntityClones(Entity* ent, size_t cloneCount,
3704                               const Vector3& min, const Vector3& max, SceneManager* mgr)
3705 {
3706     Entity *cloneEnt;
3707     for (size_t n = 0; n < cloneCount; ++n)
3708     {
3709         // Create a new node under the root.
3710         SceneNode* node = mgr->createSceneNode();
3711         // Random translate.
3712         Vector3 nodePos;
3713         nodePos.x = Math::RangeRandom(min.x, max.x);
3714         nodePos.y = Math::RangeRandom(min.y, max.y);
3715         nodePos.z = Math::RangeRandom(min.z, max.z);
3716         node->setPosition(nodePos);
3717         mgr->getRootSceneNode()->addChild(node);
3718         cloneEnt = ent->clone(ent->getName() + "_clone" + StringConverter::toString(n));
3719         // Attach to new node.
3720         node->attachObject(cloneEnt);
3721 
3722     }
3723 }
3724 
PlayPen_LotsAndLotsOfEntities()3725 PlayPen_LotsAndLotsOfEntities::PlayPen_LotsAndLotsOfEntities()
3726 {
3727     mInfo["Title"] = "PlayPen_LotsAndLotsOfEntities";
3728     mInfo["Description"] = "Tests setting up and rendering a lot of entities.";
3729     addScreenshotFrame(3);// only go a couple frames, this one is slow (and static)
3730 }
3731 //----------------------------------------------------------------------------
3732 
setupContent()3733 void PlayPen_LotsAndLotsOfEntities::setupContent()
3734 {
3735     // Set ambient light.
3736     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
3737 
3738     // Create a point light.
3739     Light* l = mSceneMgr->createLight("MainLight");
3740     l->setType(Light::LT_DIRECTIONAL);
3741     l->setDirection(-Vector3::UNIT_Y);
3742 
3743     // Create a set of random cubes.
3744     Entity* ent = mSceneMgr->createEntity("Cube", "cube.mesh");
3745     ent->setMaterial(MaterialManager::getSingleton().getDefaultMaterial());
3746     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
3747     createRandomEntityClones(ent, 3000, Vector3(-1000,-1000,-1000), Vector3(1000,1000,1000), mSceneMgr);
3748 
3749     //bool val = true;
3750     //mSceneMgr->setOption("ShowOctree", &val);
3751 
3752     mCameraNode->setPosition(0,0, -4000);
3753     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
3754 
3755     // Enable the profiler.
3756     Profiler* prof = Profiler::getSingletonPtr();
3757     if (prof)
3758         prof->setEnabled(true);
3759 
3760 }
3761 //----------------------------------------------------------------------------
3762 //----------------------------------------------------------------------------
3763 
PlayPen_ManualBoneMovement()3764 PlayPen_ManualBoneMovement::PlayPen_ManualBoneMovement()
3765 {
3766     mInfo["Title"] = "PlayPen_ManualBoneMovement";
3767     mInfo["Description"] = "Tests manually controlling a skeletal animation bone.";
3768     addScreenshotFrame(50);
3769 }
3770 //----------------------------------------------------------------------------
3771 
frameStarted(const FrameEvent & evt)3772 bool PlayPen_ManualBoneMovement::frameStarted(const FrameEvent& evt)
3773 {
3774     mBone->yaw(Degree(evt.timeSinceLastFrame*100));
3775     return true;
3776 }
3777 //----------------------------------------------------------------------------
3778 
setupContent()3779 void PlayPen_ManualBoneMovement::setupContent()
3780 {
3781     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
3782     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
3783     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
3784 
3785     //ent->setMaterialName("Examples/Rocky");
3786 
3787     SkeletonInstance* skel = ent->getSkeleton();
3788     Animation* anim = skel->getAnimation("Walk");
3789     mBone = skel->getBone("Joint10");
3790     mBone->setManuallyControlled(true);
3791     anim->destroyNodeTrack(mBone->getHandle());
3792 
3793     //AnimationState* animState = ent->getAnimationState("Walk");
3794     //animState->setEnabled(true);
3795 
3796     mCameraNode->setPosition(100,50,200);
3797     mCameraNode->lookAt(Vector3(0, 25, 0), Node::TS_PARENT);
3798 }
3799 //----------------------------------------------------------------------------
3800 //----------------------------------------------------------------------------
3801 
PlayPen_ManualIlluminationStage()3802 PlayPen_ManualIlluminationStage::PlayPen_ManualIlluminationStage()
3803 {
3804     mInfo["Title"] = "PlayPen_ManualIlluminationStage";
3805     mInfo["Description"] = "Tests manual illumination stages.";
3806     addScreenshotFrame(10);
3807 }
3808 //----------------------------------------------------------------------------
3809 
setupContent()3810 void PlayPen_ManualIlluminationStage::setupContent()
3811 {
3812     mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
3813     mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000);
3814     MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
3815     MaterialManager::getSingleton().setDefaultAnisotropy(5);
3816 
3817     // Set ambient light
3818     mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
3819 
3820     Light* mLight = mSceneMgr->createLight("MainLight");
3821     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-400,400,-300))->attachObject(mLight);
3822     mLight->setDiffuseColour(0.9, 0.9, 1);
3823     mLight->setSpecularColour(0.9, 0.9, 1);
3824     mLight->setAttenuation(6000,1,0.001,0);
3825 
3826     mLight = mSceneMgr->createLight("Light2");
3827     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(300,200,100))->attachObject(mLight);
3828     mLight->setDiffuseColour(1, 0.6, 0.5);
3829     mLight->setSpecularColour(0.9, 0.9, 1);
3830     mLight->setAttenuation(6000,1,0.001,0);
3831 
3832     MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", ASSETS_RESOURCE_GROUP);
3833     msh->buildTangentVectors();
3834     Entity* pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
3835     pEnt->setMaterialName("Examples/OffsetMapping/Specular");
3836     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject( pEnt );
3837 
3838     Plane plane;
3839     plane.normal = Vector3::UNIT_Y;
3840     plane.d = 100;
3841     MeshPtr planeMesh = MeshManager::getSingleton().createPlane(
3842         "Myplane",
3843         TRANSIENT_RESOURCE_GROUP, plane,
3844         1500, 1500, 100, 100, true, 1, 15, 15, Vector3::UNIT_Z);
3845     planeMesh->buildTangentVectors();
3846     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3847     pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular");
3848     pPlaneEnt->setCastShadows(false);
3849     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
3850 
3851     mCameraNode->setPosition(180, 34, 223);
3852     mCameraNode->lookAt(Vector3(0, 50, 0), Node::TS_PARENT);
3853 }
3854 //----------------------------------------------------------------------------
3855 //----------------------------------------------------------------------------
3856 
PlayPen_ManualObject2D()3857 PlayPen_ManualObject2D::PlayPen_ManualObject2D()
3858 {
3859     mInfo["Title"] = "PlayPen_ManualObject2D";
3860     mInfo["Description"] = "Tests 2d manual objects.";
3861     addScreenshotFrame(10);
3862 }
3863 //----------------------------------------------------------------------------
3864 
setupContent()3865 void PlayPen_ManualObject2D::setupContent()
3866 {
3867     ManualObject* man = mSceneMgr->createManualObject("1");
3868     man->begin("Examples/OgreLogo");
3869     man->position( 0.0, 0.0, 0.0);  man->textureCoord( 0, 1 );
3870     man->position( 0.1, 0.0, 0.0);  man->textureCoord( 1, 1 );
3871     man->position( 0.1, 0.1, 0.0);  man->textureCoord( 1, 0 );
3872     man->position( 0.0, 0.1, 0.0);  man->textureCoord( 0, 0 );
3873 
3874     man->triangle( 0, 1, 2 );
3875     man->triangle( 0, 2, 3 );
3876 
3877     man->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY -1);
3878     man->end();
3879     man->setUseIdentityProjection(true);
3880     man->setUseIdentityView(true);
3881     AxisAlignedBox aabb;
3882     aabb.setInfinite();
3883     man->setBoundingBox(aabb);
3884 
3885     SceneNode* sn = mSceneMgr->getRootSceneNode()->createChildSceneNode();
3886     sn->setScale(5,5,1);
3887     sn->attachObject(man);
3888 }
3889 //----------------------------------------------------------------------------
3890 //----------------------------------------------------------------------------
3891 
PlayPen_ManualObjectIndexed()3892 PlayPen_ManualObjectIndexed::PlayPen_ManualObjectIndexed()
3893 {
3894     mInfo["Title"] = "PlayPen_ManualObjectIndexed";
3895     mInfo["Description"] = "Tests indexed manual objects.";
3896     addScreenshotFrame(10);
3897 }
3898 //----------------------------------------------------------------------------
3899 
setupContent()3900 void PlayPen_ManualObjectIndexed::setupContent()
3901 {
3902     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
3903     Vector3 dir(-1, -1, 0.5);
3904     dir.normalise();
3905     Light* l = mSceneMgr->createLight("light1");
3906     l->setType(Light::LT_DIRECTIONAL);
3907     l->setDirection(dir);
3908 
3909     Plane plane;
3910     plane.normal = Vector3::UNIT_Y;
3911     plane.d = 100;
3912     MeshManager::getSingleton().createPlane("Myplane",
3913                                             TRANSIENT_RESOURCE_GROUP, plane,
3914                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
3915     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
3916     pPlaneEnt->setMaterialName("2 - Default");
3917     pPlaneEnt->setCastShadows(false);
3918     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
3919 
3920     // Define a 40x40 plane, indexed
3921     //! [manual_plane_begin]
3922     Ogre::ManualObject* man = mSceneMgr->createManualObject("test");
3923     man->begin("Examples/OgreLogo", Ogre::RenderOperation::OT_TRIANGLE_LIST);
3924     //! [manual_plane_begin]
3925 
3926     //! [manual_plane_vertices]
3927     man->position(-20, 20, 20);
3928     man->normal(0, 0, 1);
3929     man->textureCoord(0, 0);
3930 
3931     man->position(-20, -20, 20);
3932     man->normal(0, 0, 1);
3933     man->textureCoord(0, 1);
3934 
3935     man->position(20, -20, 20);
3936     man->normal(0, 0, 1);
3937     man->textureCoord(1, 1);
3938 
3939     man->position(20, 20, 20);
3940     man->normal(0, 0, 1);
3941     man->textureCoord(1, 0);
3942     //! [manual_plane_vertices]
3943 
3944     //! [manual_plane_faces]
3945     man->quad(0, 1, 2, 3);
3946     //! [manual_plane_faces]
3947 
3948     man->end();
3949 
3950     man->begin("Examples/BumpyMetal");
3951 
3952     // Define a 40x40 plane, indexed
3953     man->position(-20, 20, 20);
3954     man->normal(0, 1, 0);
3955     man->textureCoord(0, 0);
3956 
3957     man->position(20, 20, 20);
3958     man->normal(0, 1, 0);
3959     man->textureCoord(0, 1);
3960 
3961     man->position(20, 20, -20);
3962     man->normal(0, 1, 0);
3963     man->textureCoord(1, 1);
3964 
3965     man->position(-20, 20, -20);
3966     man->normal(0, 1, 0);
3967     man->textureCoord(1, 0);
3968 
3969     man->quad(0, 1, 2, 3);
3970 
3971     //! [manual_plane_end]
3972     man->end();
3973     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
3974     //! [manual_plane_end]
3975 
3976     mCameraNode->setPosition(100,100,100);
3977     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
3978 
3979 }
3980 //----------------------------------------------------------------------------
3981 //----------------------------------------------------------------------------
3982 
PlayPen_ManualObjectIndexedUpdateLarger()3983 PlayPen_ManualObjectIndexedUpdateLarger::PlayPen_ManualObjectIndexedUpdateLarger()
3984 {
3985     mInfo["Title"] = "PlayPen_ManualObjectIndexedUpdateLarger";
3986     mInfo["Description"] = "Tests updating indexed manual objects.";
3987 }
3988 //----------------------------------------------------------------------------
3989 
setupContent()3990 void PlayPen_ManualObjectIndexedUpdateLarger::setupContent()
3991 {
3992     PlayPen_ManualObjectIndexed::setupContent();
3993     ManualObject* man = static_cast<ManualObject*>(
3994         mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
3995 
3996 
3997     man->beginUpdate(0);
3998     // 1 quad larger
3999     man->position(-20, 20, 20);
4000     man->normal(0, 0, 1);
4001     man->textureCoord(0, 0);
4002 
4003     man->position(-20, -20, 20);
4004     man->normal(0, 0, 1);
4005     man->textureCoord(0, 1);
4006 
4007     man->position(20, -20, 20);
4008     man->normal(0, 0, 1);
4009     man->textureCoord(1, 1);
4010 
4011     man->position(20, 20, 20);
4012     man->normal(0, 0, 1);
4013     man->textureCoord(1, 0);
4014 
4015 
4016     man->position(-20, 40, 20);
4017     man->normal(0, 0, 1);
4018     man->textureCoord(0, 0);
4019 
4020     man->position(-20, 20, 20);
4021     man->normal(0, 0, 1);
4022     man->textureCoord(0, 1);
4023 
4024     man->position(20, 20, 20);
4025     man->normal(0, 0, 1);
4026     man->textureCoord(1, 1);
4027 
4028     man->position(20, 40, 20);
4029     man->normal(0, 0, 1);
4030     man->textureCoord(1, 0);
4031 
4032     man->quad(0, 1, 2, 3);
4033     man->quad(4, 5, 6, 7);
4034 
4035     man->end();
4036 
4037 }
4038 //----------------------------------------------------------------------------
4039 //----------------------------------------------------------------------------
4040 
PlayPen_ManualObjectIndexedUpdateSmaller()4041 PlayPen_ManualObjectIndexedUpdateSmaller::PlayPen_ManualObjectIndexedUpdateSmaller()
4042 {
4043     mInfo["Title"] = "PlayPen_ManualObjectIndexedUpdateSmaller";
4044     mInfo["Description"] = "Tests updating indexed manual objects.";
4045 }
4046 //----------------------------------------------------------------------------
4047 
setupContent()4048 void PlayPen_ManualObjectIndexedUpdateSmaller::setupContent()
4049 {
4050     PlayPen_ManualObjectIndexed::setupContent();
4051     ManualObject* man = static_cast<ManualObject*>(
4052         mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
4053 
4054 
4055     man->beginUpdate(0);
4056     // 1 tri smaller
4057     man->position(-20, 20, 20);
4058     man->normal(0, 0, 1);
4059     man->textureCoord(0, 0);
4060 
4061     man->position(-20, -20, 20);
4062     man->normal(0, 0, 1);
4063     man->textureCoord(0, 1);
4064 
4065     man->position(20, -20, 20);
4066     man->normal(0, 0, 1);
4067     man->textureCoord(1, 1);
4068 
4069     man->triangle(0, 1, 2);
4070 
4071     man->end();
4072 
4073 }
4074 //----------------------------------------------------------------------------
4075 //----------------------------------------------------------------------------
4076 
PlayPen_ManualObjectNonIndexed()4077 PlayPen_ManualObjectNonIndexed::PlayPen_ManualObjectNonIndexed()
4078 {
4079     mInfo["Title"] = "PlayPen_ManualObjectNonIndexed";
4080     mInfo["Description"] = "Tests non-indexed manual objects.";
4081     addScreenshotFrame(10);
4082 }
4083 //----------------------------------------------------------------------------
4084 
setupContent()4085 void PlayPen_ManualObjectNonIndexed::setupContent()
4086 {
4087     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
4088     Vector3 dir(-1, -1, 0.5);
4089     dir.normalise();
4090     Light* l = mSceneMgr->createLight("light1");
4091     l->setType(Light::LT_DIRECTIONAL);
4092     l->setDirection(dir);
4093 
4094     Plane plane;
4095     plane.normal = Vector3::UNIT_Y;
4096     plane.d = 100;
4097     MeshManager::getSingleton().createPlane("Myplane",
4098                                             TRANSIENT_RESOURCE_GROUP, plane,
4099                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
4100     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
4101     pPlaneEnt->setMaterialName("2 - Default");
4102     pPlaneEnt->setCastShadows(false);
4103     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
4104 
4105     ManualObject* man = static_cast<ManualObject*>(
4106         mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
4107 
4108     man->begin("Examples/OgreLogo");
4109     // Define a 40x40 plane, non-indexed
4110     man->position(-20, 20, 20);
4111     man->normal(0, 0, 1);
4112     man->textureCoord(0, 0);
4113 
4114     man->position(-20, -20, 20);
4115     man->normal(0, 0, 1);
4116     man->textureCoord(0, 1);
4117 
4118     man->position(20, 20, 20);
4119     man->normal(0, 0, 1);
4120     man->textureCoord(1, 0);
4121 
4122     man->position(-20, -20, 20);
4123     man->normal(0, 0, 1);
4124     man->textureCoord(0, 1);
4125 
4126     man->position(20, -20, 20);
4127     man->normal(0, 0, 1);
4128     man->textureCoord(1, 1);
4129 
4130     man->position(20, 20, 20);
4131     man->normal(0, 0, 1);
4132     man->textureCoord(1, 0);
4133 
4134     man->end();
4135 
4136     man->begin("Examples/BumpyMetal");
4137 
4138     // Define a 40x40 plane, non-indexed
4139     man->position(-20, 20, 20);
4140     man->normal(0, 1, 0);
4141     man->textureCoord(0, 0);
4142 
4143     man->position(20, 20, 20);
4144     man->normal(0, 1, 0);
4145     man->textureCoord(0, 1);
4146 
4147     man->position(20, 20, -20);
4148     man->normal(0, 1, 0);
4149     man->textureCoord(1, 1);
4150 
4151     man->position(20, 20, -20);
4152     man->normal(0, 1, 0);
4153     man->textureCoord(1, 1);
4154 
4155     man->position(-20, 20, -20);
4156     man->normal(0, 1, 0);
4157     man->textureCoord(1, 0);
4158 
4159     man->position(-20, 20, 20);
4160     man->normal(0, 1, 0);
4161     man->textureCoord(0, 0);
4162 
4163     man->end();
4164 
4165 
4166     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
4167     mCameraNode->setPosition(100,100,100);
4168     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
4169 
4170 }
4171 //----------------------------------------------------------------------------
4172 //----------------------------------------------------------------------------
4173 
PlayPen_ManualObjectNonIndexedUpdateLarger()4174 PlayPen_ManualObjectNonIndexedUpdateLarger::PlayPen_ManualObjectNonIndexedUpdateLarger()
4175 {
4176     mInfo["Title"] = "PlayPen_ManualObjectNonIndexedUpdateLarger";
4177     mInfo["Description"] = "Tests updating non-indexed manual objects.";
4178 }
4179 //----------------------------------------------------------------------------
4180 
setupContent()4181 void PlayPen_ManualObjectNonIndexedUpdateLarger::setupContent()
4182 {
4183     PlayPen_ManualObjectNonIndexed::setupContent();
4184     ManualObject* man = static_cast<ManualObject*>(
4185         mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
4186 
4187     // Redefine but make larger (2 more tri)
4188     man->beginUpdate(0);
4189 
4190     man->position(-20, 20, 20);
4191     man->normal(0, 0, 1);
4192     man->textureCoord(0, 0);
4193 
4194     man->position(-20, -20, 20);
4195     man->normal(0, 0, 1);
4196     man->textureCoord(0, 1);
4197 
4198     man->position(20, 20, 20);
4199     man->normal(0, 0, 1);
4200     man->textureCoord(1, 0);
4201 
4202     man->position(-20, -20, 20);
4203     man->normal(0, 0, 1);
4204     man->textureCoord(0, 1);
4205 
4206     man->position(20, -20, 20);
4207     man->normal(0, 0, 1);
4208     man->textureCoord(1, 1);
4209 
4210     man->position(20, 20, 20);
4211     man->normal(0, 0, 1);
4212     man->textureCoord(1, 0);
4213 
4214 
4215     man->position(-20, 40, 20);
4216     man->normal(0, 0, 1);
4217     man->textureCoord(0, 0);
4218 
4219     man->position(-20, 20, 20);
4220     man->normal(0, 0, 1);
4221     man->textureCoord(0, 1);
4222 
4223     man->position(20, 40, 20);
4224     man->normal(0, 0, 1);
4225     man->textureCoord(1, 0);
4226 
4227     man->position(-20, 20, 20);
4228     man->normal(0, 0, 1);
4229     man->textureCoord(0, 1);
4230 
4231     man->position(20, 20, 20);
4232     man->normal(0, 0, 1);
4233     man->textureCoord(1, 1);
4234 
4235     man->position(20, 40, 20);
4236     man->normal(0, 0, 1);
4237     man->textureCoord(1, 0);
4238 
4239 
4240     man->end();
4241 
4242 }
4243 //----------------------------------------------------------------------------
4244 //----------------------------------------------------------------------------
4245 
PlayPen_ManualObjectNonIndexedUpdateSmaller()4246 PlayPen_ManualObjectNonIndexedUpdateSmaller::PlayPen_ManualObjectNonIndexedUpdateSmaller()
4247 {
4248     mInfo["Title"] = "PlayPen_ManualObjectNonIndexedUpdateSmaller";
4249     mInfo["Description"] = "Tests updating non-indexed manual objects.";
4250 }
4251 //----------------------------------------------------------------------------
4252 
setupContent()4253 void PlayPen_ManualObjectNonIndexedUpdateSmaller::setupContent()
4254 {
4255     PlayPen_ManualObjectNonIndexed::setupContent();
4256     ManualObject* man = static_cast<ManualObject*>(
4257         mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
4258 
4259     // Redefine but make smaller (one tri less)
4260     man->beginUpdate(0);
4261     man->position(-30, 30, 30);
4262     man->normal(0, 0, 1);
4263     man->textureCoord(0, 0);
4264 
4265     man->position(-30, -30, 30);
4266     man->normal(0, 0, 1);
4267     man->textureCoord(0, 1);
4268 
4269     man->position(90, 30, 30);
4270     man->normal(0, 0, 1);
4271     man->textureCoord(1, 0);
4272 
4273 
4274     man->end();
4275 
4276 }
4277 //----------------------------------------------------------------------------
4278 //----------------------------------------------------------------------------
4279 
PlayPen_MaterialSchemes()4280 PlayPen_MaterialSchemes::PlayPen_MaterialSchemes()
4281 {
4282     mInfo["Title"] = "PlayPen_MaterialSchemes";
4283     mInfo["Description"] = "Tests material scehemes in viewports.";
4284     addScreenshotFrame(10);
4285 }
4286 //----------------------------------------------------------------------------
4287 
setupContent()4288 void PlayPen_MaterialSchemes::setupContent()
4289 {
4290 
4291     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
4292     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4293     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
4294 
4295     MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
4296                                                              TRANSIENT_RESOURCE_GROUP);
4297     // default scheme
4298     mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
4299 
4300     Technique* t = mat->createTechnique();
4301     t->setSchemeName("newscheme");
4302     t->createPass()->createTextureUnitState("rockwall.tga");
4303     ent->setMaterialName("schemetest");
4304 
4305 #ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
4306     // force create shaders for non default scheme
4307     t->setSchemeName("newscheme_tmp");
4308     RTShader::ShaderGenerator& rtShaderGen = RTShader::ShaderGenerator::getSingleton();
4309     rtShaderGen.createShaderBasedTechnique(*mat, "newscheme_tmp", "newscheme");
4310     rtShaderGen.validateMaterial("newscheme", mat->getName(), mat->getGroup());
4311 #endif
4312 
4313     // create a second viewport using alternate scheme
4314     Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
4315     vp->setMaterialScheme("newscheme");
4316     vp->setOverlaysEnabled(false);
4317 
4318     mCameraNode->setPosition(0,75,200);
4319 
4320 }
4321 //----------------------------------------------------------------------------
4322 //----------------------------------------------------------------------------
4323 
PlayPen_MaterialSchemesListener()4324 PlayPen_MaterialSchemesListener::PlayPen_MaterialSchemesListener()
4325 {
4326     mInfo["Title"] = "PlayPen_MaterialSchemesListener";
4327     mInfo["Description"] = "Tests material scheme listener.";
4328     addScreenshotFrame(10);
4329 }
4330 //----------------------------------------------------------------------------
4331 
4332 class TestMatMgrListener : public MaterialManager::Listener
4333 {
4334 public:
TestMatMgrListener()4335     TestMatMgrListener() : mTech(0) {}
4336     Technique* mTech;
4337 
4338 
handleSchemeNotFound(unsigned short schemeIndex,const String & schemeName,Material * originalMaterial,unsigned short lodIndex,const Renderable * rend)4339     Technique* handleSchemeNotFound(unsigned short schemeIndex,
4340                                     const String& schemeName, Material* originalMaterial, unsigned short lodIndex,
4341                                     const Renderable* rend)
4342     {
4343         return mTech;
4344     }
4345 };
4346 
4347 TestMatMgrListener schemeListener;
4348 
setupContent()4349 void PlayPen_MaterialSchemesListener::setupContent()
4350 {
4351     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
4352 
4353     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
4354     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4355 
4356     // create a second viewport using alternate scheme
4357     // notice it's not defined in a technique
4358     Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
4359     vp->setMaterialScheme("newscheme");
4360     vp->setOverlaysEnabled(false);
4361 
4362     MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
4363                                                              TRANSIENT_RESOURCE_GROUP);
4364     // default scheme
4365     mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
4366 
4367     schemeListener.mTech = mat->getTechnique(0);
4368     MaterialManager::getSingleton().addListener(&schemeListener);
4369 
4370     mCameraNode->setPosition(0, 75, 200);
4371 }
4372 //----------------------------------------------------------------------------
4373 //----------------------------------------------------------------------------
4374 
PlayPen_MaterialSchemesWithLOD()4375 PlayPen_MaterialSchemesWithLOD::PlayPen_MaterialSchemesWithLOD()
4376 {
4377     mInfo["Title"] = "PlayPen_MaterialSchemesWithLOD";
4378     mInfo["Description"] = "Tests material schemes with LODs.";
4379     addScreenshotFrame(10);
4380 }
4381 //----------------------------------------------------------------------------
4382 
setupContent()4383 void PlayPen_MaterialSchemesWithLOD::setupContent()
4384 {
4385 
4386     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
4387     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4388     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
4389 
4390     MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
4391                                                              TRANSIENT_RESOURCE_GROUP);
4392     // default scheme
4393     mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
4394 
4395     // LOD 0, newscheme
4396     Technique* t = mat->createTechnique();
4397     t->setSchemeName("newscheme");
4398     t->createPass()->createTextureUnitState("rockwall.tga");
4399     ent->setMaterialName("schemetest");
4400 
4401     // LOD 1, default
4402     t = mat->createTechnique();
4403     t->setLodIndex(1);
4404     t->createPass()->createTextureUnitState("Water02.jpg");
4405 
4406     // LOD 1, newscheme
4407     t = mat->createTechnique();
4408     t->setLodIndex(1);
4409     t->createPass()->createTextureUnitState("r2skin.jpg");
4410     t->setSchemeName("newscheme");
4411 
4412     Material::LodValueList ldl;
4413     //ldl.push_back(Math::Sqr(500.0f));
4414     ldl.push_back(150.0f);
4415     mat->setLodLevels(ldl);
4416 
4417 
4418     ent->setMaterialName("schemetest");
4419 
4420     // create a second viewport using alternate scheme
4421     Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
4422     vp->setMaterialScheme("newscheme");
4423     vp->setOverlaysEnabled(false);
4424 
4425     mCameraNode->setPosition(0,90,250);
4426     //mCameraNode->lookAt(Vector3(Vector3(0, 0, 0)), Node::TS_PARENT);
4427 }
4428 //----------------------------------------------------------------------------
4429 //----------------------------------------------------------------------------
4430 
PlayPen_MaterialSchemesWithMismatchedLOD()4431 PlayPen_MaterialSchemesWithMismatchedLOD::PlayPen_MaterialSchemesWithMismatchedLOD()
4432 {
4433     mInfo["Title"] = "PlayPen_MaterialSchemesWithMismatchedLOD";
4434     mInfo["Description"] = "Tests material scehemes in viewports with mismatched LODs.";
4435     addScreenshotFrame(10);
4436 }
4437 //----------------------------------------------------------------------------
4438 
setupContent()4439 void PlayPen_MaterialSchemesWithMismatchedLOD::setupContent()
4440 {
4441 
4442     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
4443     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4444     mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
4445 
4446     MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
4447                                                              TRANSIENT_RESOURCE_GROUP);
4448     // default scheme
4449     mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
4450 
4451     // LOD 0, newscheme
4452     Technique* t = mat->createTechnique();
4453     t->setSchemeName("newscheme");
4454     t->createPass()->createTextureUnitState("rockwall.tga");
4455     ent->setMaterialName("schemetest");
4456 
4457     // LOD 1, default
4458     t = mat->createTechnique();
4459     t->setLodIndex(1);
4460     t->createPass()->createTextureUnitState("Water02.jpg");
4461 
4462     // LOD 2, default
4463     t = mat->createTechnique();
4464     t->setLodIndex(2);
4465     t->createPass()->createTextureUnitState("clouds.jpg");
4466 
4467     // LOD 1, newscheme
4468     t = mat->createTechnique();
4469     t->setLodIndex(1);
4470     t->createPass()->createTextureUnitState("r2skin.jpg");
4471     t->setSchemeName("newscheme");
4472 
4473     // No LOD 2 for newscheme! Should fallback on LOD 1
4474 
4475     Material::LodValueList ldl;
4476     //ldl.push_back(Math::Sqr(250.0f));
4477     //ldl.push_back(Math::Sqr(500.0f));
4478     ldl.push_back(150.0f);
4479     ldl.push_back(300.0f);
4480     mat->setLodLevels(ldl);
4481 
4482 
4483     ent->setMaterialName("schemetest");
4484 
4485     // create a second viewport using alternate scheme
4486     Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
4487     vp->setMaterialScheme("newscheme");
4488     vp->setOverlaysEnabled(false);
4489 
4490     mCameraNode->setPosition(0,90,350);
4491 }
4492 //----------------------------------------------------------------------------
4493 //----------------------------------------------------------------------------
4494 
4495 /*PlayPen_MRTCompositorScript::PlayPen_MRTCompositorScript()
4496   {
4497   mInfo["Title"] = "PlayPen_MRTCompositorScript";
4498   mInfo["Description"] = "Tests MRT compositor.";
4499   addScreenshotFrame(250);
4500   }
4501   //----------------------------------------------------------------------------
4502 
4503   void PlayPen_MRTCompositorScript::setupContent()
4504   {
4505 
4506   Entity* e = mSceneMgr->createEntity("e1", "knot.mesh");
4507   e->setMaterialName("Ogre/MRTtest/scene");
4508   mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
4509   mCameraNode->setPosition(0, 0, -100);
4510   mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
4511 
4512   CompositorInstance* compInst =
4513   CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "TestMRT");
4514   CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), "TestMRT", true);
4515 
4516   // Set up debug panels for each of the MRT outputs
4517   String texName = compInst->getTextureInstanceName("mrt0", 0);
4518   addTextureDebugOverlay(TextureManager::getSingleton().getByName(texName), 0);
4519   texName = compInst->getTextureInstanceName("mrt0", 1);
4520   addTextureDebugOverlay(TextureManager::getSingleton().getByName(texName), 1);
4521   texName = compInst->getTextureInstanceName("mrt0", 2);
4522   addTextureDebugOverlay(TextureManager::getSingleton().getByName(texName), 2);
4523   texName = compInst->getTextureInstanceName("mrt0", 3);
4524   addTextureDebugOverlay(TextureManager::getSingleton().getByName(texName), 3);
4525   }*/
4526 //----------------------------------------------------------------------------
4527 //----------------------------------------------------------------------------
4528 
4529 /*PlayPen_MRT::PlayPen_MRT()
4530   {
4531   mInfo["Title"] = "PlayPen_MRT";
4532   mInfo["Description"] = "Tests MRT.";
4533   addScreenshotFrame(250);
4534   }
4535   //----------------------------------------------------------------------------
4536 
4537   void PlayPen_MRT::setupContent()
4538   {
4539   TexturePtr Tex[2];
4540   MultiRenderTarget* mrtTex;
4541 
4542   Viewport* viewport = mWindow->getViewport(0);
4543   int width = viewport->getActualWidth();
4544   int height = viewport->getActualHeight();
4545 
4546   Tex[0] = TextureManager::getSingleton().createManual("diffusemap", TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
4547   width,height,0,PF_R8G8B8A8,TU_RENDERTARGET);
4548   Tex[1] = TextureManager::getSingleton().createManual("normalmap",TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
4549   width,height,0,PF_R8G8B8A8,TU_RENDERTARGET);
4550 
4551   //    assert(Tex[0]->getFormat() == PF_FLOAT16_RGBA);
4552 
4553   mrtTex = Ogre::Root::getSingleton().getRenderSystem()->createMultiRenderTarget("MRT");
4554   RenderTexture* rTex[2];
4555   rTex[0] = Tex[0]->getBuffer()->getRenderTarget();
4556   rTex[1] = Tex[1]->getBuffer()->getRenderTarget();
4557 
4558   rTex[0]->setAutoUpdated(false);
4559   rTex[1]->setAutoUpdated(false);
4560   mrtTex->bindSurface(0, rTex[0]);
4561   mrtTex->bindSurface(1, rTex[1]);
4562   mrtTex->setAutoUpdated(true);
4563 
4564   Viewport *v = mrtTex->addViewport(mCamera);
4565   v->setMaterialScheme("MRT");
4566   v->setClearEveryFrame(true);
4567   v->setOverlaysEnabled(false);
4568   v->setSkiesEnabled(false);
4569   v->setBackgroundColour(ColourValue(0,0,0,0));
4570 
4571   // Create texture overlay here
4572   Overlay *debugOverlay = OverlayManager::getSingleton().create("Core/DebugOverlay");
4573   MaterialPtr debugMat = MaterialManager::getSingleton().create("DebugRTTMat1", TRANSIENT_RESOURCE_GROUP);
4574   debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
4575   TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("normalmap");
4576   t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
4577   OverlayContainer *debugPanel = (OverlayContainer *) (OverlayManager::getSingleton().createOverlayElement("Panel","DebugRTTPanel1"));
4578   debugPanel->_setPosition(0.8,0);
4579   debugPanel->_setDimensions(0.2,0.3);
4580   debugPanel->setMaterialName(debugMat->getName());
4581   debugOverlay->add2D(debugPanel);
4582 
4583   debugMat = MaterialManager::getSingleton().create("DebugRTTMat2", TRANSIENT_RESOURCE_GROUP);
4584   debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
4585   t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("diffusemap");
4586   t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
4587   debugPanel = (OverlayContainer *) (OverlayManager::getSingleton().createOverlayElement("Panel","DebugRTTPanel2"));
4588   debugPanel->_setPosition(0.8,0.3);
4589   debugPanel->_setDimensions(0.2,0.3);
4590   debugPanel->setMaterialName(debugMat->getName());
4591   debugOverlay->add2D(debugPanel);
4592   // Create scene items
4593 
4594   // Create a material to render differently to MRT compared to main viewport
4595   MaterialPtr mat = MaterialManager::getSingleton().create("MRTTest",
4596   TRANSIENT_RESOURCE_GROUP);
4597   // normal technique (0), leave as default
4598   Technique* mrtTech = mat->createTechnique();
4599   mrtTech->setSchemeName("MRT");
4600   Pass* mrtPass = mrtTech->createPass();
4601   mrtPass->setVertexProgram("DeferredShading/material/hlsl/vs");
4602   mrtPass->setFragmentProgram("DeferredShading/material/hlsl/ps");
4603   mrtPass->createTextureUnitState("rockwall.tga");
4604   mat->load();
4605 
4606   Entity* ent = mSceneMgr->createEntity("knot", "knot.mesh");
4607   ent->setMaterialName("MRTTest");
4608   mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4609 
4610   mCameraNode->setPosition(0, 0, 200);
4611   mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
4612 
4613 
4614 
4615   }*/
4616 //----------------------------------------------------------------------------
4617 //----------------------------------------------------------------------------
4618 
PlayPen_MultiSceneManagersSimple()4619 PlayPen_MultiSceneManagersSimple::PlayPen_MultiSceneManagersSimple()
4620 {
4621     mInfo["Title"] = "PlayPen_MultiSceneManagersSimple";
4622     mInfo["Description"] = "Tests multiple scene managers.";
4623     addScreenshotFrame(10);
4624 }
4625 //----------------------------------------------------------------------------
4626 
setupContent()4627 void PlayPen_MultiSceneManagersSimple::setupContent()
4628 {
4629     // Create a secondary scene manager with it's own camera
4630     SceneManager* sm2 = Root::getSingleton().createSceneManager();
4631     Light* l = sm2->createLight("l2");
4632     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 50, -100))->attachObject(l);
4633     l->setDiffuseColour(ColourValue::Green);
4634     // l->setDiffuseColour(ColourValue::Red);
4635     sm2->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
4636     // sm2->setAmbientLight(ColourValue(1, 1, 1));
4637     Entity* ent = sm2->createEntity("knot2", "knot.mesh");
4638     // Entity* ent = sm2->createEntity("head", "ogrehead.mesh");
4639     sm2->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4640     Camera* camera2 = sm2->createCamera("cam2");
4641     SceneNode* camNode2 = sm2->getRootSceneNode()->createChildSceneNode();
4642     camNode2->attachObject(camera2);
4643     camNode2->setPosition(0, 0, -500);
4644     camNode2->lookAt(Vector3::ZERO, Node::TS_PARENT);
4645 
4646     Viewport* vp = mWindow->addViewport(camera2, 1, 0.67, 0, 0.33, 0.25);
4647     vp->setOverlaysEnabled(false);
4648     vp->setBackgroundColour(ColourValue(1,0,0));
4649 
4650     // Use original SM for normal scene
4651     l = mSceneMgr->createLight("l"); // note same name, will work since different SM
4652     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 50, -100))->attachObject(l);
4653     l->setDiffuseColour(ColourValue::Red);
4654     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
4655     ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
4656     // ent = mSceneMgr->createEntity("knot", "knot.mesh");
4657     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
4658     mCameraNode->setPosition(0, 0, 500);
4659 }
4660 //----------------------------------------------------------------------------
4661 //----------------------------------------------------------------------------
4662 
PlayPen_MultiViewports()4663 PlayPen_MultiViewports::PlayPen_MultiViewports()
4664 {
4665     mInfo["Title"] = "PlayPen_MultiViewports";
4666     mInfo["Description"] = "Tests multiple viewports.";
4667     addScreenshotFrame(10);
4668 }
4669 //----------------------------------------------------------------------------
4670 
setupContent()4671 void PlayPen_MultiViewports::setupContent()
4672 {
4673     SceneNode* mTestNode[3];
4674 
4675     // Set ambient light
4676     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
4677 
4678     // Create a point light
4679     Light* l = mSceneMgr->createLight("MainLight");
4680     l->setType(Light::LT_DIRECTIONAL);
4681     l->setDirection(-Vector3::UNIT_Y);
4682 
4683     Entity* pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
4684     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
4685 
4686     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4687 
4688     pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
4689     mTestNode[0]->attachObject( pEnt );
4690     mTestNode[0]->translate(0, 0, 200);
4691 
4692     Ogre::Frustum* frustum = new Frustum();
4693     //frustum->setVisible(true);
4694     frustum->setFarClipDistance(5000);
4695     frustum->setNearClipDistance(100);
4696     mTestNode[0]->attachObject(frustum);
4697 
4698     Viewport* vp = mWindow->addViewport(mCamera, 1, 0.5, 0.5, 0.5, 0.5);
4699     vp->setOverlaysEnabled(false);
4700     vp->setBackgroundColour(ColourValue(1,0,0));
4701 
4702     mCameraNode->setPosition(0,0,500);
4703 
4704 }
4705 //----------------------------------------------------------------------------
4706 //----------------------------------------------------------------------------
4707 
PlayPen_NegativeScale()4708 PlayPen_NegativeScale::PlayPen_NegativeScale()
4709 {
4710     mInfo["Title"] = "PlayPen_NegativeScale";
4711     mInfo["Description"] = "Tests negative scaling.";
4712     addScreenshotFrame(10);
4713 }
4714 //----------------------------------------------------------------------------
4715 
setupContent()4716 void PlayPen_NegativeScale::setupContent()
4717 {
4718     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
4719     Light* l = mSceneMgr->createLight("l1");
4720     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(500, 500, 200))->attachObject(l);
4721     l->setDiffuseColour(ColourValue::White);
4722 
4723     //mSceneMgr->setFlipCullingOnNegativeScale(false);
4724 
4725     Entity *e = mSceneMgr->createEntity("1", "knot.mesh");
4726 
4727     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
4728 
4729     // one reflection
4730     e = mSceneMgr->createEntity("2", "knot.mesh");
4731     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4732     n->translate(-200, 0, 0);
4733     n->scale(-1, 1, 1);
4734     n->attachObject(e);
4735 
4736     // three reflections - will need flipping
4737     e = mSceneMgr->createEntity("3", "knot.mesh");
4738     n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4739     n->translate(200, 0, 0);
4740     n->scale(-1, -1, -1);
4741     n->attachObject(e);
4742 
4743     // two reflections - won't need flipping
4744     e = mSceneMgr->createEntity("4", "knot.mesh");
4745     n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4746     n->translate(400, 0, 0);
4747     n->scale(-1, 1, -1);
4748     n->attachObject(e);
4749 
4750     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
4751 
4752     mCameraNode->setPosition(0,0,300);
4753     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
4754 
4755 }
4756 //----------------------------------------------------------------------------
4757 //----------------------------------------------------------------------------
4758 
PlayPen_NormalMapMirroredUVs()4759 PlayPen_NormalMapMirroredUVs::PlayPen_NormalMapMirroredUVs()
4760 {
4761     mInfo["Title"] = "PlayPen_NormalMapMirroredUVs";
4762     mInfo["Description"] = "Tests mirrored UVs with normal mapping shader.";
4763     addScreenshotFrame(10);
4764 }
4765 //----------------------------------------------------------------------------
4766 
setupContent()4767 void PlayPen_NormalMapMirroredUVs::setupContent()
4768 {
4769     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
4770 
4771     // this mesh has been generated with 4-component tangents, including a parity in w
4772     Entity* e = mSceneMgr->createEntity("2", "testmirroreduvmesh.mesh");
4773     e->setMaterialName("Examples/BumpMapping/MultiLightTangentParity");
4774     // here's what it looks like without the parity
4775     // e->setMaterialName("Examples/BumpMapping/MultiLight");
4776 
4777     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
4778 
4779     Light* l = mSceneMgr->createLight("3");
4780     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(1000,500,1000))->attachObject(l);
4781 
4782     mCameraNode->setPosition(0,200,50);
4783     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
4784 
4785     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
4786 }
4787 //----------------------------------------------------------------------------
4788 //----------------------------------------------------------------------------
4789 
PlayPen_Ortho()4790 PlayPen_Ortho::PlayPen_Ortho()
4791 {
4792     mInfo["Title"] = "PlayPen_Ortho";
4793     mInfo["Description"] = "Tests orthographic rendering.";
4794     addScreenshotFrame(10);
4795 }
4796 //----------------------------------------------------------------------------
4797 
setupContent()4798 void PlayPen_Ortho::setupContent()
4799 {
4800     SceneNode* mTestNode[3];
4801 
4802     // Set ambient light
4803     mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
4804 
4805     // Create a point light
4806     Light* l = mSceneMgr->createLight("MainLight");
4807     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(800,600,0))->attachObject(l);
4808 
4809     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4810     mSceneMgr->getRootSceneNode()->createChildSceneNode();
4811 
4812     Entity* pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
4813     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
4814     mTestNode[1]->attachObject( pEnt );
4815 
4816     pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
4817     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
4818     mTestNode[2]->attachObject( pEnt );
4819 
4820 
4821     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
4822 
4823 
4824     Plane plane;
4825     plane.normal = Vector3::UNIT_Y;
4826     plane.d = 100;
4827     MeshManager::getSingleton().createPlane("Myplane",
4828                                             TRANSIENT_RESOURCE_GROUP, plane,
4829                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
4830     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
4831     pPlaneEnt->setMaterialName("2 - Default");
4832     pPlaneEnt->setCastShadows(false);
4833     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
4834 
4835     mCameraNode->setFixedYawAxis(false);
4836     mCamera->setProjectionType(PT_ORTHOGRAPHIC);
4837     mCameraNode->setPosition(0,10000,0);
4838     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
4839     mCamera->setNearClipDistance(1000);
4840 
4841 }
4842 //----------------------------------------------------------------------------
4843 //----------------------------------------------------------------------------
4844 
PlayPen_PointSprites()4845 PlayPen_PointSprites::PlayPen_PointSprites()
4846 {
4847     mInfo["Title"] = "PlayPen_PointSprites";
4848     mInfo["Description"] = "Tests point sprites.";
4849     addScreenshotFrame(10);
4850 }
4851 //----------------------------------------------------------------------------
4852 
setupContent()4853 void PlayPen_PointSprites::setupContent()
4854 {
4855     MaterialPtr mat = MaterialManager::getSingleton().create("spriteTest1",
4856                                                              TRANSIENT_RESOURCE_GROUP);
4857     Pass* p = mat->getTechnique(0)->getPass(0);
4858     p->setPointSpritesEnabled(true);
4859     p->createTextureUnitState("flare.png");
4860     p->setLightingEnabled(false);
4861     p->setDepthWriteEnabled(false);
4862     p->setSceneBlending(SBT_ADD);
4863     p->setPointAttenuation(true);
4864     p->setPointSize(3);
4865     p->setVertexColourTracking(TVC_DIFFUSE);
4866 
4867     ManualObject* man = mSceneMgr->createManualObject("man");
4868     man->begin("spriteTest1", RenderOperation::OT_POINT_LIST);
4869 
4870     for (size_t i = 0; i < 1000; ++i)
4871     {
4872         man->position(Math::SymmetricRandom() * 500,
4873                       Math::SymmetricRandom() * 500,
4874                       Math::SymmetricRandom() * 500);
4875         man->colour(Math::RangeRandom(0.5f, 1.0f),
4876                     Math::RangeRandom(0.5f, 1.0f), Math::RangeRandom(0.5f, 1.0f));
4877     }
4878 
4879     // for (size_t i = 0; i < 20; ++i)
4880     // {
4881     //     for (size_t j = 0; j < 20; ++j)
4882     //     {
4883     //         for (size_t k = 0; k < 20; ++k)
4884     //         {
4885     //             if (rand()%10 == 0)
4886     //                 man->position(i * 30, j * 30, k * 30);
4887     //         }
4888     //     }
4889     // }
4890 
4891     man->end();
4892     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
4893 
4894     mCameraNode->setPosition(0,0,1000);
4895 }
4896 //----------------------------------------------------------------------------
4897 //----------------------------------------------------------------------------
4898 
PlayPen_Projection()4899 PlayPen_Projection::PlayPen_Projection()
4900 {
4901     mInfo["Title"] = "PlayPen_Projection";
4902     mInfo["Description"] = "Tests projection.";
4903     addScreenshotFrame(10);
4904 }
4905 //----------------------------------------------------------------------------
4906 
setupContent()4907 void PlayPen_Projection::setupContent()
4908 {
4909     SceneNode* mTestNode[3];
4910 
4911     // Set ambient light
4912     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
4913 
4914     // Create a point light
4915     Light* l = mSceneMgr->createLight("MainLight");
4916     l->setType(Light::LT_DIRECTIONAL);
4917     l->setDirection(-Vector3::UNIT_Y);
4918 
4919     Entity* pEnt;
4920     //pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
4921     //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
4922     //pEnt->setMaterialName("Examples/OgreLogo");
4923 
4924     // Define a floor plane mesh
4925     Plane p;
4926     p.normal = Vector3::UNIT_Z;
4927     p.d = 200;
4928     MeshManager::getSingleton().createPlane("WallPlane",
4929                                             TRANSIENT_RESOURCE_GROUP,
4930                                             p,1500,1500,1,1,true,1,5,5,Vector3::UNIT_Y);
4931     pEnt = mSceneMgr->createEntity( "5", "WallPlane" );
4932     pEnt->setMaterialName("Examples/OgreLogo");
4933     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
4934 
4935 
4936     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
4937 
4938     //pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
4939     //mTestNode[0]->attachObject( pEnt );
4940     mTestNode[0]->translate(0, 0, 750);
4941 
4942     Ogre::Frustum* frustum = new Frustum();
4943     frustum->setVisible(true);
4944     frustum->setFarClipDistance(5000);
4945     frustum->setNearClipDistance(200);
4946     frustum->setAspectRatio(1);
4947     frustum->setProjectionType(PT_ORTHOGRAPHIC);
4948     mTestNode[0]->attachObject(frustum);
4949 
4950     // Hook the frustum up to the material
4951     MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/OgreLogo");
4952     TextureUnitState *t = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
4953     t->setProjectiveTexturing(true, frustum);
4954     //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
4955 
4956 }
4957 //----------------------------------------------------------------------------
4958 //----------------------------------------------------------------------------
4959 
PlayPen_ReflectedBillboards()4960 PlayPen_ReflectedBillboards::PlayPen_ReflectedBillboards()
4961 {
4962     mInfo["Title"] = "PlayPen_ReflectedBillboards";
4963     mInfo["Description"] = "Tests reflected billboards.";
4964     addScreenshotFrame(175); // needs to run for a bit so there are particles to be reflected...
4965 }
4966 //----------------------------------------------------------------------------
4967 
setupContent()4968 void PlayPen_ReflectedBillboards::setupContent()
4969 {
4970     Camera* reflectCam = 0;
4971     // Set ambient light
4972     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
4973 
4974     // Create a light
4975     Light* l = mSceneMgr->createLight("MainLight");
4976     l->setType(Light::LT_DIRECTIONAL);
4977     Vector3 dir(0.5, -1, 0);
4978     dir.normalise();
4979     l->setDirection(dir);
4980     l->setDiffuseColour(1.0f, 1.0f, 0.8f);
4981     l->setSpecularColour(1.0f, 1.0f, 1.0f);
4982 
4983 
4984     // Create a prefab plane
4985     Plane plane;
4986     plane.d = 0;
4987     plane.normal = Vector3::UNIT_Y;
4988     MeshManager::getSingleton().createPlane("ReflectionPlane",
4989                                             TRANSIENT_RESOURCE_GROUP,
4990                                             plane, 2000, 2000,
4991                                             1, 1, true, 1, 1, 1, Vector3::UNIT_Z);
4992     Entity* planeEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" );
4993 
4994     // Attach the rtt entity to the root of the scene
4995     SceneNode* rootNode = mSceneMgr->getRootSceneNode();
4996     SceneNode* planeNode = rootNode->createChildSceneNode();
4997 
4998     // Attach both the plane entity, and the plane definition
4999     planeNode->attachObject(planeEnt);
5000 
5001     mCameraNode->setPosition(-50, 100, 500);
5002     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
5003 
5004     TexturePtr rttTex = TextureManager::getSingleton().createManual("RttTex",
5005                                                                     TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
5006                                                                     512, 512, 1, 0, PF_R8G8B8, TU_RENDERTARGET);
5007     {
5008         reflectCam = mSceneMgr->createCamera("ReflectCam");
5009         reflectCam->setNearClipDistance(mCamera->getNearClipDistance());
5010         reflectCam->setFarClipDistance(mCamera->getFarClipDistance());
5011         reflectCam->setAspectRatio(
5012             (Real)mWindow->getViewport(0)->getActualWidth() /
5013             (Real)mWindow->getViewport(0)->getActualHeight());
5014 
5015         SceneNode* reflectCamNode = rootNode->createChildSceneNode();
5016         reflectCamNode->attachObject(reflectCam);
5017         reflectCamNode->setPosition(mCameraNode->getPosition());
5018         reflectCamNode->setOrientation(mCameraNode->getOrientation());
5019 
5020         Viewport *v = rttTex->getBuffer()->getRenderTarget()->addViewport( reflectCam );
5021         v->setClearEveryFrame( true );
5022         v->setBackgroundColour( ColourValue::Black );
5023 
5024         MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",
5025                                                                  TRANSIENT_RESOURCE_GROUP);
5026         mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg");
5027         TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
5028         // Blend with base texture
5029         t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White,
5030                                 ColourValue::White, 0.25);
5031         t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
5032         t->setProjectiveTexturing(true, reflectCam);
5033 
5034         // set up linked reflection
5035         reflectCam->enableReflection(plane);
5036         // Also clip
5037         reflectCam->enableCustomNearClipPlane(plane);
5038     }
5039 
5040     // Give the plane a texture
5041     planeEnt->setMaterialName("RttMat");
5042 
5043 
5044     // point billboards
5045     ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("fountain1",
5046                                                             "Examples/Smoke");
5047     // Point the fountain at an angle
5048     SceneNode* fNode = static_cast<SceneNode*>(rootNode->createChild());
5049     fNode->attachObject(pSys2);
5050 
5051     // oriented_self billboards
5052     ParticleSystem* pSys3 = mSceneMgr->createParticleSystem("fountain2",
5053                                                             "Examples/PurpleFountain");
5054     // Point the fountain at an angle
5055     fNode = rootNode->createChildSceneNode();
5056     fNode->translate(-200,-100,0);
5057     fNode->rotate(Vector3::UNIT_Z, Degree(-20));
5058     fNode->attachObject(pSys3);
5059 
5060 
5061 
5062     // oriented_common billboards
5063     ParticleSystem* pSys4 = mSceneMgr->createParticleSystem("rain",
5064                                                             "Examples/Rain");
5065     SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5066     rNode->translate(0,1000,0);
5067     rNode->attachObject(pSys4);
5068     // Fast-forward the rain so it looks more natural
5069     pSys4->fastForward(5);
5070 
5071 
5072 }
5073 //----------------------------------------------------------------------------
5074 //----------------------------------------------------------------------------
5075 
PlayPen_ReinitialiseEntityAlteredMesh()5076 PlayPen_ReinitialiseEntityAlteredMesh::PlayPen_ReinitialiseEntityAlteredMesh()
5077 {
5078     mInfo["Title"] = "PlayPen_ReinitialiseEntityAlteredMesh";
5079     mInfo["Description"] = "Tests updating an entity while rendering.";
5080     addScreenshotFrame(100);
5081     mTimer = 0.5f;
5082 }
5083 //----------------------------------------------------------------------------
5084 
frameStarted(const FrameEvent & evt)5085 bool PlayPen_ReinitialiseEntityAlteredMesh::frameStarted(const FrameEvent& evt)
5086 {
5087     if(mTimer > 0.f)
5088     {
5089         mTimer -= evt.timeSinceLastFrame;
5090         if(mTimer <= 0.f)
5091         {
5092             // Change the mesh, add a new submesh.
5093 
5094             // Load another mesh.
5095             MeshPtr msh = MeshManager::getSingleton().load(
5096                 "ogrehead.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
5097             for (unsigned short e = 0; e < msh->getNumSubMeshes(); ++e)
5098             {
5099                 SubMesh* sm = msh->getSubMesh(e);
5100                 sm->clone("", mUpdate);
5101             }
5102             mTimer = -5.f;
5103         }
5104     }
5105 
5106     return true;
5107 }
5108 //----------------------------------------------------------------------------
5109 
setupContent()5110 void PlayPen_ReinitialiseEntityAlteredMesh::setupContent()
5111 {
5112     // test whether an Entity picks up that Mesh has changed
5113     // and therefore rebuild SubEntities
5114 
5115     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
5116 
5117     Light* l = mSceneMgr->createLight("l1");
5118     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(200, 300, 0))->attachObject(l);
5119 
5120     Ogre::MeshManager::getSingleton().load("knot.mesh",
5121                                            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)->clone("knot_REINIT.mesh");
5122 
5123     Entity* pEnt = mSceneMgr->createEntity("testEnt", "knot_REINIT.mesh");
5124     mUpdate = pEnt->getMesh().get();
5125 
5126     mSceneMgr->getRootSceneNode()->attachObject(pEnt);
5127 
5128     mCameraNode->setPosition(0,0,200);
5129 }
5130 //----------------------------------------------------------------------------
5131 //----------------------------------------------------------------------------
5132 
PlayPen_ReloadResources()5133 PlayPen_ReloadResources::PlayPen_ReloadResources()
5134 {
5135     mInfo["Title"] = "PlayPen_ReloadResources";
5136     mInfo["Description"] = "Tests unloading and reloading resources.";
5137     addScreenshotFrame(100);
5138     mReloadTimer = 0.5f;
5139 }
5140 //----------------------------------------------------------------------------
5141 
frameStarted(const FrameEvent & evt)5142 bool PlayPen_ReloadResources::frameStarted(const FrameEvent& evt)
5143 {
5144     if(mReloadTimer > 0.f)
5145     {
5146         mReloadTimer -= evt.timeSinceLastFrame;
5147 
5148         if(mReloadTimer <= 0.f)
5149         {
5150             // unload
5151             Entity* e = mSceneMgr->getEntity("1");
5152             e->getParentSceneNode()->detachObject("1");
5153             mSceneMgr->destroyAllEntities();
5154             ResourceGroupManager::getSingleton().unloadResourceGroup("TestReload");
5155 
5156             // reload
5157             e = mSceneMgr->createEntity("1", "UniqueModel.MESH");
5158             mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
5159 
5160             mReloadTimer = -5.f;
5161         }
5162     }
5163     return true;
5164 }
5165 //----------------------------------------------------------------------------
5166 
setupContent()5167 void PlayPen_ReloadResources::setupContent()
5168 {
5169     mSceneMgr->setAmbientLight(ColourValue::White);
5170 
5171     // get path to test resources
5172     const Ogre::ResourceGroupManager::LocationList& ll = Ogre::ResourceGroupManager::getSingleton().getResourceLocationList("Tests");
5173     const Ogre::ResourceGroupManager::ResourceLocation* loc = &ll.front();
5174     Ogre::String testResourcePath = loc->archive->getName();
5175 
5176     // add a new group
5177     // Ogre::String meshFilePath = testResourcePath + "/TestReload";
5178     Ogre::String meshFilePath = testResourcePath + "/Model2";
5179     Ogre::ResourceGroupManager& resMgr = Ogre::ResourceGroupManager::getSingleton();
5180     String newGroup = meshFilePath;
5181     resMgr.createResourceGroup("TestReload", false);
5182     resMgr.addResourceLocation(meshFilePath, "FileSystem", "TestReload");
5183     resMgr.initialiseResourceGroup("TestReload");
5184 
5185     MeshManager& mmgr = MeshManager::getSingleton();
5186     mmgr.load("UniqueModel.MESH", "TestReload");
5187 
5188     Entity* e = mSceneMgr->createEntity("1", "UniqueModel.MESH");
5189     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
5190 
5191     mCameraNode->setPosition(0,0,200);
5192 }
5193 //----------------------------------------------------------------------------
5194 //----------------------------------------------------------------------------
5195 
PlayPen_RibbonTrail()5196 PlayPen_RibbonTrail::PlayPen_RibbonTrail()
5197 {
5198     mInfo["Title"] = "PlayPen_RibbonTrail";
5199     mInfo["Description"] = "Tests ribbon trail effect.";
5200     addScreenshotFrame(150);
5201 }
5202 //----------------------------------------------------------------------------
5203 
setupContent()5204 void PlayPen_RibbonTrail::setupContent()
5205 {
5206     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
5207     Vector3 dir(-1, -1, 0.5);
5208     dir.normalise();
5209     Light* l = mSceneMgr->createLight("light1");
5210     l->setType(Light::LT_DIRECTIONAL);
5211     l->setDirection(dir);
5212 
5213     NameValuePairList pairList;
5214     pairList["numberOfChains"] = "2";
5215     pairList["maxElements"] = "80";
5216     RibbonTrail* trail = static_cast<RibbonTrail*>(
5217         mSceneMgr->createMovableObject("1", "RibbonTrail", &pairList));
5218     trail->setMaterialName("Examples/LightRibbonTrail");
5219     trail->setTrailLength(400);
5220     //mRibbonTrail = trail;
5221 
5222 
5223     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(trail);
5224 
5225     // Create 3 nodes for trail to follow
5226     SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5227     animNode->setPosition(0,20,0);
5228     Animation* anim = mSceneMgr->createAnimation("an1", 10);
5229     anim->setInterpolationMode(Animation::IM_SPLINE);
5230     NodeAnimationTrack* track = anim->createNodeTrack(1, animNode);
5231     TransformKeyFrame* kf = track->createNodeKeyFrame(0);
5232     kf->setTranslate(Vector3::ZERO);
5233     kf = track->createNodeKeyFrame(2);
5234     kf->setTranslate(Vector3(100, 0, 0));
5235     kf = track->createNodeKeyFrame(4);
5236     kf->setTranslate(Vector3(200, 0, 300));
5237     kf = track->createNodeKeyFrame(6);
5238     kf->setTranslate(Vector3(0, 20, 500));
5239     kf = track->createNodeKeyFrame(8);
5240     kf->setTranslate(Vector3(-100, 10, 100));
5241     kf = track->createNodeKeyFrame(10);
5242     kf->setTranslate(Vector3::ZERO);
5243 
5244     //testremoveNode = animNode;
5245 
5246     AnimationState* animState = mSceneMgr->createAnimationState("an1");
5247     animState->setEnabled(true);
5248     mAnimStateList.push_back(animState);
5249 
5250     trail->addNode(animNode);
5251     trail->setInitialColour(0, 1.0, 0.8, 0);
5252     trail->setColourChange(0, 0.5, 0.5, 0.5, 0.5);
5253     trail->setInitialWidth(0, 5);
5254 
5255     // Add light
5256     Light* l2 = mSceneMgr->createLight("l2");
5257     l2->setDiffuseColour(trail->getInitialColour(0));
5258     animNode->attachObject(l2);
5259 
5260     // Add billboard
5261     BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
5262     bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0));
5263     bbs->setMaterialName("Examples/Flare");
5264     animNode->attachObject(bbs);
5265 
5266     animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5267     animNode->setPosition(-50,10,0);
5268     anim = mSceneMgr->createAnimation("an2", 10);
5269     anim->setInterpolationMode(Animation::IM_SPLINE);
5270     track = anim->createNodeTrack(1, animNode);
5271     kf = track->createNodeKeyFrame(0);
5272     kf->setTranslate(Vector3::ZERO);
5273     kf = track->createNodeKeyFrame(2);
5274     kf->setTranslate(Vector3(-100, 150, -30));
5275     kf = track->createNodeKeyFrame(4);
5276     kf->setTranslate(Vector3(-200, 0, 40));
5277     kf = track->createNodeKeyFrame(6);
5278     kf->setTranslate(Vector3(0, -150, 70));
5279     kf = track->createNodeKeyFrame(8);
5280     kf->setTranslate(Vector3(50, 0, 30));
5281     kf = track->createNodeKeyFrame(10);
5282     kf->setTranslate(Vector3::ZERO);
5283 
5284     animState = mSceneMgr->createAnimationState("an2");
5285     animState->setEnabled(true);
5286     mAnimStateList.push_back(animState);
5287 
5288     trail->addNode(animNode);
5289     trail->setInitialColour(1, 0.0, 1.0, 0.4);
5290     trail->setColourChange(1, 0.5, 0.5, 0.5, 0.5);
5291     trail->setInitialWidth(1, 5);
5292 
5293 
5294     // Add light
5295     l2 = mSceneMgr->createLight("l3");
5296     l2->setDiffuseColour(trail->getInitialColour(1));
5297     animNode->attachObject(l2);
5298 
5299     // Add billboard
5300     bbs = mSceneMgr->createBillboardSet("bb2", 1);
5301     bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1));
5302     bbs->setMaterialName("Examples/Flare");
5303     animNode->attachObject(bbs);
5304 
5305 
5306     mCameraNode->setPosition(0,0,500);
5307     //mSceneMgr->showBoundingBoxes(true);
5308 
5309 }
5310 //----------------------------------------------------------------------------
5311 //----------------------------------------------------------------------------
5312 
PlayPen_SerialisedColour()5313 PlayPen_SerialisedColour::PlayPen_SerialisedColour()
5314 {
5315     mInfo["Title"] = "PlayPen_SerialisedColour";
5316     mInfo["Description"] = "Tests serializing mesh color.";
5317     addScreenshotFrame(10);
5318 }
5319 //----------------------------------------------------------------------------
5320 
setupContent()5321 void PlayPen_SerialisedColour::setupContent()
5322 {
5323     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
5324     Vector3 dir(-1, -1, 0.5);
5325     dir.normalise();
5326     Light* l = mSceneMgr->createLight("light1");
5327     l->setType(Light::LT_DIRECTIONAL);
5328     l->setDirection(dir);
5329 
5330     Plane plane;
5331     plane.normal = Vector3::UNIT_Y;
5332     plane.d = 100;
5333     MeshManager::getSingleton().createPlane(
5334         "Myplane", TRANSIENT_RESOURCE_GROUP, plane,
5335         1500, 1500, 10, 10, true, 1, 5, 5, Vector3::UNIT_Z);
5336     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
5337     pPlaneEnt->setMaterialName("2 - Default");
5338     pPlaneEnt->setCastShadows(false);
5339     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
5340 
5341     ManualObject* man = static_cast<ManualObject*>(
5342         mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
5343 
5344     MaterialPtr mat = MaterialManager::getSingleton().create(
5345         "AmbientVertexColourTracking", TRANSIENT_RESOURCE_GROUP);
5346     Pass* p = mat->getTechnique(0)->getPass(0);
5347     p->setVertexColourTracking(TVC_AMBIENT);
5348     p->setLightingEnabled(false);
5349 
5350     man->begin("AmbientVertexColourTracking");
5351     //TODO Define a 40x40 plane, non-indexed
5352 
5353     // Define a 40x40 plane, indexed
5354     man->position(-20, 20, 20);
5355     man->colour(1, 0, 0);
5356 
5357     man->position(-20, -20, 20);
5358     man->colour(1, 0, 0);
5359 
5360     man->position(20, -20, 20);
5361     man->colour(1, 0, 0);
5362 
5363     man->position(20, 20, 20);
5364     man->colour(1, 0, 0);
5365 
5366     man->quad(0, 1, 2, 3);
5367     man->end();
5368 
5369     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
5370 
5371     MeshPtr mesh = man->convertToMesh("colourtest.mesh");
5372     MeshSerializer ms;
5373     ms.exportMesh(mesh.get(), "colourtest.mesh");
5374 
5375     Entity* c = mSceneMgr->createEntity("1", "colourtest.mesh");
5376     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(c);
5377 
5378     mCameraNode->setPosition(0,0,120);
5379 
5380 }
5381 //----------------------------------------------------------------------------
5382 //----------------------------------------------------------------------------
5383 
PlayPen_ShadowLod()5384 PlayPen_ShadowLod::PlayPen_ShadowLod()
5385 {
5386     mInfo["Title"] = "PlayPen_ShadowLod";
5387     mInfo["Description"] = "Tests whether LOD is based on shadow cam or main cam.";
5388     addScreenshotFrame(10);
5389 }
5390 //----------------------------------------------------------------------------
5391 
cleanupContent()5392 void PlayPen_ShadowLod::cleanupContent()
5393 {
5394     clearDebugTextureOverlays();
5395 }
5396 //----------------------------------------------------------------------------
5397 
setupContent()5398 void PlayPen_ShadowLod::setupContent()
5399 {
5400     SceneNode* mTestNode[10];
5401 
5402     // Test that LOD is based on main camera, not shadow camera
5403 
5404     mSceneMgr->setShadowTextureSize(1024);
5405     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
5406 
5407     //FocusedShadowCameraSetup* lispsmSetup = new FocusedShadowCameraSetup();
5408     //LiSPSMShadowCameraSetup* lispsmSetup = new LiSPSMShadowCameraSetup();
5409     //lispsmSetup->setOptimalAdjustFactor(1.5);
5410     //mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(lispsmSetup));
5411 
5412     mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
5413     // Set ambient light
5414     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
5415 
5416     Light* mLight = mSceneMgr->createLight("MainLight");
5417 
5418     // Directional test
5419     if (false)
5420     {
5421         mLight->setType(Light::LT_DIRECTIONAL);
5422         Vector3 vec(-1,-1,0);
5423         vec.normalise();
5424         mLight->setDirection(vec);
5425     }
5426     // Spotlight test
5427     else
5428     {
5429         mLight->setType(Light::LT_SPOTLIGHT);
5430         mLight->setAttenuation(10000, 1, 0, 0);
5431         mLight->setDiffuseColour(1.0, 1.0, 0.8);
5432         mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5433         mTestNode[0]->setPosition(400,300,0);
5434         mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD);
5435         mTestNode[0]->attachObject(mLight);
5436     }
5437 
5438     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5439 
5440 
5441     Entity* pEnt;
5442     pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
5443     // rendering distance should also be based on main cam
5444     //pEnt->setRenderingDistance(100);
5445     //pEnt->setMaterialName("2 - Default");
5446     mTestNode[1]->attachObject( pEnt );
5447     //mTestNode[1]->translate(0,-100,0);
5448     /*
5449       pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
5450       mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
5451       mTestNode[2]->attachObject( pEnt );
5452 
5453 
5454       createRandomEntityClones(pEnt, 20, Vector3(-1000,0,-1000), Vector3(1000,0,1000));
5455 
5456 
5457       // Transparent object (can force cast shadows)
5458       pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
5459       MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency",
5460       TRANSIENT_RESOURCE_GROUP);
5461       tmat->setTransparencyCastsShadows(true);
5462       Pass* tpass = tmat->getTechnique(0)->getPass(0);
5463       tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
5464       tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
5465       tpass->createTextureUnitState("gras_02.png");
5466       tpass->setCullingMode(CULL_NONE);
5467 
5468       pEnt->setMaterialName("TestAlphaTransparency");
5469       mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
5470       mTestNode[3]->attachObject( pEnt );
5471 
5472       MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
5473       TRANSIENT_RESOURCE_GROUP);
5474       msh->buildTangentVectors(VES_TANGENT, 0, 0);
5475       pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
5476       //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
5477       mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
5478       mTestNode[2]->attachObject( pEnt );
5479 
5480       mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
5481     */
5482 
5483 
5484     MovablePlane movablePlane(Vector3::UNIT_Y, 100);
5485     MeshManager::getSingleton().createPlane("Myplane",
5486                                             TRANSIENT_RESOURCE_GROUP, movablePlane,
5487                                             2500,2500,10,10,true,1,5,5,Vector3::UNIT_Z);
5488     Entity* pPlaneEnt;
5489     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
5490     if (SHADOWTYPE_TEXTURE_MODULATIVE & SHADOWDETAILTYPE_INTEGRATED)
5491     {
5492         pPlaneEnt->setMaterialName("Examples/Plane/IntegratedShadows");
5493     }
5494     else
5495     {
5496         pPlaneEnt->setMaterialName("2 - Default");
5497     }
5498     pPlaneEnt->setCastShadows(false);
5499     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
5500 
5501     addTextureShadowDebugOverlay(1, mSceneMgr);
5502 
5503 
5504     /*
5505       ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
5506       "Examples/Smoke");
5507       mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
5508       mTestNode[4]->attachObject(pSys2);
5509     */
5510 
5511     mCameraNode->setPosition(0, 1000, 500);
5512     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
5513     mCamera->setFarClipDistance(10000);
5514 
5515 }
5516 //----------------------------------------------------------------------------
5517 //----------------------------------------------------------------------------
5518 
PlayPen_SkeletalAnimation()5519 PlayPen_SkeletalAnimation::PlayPen_SkeletalAnimation()
5520 {
5521     mInfo["Title"] = "PlayPen_SkeletalAnimation";
5522     mInfo["Description"] = "Tests skeletal animation.";
5523     addScreenshotFrame(100);
5524 }
5525 //----------------------------------------------------------------------------
5526 
setupContent()5527 void PlayPen_SkeletalAnimation::setupContent()
5528 {
5529     // Set ambient light
5530     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
5531     //mWindow->getViewport(0)->setBackgroundColour(ColourValue::White);
5532 
5533 
5534 
5535     Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
5536     //ent->setDisplaySkeleton(true);
5537     // Uncomment the below to test software skinning
5538     ent->setMaterialName("Examples/Rocky");
5539     // Add entity to the scene node
5540     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
5541     Ogre::AnimationState* mAnimState = ent->getAnimationState("Walk");
5542     mAnimState->setEnabled(true);
5543 
5544     // Give it a little ambience with lights
5545     Light* l;
5546     l = mSceneMgr->createLight("BlueLight");
5547     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200,-80,-100))->attachObject(l);
5548     l->setDiffuseColour(0.5, 0.5, 1.0);
5549 
5550     l = mSceneMgr->createLight("GreenLight");
5551     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,-100))->attachObject(l);
5552     l->setDiffuseColour(0.5, 1.0, 0.5);
5553 
5554     // Position the camera
5555     mCameraNode->setPosition(200,50,0);
5556     mCameraNode->lookAt(Vector3(0, 50, 0), Node::TS_PARENT);
5557 
5558     // Report whether hardware skinning is enabled or not
5559     /*Technique* t = ent->getSubEntity(0)->getTechnique();
5560       Pass* p = t->getPass(0);
5561       OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
5562       if (p->hasVertexProgram() &&
5563       p->getVertexProgram()->isSkeletalAnimationIncluded())
5564       {
5565       guiDbg->setCaption("Hardware skinning is enabled");
5566       }
5567       else
5568       {
5569       guiDbg->setCaption("Software skinning is enabled");
5570       }*/
5571 
5572     mAnimStateList.push_back(mAnimState);
5573 }
5574 //----------------------------------------------------------------------------
5575 //----------------------------------------------------------------------------
5576 
PlayPen_SkeletonAnimationOptimise()5577 PlayPen_SkeletonAnimationOptimise::PlayPen_SkeletonAnimationOptimise()
5578 {
5579     mInfo["Title"] = "PlayPen_SkeletonAnimationOptimise";
5580     mInfo["Description"] = "Tests skeletal animation with hardware and software.";
5581     addScreenshotFrame(100);
5582 }
5583 //----------------------------------------------------------------------------
5584 
setupContent()5585 void PlayPen_SkeletonAnimationOptimise::setupContent()
5586 {
5587     SceneNode* mTestNode[5];
5588     mSceneMgr->setShadowTextureSize(512);
5589     mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
5590     mSceneMgr->setShadowFarDistance(1500);
5591     mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
5592     //mSceneMgr->setShadowFarDistance(800);
5593     // Set ambient light
5594     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
5595 
5596     Light* mLight = mSceneMgr->createLight("MainLight");
5597 
5598     /*/
5599     // Directional test
5600     mLight->setType(Light::LT_DIRECTIONAL);
5601     Vector3 vec(-1,-1,0);
5602     vec.normalise();
5603     mLight->setDirection(vec);
5604     /*/
5605     // Point test
5606     mLight->setType(Light::LT_POINT);
5607     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 200, 0))->attachObject(mLight);
5608     //*/
5609 
5610     Entity* pEnt;
5611 
5612     // Hardware animation
5613     pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
5614     AnimationState* a = pEnt->getAnimationState("Walk");
5615     a->setEnabled(true);
5616     mAnimStateList.push_back(a);
5617     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5618     mTestNode[0]->attachObject( pEnt );
5619     mTestNode[0]->translate(+100,-100,0);
5620 
5621     // Software animation
5622     pEnt = mSceneMgr->createEntity( "2", "robot.mesh" );
5623     pEnt->setMaterialName("BaseWhite");
5624     a = pEnt->getAnimationState("Walk");
5625     a->setEnabled(true);
5626     mAnimStateList.push_back(a);
5627 
5628     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5629     mTestNode[1]->attachObject( pEnt );
5630     mTestNode[1]->translate(-100,-100,0);
5631 
5632 
5633     Plane plane(Vector3::UNIT_Y, -100);
5634     MeshManager::getSingleton().createPlane("Myplane",
5635                                             TRANSIENT_RESOURCE_GROUP, plane,
5636                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
5637     Entity* pPlaneEnt;
5638     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
5639     pPlaneEnt->setMaterialName("2 - Default");
5640     pPlaneEnt->setCastShadows(false);
5641     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
5642 
5643     mCameraNode->setPosition(0,0,300);
5644 }
5645 //----------------------------------------------------------------------------
5646 //----------------------------------------------------------------------------
5647 
PlayPen_SpotlightViewProj()5648 PlayPen_SpotlightViewProj::PlayPen_SpotlightViewProj()
5649 {
5650     mInfo["Title"] = "PlayPen_SpotlightViewProj";
5651     mInfo["Description"] = "Tests spotlight camera projection.";
5652     addScreenshotFrame(10);
5653 }
5654 //----------------------------------------------------------------------------
5655 
setupContent()5656 void PlayPen_SpotlightViewProj::setupContent()
5657 {
5658     SceneNode* mTestNode[10];
5659     bool worldViewProj = true;
5660     // Define programs that use spotlight projection
5661 
5662     String vpStr;
5663     vpStr =
5664         "void vp(float4 position : POSITION,\n"
5665         "out float4 oPosition : POSITION,\n"
5666         "out float4 oUV : TEXCOORD0,\n";
5667     if (!worldViewProj)
5668     {
5669         vpStr += "uniform float4x4 world,\n"
5670             "uniform float4x4 spotlightViewProj,\n";
5671     }
5672     else
5673     {
5674         vpStr += "uniform float4x4 spotlightWorldViewProj,\n";
5675     }
5676     vpStr += "uniform float4x4 worldViewProj)\n"
5677         "{\n"
5678         "    oPosition = mul(worldViewProj, position);\n";
5679     if (worldViewProj)
5680     {
5681         vpStr += "    oUV = mul(spotlightWorldViewProj, position);\n";
5682     }
5683     else
5684     {
5685         vpStr += "    float4 worldPos = mul(world, position);\n"
5686             "    oUV = mul(spotlightViewProj, worldPos);\n";
5687     }
5688     vpStr += "}\n";
5689 
5690     String fpStr =
5691         "void fp(\n"
5692         "float4 uv : TEXCOORD0,\n"
5693         "uniform sampler2D tex : register(s0),\n"
5694         "out float4 oColor : COLOR)\n"
5695         "{\n"
5696         "   uv = uv / uv.w;\n"
5697         "    oColor = tex2D(tex, uv.xy);\n"
5698         "}\n";
5699 
5700     HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton()
5701         .createProgram("testvp",
5702                        TRANSIENT_RESOURCE_GROUP,
5703                        "cg", GPT_VERTEX_PROGRAM);
5704     vp->setSource(vpStr);
5705     vp->setParameter("profiles", "vs_1_1 arbvp1 glslv");
5706     vp->setParameter("entry_point", "vp");
5707     vp->load();
5708 
5709     HighLevelGpuProgramPtr fp = HighLevelGpuProgramManager::getSingleton()
5710         .createProgram("testfp",
5711                        TRANSIENT_RESOURCE_GROUP,
5712                        "cg", GPT_FRAGMENT_PROGRAM);
5713     fp->setSource(fpStr);
5714     fp->setParameter("profiles", "ps_2_0 arbfp1 glslf");
5715     fp->setParameter("entry_point", "fp");
5716     fp->load();
5717 
5718     MaterialPtr mat = MaterialManager::getSingleton().create("TestSpotlightProj",
5719                                                              TRANSIENT_RESOURCE_GROUP);
5720     Pass* p = mat->getTechnique(0)->getPass(0);
5721     p->setVertexProgram("testvp");
5722     p->getVertexProgramParameters()->setNamedAutoConstant(
5723         "worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
5724 
5725     if (worldViewProj)
5726     {
5727         p->getVertexProgramParameters()->setNamedAutoConstant(
5728             "spotlightWorldViewProj", GpuProgramParameters::ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX);
5729     }
5730     else
5731     {
5732         p->getVertexProgramParameters()->setNamedAutoConstant(
5733             "world", GpuProgramParameters::ACT_WORLD_MATRIX);
5734         p->getVertexProgramParameters()->setNamedAutoConstant(
5735             "spotlightViewProj", GpuProgramParameters::ACT_SPOTLIGHT_VIEWPROJ_MATRIX);
5736     }
5737     p->setFragmentProgram("testfp");
5738     p->createTextureUnitState("ogrelogo.png");
5739 
5740     Entity* pEnt;
5741 
5742     // Define a plane mesh, use the above material
5743     Plane plane;
5744     plane.normal = Vector3::UNIT_Z;
5745     plane.d = 200;
5746     MeshManager::getSingleton().createPlane("WallPlane",
5747                                             TRANSIENT_RESOURCE_GROUP,
5748                                             plane,1500,1500,100,100,true,1,5,5,Vector3::UNIT_Y);
5749     pEnt = mSceneMgr->createEntity( "5", "WallPlane" );
5750     pEnt->setMaterialName(mat->getName());
5751     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
5752 
5753 
5754     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5755 
5756     mTestNode[0]->translate(0, 0, 750);
5757 
5758     Light* spot = mSceneMgr->createLight("l1");
5759     spot->setType(Light::LT_SPOTLIGHT);
5760 
5761     mTestNode[0]->attachObject(spot);
5762 
5763 
5764 }
5765 //----------------------------------------------------------------------------
5766 //----------------------------------------------------------------------------
5767 
PlayPen_SRGBtexture()5768 PlayPen_SRGBtexture::PlayPen_SRGBtexture()
5769 {
5770     mInfo["Title"] = "PlayPen_SRGBtexture";
5771     mInfo["Description"] = "Tests sRGB textures.";
5772     addScreenshotFrame(10);
5773 }
5774 //----------------------------------------------------------------------------
5775 
setupContent()5776 void PlayPen_SRGBtexture::setupContent()
5777 {
5778     // NOTE: enable flag only turns on SRGB for texture sampling, you may
5779     // need to configure the window for the reverse conversion for consistency!
5780     MaterialPtr mat = MaterialManager::getSingleton().create("testsrgb",
5781                                                              TRANSIENT_RESOURCE_GROUP);
5782     Pass* p = mat->getTechnique(0)->getPass(0);
5783     p->setLightingEnabled(false);
5784     p->setCullingMode(CULL_NONE);
5785     TextureUnitState* t = p->createTextureUnitState("ogrelogo.png");
5786     t->setHardwareGammaEnabled(true);
5787     Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE);
5788     e->setMaterialName(mat->getName());
5789     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
5790     mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red);
5791 
5792     mCameraNode->setPosition(0,0,300);
5793     mCameraNode->lookAt(Vector3::ZERO, Node::TS_PARENT);
5794 
5795 }
5796 //----------------------------------------------------------------------------
5797 //----------------------------------------------------------------------------
5798 
PlayPen_StaticGeometry()5799 PlayPen_StaticGeometry::PlayPen_StaticGeometry()
5800 {
5801     mInfo["Title"] = "PlayPen_StaticGeometry";
5802     mInfo["Description"] = "Tests static geometry.";
5803     addScreenshotFrame(10);
5804 }
5805 //----------------------------------------------------------------------------
5806 
setupContent()5807 void PlayPen_StaticGeometry::setupContent()
5808 {
5809 
5810     // Set ambient light
5811     mSceneMgr->setAmbientLight(ColourValue(0, 0, 0));
5812 
5813     // Create a point light
5814     Light* l = mSceneMgr->createLight("MainLight");
5815     l->setDiffuseColour(0.4, 0.4, 0.4);
5816     l->setSpecularColour(ColourValue::White);
5817 
5818     SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5819     Animation* anim = mSceneMgr->createAnimation("an1", 20);
5820     anim->setInterpolationMode(Animation::IM_SPLINE);
5821     NodeAnimationTrack* track = anim->createNodeTrack(1, animNode);
5822     TransformKeyFrame* kf = track->createNodeKeyFrame(0);
5823     kf->setTranslate(Vector3(2300, 600, 2300));
5824     kf = track->createNodeKeyFrame(5);
5825     kf->setTranslate(Vector3(-2300, 600, 2300));
5826     kf = track->createNodeKeyFrame(10);
5827     kf->setTranslate(Vector3(-2300, 600, -2300));
5828     kf = track->createNodeKeyFrame(15);
5829     kf->setTranslate(Vector3(2300, 600, -2300));
5830     kf = track->createNodeKeyFrame(20);
5831     kf->setTranslate(Vector3(2300, 600, 2300));
5832 
5833     //animNode->attachObject(l);
5834     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 600, 0))->attachObject(l);
5835     l->setAttenuation(10000, 1, 0, 0);
5836 
5837     AnimationState* animState = mSceneMgr->createAnimationState("an1");
5838     animState->setEnabled(true);
5839     mAnimStateList.push_back(animState);
5840 
5841 
5842 
5843     Plane plane;
5844     plane.normal = Vector3::UNIT_Y;
5845     plane.d = 0;
5846     MeshManager::getSingleton().createPlane("Myplane",
5847                                             TRANSIENT_RESOURCE_GROUP, plane,
5848                                             4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
5849     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
5850     pPlaneEnt->setMaterialName("Examples/GrassFloor");
5851     pPlaneEnt->setCastShadows(false);
5852     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
5853 
5854     Vector3 min(-2000,30,-2000);
5855     Vector3 max(2000,30,2000);
5856 
5857 
5858     MeshPtr msh = MeshManager::getSingleton().load("ogrehead.mesh", ASSETS_RESOURCE_GROUP);
5859     msh->buildTangentVectors();
5860 
5861     Entity* e = mSceneMgr->createEntity("1", "ogrehead.mesh");
5862     e->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
5863 
5864     StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
5865     s->setCastShadows(true);
5866     s->setRegionDimensions(Vector3(500,500,500));
5867     for (int i = 0; i < 10; ++i)
5868     {
5869         Vector3 pos;
5870         pos.x = Math::RangeRandom(min.x, max.x);
5871         pos.y = Math::RangeRandom(min.y, max.y);
5872         pos.z = Math::RangeRandom(min.z, max.z);
5873 
5874         s->addEntity(e, pos);
5875         Entity* e2 = e->clone("clone" + StringConverter::toString(i));
5876         mSceneMgr->getRootSceneNode()->createChildSceneNode(pos+Vector3(0,60,0))->attachObject(e2);
5877 
5878     }
5879 
5880     s->build();
5881     mCamera->setLodBias(0.5);
5882     mCameraNode->setPosition(0,400,1200);
5883     mCameraNode->setDirection(0,-0.3f,-1.2f);
5884 
5885     //mTestNode[0] = s->getRegionIterator().getNext()->getParentSceneNode();
5886 
5887 
5888 
5889 
5890 
5891 
5892 
5893 }
5894 //----------------------------------------------------------------------------
5895 //----------------------------------------------------------------------------
5896 
PlayPen_StaticGeometryWithLOD()5897 PlayPen_StaticGeometryWithLOD::PlayPen_StaticGeometryWithLOD()
5898 {
5899     mInfo["Title"] = "PlayPen_StaticGeometryWithLOD";
5900     mInfo["Description"] = "Tests static geometry with LODs.";
5901     addScreenshotFrame(10);
5902 }
5903 //----------------------------------------------------------------------------
5904 
setupContent()5905 void PlayPen_StaticGeometryWithLOD::setupContent()
5906 {
5907     //if (stencilShadows)
5908     //{
5909     //    mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
5910     //}
5911     // Set ambient light
5912     mSceneMgr->setAmbientLight(ColourValue(0, 0, 0));
5913 
5914     // Create a point light
5915     Light* l = mSceneMgr->createLight("MainLight");
5916     l->setDiffuseColour(0.4, 0.4, 0.4);
5917     l->setSpecularColour(ColourValue::White);
5918 
5919     SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
5920     Animation* anim = mSceneMgr->createAnimation("an1", 20);
5921     anim->setInterpolationMode(Animation::IM_SPLINE);
5922     NodeAnimationTrack* track = anim->createNodeTrack(1, animNode);
5923     TransformKeyFrame* kf = track->createNodeKeyFrame(0);
5924     kf->setTranslate(Vector3(2300, 600, 2300));
5925     kf = track->createNodeKeyFrame(5);
5926     kf->setTranslate(Vector3(-2300, 600, 2300));
5927     kf = track->createNodeKeyFrame(10);
5928     kf->setTranslate(Vector3(-2300, 600, -2300));
5929     kf = track->createNodeKeyFrame(15);
5930     kf->setTranslate(Vector3(2300, 600, -2300));
5931     kf = track->createNodeKeyFrame(20);
5932     kf->setTranslate(Vector3(2300, 600, 2300));
5933 
5934     //animNode->attachObject(l);
5935     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 600, 0))->attachObject(l);
5936     l->setAttenuation(10000, 1, 0, 0);
5937 
5938     AnimationState* animState = mSceneMgr->createAnimationState("an1");
5939     animState->setEnabled(true);
5940     mAnimStateList.push_back(animState);
5941 
5942 
5943 
5944     Plane plane;
5945     plane.normal = Vector3::UNIT_Y;
5946     plane.d = 0;
5947     MeshManager::getSingleton().createPlane("Myplane",
5948                                             TRANSIENT_RESOURCE_GROUP, plane,
5949                                             4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
5950     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
5951     pPlaneEnt->setMaterialName("Examples/GrassFloor");
5952     pPlaneEnt->setCastShadows(false);
5953     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
5954 
5955     Vector3 min(-2000,30,-2000);
5956     Vector3 max(2000,30,2000);
5957 
5958 
5959     MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", ASSETS_RESOURCE_GROUP);
5960 
5961     Entity* e = mSceneMgr->createEntity("1", msh->getName());
5962 
5963     StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
5964     s->setCastShadows(true);
5965     s->setRegionDimensions(Vector3(500,500,500));
5966     for (int i = 0; i < 10; ++i)
5967     {
5968         Vector3 pos;
5969         pos.x = Math::RangeRandom(min.x, max.x);
5970         pos.y = Math::RangeRandom(min.y, max.y);
5971         pos.z = Math::RangeRandom(min.z, max.z);
5972 
5973         s->addEntity(e, pos);
5974 
5975     }
5976 
5977     s->build();
5978     mCamera->setLodBias(0.5);
5979     mCameraNode->setPosition(0,400,1200);
5980     mCameraNode->setDirection(0,-0.3f,-1.2f);
5981 
5982     //mTestNode[0] = s->getRegionIterator().getNext()->getParentSceneNode();
5983 
5984 
5985 
5986 
5987 
5988 
5989 
5990 }
5991 //----------------------------------------------------------------------------
5992 //----------------------------------------------------------------------------
5993 
5994 // render queues
5995 #define RENDER_QUEUE_OUTLINE_GLOW_OBJECTS    RENDER_QUEUE_MAIN + 1
5996 #define RENDER_QUEUE_OUTLINE_GLOW_GLOWS        RENDER_QUEUE_MAIN + 2
5997 #define RENDER_QUEUE_FULL_GLOW_ALPHA_GLOW    RENDER_QUEUE_MAIN + 3
5998 #define RENDER_QUEUE_FULL_GLOW_GLOW            RENDER_QUEUE_MAIN + 4
5999 #define LAST_STENCIL_OP_RENDER_QUEUE        RENDER_QUEUE_FULL_GLOW_GLOW
6000 
6001 // stencil values
6002 #define STENCIL_VALUE_FOR_OUTLINE_GLOW 1
6003 #define STENCIL_VALUE_FOR_FULL_GLOW 2
6004 #define STENCIL_FULL_MASK 0xFFFFFFFF
6005 
6006 // a Render queue listener to change the stencil mode
6007 class StencilOpQueueListener : public Ogre::RenderQueueListener
6008 {
6009 public:
renderQueueStarted(Ogre::uint8 queueGroupId,const Ogre::String & invocation,bool & skipThisInvocation)6010     virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
6011     {
6012         if (queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_OBJECTS) // outline glow object
6013         {
6014             Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
6015 
6016             rendersys->clearFrameBuffer(Ogre::FBT_STENCIL);
6017             rendersys->setStencilCheckEnabled(true);
6018             rendersys->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,
6019                                               STENCIL_VALUE_FOR_OUTLINE_GLOW, STENCIL_FULL_MASK, STENCIL_FULL_MASK,
6020                                               Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);
6021         }
6022         if (queueGroupId == RENDER_QUEUE_OUTLINE_GLOW_GLOWS)  // outline glow
6023         {
6024             Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
6025             rendersys->setStencilCheckEnabled(true);
6026             rendersys->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
6027                                               STENCIL_VALUE_FOR_OUTLINE_GLOW, STENCIL_FULL_MASK, STENCIL_FULL_MASK,
6028                                               Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);
6029         }
6030         if (queueGroupId == RENDER_QUEUE_FULL_GLOW_ALPHA_GLOW)  // full glow - alpha glow
6031         {
6032             Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
6033             rendersys->setStencilCheckEnabled(true);
6034             rendersys->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,
6035                                               STENCIL_VALUE_FOR_FULL_GLOW,STENCIL_FULL_MASK, STENCIL_FULL_MASK,
6036                                               Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);
6037         }
6038 
6039         if (queueGroupId == RENDER_QUEUE_FULL_GLOW_GLOW)  // full glow - glow
6040         {
6041             Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
6042             rendersys->setStencilCheckEnabled(true);
6043             rendersys->setStencilBufferParams(Ogre::CMPF_EQUAL,
6044                                               STENCIL_VALUE_FOR_FULL_GLOW,STENCIL_FULL_MASK, STENCIL_FULL_MASK,
6045                                               Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_ZERO,false);
6046         }
6047 
6048     }
6049 
renderQueueEnded(Ogre::uint8 queueGroupId,const Ogre::String & invocation,bool & repeatThisInvocation)6050     virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
6051     {
6052         if ( queueGroupId == LAST_STENCIL_OP_RENDER_QUEUE )
6053         {
6054             Ogre::RenderSystem * rendersys = Ogre::Root::getSingleton().getRenderSystem();
6055             rendersys->setStencilCheckEnabled(false);
6056             rendersys->setStencilBufferParams();
6057         }
6058     }
6059 
6060 };
6061 //---------------------------------------------------------------------------
6062 
PlayPen_StencilGlow()6063 PlayPen_StencilGlow::PlayPen_StencilGlow()
6064     :mStencilListener(0)
6065 {
6066     mInfo["Title"] = "PlayPen_StencilGlow";
6067     mInfo["Description"] = "Tests stencil glow effect.";
6068     addScreenshotFrame(100);
6069 }
6070 //---------------------------------------------------------------------------
6071 
~PlayPen_StencilGlow()6072 PlayPen_StencilGlow::~PlayPen_StencilGlow()
6073 {
6074     if(mStencilListener)
6075         delete mStencilListener;
6076 }
6077 //---------------------------------------------------------------------------
6078 
setupContent(void)6079 void PlayPen_StencilGlow::setupContent(void)
6080 {
6081     // test media
6082     Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Tests");
6083 
6084     // Set ambient light
6085     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
6086 
6087     // Create a point light
6088     Light* l = mSceneMgr->createLight("MainLight");
6089     // Accept default settings: point light, white diffuse, just set position
6090     // NB I could attach the light to a SceneNode if I wanted it to move automatically with
6091     //  other objects, but I don't
6092     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(20,80,50))->attachObject(l);
6093 
6094 
6095     // outline glow entity
6096     Entity *outlineGlowEntity = mSceneMgr->createEntity("outlineGlow", "ogrehead.mesh");
6097     outlineGlowEntity->setRenderQueueGroup(RENDER_QUEUE_OUTLINE_GLOW_OBJECTS);
6098     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(outlineGlowEntity);
6099 
6100 
6101     // outline glow entity actual glow
6102     Ogre::Entity* actualOutlineGlowEntity = outlineGlowEntity->clone(outlineGlowEntity->getName() + "_glow");
6103     actualOutlineGlowEntity->setRenderQueueGroup(RENDER_QUEUE_OUTLINE_GLOW_GLOWS);
6104     actualOutlineGlowEntity->setMaterialName("glow");
6105     Ogre::SceneNode* actualOutlineGlowNode = outlineGlowEntity->getParentSceneNode()->createChildSceneNode("outlineGlowNode");
6106     actualOutlineGlowNode->attachObject(actualOutlineGlowEntity);
6107 
6108 
6109     // normal entity
6110     Entity *normalOgreEntity = mSceneMgr->createEntity("normalOgreEntity", "ogrehead.mesh");
6111     Ogre::SceneNode* normalOgreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6112     normalOgreNode->attachObject(normalOgreEntity);
6113     normalOgreNode->setPosition(80, 0, 0);
6114 
6115 
6116 
6117     // full glow entity
6118     Entity *fullGlowEntity = mSceneMgr->createEntity("fullGlowEntity", "ogrehead.mesh");
6119     Ogre::SceneNode* fullGlowNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6120     fullGlowNode->attachObject(fullGlowEntity);
6121     fullGlowNode->setPosition(-80, 0, 0);
6122 
6123     // full glow alpha glow
6124     Ogre::Entity* alphaFullGlowEntity = fullGlowEntity->clone(fullGlowEntity->getName() + "_alphaGlow");
6125     alphaFullGlowEntity->setRenderQueueGroup(RENDER_QUEUE_FULL_GLOW_ALPHA_GLOW);
6126     alphaFullGlowEntity->setMaterialName("alpha_glow");
6127     Ogre::SceneNode* alphaFullGlowNode = fullGlowEntity->getParentSceneNode()->createChildSceneNode("fullGlowAlphaNode");
6128     alphaFullGlowNode->attachObject(alphaFullGlowEntity);
6129 
6130     // full glow alpha glow
6131     Ogre::Entity* glowFullGlowEntity = fullGlowEntity->clone(fullGlowEntity->getName() + "_glow");
6132     glowFullGlowEntity->setRenderQueueGroup(RENDER_QUEUE_FULL_GLOW_GLOW);
6133     glowFullGlowEntity->setMaterialName("no_depth_check_glow");
6134     Ogre::SceneNode* glowFullGlowNode = fullGlowEntity->getParentSceneNode()->createChildSceneNode("fullGlowGlowNode");
6135     glowFullGlowNode->attachObject(glowFullGlowEntity);
6136 
6137     mCameraNode->setPosition(0,0,200);
6138     mCameraNode->setDirection(0,0,-1);
6139 
6140     mStencilListener = new StencilOpQueueListener();
6141     mSceneMgr->addRenderQueueListener(mStencilListener);
6142 
6143 }
6144 //----------------------------------------------------------------------------
6145 //----------------------------------------------------------------------------
6146 
PlayPen_StencilShadows()6147 PlayPen_StencilShadows::PlayPen_StencilShadows()
6148 {
6149     mInfo["Title"] = "PlayPen_StencilShadows";
6150     mInfo["Description"] = "Tests stencil shadows.";
6151     addScreenshotFrame(20);
6152 }
6153 //----------------------------------------------------------------------------
6154 
setupContent()6155 void PlayPen_StencilShadows::setupContent()
6156 {
6157     SceneNode* mTestNode[10];
6158     Light* mLight = 0;
6159 
6160     mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
6161     //mSceneMgr->setShowDebugShadows(true);
6162     mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000);
6163     //mSceneMgr->setShadowColour(ColourValue(0.4, 0.25, 0.25));
6164 
6165     //mSceneMgr->setShadowFarDistance(800);
6166     // Set ambient light
6167     mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
6168 
6169     // Point light
6170     //if(pointLight)
6171     //{
6172     mLight = mSceneMgr->createLight("MainLight");
6173     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-400,400,-300))->attachObject(mLight);
6174     mLight->setDiffuseColour(0.9, 0.9, 1);
6175     mLight->setSpecularColour(0.9, 0.9, 1);
6176     mLight->setAttenuation(6000,1,0.001,0);
6177     //}
6178     // Directional light
6179     //if (directionalLight)
6180     //{
6181     mLight = mSceneMgr->createLight("Light2");
6182     Vector3 dir(-1,-1,0);
6183     dir.normalise();
6184     mLight->setType(Light::LT_DIRECTIONAL);
6185     mLight->setDirection(dir);
6186     mLight->setDiffuseColour(1, 1, 0.8);
6187     mLight->setSpecularColour(1, 1, 1);
6188     //}
6189 
6190     mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6191 
6192     // Hardware skin
6193     Entity* pEnt;
6194     pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
6195     AnimationState* anim = pEnt->getAnimationState("Walk");
6196     anim->setEnabled(true);
6197     mAnimStateList.push_back(anim);
6198     mTestNode[0]->attachObject( pEnt );
6199 
6200     // Software skin
6201     pEnt = mSceneMgr->createEntity( "12", "robot.mesh" );
6202     anim = pEnt->getAnimationState("Walk");
6203     anim->setEnabled(true);
6204     mAnimStateList.push_back(anim);
6205     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 0))->attachObject(pEnt);
6206     pEnt->setMaterialName("Examples/Rocky");
6207 
6208     // test object
6209     //pEnt = mSceneMgr->createEntity("tst", "building.mesh");
6210     //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(300, 0, 0))->attachObject(pEnt);
6211 
6212 
6213     // Does not receive shadows
6214     pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
6215     pEnt->setMaterialName("Examples/EnvMappedRustySteel");
6216     MaterialPtr mat2 = MaterialManager::getSingleton().getByName("Examples/SphereMappedRustySteel");
6217     mat2->setReceiveShadows(false);
6218     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
6219     mTestNode[2]->attachObject( pEnt );
6220 
6221     // Transparent object
6222     pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
6223     pEnt->setMaterialName("Examples/TransparentTest");
6224     MaterialPtr mat3 = MaterialManager::getSingleton().getByName("Examples/TransparentTest");
6225     pEnt->setCastShadows(false);
6226     mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
6227     mTestNode[3]->attachObject( pEnt );
6228 
6229     // User test
6230     /*
6231       pEnt = mSceneMgr->createEntity( "3.6", "ogre_male_endCaps.mesh" );
6232       mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 0, 100))->attachObject( pEnt );
6233     */
6234 
6235     MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", ASSETS_RESOURCE_GROUP);
6236     unsigned short src, dest;
6237     if (!msh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
6238     {
6239         msh->buildTangentVectors(VES_TANGENT, src, dest);
6240     }
6241     pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
6242     pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
6243     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
6244     mTestNode[2]->attachObject( pEnt );
6245 
6246     // controller based material
6247     pEnt = mSceneMgr->createEntity( "432", "knot.mesh" );
6248     pEnt->setMaterialName("Examples/TextureEffect2");
6249     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 200, 200))->attachObject( pEnt );
6250 
6251     ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
6252                                                             "Examples/Smoke");
6253     mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
6254     mTestNode[4]->attachObject(pSys2);
6255 
6256 
6257     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
6258 
6259 
6260     Plane plane;
6261     plane.normal = Vector3::UNIT_Y;
6262     plane.d = 100;
6263     MeshManager::getSingleton().createPlane("Myplane",
6264                                             TRANSIENT_RESOURCE_GROUP, plane,
6265                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
6266     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
6267     pPlaneEnt->setMaterialName("2 - Default");
6268     pPlaneEnt->setCastShadows(false);
6269     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
6270 
6271     //mCameraNode->setPosition(180, 34, 223);
6272     //mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791));
6273 
6274     mCameraNode->setPosition(0,0,400);
6275     mCameraNode->setDirection(0,0,-1);
6276 
6277     // Create a render texture
6278     /*    TexturePtr rtt = TextureManager::getSingleton().createManual("rtt0",
6279           TRANSIENT_RESOURCE_GROUP,
6280           TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET);
6281           rtt->getBuffer()->getRenderTarget()->addViewport(mCamera);
6282           // Create an overlay showing the rtt
6283           MaterialPtr debugMat = MaterialManager::getSingleton().create(
6284           "DebugRTT", TRANSIENT_RESOURCE_GROUP);
6285           debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
6286           TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("rtt0");
6287           t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
6288           OverlayContainer* debugPanel = (OverlayContainer*)
6289           (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel"));
6290           debugPanel->_setPosition(0.6, 0);
6291           debugPanel->_setDimensions(0.4, 0.6);
6292           debugPanel->setMaterialName("DebugRTT");
6293           Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
6294           debugOverlay->add2D(debugPanel);*/
6295 
6296 
6297 }
6298 //----------------------------------------------------------------------------
6299 //----------------------------------------------------------------------------
6300 
PlayPen_StencilShadowsMixedOpSubMeshes()6301 PlayPen_StencilShadowsMixedOpSubMeshes::PlayPen_StencilShadowsMixedOpSubMeshes()
6302 {
6303     mInfo["Title"] = "PlayPen_StencilShadowsMixedOpSubMeshes";
6304     mInfo["Description"] = "Tests mixed operation submeshes.";
6305     addScreenshotFrame(20);
6306 }
6307 //----------------------------------------------------------------------------
6308 
setupContent()6309 void PlayPen_StencilShadowsMixedOpSubMeshes::setupContent()
6310 {
6311     mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
6312     //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
6313     //mSceneMgr->setShowDebugShadows(true);
6314     mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000);
6315 
6316     //mSceneMgr->setShadowFarDistance(800);
6317     // Set ambient light
6318     mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
6319 
6320     Light* mLight;
6321 
6322     // Point light
6323     //if(pointLight)
6324     //{
6325     mLight = mSceneMgr->createLight("MainLight");
6326     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-400,400,-300))->attachObject(mLight);
6327     mLight->setDiffuseColour(0.9, 0.9, 1);
6328     mLight->setSpecularColour(0.9, 0.9, 1);
6329     mLight->setAttenuation(6000,1,0.001,0);
6330     //}
6331     // Directional light
6332     //if (directionalLight)
6333     //{
6334     /*mLight = mSceneMgr->createLight("Light2");
6335       Vector3 dir(-1,-1,0);
6336       dir.normalise();
6337       mLight->setType(Light::LT_DIRECTIONAL);
6338       mLight->setDirection(dir);
6339       mLight->setDiffuseColour(1, 1, 0.8);
6340       mLight->setSpecularColour(1, 1, 1);*/
6341     //}
6342 
6343     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
6344 
6345 
6346     Plane plane;
6347     plane.normal = Vector3::UNIT_Y;
6348     plane.d = 100;
6349     MeshManager::getSingleton().createPlane("Myplane",
6350                                             TRANSIENT_RESOURCE_GROUP, plane,
6351                                             1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
6352     Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
6353     pPlaneEnt->setMaterialName("2 - Default");
6354     pPlaneEnt->setCastShadows(false);
6355     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
6356 
6357     //mCameraNode->setPosition(180, 34, 223);
6358     //mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791));
6359 
6360 
6361     ManualObject* man = mSceneMgr->createManualObject("testMO_");
6362     man->begin("2 - Default");
6363     man->position(0, 200, 0);
6364     man->position(0, 50, 100);
6365     man->position(100, 50, -100);
6366     man->position(-100, 50, -100);
6367     man->triangle(0, 1, 2);
6368     man->triangle(0, 2, 3);
6369     man->triangle(0, 3, 1);
6370     man->end();
6371     man->begin("2 - Default", RenderOperation::OT_LINE_STRIP);
6372     man->position(0, 200, 0);
6373     man->position(50, 250, 0);
6374     man->position(200, 300, 0);
6375     man->index(0);
6376     man->index(1);
6377     man->index(2);
6378     man->end();
6379     MeshPtr msh = man->convertToMesh("testMO.mesh_2");
6380 
6381     Entity* e = mSceneMgr->createEntity("34", "testMO.mesh_2");
6382     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
6383 
6384     mCameraNode->setPosition(100,320,600);
6385     mCameraNode->lookAt(Vector3(0, 120, 0), Node::TS_PARENT);
6386 
6387 }
6388 //----------------------------------------------------------------------------
6389 //----------------------------------------------------------------------------
6390 
PlayPen_SubEntityVisibility()6391 PlayPen_SubEntityVisibility::PlayPen_SubEntityVisibility()
6392 {
6393     mInfo["Title"] = "PlayPen_SubEntityVisibility";
6394     mInfo["Description"] = "Tests sub entity visibility settings.";
6395     addScreenshotFrame(250);
6396 }
6397 //----------------------------------------------------------------------------
6398 
setupContent()6399 void PlayPen_SubEntityVisibility::setupContent()
6400 {
6401     SceneNode* mTestNode[5];
6402     // Set ambient light
6403     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
6404 
6405     // Create a point light
6406     Light* l = mSceneMgr->createLight("MainLight");
6407     l->setType(Light::LT_DIRECTIONAL);
6408     l->setDirection(-Vector3::UNIT_Y);
6409 
6410     mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
6411 
6412     Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
6413     mTestNode[0]->attachObject( pEnt );
6414 
6415     pEnt->getSubEntity(1)->setVisible(false);
6416 
6417     mCameraNode->setPosition(0,0,125);
6418 }
6419 //----------------------------------------------------------------------------
6420 //----------------------------------------------------------------------------
6421 
PlayPen_SuppressedShadows()6422 PlayPen_SuppressedShadows::PlayPen_SuppressedShadows()
6423 {
6424     mInfo["Title"] = "PlayPen_SuppressedShadows";
6425     mInfo["Description"] = "Tests suppressing shadows for a viewport.";
6426     addScreenshotFrame(10);
6427 }
6428 //----------------------------------------------------------------------------
6429 
setupContent()6430 void PlayPen_SuppressedShadows::setupContent()
6431 {
6432     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
6433 
6434     // Setup lighting
6435     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
6436     Light* light = mSceneMgr->createLight("MainLight");
6437     light->setType(Light::LT_DIRECTIONAL);
6438     Vector3 dir(-1, -1, 0.5);
6439     dir.normalise();
6440     light->setDirection(dir);
6441 
6442     // Create a skydome
6443     //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
6444 
6445     // Create a floor plane mesh
6446     Plane plane(Vector3::UNIT_Y, 0.0);
6447     MeshManager::getSingleton().createPlane(
6448         "FloorPlane", TRANSIENT_RESOURCE_GROUP,
6449         plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z);
6450 
6451 
6452     // Add a floor to the scene
6453     Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane");
6454     entity->setMaterialName("Examples/RustySteel");
6455     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
6456     entity->setCastShadows(false);
6457 
6458     // Add the mandatory ogre head
6459     entity = mSceneMgr->createEntity("head", "ogrehead.mesh");
6460     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity);
6461 
6462     // Position and orient the camera
6463     mCameraNode->setPosition(-100.0, 50.0, 90.0);
6464     mCameraNode->lookAt(Vector3(0.0, 10.0, -35.0), Node::TS_PARENT);
6465 
6466     // Add an additional viewport on top of the other one
6467     Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3);
6468 
6469     // Create a render queue invocation sequence for the pip viewport
6470     RenderQueueInvocationSequence* invocationSequence =
6471         mRoot->createRenderQueueInvocationSequence("pip");
6472 
6473     // Add an invocation to the sequence
6474     RenderQueueInvocation* invocation =
6475         invocationSequence->add(RENDER_QUEUE_MAIN, "main");
6476 
6477     // Disable render state changes and shadows for that invocation
6478     //invocation->setSuppressRenderStateChanges(true);
6479     invocation->setSuppressShadows(true);
6480 
6481     // Set the render queue invocation sequence for the pip viewport
6482     pip->setRenderQueueInvocationSequenceName("pip");
6483 }
6484 //----------------------------------------------------------------------------
6485 //----------------------------------------------------------------------------
6486 
6487 
PlayPen_TextureShadows()6488 PlayPen_TextureShadows::PlayPen_TextureShadows()
6489 {
6490     mInfo["Title"] = "PlayPen_TextureShadows";
6491     mInfo["Description"] = "Tests texture shadows.";
6492     addScreenshotFrame(10);
6493 }
6494 //----------------------------------------------------------------------------
6495 
cleanupContent()6496 void PlayPen_TextureShadows::cleanupContent()
6497 {
6498     clearDebugTextureOverlays();
6499 }
6500 //----------------------------------------------------------------------------
6501 
setupContent()6502 void PlayPen_TextureShadows::setupContent()
6503 {
6504     SceneNode* mTestNode[10];
6505 
6506     mSceneMgr->setShadowTextureSize(1024);
6507     mSceneMgr->setShadowTextureCount(1);
6508     //mSceneMgr->setShadowTechnique(tech);
6509     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
6510 
6511     //FocusedShadowCameraSetup* lispsmSetup = new FocusedShadowCameraSetup();
6512     //LiSPSMShadowCameraSetup* lispsmSetup = new LiSPSMShadowCameraSetup();
6513     //lispsmSetup->setOptimalAdjustFactor(1.5);
6514     //mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(lispsmSetup));
6515 
6516     mSceneMgr->setShadowFarDistance(1000);
6517     mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
6518     //mSceneMgr->setShadowFarDistance(800);
6519     // Set ambient light
6520     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
6521 
6522     Light* mLight = mSceneMgr->createLight("MainLight");
6523 
6524 
6525     // Directional test
6526     //if (directional)
6527     //{
6528     mLight->setType(Light::LT_DIRECTIONAL);
6529     Vector3 vec(-1,-1,0);
6530     vec.normalise();
6531     mLight->setDirection(vec);
6532     //}
6533     // Spotlight test
6534     /*else
6535       {
6536       mLight->setType(Light::LT_SPOTLIGHT);
6537       mLight->setAttenuation(1500, 1, 0, 0);
6538       mLight->setDiffuseColour(1.0, 1.0, 0.8);
6539       mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6540       mTestNode[0]->setPosition(800,600,0);
6541       mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD, Vector3::UNIT_Z);
6542       mTestNode[0]->attachObject(mLight);
6543       }*/
6544 
6545     mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6546 
6547 
6548     Entity* pEnt;
6549     pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
6550     //pEnt->setRenderingDistance(100);
6551     AnimationState* mAnimState = pEnt->getAnimationState("Walk");
6552     mAnimState->setEnabled(true);
6553     mAnimStateList.push_back(mAnimState);
6554     //pEnt->setMaterialName("2 - Default");
6555     mTestNode[1]->attachObject( pEnt );
6556     mTestNode[1]->translate(0,-100,0);
6557 
6558     Quaternion quat2;
6559     quat2.FromAngleAxis(Degree(360), Vector3::UNIT_Y);
6560 
6561     pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
6562     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
6563     mTestNode[2]->attachObject( pEnt );
6564 
6565     createRandomEntityClones(pEnt, 20, Vector3(-1000,0,-1000), Vector3(1000,0,1000), mSceneMgr);
6566 
6567 
6568     // Transparent object (can force cast shadows)
6569     pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
6570     MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency",
6571                                                               TRANSIENT_RESOURCE_GROUP);
6572     tmat->setTransparencyCastsShadows(true);
6573     Pass* tpass = tmat->getTechnique(0)->getPass(0);
6574     tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
6575     tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
6576     tpass->createTextureUnitState("gras_02.png");
6577     tpass->setCullingMode(CULL_NONE);
6578 
6579     pEnt->setMaterialName("TestAlphaTransparency");
6580     mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
6581     mTestNode[3]->attachObject( pEnt );
6582 
6583     pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
6584     mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
6585     mTestNode[2]->attachObject( pEnt );
6586 
6587     mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
6588 
6589 
6590     MovablePlane movablePlane(Vector3::UNIT_Y, 100);
6591     MeshManager::getSingleton().createPlane("Myplane",
6592                                             TRANSIENT_RESOURCE_GROUP, movablePlane,
6593                                             2500,2500,10,10,true,1,5,5,Vector3::UNIT_Z);
6594     Entity* pPlaneEnt;
6595     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
6596     if (SHADOWTYPE_TEXTURE_ADDITIVE & SHADOWDETAILTYPE_INTEGRATED)
6597     {
6598         pPlaneEnt->setMaterialName("Examples/Plane/IntegratedShadows");
6599     }
6600     else
6601     {
6602         pPlaneEnt->setMaterialName("2 - Default");
6603     }
6604     pPlaneEnt->setCastShadows(false);
6605     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
6606 
6607     addTextureShadowDebugOverlay(1,mSceneMgr);
6608 
6609 
6610     /*
6611       ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
6612       "Examples/Smoke");
6613       mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
6614       mTestNode[4]->attachObject(pSys2);
6615     */
6616 
6617     mCameraNode->setPosition(0, 1000, 500);
6618     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
6619     mCamera->setFarClipDistance(10000);
6620 
6621 
6622 }
6623 //----------------------------------------------------------------------------
6624 //----------------------------------------------------------------------------
6625 
PlayPen_TextureShadowsCustomCasterMat()6626 PlayPen_TextureShadowsCustomCasterMat::PlayPen_TextureShadowsCustomCasterMat()
6627 {
6628     mInfo["Title"] = "PlayPen_TextureShadowsCustomCasterMat";
6629     mInfo["Description"] = "Tests texture shadows with a custom caster material.";
6630     addScreenshotFrame(10);
6631 }
6632 //----------------------------------------------------------------------------
6633 
setupContent()6634 void PlayPen_TextureShadowsCustomCasterMat::setupContent()
6635 {
6636     PlayPen_TextureShadows::setupContent();
6637 
6638     String customCasterMatVp =
6639         "void customCasterVp(float4 position : POSITION,\n"
6640         "out float4 oPosition : POSITION,\n"
6641         "uniform float4x4 worldViewProj)\n"
6642         "{\n"
6643         "    oPosition = mul(worldViewProj, position);\n"
6644         "}\n";
6645     String customCasterMatFp =
6646         "void customCasterFp(\n"
6647         "out float4 oColor : COLOR)\n"
6648         "{\n"
6649         "    oColor = float4(1,1,0,1); // just a test\n"
6650         "}\n";
6651 
6652     HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton()
6653         .createProgram("CustomShadowCasterVp",
6654                        TRANSIENT_RESOURCE_GROUP,
6655                        "cg", GPT_VERTEX_PROGRAM);
6656     vp->setSource(customCasterMatVp);
6657     vp->setParameter("profiles", "vs_1_1 arbvp1 glslv");
6658     vp->setParameter("entry_point", "customCasterVp");
6659     vp->load();
6660 
6661     HighLevelGpuProgramPtr fp = HighLevelGpuProgramManager::getSingleton()
6662         .createProgram("CustomShadowCasterFp",
6663                        TRANSIENT_RESOURCE_GROUP,
6664                        "cg", GPT_FRAGMENT_PROGRAM);
6665     fp->setSource(customCasterMatFp);
6666     fp->setParameter("profiles", "ps_1_1 arbfp1 glslf");
6667     fp->setParameter("entry_point", "customCasterFp");
6668     fp->load();
6669 
6670     MaterialPtr mat = MaterialManager::getSingleton().create("CustomShadowCaster",
6671                                                              TRANSIENT_RESOURCE_GROUP);
6672     Pass* p = mat->getTechnique(0)->getPass(0);
6673     p->setVertexProgram("CustomShadowCasterVp");
6674     p->getVertexProgramParameters()->setNamedAutoConstant(
6675         "worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
6676     p->setFragmentProgram("CustomShadowCasterFp");
6677 
6678     mSceneMgr->setShadowTextureCasterMaterial(mat);
6679 
6680 
6681 
6682 
6683 
6684 }
6685 //----------------------------------------------------------------------------
6686 //----------------------------------------------------------------------------
6687 
PlayPen_TextureShadowsCustomReceiverMat()6688 PlayPen_TextureShadowsCustomReceiverMat::PlayPen_TextureShadowsCustomReceiverMat()
6689 {
6690     mInfo["Title"] = "PlayPen_TextureShadowsCustomReceiverMat";
6691     mInfo["Description"] = "Tests texture shadows with a custom receiver material.";
6692     addScreenshotFrame(10);
6693 }
6694 //----------------------------------------------------------------------------
6695 
setupContent()6696 void PlayPen_TextureShadowsCustomReceiverMat::setupContent()
6697 {
6698     PlayPen_TextureShadows::setupContent();
6699 
6700     String customReceiverMatVp =
6701         "void customReceiverVp(float4 position : POSITION,\n"
6702         "out float4 oPosition : POSITION,\n"
6703         "out float2 oUV : TEXCOORD0,\n"
6704         "uniform float4x4 texViewProj,\n"
6705         "uniform float4x4 worldViewProj)\n"
6706         "{\n"
6707         "    oPosition = mul(worldViewProj, position);\n"
6708         "    float4 suv = mul(texViewProj, position);\n"
6709         "    oUV = suv.xy / suv.w;\n"
6710         "}\n";
6711     String customReceiverMatFp =
6712         "void customReceiverFp(\n"
6713         "float2 uv : TEXCOORD0,\n"
6714         "uniform sampler2D shadowTex : register(s0),\n"
6715         "out float4 oColor : COLOR)\n"
6716         "{\n"
6717         "    float4 shadow = tex2D(shadowTex, uv);\n"
6718         "    oColor = shadow * float4(1,0,1,1); // just a test\n"
6719         "}\n";
6720 
6721     HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton()
6722         .createProgram("CustomShadowReceiverVp",
6723                        TRANSIENT_RESOURCE_GROUP,
6724                        "cg", GPT_VERTEX_PROGRAM);
6725     vp->setSource(customReceiverMatVp);
6726     vp->setParameter("profiles", "vs_1_1 arbvp1 glslv");
6727     vp->setParameter("entry_point", "customReceiverVp");
6728     vp->load();
6729 
6730     HighLevelGpuProgramPtr fp = HighLevelGpuProgramManager::getSingleton()
6731         .createProgram("CustomShadowReceiverFp",
6732                        TRANSIENT_RESOURCE_GROUP,
6733                        "cg", GPT_FRAGMENT_PROGRAM);
6734     fp->setSource(customReceiverMatFp);
6735     fp->setParameter("profiles", "ps_1_1 arbfp1 glslf");
6736     fp->setParameter("entry_point", "customReceiverFp");
6737     fp->load();
6738 
6739     MaterialPtr mat = MaterialManager::getSingleton().create("CustomShadowReceiver",
6740                                                              TRANSIENT_RESOURCE_GROUP);
6741     Pass* p = mat->getTechnique(0)->getPass(0);
6742     p->setVertexProgram("CustomShadowReceiverVp");
6743     p->getVertexProgramParameters()->setNamedAutoConstant(
6744         "worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
6745     p->getVertexProgramParameters()->setNamedAutoConstant(
6746         "texViewProj", GpuProgramParameters::ACT_TEXTURE_VIEWPROJ_MATRIX);
6747     p->setFragmentProgram("CustomShadowReceiverFp");
6748     p->createTextureUnitState(); // shadow texture will populate
6749 
6750     mSceneMgr->setShadowTextureReceiverMaterial(mat);
6751 
6752 
6753 
6754 }
6755 //----------------------------------------------------------------------------
6756 //----------------------------------------------------------------------------
6757 
PlayPen_TextureShadowsIntegrated()6758 PlayPen_TextureShadowsIntegrated::PlayPen_TextureShadowsIntegrated()
6759 {
6760     mInfo["Title"] = "PlayPen_TextureShadowsIntegrated";
6761     mInfo["Description"] = "Tests integrated texture shadows.";
6762     addScreenshotFrame(10);
6763 }
6764 //----------------------------------------------------------------------------
6765 
cleanupContent()6766 void PlayPen_TextureShadowsIntegrated::cleanupContent()
6767 {
6768     clearDebugTextureOverlays();
6769 }
6770 //----------------------------------------------------------------------------
6771 
setupContent()6772 void PlayPen_TextureShadowsIntegrated::setupContent()
6773 {
6774     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
6775     //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
6776     MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
6777     MaterialManager::getSingleton().setDefaultAnisotropy(5);
6778 
6779     mSceneMgr->setShadowTextureSettings(1024, 2);
6780 
6781     mSceneMgr->setAmbientLight(ColourValue::Black);
6782     Light* l = mSceneMgr->createLight("Spot1");
6783     l->setType(Light::LT_SPOTLIGHT);
6784     l->setAttenuation(5000,1,0,0);
6785     l->setSpotlightRange(Degree(30),Degree(45),1.0f);
6786     SceneNode* lightNode1 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6787     lightNode1->attachObject(l);
6788     lightNode1->setPosition(400, 250, 500);
6789     lightNode1->lookAt(Vector3(0,-200,0), Node::TS_WORLD);
6790     l->setDiffuseColour(0.7, 0.7, 0.5);
6791 
6792     l = mSceneMgr->createLight("Spot2");
6793     l->setAttenuation(5000,1,0,0);
6794     /* // spotlight */
6795     l->setType(Light::LT_SPOTLIGHT);
6796     l->setSpotlightRange(Degree(30),Degree(45),1.0f);
6797     /**/
6798     // point
6799     SceneNode* lightNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6800     lightNode2->attachObject(l);
6801     lightNode2->setPosition(-500, 200, 500);
6802     lightNode2->lookAt(Vector3(0,-200,0), Node::TS_WORLD);
6803     /* // directional
6804        l->setType(Light::LT_DIRECTIONAL);
6805        Vector3 dir(0.5, -1, 0.5);
6806        dir.normalise();
6807        l->setDirection(dir);
6808     */
6809     l->setDiffuseColour(1, 0.2, 0.2);
6810 
6811     /*
6812     // Test spot 3
6813     l = mSceneMgr->createLight("Spot3");
6814     l->setType(Light::LT_SPOTLIGHT);
6815     l->setAttenuation(5000,1,0,0);
6816     l->setSpotlightRange(Degree(30),Degree(45),1.0f);
6817     SceneNode* lightNode3 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6818     lightNode3->attachObject(l);
6819     lightNode3->setPosition(700, 250, 500);
6820     lightNode3->lookAt(Vector3(0,-200,0), Node::TS_WORLD);
6821     l->setDiffuseColour(0.0, 0.7, 1.0);
6822     */
6823 
6824     // Create a basic plane to have something in the scene to look at
6825     Plane plane;
6826     plane.normal = Vector3::UNIT_Y;
6827     plane.d = 100;
6828     MeshPtr msh = MeshManager::getSingleton().createPlane("Myplane_IS",
6829                                                           TRANSIENT_RESOURCE_GROUP, plane,
6830                                                           4500,4500,100,100,true,1,40,40,Vector3::UNIT_Z);
6831     msh->buildTangentVectors(VES_TANGENT);
6832     Entity* pPlaneEnt;
6833     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane_IS" );
6834     //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular");
6835     pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows");
6836     pPlaneEnt->setCastShadows(false);
6837     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
6838 
6839     pPlaneEnt = mSceneMgr->createEntity( "plane2", "Myplane_IS" );
6840     //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular");
6841     pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows");
6842     pPlaneEnt->setCastShadows(false);
6843     SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6844     n->roll(Degree(90));
6845     n->translate(100,0,0);
6846     //n->attachObject(pPlaneEnt);
6847 
6848     pPlaneEnt = mSceneMgr->createEntity( "plane3", "Myplane_IS" );
6849     //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular");
6850     pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows");
6851     pPlaneEnt->setCastShadows(false);
6852     n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
6853     n->pitch(Degree(90));
6854     n->yaw(Degree(-90));
6855     n->translate(0,0,-100);
6856     n->attachObject(pPlaneEnt);
6857 
6858     mCameraNode->setPosition(-50, 500, 1000);
6859     mCameraNode->lookAt(Vector3(Vector3(-50, -100, 0)), Node::TS_PARENT);
6860 
6861     Entity* ent = mSceneMgr->createEntity("athene", "athene.mesh");
6862     ent->setMaterialName("Examples/Athene/NormalMapped");
6863     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,-20,0))->attachObject(ent);
6864 
6865     addTextureShadowDebugOverlay(2, mSceneMgr);
6866 
6867 
6868 
6869 }
6870 //----------------------------------------------------------------------------
6871 //----------------------------------------------------------------------------
6872 
PlayPen_TextureShadowsIntegratedPSSM()6873 PlayPen_TextureShadowsIntegratedPSSM::PlayPen_TextureShadowsIntegratedPSSM()
6874 {
6875     mInfo["Title"] = "PlayPen_TextureShadowsIntegratedPSSM";
6876     mInfo["Description"] = "Tests integrated parallel split shadow mapping.";
6877     addScreenshotFrame(10);
6878 }
6879 //----------------------------------------------------------------------------
6880 
cleanupContent()6881 void PlayPen_TextureShadowsIntegratedPSSM::cleanupContent()
6882 {
6883     clearDebugTextureOverlays();
6884 }
6885 //----------------------------------------------------------------------------
6886 
setupContent()6887 void PlayPen_TextureShadowsIntegratedPSSM::setupContent()
6888 {
6889     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
6890 
6891     // 3 textures per directional light
6892     mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
6893     mSceneMgr->setShadowTextureSettings(512, 3, PF_FLOAT32_R);
6894     mSceneMgr->setShadowTextureSelfShadow(true);
6895     // Set up caster material - this is just a standard depth/shadow map caster
6896     mSceneMgr->setShadowTextureCasterMaterial(
6897         MaterialManager::getSingleton().getByName("PSSM/shadow_caster", "General"));
6898 
6899     // shadow camera setup
6900     PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup();
6901     pssmSetup->calculateSplitPoints(3, mCamera->getNearClipDistance(), mCamera->getFarClipDistance());
6902     pssmSetup->setSplitPadding(10);
6903     pssmSetup->setOptimalAdjustFactor(0, 2);
6904     pssmSetup->setOptimalAdjustFactor(1, 1);
6905     pssmSetup->setOptimalAdjustFactor(2, 0.5);
6906 
6907     mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(pssmSetup));
6908 
6909 
6910     mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
6911     Light* l = mSceneMgr->createLight("Dir");
6912     l->setType(Light::LT_DIRECTIONAL);
6913     Vector3 dir(0.3, -1, 0.2);
6914     dir.normalise();
6915     l->setDirection(dir);
6916 
6917 
6918     // Create a basic plane to have something in the scene to look at
6919     Plane plane;
6920     plane.normal = Vector3::UNIT_Y;
6921     plane.d = 100;
6922     MeshPtr msh = MeshManager::getSingleton().createPlane("Myplane",
6923                                                           TRANSIENT_RESOURCE_GROUP, plane,
6924                                                           4500,4500,100,100,true,1,40,40,Vector3::UNIT_Z);
6925     msh->buildTangentVectors(VES_TANGENT);
6926     Entity* pPlaneEnt;
6927     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
6928     pPlaneEnt->setMaterialName("PSSM/Plane");
6929     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
6930 
6931     mCameraNode->setPosition(-50, 500, 1000);
6932     mCameraNode->lookAt(Vector3(Vector3(-50, -100, 0)), Node::TS_PARENT);
6933 
6934     Entity* ent = mSceneMgr->createEntity("knot", "knot.mesh");
6935     ent->setMaterialName("PSSM/Knot");
6936     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0))->attachObject(ent);
6937     createRandomEntityClones(ent, 20, Vector3(-1000,0,-1000), Vector3(1000,0,1000), mSceneMgr);
6938 
6939 
6940     Vector4 splitPoints;
6941     const PSSMShadowCameraSetup::SplitPointList& splitPointList = pssmSetup->getSplitPoints();
6942     for (int i = 0; i < 3; ++i)
6943     {
6944         splitPoints[i] = splitPointList[i];
6945     }
6946     MaterialPtr mat = MaterialManager::getSingleton().getByName("PSSM/Plane");
6947     mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
6948     mat = MaterialManager::getSingleton().getByName("PSSM/Knot");
6949     mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
6950 
6951     addTextureShadowDebugOverlay(3, mSceneMgr);
6952 
6953 
6954 
6955 }
6956 //----------------------------------------------------------------------------
6957 //----------------------------------------------------------------------------
6958 
PlayPen_TextureShadowsTransparentCaster()6959 PlayPen_TextureShadowsTransparentCaster::PlayPen_TextureShadowsTransparentCaster()
6960 {
6961     mInfo["Title"] = "PlayPen_TextureShadowsTransparentCaster";
6962     mInfo["Description"] = "Tests transparent shadow casters.";
6963     addScreenshotFrame(10);
6964 }
6965 //----------------------------------------------------------------------------
6966 
setupContent()6967 void PlayPen_TextureShadowsTransparentCaster::setupContent()
6968 {
6969     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
6970 
6971     //mLiSPSMSetup->setUseAggressiveFocusRegion(false);
6972     //ShadowCameraSetupPtr(new PlaneOptimalShadowCameraSetup(mPlane));
6973     mSceneMgr->setShadowCameraSetup(LiSPSMShadowCameraSetup::create());
6974 
6975     PixelFormat pxFmt = PF_L8;
6976     if (Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_TEXTURE_FLOAT))
6977     {
6978         pxFmt = PF_FLOAT32_R;
6979     }
6980     mSceneMgr->setShadowTextureSettings(1024, 1, pxFmt);
6981 
6982     // New depth shadow mapping
6983     String CUSTOM_ROCKWALL_MATERIAL("Ogre/DepthShadowmap/Receiver/RockWall");
6984     MaterialPtr CUSTOM_CASTER_MATERIAL = MaterialManager::getSingleton().getByName("Ogre/DepthShadowmap/Caster/Float", "General");
6985     MaterialPtr CUSTOM_RECEIVER_MATERIAL = MaterialManager::getSingleton().getByName("Ogre/DepthShadowmap/Receiver/Float", "General");
6986 
6987     mSceneMgr->setShadowTextureCasterMaterial(CUSTOM_CASTER_MATERIAL);
6988     mSceneMgr->setShadowTextureReceiverMaterial(CUSTOM_RECEIVER_MATERIAL);
6989     mSceneMgr->setShadowTextureSelfShadow(true);
6990 
6991     mSceneMgr->setShadowTextureFadeStart(1.0);
6992     mSceneMgr->setShadowTextureFadeEnd(1.0);
6993 
6994     mSceneMgr->setShadowTextureSelfShadow(true);
6995 
6996     MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
6997     MaterialManager::getSingleton().setDefaultAnisotropy(5);
6998 
6999     mSceneMgr->setShadowDirLightTextureOffset(0.2);
7000     mSceneMgr->setShadowFarDistance(150);
7001     //mSceneMgr->setShadowCasterRenderBackFaces(false);
7002 
7003     // Create a basic plane to have something in the scene to look at
7004     Plane plane;
7005     plane.normal = Vector3::UNIT_Y;
7006     plane.d = 100;
7007     MeshPtr msh = MeshManager::getSingleton().createPlane("Myplane",
7008                                                           TRANSIENT_RESOURCE_GROUP, plane,
7009                                                           4500,4500,100,100,true,1,40,40,Vector3::UNIT_Z);
7010     msh->buildTangentVectors(VES_TANGENT);
7011     Entity* pPlaneEnt;
7012     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
7013 
7014     pPlaneEnt->setMaterialName(CUSTOM_ROCKWALL_MATERIAL);
7015     pPlaneEnt->setCastShadows(false);
7016     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
7017 
7018 
7019 
7020     // Reorient the plane and create a plane mesh for the test planes
7021     plane.normal = Vector3::UNIT_Z;
7022     MeshManager::getSingleton().createPlane(
7023         "Test_Plane", TRANSIENT_RESOURCE_GROUP,
7024         plane, 50.0, 50.0, 1, 1, true);
7025 
7026 
7027     const String GRASSMAT("Examples/GrassBladesAdditiveFloatTransparent");
7028     //const String GRASSMAT("Examples/DepthShadowmap/CasterReceiver/GrassBlades");
7029     //const String GRASSMAT("tree4324");//"tree1.tga");
7030 
7031 
7032     // Add test plane entities to the scene
7033     Entity* entity = mSceneMgr->createEntity("GrassBlades0", "Test_Plane");
7034     entity->setMaterialName(GRASSMAT);
7035     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7036         Vector3(0.0, -100.0+25.0, 0.0))->attachObject(entity);
7037 
7038 
7039     entity = mSceneMgr->createEntity("GrassBlades1", "Test_Plane");
7040     entity->setMaterialName(GRASSMAT);
7041     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7042         Vector3(0.0, -100.0+25.0, -20.0))->attachObject(entity);
7043 
7044     entity = mSceneMgr->createEntity("GrassBlades2", "Test_Plane");
7045     entity->setMaterialName(GRASSMAT);
7046     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7047         Vector3(0.0, -100.0+25.0, -40.0))->attachObject(entity);
7048 
7049     // Add test plane entities to the scene, shadowed partially by athene mesh
7050     entity = mSceneMgr->createEntity("GrassBlades3", "Test_Plane");
7051     entity->setMaterialName(GRASSMAT);
7052     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7053         Vector3(-80.0, -100.0+25.0, 0.0))->attachObject(entity);
7054 
7055     entity = mSceneMgr->createEntity("GrassBlades4", "Test_Plane");
7056     entity->setMaterialName(GRASSMAT);
7057     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7058         Vector3(-130.0, -100.0+25.0, -20.0))->attachObject(entity);
7059 
7060     entity = mSceneMgr->createEntity("GrassBlades5", "Test_Plane");
7061     entity->setMaterialName(GRASSMAT);
7062     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7063         Vector3(-180.0, -100.0+25.0, -40.0))->attachObject(entity);
7064 
7065 
7066 
7067     Entity* ent = mSceneMgr->createEntity("athene", "athene.mesh");
7068     ent->setMaterialName(CUSTOM_ROCKWALL_MATERIAL);
7069     //ent->setMaterialName(GRASSMAT);
7070     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,-20,-20))->attachObject(ent);
7071 
7072     // Add test plane entities to the scene, one after another
7073     entity = mSceneMgr->createEntity("GrassBlades6", "Test_Plane");
7074     entity->setMaterialName(GRASSMAT);
7075     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7076         Vector3(-260.0, -100.0+25.0, 0.0))->attachObject(entity);
7077 
7078     entity = mSceneMgr->createEntity("GrassBlades7", "Test_Plane");
7079     entity->setMaterialName(GRASSMAT);
7080     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7081         Vector3(-260.0, -100.0+25.0, -10.0))->attachObject(entity);
7082 
7083     entity = mSceneMgr->createEntity("GrassBlades8", "Test_Plane");
7084     entity->setMaterialName(GRASSMAT);
7085     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7086         Vector3(-260.0, -100.0+25.0, -20.0))->attachObject(entity);
7087 
7088     // Add test plane entities to the scene, alone with other material
7089 
7090     const String GRASSMAT_CUSTOM_DEFAULT_CUSTOM("Examples/GrassBladesAdditiveFloat");
7091     const String GRASSMAT_CUSTOM_NOSPECIAL_CUSTOM("Examples/GrassBladesAdditive");
7092     const String GRASSMAT_ORIG("Examples/GrassBlades");
7093 
7094     entity = mSceneMgr->createEntity("GrassBlades9", "Test_Plane");
7095     entity->setMaterialName(GRASSMAT_CUSTOM_DEFAULT_CUSTOM);
7096     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7097         Vector3(-80.0, -100.0+25.0, -80.0))->attachObject(entity);
7098 
7099     entity = mSceneMgr->createEntity("GrassBlades10", "Test_Plane");
7100     entity->setMaterialName(GRASSMAT_CUSTOM_NOSPECIAL_CUSTOM);
7101     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7102         Vector3(-130.0, -100.0+25.0, -90.0))->attachObject(entity);
7103 
7104     entity = mSceneMgr->createEntity("GrassBlades11", "Test_Plane");
7105     entity->setMaterialName(GRASSMAT_ORIG);
7106     mSceneMgr->getRootSceneNode()->createChildSceneNode(
7107         Vector3(-180.0, -100.0+25.0, -90.0))->attachObject(entity);
7108 
7109     // Position and orient the camera
7110     //mCameraNode->setPosition(-55.0, 40.0, 100.0);
7111     //mCameraNode->lookAt(-10.0, 20.0, -35.0, Node::TS_PARENT);
7112     //mCameraNode->setPosition(-75.0, 30.0, 150.0);
7113     //mCameraNode->lookAt(0.0, 20.0, -35.0, Node::TS_PARENT);
7114     mCameraNode->setPosition(100,50,150);
7115     mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);
7116 
7117     //mSceneMgr->setAmbientLight(ColourValue::Black);
7118     Light* l;
7119 
7120     l = mSceneMgr->createLight("Dir1");
7121     l->setType(Light::LT_DIRECTIONAL);
7122     //l->setAttenuation(5000,1,0,0);
7123     Vector3 dir1(0.0, -0.7, -0.5);
7124     dir1.normalise();
7125     l->setDirection(dir1);
7126     l->setCastShadows(true);
7127 
7128     l->setDiffuseColour(ColourValue(1.0, 1.0, 1.0));
7129 
7130 
7131     mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.2));
7132 
7133     //         l = mSceneMgr->createLight("Spot2");
7134     //         l->setAttenuation(5000,1,0,0);
7135     //         /* // spotlight */
7136     //         l->setType(Light::LT_SPOTLIGHT);
7137     //         l->setSpotlightRange(Degree(30),Degree(45),1.0f);
7138     //
7139     //
7140     //         SceneNode* lightNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
7141     //         lightNode2->attachObject(l);
7142     //         lightNode2->setPosition(-500, 200, 500);
7143     //         lightNode2->lookAt(Vector3(0,-200,0), Node::TS_WORLD);
7144     //lightNode2->setPosition(-75.0, 30.0, 150.0);
7145     //lightNode2->lookAt(Vector3(.0, 20.0, -35.0), Node::TS_WORLD);
7146 
7147 
7148     // addTextureShadowDebugOverlay(1, mSceneMgr);
7149 
7150     // not completely necessary, and can't guarantee determinism easily
7151     //Root::getSingleton().addFrameListener(new GrassListener(mSceneMgr));
7152 
7153 }
7154 //----------------------------------------------------------------------------
7155 //----------------------------------------------------------------------------
7156 
PlayPen_TransparencyMipMaps()7157 PlayPen_TransparencyMipMaps::PlayPen_TransparencyMipMaps()
7158 {
7159     mInfo["Title"] = "PlayPen_TransparencyMipMaps";
7160     mInfo["Description"] = "Tests transparent materials with mipmaps.";
7161     addScreenshotFrame(10);
7162 }
7163 //----------------------------------------------------------------------------
7164 
setupContent()7165 void PlayPen_TransparencyMipMaps::setupContent()
7166 {
7167     MaterialPtr mat = MaterialManager::getSingleton().create("test",
7168                                                              TRANSIENT_RESOURCE_GROUP);
7169     // known png with alpha
7170     Pass* pass = mat->getTechnique(0)->getPass(0);
7171     pass->createTextureUnitState("sdk_logo.png");
7172     pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
7173     // alpha blend
7174     pass->setDepthWriteEnabled(false);
7175 
7176     // alpha reject
7177     //pass->setDepthWriteEnabled(true);
7178     //pass->setAlphaRejectSettings(CMPF_LESS, 128);
7179 
7180     // Define a floor plane mesh
7181     Plane p;
7182     p.normal = Vector3::UNIT_Y;
7183     p.d = 200;
7184     MeshManager::getSingleton().createPlane("FloorPlane",
7185                                             TRANSIENT_RESOURCE_GROUP,
7186                                             p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
7187 
7188     // Create an entity (the floor)
7189     Entity* ent = mSceneMgr->createEntity("floor", "FloorPlane");
7190     ent->setMaterialName("test");
7191     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
7192 
7193     mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
7194     mSceneMgr->setAmbientLight(ColourValue::White);
7195 
7196 
7197     {
7198 
7199         Real alphaLevel = 0.5f;
7200         MaterialPtr alphamat = MaterialManager::getSingleton().create("testy",
7201                                                                       TRANSIENT_RESOURCE_GROUP);
7202         Pass* alphaPass = alphamat->getTechnique(0)->getPass(0);
7203         alphaPass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
7204         alphaPass->setDepthWriteEnabled(false);
7205         TextureUnitState* t = alphaPass->createTextureUnitState();
7206         t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alphaLevel);
7207 
7208         ent = mSceneMgr->createEntity("asd", "ogrehead.mesh");
7209         ent->setMaterialName("testy");
7210         mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
7211 
7212     }
7213 
7214     mCameraNode->setPosition(0,0,1000);
7215 
7216 }
7217 //----------------------------------------------------------------------------
7218 //----------------------------------------------------------------------------
7219 
PlayPen_VertexTexture()7220 PlayPen_VertexTexture::PlayPen_VertexTexture()
7221 {
7222     mInfo["Title"] = "PlayPen_VertexTexture";
7223     mInfo["Description"] = "Tests vertex texture rendering (DX only).";
7224     addScreenshotFrame(10);
7225 }
7226 //----------------------------------------------------------------------------
7227 
setupContent()7228 void PlayPen_VertexTexture::setupContent()
7229 {
7230     //TODO DirectX only right now - add OpenGL.
7231 
7232     Light* l = mSceneMgr->createLight("MainLight");
7233     l->setType(Light::LT_POINT);
7234     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 200, 0))->attachObject(l);
7235 
7236 
7237     // Create single-channel floating point texture, no mips
7238     TexturePtr tex = TextureManager::getSingleton().createManual(
7239         "vertexTexture", TRANSIENT_RESOURCE_GROUP, TEX_TYPE_2D,
7240         128, 128, 0, PF_FLOAT32_R);
7241     float* pData = static_cast<float*>(
7242         tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD));
7243     // write concentric circles into the texture
7244     for (int y  = -64; y < 64; ++y)
7245     {
7246         for (int x = -64; x < 64; ++x)
7247         {
7248 
7249             float val = Math::Sqrt(x*x + y*y);
7250             // repeat every 20 pixels
7251             val = val * Math::TWO_PI / 20.0f;
7252             *pData++ = Math::Sin(val);
7253         }
7254     }
7255     tex->getBuffer()->unlock();
7256 
7257     String progSource =
7258         "void main(\n"
7259         "float4 pos : POSITION,\n"
7260         "float2 uv1 : TEXCOORD0,\n"
7261         "uniform float4x4 world, \n"
7262         "uniform float4x4 viewProj,\n"
7263         "uniform float heightscale,\n"
7264         "uniform sampler2D heightmap,\n"
7265         "out float4 oPos : POSITION,\n"
7266         "out float2 oUv1 : TEXCOORD1,\n"
7267         "out float4 col : COLOR)\n"
7268         "{\n"
7269         "oPos = mul(world, pos);\n"
7270         "// tex2Dlod since no mip\n"
7271         "float4 t = float4(0,0,0,0);\n"
7272         "t.xy = uv1.xy;\n"
7273         "float height = tex2Dlod(heightmap, t);\n"
7274         "oPos.y = oPos.y + (height * heightscale);\n"
7275         "oPos = mul(viewProj, oPos);\n"
7276         "oUv1 = uv1;\n"
7277         "col = float4(1,1,1,1);\n"
7278         "}\n";
7279     HighLevelGpuProgramPtr prog = HighLevelGpuProgramManager::getSingleton().createProgram(
7280         "TestVertexTextureFetch", TRANSIENT_RESOURCE_GROUP,
7281         "hlsl", GPT_VERTEX_PROGRAM);
7282     prog->setSource(progSource);
7283     prog->setParameter("target", "vs_3_0");
7284     prog->setVertexTextureFetchRequired(true);
7285     prog->setParameter("entry_point", "main");
7286     prog->load();
7287 
7288 
7289     MaterialPtr mat = MaterialManager::getSingleton().create("TestVertexTexture",
7290                                                              TRANSIENT_RESOURCE_GROUP);
7291     Pass* pass = mat->getTechnique(0)->getPass(0);
7292     pass->setLightingEnabled(false);
7293     pass->setVertexProgram("TestVertexTextureFetch");
7294     GpuProgramParametersSharedPtr vp = pass->getVertexProgramParameters();
7295     vp->setNamedAutoConstant("world", GpuProgramParameters::ACT_WORLD_MATRIX);
7296     vp->setNamedAutoConstant("viewProj", GpuProgramParameters::ACT_VIEWPROJ_MATRIX);
7297     vp->setNamedConstant("heightscale", 30.0f);
7298     // vertex texture
7299     TextureUnitState* t = pass->createTextureUnitState("vertexTexture");
7300     t->setBindingType(TextureUnitState::BT_VERTEX);
7301     // regular texture
7302     pass->createTextureUnitState("BumpyMetal.jpg");
7303 
7304     Plane plane;
7305     plane.normal = Vector3::UNIT_Y;
7306     plane.d = 100;
7307     // 128 x 128 segment plane
7308     MeshManager::getSingleton().createPlane("Myplane",
7309                                             TRANSIENT_RESOURCE_GROUP, plane,
7310                                             1500,1500,128,128,true,1,1,1,Vector3::UNIT_Z);
7311     Entity* pPlaneEnt;
7312     pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
7313     pPlaneEnt->setMaterialName("TestVertexTexture");
7314     pPlaneEnt->setCastShadows(false);
7315     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
7316 
7317 
7318 }
7319 //----------------------------------------------------------------------------
7320 //----------------------------------------------------------------------------
7321 
PlayPen_ViewportNoShadows()7322 PlayPen_ViewportNoShadows::PlayPen_ViewportNoShadows()
7323 {
7324     mInfo["Title"] = "PlayPen_ViewportNoShadows";
7325     mInfo["Description"] = "Tests disabling shadows for a viewport.";
7326     addScreenshotFrame(10);
7327 }
7328 //----------------------------------------------------------------------------
7329 
setupContent()7330 void PlayPen_ViewportNoShadows::setupContent()
7331 {
7332     mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
7333 
7334     // Setup lighting
7335     mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
7336     Light* light = mSceneMgr->createLight("MainLight");
7337     light->setType(Light::LT_DIRECTIONAL);
7338     Vector3 dir(-1, -1, 0.5);
7339     dir.normalise();
7340     light->setDirection(dir);
7341 
7342     // Create a skydome
7343     //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
7344 
7345     // Create a floor plane mesh
7346     Plane plane(Vector3::UNIT_Y, 0.0);
7347     MeshManager::getSingleton().createPlane(
7348         "FloorPlane", TRANSIENT_RESOURCE_GROUP,
7349         plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z);
7350 
7351 
7352     // Add a floor to the scene
7353     Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane");
7354     entity->setMaterialName("Examples/RustySteel");
7355     mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
7356     entity->setCastShadows(false);
7357 
7358     // Add the mandatory ogre head
7359     entity = mSceneMgr->createEntity("head", "ogrehead.mesh");
7360     mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity);
7361 
7362     // Position and orient the camera
7363     mCameraNode->setPosition(-100.0, 50.0, 90.0);
7364     mCameraNode->lookAt(Vector3(0.0, 10.0, -35.0), Node::TS_WORLD);
7365 
7366     // Add an additional viewport on top of the other one
7367     Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3);
7368     pip->setShadowsEnabled(false);
7369 
7370 }
7371 //----------------------------------------------------------------------------
7372 //----------------------------------------------------------------------------
7373 
PlayPen_WindowedViewportMode()7374 PlayPen_WindowedViewportMode::PlayPen_WindowedViewportMode()
7375 {
7376     mInfo["Title"] = "PlayPen_WindowedViewportMode";
7377     mInfo["Description"] = "Tests windowed viewport.";
7378     addScreenshotFrame(10);
7379 }
7380 //----------------------------------------------------------------------------
7381 
setupContent()7382 void PlayPen_WindowedViewportMode::setupContent()
7383 {
7384     Ogre::SceneNode* mTestNode[5];
7385 
7386     // Set ambient light
7387     mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
7388 
7389     // Create a point light
7390     Light* l = mSceneMgr->createLight("MainLight");
7391     l->setType(Light::LT_DIRECTIONAL);
7392     l->setDirection(-Vector3::UNIT_Y);
7393 
7394     mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
7395 
7396     Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
7397     mTestNode[0]->attachObject( pEnt );
7398 
7399     mCamera->setWindow(0,0,0.5,0.5);
7400 
7401     mCameraNode->setPosition(0,0,125);
7402 }
7403 
7404 //-----------------------------------------------------------------------
7405 //-----------------------------------------------------------------------
7406 
addTextureDebugOverlay(const Ogre::String & texname,size_t i)7407 void addTextureDebugOverlay(const Ogre::String& texname, size_t i)
7408 {
7409     Ogre::Overlay* debugOverlay = Ogre::OverlayManager::getSingleton().getByName("Core/DebugOverlay");
7410 
7411     if(!debugOverlay)
7412         debugOverlay = Ogre::OverlayManager::getSingleton().create("Core/DebugOverlay");
7413 
7414     debugOverlay->show();
7415 
7416     // Set up a debug panel to display the shadow
7417     Ogre::MaterialPtr debugMat = Ogre::MaterialManager::getSingleton().create(
7418         "Ogre/DebugTexture" + Ogre::StringConverter::toString(i),
7419         "VisualTestTransient");
7420     debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
7421     Ogre::TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(texname);
7422     t->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
7423     //t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("spot_shadow_fade.png");
7424     //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
7425     //t->setColourOperation(LBO_ADD);
7426 
7427 
7428     Ogre::OverlayContainer* debugPanel = (Ogre::OverlayContainer*)
7429         (Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + Ogre::StringConverter::toString(i)));
7430     debugPanel->_setPosition(0.8, i*0.25);
7431     debugPanel->_setDimensions(0.2, 0.24);
7432     debugPanel->setMaterialName(debugMat->getName());
7433     debugOverlay->add2D(debugPanel);
7434 
7435 }
7436 //-----------------------------------------------------------------------
7437 
clearDebugTextureOverlays()7438 void clearDebugTextureOverlays()
7439 {
7440     Ogre::Overlay* debugOverlay = Ogre::OverlayManager::getSingleton().getByName("Core/DebugOverlay");
7441 
7442     if(debugOverlay)
7443         Ogre::OverlayManager::getSingleton().destroy("Core/DebugOverlay");
7444     //debugOverlay->hide();
7445 
7446     for(int i = 0; i < 10; ++i)
7447     {
7448         if(Ogre::OverlayManager::getSingleton().hasOverlayElement(
7449             "Ogre/DebugTexPanel" + Ogre::StringConverter::toString(i)))
7450         {
7451             OverlayManager::getSingleton().destroyOverlayElement(
7452                 "Ogre/DebugTexPanel" + Ogre::StringConverter::toString(i));
7453             MaterialManager::getSingleton().remove("Ogre/DebugTexture" + StringConverter::toString(i), "VisualTestTransient");
7454         }
7455     }
7456 }
7457 //-----------------------------------------------------------------------
7458 
addTextureDebugOverlay(Ogre::TexturePtr tex,size_t i)7459 void addTextureDebugOverlay(Ogre::TexturePtr tex, size_t i)
7460 {
7461     addTextureDebugOverlay(tex->getName(), i);
7462 }
7463 //-----------------------------------------------------------------------
7464 
addTextureShadowDebugOverlay(size_t num,Ogre::SceneManager * mgr)7465 void addTextureShadowDebugOverlay(size_t num, Ogre::SceneManager* mgr)
7466 {
7467     for (size_t i = 0; i < num; ++i)
7468     {
7469         Ogre::TexturePtr shadowTex = mgr->getShadowTexture(i);
7470         addTextureDebugOverlay(shadowTex, i);
7471     }
7472 }
7473 //-----------------------------------------------------------------------
7474