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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | /*
|
---|
26 | -----------------------------------------------------------------------------
|
---|
27 | Filename: PlayPen.cpp
|
---|
28 | Description: Somewhere to play in the sand...
|
---|
29 | -----------------------------------------------------------------------------
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "ExampleApplication.h"
|
---|
33 | #include "OgreProgressiveMesh.h"
|
---|
34 | #include "OgreEdgeListBuilder.h"
|
---|
35 |
|
---|
36 | /*
|
---|
37 | #include "OgreNoMemoryMacros.h"
|
---|
38 | #include <ode/odecpp.h>
|
---|
39 | #include <ode/odecpp_collision.h>
|
---|
40 | #include "OgreMemoryMacros.h"
|
---|
41 | */
|
---|
42 |
|
---|
43 | /*
|
---|
44 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
45 | #include "OgreNoMemoryMacros.h"
|
---|
46 | #include <crtdbg.h>
|
---|
47 | #endi*/
|
---|
48 |
|
---|
49 | #define NUM_TEST_NODES 5
|
---|
50 | SceneNode* mTestNode[NUM_TEST_NODES] = {0,0,0,0,0};
|
---|
51 | SceneNode* mLightNode = 0;
|
---|
52 | SceneNode* mRootNode;
|
---|
53 | SceneNode* camNode;
|
---|
54 | Entity* mEntity;
|
---|
55 | Real animTime = 0;
|
---|
56 | Animation* mAnim = 0;
|
---|
57 | std::vector<AnimationState*> mAnimStateList;
|
---|
58 | AnimationState* mAnimState = 0;
|
---|
59 | Overlay* mpOverlay;
|
---|
60 | Entity* pPlaneEnt;
|
---|
61 | Camera* testCam = 0;
|
---|
62 | Camera* reflectCam = 0;
|
---|
63 | SceneNode* camPlaneNode[6];
|
---|
64 | Light* mLight;
|
---|
65 | IntersectionSceneQuery* intersectionQuery = 0;
|
---|
66 | RaySceneQuery* rayQuery = 0;
|
---|
67 | Entity* ball = 0;
|
---|
68 | Vector3 ballVector;
|
---|
69 | bool testreload = false;
|
---|
70 | Plane plane;
|
---|
71 |
|
---|
72 |
|
---|
73 | // Hacky globals
|
---|
74 | GpuProgramParametersSharedPtr fragParams;
|
---|
75 | GpuProgramParametersSharedPtr vertParams;
|
---|
76 | MaterialPtr skin;
|
---|
77 | Frustum* frustum = 0;
|
---|
78 | Camera* theCam;
|
---|
79 |
|
---|
80 | class RefractionTextureListener : public RenderTargetListener
|
---|
81 | {
|
---|
82 | public:
|
---|
83 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
84 | {
|
---|
85 | pPlaneEnt->setVisible(false);
|
---|
86 |
|
---|
87 | }
|
---|
88 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
89 | {
|
---|
90 | pPlaneEnt->setVisible(true);
|
---|
91 | }
|
---|
92 |
|
---|
93 | };
|
---|
94 | class ReflectionTextureListener : public RenderTargetListener
|
---|
95 | {
|
---|
96 | public:
|
---|
97 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
98 | {
|
---|
99 | static Plane reflectPlane(Vector3::UNIT_Y, -100);
|
---|
100 | pPlaneEnt->setVisible(false);
|
---|
101 | theCam->enableReflection(reflectPlane);
|
---|
102 |
|
---|
103 | }
|
---|
104 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
105 | {
|
---|
106 | pPlaneEnt->setVisible(true);
|
---|
107 | theCam->disableReflection();
|
---|
108 | }
|
---|
109 |
|
---|
110 | };
|
---|
111 |
|
---|
112 | class UberSimpleFrameListener : public FrameListener
|
---|
113 | {
|
---|
114 | protected:
|
---|
115 | InputReader* mInputDevice;
|
---|
116 |
|
---|
117 | public:
|
---|
118 | UberSimpleFrameListener(RenderWindow* win, Camera* cam)
|
---|
119 | {
|
---|
120 | mInputDevice = PlatformManager::getSingleton().createInputReader();
|
---|
121 | mInputDevice->initialise(win,true, true);
|
---|
122 | }
|
---|
123 | ~UberSimpleFrameListener()
|
---|
124 | {
|
---|
125 | PlatformManager::getSingleton().destroyInputReader( mInputDevice );
|
---|
126 | }
|
---|
127 |
|
---|
128 | bool frameStarted(const FrameEvent& evt)
|
---|
129 | {
|
---|
130 | mInputDevice->capture();
|
---|
131 | if (mInputDevice->isKeyDown(KC_ESCAPE))
|
---|
132 | {
|
---|
133 | return false;
|
---|
134 | }
|
---|
135 | return true;
|
---|
136 |
|
---|
137 | }
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | class PlayPenListener : public ExampleFrameListener
|
---|
143 | {
|
---|
144 | protected:
|
---|
145 | SceneManager* mSceneMgr;
|
---|
146 | public:
|
---|
147 | PlayPenListener(SceneManager* mgr, RenderWindow* win, Camera* cam)
|
---|
148 | : ExampleFrameListener(win, cam),mSceneMgr(mgr)
|
---|
149 | {
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | bool frameStarted(const FrameEvent& evt)
|
---|
154 | {
|
---|
155 |
|
---|
156 | if (!vertParams.isNull())
|
---|
157 | {
|
---|
158 | Matrix4 scaleMat = Matrix4::IDENTITY;
|
---|
159 | scaleMat[0][0] = 0.5f;
|
---|
160 | scaleMat[1][1] = -0.5f;
|
---|
161 | scaleMat[2][2] = 0.5f;
|
---|
162 | scaleMat[0][3] = 0.5f;
|
---|
163 | scaleMat[1][3] = 0.5f;
|
---|
164 | scaleMat[2][3] = 0.5f;
|
---|
165 | Matrix4 mat = frustum->getProjectionMatrix() *
|
---|
166 | frustum->getViewMatrix();
|
---|
167 |
|
---|
168 |
|
---|
169 | mat = scaleMat * mat;
|
---|
170 |
|
---|
171 | vertParams->setNamedConstant("texViewProjMatrix", mat);
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | static float reloadtime = 10.0f;
|
---|
179 | if (testreload)
|
---|
180 | {
|
---|
181 | reloadtime -= evt.timeSinceLastFrame;
|
---|
182 | if (reloadtime <= 0)
|
---|
183 | {
|
---|
184 | Entity* e = mSceneMgr->getEntity("1");
|
---|
185 | e->getParentSceneNode()->detachObject("1");
|
---|
186 | e = mSceneMgr->getEntity("2");
|
---|
187 | e->getParentSceneNode()->detachObject("2");
|
---|
188 | mSceneMgr->removeAllEntities();
|
---|
189 | ResourceGroupManager::getSingleton().unloadResourceGroup("Sinbad");
|
---|
190 | ResourceGroupManager::getSingleton().loadResourceGroup("Sinbad");
|
---|
191 |
|
---|
192 | testreload = false;
|
---|
193 |
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 | bool ret = ExampleFrameListener::frameStarted(evt);
|
---|
200 |
|
---|
201 | // Sync reflection cam
|
---|
202 | if (reflectCam)
|
---|
203 | {
|
---|
204 | reflectCam->setOrientation(mCamera->getOrientation());
|
---|
205 | reflectCam->setPosition(mCamera->getPosition());
|
---|
206 | }
|
---|
207 |
|
---|
208 | return ret;
|
---|
209 |
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | bool frameEnded(const FrameEvent& evt)
|
---|
214 | {
|
---|
215 |
|
---|
216 |
|
---|
217 |
|
---|
218 | // local just to stop toggles flipping too fast
|
---|
219 | static Real timeUntilNextToggle = 0;
|
---|
220 | static bool animate = true;
|
---|
221 | static bool rotate = false;
|
---|
222 |
|
---|
223 | static bool firstTime = true;
|
---|
224 |
|
---|
225 | if (!firstTime)
|
---|
226 | {
|
---|
227 | //mCamera->yaw(20);
|
---|
228 | }
|
---|
229 | firstTime = false;
|
---|
230 |
|
---|
231 | if (timeUntilNextToggle >= 0)
|
---|
232 | timeUntilNextToggle -= evt.timeSinceLastFrame;
|
---|
233 |
|
---|
234 | static bool mWireframe = false;
|
---|
235 | if (mInputDevice->isKeyDown(KC_G) && timeUntilNextToggle <= 0)
|
---|
236 | {
|
---|
237 | mWireframe = !mWireframe;
|
---|
238 | if (mWireframe)
|
---|
239 | {
|
---|
240 | mCamera->setDetailLevel(SDL_WIREFRAME);
|
---|
241 | }
|
---|
242 | else
|
---|
243 | {
|
---|
244 | mCamera->setDetailLevel(SDL_SOLID);
|
---|
245 | }
|
---|
246 | timeUntilNextToggle = 0.5;
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Core/StatsBlockBorder/Up");
|
---|
251 | mat->setDepthCheckEnabled(true);
|
---|
252 | mat->setDepthWriteEnabled(true);
|
---|
253 |
|
---|
254 | for (int i = 0; i < NUM_TEST_NODES; ++i)
|
---|
255 | {
|
---|
256 | if (mTestNode[i] && rotate)
|
---|
257 | mTestNode[i]->yaw(Degree(evt.timeSinceLastFrame * 15));
|
---|
258 | }
|
---|
259 |
|
---|
260 | if (mAnimState && animate)
|
---|
261 | mAnimState->addTime(evt.timeSinceLastFrame);
|
---|
262 | std::vector<AnimationState*>::iterator animi;
|
---|
263 | for (animi = mAnimStateList.begin(); animi != mAnimStateList.end(); ++animi)
|
---|
264 | {
|
---|
265 | (*animi)->addTime(evt.timeSinceLastFrame);
|
---|
266 | }
|
---|
267 |
|
---|
268 | if (mInputDevice->isKeyDown(KC_R) && timeUntilNextToggle <= 0)
|
---|
269 | {
|
---|
270 | rotate = !rotate;
|
---|
271 | timeUntilNextToggle = 0.5;
|
---|
272 | }
|
---|
273 | if (mInputDevice->isKeyDown(KC_1) && timeUntilNextToggle <= 0)
|
---|
274 | {
|
---|
275 | animate = !animate;
|
---|
276 | timeUntilNextToggle = 0.5;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | if (rayQuery)
|
---|
281 | {
|
---|
282 | static Ray camRay;
|
---|
283 | static std::set<Entity*> lastEnts;
|
---|
284 | camRay.setOrigin(mCamera->getPosition());
|
---|
285 | camRay.setDirection(mCamera->getDirection());
|
---|
286 | rayQuery->setRay(camRay);
|
---|
287 |
|
---|
288 | // Reset last set
|
---|
289 | for (std::set<Entity*>::iterator lasti = lastEnts.begin();
|
---|
290 | lasti != lastEnts.end(); ++lasti)
|
---|
291 | {
|
---|
292 | (*lasti)->setMaterialName("Examples/OgreLogo");
|
---|
293 | }
|
---|
294 | lastEnts.clear();
|
---|
295 |
|
---|
296 |
|
---|
297 | RaySceneQueryResult& results = rayQuery->execute();
|
---|
298 | for (RaySceneQueryResult::iterator mov = results.begin();
|
---|
299 | mov != results.end(); ++mov)
|
---|
300 | {
|
---|
301 | if (mov->movable)
|
---|
302 | {
|
---|
303 | if (mov->movable->getMovableType() == "Entity")
|
---|
304 | {
|
---|
305 | Entity* ent = static_cast<Entity*>(mov->movable);
|
---|
306 | lastEnts.insert(ent);
|
---|
307 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
308 |
|
---|
309 | }
|
---|
310 | }
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (intersectionQuery)
|
---|
315 | {
|
---|
316 | static std::set<Entity*> lastEnts;
|
---|
317 |
|
---|
318 | // Reset last set
|
---|
319 | for (std::set<Entity*>::iterator lasti = lastEnts.begin();
|
---|
320 | lasti != lastEnts.end(); ++lasti)
|
---|
321 | {
|
---|
322 | (*lasti)->setMaterialName("Examples/OgreLogo");
|
---|
323 | }
|
---|
324 | lastEnts.clear();
|
---|
325 |
|
---|
326 |
|
---|
327 | IntersectionSceneQueryResult& results = intersectionQuery->execute();
|
---|
328 | for (SceneQueryMovableIntersectionList::iterator mov = results.movables2movables.begin();
|
---|
329 | mov != results.movables2movables.end(); ++mov)
|
---|
330 | {
|
---|
331 | SceneQueryMovableObjectPair& thepair = *mov;
|
---|
332 | if (thepair.first->getMovableType() == "Entity")
|
---|
333 | {
|
---|
334 | Entity* ent = static_cast<Entity*>(thepair.first);
|
---|
335 | lastEnts.insert(ent);
|
---|
336 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
337 |
|
---|
338 | }
|
---|
339 | if (thepair.second->getMovableType() == "Entity")
|
---|
340 | {
|
---|
341 | Entity* ent = static_cast<Entity*>(thepair.second);
|
---|
342 | lastEnts.insert(ent);
|
---|
343 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
344 |
|
---|
345 | }
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | /*
|
---|
350 | if (mInputDevice->isKeyDown(KC_V) && timeUntilNextToggle <= 0)
|
---|
351 | {
|
---|
352 | static bool isVP = false;
|
---|
353 | if (!isVP)
|
---|
354 | {
|
---|
355 | skin->getTechnique(0)->getPass(0)->setVertexProgram("SimpleVP");
|
---|
356 | skin->getTechnique(0)->getPass(0)->setVertexProgramParameters(vertParams);
|
---|
357 | isVP = true;
|
---|
358 | }
|
---|
359 | else
|
---|
360 | {
|
---|
361 | skin->getTechnique(0)->getPass(0)->setVertexProgram("");
|
---|
362 | isVP = false;
|
---|
363 | }
|
---|
364 | timeUntilNextToggle = 0.5;
|
---|
365 | }
|
---|
366 | */
|
---|
367 |
|
---|
368 | if (mInputDevice->isKeyDown(KC_P))
|
---|
369 | {
|
---|
370 | mTestNode[0]->yaw(Degree(-evt.timeSinceLastFrame * 30));
|
---|
371 | }
|
---|
372 | if (mInputDevice->isKeyDown(KC_O))
|
---|
373 | {
|
---|
374 | mTestNode[0]->yaw(Degree(evt.timeSinceLastFrame * 30));
|
---|
375 | }
|
---|
376 | if (mInputDevice->isKeyDown(KC_K))
|
---|
377 | {
|
---|
378 | mTestNode[0]->roll(Degree(-evt.timeSinceLastFrame * 30));
|
---|
379 | }
|
---|
380 | if (mInputDevice->isKeyDown(KC_L))
|
---|
381 | {
|
---|
382 | mTestNode[0]->roll(Degree(evt.timeSinceLastFrame * 30));
|
---|
383 | }
|
---|
384 | if (mInputDevice->isKeyDown(KC_U))
|
---|
385 | {
|
---|
386 | mTestNode[0]->translate(0,0,-evt.timeSinceLastFrame * 30);
|
---|
387 | }
|
---|
388 | if (mInputDevice->isKeyDown(KC_J))
|
---|
389 | {
|
---|
390 | mTestNode[0]->translate(0,0,evt.timeSinceLastFrame * 30);
|
---|
391 | }
|
---|
392 | if (mInputDevice->isKeyDown(KC_M))
|
---|
393 | {
|
---|
394 | mTestNode[0]->translate(0,evt.timeSinceLastFrame * 30, 0);
|
---|
395 | }
|
---|
396 | if (mInputDevice->isKeyDown(KC_N))
|
---|
397 | {
|
---|
398 | mTestNode[0]->translate(0,-evt.timeSinceLastFrame * 30, 0);
|
---|
399 | }
|
---|
400 |
|
---|
401 | if (mInputDevice->isKeyDown(KC_0) && timeUntilNextToggle <= 0)
|
---|
402 | {
|
---|
403 | mAnimState->setEnabled(!mAnimState->getEnabled());
|
---|
404 | timeUntilNextToggle = 0.5;
|
---|
405 | }
|
---|
406 |
|
---|
407 |
|
---|
408 | /** Hack to test frustum vols
|
---|
409 | if (testCam)
|
---|
410 | {
|
---|
411 | // reposition the camera planes
|
---|
412 | PlaneBoundedVolumeList volList = mLight->_getFrustumClipVolumes(testCam);
|
---|
413 |
|
---|
414 | PlaneBoundedVolume& vol = volList[1];
|
---|
415 | for (int p = 0; p < 6; ++p)
|
---|
416 | {
|
---|
417 | Plane& pl = vol.planes[p];
|
---|
418 | camPlaneNode[p]->setOrientation(Vector3::UNIT_Z.getRotationTo(pl.normal));
|
---|
419 | camPlaneNode[p]->setPosition(0,0,0);
|
---|
420 | camPlaneNode[p]->translate(0,0, pl.d, Node::TS_LOCAL);
|
---|
421 | }
|
---|
422 |
|
---|
423 | vol.intersects(mEntity->getWorldBoundingBox());
|
---|
424 | }
|
---|
425 | */
|
---|
426 |
|
---|
427 | // Print camera details
|
---|
428 | mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " +
|
---|
429 | "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
|
---|
430 | return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
|
---|
431 |
|
---|
432 |
|
---|
433 | }
|
---|
434 |
|
---|
435 |
|
---|
436 | };
|
---|
437 |
|
---|
438 | class PlayPenApplication : public ExampleApplication
|
---|
439 | {
|
---|
440 | protected:
|
---|
441 | RefractionTextureListener mRefractionListener;
|
---|
442 | ReflectionTextureListener mReflectionListener;
|
---|
443 | public:
|
---|
444 | PlayPenApplication() {
|
---|
445 |
|
---|
446 |
|
---|
447 | }
|
---|
448 |
|
---|
449 | ~PlayPenApplication()
|
---|
450 | {
|
---|
451 | if (frustum)
|
---|
452 | delete frustum;
|
---|
453 | }
|
---|
454 | protected:
|
---|
455 |
|
---|
456 | void chooseSceneManager(void)
|
---|
457 | {
|
---|
458 | mSceneMgr = mRoot->getSceneManager( ST_GENERIC );
|
---|
459 | //mSceneMgr = mRoot->getSceneManager(ST_INTERIOR);
|
---|
460 |
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | void createTestBugPlaneMesh3Streams(const String& testMeshName)
|
---|
465 | {
|
---|
466 | Plane plane(Vector3::UNIT_Z, 0);
|
---|
467 | Real width = 258;
|
---|
468 | Real height = 171;
|
---|
469 | int xsegments = 50;
|
---|
470 | int ysegments = 50;
|
---|
471 | Real xTile = 1.0f;
|
---|
472 | Real yTile = 1.0f;
|
---|
473 | const Vector3& upVector = Vector3::UNIT_Y;
|
---|
474 | MeshPtr pMesh = MeshManager::getSingleton().createManual(testMeshName,
|
---|
475 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
476 | SubMesh *pSub = pMesh->createSubMesh();
|
---|
477 |
|
---|
478 | // Set up vertex data
|
---|
479 | // Use a single shared buffer
|
---|
480 | pMesh->sharedVertexData = new VertexData();
|
---|
481 | VertexData* vertexData = pMesh->sharedVertexData;
|
---|
482 | // Set up Vertex Declaration
|
---|
483 | VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
|
---|
484 | // We always need positions
|
---|
485 | vertexDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
486 | vertexDecl->addElement(1, 0, VET_FLOAT3, VES_NORMAL);
|
---|
487 | vertexDecl->addElement(2, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
|
---|
488 |
|
---|
489 | vertexData->vertexCount = (xsegments + 1) * (ysegments + 1);
|
---|
490 |
|
---|
491 | // Allocate vertex buffers
|
---|
492 | HardwareVertexBufferSharedPtr vbufpos =
|
---|
493 | HardwareBufferManager::getSingleton().
|
---|
494 | createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount,
|
---|
495 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
496 | HardwareVertexBufferSharedPtr vbufnorm =
|
---|
497 | HardwareBufferManager::getSingleton().
|
---|
498 | createVertexBuffer(vertexDecl->getVertexSize(1), vertexData->vertexCount,
|
---|
499 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
500 | HardwareVertexBufferSharedPtr vbuftex =
|
---|
501 | HardwareBufferManager::getSingleton().
|
---|
502 | createVertexBuffer(vertexDecl->getVertexSize(2), vertexData->vertexCount,
|
---|
503 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
504 |
|
---|
505 | // Set up the binding (one source only)
|
---|
506 | VertexBufferBinding* binding = vertexData->vertexBufferBinding;
|
---|
507 | binding->setBinding(0, vbufpos);
|
---|
508 | binding->setBinding(1, vbufnorm);
|
---|
509 | binding->setBinding(2, vbuftex);
|
---|
510 |
|
---|
511 | // Work out the transform required
|
---|
512 | // Default orientation of plane is normal along +z, distance 0
|
---|
513 | Matrix4 xlate, xform, rot;
|
---|
514 | Matrix3 rot3;
|
---|
515 | xlate = rot = Matrix4::IDENTITY;
|
---|
516 | // Determine axes
|
---|
517 | Vector3 zAxis, yAxis, xAxis;
|
---|
518 | zAxis = plane.normal;
|
---|
519 | zAxis.normalise();
|
---|
520 | yAxis = upVector;
|
---|
521 | yAxis.normalise();
|
---|
522 | xAxis = yAxis.crossProduct(zAxis);
|
---|
523 |
|
---|
524 | rot3.FromAxes(xAxis, yAxis, zAxis);
|
---|
525 | rot = rot3;
|
---|
526 |
|
---|
527 | // Set up standard xform from origin
|
---|
528 | xlate.setTrans(plane.normal * -plane.d);
|
---|
529 |
|
---|
530 | // concatenate
|
---|
531 | xform = xlate * rot;
|
---|
532 |
|
---|
533 | // Generate vertex data
|
---|
534 | // Lock the whole buffer
|
---|
535 | float* pPos = static_cast<float*>(
|
---|
536 | vbufpos->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
537 | float* pNorm = static_cast<float*>(
|
---|
538 | vbufnorm->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
539 | float* pTex = static_cast<float*>(
|
---|
540 | vbuftex->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
541 | Real xSpace = width / xsegments;
|
---|
542 | Real ySpace = height / ysegments;
|
---|
543 | Real halfWidth = width / 2;
|
---|
544 | Real halfHeight = height / 2;
|
---|
545 | Real xTex = (1.0f * xTile) / xsegments;
|
---|
546 | Real yTex = (1.0f * yTile) / ysegments;
|
---|
547 | Vector3 vec;
|
---|
548 | Vector3 min, max;
|
---|
549 | Real maxSquaredLength;
|
---|
550 | bool firstTime = true;
|
---|
551 |
|
---|
552 | for (int y = 0; y < ysegments + 1; ++y)
|
---|
553 | {
|
---|
554 | for (int x = 0; x < xsegments + 1; ++x)
|
---|
555 | {
|
---|
556 | // Work out centered on origin
|
---|
557 | vec.x = (x * xSpace) - halfWidth;
|
---|
558 | vec.y = (y * ySpace) - halfHeight;
|
---|
559 | vec.z = 0.0f;
|
---|
560 | // Transform by orientation and distance
|
---|
561 | vec = xform * vec;
|
---|
562 | // Assign to geometry
|
---|
563 | *pPos++ = vec.x;
|
---|
564 | *pPos++ = vec.y;
|
---|
565 | *pPos++ = vec.z;
|
---|
566 |
|
---|
567 | // Build bounds as we go
|
---|
568 | if (firstTime)
|
---|
569 | {
|
---|
570 | min = vec;
|
---|
571 | max = vec;
|
---|
572 | maxSquaredLength = vec.squaredLength();
|
---|
573 | firstTime = false;
|
---|
574 | }
|
---|
575 | else
|
---|
576 | {
|
---|
577 | min.makeFloor(vec);
|
---|
578 | max.makeCeil(vec);
|
---|
579 | maxSquaredLength = std::max(maxSquaredLength, vec.squaredLength());
|
---|
580 | }
|
---|
581 |
|
---|
582 | // Default normal is along unit Z
|
---|
583 | vec = Vector3::UNIT_Z;
|
---|
584 | // Rotate
|
---|
585 | vec = rot * vec;
|
---|
586 |
|
---|
587 | *pNorm++ = vec.x;
|
---|
588 | *pNorm++ = vec.y;
|
---|
589 | *pNorm++ = vec.z;
|
---|
590 |
|
---|
591 | *pTex++ = x * xTex;
|
---|
592 | *pTex++ = 1 - (y * yTex);
|
---|
593 |
|
---|
594 |
|
---|
595 | } // x
|
---|
596 | } // y
|
---|
597 |
|
---|
598 | // Unlock
|
---|
599 | vbufpos->unlock();
|
---|
600 | vbufnorm->unlock();
|
---|
601 | vbuftex->unlock();
|
---|
602 | // Generate face list
|
---|
603 | pSub->useSharedVertices = true;
|
---|
604 | //tesselate2DMesh(pSub, xsegments + 1, ysegments + 1, false, indexBufferUsage, indexShadowBuffer);
|
---|
605 | SubMesh* sm = pSub;
|
---|
606 | int meshWidth = xsegments + 1;
|
---|
607 | int meshHeight = ysegments + 1;
|
---|
608 | bool doubleSided = false;
|
---|
609 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY;
|
---|
610 | bool indexShadowBuffer = true;
|
---|
611 | // The mesh is built, just make a list of indexes to spit out the triangles
|
---|
612 | int vInc, uInc, v, u, iterations;
|
---|
613 | int vCount, uCount;
|
---|
614 |
|
---|
615 | if (doubleSided)
|
---|
616 | {
|
---|
617 | iterations = 2;
|
---|
618 | vInc = 1;
|
---|
619 | v = 0; // Start with front
|
---|
620 | }
|
---|
621 | else
|
---|
622 | {
|
---|
623 | iterations = 1;
|
---|
624 | vInc = 1;
|
---|
625 | v = 0;
|
---|
626 | }
|
---|
627 |
|
---|
628 | // Allocate memory for faces
|
---|
629 | // Num faces, width*height*2 (2 tris per square), index count is * 3 on top
|
---|
630 | sm->indexData->indexCount = (meshWidth-1) * (meshHeight-1) * 2 * iterations * 3;
|
---|
631 | sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
|
---|
632 | createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
|
---|
633 | sm->indexData->indexCount, indexBufferUsage, indexShadowBuffer);
|
---|
634 |
|
---|
635 | int v1, v2, v3;
|
---|
636 | //bool firstTri = true;
|
---|
637 | HardwareIndexBufferSharedPtr ibuf = sm->indexData->indexBuffer;
|
---|
638 | // Lock the whole buffer
|
---|
639 | unsigned short* pIndexes = static_cast<unsigned short*>(
|
---|
640 | ibuf->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
641 |
|
---|
642 | while (iterations--)
|
---|
643 | {
|
---|
644 | // Make tris in a zigzag pattern (compatible with strips)
|
---|
645 | u = 0;
|
---|
646 | uInc = 1; // Start with moving +u
|
---|
647 |
|
---|
648 | vCount = meshHeight - 1;
|
---|
649 | while (vCount--)
|
---|
650 | {
|
---|
651 | uCount = meshWidth - 1;
|
---|
652 | while (uCount--)
|
---|
653 | {
|
---|
654 | // First Tri in cell
|
---|
655 | // -----------------
|
---|
656 | v1 = ((v + vInc) * meshWidth) + u;
|
---|
657 | v2 = (v * meshWidth) + u;
|
---|
658 | v3 = ((v + vInc) * meshWidth) + (u + uInc);
|
---|
659 | // Output indexes
|
---|
660 | *pIndexes++ = v1;
|
---|
661 | *pIndexes++ = v2;
|
---|
662 | *pIndexes++ = v3;
|
---|
663 | // Second Tri in cell
|
---|
664 | // ------------------
|
---|
665 | v1 = ((v + vInc) * meshWidth) + (u + uInc);
|
---|
666 | v2 = (v * meshWidth) + u;
|
---|
667 | v3 = (v * meshWidth) + (u + uInc);
|
---|
668 | // Output indexes
|
---|
669 | *pIndexes++ = v1;
|
---|
670 | *pIndexes++ = v2;
|
---|
671 | *pIndexes++ = v3;
|
---|
672 |
|
---|
673 | // Next column
|
---|
674 | u += uInc;
|
---|
675 | }
|
---|
676 | // Next row
|
---|
677 | v += vInc;
|
---|
678 | u = 0;
|
---|
679 |
|
---|
680 |
|
---|
681 | }
|
---|
682 |
|
---|
683 | // Reverse vInc for double sided
|
---|
684 | v = meshHeight - 1;
|
---|
685 | vInc = -vInc;
|
---|
686 |
|
---|
687 | }
|
---|
688 | // Unlock
|
---|
689 | ibuf->unlock();
|
---|
690 |
|
---|
691 | //pMesh->_updateBounds();
|
---|
692 | pMesh->_setBounds(AxisAlignedBox(min, max));
|
---|
693 | pMesh->_setBoundingSphereRadius(Math::Sqrt(maxSquaredLength));
|
---|
694 | // load
|
---|
695 | pMesh->load();
|
---|
696 | pMesh->touch();
|
---|
697 | }
|
---|
698 |
|
---|
699 | void stressTestStaticGeometry(void)
|
---|
700 | {
|
---|
701 |
|
---|
702 | // Set ambient light
|
---|
703 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
704 |
|
---|
705 | // Create a point light
|
---|
706 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
707 | l->setType(Light::LT_DIRECTIONAL);
|
---|
708 | Vector3 dir(1, -1, -1.5);
|
---|
709 | dir.normalise();
|
---|
710 | l->setDirection(dir);
|
---|
711 | l->setDiffuseColour(1.0, 0.7, 0.0);
|
---|
712 |
|
---|
713 |
|
---|
714 | Plane plane;
|
---|
715 | plane.normal = Vector3::UNIT_Y;
|
---|
716 | plane.d = 0;
|
---|
717 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
718 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
719 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
720 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
721 | pPlaneEnt->setMaterialName("Examples/GrassFloor");
|
---|
722 | pPlaneEnt->setCastShadows(false);
|
---|
723 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
724 |
|
---|
725 | Vector3 min(-2000,0,-2000);
|
---|
726 | Vector3 max(2000,0,2000);
|
---|
727 |
|
---|
728 |
|
---|
729 | Entity* e = mSceneMgr->createEntity("1", "ogrehead.mesh");
|
---|
730 | StaticGeometry* s = 0;
|
---|
731 |
|
---|
732 | unsigned int count = 10;
|
---|
733 | while(count--)
|
---|
734 | {
|
---|
735 | if(s) mSceneMgr->removeStaticGeometry(s);
|
---|
736 | s = mSceneMgr->createStaticGeometry("bing");
|
---|
737 |
|
---|
738 | s->addEntity(e, Vector3(100, 100, 100));
|
---|
739 |
|
---|
740 | s->build();
|
---|
741 | }
|
---|
742 |
|
---|
743 |
|
---|
744 | //s->setRenderingDistance(1000);
|
---|
745 | //s->dump("static.txt");
|
---|
746 | //mSceneMgr->showBoundingBoxes(true);
|
---|
747 | mCamera->setLodBias(0.5);
|
---|
748 |
|
---|
749 |
|
---|
750 | }
|
---|
751 |
|
---|
752 | void testReflectedBillboards()
|
---|
753 | {
|
---|
754 | // Set ambient light
|
---|
755 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
756 |
|
---|
757 | // Create a light
|
---|
758 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
759 | l->setType(Light::LT_DIRECTIONAL);
|
---|
760 | Vector3 dir(0.5, -1, 0);
|
---|
761 | dir.normalise();
|
---|
762 | l->setDirection(dir);
|
---|
763 | l->setDiffuseColour(1.0f, 1.0f, 0.8f);
|
---|
764 | l->setSpecularColour(1.0f, 1.0f, 1.0f);
|
---|
765 |
|
---|
766 |
|
---|
767 | // Create a prefab plane
|
---|
768 | plane.d = 0;
|
---|
769 | plane.normal = Vector3::UNIT_Y;
|
---|
770 | MeshManager::getSingleton().createPlane("ReflectionPlane",
|
---|
771 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
772 | plane, 2000, 2000,
|
---|
773 | 1, 1, true, 1, 1, 1, Vector3::UNIT_Z);
|
---|
774 | Entity* planeEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" );
|
---|
775 |
|
---|
776 | // Attach the rtt entity to the root of the scene
|
---|
777 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
778 | SceneNode* planeNode = rootNode->createChildSceneNode();
|
---|
779 |
|
---|
780 | // Attach both the plane entity, and the plane definition
|
---|
781 | planeNode->attachObject(planeEnt);
|
---|
782 |
|
---|
783 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "RttTex", 512, 512, TEX_TYPE_2D, PF_R8G8B8 );
|
---|
784 | {
|
---|
785 | reflectCam = mSceneMgr->createCamera("ReflectCam");
|
---|
786 | reflectCam->setNearClipDistance(mCamera->getNearClipDistance());
|
---|
787 | reflectCam->setFarClipDistance(mCamera->getFarClipDistance());
|
---|
788 | reflectCam->setAspectRatio(
|
---|
789 | (Real)mWindow->getViewport(0)->getActualWidth() /
|
---|
790 | (Real)mWindow->getViewport(0)->getActualHeight());
|
---|
791 |
|
---|
792 | Viewport *v = rttTex->addViewport( reflectCam );
|
---|
793 | v->setClearEveryFrame( true );
|
---|
794 | v->setBackgroundColour( ColourValue::Black );
|
---|
795 |
|
---|
796 | MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",
|
---|
797 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
798 | TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg");
|
---|
799 | t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
|
---|
800 | // Blend with base texture
|
---|
801 | t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White,
|
---|
802 | ColourValue::White, 0.25);
|
---|
803 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
804 | t->setProjectiveTexturing(true, reflectCam);
|
---|
805 |
|
---|
806 | // set up linked reflection
|
---|
807 | reflectCam->enableReflection(plane);
|
---|
808 | // Also clip
|
---|
809 | reflectCam->enableCustomNearClipPlane(plane);
|
---|
810 | }
|
---|
811 |
|
---|
812 | // Give the plane a texture
|
---|
813 | planeEnt->setMaterialName("RttMat");
|
---|
814 |
|
---|
815 |
|
---|
816 | // point billboards
|
---|
817 | ParticleSystem* pSys2 = ParticleSystemManager::getSingleton().createSystem("fountain1",
|
---|
818 | "Examples/Smoke");
|
---|
819 | // Point the fountain at an angle
|
---|
820 | SceneNode* fNode = static_cast<SceneNode*>(rootNode->createChild());
|
---|
821 | fNode->attachObject(pSys2);
|
---|
822 |
|
---|
823 | // oriented_self billboards
|
---|
824 | ParticleSystem* pSys3 = ParticleSystemManager::getSingleton().createSystem("fountain2",
|
---|
825 | "Examples/PurpleFountain");
|
---|
826 | // Point the fountain at an angle
|
---|
827 | fNode = rootNode->createChildSceneNode();
|
---|
828 | fNode->translate(-200,-100,0);
|
---|
829 | fNode->rotate(Vector3::UNIT_Z, Degree(-20));
|
---|
830 | fNode->attachObject(pSys3);
|
---|
831 |
|
---|
832 |
|
---|
833 |
|
---|
834 | // oriented_common billboards
|
---|
835 | ParticleSystem* pSys4 = ParticleSystemManager::getSingleton().createSystem("rain",
|
---|
836 | "Examples/Rain");
|
---|
837 | SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
838 | rNode->translate(0,1000,0);
|
---|
839 | rNode->attachObject(pSys4);
|
---|
840 | // Fast-forward the rain so it looks more natural
|
---|
841 | pSys4->fastForward(5);
|
---|
842 |
|
---|
843 |
|
---|
844 | mCamera->setPosition(-50, 100, 500);
|
---|
845 | mCamera->lookAt(0,0,0);
|
---|
846 | }
|
---|
847 |
|
---|
848 | void testBug()
|
---|
849 | {
|
---|
850 | SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
851 | SceneNode* n2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
852 | n->setAutoTracking(true, n2);
|
---|
853 |
|
---|
854 | mSceneMgr->destroySceneNode(n->getName());
|
---|
855 | mSceneMgr->destroySceneNode(n2->getName());
|
---|
856 |
|
---|
857 |
|
---|
858 | }
|
---|
859 |
|
---|
860 | void testTransparencyMipMaps()
|
---|
861 | {
|
---|
862 | MaterialPtr mat = MaterialManager::getSingleton().create("test",
|
---|
863 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
864 | // known png with alpha
|
---|
865 | Pass* pass = mat->getTechnique(0)->getPass(0);
|
---|
866 | pass->createTextureUnitState("ogretext.png");
|
---|
867 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
868 | // alpha blend
|
---|
869 | pass->setDepthWriteEnabled(false);
|
---|
870 |
|
---|
871 | // alpha reject
|
---|
872 | //pass->setDepthWriteEnabled(true);
|
---|
873 | //pass->setAlphaRejectSettings(CMPF_LESS, 128);
|
---|
874 |
|
---|
875 | // Define a floor plane mesh
|
---|
876 | Plane p;
|
---|
877 | p.normal = Vector3::UNIT_Y;
|
---|
878 | p.d = 200;
|
---|
879 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
880 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
881 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
882 |
|
---|
883 | // Create an entity (the floor)
|
---|
884 | Entity* ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
885 | ent->setMaterialName("test");
|
---|
886 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
887 |
|
---|
888 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
889 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
890 |
|
---|
891 |
|
---|
892 | {
|
---|
893 |
|
---|
894 | Real alphaLevel = 0.5f;
|
---|
895 | MaterialPtr alphamat = MaterialManager::getSingleton().create("testy",
|
---|
896 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
897 | Pass* pass = alphamat->getTechnique(0)->getPass(0);
|
---|
898 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
899 | pass->setDepthWriteEnabled(false);
|
---|
900 | TextureUnitState* t = pass->createTextureUnitState();
|
---|
901 | t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alphaLevel);
|
---|
902 |
|
---|
903 | ent = mSceneMgr->createEntity("asd", "ogrehead.mesh");
|
---|
904 | ent->setMaterialName("testy");
|
---|
905 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
906 |
|
---|
907 | }
|
---|
908 |
|
---|
909 | }
|
---|
910 |
|
---|
911 | void testCthNewBlending(void)
|
---|
912 | {
|
---|
913 | // Set ambient light
|
---|
914 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
915 |
|
---|
916 | // Create a point light
|
---|
917 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
918 | l->setType(Light::LT_DIRECTIONAL);
|
---|
919 | l->setDirection(-Vector3::UNIT_Y);
|
---|
920 |
|
---|
921 | // Accept default settings: point light, white diffuse, just set position
|
---|
922 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
923 | // other objects, but I don't
|
---|
924 | //l->setPosition(20,80,50);
|
---|
925 |
|
---|
926 |
|
---|
927 | Entity *ent = mSceneMgr->createEntity("head", "ogrehead_2.mesh");
|
---|
928 |
|
---|
929 | // Add entity to the root scene node
|
---|
930 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
931 | static_cast<SceneNode*>(mRootNode->createChild())->attachObject(ent);
|
---|
932 |
|
---|
933 | mTestNode[0] = static_cast<SceneNode*>(
|
---|
934 | mRootNode->createChild("TestNode", Vector3(100,0,0)));
|
---|
935 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
936 | mTestNode[0]->attachObject(ent);
|
---|
937 |
|
---|
938 | mTestNode[0]->attachObject(l);
|
---|
939 |
|
---|
940 |
|
---|
941 | // Create a skydome
|
---|
942 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
943 |
|
---|
944 | // Define a floor plane mesh
|
---|
945 | Plane p;
|
---|
946 | p.normal = Vector3::UNIT_Y;
|
---|
947 | p.d = 200;
|
---|
948 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
949 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
950 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
951 |
|
---|
952 | // Create an entity (the floor)
|
---|
953 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
954 | ent->setMaterialName("Block/Material1");
|
---|
955 |
|
---|
956 | mRootNode->attachObject(ent);
|
---|
957 |
|
---|
958 | mCamera->setPosition(0,0,200);
|
---|
959 | mCamera->setDirection(0,0,-1);
|
---|
960 |
|
---|
961 | //mSceneMgr->setDisplaySceneNodes(true);
|
---|
962 |
|
---|
963 | }
|
---|
964 |
|
---|
965 | void testMatrices(void)
|
---|
966 | {
|
---|
967 | mCamera->setPosition(0,0,500);
|
---|
968 | mCamera->lookAt(0,0,0);
|
---|
969 | const Matrix4& view = mCamera->getViewMatrix();
|
---|
970 | const Matrix4& proj = mCamera->getProjectionMatrix();
|
---|
971 |
|
---|
972 | Matrix4 viewproj = proj * view;
|
---|
973 |
|
---|
974 | Vector3 point3d(100,100,0);
|
---|
975 |
|
---|
976 | Vector3 projPoint = viewproj * point3d;
|
---|
977 |
|
---|
978 | point3d = Vector3(100,100,400);
|
---|
979 | projPoint = viewproj * point3d;
|
---|
980 | }
|
---|
981 | void testBasicPlane()
|
---|
982 | {
|
---|
983 | /*
|
---|
984 | // Create a light
|
---|
985 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
986 | // Accept default settings: point light, white diffuse, just set position
|
---|
987 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
988 | // other objects, but I don't
|
---|
989 | l->setPosition(20,80,50);
|
---|
990 | */
|
---|
991 |
|
---|
992 | // Create a point light
|
---|
993 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
994 | l->setType(Light::LT_DIRECTIONAL);
|
---|
995 | l->setDirection(-Vector3::UNIT_Y);
|
---|
996 | Entity *ent;
|
---|
997 |
|
---|
998 | // Define a floor plane mesh
|
---|
999 | Plane p;
|
---|
1000 | p.normal = Vector3::UNIT_Y;
|
---|
1001 | p.d = 200;
|
---|
1002 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1003 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1004 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
1005 |
|
---|
1006 | // Create an entity (the floor)
|
---|
1007 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1008 | ent->setMaterialName("Examples/RustySteel");
|
---|
1009 |
|
---|
1010 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
1011 |
|
---|
1012 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh");
|
---|
1013 |
|
---|
1014 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
1015 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
1016 | node->attachObject(sphereEnt);
|
---|
1017 | mRootNode->addChild(node);
|
---|
1018 |
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | void testAlpha()
|
---|
1022 | {
|
---|
1023 | /*
|
---|
1024 | // Create a light
|
---|
1025 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1026 | // Accept default settings: point light, white diffuse, just set position
|
---|
1027 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
1028 | // other objects, but I don't
|
---|
1029 | l->setPosition(20,80,50);
|
---|
1030 | */
|
---|
1031 |
|
---|
1032 | // Create a point light
|
---|
1033 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1034 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1035 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1036 | Entity *ent;
|
---|
1037 |
|
---|
1038 | // Define a floor plane mesh
|
---|
1039 | Plane p;
|
---|
1040 | p.normal = Vector3::UNIT_Y;
|
---|
1041 | p.d = 200;
|
---|
1042 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1043 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1044 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
1045 |
|
---|
1046 | p.normal = Vector3::UNIT_Z;
|
---|
1047 | p.d = 200;
|
---|
1048 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
1049 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1050 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Y);
|
---|
1051 |
|
---|
1052 | // Create an entity (the floor)
|
---|
1053 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1054 | ent->setMaterialName("Core/StatsBlockBorder/Up");
|
---|
1055 |
|
---|
1056 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
1057 |
|
---|
1058 | ent = mSceneMgr->createEntity("wall", "WallPlane");
|
---|
1059 | ent->setMaterialName("Core/StatsBlockBorder/Up");
|
---|
1060 |
|
---|
1061 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
1062 |
|
---|
1063 |
|
---|
1064 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh");
|
---|
1065 |
|
---|
1066 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
1067 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
1068 | node->attachObject(sphereEnt);
|
---|
1069 | mRootNode->addChild(node);
|
---|
1070 |
|
---|
1071 | mSceneMgr->showBoundingBoxes(true);
|
---|
1072 |
|
---|
1073 | }
|
---|
1074 | void testBsp()
|
---|
1075 | {
|
---|
1076 | // Load Quake3 locations from a file
|
---|
1077 | ConfigFile cf;
|
---|
1078 |
|
---|
1079 | cf.load("quake3settings.cfg");
|
---|
1080 |
|
---|
1081 | String quakePk3 = cf.getSetting("Pak0Location");
|
---|
1082 | String quakeLevel = cf.getSetting("Map");
|
---|
1083 |
|
---|
1084 | ResourceGroupManager::getSingleton().addResourceLocation(quakePk3, "Zip");
|
---|
1085 |
|
---|
1086 |
|
---|
1087 | // Load world geometry
|
---|
1088 | mSceneMgr->setWorldGeometry(quakeLevel);
|
---|
1089 |
|
---|
1090 | // modify camera for close work
|
---|
1091 | mCamera->setNearClipDistance(4);
|
---|
1092 | mCamera->setFarClipDistance(4000);
|
---|
1093 |
|
---|
1094 | // Also change position, and set Quake-type orientation
|
---|
1095 | // Get random player start point
|
---|
1096 | ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true);
|
---|
1097 | mCamera->setPosition(vp.position);
|
---|
1098 | mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up
|
---|
1099 | mCamera->rotate(vp.orientation);
|
---|
1100 | // Don't yaw along variable axis, causes leaning
|
---|
1101 | mCamera->setFixedYawAxis(true, Vector3::UNIT_Z);
|
---|
1102 |
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | void testAnimation()
|
---|
1106 | {
|
---|
1107 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1108 | l->setPosition(200,110,0);
|
---|
1109 | l->setType(Light::LT_POINT);
|
---|
1110 | Entity *ent;
|
---|
1111 |
|
---|
1112 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.4));
|
---|
1113 |
|
---|
1114 | // Create an entity (the plant)
|
---|
1115 | ent = mSceneMgr->createEntity("1", "limo.mesh");
|
---|
1116 |
|
---|
1117 | SceneNode* node = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild(Vector3(-50,0,0)));
|
---|
1118 | node->attachObject(ent);
|
---|
1119 | node->scale(2,2,2);
|
---|
1120 |
|
---|
1121 | mAnimState = ent->getAnimationState("SteerLeftOn");
|
---|
1122 | mAnimState->setEnabled(true);
|
---|
1123 |
|
---|
1124 | mWindow->getViewport(0)->setBackgroundColour(ColourValue(1,0,0));
|
---|
1125 |
|
---|
1126 |
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | void testGpuPrograms(void)
|
---|
1130 | {
|
---|
1131 | // Set ambient light
|
---|
1132 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1133 |
|
---|
1134 | // Create a point light
|
---|
1135 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1136 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1137 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1138 |
|
---|
1139 | Entity* pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
1140 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
|
---|
1141 |
|
---|
1142 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1143 |
|
---|
1144 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1145 | mTestNode[0]->attachObject( pEnt );
|
---|
1146 | mTestNode[0]->translate(100,0,0);
|
---|
1147 |
|
---|
1148 | // Rejig the ogre skin material
|
---|
1149 | // Load the programs first
|
---|
1150 |
|
---|
1151 | pEnt->getSubEntity(1)->setMaterialName("SimpleTest");
|
---|
1152 |
|
---|
1153 | }
|
---|
1154 | void testProjection(void)
|
---|
1155 | {
|
---|
1156 | // Set ambient light
|
---|
1157 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1158 |
|
---|
1159 | // Create a point light
|
---|
1160 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1161 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1162 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1163 |
|
---|
1164 | Entity* pEnt;
|
---|
1165 | //pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
|
---|
1166 | //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
|
---|
1167 | //pEnt->setMaterialName("Examples/OgreLogo");
|
---|
1168 |
|
---|
1169 | // Define a floor plane mesh
|
---|
1170 | Plane p;
|
---|
1171 | p.normal = Vector3::UNIT_Z;
|
---|
1172 | p.d = 200;
|
---|
1173 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
1174 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1175 | p,1500,1500,1,1,true,1,5,5,Vector3::UNIT_Y);
|
---|
1176 | pEnt = mSceneMgr->createEntity( "5", "WallPlane" );
|
---|
1177 | pEnt->setMaterialName("Examples/OgreLogo");
|
---|
1178 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
|
---|
1179 |
|
---|
1180 |
|
---|
1181 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1182 |
|
---|
1183 | //pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1184 | //mTestNode[0]->attachObject( pEnt );
|
---|
1185 | mTestNode[0]->translate(0, 0, 750);
|
---|
1186 |
|
---|
1187 | frustum = new Frustum();
|
---|
1188 | //frustum->setVisible(true);
|
---|
1189 | frustum->setFarClipDistance(5000);
|
---|
1190 | frustum->setNearClipDistance(200);
|
---|
1191 | frustum->setAspectRatio(1);
|
---|
1192 | frustum->setProjectionType(PT_ORTHOGRAPHIC);
|
---|
1193 | mTestNode[0]->attachObject(frustum);
|
---|
1194 |
|
---|
1195 | // Hook the frustum up to the material
|
---|
1196 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/OgreLogo");
|
---|
1197 | TextureUnitState *t = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
|
---|
1198 | t->setProjectiveTexturing(true, frustum);
|
---|
1199 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
1200 |
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | void testMultiViewports(void)
|
---|
1204 | {
|
---|
1205 | // Set ambient light
|
---|
1206 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1207 |
|
---|
1208 | // Create a point light
|
---|
1209 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1210 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1211 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1212 |
|
---|
1213 | Entity* pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
|
---|
1214 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
|
---|
1215 |
|
---|
1216 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1217 |
|
---|
1218 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1219 | mTestNode[0]->attachObject( pEnt );
|
---|
1220 | mTestNode[0]->translate(0, 0, 200);
|
---|
1221 |
|
---|
1222 | frustum = new Frustum();
|
---|
1223 | //frustum->setVisible(true);
|
---|
1224 | frustum->setFarClipDistance(5000);
|
---|
1225 | frustum->setNearClipDistance(100);
|
---|
1226 | mTestNode[0]->attachObject(frustum);
|
---|
1227 |
|
---|
1228 | Viewport* vp = mRoot->getAutoCreatedWindow()->addViewport(mCamera, 1, 0.5, 0.5, 0.5, 0.5);
|
---|
1229 | vp->setOverlaysEnabled(false);
|
---|
1230 | vp->setBackgroundColour(ColourValue(1,0,0));
|
---|
1231 |
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 |
|
---|
1235 | // Just override the mandatory create scene method
|
---|
1236 | void testSceneNodeTracking(void)
|
---|
1237 | {
|
---|
1238 |
|
---|
1239 | // Set ambient light
|
---|
1240 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
1241 |
|
---|
1242 | // Create a skydome
|
---|
1243 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
1244 |
|
---|
1245 | // Create a light
|
---|
1246 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1247 | // Accept default settings: point light, white diffuse, just set position
|
---|
1248 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
1249 | // other objects, but I don't
|
---|
1250 | l->setPosition(20,80,50);
|
---|
1251 |
|
---|
1252 | Entity *ent;
|
---|
1253 |
|
---|
1254 | // Define a floor plane mesh
|
---|
1255 | Plane p;
|
---|
1256 | p.normal = Vector3::UNIT_Y;
|
---|
1257 | p.d = 200;
|
---|
1258 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1259 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1260 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
|
---|
1261 |
|
---|
1262 | // Create an entity (the floor)
|
---|
1263 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1264 | ent->setMaterialName("Examples/RustySteel");
|
---|
1265 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
|
---|
1266 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1267 |
|
---|
1268 | // Add a head, give it it's own node
|
---|
1269 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1270 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
1271 | headNode->attachObject(ent);
|
---|
1272 |
|
---|
1273 | // Add another head, give it it's own node
|
---|
1274 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1275 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
1276 | headNode2->attachObject(ent);
|
---|
1277 |
|
---|
1278 | // Make sure the head node tracks the root
|
---|
1279 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z);
|
---|
1280 | //headNode->setFixedYawAxis(true);
|
---|
1281 |
|
---|
1282 | // Create the camera node & attach camera
|
---|
1283 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1284 | //camNode->attachObject(mCamera);
|
---|
1285 |
|
---|
1286 | // set up spline animation of node
|
---|
1287 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
|
---|
1288 | // Spline it for nice curves
|
---|
1289 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
1290 | // Create a track to animate the head's node
|
---|
1291 | AnimationTrack* track = anim->createTrack(0, headNode);
|
---|
1292 | // Setup keyframes
|
---|
1293 | KeyFrame* key = track->createKeyFrame(0); // startposition
|
---|
1294 | key = track->createKeyFrame(2.5);
|
---|
1295 | key->setTranslate(Vector3(500,500,-1000));
|
---|
1296 | key = track->createKeyFrame(5);
|
---|
1297 | key->setTranslate(Vector3(-1500,1000,-600));
|
---|
1298 | key = track->createKeyFrame(7.5);
|
---|
1299 | key->setTranslate(Vector3(0,-100,0));
|
---|
1300 | key = track->createKeyFrame(10);
|
---|
1301 | key->setTranslate(Vector3(0,0,0));
|
---|
1302 | // Create a track to animate the second head's node
|
---|
1303 | track = anim->createTrack(1, headNode2);
|
---|
1304 | // Setup keyframes
|
---|
1305 | key = track->createKeyFrame(0); // startposition
|
---|
1306 | key = track->createKeyFrame(2.5);
|
---|
1307 | key->setTranslate(Vector3(-500,600,-100));
|
---|
1308 | key = track->createKeyFrame(5);
|
---|
1309 | key->setTranslate(Vector3(800,200,-600));
|
---|
1310 | key = track->createKeyFrame(7.5);
|
---|
1311 | key->setTranslate(Vector3(200,-1000,0));
|
---|
1312 | key = track->createKeyFrame(10);
|
---|
1313 | key->setTranslate(Vector3(30,70,110));
|
---|
1314 | // Create a new animation state to track this
|
---|
1315 | mAnimState = mSceneMgr->createAnimationState("CameraTrack");
|
---|
1316 | mAnimState->setEnabled(true);
|
---|
1317 |
|
---|
1318 | // Put in a bit of fog for the hell of it
|
---|
1319 | mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);
|
---|
1320 |
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 |
|
---|
1324 |
|
---|
1325 | void testDistortion(void)
|
---|
1326 | {
|
---|
1327 | theCam = mCamera;
|
---|
1328 | // Set ambient light
|
---|
1329 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1330 |
|
---|
1331 | // Create a point light
|
---|
1332 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1333 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1334 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1335 |
|
---|
1336 | Entity* pEnt;
|
---|
1337 |
|
---|
1338 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "Refraction", 512, 512 );
|
---|
1339 | {
|
---|
1340 | Viewport *v = rttTex->addViewport( mCamera );
|
---|
1341 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
|
---|
1342 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction");
|
---|
1343 | v->setOverlaysEnabled(false);
|
---|
1344 | rttTex->addListener(&mRefractionListener);
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | rttTex = mRoot->getRenderSystem()->createRenderTexture( "Reflection", 512, 512 );
|
---|
1348 | {
|
---|
1349 | Viewport *v = rttTex->addViewport( mCamera );
|
---|
1350 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
|
---|
1351 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection");
|
---|
1352 | v->setOverlaysEnabled(false);
|
---|
1353 | rttTex->addListener(&mReflectionListener);
|
---|
1354 | }
|
---|
1355 | // Define a floor plane mesh
|
---|
1356 | Plane p;
|
---|
1357 | p.normal = Vector3::UNIT_Y;
|
---|
1358 | p.d = 100;
|
---|
1359 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
1360 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1361 | p,1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
1362 | pPlaneEnt = mSceneMgr->createEntity( "5", "WallPlane" );
|
---|
1363 | pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction");
|
---|
1364 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
1365 |
|
---|
1366 |
|
---|
1367 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
1368 |
|
---|
1369 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1370 | int i;
|
---|
1371 | for (i = 0; i < 10; ++i)
|
---|
1372 | {
|
---|
1373 | pEnt = mSceneMgr->createEntity( "ogre" + StringConverter::toString(i), "ogrehead.mesh" );
|
---|
1374 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, -75, 0))->attachObject(pEnt);
|
---|
1375 | pEnt = mSceneMgr->createEntity( "knot" + StringConverter::toString(i), "knot.mesh" );
|
---|
1376 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, 140, 0))->attachObject(pEnt);
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 |
|
---|
1384 | void testEdgeBuilderSingleIndexBufSingleVertexBuf()
|
---|
1385 | {
|
---|
1386 | /* This tests the edge builders ability to find shared edges in the simple case
|
---|
1387 | of a single index buffer referencing a single vertex buffer
|
---|
1388 | */
|
---|
1389 | VertexData vd;
|
---|
1390 | IndexData id;
|
---|
1391 | // Test pyramid
|
---|
1392 | vd.vertexCount = 4;
|
---|
1393 | vd.vertexStart = 0;
|
---|
1394 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1395 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1396 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
1397 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
1398 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1399 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1400 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1401 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1402 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1403 | vbuf->unlock();
|
---|
1404 |
|
---|
1405 | id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1406 | HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true);
|
---|
1407 | id.indexCount = 12;
|
---|
1408 | id.indexStart = 0;
|
---|
1409 | unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1410 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1411 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
1412 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
1413 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
1414 | id.indexBuffer->unlock();
|
---|
1415 |
|
---|
1416 | EdgeListBuilder edgeBuilder;
|
---|
1417 | edgeBuilder.addVertexData(&vd);
|
---|
1418 | edgeBuilder.addIndexData(&id);
|
---|
1419 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1420 |
|
---|
1421 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1422 |
|
---|
1423 | delete edgeData;
|
---|
1424 |
|
---|
1425 |
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | void testEdgeBuilderMultiIndexBufSingleVertexBuf()
|
---|
1429 | {
|
---|
1430 | /* This tests the edge builders ability to find shared edges when there are
|
---|
1431 | multiple index sets (submeshes) using a single vertex buffer.
|
---|
1432 | */
|
---|
1433 | VertexData vd;
|
---|
1434 | IndexData id[4];
|
---|
1435 | // Test pyramid
|
---|
1436 | vd.vertexCount = 4;
|
---|
1437 | vd.vertexStart = 0;
|
---|
1438 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1439 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1440 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
1441 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
1442 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1443 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1444 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1445 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1446 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1447 | vbuf->unlock();
|
---|
1448 |
|
---|
1449 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1450 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1451 | id[0].indexCount = 3;
|
---|
1452 | id[0].indexStart = 0;
|
---|
1453 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1454 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1455 | id[0].indexBuffer->unlock();
|
---|
1456 |
|
---|
1457 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1458 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1459 | id[1].indexCount = 3;
|
---|
1460 | id[1].indexStart = 0;
|
---|
1461 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1462 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
1463 | id[1].indexBuffer->unlock();
|
---|
1464 |
|
---|
1465 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1466 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1467 | id[2].indexCount = 3;
|
---|
1468 | id[2].indexStart = 0;
|
---|
1469 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1470 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
1471 | id[2].indexBuffer->unlock();
|
---|
1472 |
|
---|
1473 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1474 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1475 | id[3].indexCount = 3;
|
---|
1476 | id[3].indexStart = 0;
|
---|
1477 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1478 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
1479 | id[3].indexBuffer->unlock();
|
---|
1480 |
|
---|
1481 | EdgeListBuilder edgeBuilder;
|
---|
1482 | edgeBuilder.addVertexData(&vd);
|
---|
1483 | edgeBuilder.addIndexData(&id[0]);
|
---|
1484 | edgeBuilder.addIndexData(&id[1]);
|
---|
1485 | edgeBuilder.addIndexData(&id[2]);
|
---|
1486 | edgeBuilder.addIndexData(&id[3]);
|
---|
1487 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1488 |
|
---|
1489 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1490 |
|
---|
1491 | delete edgeData;
|
---|
1492 |
|
---|
1493 |
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 |
|
---|
1497 | void testEdgeBuilderMultiIndexBufMultiVertexBuf()
|
---|
1498 | {
|
---|
1499 | /* This tests the edge builders ability to find shared edges when there are
|
---|
1500 | both multiple index sets (submeshes) each using a different vertex buffer
|
---|
1501 | (not using shared geoemtry).
|
---|
1502 | */
|
---|
1503 |
|
---|
1504 | VertexData vd[4];
|
---|
1505 | IndexData id[4];
|
---|
1506 | // Test pyramid
|
---|
1507 | vd[0].vertexCount = 3;
|
---|
1508 | vd[0].vertexStart = 0;
|
---|
1509 | vd[0].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1510 | vd[0].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1511 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1512 | vd[0].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1513 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1514 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1515 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1516 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1517 | vbuf->unlock();
|
---|
1518 |
|
---|
1519 | vd[1].vertexCount = 3;
|
---|
1520 | vd[1].vertexStart = 0;
|
---|
1521 | vd[1].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1522 | vd[1].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1523 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1524 | vd[1].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1525 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1526 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1527 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1528 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1529 | vbuf->unlock();
|
---|
1530 |
|
---|
1531 | vd[2].vertexCount = 3;
|
---|
1532 | vd[2].vertexStart = 0;
|
---|
1533 | vd[2].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1534 | vd[2].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1535 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1536 | vd[2].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1537 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1538 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1539 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1540 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1541 | vbuf->unlock();
|
---|
1542 |
|
---|
1543 | vd[3].vertexCount = 3;
|
---|
1544 | vd[3].vertexStart = 0;
|
---|
1545 | vd[3].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1546 | vd[3].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1547 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1548 | vd[3].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1549 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1550 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1551 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1552 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1553 | vbuf->unlock();
|
---|
1554 |
|
---|
1555 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1556 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1557 | id[0].indexCount = 3;
|
---|
1558 | id[0].indexStart = 0;
|
---|
1559 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1560 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1561 | id[0].indexBuffer->unlock();
|
---|
1562 |
|
---|
1563 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1564 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1565 | id[1].indexCount = 3;
|
---|
1566 | id[1].indexStart = 0;
|
---|
1567 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1568 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1569 | id[1].indexBuffer->unlock();
|
---|
1570 |
|
---|
1571 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1572 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1573 | id[2].indexCount = 3;
|
---|
1574 | id[2].indexStart = 0;
|
---|
1575 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1576 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
1577 | id[2].indexBuffer->unlock();
|
---|
1578 |
|
---|
1579 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1580 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1581 | id[3].indexCount = 3;
|
---|
1582 | id[3].indexStart = 0;
|
---|
1583 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1584 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
1585 | id[3].indexBuffer->unlock();
|
---|
1586 |
|
---|
1587 | EdgeListBuilder edgeBuilder;
|
---|
1588 | edgeBuilder.addVertexData(&vd[0]);
|
---|
1589 | edgeBuilder.addVertexData(&vd[1]);
|
---|
1590 | edgeBuilder.addVertexData(&vd[2]);
|
---|
1591 | edgeBuilder.addVertexData(&vd[3]);
|
---|
1592 | edgeBuilder.addIndexData(&id[0], 0);
|
---|
1593 | edgeBuilder.addIndexData(&id[1], 1);
|
---|
1594 | edgeBuilder.addIndexData(&id[2], 2);
|
---|
1595 | edgeBuilder.addIndexData(&id[3], 3);
|
---|
1596 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1597 |
|
---|
1598 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1599 |
|
---|
1600 | delete edgeData;
|
---|
1601 |
|
---|
1602 |
|
---|
1603 | }
|
---|
1604 |
|
---|
1605 | void testSkeletalAnimation()
|
---|
1606 | {
|
---|
1607 | // Set ambient light
|
---|
1608 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1609 | //mWindow->getViewport(0)->setBackgroundColour(ColourValue::White);
|
---|
1610 |
|
---|
1611 |
|
---|
1612 |
|
---|
1613 | //Entity *ent = mSceneMgr->createEntity("robot", "scuttlepod.mesh");
|
---|
1614 | //mAnimState = ent->getAnimationState("Walk");
|
---|
1615 | //Entity *ent = mSceneMgr->createEntity("robot", "jaiqua.mesh");
|
---|
1616 | //mAnimState = ent->getAnimationState("Jaiqua_walk_Preset");
|
---|
1617 | Entity *ent = mSceneMgr->createEntity("robot", "Golden.mesh");
|
---|
1618 | mAnimState = ent->getAnimationState("TestAnimationThatDoesntWork");
|
---|
1619 |
|
---|
1620 | mAnimState->setEnabled(true);
|
---|
1621 |
|
---|
1622 | // Uncomment the below to test software skinning
|
---|
1623 | //ent->setMaterialName("Examples/Rocky");
|
---|
1624 | // Add entity to the scene node
|
---|
1625 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1626 |
|
---|
1627 | // Give it a little ambience with lights
|
---|
1628 | Light* l;
|
---|
1629 | l = mSceneMgr->createLight("Light");
|
---|
1630 | Vector3 dir(-1,-1, 0);
|
---|
1631 | dir.normalise();
|
---|
1632 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1633 | l->setDirection(dir);
|
---|
1634 |
|
---|
1635 | l = mSceneMgr->createLight("GreenLight");
|
---|
1636 | l->setPosition(0,0,-100);
|
---|
1637 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1638 |
|
---|
1639 | // Position the camera
|
---|
1640 | mCamera->setPosition(100,50,100);
|
---|
1641 | mCamera->lookAt(-50,50,0);
|
---|
1642 |
|
---|
1643 | // Report whether hardware skinning is enabled or not
|
---|
1644 | Technique* t = ent->getSubEntity(0)->getMaterial()->getBestTechnique();
|
---|
1645 | Pass* p = t->getPass(0);
|
---|
1646 | if (p->hasVertexProgram() &&
|
---|
1647 | p->getVertexProgram()->isSkeletalAnimationIncluded())
|
---|
1648 | {
|
---|
1649 | mWindow->setDebugText("Hardware skinning is enabled");
|
---|
1650 | }
|
---|
1651 | else
|
---|
1652 | {
|
---|
1653 | mWindow->setDebugText("Software skinning is enabled");
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 |
|
---|
1657 | }
|
---|
1658 |
|
---|
1659 |
|
---|
1660 | void testPrepareShadowVolume(void)
|
---|
1661 | {
|
---|
1662 |
|
---|
1663 | // Set ambient light
|
---|
1664 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1665 |
|
---|
1666 | // Create a point light
|
---|
1667 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1668 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1669 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1670 |
|
---|
1671 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1672 |
|
---|
1673 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1674 | mTestNode[0]->attachObject( pEnt );
|
---|
1675 |
|
---|
1676 | pEnt->getMesh()->prepareForShadowVolume();
|
---|
1677 |
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | void testWindowedViewportMode()
|
---|
1681 | {
|
---|
1682 | // Set ambient light
|
---|
1683 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1684 |
|
---|
1685 | // Create a point light
|
---|
1686 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1687 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1688 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1689 |
|
---|
1690 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1691 |
|
---|
1692 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1693 | mTestNode[0]->attachObject( pEnt );
|
---|
1694 |
|
---|
1695 | mCamera->setWindow(0,0,0.5,0.5);
|
---|
1696 |
|
---|
1697 | }
|
---|
1698 | void testSubEntityVisibility()
|
---|
1699 | {
|
---|
1700 | // Set ambient light
|
---|
1701 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1702 |
|
---|
1703 | // Create a point light
|
---|
1704 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1705 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1706 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1707 |
|
---|
1708 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1709 |
|
---|
1710 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1711 | mTestNode[0]->attachObject( pEnt );
|
---|
1712 |
|
---|
1713 | pEnt->getSubEntity(1)->setVisible(false);
|
---|
1714 |
|
---|
1715 |
|
---|
1716 | }
|
---|
1717 |
|
---|
1718 | void testAttachObjectsToBones()
|
---|
1719 | {
|
---|
1720 | Entity *ent;
|
---|
1721 | for (int i = 0; i < 5; ++i)
|
---|
1722 | {
|
---|
1723 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
|
---|
1724 | Entity* ent2 = mSceneMgr->createEntity("plane" + StringConverter::toString(i), "razor.mesh");
|
---|
1725 | ent->attachObjectToBone("Joint8", ent2);
|
---|
1726 | // Add entity to the scene node
|
---|
1727 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1728 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1729 | if (i==4)
|
---|
1730 | {
|
---|
1731 | ent->getParentNode()->yaw(Degree(45));
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | ent->getParentNode()->scale(Vector3(0.5, 0.5, 0.5));
|
---|
1735 | }
|
---|
1736 | mAnimState = ent->getAnimationState("Walk");
|
---|
1737 | mAnimState->setEnabled(true);
|
---|
1738 |
|
---|
1739 |
|
---|
1740 |
|
---|
1741 | // Give it a little ambience with lights
|
---|
1742 | Light* l;
|
---|
1743 | l = mSceneMgr->createLight("BlueLight");
|
---|
1744 | l->setPosition(-200,-80,-100);
|
---|
1745 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1746 |
|
---|
1747 | l = mSceneMgr->createLight("GreenLight");
|
---|
1748 | l->setPosition(0,0,-100);
|
---|
1749 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1750 |
|
---|
1751 | // Position the camera
|
---|
1752 | mCamera->setPosition(100,50,100);
|
---|
1753 | mCamera->lookAt(-50,50,0);
|
---|
1754 |
|
---|
1755 | mSceneMgr->setAmbientLight(ColourValue(1,1,1,1));
|
---|
1756 | mSceneMgr->showBoundingBoxes(true);
|
---|
1757 |
|
---|
1758 | }
|
---|
1759 | void testOrtho()
|
---|
1760 | {
|
---|
1761 | // Set ambient light
|
---|
1762 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
|
---|
1763 |
|
---|
1764 | // Create a point light
|
---|
1765 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1766 | l->setPosition(800,600,0);
|
---|
1767 |
|
---|
1768 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1769 | mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1770 |
|
---|
1771 | Entity* pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
1772 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
1773 | mTestNode[1]->attachObject( pEnt );
|
---|
1774 |
|
---|
1775 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
1776 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
1777 | mTestNode[2]->attachObject( pEnt );
|
---|
1778 |
|
---|
1779 |
|
---|
1780 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
1781 |
|
---|
1782 |
|
---|
1783 | Plane plane;
|
---|
1784 | plane.normal = Vector3::UNIT_Y;
|
---|
1785 | plane.d = 100;
|
---|
1786 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
1787 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
1788 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
1789 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
1790 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
1791 | pPlaneEnt->setCastShadows(false);
|
---|
1792 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
1793 |
|
---|
1794 | mCamera->setFixedYawAxis(false);
|
---|
1795 | mCamera->setProjectionType(PT_ORTHOGRAPHIC);
|
---|
1796 | mCamera->setPosition(0,10000,0);
|
---|
1797 | mCamera->lookAt(0,0,0);
|
---|
1798 | mCamera->setNearClipDistance(1000);
|
---|
1799 |
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | void testManualLOD()
|
---|
1803 | {
|
---|
1804 | MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("robot.mesh",
|
---|
1805 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1806 |
|
---|
1807 | msh1->createManualLodLevel(200, "razor.mesh");
|
---|
1808 | msh1->createManualLodLevel(500, "sphere.mesh");
|
---|
1809 |
|
---|
1810 | Entity *ent;
|
---|
1811 | for (int i = 0; i < 5; ++i)
|
---|
1812 | {
|
---|
1813 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
|
---|
1814 | // Add entity to the scene node
|
---|
1815 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1816 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1817 | }
|
---|
1818 | mAnimState = ent->getAnimationState("Walk");
|
---|
1819 | mAnimState->setEnabled(true);
|
---|
1820 |
|
---|
1821 |
|
---|
1822 |
|
---|
1823 | // Give it a little ambience with lights
|
---|
1824 | Light* l;
|
---|
1825 | l = mSceneMgr->createLight("BlueLight");
|
---|
1826 | l->setPosition(-200,-80,-100);
|
---|
1827 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1828 |
|
---|
1829 | l = mSceneMgr->createLight("GreenLight");
|
---|
1830 | l->setPosition(0,0,-100);
|
---|
1831 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1832 |
|
---|
1833 | // Position the camera
|
---|
1834 | mCamera->setPosition(100,50,100);
|
---|
1835 | mCamera->lookAt(-50,50,0);
|
---|
1836 |
|
---|
1837 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
1838 |
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | void clearSceneSetup()
|
---|
1842 | {
|
---|
1843 | bool showOctree = true;
|
---|
1844 | mSceneMgr->setOption("ShowOctree", &showOctree);
|
---|
1845 |
|
---|
1846 | // Set ambient light
|
---|
1847 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
1848 |
|
---|
1849 | // Create a skydome
|
---|
1850 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
1851 |
|
---|
1852 | // Create a light
|
---|
1853 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1854 | // Accept default settings: point light, white diffuse, just set position
|
---|
1855 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
1856 | // other objects, but I don't
|
---|
1857 | l->setPosition(20,80,50);
|
---|
1858 |
|
---|
1859 | Entity *ent;
|
---|
1860 |
|
---|
1861 | // Create an entity (the floor)
|
---|
1862 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1863 | ent->setMaterialName("Examples/RustySteel");
|
---|
1864 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
|
---|
1865 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1866 |
|
---|
1867 | // Add a head, give it it's own node
|
---|
1868 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1869 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
1870 | headNode->attachObject(ent);
|
---|
1871 |
|
---|
1872 | // Add another head, give it it's own node
|
---|
1873 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1874 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
1875 | headNode2->attachObject(ent);
|
---|
1876 |
|
---|
1877 | // Make sure the head node tracks the root
|
---|
1878 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z);
|
---|
1879 | //headNode->setFixedYawAxis(true);
|
---|
1880 |
|
---|
1881 | // Create the camera node & attach camera
|
---|
1882 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1883 | //camNode->attachObject(mCamera);
|
---|
1884 |
|
---|
1885 | // set up spline animation of node
|
---|
1886 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
|
---|
1887 | // Spline it for nice curves
|
---|
1888 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
1889 | // Create a track to animate the head's node
|
---|
1890 | AnimationTrack* track = anim->createTrack(0, headNode);
|
---|
1891 | // Setup keyframes
|
---|
1892 | KeyFrame* key = track->createKeyFrame(0); // startposition
|
---|
1893 | key = track->createKeyFrame(2.5);
|
---|
1894 | key->setTranslate(Vector3(500,500,-1000));
|
---|
1895 | key = track->createKeyFrame(5);
|
---|
1896 | key->setTranslate(Vector3(-1500,1000,-600));
|
---|
1897 | key = track->createKeyFrame(7.5);
|
---|
1898 | key->setTranslate(Vector3(0,-100,0));
|
---|
1899 | key = track->createKeyFrame(10);
|
---|
1900 | key->setTranslate(Vector3(0,0,0));
|
---|
1901 | // Create a track to animate the second head's node
|
---|
1902 | track = anim->createTrack(1, headNode2);
|
---|
1903 | // Setup keyframes
|
---|
1904 | key = track->createKeyFrame(0); // startposition
|
---|
1905 | key = track->createKeyFrame(2.5);
|
---|
1906 | key->setTranslate(Vector3(-500,600,-100));
|
---|
1907 | key = track->createKeyFrame(5);
|
---|
1908 | key->setTranslate(Vector3(800,200,-600));
|
---|
1909 | key = track->createKeyFrame(7.5);
|
---|
1910 | key->setTranslate(Vector3(200,-1000,0));
|
---|
1911 | key = track->createKeyFrame(10);
|
---|
1912 | key->setTranslate(Vector3(30,70,110));
|
---|
1913 | // Create a new animation state to track this
|
---|
1914 | mAnimState = mSceneMgr->createAnimationState("CameraTrack");
|
---|
1915 | mAnimState->setEnabled(true);
|
---|
1916 | }
|
---|
1917 | class ClearSceneListener : public FrameListener
|
---|
1918 | {
|
---|
1919 | protected:
|
---|
1920 | SceneManager* mSceneMgr;
|
---|
1921 | PlayPenApplication* ppApp;
|
---|
1922 |
|
---|
1923 | public:
|
---|
1924 | ClearSceneListener(SceneManager* sm, PlayPenApplication* target)
|
---|
1925 | {
|
---|
1926 | mSceneMgr = sm;
|
---|
1927 | ppApp = target;
|
---|
1928 | }
|
---|
1929 | bool frameStarted(const FrameEvent& evt)
|
---|
1930 | {
|
---|
1931 | static Real timeElapsed = 0;
|
---|
1932 |
|
---|
1933 | timeElapsed += evt.timeSinceLastFrame;
|
---|
1934 | if (timeElapsed > 15)
|
---|
1935 | {
|
---|
1936 | mSceneMgr->clearScene();
|
---|
1937 | ppApp->clearSceneSetup();
|
---|
1938 | timeElapsed = 0;
|
---|
1939 | }
|
---|
1940 | return true;
|
---|
1941 | }
|
---|
1942 | };
|
---|
1943 | ClearSceneListener* csListener;
|
---|
1944 | void testClearScene()
|
---|
1945 | {
|
---|
1946 | // Define a floor plane mesh
|
---|
1947 | Plane p;
|
---|
1948 | p.normal = Vector3::UNIT_Y;
|
---|
1949 | p.d = 200;
|
---|
1950 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1951 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1952 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
|
---|
1953 |
|
---|
1954 |
|
---|
1955 | // leak here I know
|
---|
1956 | csListener = new ClearSceneListener(mSceneMgr, this);
|
---|
1957 | Root::getSingleton().addFrameListener(csListener);
|
---|
1958 | clearSceneSetup();
|
---|
1959 | }
|
---|
1960 |
|
---|
1961 | void testStencilShadows(ShadowTechnique tech, bool pointLight, bool directionalLight)
|
---|
1962 | {
|
---|
1963 | mSceneMgr->setShadowTechnique(tech);
|
---|
1964 | //mSceneMgr->setShowDebugShadows(true);
|
---|
1965 | mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000);
|
---|
1966 | //mSceneMgr->setShadowColour(ColourValue(0.4, 0.25, 0.25));
|
---|
1967 |
|
---|
1968 | //mSceneMgr->setShadowFarDistance(800);
|
---|
1969 | // Set ambient light
|
---|
1970 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
|
---|
1971 |
|
---|
1972 | // Point light
|
---|
1973 | if(pointLight)
|
---|
1974 | {
|
---|
1975 | mLight = mSceneMgr->createLight("MainLight");
|
---|
1976 | mLight->setPosition(-400,400,-300);
|
---|
1977 | mLight->setDiffuseColour(0.9, 0.9, 1);
|
---|
1978 | mLight->setSpecularColour(0.9, 0.9, 1);
|
---|
1979 | mLight->setAttenuation(6000,1,0.001,0);
|
---|
1980 | }
|
---|
1981 | // Directional light
|
---|
1982 | if (directionalLight)
|
---|
1983 | {
|
---|
1984 | mLight = mSceneMgr->createLight("Light2");
|
---|
1985 | Vector3 dir(-1,-1,0);
|
---|
1986 | dir.normalise();
|
---|
1987 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
1988 | mLight->setDirection(dir);
|
---|
1989 | mLight->setDiffuseColour(1, 1, 0.8);
|
---|
1990 | mLight->setSpecularColour(1, 1, 1);
|
---|
1991 | }
|
---|
1992 |
|
---|
1993 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1994 |
|
---|
1995 | // Hardware skin
|
---|
1996 | Entity* pEnt;
|
---|
1997 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
1998 | AnimationState* anim = pEnt->getAnimationState("Walk");
|
---|
1999 | anim->setEnabled(true);
|
---|
2000 | mAnimStateList.push_back(anim);
|
---|
2001 | mTestNode[0]->attachObject( pEnt );
|
---|
2002 |
|
---|
2003 | // Software skin
|
---|
2004 | pEnt = mSceneMgr->createEntity( "12", "robot.mesh" );
|
---|
2005 | anim = pEnt->getAnimationState("Walk");
|
---|
2006 | anim->setEnabled(true);
|
---|
2007 | mAnimStateList.push_back(anim);
|
---|
2008 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 0))->attachObject(pEnt);
|
---|
2009 | pEnt->setMaterialName("Examples/Rocky");
|
---|
2010 |
|
---|
2011 |
|
---|
2012 | // Does not receive shadows
|
---|
2013 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
2014 | pEnt->setMaterialName("Examples/EnvMappedRustySteel");
|
---|
2015 | MaterialPtr mat2 = MaterialManager::getSingleton().getByName("Examples/EnvMappedRustySteel");
|
---|
2016 | mat2->setReceiveShadows(false);
|
---|
2017 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
2018 | mTestNode[2]->attachObject( pEnt );
|
---|
2019 |
|
---|
2020 | // Transparent object
|
---|
2021 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
|
---|
2022 | pEnt->setMaterialName("Examples/TransparentTest");
|
---|
2023 | MaterialPtr mat3 = MaterialManager::getSingleton().getByName("Examples/TransparentTest");
|
---|
2024 | pEnt->setCastShadows(false);
|
---|
2025 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
|
---|
2026 | mTestNode[3]->attachObject( pEnt );
|
---|
2027 |
|
---|
2028 | // User test
|
---|
2029 | /*
|
---|
2030 | pEnt = mSceneMgr->createEntity( "3.6", "ogre_male_endCaps.mesh" );
|
---|
2031 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 0, 100))->attachObject( pEnt );
|
---|
2032 | */
|
---|
2033 |
|
---|
2034 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
|
---|
2035 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2036 | unsigned short src, dest;
|
---|
2037 | if (!msh->suggestTangentVectorBuildParams(src, dest))
|
---|
2038 | {
|
---|
2039 | msh->buildTangentVectors(src, dest);
|
---|
2040 | }
|
---|
2041 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
2042 | pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
|
---|
2043 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
2044 | mTestNode[2]->attachObject( pEnt );
|
---|
2045 |
|
---|
2046 |
|
---|
2047 | ParticleSystem* pSys2 = ParticleSystemManager::getSingleton().createSystem("smoke",
|
---|
2048 | "Examples/Smoke");
|
---|
2049 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
|
---|
2050 | mTestNode[4]->attachObject(pSys2);
|
---|
2051 |
|
---|
2052 |
|
---|
2053 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
2054 |
|
---|
2055 |
|
---|
2056 | Plane plane;
|
---|
2057 | plane.normal = Vector3::UNIT_Y;
|
---|
2058 | plane.d = 100;
|
---|
2059 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2060 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2061 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2062 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2063 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2064 | pPlaneEnt->setCastShadows(false);
|
---|
2065 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2066 |
|
---|
2067 | mCamera->setPosition(180, 34, 223);
|
---|
2068 | mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791));
|
---|
2069 |
|
---|
2070 | }
|
---|
2071 |
|
---|
2072 | void test2Spotlights()
|
---|
2073 | {
|
---|
2074 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
2075 |
|
---|
2076 | mLight = mSceneMgr->createLight("MainLight");
|
---|
2077 | // Spotlight test
|
---|
2078 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2079 | mLight->setDiffuseColour(1.0, 0.0, 0.8);
|
---|
2080 | mLight->setSpotlightRange(Degree(30), Degree(40));
|
---|
2081 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2082 | mTestNode[0]->setPosition(800,600,0);
|
---|
2083 | mTestNode[0]->lookAt(Vector3(800,0,0), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2084 | mTestNode[0]->attachObject(mLight);
|
---|
2085 |
|
---|
2086 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2087 | mLight = mSceneMgr->createLight("AnotherLight");
|
---|
2088 | // Spotlight test
|
---|
2089 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2090 | mLight->setDiffuseColour(0, 1.0, 0.8);
|
---|
2091 | mLight->setSpotlightRange(Degree(30), Degree(40));
|
---|
2092 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2093 | mTestNode[1]->setPosition(0,600,800);
|
---|
2094 | mTestNode[1]->lookAt(Vector3(0,0,800), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2095 | mTestNode[1]->attachObject(mLight);
|
---|
2096 |
|
---|
2097 |
|
---|
2098 | Plane plane;
|
---|
2099 | plane.normal = Vector3::UNIT_Y;
|
---|
2100 | plane.d = 100;
|
---|
2101 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2102 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2103 | 3500,3500,100,100,true,1,5,5,Vector3::UNIT_Z);
|
---|
2104 | Entity* pPlaneEnt;
|
---|
2105 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2106 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2107 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2108 |
|
---|
2109 | }
|
---|
2110 | void testTextureShadows(bool directional)
|
---|
2111 | {
|
---|
2112 | mSceneMgr->setShadowTextureSize(512);
|
---|
2113 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
2114 | mSceneMgr->setShadowFarDistance(1500);
|
---|
2115 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
|
---|
2116 | //mSceneMgr->setShadowFarDistance(800);
|
---|
2117 | // Set ambient light
|
---|
2118 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
2119 |
|
---|
2120 | mLight = mSceneMgr->createLight("MainLight");
|
---|
2121 |
|
---|
2122 |
|
---|
2123 | if (directional)
|
---|
2124 | {
|
---|
2125 | // Directional test
|
---|
2126 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
2127 | Vector3 vec(-1,-1,0);
|
---|
2128 | vec.normalise();
|
---|
2129 | mLight->setDirection(vec);
|
---|
2130 | }
|
---|
2131 | else
|
---|
2132 | {
|
---|
2133 |
|
---|
2134 | // Spotlight test
|
---|
2135 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2136 | mLight->setDiffuseColour(1.0, 1.0, 0.8);
|
---|
2137 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2138 | mTestNode[0]->setPosition(800,600,0);
|
---|
2139 | mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2140 | mTestNode[0]->attachObject(mLight);
|
---|
2141 | }
|
---|
2142 |
|
---|
2143 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2144 |
|
---|
2145 |
|
---|
2146 | Entity* pEnt;
|
---|
2147 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
2148 | mAnimState = pEnt->getAnimationState("Walk");
|
---|
2149 | mAnimState->setEnabled(true);
|
---|
2150 | //pEnt->setMaterialName("2 - Default");
|
---|
2151 | mTestNode[1]->attachObject( pEnt );
|
---|
2152 | mTestNode[1]->translate(0,-100,0);
|
---|
2153 |
|
---|
2154 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
2155 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
2156 | mTestNode[2]->attachObject( pEnt );
|
---|
2157 |
|
---|
2158 | // Transparent object (can force cast shadows)
|
---|
2159 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
|
---|
2160 | MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency",
|
---|
2161 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2162 | tmat->setTransparencyCastsShadows(true);
|
---|
2163 | Pass* tpass = tmat->getTechnique(0)->getPass(0);
|
---|
2164 | tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
|
---|
2165 | tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
2166 | tpass->createTextureUnitState("gras_02.png");
|
---|
2167 | tpass->setCullingMode(CULL_NONE);
|
---|
2168 |
|
---|
2169 | pEnt->setMaterialName("TestAlphaTransparency");
|
---|
2170 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
|
---|
2171 | mTestNode[3]->attachObject( pEnt );
|
---|
2172 |
|
---|
2173 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
|
---|
2174 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2175 | msh->buildTangentVectors();
|
---|
2176 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
2177 | //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
|
---|
2178 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
2179 | mTestNode[2]->attachObject( pEnt );
|
---|
2180 |
|
---|
2181 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
2182 |
|
---|
2183 |
|
---|
2184 | Plane plane;
|
---|
2185 | plane.normal = Vector3::UNIT_Y;
|
---|
2186 | plane.d = 100;
|
---|
2187 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2188 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2189 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2190 | Entity* pPlaneEnt;
|
---|
2191 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2192 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2193 | pPlaneEnt->setCastShadows(false);
|
---|
2194 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2195 |
|
---|
2196 | // Set up a debug panel to display the shadow
|
---|
2197 | MaterialPtr debugMat = MaterialManager::getSingleton().create(
|
---|
2198 | "Ogre/DebugShadowMap", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2199 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
|
---|
2200 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("Ogre/ShadowTexture0");
|
---|
2201 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2202 | //t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("spot_shadow_fade.png");
|
---|
2203 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2204 | //t->setColourOperation(LBO_ADD);
|
---|
2205 |
|
---|
2206 | OverlayContainer* debugPanel = (OverlayContainer*)
|
---|
2207 | (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel"));
|
---|
2208 | debugPanel->_setPosition(0.8, 0);
|
---|
2209 | debugPanel->_setDimensions(0.2, 0.3);
|
---|
2210 | debugPanel->setMaterialName("Ogre/DebugShadowMap");
|
---|
2211 | Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
|
---|
2212 | debugOverlay->add2D(debugPanel);
|
---|
2213 |
|
---|
2214 |
|
---|
2215 |
|
---|
2216 | ParticleSystem* pSys2 = ParticleSystemManager::getSingleton().createSystem("smoke",
|
---|
2217 | "Examples/Smoke");
|
---|
2218 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
|
---|
2219 | mTestNode[4]->attachObject(pSys2);
|
---|
2220 |
|
---|
2221 |
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | void testRenderToFloatTexture()
|
---|
2225 | {
|
---|
2226 | //mSceneMgr->setShadowFarDistance(800);
|
---|
2227 | // Set ambient light
|
---|
2228 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
2229 |
|
---|
2230 | mLight = mSceneMgr->createLight("MainLight");
|
---|
2231 |
|
---|
2232 | // Directional test
|
---|
2233 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
2234 | Vector3 vec(-1,-1,0);
|
---|
2235 | vec.normalise();
|
---|
2236 | mLight->setDirection(vec);
|
---|
2237 |
|
---|
2238 |
|
---|
2239 | Entity* pEnt;
|
---|
2240 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
2241 | mAnimState = pEnt->getAnimationState("Walk");
|
---|
2242 | mAnimState->setEnabled(true);
|
---|
2243 | //pEnt->setMaterialName("2 - Default");
|
---|
2244 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2245 | mTestNode[1]->attachObject( pEnt );
|
---|
2246 | mTestNode[1]->translate(0,-100,0);
|
---|
2247 |
|
---|
2248 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
2249 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
2250 | mTestNode[2]->attachObject( pEnt );
|
---|
2251 |
|
---|
2252 | // Transparent object (can force cast shadows)
|
---|
2253 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
|
---|
2254 | pEnt->setMaterialName("Examples/TransparentTest");
|
---|
2255 | MaterialPtr mat3 = MaterialManager::getSingleton().getByName("Examples/TransparentTest");
|
---|
2256 | mat3->setTransparencyCastsShadows(true);
|
---|
2257 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
|
---|
2258 | mTestNode[3]->attachObject( pEnt );
|
---|
2259 |
|
---|
2260 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
|
---|
2261 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2262 | msh->buildTangentVectors();
|
---|
2263 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
2264 | //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
|
---|
2265 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
2266 | mTestNode[2]->attachObject( pEnt );
|
---|
2267 |
|
---|
2268 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
2269 |
|
---|
2270 |
|
---|
2271 | Plane plane;
|
---|
2272 | plane.normal = Vector3::UNIT_Y;
|
---|
2273 | plane.d = 100;
|
---|
2274 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2275 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2276 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2277 | Entity* pPlaneEnt;
|
---|
2278 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2279 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2280 | pPlaneEnt->setCastShadows(false);
|
---|
2281 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2282 |
|
---|
2283 | RenderTexture* rttTex =
|
---|
2284 | mRoot->getRenderSystem()->createRenderTexture( "RttTex", 512, 512, TEX_TYPE_2D, PF_FLOAT32_RGB );
|
---|
2285 |
|
---|
2286 | Viewport *v = rttTex->addViewport( mCamera );
|
---|
2287 | v->setClearEveryFrame( true );
|
---|
2288 | v->setBackgroundColour( ColourValue::Black );
|
---|
2289 |
|
---|
2290 |
|
---|
2291 |
|
---|
2292 | // Set up a debug panel to display the RTT
|
---|
2293 | MaterialPtr debugMat = MaterialManager::getSingleton().create(
|
---|
2294 | "Ogre/DebugShadowMap", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2295 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
|
---|
2296 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
|
---|
2297 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2298 | //t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("spot_shadow_fade.png");
|
---|
2299 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2300 | //t->setColourOperation(LBO_ADD);
|
---|
2301 |
|
---|
2302 | OverlayContainer* debugPanel = (OverlayContainer*)
|
---|
2303 | (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel"));
|
---|
2304 | debugPanel->_setPosition(0.8, 0);
|
---|
2305 | debugPanel->_setDimensions(0.2, 0.3);
|
---|
2306 | debugPanel->setMaterialName("Ogre/DebugShadowMap");
|
---|
2307 | Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
|
---|
2308 | debugOverlay->add2D(debugPanel);
|
---|
2309 |
|
---|
2310 |
|
---|
2311 |
|
---|
2312 | ParticleSystem* pSys2 = ParticleSystemManager::getSingleton().createSystem("smoke",
|
---|
2313 | "Examples/Smoke");
|
---|
2314 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
|
---|
2315 | mTestNode[4]->attachObject(pSys2);
|
---|
2316 |
|
---|
2317 |
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 | void testOverlayZOrder(void)
|
---|
2321 | {
|
---|
2322 | Overlay* o = OverlayManager::getSingleton().getByName("Test/Overlay3");
|
---|
2323 | o->show();
|
---|
2324 | o = OverlayManager::getSingleton().getByName("Test/Overlay2");
|
---|
2325 | o->show();
|
---|
2326 | o = OverlayManager::getSingleton().getByName("Test/Overlay1");
|
---|
2327 | o->show();
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | void createRandomEntityClones(Entity* ent, size_t cloneCount,
|
---|
2331 | const Vector3& min, const Vector3& max)
|
---|
2332 | {
|
---|
2333 | Entity *cloneEnt;
|
---|
2334 | for (int n = 0; n < cloneCount; ++n)
|
---|
2335 | {
|
---|
2336 | // Create a new node under the root
|
---|
2337 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
2338 | // Random translate
|
---|
2339 | Vector3 nodePos;
|
---|
2340 | nodePos.x = Math::RangeRandom(min.x, max.x);
|
---|
2341 | nodePos.y = Math::RangeRandom(min.y, max.y);
|
---|
2342 | nodePos.z = Math::RangeRandom(min.z, max.z);
|
---|
2343 | node->setPosition(nodePos);
|
---|
2344 | mSceneMgr->getRootSceneNode()->addChild(node);
|
---|
2345 | cloneEnt = ent->clone(ent->getName() + "_clone" + StringConverter::toString(n));
|
---|
2346 | // Attach to new node
|
---|
2347 | node->attachObject(cloneEnt);
|
---|
2348 |
|
---|
2349 | }
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | void testIntersectionSceneQuery()
|
---|
2353 | {
|
---|
2354 | // Set ambient light
|
---|
2355 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2356 |
|
---|
2357 | // Create a point light
|
---|
2358 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2359 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2360 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2361 |
|
---|
2362 | // Create a set of random balls
|
---|
2363 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh");
|
---|
2364 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2365 | createRandomEntityClones(ent, 500, Vector3(-5000,-5000,-5000), Vector3(5000,5000,5000));
|
---|
2366 |
|
---|
2367 | //intersectionQuery = mSceneMgr->createIntersectionQuery();
|
---|
2368 | }
|
---|
2369 |
|
---|
2370 | void testRaySceneQuery()
|
---|
2371 | {
|
---|
2372 | // Set ambient light
|
---|
2373 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2374 |
|
---|
2375 | // Create a point light
|
---|
2376 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2377 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2378 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2379 |
|
---|
2380 | // Create a set of random balls
|
---|
2381 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh");
|
---|
2382 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2383 | createRandomEntityClones(ent, 100, Vector3(-1000,-1000,-1000), Vector3(1000,1000,1000));
|
---|
2384 |
|
---|
2385 | rayQuery = mSceneMgr->createRayQuery(
|
---|
2386 | Ray(mCamera->getPosition(), mCamera->getDirection()));
|
---|
2387 | rayQuery->setSortByDistance(true, 1);
|
---|
2388 |
|
---|
2389 | //bool val = true;
|
---|
2390 | //mSceneMgr->setOption("ShowOctree", &val);
|
---|
2391 |
|
---|
2392 | }
|
---|
2393 |
|
---|
2394 | void testLotsAndLotsOfEntities()
|
---|
2395 | {
|
---|
2396 | // Set ambient light
|
---|
2397 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2398 |
|
---|
2399 | // Create a point light
|
---|
2400 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2401 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2402 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2403 |
|
---|
2404 | // Create a set of random balls
|
---|
2405 | Entity* ent = mSceneMgr->createEntity("Ball", "ogrehead.mesh");
|
---|
2406 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2407 | createRandomEntityClones(ent, 400, Vector3(-2000,-2000,-2000), Vector3(2000,2000,2000));
|
---|
2408 |
|
---|
2409 | //bool val = true;
|
---|
2410 | //mSceneMgr->setOption("ShowOctree", &val);
|
---|
2411 |
|
---|
2412 | }
|
---|
2413 |
|
---|
2414 | void testSimpleMesh()
|
---|
2415 | {
|
---|
2416 | // Set ambient light
|
---|
2417 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2418 |
|
---|
2419 | // Create a point light
|
---|
2420 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2421 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2422 | Vector3 dir(1, -1, 0);
|
---|
2423 | dir.normalise();
|
---|
2424 | l->setDirection(dir);
|
---|
2425 |
|
---|
2426 | // Create a set of random balls
|
---|
2427 | Entity* ent = mSceneMgr->createEntity("test", "xsicylinder.mesh");
|
---|
2428 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2429 |
|
---|
2430 | }
|
---|
2431 |
|
---|
2432 | void test2Windows(void)
|
---|
2433 | {
|
---|
2434 | // Set ambient light
|
---|
2435 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2436 |
|
---|
2437 | // Create a point light
|
---|
2438 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2439 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2440 | Vector3 dir(1, -1, 0);
|
---|
2441 | dir.normalise();
|
---|
2442 | l->setDirection(dir);
|
---|
2443 |
|
---|
2444 | // Create a set of random balls
|
---|
2445 | Entity* ent = mSceneMgr->createEntity("test", "ogrehead.mesh");
|
---|
2446 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2447 |
|
---|
2448 | NameValuePairList valuePair;
|
---|
2449 | valuePair["top"] = StringConverter::toString(0);
|
---|
2450 | valuePair["left"] = StringConverter::toString(0);
|
---|
2451 |
|
---|
2452 | RenderWindow* win2 = mRoot->createRenderWindow("window2", 200,200, false, &valuePair);
|
---|
2453 | win2->addViewport(mCamera);
|
---|
2454 |
|
---|
2455 | }
|
---|
2456 |
|
---|
2457 | void testStaticGeometry(void)
|
---|
2458 | {
|
---|
2459 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
|
---|
2460 | //mSceneMgr->setShowDebugShadows(true);
|
---|
2461 |
|
---|
2462 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
|
---|
2463 | // Set ambient light
|
---|
2464 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2465 |
|
---|
2466 | // Create a point light
|
---|
2467 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2468 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2469 | Vector3 dir(1, -1, -1.5);
|
---|
2470 | dir.normalise();
|
---|
2471 | l->setDirection(dir);
|
---|
2472 | l->setDiffuseColour(1.0, 0.7, 0.0);
|
---|
2473 |
|
---|
2474 |
|
---|
2475 | Plane plane;
|
---|
2476 | plane.normal = Vector3::UNIT_Y;
|
---|
2477 | plane.d = 0;
|
---|
2478 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2479 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2480 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2481 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2482 | pPlaneEnt->setMaterialName("Examples/GrassFloor");
|
---|
2483 | pPlaneEnt->setCastShadows(false);
|
---|
2484 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2485 |
|
---|
2486 | Vector3 min(-2000,0,-2000);
|
---|
2487 | Vector3 max(2000,0,2000);
|
---|
2488 |
|
---|
2489 |
|
---|
2490 | Entity* e = mSceneMgr->createEntity("1", "column.mesh");
|
---|
2491 | //createRandomEntityClones(e, 1000, min, max);
|
---|
2492 |
|
---|
2493 | StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
|
---|
2494 | s->setCastShadows(true);
|
---|
2495 | s->setRegionDimensions(Vector3(500,500,500));
|
---|
2496 | for (int i = 0; i < 300; ++i)
|
---|
2497 | {
|
---|
2498 | Vector3 pos;
|
---|
2499 | pos.x = Math::RangeRandom(min.x, max.x);
|
---|
2500 | pos.y = Math::RangeRandom(min.y, max.y);
|
---|
2501 | pos.z = Math::RangeRandom(min.z, max.z);
|
---|
2502 |
|
---|
2503 | s->addEntity(e, pos, Quaternion::IDENTITY, Vector3(5,5,5));
|
---|
2504 |
|
---|
2505 | }
|
---|
2506 |
|
---|
2507 | s->build();
|
---|
2508 | //s->setRenderingDistance(1000);
|
---|
2509 | //s->dump("static.txt");
|
---|
2510 | //mSceneMgr->showBoundingBoxes(true);
|
---|
2511 | mCamera->setLodBias(0.5);
|
---|
2512 |
|
---|
2513 |
|
---|
2514 |
|
---|
2515 |
|
---|
2516 | }
|
---|
2517 |
|
---|
2518 | void testReloadResources()
|
---|
2519 | {
|
---|
2520 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
2521 | ResourceGroupManager::getSingleton().createResourceGroup("Sinbad");
|
---|
2522 | Root::getSingleton().addResourceLocation("../../../Media/models", "FileSystem", "Sinbad");
|
---|
2523 | MeshManager& mmgr = MeshManager::getSingleton();
|
---|
2524 | mmgr.load("robot.mesh", "Sinbad");
|
---|
2525 | mmgr.load("knot.mesh", "Sinbad");
|
---|
2526 |
|
---|
2527 | Entity* e = mSceneMgr->createEntity("1", "robot.mesh");
|
---|
2528 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
|
---|
2529 | e = mSceneMgr->createEntity("2", "robot.mesh");
|
---|
2530 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0))->attachObject(e);
|
---|
2531 | e = mSceneMgr->createEntity("3", "knot.mesh");
|
---|
2532 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,300,0))->attachObject(e);
|
---|
2533 |
|
---|
2534 | testreload = true;
|
---|
2535 |
|
---|
2536 | }
|
---|
2537 |
|
---|
2538 | void testDepthBias()
|
---|
2539 | {
|
---|
2540 | SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Entity");
|
---|
2541 | const String meshName("cube.mesh");
|
---|
2542 | Entity* entity;
|
---|
2543 |
|
---|
2544 | entity = mSceneMgr->createEntity("Entity", meshName);
|
---|
2545 | entity->setMaterialName("Entity");
|
---|
2546 | node->attachObject(entity);
|
---|
2547 |
|
---|
2548 | for (size_t i = 0; i <= 6;++i)
|
---|
2549 | {
|
---|
2550 | String name("Decal");
|
---|
2551 | name += StringConverter::toString(i);
|
---|
2552 |
|
---|
2553 | MaterialPtr pMat = static_cast<MaterialPtr>(MaterialManager::getSingleton().create(
|
---|
2554 | name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME));
|
---|
2555 |
|
---|
2556 | pMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
|
---|
2557 | pMat->getTechnique(0)->getPass(0)->setAlphaRejectSettings(CMPF_GREATER_EQUAL, 128);
|
---|
2558 | pMat->getTechnique(0)->getPass(0)->setDepthBias(i);
|
---|
2559 | pMat->getTechnique(0)->getPass(0)->createTextureUnitState(name + ".png");
|
---|
2560 |
|
---|
2561 | entity = mSceneMgr->createEntity(name, meshName);
|
---|
2562 | entity->setMaterialName(name);
|
---|
2563 | node->attachObject(entity);
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 | node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Entity2",
|
---|
2567 | Vector3(-50.0, 0.0, 50.0), Quaternion(Degree(45.0), Vector3::UNIT_Z));
|
---|
2568 | entity = mSceneMgr->createEntity("Entity2", meshName);
|
---|
2569 | entity->setMaterialName("Examples/RustySteel");
|
---|
2570 | node->attachObject(entity);
|
---|
2571 |
|
---|
2572 | mCamera->setPosition(70.0, 90.0, 220.0);
|
---|
2573 | mCamera->lookAt(Vector3::ZERO);
|
---|
2574 | }
|
---|
2575 |
|
---|
2576 | void testPerf()
|
---|
2577 | {
|
---|
2578 | int count = 0;
|
---|
2579 | Entity* ent;
|
---|
2580 | SceneNode *node;
|
---|
2581 | for (int i = 0; i < 21; i++)
|
---|
2582 | for(int j = 0; j < 21; j++)
|
---|
2583 | {
|
---|
2584 | char tmp[64];
|
---|
2585 | sprintf(tmp, "Trial_%d", count);
|
---|
2586 | count++;
|
---|
2587 | ent = mSceneMgr->createEntity(tmp,"cube.mesh");
|
---|
2588 | node =mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2589 | node->attachObject( ent );
|
---|
2590 | node->setPosition(i*100, 0, j*100);
|
---|
2591 | }
|
---|
2592 |
|
---|
2593 | mCamera->setPosition(Vector3(3000,1000,3000));
|
---|
2594 | mCamera->lookAt(Vector3(0,0,0));
|
---|
2595 | }
|
---|
2596 | void testSphere(const std::string& strName, const float r, const int nRings = 16, const int nSegments = 16)
|
---|
2597 | {
|
---|
2598 | MeshPtr pSphere = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2599 | SubMesh *pSphereVertex = pSphere->createSubMesh();
|
---|
2600 |
|
---|
2601 | pSphere->sharedVertexData = new VertexData();
|
---|
2602 | VertexData* vertexData = pSphere->sharedVertexData;
|
---|
2603 |
|
---|
2604 | // define the vertex format
|
---|
2605 | VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
|
---|
2606 | size_t currOffset = 0;
|
---|
2607 | // positions
|
---|
2608 | vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION);
|
---|
2609 | currOffset += VertexElement::getTypeSize(VET_FLOAT3);
|
---|
2610 | // normals
|
---|
2611 | vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL);
|
---|
2612 | currOffset += VertexElement::getTypeSize(VET_FLOAT3);
|
---|
2613 | // two dimensional texture coordinates
|
---|
2614 | vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
|
---|
2615 | currOffset += VertexElement::getTypeSize(VET_FLOAT2);
|
---|
2616 |
|
---|
2617 | // allocate the vertex buffer
|
---|
2618 | vertexData->vertexCount = (nRings + 1) * (nSegments+1);
|
---|
2619 | HardwareVertexBufferSharedPtr vBuf = HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
2620 | VertexBufferBinding* binding = vertexData->vertexBufferBinding;
|
---|
2621 | binding->setBinding(0, vBuf);
|
---|
2622 | float* pVertex = static_cast<float*>(vBuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
2623 |
|
---|
2624 | // allocate index buffer
|
---|
2625 | pSphereVertex->indexData->indexCount = 6 * nRings * (nSegments + 1);
|
---|
2626 | pSphereVertex->indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, pSphereVertex->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
2627 | HardwareIndexBufferSharedPtr iBuf = pSphereVertex->indexData->indexBuffer;
|
---|
2628 | unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
2629 |
|
---|
2630 | float fDeltaRingAngle = (Math::PI / nRings);
|
---|
2631 | float fDeltaSegAngle = (2 * Math::PI / nSegments);
|
---|
2632 | unsigned short wVerticeIndex = 0 ;
|
---|
2633 |
|
---|
2634 | // Generate the group of rings for the sphere
|
---|
2635 | for( int ring = 0; ring <= nRings; ring++ ) {
|
---|
2636 | float r0 = r * sinf (ring * fDeltaRingAngle);
|
---|
2637 | float y0 = r * cosf (ring * fDeltaRingAngle);
|
---|
2638 |
|
---|
2639 | // Generate the group of segments for the current ring
|
---|
2640 | for(int seg = 0; seg <= nSegments; seg++) {
|
---|
2641 | float x0 = r0 * sinf(seg * fDeltaSegAngle);
|
---|
2642 | float z0 = r0 * cosf(seg * fDeltaSegAngle);
|
---|
2643 |
|
---|
2644 | // Add one vertex to the strip which makes up the sphere
|
---|
2645 | *pVertex++ = x0;
|
---|
2646 | *pVertex++ = y0;
|
---|
2647 | *pVertex++ = z0;
|
---|
2648 |
|
---|
2649 | Vector3 vNormal = Vector3(x0, y0, z0).normalisedCopy();
|
---|
2650 | *pVertex++ = vNormal.x;
|
---|
2651 | *pVertex++ = vNormal.y;
|
---|
2652 | *pVertex++ = vNormal.z;
|
---|
2653 |
|
---|
2654 | *pVertex++ = (float) seg / (float) nSegments;
|
---|
2655 | *pVertex++ = (float) ring / (float) nRings;
|
---|
2656 |
|
---|
2657 | if (ring != nRings) {
|
---|
2658 | // each vertex (except the last) has six indices pointing to it
|
---|
2659 | *pIndices++ = wVerticeIndex + nSegments + 1;
|
---|
2660 | *pIndices++ = wVerticeIndex;
|
---|
2661 | *pIndices++ = wVerticeIndex + nSegments;
|
---|
2662 | *pIndices++ = wVerticeIndex + nSegments + 1;
|
---|
2663 | *pIndices++ = wVerticeIndex + 1;
|
---|
2664 | *pIndices++ = wVerticeIndex;
|
---|
2665 | wVerticeIndex ++;
|
---|
2666 | }
|
---|
2667 | }; // end for seg
|
---|
2668 | } // end for ring
|
---|
2669 |
|
---|
2670 | // Unlock
|
---|
2671 | vBuf->unlock();
|
---|
2672 | iBuf->unlock();
|
---|
2673 | // Generate face list
|
---|
2674 | pSphereVertex->useSharedVertices = true;
|
---|
2675 |
|
---|
2676 | // the original code was missing this line:
|
---|
2677 | pSphere->_setBounds( AxisAlignedBox( Vector3(-r, -r, -r), Vector3(r, r, r) ), false );
|
---|
2678 | pSphere->_setBoundingSphereRadius(r);
|
---|
2679 | // this line makes clear the mesh is loaded (avoids memory leaks)
|
---|
2680 | pSphere->load();
|
---|
2681 |
|
---|
2682 | pSphere->unload();
|
---|
2683 | }
|
---|
2684 |
|
---|
2685 | void testColourCube()
|
---|
2686 | {
|
---|
2687 | /// Create the mesh via the MeshManager
|
---|
2688 | Ogre::MeshPtr msh = MeshManager::getSingleton().createManual("ColourCube", "General");
|
---|
2689 |
|
---|
2690 | /// Create one submesh
|
---|
2691 | SubMesh* sub = msh->createSubMesh();
|
---|
2692 |
|
---|
2693 | const float sqrt13 = 0.577350269f; /* sqrt(1/3) */
|
---|
2694 |
|
---|
2695 | /// Define the vertices (8 vertices, each consisting of 3 groups of 3 floats
|
---|
2696 | const size_t nVertices = 8;
|
---|
2697 | const size_t vbufCount = 3*2*nVertices;
|
---|
2698 | float vertices[vbufCount] = {
|
---|
2699 | -100.0,100.0,-100.0, //0 position
|
---|
2700 | -sqrt13,sqrt13,-sqrt13, //0 normal
|
---|
2701 | 100.0,100.0,-100.0, //1 position
|
---|
2702 | sqrt13,sqrt13,-sqrt13, //1 normal
|
---|
2703 | 100.0,-100.0,-100.0, //2 position
|
---|
2704 | sqrt13,-sqrt13,-sqrt13, //2 normal
|
---|
2705 | -100.0,-100.0,-100.0, //3 position
|
---|
2706 | -sqrt13,-sqrt13,-sqrt13, //3 normal
|
---|
2707 | -100.0,100.0,100.0, //4 position
|
---|
2708 | -sqrt13,sqrt13,sqrt13, //4 normal
|
---|
2709 | 100.0,100.0,100.0, //5 position
|
---|
2710 | sqrt13,sqrt13,sqrt13, //5 normal
|
---|
2711 | 100.0,-100.0,100.0, //6 position
|
---|
2712 | sqrt13,-sqrt13,sqrt13, //6 normal
|
---|
2713 | -100.0,-100.0,100.0, //7 position
|
---|
2714 | -sqrt13,-sqrt13,sqrt13, //7 normal
|
---|
2715 | };
|
---|
2716 |
|
---|
2717 | RenderSystem* rs = Root::getSingleton().getRenderSystem();
|
---|
2718 | RGBA colours[nVertices];
|
---|
2719 | RGBA *pColour = colours;
|
---|
2720 | // Use render system to convert colour value since colour packing varies
|
---|
2721 | rs->convertColourValue(ColourValue(1.0,0.0,0.0), pColour++); //0 colour
|
---|
2722 | rs->convertColourValue(ColourValue(1.0,1.0,0.0), pColour++); //1 colour
|
---|
2723 | rs->convertColourValue(ColourValue(0.0,1.0,0.0), pColour++); //2 colour
|
---|
2724 | rs->convertColourValue(ColourValue(0.0,0.0,0.0), pColour++); //3 colour
|
---|
2725 | rs->convertColourValue(ColourValue(1.0,0.0,1.0), pColour++); //4 colour
|
---|
2726 | rs->convertColourValue(ColourValue(1.0,1.0,1.0), pColour++); //5 colour
|
---|
2727 | rs->convertColourValue(ColourValue(0.0,1.0,1.0), pColour++); //6 colour
|
---|
2728 | rs->convertColourValue(ColourValue(0.0,0.0,1.0), pColour++); //7 colour
|
---|
2729 |
|
---|
2730 | /// Define 12 triangles (two triangles per cube face)
|
---|
2731 | /// The values in this table refer to vertices in the above table
|
---|
2732 | const size_t ibufCount = 36;
|
---|
2733 | unsigned short faces[ibufCount] = {
|
---|
2734 | 0,2,3,
|
---|
2735 | 0,1,2,
|
---|
2736 | 1,6,2,
|
---|
2737 | 1,5,6,
|
---|
2738 | 4,6,5,
|
---|
2739 | 4,7,6,
|
---|
2740 | 0,7,4,
|
---|
2741 | 0,3,7,
|
---|
2742 | 0,5,1,
|
---|
2743 | 0,4,5,
|
---|
2744 | 2,7,3,
|
---|
2745 | 2,6,7
|
---|
2746 | };
|
---|
2747 |
|
---|
2748 | /// Create vertex data structure for 8 vertices shared between submeshes
|
---|
2749 | msh->sharedVertexData = new VertexData();
|
---|
2750 | msh->sharedVertexData->vertexCount = nVertices;
|
---|
2751 |
|
---|
2752 | /// Create declaration (memory format) of vertex data
|
---|
2753 | VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
|
---|
2754 | size_t offset = 0;
|
---|
2755 | // 1st buffer
|
---|
2756 | decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
|
---|
2757 | offset += VertexElement::getTypeSize(VET_FLOAT3);
|
---|
2758 | decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
|
---|
2759 | offset += VertexElement::getTypeSize(VET_FLOAT3);
|
---|
2760 | /// Allocate vertex buffer of the requested number of vertices (vertexCount)
|
---|
2761 | /// and bytes per vertex (offset)
|
---|
2762 | HardwareVertexBufferSharedPtr vbuf =
|
---|
2763 | HardwareBufferManager::getSingleton().createVertexBuffer(
|
---|
2764 | offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
2765 | /// Upload the vertex data to the card
|
---|
2766 | vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
|
---|
2767 |
|
---|
2768 | /// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
|
---|
2769 | VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
|
---|
2770 | bind->setBinding(0, vbuf);
|
---|
2771 |
|
---|
2772 | // 2nd buffer
|
---|
2773 | offset = 0;
|
---|
2774 | decl->addElement(1, offset, VET_COLOUR, VES_DIFFUSE);
|
---|
2775 | offset += VertexElement::getTypeSize(VET_COLOUR);
|
---|
2776 | /// Allocate vertex buffer of the requested number of vertices (vertexCount)
|
---|
2777 | /// and bytes per vertex (offset)
|
---|
2778 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
|
---|
2779 | offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
2780 | /// Upload the vertex data to the card
|
---|
2781 | vbuf->writeData(0, vbuf->getSizeInBytes(), colours, true);
|
---|
2782 |
|
---|
2783 | /// Set vertex buffer binding so buffer 1 is bound to our colour buffer
|
---|
2784 | bind->setBinding(1, vbuf);
|
---|
2785 |
|
---|
2786 | /// Allocate index buffer of the requested number of vertices (ibufCount)
|
---|
2787 | HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
|
---|
2788 | createIndexBuffer(
|
---|
2789 | HardwareIndexBuffer::IT_16BIT,
|
---|
2790 | ibufCount,
|
---|
2791 | HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
---|
2792 |
|
---|
2793 | /// Upload the index data to the card
|
---|
2794 | ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
|
---|
2795 |
|
---|
2796 | /// Set parameters of the submesh
|
---|
2797 | sub->useSharedVertices = true;
|
---|
2798 | sub->indexData->indexBuffer = ibuf;
|
---|
2799 | sub->indexData->indexCount = ibufCount;
|
---|
2800 | sub->indexData->indexStart = 0;
|
---|
2801 |
|
---|
2802 | /// Set bounding information (for culling)
|
---|
2803 | msh->_setBounds(AxisAlignedBox(-100,-100,0,100,100,0));
|
---|
2804 | msh->_setBoundingSphereRadius(Math::Sqrt(100*100+100*100));
|
---|
2805 |
|
---|
2806 | /// Notify Mesh object that it has been loaded
|
---|
2807 | msh->load();
|
---|
2808 |
|
---|
2809 |
|
---|
2810 | MaterialPtr mat = MaterialManager::getSingleton().create(
|
---|
2811 | "Test/ColourTest", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2812 | mat->getTechnique(0)->getPass(0)->setVertexColourTracking(TVC_AMBIENT);
|
---|
2813 |
|
---|
2814 | Entity* thisEntity = mSceneMgr->createEntity("cc", "ColourCube");
|
---|
2815 | thisEntity->setMaterialName("Test/ColourTest");
|
---|
2816 | SceneNode* thisSceneNode = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild());
|
---|
2817 | thisSceneNode->setPosition(-35, 0, 0);
|
---|
2818 | thisSceneNode->attachObject(thisEntity);
|
---|
2819 |
|
---|
2820 | }
|
---|
2821 | void testSplitPassesTooManyTexUnits()
|
---|
2822 | {
|
---|
2823 | MaterialPtr mat = MaterialManager::getSingleton().create(
|
---|
2824 | "Test", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2825 |
|
---|
2826 | Pass* p = mat->getTechnique(0)->getPass(0);
|
---|
2827 | p->createTextureUnitState("gras_02.png");
|
---|
2828 | p->createTextureUnitState("gras_02.png");
|
---|
2829 | p->createTextureUnitState("gras_02.png");
|
---|
2830 | p->createTextureUnitState("gras_02.png");
|
---|
2831 | p->createTextureUnitState("gras_02.png");
|
---|
2832 | p->createTextureUnitState("gras_02.png");
|
---|
2833 | p->createTextureUnitState("gras_02.png");
|
---|
2834 | p->createTextureUnitState("gras_02.png");
|
---|
2835 | p->createTextureUnitState("gras_02.png");
|
---|
2836 |
|
---|
2837 | mat->compile();
|
---|
2838 |
|
---|
2839 | }
|
---|
2840 | // Just override the mandatory create scene method
|
---|
2841 | void createScene(void)
|
---|
2842 | {
|
---|
2843 | //testMatrices();
|
---|
2844 | //testBsp();
|
---|
2845 | //testAlpha();
|
---|
2846 | //testAnimation();
|
---|
2847 |
|
---|
2848 | //testGpuPrograms();
|
---|
2849 | //testMultiViewports();
|
---|
2850 | //testDistortion();
|
---|
2851 | //testEdgeBuilderSingleIndexBufSingleVertexBuf();
|
---|
2852 | //testEdgeBuilderMultiIndexBufSingleVertexBuf();
|
---|
2853 | //testEdgeBuilderMultiIndexBufMultiVertexBuf();
|
---|
2854 | //testPrepareShadowVolume();
|
---|
2855 | //testWindowedViewportMode();
|
---|
2856 | //testSubEntityVisibility();
|
---|
2857 | //testAttachObjectsToBones();
|
---|
2858 | //testSkeletalAnimation();
|
---|
2859 | //testOrtho();
|
---|
2860 | //testClearScene();
|
---|
2861 |
|
---|
2862 | //testProjection();
|
---|
2863 | //testStencilShadows(SHADOWTYPE_STENCIL_ADDITIVE, true, true);
|
---|
2864 | //testStencilShadows(SHADOWTYPE_STENCIL_MODULATIVE, false, true);
|
---|
2865 | //testTextureShadows(true);
|
---|
2866 | testSplitPassesTooManyTexUnits();
|
---|
2867 | //testOverlayZOrder();
|
---|
2868 |
|
---|
2869 | //testRaySceneQuery();
|
---|
2870 | //testSphere("MrSphere", 100);
|
---|
2871 | //testIntersectionSceneQuery();
|
---|
2872 |
|
---|
2873 | //test2Spotlights();
|
---|
2874 |
|
---|
2875 | //testManualLOD();
|
---|
2876 | //testLotsAndLotsOfEntities();
|
---|
2877 | //testSimpleMesh();
|
---|
2878 | //test2Windows();
|
---|
2879 | //testStaticGeometry();
|
---|
2880 | //testBug();
|
---|
2881 | //testReloadResources();
|
---|
2882 | //testTransparencyMipMaps();
|
---|
2883 | //testDepthBias();
|
---|
2884 | //testPerf();
|
---|
2885 | //testColourCube();
|
---|
2886 | //testReflectedBillboards();
|
---|
2887 |
|
---|
2888 | }
|
---|
2889 | // Create new frame listener
|
---|
2890 | void createFrameListener(void)
|
---|
2891 | {
|
---|
2892 | mFrameListener= new PlayPenListener(mSceneMgr, mWindow, mCamera);
|
---|
2893 | mFrameListener->showDebugOverlay(true);
|
---|
2894 | mRoot->addFrameListener(mFrameListener);
|
---|
2895 | //FrameListener* fl = new UberSimpleFrameListener(mWindow, mCamera);
|
---|
2896 | //mRoot->addFrameListener(fl);
|
---|
2897 |
|
---|
2898 | }
|
---|
2899 |
|
---|
2900 |
|
---|
2901 | public:
|
---|
2902 | void go(void)
|
---|
2903 | {
|
---|
2904 | if (!setup())
|
---|
2905 | return;
|
---|
2906 |
|
---|
2907 | mRoot->startRendering();
|
---|
2908 | }
|
---|
2909 |
|
---|
2910 |
|
---|
2911 | };
|
---|
2912 |
|
---|
2913 |
|
---|
2914 |
|
---|
2915 | //-----------------------------------------------------------------------------
|
---|
2916 | //-----------------------------------------------------------------------------
|
---|
2917 | class SwitchApplication : public ExampleApplication
|
---|
2918 | {
|
---|
2919 | public:
|
---|
2920 | SwitchApplication() { }
|
---|
2921 | ~SwitchApplication() { }
|
---|
2922 |
|
---|
2923 | bool frameStarted(const FrameEvent &evt);
|
---|
2924 | void cleanup();
|
---|
2925 | void scene1();
|
---|
2926 | void scene2();
|
---|
2927 | Camera* getCamera() { return mCamera; }
|
---|
2928 |
|
---|
2929 | protected:
|
---|
2930 | AnimationState *mAnimationState;
|
---|
2931 |
|
---|
2932 | void createCamera() { }
|
---|
2933 | void createViewports() { }
|
---|
2934 | void chooseSceneManager(void) { }
|
---|
2935 | void createScene(void) { scene1(); }
|
---|
2936 |
|
---|
2937 | void createFrameListener(void);
|
---|
2938 | };
|
---|
2939 |
|
---|
2940 |
|
---|
2941 | class SwitchListener : public ExampleFrameListener
|
---|
2942 | {
|
---|
2943 | protected:
|
---|
2944 | SwitchApplication* mApp;
|
---|
2945 | public:
|
---|
2946 | SwitchListener(SwitchApplication* app, RenderWindow* win, Camera* cam)
|
---|
2947 | : ExampleFrameListener(win, cam, false, false)
|
---|
2948 | {
|
---|
2949 | mApp = app;
|
---|
2950 | }
|
---|
2951 |
|
---|
2952 | bool frameStarted(const FrameEvent &evt);
|
---|
2953 | };
|
---|
2954 |
|
---|
2955 |
|
---|
2956 | bool SwitchListener::frameStarted(const FrameEvent &evt)
|
---|
2957 | {
|
---|
2958 | if ( mInputDevice->isKeyDown( KC_1 ) && (mTimeUntilNextToggle < 0.0f))
|
---|
2959 | {
|
---|
2960 | mApp->cleanup();
|
---|
2961 | mApp->scene1();
|
---|
2962 | mCamera = mApp->getCamera();
|
---|
2963 | mTimeUntilNextToggle = 0.5f;
|
---|
2964 | }
|
---|
2965 |
|
---|
2966 | if ( mInputDevice->isKeyDown( KC_2 ) && (mTimeUntilNextToggle < 0.0f))
|
---|
2967 | {
|
---|
2968 | mApp->cleanup();
|
---|
2969 | mApp->scene2();
|
---|
2970 | mCamera = mApp->getCamera();
|
---|
2971 | mTimeUntilNextToggle = 0.5f;
|
---|
2972 | }
|
---|
2973 |
|
---|
2974 | mApp->frameStarted(evt); // for processing animation
|
---|
2975 | return ExampleFrameListener::frameStarted(evt);
|
---|
2976 | }
|
---|
2977 |
|
---|
2978 | bool SwitchApplication::frameStarted(const FrameEvent &evt)
|
---|
2979 | {
|
---|
2980 | if(mAnimationState)
|
---|
2981 | mAnimationState->addTime(evt.timeSinceLastFrame);
|
---|
2982 | return true;
|
---|
2983 | }
|
---|
2984 |
|
---|
2985 | void SwitchApplication::cleanup()
|
---|
2986 | {
|
---|
2987 | mAnimationState = 0;
|
---|
2988 | mWindow->removeAllViewports();
|
---|
2989 | mSceneMgr->removeAllCameras();
|
---|
2990 | mSceneMgr->clearScene();
|
---|
2991 | }
|
---|
2992 |
|
---|
2993 | void SwitchApplication::scene1()
|
---|
2994 | {
|
---|
2995 | mSceneMgr = Root::getSingleton().getSceneManager(ST_EXTERIOR_CLOSE);
|
---|
2996 | mCamera = mSceneMgr->createCamera("camera1");
|
---|
2997 | mCamera->setNearClipDistance(1);
|
---|
2998 | mCamera->setPosition(400, 100, 850);
|
---|
2999 | mCamera->lookAt(490, 100, 590);
|
---|
3000 | mWindow->addViewport(mCamera);
|
---|
3001 |
|
---|
3002 | mSceneMgr->setWorldGeometry( "Terrain.cfg" );
|
---|
3003 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 1000 );
|
---|
3004 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
|
---|
3005 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
3006 |
|
---|
3007 | Light *light = mSceneMgr->createLight("Light1");
|
---|
3008 | light->setPosition(Vector3(-1000, 1000, 1000));
|
---|
3009 | light->setType(Light::LT_DIRECTIONAL);
|
---|
3010 | Vector3 direction = Vector3(1.5, -.6, -1.2);
|
---|
3011 | direction.normalise();
|
---|
3012 | light->setDirection(direction);
|
---|
3013 | light->setDiffuseColour(ColourValue(.95, .95, .5));
|
---|
3014 | light->setSpecularColour(ColourValue(.95, .95, .5));
|
---|
3015 |
|
---|
3016 |
|
---|
3017 | Entity *ent = mSceneMgr->createEntity( "Robot", "robot.mesh" );
|
---|
3018 | ent->setMaterialName( "Examples/Rocky" );
|
---|
3019 | SceneNode *sn;
|
---|
3020 | sn = mSceneMgr->getRootSceneNode()->createChildSceneNode("RobotNode");
|
---|
3021 | sn->attachObject(ent);
|
---|
3022 | sn->setPosition(490,100,590);
|
---|
3023 |
|
---|
3024 | mAnimationState = ent->getAnimationState( "Idle" );
|
---|
3025 | mAnimationState->setLoop( true );
|
---|
3026 | mAnimationState->setEnabled( true );
|
---|
3027 | }
|
---|
3028 |
|
---|
3029 | void SwitchApplication::scene2()
|
---|
3030 | {
|
---|
3031 | mSceneMgr = Root::getSingleton().getSceneManager(ST_GENERIC);
|
---|
3032 | mCamera = mSceneMgr->createCamera("camera1");
|
---|
3033 | mCamera->setNearClipDistance(1);
|
---|
3034 | mCamera->setPosition(0, 10, 300);
|
---|
3035 | mCamera->lookAt(0, 0, 0);
|
---|
3036 | mWindow->addViewport(mCamera);
|
---|
3037 |
|
---|
3038 | mSceneMgr->setSkyBox(true,"Examples/EveningSkyBox", 1000);
|
---|
3039 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
|
---|
3040 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
|
---|
3041 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
3042 |
|
---|
3043 | Light *light = mSceneMgr->createLight("Light2");
|
---|
3044 | light->setPosition(Vector3(-1000, 1000, 1000));
|
---|
3045 | light->setType(Light::LT_DIRECTIONAL);
|
---|
3046 | Vector3 direction = Vector3(1.5, -.6, -1.2);
|
---|
3047 | direction.normalise();
|
---|
3048 | light->setDirection(direction);
|
---|
3049 | light->setDiffuseColour(ColourValue(.95, .95, .5));
|
---|
3050 | light->setSpecularColour(ColourValue(.95, .95, .5));
|
---|
3051 |
|
---|
3052 | Plane plane(Vector3::UNIT_Y, 0);
|
---|
3053 | MeshManager::getSingleton().createPlane("ground",
|
---|
3054 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3055 | 3000,1000,30,10,true,1,30,10,Vector3::UNIT_Z);
|
---|
3056 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
---|
3057 |
|
---|
3058 | Entity *ent = mSceneMgr->createEntity("groundEnt", "ground");
|
---|
3059 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3060 | ent->setMaterialName("Examples/Water5");
|
---|
3061 | ent->setCastShadows(false);
|
---|
3062 |
|
---|
3063 | SceneNode *sn;
|
---|
3064 | ent = mSceneMgr->createEntity ("ogreEnt", "ogrehead.mesh");
|
---|
3065 | ent->setMaterialName("Examples/TransparentTest");
|
---|
3066 | sn = mSceneMgr->getRootSceneNode()->createChildSceneNode("ogreNode");
|
---|
3067 | sn->attachObject(ent);
|
---|
3068 | sn->setPosition(0, 30, 0);
|
---|
3069 | }
|
---|
3070 |
|
---|
3071 |
|
---|
3072 | void SwitchApplication::createFrameListener(void)
|
---|
3073 | {
|
---|
3074 | mFrameListener = new SwitchListener(this, mWindow, mCamera);
|
---|
3075 | mFrameListener->showDebugOverlay(true);
|
---|
3076 | mRoot->addFrameListener(mFrameListener);
|
---|
3077 | }
|
---|
3078 | //-----------------------------------------------------------------------------
|
---|
3079 | //-----------------------------------------------------------------------------
|
---|
3080 | bool gReload;
|
---|
3081 |
|
---|
3082 | // Listener class for frame updates
|
---|
3083 | class MemoryTestFrameListener : public FrameListener, public KeyListener
|
---|
3084 | {
|
---|
3085 | protected:
|
---|
3086 | Real time;
|
---|
3087 | EventProcessor* mEventProcessor;
|
---|
3088 | InputReader* mInputDevice;
|
---|
3089 | public:
|
---|
3090 | MemoryTestFrameListener(RenderWindow * win)
|
---|
3091 | {
|
---|
3092 | time = 0;
|
---|
3093 | mEventProcessor = new EventProcessor();
|
---|
3094 | mEventProcessor->initialise(win);
|
---|
3095 | mEventProcessor->startProcessingEvents();
|
---|
3096 | mEventProcessor->addKeyListener(this);
|
---|
3097 | mInputDevice = mEventProcessor->getInputReader();
|
---|
3098 | }
|
---|
3099 | virtual ~MemoryTestFrameListener()
|
---|
3100 | {
|
---|
3101 | time = 0;
|
---|
3102 | delete mEventProcessor;
|
---|
3103 | }
|
---|
3104 |
|
---|
3105 | bool frameStarted(const FrameEvent& evt)
|
---|
3106 | {
|
---|
3107 | if( mInputDevice->isKeyDown( KC_ESCAPE) )
|
---|
3108 | {
|
---|
3109 | gReload = false;
|
---|
3110 | return false;
|
---|
3111 | }
|
---|
3112 |
|
---|
3113 | time += evt.timeSinceLastFrame;
|
---|
3114 | if(time>5)
|
---|
3115 | {
|
---|
3116 | LogManager::getSingleton().logMessage("Reloading scene after 5 seconds");
|
---|
3117 | gReload = true;
|
---|
3118 | time=0;
|
---|
3119 | return false;
|
---|
3120 | }
|
---|
3121 | else
|
---|
3122 | {
|
---|
3123 | gReload = false;
|
---|
3124 | return true;
|
---|
3125 | }
|
---|
3126 | }
|
---|
3127 |
|
---|
3128 | void keyClicked(KeyEvent* e) {};
|
---|
3129 | void keyPressed(KeyEvent* e) {};
|
---|
3130 | void keyReleased(KeyEvent* e) {};
|
---|
3131 | void keyFocusIn(KeyEvent* e) {}
|
---|
3132 | void keyFocusOut(KeyEvent* e) {}
|
---|
3133 | };
|
---|
3134 |
|
---|
3135 | /** Application class */
|
---|
3136 | class MemoryTestApplication : public ExampleApplication
|
---|
3137 | {
|
---|
3138 | protected:
|
---|
3139 | MemoryTestFrameListener * mTestFrameListener;
|
---|
3140 | public:
|
---|
3141 |
|
---|
3142 | void go(void)
|
---|
3143 | {
|
---|
3144 | mRoot = 0;
|
---|
3145 | if (!setup())
|
---|
3146 | return;
|
---|
3147 |
|
---|
3148 | mRoot->startRendering();
|
---|
3149 |
|
---|
3150 | while(gReload)
|
---|
3151 | {
|
---|
3152 | // clean up
|
---|
3153 | destroyScene();
|
---|
3154 | destroyResources();
|
---|
3155 | if (!setup())
|
---|
3156 | return;
|
---|
3157 | mRoot->startRendering();
|
---|
3158 | }
|
---|
3159 | // clean up
|
---|
3160 | destroyScene();
|
---|
3161 | }
|
---|
3162 |
|
---|
3163 | bool setup(void)
|
---|
3164 | {
|
---|
3165 | if(!gReload)
|
---|
3166 | mRoot = new Root();
|
---|
3167 |
|
---|
3168 | setupResources();
|
---|
3169 |
|
---|
3170 | if(!gReload)
|
---|
3171 | {
|
---|
3172 | bool carryOn = configure();
|
---|
3173 | if (!carryOn)
|
---|
3174 | return false;
|
---|
3175 |
|
---|
3176 | chooseSceneManager();
|
---|
3177 | createCamera();
|
---|
3178 | createViewports();
|
---|
3179 |
|
---|
3180 | // Set default mipmap level (NB some APIs ignore this)
|
---|
3181 | TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
---|
3182 |
|
---|
3183 | // Create any resource listeners (for loading screens)
|
---|
3184 | createResourceListener();
|
---|
3185 |
|
---|
3186 | createFrameListener();
|
---|
3187 | }
|
---|
3188 | // Load resources
|
---|
3189 | loadResources();
|
---|
3190 |
|
---|
3191 | // Create the scene
|
---|
3192 | createScene();
|
---|
3193 |
|
---|
3194 | return true;
|
---|
3195 |
|
---|
3196 | }
|
---|
3197 |
|
---|
3198 | /// Method which will define the source of resources (other than current folder)
|
---|
3199 | virtual void setupResources(void)
|
---|
3200 | {
|
---|
3201 | // Custom setup
|
---|
3202 | ResourceGroupManager::getSingleton().createResourceGroup("CustomResourceGroup");
|
---|
3203 | ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
3204 | "../../../media/ogrehead.zip", "Zip", "CustomResourceGroup");
|
---|
3205 | }
|
---|
3206 | void loadResources(void)
|
---|
3207 | {
|
---|
3208 | // Initialise, parse scripts etc
|
---|
3209 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
---|
3210 | }
|
---|
3211 | void destroyResources()
|
---|
3212 | {
|
---|
3213 | LogManager::getSingleton().logMessage("Destroying resources");
|
---|
3214 | ResourceGroupManager::getSingleton().removeResourceLocation(
|
---|
3215 | "../../../media/ogrehead.zip");
|
---|
3216 | ResourceGroupManager::getSingleton().destroyResourceGroup("CustomResourceGroup");
|
---|
3217 | }
|
---|
3218 |
|
---|
3219 | void createScene(void)
|
---|
3220 | {
|
---|
3221 | // Set a very low level of ambient lighting
|
---|
3222 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
3223 |
|
---|
3224 | // Load ogre head
|
---|
3225 | MeshManager::getSingleton().load("ogrehead.mesh","CustomResourceGroup");
|
---|
3226 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
3227 |
|
---|
3228 | // Attach the head to the scene
|
---|
3229 | mSceneMgr->getRootSceneNode()->attachObject(head);
|
---|
3230 |
|
---|
3231 | }
|
---|
3232 |
|
---|
3233 | void createFrameListener(void)
|
---|
3234 | {
|
---|
3235 | // This is where we instantiate our own frame listener
|
---|
3236 | mTestFrameListener= new MemoryTestFrameListener(mWindow);
|
---|
3237 | mRoot->addFrameListener(mTestFrameListener);
|
---|
3238 | /*if(!gReload)
|
---|
3239 | {
|
---|
3240 | ExampleApplication::createFrameListener();
|
---|
3241 | }*/
|
---|
3242 | }
|
---|
3243 |
|
---|
3244 | void destroyScene(void)
|
---|
3245 | {
|
---|
3246 | LogManager::getSingleton().logMessage("Clearing scene");
|
---|
3247 | mSceneMgr->clearScene();
|
---|
3248 | }
|
---|
3249 | };
|
---|
3250 | //-----------------------------------------------------------------------------
|
---|
3251 | //-----------------------------------------------------------------------------
|
---|
3252 |
|
---|
3253 |
|
---|
3254 |
|
---|
3255 |
|
---|
3256 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
3257 | #define WIN32_LEAN_AND_MEAN
|
---|
3258 | #include "windows.h"
|
---|
3259 |
|
---|
3260 |
|
---|
3261 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
3262 | #else
|
---|
3263 | int main(int argc, char **argv)
|
---|
3264 | #endif
|
---|
3265 | {
|
---|
3266 | // Create application object
|
---|
3267 | PlayPenApplication app;
|
---|
3268 | //SwitchApplication app;
|
---|
3269 | //MemoryTestApplication app;
|
---|
3270 |
|
---|
3271 | try {
|
---|
3272 | app.go();
|
---|
3273 | } catch( Exception& e ) {
|
---|
3274 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
3275 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
3276 | #else
|
---|
3277 | std::cerr << "An exception has occured: " << e.getFullDescription();
|
---|
3278 | #endif
|
---|
3279 | }
|
---|
3280 |
|
---|
3281 |
|
---|
3282 | return 0;
|
---|
3283 | }
|
---|
3284 |
|
---|
3285 |
|
---|
3286 |
|
---|
3287 |
|
---|
3288 |
|
---|
3289 |
|
---|
3290 |
|
---|