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 | #include "OgreBillboardChain.h"
|
---|
36 |
|
---|
37 | /*
|
---|
38 | #include "OgreNoMemoryMacros.h"
|
---|
39 | #include <ode/odecpp.h>
|
---|
40 | #include <ode/odecpp_collision.h>
|
---|
41 | #include "OgreMemoryMacros.h"
|
---|
42 | */
|
---|
43 |
|
---|
44 | /*
|
---|
45 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
46 | #include "OgreNoMemoryMacros.h"
|
---|
47 | #include <crtdbg.h>
|
---|
48 | #endi*/
|
---|
49 |
|
---|
50 | #define NUM_TEST_NODES 5
|
---|
51 | SceneNode* mTestNode[NUM_TEST_NODES] = {0,0,0,0,0};
|
---|
52 | SceneNode* mLightNode = 0;
|
---|
53 | SceneNode* mRootNode;
|
---|
54 | SceneNode* camNode;
|
---|
55 | Entity* mEntity;
|
---|
56 | Real animTime = 0;
|
---|
57 | Animation* mAnim = 0;
|
---|
58 | std::vector<AnimationState*> mAnimStateList;
|
---|
59 | AnimationState* mAnimState = 0;
|
---|
60 | Overlay* mpOverlay;
|
---|
61 | Entity* pPlaneEnt;
|
---|
62 | Camera* testCam = 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 |
|
---|
71 | // Hacky globals
|
---|
72 | GpuProgramParametersSharedPtr fragParams;
|
---|
73 | GpuProgramParametersSharedPtr vertParams;
|
---|
74 | MaterialPtr skin;
|
---|
75 | Frustum* frustum = 0;
|
---|
76 | Camera* theCam;
|
---|
77 | Camera* reflectCam = 0;
|
---|
78 | Camera* camera2 = 0;
|
---|
79 | Bone* manuallyControlledBone = 0;
|
---|
80 |
|
---|
81 |
|
---|
82 | class RefractionTextureListener : public RenderTargetListener
|
---|
83 | {
|
---|
84 | public:
|
---|
85 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
86 | {
|
---|
87 | pPlaneEnt->setVisible(false);
|
---|
88 |
|
---|
89 | }
|
---|
90 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
91 | {
|
---|
92 | pPlaneEnt->setVisible(true);
|
---|
93 | }
|
---|
94 |
|
---|
95 | };
|
---|
96 | class ReflectionTextureListener : public RenderTargetListener
|
---|
97 | {
|
---|
98 | public:
|
---|
99 | void preRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
100 | {
|
---|
101 | static Plane reflectPlane(Vector3::UNIT_Y, -100);
|
---|
102 | pPlaneEnt->setVisible(false);
|
---|
103 | theCam->enableReflection(reflectPlane);
|
---|
104 |
|
---|
105 | }
|
---|
106 | void postRenderTargetUpdate(const RenderTargetEvent& evt)
|
---|
107 | {
|
---|
108 | pPlaneEnt->setVisible(true);
|
---|
109 | theCam->disableReflection();
|
---|
110 | }
|
---|
111 |
|
---|
112 | };
|
---|
113 |
|
---|
114 | class UberSimpleFrameListener : public FrameListener
|
---|
115 | {
|
---|
116 | protected:
|
---|
117 | InputReader* mInputDevice;
|
---|
118 |
|
---|
119 | public:
|
---|
120 | UberSimpleFrameListener(RenderWindow* win, Camera* cam)
|
---|
121 | {
|
---|
122 | mInputDevice = PlatformManager::getSingleton().createInputReader();
|
---|
123 | mInputDevice->initialise(win,true, true);
|
---|
124 | }
|
---|
125 | ~UberSimpleFrameListener()
|
---|
126 | {
|
---|
127 | PlatformManager::getSingleton().destroyInputReader( mInputDevice );
|
---|
128 | }
|
---|
129 |
|
---|
130 | bool frameStarted(const FrameEvent& evt)
|
---|
131 | {
|
---|
132 | mInputDevice->capture();
|
---|
133 | if (mInputDevice->isKeyDown(KC_ESCAPE))
|
---|
134 | {
|
---|
135 | return false;
|
---|
136 | }
|
---|
137 | return true;
|
---|
138 |
|
---|
139 | }
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 | class PlayPenListener : public ExampleFrameListener
|
---|
145 | {
|
---|
146 | protected:
|
---|
147 | SceneManager* mSceneMgr;
|
---|
148 | public:
|
---|
149 | PlayPenListener(SceneManager* mgr, RenderWindow* win, Camera* cam)
|
---|
150 | : ExampleFrameListener(win, cam),mSceneMgr(mgr)
|
---|
151 | {
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | bool frameStarted(const FrameEvent& evt)
|
---|
156 | {
|
---|
157 | if (!vertParams.isNull())
|
---|
158 | {
|
---|
159 | Matrix4 scaleMat = Matrix4::IDENTITY;
|
---|
160 | scaleMat[0][0] = 0.5f;
|
---|
161 | scaleMat[1][1] = -0.5f;
|
---|
162 | scaleMat[2][2] = 0.5f;
|
---|
163 | scaleMat[0][3] = 0.5f;
|
---|
164 | scaleMat[1][3] = 0.5f;
|
---|
165 | scaleMat[2][3] = 0.5f;
|
---|
166 | Matrix4 mat = frustum->getProjectionMatrixWithRSDepth() *
|
---|
167 | frustum->getViewMatrix();
|
---|
168 |
|
---|
169 |
|
---|
170 | mat = scaleMat * mat;
|
---|
171 |
|
---|
172 | vertParams->setNamedConstant("texViewProjMatrix", mat);
|
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (manuallyControlledBone)
|
---|
179 | {
|
---|
180 | manuallyControlledBone->yaw(Degree(evt.timeSinceLastFrame*100));
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | static float reloadtime = 10.0f;
|
---|
185 | if (testreload)
|
---|
186 | {
|
---|
187 | reloadtime -= evt.timeSinceLastFrame;
|
---|
188 | if (reloadtime <= 0)
|
---|
189 | {
|
---|
190 | Entity* e = mSceneMgr->getEntity("1");
|
---|
191 | e->getParentSceneNode()->detachObject("1");
|
---|
192 | e = mSceneMgr->getEntity("2");
|
---|
193 | e->getParentSceneNode()->detachObject("2");
|
---|
194 | mSceneMgr->destroyAllEntities();
|
---|
195 | ResourceGroupManager::getSingleton().unloadResourceGroup("Sinbad");
|
---|
196 | ResourceGroupManager::getSingleton().loadResourceGroup("Sinbad");
|
---|
197 |
|
---|
198 | testreload = false;
|
---|
199 |
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | bool ret = ExampleFrameListener::frameStarted(evt);
|
---|
207 |
|
---|
208 | if (reflectCam)
|
---|
209 | {
|
---|
210 | reflectCam->setOrientation(mCamera->getOrientation());
|
---|
211 | reflectCam->setPosition(mCamera->getPosition());
|
---|
212 | }
|
---|
213 | if (camera2)
|
---|
214 | {
|
---|
215 | camera2->setOrientation(mCamera->getOrientation());
|
---|
216 | camera2->setPosition(mCamera->getPosition());
|
---|
217 | }
|
---|
218 | return ret;
|
---|
219 |
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | bool frameEnded(const FrameEvent& evt)
|
---|
224 | {
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 | // local just to stop toggles flipping too fast
|
---|
229 | static Real timeUntilNextToggle = 0;
|
---|
230 | static bool animate = true;
|
---|
231 | static bool rotate = false;
|
---|
232 |
|
---|
233 | static bool firstTime = true;
|
---|
234 |
|
---|
235 | if (!firstTime)
|
---|
236 | {
|
---|
237 | //mCamera->yaw(20);
|
---|
238 | }
|
---|
239 | firstTime = false;
|
---|
240 |
|
---|
241 | if (timeUntilNextToggle >= 0)
|
---|
242 | timeUntilNextToggle -= evt.timeSinceLastFrame;
|
---|
243 |
|
---|
244 | static bool mWireframe = false;
|
---|
245 | if (mInputDevice->isKeyDown(KC_G) && timeUntilNextToggle <= 0)
|
---|
246 | {
|
---|
247 | mWireframe = !mWireframe;
|
---|
248 | if (mWireframe)
|
---|
249 | {
|
---|
250 | mCamera->setPolygonMode(PM_WIREFRAME);
|
---|
251 | }
|
---|
252 | else
|
---|
253 | {
|
---|
254 | mCamera->setPolygonMode(PM_SOLID);
|
---|
255 | }
|
---|
256 | timeUntilNextToggle = 0.5;
|
---|
257 |
|
---|
258 | }
|
---|
259 |
|
---|
260 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Core/StatsBlockBorder/Up");
|
---|
261 | mat->setDepthCheckEnabled(true);
|
---|
262 | mat->setDepthWriteEnabled(true);
|
---|
263 |
|
---|
264 | for (int i = 0; i < NUM_TEST_NODES; ++i)
|
---|
265 | {
|
---|
266 | if (mTestNode[i] && rotate)
|
---|
267 | mTestNode[i]->yaw(Degree(evt.timeSinceLastFrame * 15));
|
---|
268 | }
|
---|
269 |
|
---|
270 | if (mAnimState && animate)
|
---|
271 | mAnimState->addTime(evt.timeSinceLastFrame);
|
---|
272 | std::vector<AnimationState*>::iterator animi;
|
---|
273 | for (animi = mAnimStateList.begin(); animi != mAnimStateList.end(); ++animi)
|
---|
274 | {
|
---|
275 | (*animi)->addTime(evt.timeSinceLastFrame);
|
---|
276 | }
|
---|
277 |
|
---|
278 | if (mInputDevice->isKeyDown(KC_R) && timeUntilNextToggle <= 0)
|
---|
279 | {
|
---|
280 | rotate = !rotate;
|
---|
281 | timeUntilNextToggle = 0.5;
|
---|
282 | }
|
---|
283 | if (mInputDevice->isKeyDown(KC_1) && timeUntilNextToggle <= 0)
|
---|
284 | {
|
---|
285 | animate = !animate;
|
---|
286 | timeUntilNextToggle = 0.5;
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | if (rayQuery)
|
---|
291 | {
|
---|
292 | static Ray camRay;
|
---|
293 | static std::set<Entity*> lastEnts;
|
---|
294 | camRay.setOrigin(mCamera->getPosition());
|
---|
295 | camRay.setDirection(mCamera->getDirection());
|
---|
296 | rayQuery->setRay(camRay);
|
---|
297 |
|
---|
298 | // Reset last set
|
---|
299 | for (std::set<Entity*>::iterator lasti = lastEnts.begin();
|
---|
300 | lasti != lastEnts.end(); ++lasti)
|
---|
301 | {
|
---|
302 | (*lasti)->setMaterialName("Examples/OgreLogo");
|
---|
303 | }
|
---|
304 | lastEnts.clear();
|
---|
305 |
|
---|
306 |
|
---|
307 | RaySceneQueryResult& results = rayQuery->execute();
|
---|
308 | for (RaySceneQueryResult::iterator mov = results.begin();
|
---|
309 | mov != results.end(); ++mov)
|
---|
310 | {
|
---|
311 | if (mov->movable)
|
---|
312 | {
|
---|
313 | if (mov->movable->getMovableType() == "Entity")
|
---|
314 | {
|
---|
315 | Entity* ent = static_cast<Entity*>(mov->movable);
|
---|
316 | lastEnts.insert(ent);
|
---|
317 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
318 |
|
---|
319 | }
|
---|
320 | }
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | if (intersectionQuery)
|
---|
325 | {
|
---|
326 | static std::set<Entity*> lastEnts;
|
---|
327 |
|
---|
328 | // Reset last set
|
---|
329 | for (std::set<Entity*>::iterator lasti = lastEnts.begin();
|
---|
330 | lasti != lastEnts.end(); ++lasti)
|
---|
331 | {
|
---|
332 | (*lasti)->setMaterialName("Examples/OgreLogo");
|
---|
333 | }
|
---|
334 | lastEnts.clear();
|
---|
335 |
|
---|
336 |
|
---|
337 | IntersectionSceneQueryResult& results = intersectionQuery->execute();
|
---|
338 | for (SceneQueryMovableIntersectionList::iterator mov = results.movables2movables.begin();
|
---|
339 | mov != results.movables2movables.end(); ++mov)
|
---|
340 | {
|
---|
341 | SceneQueryMovableObjectPair& thepair = *mov;
|
---|
342 | if (thepair.first->getMovableType() == "Entity")
|
---|
343 | {
|
---|
344 | Entity* ent = static_cast<Entity*>(thepair.first);
|
---|
345 | lastEnts.insert(ent);
|
---|
346 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
347 |
|
---|
348 | }
|
---|
349 | if (thepair.second->getMovableType() == "Entity")
|
---|
350 | {
|
---|
351 | Entity* ent = static_cast<Entity*>(thepair.second);
|
---|
352 | lastEnts.insert(ent);
|
---|
353 | ent->setMaterialName("Examples/TextureEffect2");
|
---|
354 |
|
---|
355 | }
|
---|
356 | }
|
---|
357 | }
|
---|
358 |
|
---|
359 | /*
|
---|
360 | if (mInputDevice->isKeyDown(KC_V) && timeUntilNextToggle <= 0)
|
---|
361 | {
|
---|
362 | static bool isVP = false;
|
---|
363 | if (!isVP)
|
---|
364 | {
|
---|
365 | skin->getTechnique(0)->getPass(0)->setVertexProgram("SimpleVP");
|
---|
366 | skin->getTechnique(0)->getPass(0)->setVertexProgramParameters(vertParams);
|
---|
367 | isVP = true;
|
---|
368 | }
|
---|
369 | else
|
---|
370 | {
|
---|
371 | skin->getTechnique(0)->getPass(0)->setVertexProgram("");
|
---|
372 | isVP = false;
|
---|
373 | }
|
---|
374 | timeUntilNextToggle = 0.5;
|
---|
375 | }
|
---|
376 | */
|
---|
377 |
|
---|
378 | if (mInputDevice->isKeyDown(KC_P))
|
---|
379 | {
|
---|
380 | mTestNode[0]->yaw(Degree(-evt.timeSinceLastFrame * 30));
|
---|
381 | }
|
---|
382 | if (mInputDevice->isKeyDown(KC_O))
|
---|
383 | {
|
---|
384 | mTestNode[0]->yaw(Degree(evt.timeSinceLastFrame * 30));
|
---|
385 | }
|
---|
386 | if (mInputDevice->isKeyDown(KC_K))
|
---|
387 | {
|
---|
388 | mTestNode[0]->roll(Degree(-evt.timeSinceLastFrame * 30));
|
---|
389 | }
|
---|
390 | if (mInputDevice->isKeyDown(KC_L))
|
---|
391 | {
|
---|
392 | mTestNode[0]->roll(Degree(evt.timeSinceLastFrame * 30));
|
---|
393 | }
|
---|
394 | if (mInputDevice->isKeyDown(KC_U))
|
---|
395 | {
|
---|
396 | mTestNode[0]->translate(0,0,-evt.timeSinceLastFrame * 30);
|
---|
397 | }
|
---|
398 | if (mInputDevice->isKeyDown(KC_J))
|
---|
399 | {
|
---|
400 | mTestNode[0]->translate(0,0,evt.timeSinceLastFrame * 30);
|
---|
401 | }
|
---|
402 | if (mInputDevice->isKeyDown(KC_M))
|
---|
403 | {
|
---|
404 | mTestNode[0]->translate(0,evt.timeSinceLastFrame * 30, 0);
|
---|
405 | }
|
---|
406 | if (mInputDevice->isKeyDown(KC_N))
|
---|
407 | {
|
---|
408 | mTestNode[0]->translate(0,-evt.timeSinceLastFrame * 30, 0);
|
---|
409 | }
|
---|
410 |
|
---|
411 | if (mInputDevice->isKeyDown(KC_0) && timeUntilNextToggle <= 0)
|
---|
412 | {
|
---|
413 | mAnimState->setEnabled(!mAnimState->getEnabled());
|
---|
414 | timeUntilNextToggle = 0.5;
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 | /** Hack to test frustum vols
|
---|
420 | if (testCam)
|
---|
421 | {
|
---|
422 | // reposition the camera planes
|
---|
423 | PlaneBoundedVolumeList volList = mLight->_getFrustumClipVolumes(testCam);
|
---|
424 |
|
---|
425 | PlaneBoundedVolume& vol = volList[1];
|
---|
426 | for (int p = 0; p < 6; ++p)
|
---|
427 | {
|
---|
428 | Plane& pl = vol.planes[p];
|
---|
429 | camPlaneNode[p]->setOrientation(Vector3::UNIT_Z.getRotationTo(pl.normal));
|
---|
430 | camPlaneNode[p]->setPosition(0,0,0);
|
---|
431 | camPlaneNode[p]->translate(0,0, pl.d, Node::TS_LOCAL);
|
---|
432 | }
|
---|
433 |
|
---|
434 | vol.intersects(mEntity->getWorldBoundingBox());
|
---|
435 | }
|
---|
436 | */
|
---|
437 |
|
---|
438 | // Print camera details
|
---|
439 | mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " +
|
---|
440 | "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
|
---|
441 | return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt);
|
---|
442 |
|
---|
443 | }
|
---|
444 |
|
---|
445 |
|
---|
446 | };
|
---|
447 |
|
---|
448 | class PlayPenApplication : public ExampleApplication
|
---|
449 | {
|
---|
450 | protected:
|
---|
451 | RefractionTextureListener mRefractionListener;
|
---|
452 | ReflectionTextureListener mReflectionListener;
|
---|
453 | public:
|
---|
454 | PlayPenApplication() {
|
---|
455 |
|
---|
456 |
|
---|
457 | }
|
---|
458 |
|
---|
459 | ~PlayPenApplication()
|
---|
460 | {
|
---|
461 | if (frustum)
|
---|
462 | delete frustum;
|
---|
463 | }
|
---|
464 | protected:
|
---|
465 |
|
---|
466 | void chooseSceneManager(void)
|
---|
467 | {
|
---|
468 | mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "PlayPenSMInstance");
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | void createTestBugPlaneMesh3Streams(const String& testMeshName)
|
---|
473 | {
|
---|
474 | Plane plane(Vector3::UNIT_Z, 0);
|
---|
475 | Real width = 258;
|
---|
476 | Real height = 171;
|
---|
477 | int xsegments = 50;
|
---|
478 | int ysegments = 50;
|
---|
479 | Real xTile = 1.0f;
|
---|
480 | Real yTile = 1.0f;
|
---|
481 | const Vector3& upVector = Vector3::UNIT_Y;
|
---|
482 | MeshPtr pMesh = MeshManager::getSingleton().createManual(testMeshName,
|
---|
483 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
484 | SubMesh *pSub = pMesh->createSubMesh();
|
---|
485 |
|
---|
486 | // Set up vertex data
|
---|
487 | // Use a single shared buffer
|
---|
488 | pMesh->sharedVertexData = new VertexData();
|
---|
489 | VertexData* vertexData = pMesh->sharedVertexData;
|
---|
490 | // Set up Vertex Declaration
|
---|
491 | VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
|
---|
492 | // We always need positions
|
---|
493 | vertexDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
494 | vertexDecl->addElement(1, 0, VET_FLOAT3, VES_NORMAL);
|
---|
495 | vertexDecl->addElement(2, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
|
---|
496 |
|
---|
497 | vertexData->vertexCount = (xsegments + 1) * (ysegments + 1);
|
---|
498 |
|
---|
499 | // Allocate vertex buffers
|
---|
500 | HardwareVertexBufferSharedPtr vbufpos =
|
---|
501 | HardwareBufferManager::getSingleton().
|
---|
502 | createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount,
|
---|
503 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
504 | HardwareVertexBufferSharedPtr vbufnorm =
|
---|
505 | HardwareBufferManager::getSingleton().
|
---|
506 | createVertexBuffer(vertexDecl->getVertexSize(1), vertexData->vertexCount,
|
---|
507 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
508 | HardwareVertexBufferSharedPtr vbuftex =
|
---|
509 | HardwareBufferManager::getSingleton().
|
---|
510 | createVertexBuffer(vertexDecl->getVertexSize(2), vertexData->vertexCount,
|
---|
511 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
|
---|
512 |
|
---|
513 | // Set up the binding (one source only)
|
---|
514 | VertexBufferBinding* binding = vertexData->vertexBufferBinding;
|
---|
515 | binding->setBinding(0, vbufpos);
|
---|
516 | binding->setBinding(1, vbufnorm);
|
---|
517 | binding->setBinding(2, vbuftex);
|
---|
518 |
|
---|
519 | // Work out the transform required
|
---|
520 | // Default orientation of plane is normal along +z, distance 0
|
---|
521 | Matrix4 xlate, xform, rot;
|
---|
522 | Matrix3 rot3;
|
---|
523 | xlate = rot = Matrix4::IDENTITY;
|
---|
524 | // Determine axes
|
---|
525 | Vector3 zAxis, yAxis, xAxis;
|
---|
526 | zAxis = plane.normal;
|
---|
527 | zAxis.normalise();
|
---|
528 | yAxis = upVector;
|
---|
529 | yAxis.normalise();
|
---|
530 | xAxis = yAxis.crossProduct(zAxis);
|
---|
531 |
|
---|
532 | rot3.FromAxes(xAxis, yAxis, zAxis);
|
---|
533 | rot = rot3;
|
---|
534 |
|
---|
535 | // Set up standard xform from origin
|
---|
536 | xlate.setTrans(plane.normal * -plane.d);
|
---|
537 |
|
---|
538 | // concatenate
|
---|
539 | xform = xlate * rot;
|
---|
540 |
|
---|
541 | // Generate vertex data
|
---|
542 | // Lock the whole buffer
|
---|
543 | float* pPos = static_cast<float*>(
|
---|
544 | vbufpos->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
545 | float* pNorm = static_cast<float*>(
|
---|
546 | vbufnorm->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
547 | float* pTex = static_cast<float*>(
|
---|
548 | vbuftex->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
549 | Real xSpace = width / xsegments;
|
---|
550 | Real ySpace = height / ysegments;
|
---|
551 | Real halfWidth = width / 2;
|
---|
552 | Real halfHeight = height / 2;
|
---|
553 | Real xTex = (1.0f * xTile) / xsegments;
|
---|
554 | Real yTex = (1.0f * yTile) / ysegments;
|
---|
555 | Vector3 vec;
|
---|
556 | Vector3 min, max;
|
---|
557 | Real maxSquaredLength;
|
---|
558 | bool firstTime = true;
|
---|
559 |
|
---|
560 | for (int y = 0; y < ysegments + 1; ++y)
|
---|
561 | {
|
---|
562 | for (int x = 0; x < xsegments + 1; ++x)
|
---|
563 | {
|
---|
564 | // Work out centered on origin
|
---|
565 | vec.x = (x * xSpace) - halfWidth;
|
---|
566 | vec.y = (y * ySpace) - halfHeight;
|
---|
567 | vec.z = 0.0f;
|
---|
568 | // Transform by orientation and distance
|
---|
569 | vec = xform * vec;
|
---|
570 | // Assign to geometry
|
---|
571 | *pPos++ = vec.x;
|
---|
572 | *pPos++ = vec.y;
|
---|
573 | *pPos++ = vec.z;
|
---|
574 |
|
---|
575 | // Build bounds as we go
|
---|
576 | if (firstTime)
|
---|
577 | {
|
---|
578 | min = vec;
|
---|
579 | max = vec;
|
---|
580 | maxSquaredLength = vec.squaredLength();
|
---|
581 | firstTime = false;
|
---|
582 | }
|
---|
583 | else
|
---|
584 | {
|
---|
585 | min.makeFloor(vec);
|
---|
586 | max.makeCeil(vec);
|
---|
587 | maxSquaredLength = std::max(maxSquaredLength, vec.squaredLength());
|
---|
588 | }
|
---|
589 |
|
---|
590 | // Default normal is along unit Z
|
---|
591 | vec = Vector3::UNIT_Z;
|
---|
592 | // Rotate
|
---|
593 | vec = rot * vec;
|
---|
594 |
|
---|
595 | *pNorm++ = vec.x;
|
---|
596 | *pNorm++ = vec.y;
|
---|
597 | *pNorm++ = vec.z;
|
---|
598 |
|
---|
599 | *pTex++ = x * xTex;
|
---|
600 | *pTex++ = 1 - (y * yTex);
|
---|
601 |
|
---|
602 |
|
---|
603 | } // x
|
---|
604 | } // y
|
---|
605 |
|
---|
606 | // Unlock
|
---|
607 | vbufpos->unlock();
|
---|
608 | vbufnorm->unlock();
|
---|
609 | vbuftex->unlock();
|
---|
610 | // Generate face list
|
---|
611 | pSub->useSharedVertices = true;
|
---|
612 | //tesselate2DMesh(pSub, xsegments + 1, ysegments + 1, false, indexBufferUsage, indexShadowBuffer);
|
---|
613 | SubMesh* sm = pSub;
|
---|
614 | int meshWidth = xsegments + 1;
|
---|
615 | int meshHeight = ysegments + 1;
|
---|
616 | bool doubleSided = false;
|
---|
617 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY;
|
---|
618 | bool indexShadowBuffer = true;
|
---|
619 | // The mesh is built, just make a list of indexes to spit out the triangles
|
---|
620 | int vInc, uInc, v, u, iterations;
|
---|
621 | int vCount, uCount;
|
---|
622 |
|
---|
623 | if (doubleSided)
|
---|
624 | {
|
---|
625 | iterations = 2;
|
---|
626 | vInc = 1;
|
---|
627 | v = 0; // Start with front
|
---|
628 | }
|
---|
629 | else
|
---|
630 | {
|
---|
631 | iterations = 1;
|
---|
632 | vInc = 1;
|
---|
633 | v = 0;
|
---|
634 | }
|
---|
635 |
|
---|
636 | // Allocate memory for faces
|
---|
637 | // Num faces, width*height*2 (2 tris per square), index count is * 3 on top
|
---|
638 | sm->indexData->indexCount = (meshWidth-1) * (meshHeight-1) * 2 * iterations * 3;
|
---|
639 | sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
|
---|
640 | createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
|
---|
641 | sm->indexData->indexCount, indexBufferUsage, indexShadowBuffer);
|
---|
642 |
|
---|
643 | int v1, v2, v3;
|
---|
644 | //bool firstTri = true;
|
---|
645 | HardwareIndexBufferSharedPtr ibuf = sm->indexData->indexBuffer;
|
---|
646 | // Lock the whole buffer
|
---|
647 | unsigned short* pIndexes = static_cast<unsigned short*>(
|
---|
648 | ibuf->lock(HardwareBuffer::HBL_DISCARD) );
|
---|
649 |
|
---|
650 | while (iterations--)
|
---|
651 | {
|
---|
652 | // Make tris in a zigzag pattern (compatible with strips)
|
---|
653 | u = 0;
|
---|
654 | uInc = 1; // Start with moving +u
|
---|
655 |
|
---|
656 | vCount = meshHeight - 1;
|
---|
657 | while (vCount--)
|
---|
658 | {
|
---|
659 | uCount = meshWidth - 1;
|
---|
660 | while (uCount--)
|
---|
661 | {
|
---|
662 | // First Tri in cell
|
---|
663 | // -----------------
|
---|
664 | v1 = ((v + vInc) * meshWidth) + u;
|
---|
665 | v2 = (v * meshWidth) + u;
|
---|
666 | v3 = ((v + vInc) * meshWidth) + (u + uInc);
|
---|
667 | // Output indexes
|
---|
668 | *pIndexes++ = v1;
|
---|
669 | *pIndexes++ = v2;
|
---|
670 | *pIndexes++ = v3;
|
---|
671 | // Second Tri in cell
|
---|
672 | // ------------------
|
---|
673 | v1 = ((v + vInc) * meshWidth) + (u + uInc);
|
---|
674 | v2 = (v * meshWidth) + u;
|
---|
675 | v3 = (v * meshWidth) + (u + uInc);
|
---|
676 | // Output indexes
|
---|
677 | *pIndexes++ = v1;
|
---|
678 | *pIndexes++ = v2;
|
---|
679 | *pIndexes++ = v3;
|
---|
680 |
|
---|
681 | // Next column
|
---|
682 | u += uInc;
|
---|
683 | }
|
---|
684 | // Next row
|
---|
685 | v += vInc;
|
---|
686 | u = 0;
|
---|
687 |
|
---|
688 |
|
---|
689 | }
|
---|
690 |
|
---|
691 | // Reverse vInc for double sided
|
---|
692 | v = meshHeight - 1;
|
---|
693 | vInc = -vInc;
|
---|
694 |
|
---|
695 | }
|
---|
696 | // Unlock
|
---|
697 | ibuf->unlock();
|
---|
698 |
|
---|
699 | //pMesh->_updateBounds();
|
---|
700 | pMesh->_setBounds(AxisAlignedBox(min, max));
|
---|
701 | pMesh->_setBoundingSphereRadius(Math::Sqrt(maxSquaredLength));
|
---|
702 | // load
|
---|
703 | pMesh->load();
|
---|
704 | pMesh->touch();
|
---|
705 | }
|
---|
706 |
|
---|
707 | void stressTestStaticGeometry(void)
|
---|
708 | {
|
---|
709 |
|
---|
710 | // Set ambient light
|
---|
711 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
712 |
|
---|
713 | // Create a point light
|
---|
714 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
715 | l->setType(Light::LT_DIRECTIONAL);
|
---|
716 | Vector3 dir(1, -1, -1.5);
|
---|
717 | dir.normalise();
|
---|
718 | l->setDirection(dir);
|
---|
719 | l->setDiffuseColour(1.0, 0.7, 0.0);
|
---|
720 |
|
---|
721 |
|
---|
722 | Plane plane;
|
---|
723 | plane.normal = Vector3::UNIT_Y;
|
---|
724 | plane.d = 0;
|
---|
725 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
726 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
727 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
728 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
729 | pPlaneEnt->setMaterialName("Examples/GrassFloor");
|
---|
730 | pPlaneEnt->setCastShadows(false);
|
---|
731 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
732 |
|
---|
733 | Vector3 min(-2000,0,-2000);
|
---|
734 | Vector3 max(2000,0,2000);
|
---|
735 |
|
---|
736 |
|
---|
737 | Entity* e = mSceneMgr->createEntity("1", "ogrehead.mesh");
|
---|
738 | StaticGeometry* s = 0;
|
---|
739 |
|
---|
740 | unsigned int count = 10;
|
---|
741 | while(count--)
|
---|
742 | {
|
---|
743 | if(s) mSceneMgr->destroyStaticGeometry(s);
|
---|
744 | s = mSceneMgr->createStaticGeometry("bing");
|
---|
745 |
|
---|
746 | s->addEntity(e, Vector3(100, 100, 100));
|
---|
747 |
|
---|
748 | s->build();
|
---|
749 | }
|
---|
750 |
|
---|
751 |
|
---|
752 | //s->setRenderingDistance(1000);
|
---|
753 | //s->dump("static.txt");
|
---|
754 | //mSceneMgr->showBoundingBoxes(true);
|
---|
755 | mCamera->setLodBias(0.5);
|
---|
756 |
|
---|
757 |
|
---|
758 | }
|
---|
759 |
|
---|
760 | void testBug()
|
---|
761 | {
|
---|
762 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
|
---|
763 |
|
---|
764 | // Setup lighting
|
---|
765 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
766 | Light* light = mSceneMgr->createLight("MainLight");
|
---|
767 | light->setType(Light::LT_DIRECTIONAL);
|
---|
768 | Vector3 dir(-1, -1, 0.5);
|
---|
769 | dir.normalise();
|
---|
770 | light->setDirection(dir);
|
---|
771 |
|
---|
772 | // Create a floor plane mesh
|
---|
773 | Plane plane(Vector3::UNIT_Y, 0.0);
|
---|
774 | MeshManager::getSingleton().createPlane(
|
---|
775 | "FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
776 | plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z);
|
---|
777 |
|
---|
778 | // Add a floor to the scene
|
---|
779 | Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
780 | entity->setMaterialName("Examples/RustySteel");
|
---|
781 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
|
---|
782 |
|
---|
783 | // Add the mandatory ogre heads ;)
|
---|
784 | entity = mSceneMgr->createEntity("head0", "ogrehead.mesh");
|
---|
785 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
786 | Vector3(0.0, 10.0, 0.0))->attachObject(entity);
|
---|
787 |
|
---|
788 | entity = mSceneMgr->createEntity("head1", "ogrehead.mesh");
|
---|
789 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
790 | Vector3(-50.0, 10.0, -50.0))->attachObject(entity);
|
---|
791 |
|
---|
792 | entity = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
793 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
794 | Vector3(70.0, 10.0, -80.0))->attachObject(entity);
|
---|
795 |
|
---|
796 | // Position and orient the camera
|
---|
797 | mCamera->setPosition(-55.0, 40.0, 100.0);
|
---|
798 | mCamera->lookAt(-10.0, 20.0, -35.0);
|
---|
799 |
|
---|
800 | mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3);
|
---|
801 | }
|
---|
802 |
|
---|
803 | void testTransparencyMipMaps()
|
---|
804 | {
|
---|
805 | MaterialPtr mat = MaterialManager::getSingleton().create("test",
|
---|
806 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
807 | // known png with alpha
|
---|
808 | Pass* pass = mat->getTechnique(0)->getPass(0);
|
---|
809 | pass->createTextureUnitState("ogretext.png");
|
---|
810 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
811 | // alpha blend
|
---|
812 | pass->setDepthWriteEnabled(false);
|
---|
813 |
|
---|
814 | // alpha reject
|
---|
815 | //pass->setDepthWriteEnabled(true);
|
---|
816 | //pass->setAlphaRejectSettings(CMPF_LESS, 128);
|
---|
817 |
|
---|
818 | // Define a floor plane mesh
|
---|
819 | Plane p;
|
---|
820 | p.normal = Vector3::UNIT_Y;
|
---|
821 | p.d = 200;
|
---|
822 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
823 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
824 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
825 |
|
---|
826 | // Create an entity (the floor)
|
---|
827 | Entity* ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
828 | ent->setMaterialName("test");
|
---|
829 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
830 |
|
---|
831 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
832 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
833 |
|
---|
834 |
|
---|
835 | {
|
---|
836 |
|
---|
837 | Real alphaLevel = 0.5f;
|
---|
838 | MaterialPtr alphamat = MaterialManager::getSingleton().create("testy",
|
---|
839 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
840 | Pass* pass = alphamat->getTechnique(0)->getPass(0);
|
---|
841 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
842 | pass->setDepthWriteEnabled(false);
|
---|
843 | TextureUnitState* t = pass->createTextureUnitState();
|
---|
844 | t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alphaLevel);
|
---|
845 |
|
---|
846 | ent = mSceneMgr->createEntity("asd", "ogrehead.mesh");
|
---|
847 | ent->setMaterialName("testy");
|
---|
848 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
849 |
|
---|
850 | }
|
---|
851 |
|
---|
852 | }
|
---|
853 |
|
---|
854 | void testCthNewBlending(void)
|
---|
855 | {
|
---|
856 | // Set ambient light
|
---|
857 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
858 |
|
---|
859 | // Create a point light
|
---|
860 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
861 | l->setType(Light::LT_DIRECTIONAL);
|
---|
862 | l->setDirection(-Vector3::UNIT_Y);
|
---|
863 |
|
---|
864 | // Accept default settings: point light, white diffuse, just set position
|
---|
865 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
866 | // other objects, but I don't
|
---|
867 | //l->setPosition(20,80,50);
|
---|
868 |
|
---|
869 |
|
---|
870 | Entity *ent = mSceneMgr->createEntity("head", "ogrehead_2.mesh");
|
---|
871 |
|
---|
872 | // Add entity to the root scene node
|
---|
873 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
874 | static_cast<SceneNode*>(mRootNode->createChild())->attachObject(ent);
|
---|
875 |
|
---|
876 | mTestNode[0] = static_cast<SceneNode*>(
|
---|
877 | mRootNode->createChild("TestNode", Vector3(100,0,0)));
|
---|
878 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
879 | mTestNode[0]->attachObject(ent);
|
---|
880 |
|
---|
881 | mTestNode[0]->attachObject(l);
|
---|
882 |
|
---|
883 |
|
---|
884 | // Create a skydome
|
---|
885 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
886 |
|
---|
887 | // Define a floor plane mesh
|
---|
888 | Plane p;
|
---|
889 | p.normal = Vector3::UNIT_Y;
|
---|
890 | p.d = 200;
|
---|
891 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
892 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
893 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
894 |
|
---|
895 | // Create an entity (the floor)
|
---|
896 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
897 | ent->setMaterialName("Block/Material1");
|
---|
898 |
|
---|
899 | mRootNode->attachObject(ent);
|
---|
900 |
|
---|
901 | mCamera->setPosition(0,0,200);
|
---|
902 | mCamera->setDirection(0,0,-1);
|
---|
903 |
|
---|
904 | //mSceneMgr->setDisplaySceneNodes(true);
|
---|
905 |
|
---|
906 | }
|
---|
907 |
|
---|
908 | void testMatrices(void)
|
---|
909 | {
|
---|
910 | mCamera->setPosition(0,0,500);
|
---|
911 | mCamera->lookAt(0,0,0);
|
---|
912 | const Matrix4& view = mCamera->getViewMatrix();
|
---|
913 | const Matrix4& proj = mCamera->getProjectionMatrix();
|
---|
914 |
|
---|
915 | Matrix4 viewproj = proj * view;
|
---|
916 |
|
---|
917 | Vector3 point3d(100,100,0);
|
---|
918 |
|
---|
919 | Vector3 projPoint = viewproj * point3d;
|
---|
920 |
|
---|
921 | point3d = Vector3(100,100,400);
|
---|
922 | projPoint = viewproj * point3d;
|
---|
923 | }
|
---|
924 | void testBasicPlane()
|
---|
925 | {
|
---|
926 | /*
|
---|
927 | // Create a light
|
---|
928 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
929 | // Accept default settings: point light, white diffuse, just set position
|
---|
930 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
931 | // other objects, but I don't
|
---|
932 | l->setPosition(20,80,50);
|
---|
933 | */
|
---|
934 |
|
---|
935 | // Create a point light
|
---|
936 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
937 | l->setType(Light::LT_DIRECTIONAL);
|
---|
938 | l->setDirection(-Vector3::UNIT_Y);
|
---|
939 | Entity *ent;
|
---|
940 |
|
---|
941 | // Define a floor plane mesh
|
---|
942 | Plane p;
|
---|
943 | p.normal = Vector3::UNIT_Y;
|
---|
944 | p.d = 200;
|
---|
945 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
946 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
947 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
948 |
|
---|
949 | // Create an entity (the floor)
|
---|
950 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
951 | ent->setMaterialName("Examples/RustySteel");
|
---|
952 |
|
---|
953 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
954 |
|
---|
955 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh");
|
---|
956 |
|
---|
957 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
958 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
959 | node->attachObject(sphereEnt);
|
---|
960 | mRootNode->addChild(node);
|
---|
961 |
|
---|
962 | }
|
---|
963 |
|
---|
964 | void testAlpha()
|
---|
965 | {
|
---|
966 | /*
|
---|
967 | // Create a light
|
---|
968 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
969 | // Accept default settings: point light, white diffuse, just set position
|
---|
970 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
971 | // other objects, but I don't
|
---|
972 | l->setPosition(20,80,50);
|
---|
973 | */
|
---|
974 |
|
---|
975 | // Create a point light
|
---|
976 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
977 | l->setType(Light::LT_DIRECTIONAL);
|
---|
978 | l->setDirection(-Vector3::UNIT_Y);
|
---|
979 | Entity *ent;
|
---|
980 |
|
---|
981 | // Define a floor plane mesh
|
---|
982 | Plane p;
|
---|
983 | p.normal = Vector3::UNIT_Y;
|
---|
984 | p.d = 200;
|
---|
985 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
986 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
987 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
|
---|
988 |
|
---|
989 | p.normal = Vector3::UNIT_Z;
|
---|
990 | p.d = 200;
|
---|
991 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
992 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
993 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Y);
|
---|
994 |
|
---|
995 | // Create an entity (the floor)
|
---|
996 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
997 | ent->setMaterialName("Core/StatsBlockBorder/Up");
|
---|
998 |
|
---|
999 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
1000 |
|
---|
1001 | ent = mSceneMgr->createEntity("wall", "WallPlane");
|
---|
1002 | ent->setMaterialName("Core/StatsBlockBorder/Up");
|
---|
1003 |
|
---|
1004 | mSceneMgr->getRootSceneNode()->attachObject(ent);
|
---|
1005 |
|
---|
1006 |
|
---|
1007 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh");
|
---|
1008 |
|
---|
1009 | mRootNode = mSceneMgr->getRootSceneNode();
|
---|
1010 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
1011 | node->attachObject(sphereEnt);
|
---|
1012 | mRootNode->addChild(node);
|
---|
1013 |
|
---|
1014 | mSceneMgr->showBoundingBoxes(true);
|
---|
1015 |
|
---|
1016 | }
|
---|
1017 | void testBsp()
|
---|
1018 | {
|
---|
1019 | // Load Quake3 locations from a file
|
---|
1020 | ConfigFile cf;
|
---|
1021 |
|
---|
1022 | cf.load("quake3settings.cfg");
|
---|
1023 |
|
---|
1024 | String quakePk3 = cf.getSetting("Pak0Location");
|
---|
1025 | String quakeLevel = cf.getSetting("Map");
|
---|
1026 |
|
---|
1027 | ResourceGroupManager::getSingleton().addResourceLocation(quakePk3, "Zip");
|
---|
1028 |
|
---|
1029 |
|
---|
1030 | // Load world geometry
|
---|
1031 | mSceneMgr->setWorldGeometry(quakeLevel);
|
---|
1032 |
|
---|
1033 | // modify camera for close work
|
---|
1034 | mCamera->setNearClipDistance(4);
|
---|
1035 | mCamera->setFarClipDistance(4000);
|
---|
1036 |
|
---|
1037 | // Also change position, and set Quake-type orientation
|
---|
1038 | // Get random player start point
|
---|
1039 | ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true);
|
---|
1040 | mCamera->setPosition(vp.position);
|
---|
1041 | mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up
|
---|
1042 | mCamera->rotate(vp.orientation);
|
---|
1043 | // Don't yaw along variable axis, causes leaning
|
---|
1044 | mCamera->setFixedYawAxis(true, Vector3::UNIT_Z);
|
---|
1045 |
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | void testAnimation()
|
---|
1049 | {
|
---|
1050 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1051 | l->setPosition(200,110,0);
|
---|
1052 | l->setType(Light::LT_POINT);
|
---|
1053 | Entity *ent;
|
---|
1054 |
|
---|
1055 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.4));
|
---|
1056 |
|
---|
1057 | // Create an entity (the plant)
|
---|
1058 | ent = mSceneMgr->createEntity("1", "limo.mesh");
|
---|
1059 |
|
---|
1060 | SceneNode* node = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild(Vector3(-50,0,0)));
|
---|
1061 | node->attachObject(ent);
|
---|
1062 | node->scale(2,2,2);
|
---|
1063 |
|
---|
1064 | mAnimState = ent->getAnimationState("SteerLeftOn");
|
---|
1065 | mAnimState->setEnabled(true);
|
---|
1066 |
|
---|
1067 | mWindow->getViewport(0)->setBackgroundColour(ColourValue(1,0,0));
|
---|
1068 |
|
---|
1069 |
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | void testGpuPrograms(void)
|
---|
1073 | {
|
---|
1074 | // Set ambient light
|
---|
1075 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1076 |
|
---|
1077 | // Create a point light
|
---|
1078 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1079 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1080 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1081 |
|
---|
1082 | Entity* pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
1083 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
|
---|
1084 |
|
---|
1085 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1086 |
|
---|
1087 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1088 | mTestNode[0]->attachObject( pEnt );
|
---|
1089 | mTestNode[0]->translate(100,0,0);
|
---|
1090 |
|
---|
1091 | // Rejig the ogre skin material
|
---|
1092 | // Load the programs first
|
---|
1093 |
|
---|
1094 | pEnt->getSubEntity(1)->setMaterialName("SimpleTest");
|
---|
1095 |
|
---|
1096 | }
|
---|
1097 | void testProjection(void)
|
---|
1098 | {
|
---|
1099 | // Set ambient light
|
---|
1100 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1101 |
|
---|
1102 | // Create a point light
|
---|
1103 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1104 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1105 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1106 |
|
---|
1107 | Entity* pEnt;
|
---|
1108 | //pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
|
---|
1109 | //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
|
---|
1110 | //pEnt->setMaterialName("Examples/OgreLogo");
|
---|
1111 |
|
---|
1112 | // Define a floor plane mesh
|
---|
1113 | Plane p;
|
---|
1114 | p.normal = Vector3::UNIT_Z;
|
---|
1115 | p.d = 200;
|
---|
1116 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
1117 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1118 | p,1500,1500,1,1,true,1,5,5,Vector3::UNIT_Y);
|
---|
1119 | pEnt = mSceneMgr->createEntity( "5", "WallPlane" );
|
---|
1120 | pEnt->setMaterialName("Examples/OgreLogo");
|
---|
1121 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt);
|
---|
1122 |
|
---|
1123 |
|
---|
1124 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1125 |
|
---|
1126 | //pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1127 | //mTestNode[0]->attachObject( pEnt );
|
---|
1128 | mTestNode[0]->translate(0, 0, 750);
|
---|
1129 |
|
---|
1130 | frustum = new Frustum();
|
---|
1131 | frustum->setVisible(true);
|
---|
1132 | frustum->setFarClipDistance(5000);
|
---|
1133 | frustum->setNearClipDistance(200);
|
---|
1134 | frustum->setAspectRatio(1);
|
---|
1135 | //frustum->setProjectionType(PT_ORTHOGRAPHIC);
|
---|
1136 | mTestNode[0]->attachObject(frustum);
|
---|
1137 |
|
---|
1138 | // Hook the frustum up to the material
|
---|
1139 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/OgreLogo");
|
---|
1140 | TextureUnitState *t = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
|
---|
1141 | t->setProjectiveTexturing(true, frustum);
|
---|
1142 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
1143 |
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | void testMultiViewports(void)
|
---|
1147 | {
|
---|
1148 | // Set ambient light
|
---|
1149 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1150 |
|
---|
1151 | // Create a point light
|
---|
1152 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1153 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1154 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1155 |
|
---|
1156 | Entity* pEnt = mSceneMgr->createEntity( "1", "knot.mesh" );
|
---|
1157 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt);
|
---|
1158 |
|
---|
1159 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1160 |
|
---|
1161 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" );
|
---|
1162 | mTestNode[0]->attachObject( pEnt );
|
---|
1163 | mTestNode[0]->translate(0, 0, 200);
|
---|
1164 |
|
---|
1165 | frustum = new Frustum();
|
---|
1166 | //frustum->setVisible(true);
|
---|
1167 | frustum->setFarClipDistance(5000);
|
---|
1168 | frustum->setNearClipDistance(100);
|
---|
1169 | mTestNode[0]->attachObject(frustum);
|
---|
1170 |
|
---|
1171 | Viewport* vp = mRoot->getAutoCreatedWindow()->addViewport(mCamera, 1, 0.5, 0.5, 0.5, 0.5);
|
---|
1172 | vp->setOverlaysEnabled(false);
|
---|
1173 | vp->setBackgroundColour(ColourValue(1,0,0));
|
---|
1174 |
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 |
|
---|
1178 | // Just override the mandatory create scene method
|
---|
1179 | void testSceneNodeTracking(void)
|
---|
1180 | {
|
---|
1181 |
|
---|
1182 | // Set ambient light
|
---|
1183 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
1184 |
|
---|
1185 | // Create a skydome
|
---|
1186 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
1187 |
|
---|
1188 | // Create a light
|
---|
1189 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1190 | // Accept default settings: point light, white diffuse, just set position
|
---|
1191 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
1192 | // other objects, but I don't
|
---|
1193 | l->setPosition(20,80,50);
|
---|
1194 |
|
---|
1195 | Entity *ent;
|
---|
1196 |
|
---|
1197 | // Define a floor plane mesh
|
---|
1198 | Plane p;
|
---|
1199 | p.normal = Vector3::UNIT_Y;
|
---|
1200 | p.d = 200;
|
---|
1201 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1202 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1203 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
|
---|
1204 |
|
---|
1205 | // Create an entity (the floor)
|
---|
1206 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1207 | ent->setMaterialName("Examples/RustySteel");
|
---|
1208 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
|
---|
1209 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1210 |
|
---|
1211 | // Add a head, give it it's own node
|
---|
1212 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1213 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
1214 | headNode->attachObject(ent);
|
---|
1215 |
|
---|
1216 | // Add another head, give it it's own node
|
---|
1217 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1218 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
1219 | headNode2->attachObject(ent);
|
---|
1220 |
|
---|
1221 | // Make sure the head node tracks the root
|
---|
1222 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z);
|
---|
1223 | //headNode->setFixedYawAxis(true);
|
---|
1224 |
|
---|
1225 | // Create the camera node & attach camera
|
---|
1226 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1227 | //camNode->attachObject(mCamera);
|
---|
1228 |
|
---|
1229 | // set up spline animation of node
|
---|
1230 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
|
---|
1231 | // Spline it for nice curves
|
---|
1232 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
1233 | // Create a track to animate the head's node
|
---|
1234 | NodeAnimationTrack* track = anim->createNodeTrack(0, headNode);
|
---|
1235 | // Setup keyframes
|
---|
1236 | TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition
|
---|
1237 | key = track->createNodeKeyFrame(2.5);
|
---|
1238 | key->setTranslate(Vector3(500,500,-1000));
|
---|
1239 | key = track->createNodeKeyFrame(5);
|
---|
1240 | key->setTranslate(Vector3(-1500,1000,-600));
|
---|
1241 | key = track->createNodeKeyFrame(7.5);
|
---|
1242 | key->setTranslate(Vector3(0,-100,0));
|
---|
1243 | key = track->createNodeKeyFrame(10);
|
---|
1244 | key->setTranslate(Vector3(0,0,0));
|
---|
1245 | // Create a track to animate the second head's node
|
---|
1246 | track = anim->createNodeTrack(1, headNode2);
|
---|
1247 | // Setup keyframes
|
---|
1248 | key = track->createNodeKeyFrame(0); // startposition
|
---|
1249 | key = track->createNodeKeyFrame(2.5);
|
---|
1250 | key->setTranslate(Vector3(-500,600,-100));
|
---|
1251 | key = track->createNodeKeyFrame(5);
|
---|
1252 | key->setTranslate(Vector3(800,200,-600));
|
---|
1253 | key = track->createNodeKeyFrame(7.5);
|
---|
1254 | key->setTranslate(Vector3(200,-1000,0));
|
---|
1255 | key = track->createNodeKeyFrame(10);
|
---|
1256 | key->setTranslate(Vector3(30,70,110));
|
---|
1257 | // Create a new animation state to track this
|
---|
1258 | mAnimState = mSceneMgr->createAnimationState("CameraTrack");
|
---|
1259 | mAnimState->setEnabled(true);
|
---|
1260 |
|
---|
1261 | // Put in a bit of fog for the hell of it
|
---|
1262 | mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);
|
---|
1263 |
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 |
|
---|
1267 |
|
---|
1268 | void testDistortion(void)
|
---|
1269 | {
|
---|
1270 | theCam = mCamera;
|
---|
1271 | // Set ambient light
|
---|
1272 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1273 |
|
---|
1274 | // Create a point light
|
---|
1275 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1276 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1277 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1278 |
|
---|
1279 | Entity* pEnt;
|
---|
1280 |
|
---|
1281 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "Refraction", 512, 512 );
|
---|
1282 | {
|
---|
1283 | Viewport *v = rttTex->addViewport( mCamera );
|
---|
1284 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
|
---|
1285 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction");
|
---|
1286 | v->setOverlaysEnabled(false);
|
---|
1287 | rttTex->addListener(&mRefractionListener);
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | rttTex = mRoot->getRenderSystem()->createRenderTexture( "Reflection", 512, 512 );
|
---|
1291 | {
|
---|
1292 | Viewport *v = rttTex->addViewport( mCamera );
|
---|
1293 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction");
|
---|
1294 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection");
|
---|
1295 | v->setOverlaysEnabled(false);
|
---|
1296 | rttTex->addListener(&mReflectionListener);
|
---|
1297 | }
|
---|
1298 | // Define a floor plane mesh
|
---|
1299 | Plane p;
|
---|
1300 | p.normal = Vector3::UNIT_Y;
|
---|
1301 | p.d = 100;
|
---|
1302 | MeshManager::getSingleton().createPlane("WallPlane",
|
---|
1303 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1304 | p,1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
1305 | pPlaneEnt = mSceneMgr->createEntity( "5", "WallPlane" );
|
---|
1306 | pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction");
|
---|
1307 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
1308 |
|
---|
1309 |
|
---|
1310 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
1311 |
|
---|
1312 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1313 | int i;
|
---|
1314 | for (i = 0; i < 10; ++i)
|
---|
1315 | {
|
---|
1316 | pEnt = mSceneMgr->createEntity( "ogre" + StringConverter::toString(i), "ogrehead.mesh" );
|
---|
1317 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, -75, 0))->attachObject(pEnt);
|
---|
1318 | pEnt = mSceneMgr->createEntity( "knot" + StringConverter::toString(i), "knot.mesh" );
|
---|
1319 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, 140, 0))->attachObject(pEnt);
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 |
|
---|
1323 |
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 |
|
---|
1327 | void testEdgeBuilderSingleIndexBufSingleVertexBuf()
|
---|
1328 | {
|
---|
1329 | /* This tests the edge builders ability to find shared edges in the simple case
|
---|
1330 | of a single index buffer referencing a single vertex buffer
|
---|
1331 | */
|
---|
1332 | VertexData vd;
|
---|
1333 | IndexData id;
|
---|
1334 | // Test pyramid
|
---|
1335 | vd.vertexCount = 4;
|
---|
1336 | vd.vertexStart = 0;
|
---|
1337 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1338 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1339 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
1340 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
1341 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1342 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1343 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1344 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1345 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1346 | vbuf->unlock();
|
---|
1347 |
|
---|
1348 | id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1349 | HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true);
|
---|
1350 | id.indexCount = 12;
|
---|
1351 | id.indexStart = 0;
|
---|
1352 | unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1353 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1354 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
1355 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
1356 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
1357 | id.indexBuffer->unlock();
|
---|
1358 |
|
---|
1359 | EdgeListBuilder edgeBuilder;
|
---|
1360 | edgeBuilder.addVertexData(&vd);
|
---|
1361 | edgeBuilder.addIndexData(&id);
|
---|
1362 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1363 |
|
---|
1364 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1365 |
|
---|
1366 | delete edgeData;
|
---|
1367 |
|
---|
1368 |
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | void testEdgeBuilderMultiIndexBufSingleVertexBuf()
|
---|
1372 | {
|
---|
1373 | /* This tests the edge builders ability to find shared edges when there are
|
---|
1374 | multiple index sets (submeshes) using a single vertex buffer.
|
---|
1375 | */
|
---|
1376 | VertexData vd;
|
---|
1377 | IndexData id[4];
|
---|
1378 | // Test pyramid
|
---|
1379 | vd.vertexCount = 4;
|
---|
1380 | vd.vertexStart = 0;
|
---|
1381 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1382 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1383 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
|
---|
1384 | vd.vertexBufferBinding->setBinding(0, vbuf);
|
---|
1385 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1386 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1387 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1388 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1389 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1390 | vbuf->unlock();
|
---|
1391 |
|
---|
1392 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1393 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1394 | id[0].indexCount = 3;
|
---|
1395 | id[0].indexStart = 0;
|
---|
1396 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1397 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1398 | id[0].indexBuffer->unlock();
|
---|
1399 |
|
---|
1400 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1401 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1402 | id[1].indexCount = 3;
|
---|
1403 | id[1].indexStart = 0;
|
---|
1404 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1405 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
|
---|
1406 | id[1].indexBuffer->unlock();
|
---|
1407 |
|
---|
1408 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1409 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1410 | id[2].indexCount = 3;
|
---|
1411 | id[2].indexStart = 0;
|
---|
1412 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1413 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
|
---|
1414 | id[2].indexBuffer->unlock();
|
---|
1415 |
|
---|
1416 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1417 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1418 | id[3].indexCount = 3;
|
---|
1419 | id[3].indexStart = 0;
|
---|
1420 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1421 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
|
---|
1422 | id[3].indexBuffer->unlock();
|
---|
1423 |
|
---|
1424 | EdgeListBuilder edgeBuilder;
|
---|
1425 | edgeBuilder.addVertexData(&vd);
|
---|
1426 | edgeBuilder.addIndexData(&id[0]);
|
---|
1427 | edgeBuilder.addIndexData(&id[1]);
|
---|
1428 | edgeBuilder.addIndexData(&id[2]);
|
---|
1429 | edgeBuilder.addIndexData(&id[3]);
|
---|
1430 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1431 |
|
---|
1432 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1433 |
|
---|
1434 | delete edgeData;
|
---|
1435 |
|
---|
1436 |
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 |
|
---|
1440 | void testEdgeBuilderMultiIndexBufMultiVertexBuf()
|
---|
1441 | {
|
---|
1442 | /* This tests the edge builders ability to find shared edges when there are
|
---|
1443 | both multiple index sets (submeshes) each using a different vertex buffer
|
---|
1444 | (not using shared geoemtry).
|
---|
1445 | */
|
---|
1446 |
|
---|
1447 | VertexData vd[4];
|
---|
1448 | IndexData id[4];
|
---|
1449 | // Test pyramid
|
---|
1450 | vd[0].vertexCount = 3;
|
---|
1451 | vd[0].vertexStart = 0;
|
---|
1452 | vd[0].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1453 | vd[0].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1454 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1455 | vd[0].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1456 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1457 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1458 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1459 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1460 | vbuf->unlock();
|
---|
1461 |
|
---|
1462 | vd[1].vertexCount = 3;
|
---|
1463 | vd[1].vertexStart = 0;
|
---|
1464 | vd[1].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1465 | vd[1].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1466 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1467 | vd[1].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1468 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1469 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1470 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1471 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1472 | vbuf->unlock();
|
---|
1473 |
|
---|
1474 | vd[2].vertexCount = 3;
|
---|
1475 | vd[2].vertexStart = 0;
|
---|
1476 | vd[2].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1477 | vd[2].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1478 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1479 | vd[2].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1480 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1481 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1482 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ;
|
---|
1483 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1484 | vbuf->unlock();
|
---|
1485 |
|
---|
1486 | vd[3].vertexCount = 3;
|
---|
1487 | vd[3].vertexStart = 0;
|
---|
1488 | vd[3].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
|
---|
1489 | vd[3].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
|
---|
1490 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true);
|
---|
1491 | vd[3].vertexBufferBinding->setBinding(0, vbuf);
|
---|
1492 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1493 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1494 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ;
|
---|
1495 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50;
|
---|
1496 | vbuf->unlock();
|
---|
1497 |
|
---|
1498 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1499 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1500 | id[0].indexCount = 3;
|
---|
1501 | id[0].indexStart = 0;
|
---|
1502 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1503 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1504 | id[0].indexBuffer->unlock();
|
---|
1505 |
|
---|
1506 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1507 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1508 | id[1].indexCount = 3;
|
---|
1509 | id[1].indexStart = 0;
|
---|
1510 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1511 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
|
---|
1512 | id[1].indexBuffer->unlock();
|
---|
1513 |
|
---|
1514 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1515 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1516 | id[2].indexCount = 3;
|
---|
1517 | id[2].indexStart = 0;
|
---|
1518 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1519 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
1520 | id[2].indexBuffer->unlock();
|
---|
1521 |
|
---|
1522 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
|
---|
1523 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true);
|
---|
1524 | id[3].indexCount = 3;
|
---|
1525 | id[3].indexStart = 0;
|
---|
1526 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
---|
1527 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1;
|
---|
1528 | id[3].indexBuffer->unlock();
|
---|
1529 |
|
---|
1530 | EdgeListBuilder edgeBuilder;
|
---|
1531 | edgeBuilder.addVertexData(&vd[0]);
|
---|
1532 | edgeBuilder.addVertexData(&vd[1]);
|
---|
1533 | edgeBuilder.addVertexData(&vd[2]);
|
---|
1534 | edgeBuilder.addVertexData(&vd[3]);
|
---|
1535 | edgeBuilder.addIndexData(&id[0], 0);
|
---|
1536 | edgeBuilder.addIndexData(&id[1], 1);
|
---|
1537 | edgeBuilder.addIndexData(&id[2], 2);
|
---|
1538 | edgeBuilder.addIndexData(&id[3], 3);
|
---|
1539 | EdgeData* edgeData = edgeBuilder.build();
|
---|
1540 |
|
---|
1541 | edgeData->log(LogManager::getSingleton().getDefaultLog());
|
---|
1542 |
|
---|
1543 | delete edgeData;
|
---|
1544 |
|
---|
1545 |
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | void testSkeletalAnimation()
|
---|
1549 | {
|
---|
1550 | // Set ambient light
|
---|
1551 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1552 | //mWindow->getViewport(0)->setBackgroundColour(ColourValue::White);
|
---|
1553 |
|
---|
1554 |
|
---|
1555 |
|
---|
1556 | Entity *ent = mSceneMgr->createEntity("robot", "scuttlepod.mesh");
|
---|
1557 | // Uncomment the below to test software skinning
|
---|
1558 | //ent->setMaterialName("Examples/Rocky");
|
---|
1559 | // Add entity to the scene node
|
---|
1560 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1561 | mAnimState = ent->getAnimationState("Walk");
|
---|
1562 | mAnimState->setEnabled(true);
|
---|
1563 |
|
---|
1564 | // Give it a little ambience with lights
|
---|
1565 | Light* l;
|
---|
1566 | l = mSceneMgr->createLight("BlueLight");
|
---|
1567 | l->setPosition(-200,-80,-100);
|
---|
1568 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1569 |
|
---|
1570 | l = mSceneMgr->createLight("GreenLight");
|
---|
1571 | l->setPosition(0,0,-100);
|
---|
1572 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1573 |
|
---|
1574 | // Position the camera
|
---|
1575 | mCamera->setPosition(100,50,100);
|
---|
1576 | mCamera->lookAt(-50,50,0);
|
---|
1577 |
|
---|
1578 | // Report whether hardware skinning is enabled or not
|
---|
1579 | Technique* t = ent->getSubEntity(0)->getMaterial()->getBestTechnique();
|
---|
1580 | Pass* p = t->getPass(0);
|
---|
1581 | if (p->hasVertexProgram() &&
|
---|
1582 | p->getVertexProgram()->isSkeletalAnimationIncluded())
|
---|
1583 | {
|
---|
1584 | mWindow->setDebugText("Hardware skinning is enabled");
|
---|
1585 | }
|
---|
1586 | else
|
---|
1587 | {
|
---|
1588 | mWindow->setDebugText("Software skinning is enabled");
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 |
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 |
|
---|
1595 | void testPrepareShadowVolume(void)
|
---|
1596 | {
|
---|
1597 |
|
---|
1598 | // Set ambient light
|
---|
1599 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1600 |
|
---|
1601 | // Create a point light
|
---|
1602 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1603 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1604 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1605 |
|
---|
1606 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1607 |
|
---|
1608 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1609 | mTestNode[0]->attachObject( pEnt );
|
---|
1610 |
|
---|
1611 | pEnt->getMesh()->prepareForShadowVolume();
|
---|
1612 |
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | void testWindowedViewportMode()
|
---|
1616 | {
|
---|
1617 | // Set ambient light
|
---|
1618 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1619 |
|
---|
1620 | // Create a point light
|
---|
1621 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1622 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1623 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1624 |
|
---|
1625 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1626 |
|
---|
1627 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1628 | mTestNode[0]->attachObject( pEnt );
|
---|
1629 |
|
---|
1630 | mCamera->setWindow(0,0,0.5,0.5);
|
---|
1631 |
|
---|
1632 | }
|
---|
1633 | void testSubEntityVisibility()
|
---|
1634 | {
|
---|
1635 | // Set ambient light
|
---|
1636 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
1637 |
|
---|
1638 | // Create a point light
|
---|
1639 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1640 | l->setType(Light::LT_DIRECTIONAL);
|
---|
1641 | l->setDirection(-Vector3::UNIT_Y);
|
---|
1642 |
|
---|
1643 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild();
|
---|
1644 |
|
---|
1645 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" );
|
---|
1646 | mTestNode[0]->attachObject( pEnt );
|
---|
1647 |
|
---|
1648 | pEnt->getSubEntity(1)->setVisible(false);
|
---|
1649 |
|
---|
1650 |
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | void testAttachObjectsToBones()
|
---|
1654 | {
|
---|
1655 | Entity *ent;
|
---|
1656 | for (int i = 0; i < 5; ++i)
|
---|
1657 | {
|
---|
1658 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
|
---|
1659 | Entity* ent2 = mSceneMgr->createEntity("plane" + StringConverter::toString(i), "razor.mesh");
|
---|
1660 | ent->attachObjectToBone("Joint8", ent2);
|
---|
1661 | // Add entity to the scene node
|
---|
1662 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1663 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1664 | if (i==4)
|
---|
1665 | {
|
---|
1666 | ent->getParentNode()->yaw(Degree(45));
|
---|
1667 | }
|
---|
1668 | }
|
---|
1669 | mAnimState = ent->getAnimationState("Walk");
|
---|
1670 | mAnimState->setEnabled(true);
|
---|
1671 |
|
---|
1672 |
|
---|
1673 |
|
---|
1674 | // Give it a little ambience with lights
|
---|
1675 | Light* l;
|
---|
1676 | l = mSceneMgr->createLight("BlueLight");
|
---|
1677 | l->setPosition(-200,-80,-100);
|
---|
1678 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1679 |
|
---|
1680 | l = mSceneMgr->createLight("GreenLight");
|
---|
1681 | l->setPosition(0,0,-100);
|
---|
1682 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1683 |
|
---|
1684 | // Position the camera
|
---|
1685 | mCamera->setPosition(100,50,100);
|
---|
1686 | mCamera->lookAt(-50,50,0);
|
---|
1687 |
|
---|
1688 | mSceneMgr->setAmbientLight(ColourValue(1,1,1,1));
|
---|
1689 | mSceneMgr->showBoundingBoxes(true);
|
---|
1690 |
|
---|
1691 | }
|
---|
1692 | void testOrtho()
|
---|
1693 | {
|
---|
1694 | // Set ambient light
|
---|
1695 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
|
---|
1696 |
|
---|
1697 | // Create a point light
|
---|
1698 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1699 | l->setPosition(800,600,0);
|
---|
1700 |
|
---|
1701 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1702 | mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1703 |
|
---|
1704 | Entity* pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
1705 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
1706 | mTestNode[1]->attachObject( pEnt );
|
---|
1707 |
|
---|
1708 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
1709 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
1710 | mTestNode[2]->attachObject( pEnt );
|
---|
1711 |
|
---|
1712 |
|
---|
1713 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
1714 |
|
---|
1715 |
|
---|
1716 | Plane plane;
|
---|
1717 | plane.normal = Vector3::UNIT_Y;
|
---|
1718 | plane.d = 100;
|
---|
1719 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
1720 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
1721 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
1722 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
1723 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
1724 | pPlaneEnt->setCastShadows(false);
|
---|
1725 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
1726 |
|
---|
1727 | mCamera->setFixedYawAxis(false);
|
---|
1728 | mCamera->setProjectionType(PT_ORTHOGRAPHIC);
|
---|
1729 | mCamera->setPosition(0,10000,0);
|
---|
1730 | mCamera->lookAt(0,0,0);
|
---|
1731 | mCamera->setNearClipDistance(1000);
|
---|
1732 |
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | void testManualLOD()
|
---|
1736 | {
|
---|
1737 | MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("robot.mesh",
|
---|
1738 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1739 |
|
---|
1740 | msh1->createManualLodLevel(200, "razor.mesh");
|
---|
1741 | msh1->createManualLodLevel(500, "sphere.mesh");
|
---|
1742 |
|
---|
1743 | Entity *ent;
|
---|
1744 | for (int i = 0; i < 5; ++i)
|
---|
1745 | {
|
---|
1746 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
|
---|
1747 | // Add entity to the scene node
|
---|
1748 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1749 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1750 | }
|
---|
1751 | mAnimState = ent->getAnimationState("Walk");
|
---|
1752 | mAnimState->setEnabled(true);
|
---|
1753 |
|
---|
1754 |
|
---|
1755 |
|
---|
1756 | // Give it a little ambience with lights
|
---|
1757 | Light* l;
|
---|
1758 | l = mSceneMgr->createLight("BlueLight");
|
---|
1759 | l->setPosition(-200,-80,-100);
|
---|
1760 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1761 |
|
---|
1762 | l = mSceneMgr->createLight("GreenLight");
|
---|
1763 | l->setPosition(0,0,-100);
|
---|
1764 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1765 |
|
---|
1766 | // Position the camera
|
---|
1767 | mCamera->setPosition(100,50,100);
|
---|
1768 | mCamera->lookAt(-50,50,0);
|
---|
1769 |
|
---|
1770 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
1771 |
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | void testFallbackResourceGroup()
|
---|
1775 | {
|
---|
1776 | // Load all textures from new resource group "Test"
|
---|
1777 | ResourceGroupManager::getSingleton().removeResourceLocation("../../../Media/materials/textures");
|
---|
1778 | ResourceGroupManager::getSingleton().createResourceGroup("Test");
|
---|
1779 | ResourceGroupManager::getSingleton().addResourceLocation("../../../Media/materials/textures", "FileSystem", "Test");
|
---|
1780 |
|
---|
1781 | // Load a texture from default group (won't be found there, but should fall back)
|
---|
1782 | TextureManager::getSingleton().load("dirt01.jpg", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1783 |
|
---|
1784 | ResourceGroupManager::getSingleton().unloadUnreferencedResourcesInGroup("Test");
|
---|
1785 |
|
---|
1786 | // Add a few robots for fun
|
---|
1787 | Entity *ent;
|
---|
1788 | for (int i = 0; i < 5; ++i)
|
---|
1789 | {
|
---|
1790 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh");
|
---|
1791 | // Add entity to the scene node
|
---|
1792 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1793 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1794 | }
|
---|
1795 | // Give it a little ambience with lights
|
---|
1796 | Light* l;
|
---|
1797 | l = mSceneMgr->createLight("BlueLight");
|
---|
1798 | l->setPosition(-200,-80,-100);
|
---|
1799 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1800 |
|
---|
1801 | l = mSceneMgr->createLight("GreenLight");
|
---|
1802 | l->setPosition(0,0,-100);
|
---|
1803 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1804 |
|
---|
1805 | // Position the camera
|
---|
1806 | mCamera->setPosition(100,50,100);
|
---|
1807 | mCamera->lookAt(-50,50,0);
|
---|
1808 |
|
---|
1809 | }
|
---|
1810 |
|
---|
1811 | void testGeneratedLOD()
|
---|
1812 | {
|
---|
1813 | MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("barrel.mesh",
|
---|
1814 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
1815 |
|
---|
1816 | msh1->removeLodLevels();
|
---|
1817 |
|
---|
1818 | Mesh::LodDistanceList lodList;
|
---|
1819 | lodList.push_back(50);
|
---|
1820 | lodList.push_back(100);
|
---|
1821 | lodList.push_back(150);
|
---|
1822 | lodList.push_back(200);
|
---|
1823 | lodList.push_back(250);
|
---|
1824 | lodList.push_back(300);
|
---|
1825 |
|
---|
1826 | msh1->generateLodLevels(lodList, ProgressiveMesh::VRQ_PROPORTIONAL, 0.3);
|
---|
1827 |
|
---|
1828 | Entity *ent;
|
---|
1829 | for (int i = 0; i < 1; ++i)
|
---|
1830 | {
|
---|
1831 | ent = mSceneMgr->createEntity("tst" + StringConverter::toString(i), "barrel.mesh");
|
---|
1832 | // Add entity to the scene node
|
---|
1833 | mSceneMgr->getRootSceneNode()->createChildSceneNode(
|
---|
1834 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent);
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | // Give it a little ambience with lights
|
---|
1838 | Light* l;
|
---|
1839 | l = mSceneMgr->createLight("BlueLight");
|
---|
1840 | l->setPosition(-200,-80,-100);
|
---|
1841 | l->setDiffuseColour(0.5, 0.5, 1.0);
|
---|
1842 |
|
---|
1843 | l = mSceneMgr->createLight("GreenLight");
|
---|
1844 | l->setPosition(0,0,-100);
|
---|
1845 | l->setDiffuseColour(0.5, 1.0, 0.5);
|
---|
1846 |
|
---|
1847 | // Position the camera
|
---|
1848 | mCamera->setPosition(100,50,100);
|
---|
1849 | mCamera->lookAt(-50,50,0);
|
---|
1850 |
|
---|
1851 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
1852 |
|
---|
1853 | }
|
---|
1854 |
|
---|
1855 | void clearSceneSetup()
|
---|
1856 | {
|
---|
1857 | bool showOctree = true;
|
---|
1858 | mSceneMgr->setOption("ShowOctree", &showOctree);
|
---|
1859 |
|
---|
1860 | // Set ambient light
|
---|
1861 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
1862 |
|
---|
1863 | // Create a skydome
|
---|
1864 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
1865 |
|
---|
1866 | // Create a light
|
---|
1867 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
1868 | // Accept default settings: point light, white diffuse, just set position
|
---|
1869 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
1870 | // other objects, but I don't
|
---|
1871 | l->setPosition(20,80,50);
|
---|
1872 |
|
---|
1873 | Entity *ent;
|
---|
1874 |
|
---|
1875 | // Create an entity (the floor)
|
---|
1876 | ent = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
1877 | ent->setMaterialName("Examples/RustySteel");
|
---|
1878 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
|
---|
1879 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
1880 |
|
---|
1881 | // Add a head, give it it's own node
|
---|
1882 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1883 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
1884 | headNode->attachObject(ent);
|
---|
1885 |
|
---|
1886 | // Add another head, give it it's own node
|
---|
1887 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1888 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh");
|
---|
1889 | headNode2->attachObject(ent);
|
---|
1890 |
|
---|
1891 | // Make sure the head node tracks the root
|
---|
1892 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z);
|
---|
1893 | //headNode->setFixedYawAxis(true);
|
---|
1894 |
|
---|
1895 | // Create the camera node & attach camera
|
---|
1896 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
1897 | //camNode->attachObject(mCamera);
|
---|
1898 |
|
---|
1899 | // set up spline animation of node
|
---|
1900 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10);
|
---|
1901 | // Spline it for nice curves
|
---|
1902 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
1903 | // Create a track to animate the head's node
|
---|
1904 | NodeAnimationTrack* track = anim->createNodeTrack(0, headNode);
|
---|
1905 | // Setup keyframes
|
---|
1906 | TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition
|
---|
1907 | key = track->createNodeKeyFrame(2.5);
|
---|
1908 | key->setTranslate(Vector3(500,500,-1000));
|
---|
1909 | key = track->createNodeKeyFrame(5);
|
---|
1910 | key->setTranslate(Vector3(-1500,1000,-600));
|
---|
1911 | key = track->createNodeKeyFrame(7.5);
|
---|
1912 | key->setTranslate(Vector3(0,-100,0));
|
---|
1913 | key = track->createNodeKeyFrame(10);
|
---|
1914 | key->setTranslate(Vector3(0,0,0));
|
---|
1915 | // Create a track to animate the second head's node
|
---|
1916 | track = anim->createNodeTrack(1, headNode2);
|
---|
1917 | // Setup keyframes
|
---|
1918 | key = track->createNodeKeyFrame(0); // startposition
|
---|
1919 | key = track->createNodeKeyFrame(2.5);
|
---|
1920 | key->setTranslate(Vector3(-500,600,-100));
|
---|
1921 | key = track->createNodeKeyFrame(5);
|
---|
1922 | key->setTranslate(Vector3(800,200,-600));
|
---|
1923 | key = track->createNodeKeyFrame(7.5);
|
---|
1924 | key->setTranslate(Vector3(200,-1000,0));
|
---|
1925 | key = track->createNodeKeyFrame(10);
|
---|
1926 | key->setTranslate(Vector3(30,70,110));
|
---|
1927 | // Create a new animation state to track this
|
---|
1928 | mAnimState = mSceneMgr->createAnimationState("CameraTrack");
|
---|
1929 | mAnimState->setEnabled(true);
|
---|
1930 | }
|
---|
1931 | class ClearSceneListener : public FrameListener
|
---|
1932 | {
|
---|
1933 | protected:
|
---|
1934 | SceneManager* mSceneMgr;
|
---|
1935 | PlayPenApplication* ppApp;
|
---|
1936 |
|
---|
1937 | public:
|
---|
1938 | ClearSceneListener(SceneManager* sm, PlayPenApplication* target)
|
---|
1939 | {
|
---|
1940 | mSceneMgr = sm;
|
---|
1941 | ppApp = target;
|
---|
1942 | }
|
---|
1943 | bool frameStarted(const FrameEvent& evt)
|
---|
1944 | {
|
---|
1945 | static Real timeElapsed = 0;
|
---|
1946 |
|
---|
1947 | timeElapsed += evt.timeSinceLastFrame;
|
---|
1948 | if (timeElapsed > 15)
|
---|
1949 | {
|
---|
1950 | mSceneMgr->clearScene();
|
---|
1951 | ppApp->clearSceneSetup();
|
---|
1952 | timeElapsed = 0;
|
---|
1953 | }
|
---|
1954 | return true;
|
---|
1955 | }
|
---|
1956 | };
|
---|
1957 | ClearSceneListener* csListener;
|
---|
1958 | void testClearScene()
|
---|
1959 | {
|
---|
1960 | // Define a floor plane mesh
|
---|
1961 | Plane p;
|
---|
1962 | p.normal = Vector3::UNIT_Y;
|
---|
1963 | p.d = 200;
|
---|
1964 | MeshManager::getSingleton().createPlane("FloorPlane",
|
---|
1965 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
1966 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z);
|
---|
1967 |
|
---|
1968 |
|
---|
1969 | // leak here I know
|
---|
1970 | csListener = new ClearSceneListener(mSceneMgr, this);
|
---|
1971 | Root::getSingleton().addFrameListener(csListener);
|
---|
1972 | clearSceneSetup();
|
---|
1973 | }
|
---|
1974 |
|
---|
1975 | void testStencilShadows(ShadowTechnique tech, bool pointLight, bool directionalLight)
|
---|
1976 | {
|
---|
1977 | mSceneMgr->setShadowTechnique(tech);
|
---|
1978 | //mSceneMgr->setShowDebugShadows(true);
|
---|
1979 | mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000);
|
---|
1980 | //mSceneMgr->setShadowColour(ColourValue(0.4, 0.25, 0.25));
|
---|
1981 |
|
---|
1982 | //mSceneMgr->setShadowFarDistance(800);
|
---|
1983 | // Set ambient light
|
---|
1984 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));
|
---|
1985 |
|
---|
1986 | // Point light
|
---|
1987 | if(pointLight)
|
---|
1988 | {
|
---|
1989 | mLight = mSceneMgr->createLight("MainLight");
|
---|
1990 | mLight->setPosition(-400,400,-300);
|
---|
1991 | mLight->setDiffuseColour(0.9, 0.9, 1);
|
---|
1992 | mLight->setSpecularColour(0.9, 0.9, 1);
|
---|
1993 | mLight->setAttenuation(6000,1,0.001,0);
|
---|
1994 | }
|
---|
1995 | // Directional light
|
---|
1996 | if (directionalLight)
|
---|
1997 | {
|
---|
1998 | mLight = mSceneMgr->createLight("Light2");
|
---|
1999 | Vector3 dir(-1,-1,0);
|
---|
2000 | dir.normalise();
|
---|
2001 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
2002 | mLight->setDirection(dir);
|
---|
2003 | mLight->setDiffuseColour(1, 1, 0.8);
|
---|
2004 | mLight->setSpecularColour(1, 1, 1);
|
---|
2005 | }
|
---|
2006 |
|
---|
2007 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2008 |
|
---|
2009 | // Hardware skin
|
---|
2010 | Entity* pEnt;
|
---|
2011 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
2012 | AnimationState* anim = pEnt->getAnimationState("Walk");
|
---|
2013 | anim->setEnabled(true);
|
---|
2014 | mAnimStateList.push_back(anim);
|
---|
2015 | mTestNode[0]->attachObject( pEnt );
|
---|
2016 |
|
---|
2017 | // Software skin
|
---|
2018 | pEnt = mSceneMgr->createEntity( "12", "robot.mesh" );
|
---|
2019 | anim = pEnt->getAnimationState("Walk");
|
---|
2020 | anim->setEnabled(true);
|
---|
2021 | mAnimStateList.push_back(anim);
|
---|
2022 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 0))->attachObject(pEnt);
|
---|
2023 | pEnt->setMaterialName("Examples/Rocky");
|
---|
2024 |
|
---|
2025 |
|
---|
2026 | // Does not receive shadows
|
---|
2027 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
2028 | pEnt->setMaterialName("Examples/EnvMappedRustySteel");
|
---|
2029 | MaterialPtr mat2 = MaterialManager::getSingleton().getByName("Examples/EnvMappedRustySteel");
|
---|
2030 | mat2->setReceiveShadows(false);
|
---|
2031 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
2032 | mTestNode[2]->attachObject( pEnt );
|
---|
2033 |
|
---|
2034 | // Transparent object
|
---|
2035 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
|
---|
2036 | pEnt->setMaterialName("Examples/TransparentTest");
|
---|
2037 | MaterialPtr mat3 = MaterialManager::getSingleton().getByName("Examples/TransparentTest");
|
---|
2038 | pEnt->setCastShadows(false);
|
---|
2039 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
|
---|
2040 | mTestNode[3]->attachObject( pEnt );
|
---|
2041 |
|
---|
2042 | // User test
|
---|
2043 | /*
|
---|
2044 | pEnt = mSceneMgr->createEntity( "3.6", "ogre_male_endCaps.mesh" );
|
---|
2045 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 0, 100))->attachObject( pEnt );
|
---|
2046 | */
|
---|
2047 |
|
---|
2048 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
|
---|
2049 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2050 | unsigned short src, dest;
|
---|
2051 | if (!msh->suggestTangentVectorBuildParams(src, dest))
|
---|
2052 | {
|
---|
2053 | msh->buildTangentVectors(src, dest);
|
---|
2054 | }
|
---|
2055 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
2056 | pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
|
---|
2057 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
2058 | mTestNode[2]->attachObject( pEnt );
|
---|
2059 |
|
---|
2060 |
|
---|
2061 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
|
---|
2062 | "Examples/Smoke");
|
---|
2063 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
|
---|
2064 | mTestNode[4]->attachObject(pSys2);
|
---|
2065 |
|
---|
2066 |
|
---|
2067 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
2068 |
|
---|
2069 |
|
---|
2070 | Plane plane;
|
---|
2071 | plane.normal = Vector3::UNIT_Y;
|
---|
2072 | plane.d = 100;
|
---|
2073 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2074 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2075 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2076 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2077 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2078 | pPlaneEnt->setCastShadows(false);
|
---|
2079 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2080 |
|
---|
2081 | mCamera->setPosition(180, 34, 223);
|
---|
2082 | mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791));
|
---|
2083 |
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | void test2Spotlights()
|
---|
2087 | {
|
---|
2088 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
2089 |
|
---|
2090 | mLight = mSceneMgr->createLight("MainLight");
|
---|
2091 | // Spotlight test
|
---|
2092 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2093 | mLight->setDiffuseColour(1.0, 0.0, 0.8);
|
---|
2094 | mLight->setSpotlightRange(Degree(30), Degree(40));
|
---|
2095 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2096 | mTestNode[0]->setPosition(800,600,0);
|
---|
2097 | mTestNode[0]->lookAt(Vector3(800,0,0), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2098 | mTestNode[0]->attachObject(mLight);
|
---|
2099 |
|
---|
2100 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2101 | mLight = mSceneMgr->createLight("AnotherLight");
|
---|
2102 | // Spotlight test
|
---|
2103 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2104 | mLight->setDiffuseColour(0, 1.0, 0.8);
|
---|
2105 | mLight->setSpotlightRange(Degree(30), Degree(40));
|
---|
2106 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2107 | mTestNode[1]->setPosition(0,600,800);
|
---|
2108 | mTestNode[1]->lookAt(Vector3(0,0,800), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2109 | mTestNode[1]->attachObject(mLight);
|
---|
2110 |
|
---|
2111 |
|
---|
2112 | Plane plane;
|
---|
2113 | plane.normal = Vector3::UNIT_Y;
|
---|
2114 | plane.d = 100;
|
---|
2115 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2116 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2117 | 3500,3500,100,100,true,1,5,5,Vector3::UNIT_Z);
|
---|
2118 | Entity* pPlaneEnt;
|
---|
2119 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2120 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2121 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2122 |
|
---|
2123 | }
|
---|
2124 | void testTextureShadows(ShadowTechnique tech)
|
---|
2125 | {
|
---|
2126 | mSceneMgr->setShadowTextureSize(512);
|
---|
2127 | mSceneMgr->setShadowTechnique(tech);
|
---|
2128 | mSceneMgr->setShadowFarDistance(1500);
|
---|
2129 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
|
---|
2130 | //mSceneMgr->setShadowFarDistance(800);
|
---|
2131 | // Set ambient light
|
---|
2132 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
2133 |
|
---|
2134 | mLight = mSceneMgr->createLight("MainLight");
|
---|
2135 |
|
---|
2136 | // Directional test
|
---|
2137 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
2138 | Vector3 vec(-1,-1,0);
|
---|
2139 | vec.normalise();
|
---|
2140 | mLight->setDirection(vec);
|
---|
2141 |
|
---|
2142 | /*
|
---|
2143 | // Spotlight test
|
---|
2144 | mLight->setType(Light::LT_SPOTLIGHT);
|
---|
2145 | mLight->setDiffuseColour(1.0, 1.0, 0.8);
|
---|
2146 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2147 | mTestNode[0]->setPosition(800,600,0);
|
---|
2148 | mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD, Vector3::UNIT_Z);
|
---|
2149 | mTestNode[0]->attachObject(mLight);
|
---|
2150 | */
|
---|
2151 |
|
---|
2152 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2153 |
|
---|
2154 |
|
---|
2155 | Entity* pEnt;
|
---|
2156 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
2157 | //pEnt->setRenderingDistance(100);
|
---|
2158 | mAnimState = pEnt->getAnimationState("Walk");
|
---|
2159 | mAnimState->setEnabled(true);
|
---|
2160 | //pEnt->setMaterialName("2 - Default");
|
---|
2161 | mTestNode[1]->attachObject( pEnt );
|
---|
2162 | mTestNode[1]->translate(0,-100,0);
|
---|
2163 |
|
---|
2164 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
|
---|
2165 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200));
|
---|
2166 | mTestNode[2]->attachObject( pEnt );
|
---|
2167 |
|
---|
2168 | // Transparent object (can force cast shadows)
|
---|
2169 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" );
|
---|
2170 | MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency",
|
---|
2171 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2172 | tmat->setTransparencyCastsShadows(true);
|
---|
2173 | Pass* tpass = tmat->getTechnique(0)->getPass(0);
|
---|
2174 | tpass->setAlphaRejectSettings(CMPF_GREATER, 150);
|
---|
2175 | tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
---|
2176 | tpass->createTextureUnitState("gras_02.png");
|
---|
2177 | tpass->setCullingMode(CULL_NONE);
|
---|
2178 |
|
---|
2179 | pEnt->setMaterialName("TestAlphaTransparency");
|
---|
2180 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200));
|
---|
2181 | mTestNode[3]->attachObject( pEnt );
|
---|
2182 |
|
---|
2183 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh",
|
---|
2184 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2185 | msh->buildTangentVectors();
|
---|
2186 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" );
|
---|
2187 | //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular");
|
---|
2188 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200));
|
---|
2189 | mTestNode[2]->attachObject( pEnt );
|
---|
2190 |
|
---|
2191 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
|
---|
2192 |
|
---|
2193 |
|
---|
2194 | Plane plane;
|
---|
2195 | plane.normal = Vector3::UNIT_Y;
|
---|
2196 | plane.d = 100;
|
---|
2197 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2198 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2199 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2200 | Entity* pPlaneEnt;
|
---|
2201 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2202 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2203 | pPlaneEnt->setCastShadows(false);
|
---|
2204 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2205 |
|
---|
2206 | // Set up a debug panel to display the shadow
|
---|
2207 | MaterialPtr debugMat = MaterialManager::getSingleton().create(
|
---|
2208 | "Ogre/DebugShadowMap", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2209 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
|
---|
2210 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("Ogre/ShadowTexture0");
|
---|
2211 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2212 | //t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("spot_shadow_fade.png");
|
---|
2213 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2214 | //t->setColourOperation(LBO_ADD);
|
---|
2215 |
|
---|
2216 | OverlayContainer* debugPanel = (OverlayContainer*)
|
---|
2217 | (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel"));
|
---|
2218 | debugPanel->_setPosition(0.8, 0);
|
---|
2219 | debugPanel->_setDimensions(0.2, 0.3);
|
---|
2220 | debugPanel->setMaterialName("Ogre/DebugShadowMap");
|
---|
2221 | Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
|
---|
2222 | debugOverlay->add2D(debugPanel);
|
---|
2223 |
|
---|
2224 |
|
---|
2225 |
|
---|
2226 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke",
|
---|
2227 | "Examples/Smoke");
|
---|
2228 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200));
|
---|
2229 | mTestNode[4]->attachObject(pSys2);
|
---|
2230 |
|
---|
2231 |
|
---|
2232 | }
|
---|
2233 |
|
---|
2234 | void testOverlayZOrder(void)
|
---|
2235 | {
|
---|
2236 | Overlay* o = OverlayManager::getSingleton().getByName("Test/Overlay3");
|
---|
2237 | o->show();
|
---|
2238 | o = OverlayManager::getSingleton().getByName("Test/Overlay2");
|
---|
2239 | o->show();
|
---|
2240 | o = OverlayManager::getSingleton().getByName("Test/Overlay1");
|
---|
2241 | o->show();
|
---|
2242 | }
|
---|
2243 |
|
---|
2244 | void createRandomEntityClones(Entity* ent, size_t cloneCount,
|
---|
2245 | const Vector3& min, const Vector3& max)
|
---|
2246 | {
|
---|
2247 | Entity *cloneEnt;
|
---|
2248 | for (size_t n = 0; n < cloneCount; ++n)
|
---|
2249 | {
|
---|
2250 | // Create a new node under the root
|
---|
2251 | SceneNode* node = mSceneMgr->createSceneNode();
|
---|
2252 | // Random translate
|
---|
2253 | Vector3 nodePos;
|
---|
2254 | nodePos.x = Math::RangeRandom(min.x, max.x);
|
---|
2255 | nodePos.y = Math::RangeRandom(min.y, max.y);
|
---|
2256 | nodePos.z = Math::RangeRandom(min.z, max.z);
|
---|
2257 | node->setPosition(nodePos);
|
---|
2258 | mSceneMgr->getRootSceneNode()->addChild(node);
|
---|
2259 | cloneEnt = ent->clone(ent->getName() + "_clone" + StringConverter::toString(n));
|
---|
2260 | // Attach to new node
|
---|
2261 | node->attachObject(cloneEnt);
|
---|
2262 |
|
---|
2263 | }
|
---|
2264 | }
|
---|
2265 |
|
---|
2266 | void testIntersectionSceneQuery()
|
---|
2267 | {
|
---|
2268 | // Set ambient light
|
---|
2269 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2270 |
|
---|
2271 | // Create a point light
|
---|
2272 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2273 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2274 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2275 |
|
---|
2276 | // Create a set of random balls
|
---|
2277 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh");
|
---|
2278 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2279 | createRandomEntityClones(ent, 500, Vector3(-5000,-5000,-5000), Vector3(5000,5000,5000));
|
---|
2280 |
|
---|
2281 | //intersectionQuery = mSceneMgr->createIntersectionQuery();
|
---|
2282 | }
|
---|
2283 |
|
---|
2284 | void testRaySceneQuery()
|
---|
2285 | {
|
---|
2286 | // Set ambient light
|
---|
2287 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2288 |
|
---|
2289 | // Create a point light
|
---|
2290 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2291 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2292 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2293 |
|
---|
2294 | // Create a set of random balls
|
---|
2295 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh");
|
---|
2296 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2297 | createRandomEntityClones(ent, 100, Vector3(-1000,-1000,-1000), Vector3(1000,1000,1000));
|
---|
2298 |
|
---|
2299 | rayQuery = mSceneMgr->createRayQuery(
|
---|
2300 | Ray(mCamera->getPosition(), mCamera->getDirection()));
|
---|
2301 | rayQuery->setSortByDistance(true, 1);
|
---|
2302 |
|
---|
2303 | //bool val = true;
|
---|
2304 | //mSceneMgr->setOption("ShowOctree", &val);
|
---|
2305 |
|
---|
2306 | }
|
---|
2307 |
|
---|
2308 | void testLotsAndLotsOfEntities()
|
---|
2309 | {
|
---|
2310 | // Set ambient light
|
---|
2311 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2312 |
|
---|
2313 | // Create a point light
|
---|
2314 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2315 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2316 | l->setDirection(-Vector3::UNIT_Y);
|
---|
2317 |
|
---|
2318 | // Create a set of random balls
|
---|
2319 | Entity* ent = mSceneMgr->createEntity("Ball", "ogrehead.mesh");
|
---|
2320 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2321 | createRandomEntityClones(ent, 400, Vector3(-2000,-2000,-2000), Vector3(2000,2000,2000));
|
---|
2322 |
|
---|
2323 | //bool val = true;
|
---|
2324 | //mSceneMgr->setOption("ShowOctree", &val);
|
---|
2325 |
|
---|
2326 | }
|
---|
2327 |
|
---|
2328 | void testSimpleMesh()
|
---|
2329 | {
|
---|
2330 | // Set ambient light
|
---|
2331 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2332 |
|
---|
2333 | // Create a point light
|
---|
2334 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2335 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2336 | Vector3 dir(1, -1, 0);
|
---|
2337 | dir.normalise();
|
---|
2338 | l->setDirection(dir);
|
---|
2339 |
|
---|
2340 | // Create a set of random balls
|
---|
2341 | Entity* ent = mSceneMgr->createEntity("test", "xsicylinder.mesh");
|
---|
2342 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2343 |
|
---|
2344 | }
|
---|
2345 |
|
---|
2346 | void test2Windows(void)
|
---|
2347 | {
|
---|
2348 | // Set ambient light
|
---|
2349 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2350 |
|
---|
2351 | // Create a point light
|
---|
2352 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2353 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2354 | Vector3 dir(1, -1, 0);
|
---|
2355 | dir.normalise();
|
---|
2356 | l->setDirection(dir);
|
---|
2357 |
|
---|
2358 | // Create a set of random balls
|
---|
2359 | Entity* ent = mSceneMgr->createEntity("test", "ogrehead.mesh");
|
---|
2360 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
2361 |
|
---|
2362 | NameValuePairList valuePair;
|
---|
2363 | valuePair["top"] = StringConverter::toString(0);
|
---|
2364 | valuePair["left"] = StringConverter::toString(0);
|
---|
2365 |
|
---|
2366 | RenderWindow* win2 = mRoot->createRenderWindow("window2", 200,200, false, &valuePair);
|
---|
2367 | win2->addViewport(mCamera);
|
---|
2368 |
|
---|
2369 | }
|
---|
2370 |
|
---|
2371 | void testStaticGeometry(void)
|
---|
2372 | {
|
---|
2373 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
2374 | //mSceneMgr->setShowDebugShadows(true);
|
---|
2375 |
|
---|
2376 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox");
|
---|
2377 | // Set ambient light
|
---|
2378 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2379 |
|
---|
2380 | // Create a point light
|
---|
2381 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2382 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2383 | Vector3 dir(0, -1, -1.5);
|
---|
2384 | dir.normalise();
|
---|
2385 | l->setDirection(dir);
|
---|
2386 | l->setDiffuseColour(1.0, 0.7, 0.0);
|
---|
2387 |
|
---|
2388 |
|
---|
2389 | Plane plane;
|
---|
2390 | plane.normal = Vector3::UNIT_Y;
|
---|
2391 | plane.d = 0;
|
---|
2392 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2393 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2394 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2395 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2396 | pPlaneEnt->setMaterialName("Examples/GrassFloor");
|
---|
2397 | pPlaneEnt->setCastShadows(false);
|
---|
2398 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2399 |
|
---|
2400 | Vector3 min(-2000,0,-2000);
|
---|
2401 | Vector3 max(2000,0,2000);
|
---|
2402 |
|
---|
2403 |
|
---|
2404 | Entity* e = mSceneMgr->createEntity("1", "column.mesh");
|
---|
2405 | //createRandomEntityClones(e, 1000, min, max);
|
---|
2406 |
|
---|
2407 | StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
|
---|
2408 | s->setCastShadows(true);
|
---|
2409 | s->setRegionDimensions(Vector3(500,500,500));
|
---|
2410 | for (int i = 0; i < 100; ++i)
|
---|
2411 | {
|
---|
2412 | Vector3 pos;
|
---|
2413 | pos.x = Math::RangeRandom(min.x, max.x);
|
---|
2414 | pos.y = Math::RangeRandom(min.y, max.y);
|
---|
2415 | pos.z = Math::RangeRandom(min.z, max.z);
|
---|
2416 |
|
---|
2417 | s->addEntity(e, pos, Quaternion::IDENTITY);
|
---|
2418 |
|
---|
2419 | }
|
---|
2420 |
|
---|
2421 | s->build();
|
---|
2422 | //s->setRenderingDistance(1000);
|
---|
2423 | //s->dump("static.txt");
|
---|
2424 | //mSceneMgr->showBoundingBoxes(true);
|
---|
2425 | mCamera->setLodBias(0.5);
|
---|
2426 |
|
---|
2427 |
|
---|
2428 |
|
---|
2429 |
|
---|
2430 | }
|
---|
2431 |
|
---|
2432 | void testReloadResources()
|
---|
2433 | {
|
---|
2434 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
2435 | ResourceGroupManager::getSingleton().createResourceGroup("Sinbad");
|
---|
2436 | Root::getSingleton().addResourceLocation("../../../Media/models", "FileSystem", "Sinbad");
|
---|
2437 | MeshManager& mmgr = MeshManager::getSingleton();
|
---|
2438 | mmgr.load("robot.mesh", "Sinbad");
|
---|
2439 | mmgr.load("knot.mesh", "Sinbad");
|
---|
2440 |
|
---|
2441 | Entity* e = mSceneMgr->createEntity("1", "robot.mesh");
|
---|
2442 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
|
---|
2443 | e = mSceneMgr->createEntity("2", "robot.mesh");
|
---|
2444 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0))->attachObject(e);
|
---|
2445 | e = mSceneMgr->createEntity("3", "knot.mesh");
|
---|
2446 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,300,0))->attachObject(e);
|
---|
2447 |
|
---|
2448 | testreload = true;
|
---|
2449 |
|
---|
2450 | }
|
---|
2451 |
|
---|
2452 | void testBillboardTextureCoords()
|
---|
2453 | {
|
---|
2454 | mSceneMgr->setAmbientLight(ColourValue::White);
|
---|
2455 |
|
---|
2456 | BillboardSet* bbs = mSceneMgr->createBillboardSet("test");
|
---|
2457 | BillboardSet* bbs2 = mSceneMgr->createBillboardSet("test2");
|
---|
2458 | float xsegs = 3;
|
---|
2459 | float ysegs = 3;
|
---|
2460 | float width = 300;
|
---|
2461 | float height = 300;
|
---|
2462 | float gap = 20;
|
---|
2463 |
|
---|
2464 | // set up texture coords
|
---|
2465 | bbs->setTextureStacksAndSlices(ysegs, xsegs);
|
---|
2466 | bbs->setDefaultDimensions(width/xsegs, height/xsegs);
|
---|
2467 | bbs2->setDefaultDimensions(width/xsegs, height/xsegs);
|
---|
2468 |
|
---|
2469 | for (float y = 0; y < ysegs; ++y)
|
---|
2470 | {
|
---|
2471 | for (float x = 0; x < xsegs; ++x)
|
---|
2472 | {
|
---|
2473 | Vector3 midPoint;
|
---|
2474 | midPoint.x = (x * width / xsegs) + ((x-1) * gap);
|
---|
2475 | midPoint.y = (y * height / ysegs) + ((y-1) * gap);
|
---|
2476 | midPoint.z = 0;
|
---|
2477 | Billboard* bb = bbs->createBillboard(midPoint);
|
---|
2478 | bb->setTexcoordIndex((ysegs - y - 1)*xsegs + x);
|
---|
2479 | Billboard* bb2 = bbs2->createBillboard(midPoint);
|
---|
2480 | bb2->setTexcoordRect(
|
---|
2481 | FloatRect((x + 0) / xsegs, (ysegs - y - 1) / ysegs,
|
---|
2482 | (x + 1) / xsegs, (ysegs - y - 0) / ysegs));
|
---|
2483 | }
|
---|
2484 | }
|
---|
2485 |
|
---|
2486 | bbs->setMaterialName("Examples/OgreLogo");
|
---|
2487 | bbs2->setMaterialName("Examples/OgreLogo");
|
---|
2488 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
|
---|
2489 | mSceneMgr->getRootSceneNode()
|
---|
2490 | ->createChildSceneNode(Vector3(- (width + xsegs * gap), 0, 0))
|
---|
2491 | ->attachObject(bbs2);
|
---|
2492 |
|
---|
2493 | }
|
---|
2494 |
|
---|
2495 | class SortFunctor
|
---|
2496 | {
|
---|
2497 | public:
|
---|
2498 | int operator()(const int& p) const
|
---|
2499 | {
|
---|
2500 | return p;
|
---|
2501 | }
|
---|
2502 |
|
---|
2503 | };
|
---|
2504 | void testRadixSort()
|
---|
2505 | {
|
---|
2506 | RadixSort<std::list<int>, int, int> rs;
|
---|
2507 | SortFunctor f;
|
---|
2508 |
|
---|
2509 | std::list<int> particles;
|
---|
2510 | for (int r = 0; r < 20; ++r)
|
---|
2511 | {
|
---|
2512 | particles.push_back((int)Math::RangeRandom(-1e3f, 1e3f));
|
---|
2513 | }
|
---|
2514 |
|
---|
2515 | std::list<int>::iterator i;
|
---|
2516 | LogManager::getSingleton().logMessage("BEFORE");
|
---|
2517 | for (i = particles.begin(); i != particles.end(); ++i)
|
---|
2518 | {
|
---|
2519 | StringUtil::StrStreamType str;
|
---|
2520 | str << *i;
|
---|
2521 | LogManager::getSingleton().logMessage(str.str());
|
---|
2522 | }
|
---|
2523 |
|
---|
2524 | rs.sort(particles, f);
|
---|
2525 |
|
---|
2526 |
|
---|
2527 | LogManager::getSingleton().logMessage("AFTER");
|
---|
2528 | for (i = particles.begin(); i != particles.end(); ++i)
|
---|
2529 | {
|
---|
2530 | StringUtil::StrStreamType str;
|
---|
2531 | str << *i;
|
---|
2532 | LogManager::getSingleton().logMessage(str.str());
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 |
|
---|
2536 |
|
---|
2537 | }
|
---|
2538 |
|
---|
2539 | void testMorphAnimation()
|
---|
2540 | {
|
---|
2541 | bool testStencil = true;
|
---|
2542 |
|
---|
2543 | if (testStencil)
|
---|
2544 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
|
---|
2545 |
|
---|
2546 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2547 | Vector3 dir(-1, -1, 0.5);
|
---|
2548 | dir.normalise();
|
---|
2549 | Light* l = mSceneMgr->createLight("light1");
|
---|
2550 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2551 | l->setDirection(dir);
|
---|
2552 |
|
---|
2553 |
|
---|
2554 | MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh",
|
---|
2555 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2556 |
|
---|
2557 | SubMesh* sm = mesh->getSubMesh(0);
|
---|
2558 | // Re-organise geometry since this mesh has no animation and all
|
---|
2559 | // vertex elements are packed into one buffer
|
---|
2560 | VertexDeclaration* newDecl =
|
---|
2561 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true);
|
---|
2562 | sm->vertexData->reorganiseBuffers(newDecl);
|
---|
2563 | if (testStencil)
|
---|
2564 | sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised
|
---|
2565 | // get the position buffer (which should now be separate);
|
---|
2566 | const VertexElement* posElem =
|
---|
2567 | sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
|
---|
2568 | HardwareVertexBufferSharedPtr origbuf =
|
---|
2569 | sm->vertexData->vertexBufferBinding->getBuffer(
|
---|
2570 | posElem->getSource());
|
---|
2571 |
|
---|
2572 | // Create a new position buffer with updated values
|
---|
2573 | HardwareVertexBufferSharedPtr newbuf =
|
---|
2574 | HardwareBufferManager::getSingleton().createVertexBuffer(
|
---|
2575 | VertexElement::getTypeSize(VET_FLOAT3),
|
---|
2576 | sm->vertexData->vertexCount,
|
---|
2577 | HardwareBuffer::HBU_STATIC, true);
|
---|
2578 | float* pSrc = static_cast<float*>(origbuf->lock(HardwareBuffer::HBL_READ_ONLY));
|
---|
2579 | float* pDst = static_cast<float*>(newbuf->lock(HardwareBuffer::HBL_DISCARD));
|
---|
2580 |
|
---|
2581 | for (size_t v = 0; v < sm->vertexData->vertexCount; ++v)
|
---|
2582 | {
|
---|
2583 | // x
|
---|
2584 | *pDst++ = *pSrc++;
|
---|
2585 | // y (translate)
|
---|
2586 | *pDst++ = (*pSrc++) + 100.0f;
|
---|
2587 | // z
|
---|
2588 | *pDst++ = *pSrc++;
|
---|
2589 | }
|
---|
2590 |
|
---|
2591 | origbuf->unlock();
|
---|
2592 | newbuf->unlock();
|
---|
2593 |
|
---|
2594 | // create a morph animation
|
---|
2595 | Animation* anim = mesh->createAnimation("testAnim", 10.0f);
|
---|
2596 | VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_MORPH);
|
---|
2597 | // re-use start positions for frame 0
|
---|
2598 | VertexMorphKeyFrame* kf = vt->createVertexMorphKeyFrame(0);
|
---|
2599 | kf->setVertexBuffer(origbuf);
|
---|
2600 |
|
---|
2601 | // Use translated buffer for mid frame
|
---|
2602 | kf = vt->createVertexMorphKeyFrame(5.0f);
|
---|
2603 | kf->setVertexBuffer(newbuf);
|
---|
2604 |
|
---|
2605 | // re-use start positions for final frame
|
---|
2606 | kf = vt->createVertexMorphKeyFrame(10.0f);
|
---|
2607 | kf->setVertexBuffer(origbuf);
|
---|
2608 |
|
---|
2609 | // write
|
---|
2610 | MeshSerializer ser;
|
---|
2611 | ser.exportMesh(mesh.get(), "../../../Media/testmorph.mesh");
|
---|
2612 |
|
---|
2613 |
|
---|
2614 | Entity* e = mSceneMgr->createEntity("test", "testmorph.mesh");
|
---|
2615 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
|
---|
2616 | AnimationState* animState = e->getAnimationState("testAnim");
|
---|
2617 | animState->setEnabled(true);
|
---|
2618 | animState->setWeight(1.0f);
|
---|
2619 | mAnimStateList.push_back(animState);
|
---|
2620 |
|
---|
2621 | e = mSceneMgr->createEntity("test2", "testmorph.mesh");
|
---|
2622 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0))->attachObject(e);
|
---|
2623 | // test hardware morph
|
---|
2624 | e->setMaterialName("Examples/HardwareMorphAnimation");
|
---|
2625 | animState = e->getAnimationState("testAnim");
|
---|
2626 | animState->setEnabled(true);
|
---|
2627 | animState->setWeight(1.0f);
|
---|
2628 | mAnimStateList.push_back(animState);
|
---|
2629 |
|
---|
2630 | mCamera->setNearClipDistance(0.5);
|
---|
2631 | //mSceneMgr->setShowDebugShadows(true);
|
---|
2632 |
|
---|
2633 | Plane plane;
|
---|
2634 | plane.normal = Vector3::UNIT_Y;
|
---|
2635 | plane.d = 200;
|
---|
2636 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2637 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2638 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2639 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2640 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2641 | pPlaneEnt->setCastShadows(false);
|
---|
2642 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2643 |
|
---|
2644 |
|
---|
2645 |
|
---|
2646 | }
|
---|
2647 |
|
---|
2648 |
|
---|
2649 | void testPoseAnimation()
|
---|
2650 | {
|
---|
2651 | bool testStencil = false;
|
---|
2652 |
|
---|
2653 | if (testStencil)
|
---|
2654 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
|
---|
2655 |
|
---|
2656 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2657 | Vector3 dir(-1, -1, 0.5);
|
---|
2658 | dir.normalise();
|
---|
2659 | Light* l = mSceneMgr->createLight("light1");
|
---|
2660 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2661 | l->setDirection(dir);
|
---|
2662 |
|
---|
2663 | MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh",
|
---|
2664 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2665 |
|
---|
2666 | SubMesh* sm = mesh->getSubMesh(0);
|
---|
2667 | // Re-organise geometry since this mesh has no animation and all
|
---|
2668 | // vertex elements are packed into one buffer
|
---|
2669 | VertexDeclaration* newDecl =
|
---|
2670 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true);
|
---|
2671 | sm->vertexData->reorganiseBuffers(newDecl);
|
---|
2672 | if (testStencil)
|
---|
2673 | sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised
|
---|
2674 | // get the position buffer (which should now be separate);
|
---|
2675 | const VertexElement* posElem =
|
---|
2676 | sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
|
---|
2677 | HardwareVertexBufferSharedPtr origbuf =
|
---|
2678 | sm->vertexData->vertexBufferBinding->getBuffer(
|
---|
2679 | posElem->getSource());
|
---|
2680 |
|
---|
2681 |
|
---|
2682 | // create 2 poses
|
---|
2683 | Pose* pose = mesh->createPose(1, "pose1");
|
---|
2684 | // Pose1 moves vertices 0, 1, 2 and 3 upward
|
---|
2685 | Vector3 offset1(0, 50, 0);
|
---|
2686 | pose->addVertex(0, offset1);
|
---|
2687 | pose->addVertex(1, offset1);
|
---|
2688 | pose->addVertex(2, offset1);
|
---|
2689 | pose->addVertex(3, offset1);
|
---|
2690 |
|
---|
2691 | pose = mesh->createPose(1, "pose2");
|
---|
2692 | // Pose2 moves vertices 3, 4, and 5 to the right
|
---|
2693 | // Note 3 gets affected by both
|
---|
2694 | Vector3 offset2(100, 0, 0);
|
---|
2695 | pose->addVertex(3, offset2);
|
---|
2696 | pose->addVertex(4, offset2);
|
---|
2697 | pose->addVertex(5, offset2);
|
---|
2698 |
|
---|
2699 |
|
---|
2700 | Animation* anim = mesh->createAnimation("poseanim", 20.0f);
|
---|
2701 | VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE);
|
---|
2702 |
|
---|
2703 | // Frame 0 - no effect
|
---|
2704 | VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(0);
|
---|
2705 |
|
---|
2706 | // Frame 1 - bring in pose 1 (index 0)
|
---|
2707 | kf = vt->createVertexPoseKeyFrame(3);
|
---|
2708 | kf->addPoseReference(0, 1.0f);
|
---|
2709 |
|
---|
2710 | // Frame 2 - remove all
|
---|
2711 | kf = vt->createVertexPoseKeyFrame(6);
|
---|
2712 |
|
---|
2713 | // Frame 3 - bring in pose 2 (index 1)
|
---|
2714 | kf = vt->createVertexPoseKeyFrame(9);
|
---|
2715 | kf->addPoseReference(1, 1.0f);
|
---|
2716 |
|
---|
2717 | // Frame 4 - remove all
|
---|
2718 | kf = vt->createVertexPoseKeyFrame(12);
|
---|
2719 |
|
---|
2720 |
|
---|
2721 | // Frame 5 - bring in pose 1 at 50%, pose 2 at 100%
|
---|
2722 | kf = vt->createVertexPoseKeyFrame(15);
|
---|
2723 | kf->addPoseReference(0, 0.5f);
|
---|
2724 | kf->addPoseReference(1, 1.0f);
|
---|
2725 |
|
---|
2726 | // Frame 6 - bring in pose 1 at 100%, pose 2 at 50%
|
---|
2727 | kf = vt->createVertexPoseKeyFrame(18);
|
---|
2728 | kf->addPoseReference(0, 1.0f);
|
---|
2729 | kf->addPoseReference(1, 0.5f);
|
---|
2730 |
|
---|
2731 | // Frame 7 - reset
|
---|
2732 | kf = vt->createVertexPoseKeyFrame(20);
|
---|
2733 |
|
---|
2734 | // write
|
---|
2735 | MeshSerializer ser;
|
---|
2736 | ser.exportMesh(mesh.get(), "../../../Media/testpose.mesh");
|
---|
2737 |
|
---|
2738 |
|
---|
2739 |
|
---|
2740 | // software pose
|
---|
2741 | Entity* e = mSceneMgr->createEntity("test2", "testpose.mesh");
|
---|
2742 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
|
---|
2743 | AnimationState* animState = e->getAnimationState("poseanim");
|
---|
2744 | animState->setEnabled(true);
|
---|
2745 | animState->setWeight(1.0f);
|
---|
2746 | mAnimStateList.push_back(animState);
|
---|
2747 |
|
---|
2748 |
|
---|
2749 | // test hardware pose
|
---|
2750 | e = mSceneMgr->createEntity("test", "testpose.mesh");
|
---|
2751 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
|
---|
2752 | e->setMaterialName("Examples/HardwarePoseAnimation");
|
---|
2753 | animState = e->getAnimationState("poseanim");
|
---|
2754 | animState->setEnabled(true);
|
---|
2755 | animState->setWeight(1.0f);
|
---|
2756 | mAnimStateList.push_back(animState);
|
---|
2757 |
|
---|
2758 |
|
---|
2759 | mCamera->setNearClipDistance(0.5);
|
---|
2760 | mSceneMgr->setShowDebugShadows(true);
|
---|
2761 |
|
---|
2762 | Plane plane;
|
---|
2763 | plane.normal = Vector3::UNIT_Y;
|
---|
2764 | plane.d = 200;
|
---|
2765 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2766 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2767 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2768 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2769 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2770 | pPlaneEnt->setCastShadows(false);
|
---|
2771 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2772 |
|
---|
2773 | mCamera->setPosition(0,0,-300);
|
---|
2774 | mCamera->lookAt(0,0,0);
|
---|
2775 |
|
---|
2776 |
|
---|
2777 |
|
---|
2778 | }
|
---|
2779 |
|
---|
2780 | void testPoseAnimation2()
|
---|
2781 | {
|
---|
2782 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2783 | Vector3 dir(-1, -1, -0.5);
|
---|
2784 | dir.normalise();
|
---|
2785 | Light* l = mSceneMgr->createLight("light1");
|
---|
2786 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2787 | l->setDirection(dir);
|
---|
2788 |
|
---|
2789 | /*
|
---|
2790 | MeshPtr mesh = MeshManager::getSingleton().load("facial.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2791 | Animation* anim = mesh->createAnimation("pose", 20);
|
---|
2792 | VertexAnimationTrack* track = anim->createVertexTrack(4, VAT_POSE);
|
---|
2793 | // Frame 0 - no effect
|
---|
2794 | VertexPoseKeyFrame* kf = track->createVertexPoseKeyFrame(0);
|
---|
2795 |
|
---|
2796 | // bring in pose 4 (happy)
|
---|
2797 | kf = track->createVertexPoseKeyFrame(5);
|
---|
2798 | kf->addPoseReference(4, 1.0f);
|
---|
2799 |
|
---|
2800 | // bring in pose 5 (sad)
|
---|
2801 | kf = track->createVertexPoseKeyFrame(10);
|
---|
2802 | kf->addPoseReference(5, 1.0f);
|
---|
2803 |
|
---|
2804 | // bring in pose 6 (mad)
|
---|
2805 | kf = track->createVertexPoseKeyFrame(15);
|
---|
2806 | kf->addPoseReference(6, 1.0f);
|
---|
2807 |
|
---|
2808 | kf = track->createVertexPoseKeyFrame(20);
|
---|
2809 | */
|
---|
2810 |
|
---|
2811 | // software pose
|
---|
2812 | Entity* e = mSceneMgr->createEntity("test2", "facial.mesh");
|
---|
2813 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
|
---|
2814 | AnimationState* animState = e->getAnimationState("Speak");
|
---|
2815 | animState->setEnabled(true);
|
---|
2816 | animState->setWeight(1.0f);
|
---|
2817 | mAnimStateList.push_back(animState);
|
---|
2818 |
|
---|
2819 |
|
---|
2820 | /*
|
---|
2821 | // test hardware pose
|
---|
2822 | e = mSceneMgr->createEntity("test", "testpose.mesh");
|
---|
2823 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
|
---|
2824 | e->setMaterialName("Examples/HardwarePoseAnimation");
|
---|
2825 | animState = e->getAnimationState("poseanim");
|
---|
2826 | animState->setEnabled(true);
|
---|
2827 | animState->setWeight(1.0f);
|
---|
2828 | mAnimStateList.push_back(animState);
|
---|
2829 | */
|
---|
2830 |
|
---|
2831 |
|
---|
2832 | mCamera->setNearClipDistance(0.5);
|
---|
2833 | mSceneMgr->setShowDebugShadows(true);
|
---|
2834 |
|
---|
2835 | Plane plane;
|
---|
2836 | plane.normal = Vector3::UNIT_Y;
|
---|
2837 | plane.d = 200;
|
---|
2838 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2839 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2840 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2841 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2842 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2843 | pPlaneEnt->setCastShadows(false);
|
---|
2844 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2845 |
|
---|
2846 | }
|
---|
2847 |
|
---|
2848 |
|
---|
2849 | void testReflectedBillboards()
|
---|
2850 | {
|
---|
2851 | // Set ambient light
|
---|
2852 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
2853 |
|
---|
2854 | // Create a light
|
---|
2855 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
2856 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2857 | Vector3 dir(0.5, -1, 0);
|
---|
2858 | dir.normalise();
|
---|
2859 | l->setDirection(dir);
|
---|
2860 | l->setDiffuseColour(1.0f, 1.0f, 0.8f);
|
---|
2861 | l->setSpecularColour(1.0f, 1.0f, 1.0f);
|
---|
2862 |
|
---|
2863 |
|
---|
2864 | // Create a prefab plane
|
---|
2865 | Plane plane;
|
---|
2866 | plane.d = 0;
|
---|
2867 | plane.normal = Vector3::UNIT_Y;
|
---|
2868 | MeshManager::getSingleton().createPlane("ReflectionPlane",
|
---|
2869 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
2870 | plane, 2000, 2000,
|
---|
2871 | 1, 1, true, 1, 1, 1, Vector3::UNIT_Z);
|
---|
2872 | Entity* planeEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" );
|
---|
2873 |
|
---|
2874 | // Attach the rtt entity to the root of the scene
|
---|
2875 | SceneNode* rootNode = mSceneMgr->getRootSceneNode();
|
---|
2876 | SceneNode* planeNode = rootNode->createChildSceneNode();
|
---|
2877 |
|
---|
2878 | // Attach both the plane entity, and the plane definition
|
---|
2879 | planeNode->attachObject(planeEnt);
|
---|
2880 |
|
---|
2881 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "RttTex", 512, 512, TEX_TYPE_2D, PF_R8G8B8 );
|
---|
2882 | {
|
---|
2883 | reflectCam = mSceneMgr->createCamera("ReflectCam");
|
---|
2884 | reflectCam->setNearClipDistance(mCamera->getNearClipDistance());
|
---|
2885 | reflectCam->setFarClipDistance(mCamera->getFarClipDistance());
|
---|
2886 | reflectCam->setAspectRatio(
|
---|
2887 | (Real)mWindow->getViewport(0)->getActualWidth() /
|
---|
2888 | (Real)mWindow->getViewport(0)->getActualHeight());
|
---|
2889 |
|
---|
2890 | Viewport *v = rttTex->addViewport( reflectCam );
|
---|
2891 | v->setClearEveryFrame( true );
|
---|
2892 | v->setBackgroundColour( ColourValue::Black );
|
---|
2893 |
|
---|
2894 | MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",
|
---|
2895 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
2896 | TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg");
|
---|
2897 | t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
|
---|
2898 | // Blend with base texture
|
---|
2899 | t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White,
|
---|
2900 | ColourValue::White, 0.25);
|
---|
2901 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
|
---|
2902 | t->setProjectiveTexturing(true, reflectCam);
|
---|
2903 |
|
---|
2904 | // set up linked reflection
|
---|
2905 | reflectCam->enableReflection(plane);
|
---|
2906 | // Also clip
|
---|
2907 | reflectCam->enableCustomNearClipPlane(plane);
|
---|
2908 | }
|
---|
2909 |
|
---|
2910 | // Give the plane a texture
|
---|
2911 | planeEnt->setMaterialName("RttMat");
|
---|
2912 |
|
---|
2913 |
|
---|
2914 | // point billboards
|
---|
2915 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("fountain1",
|
---|
2916 | "Examples/Smoke");
|
---|
2917 | // Point the fountain at an angle
|
---|
2918 | SceneNode* fNode = static_cast<SceneNode*>(rootNode->createChild());
|
---|
2919 | fNode->attachObject(pSys2);
|
---|
2920 |
|
---|
2921 | // oriented_self billboards
|
---|
2922 | ParticleSystem* pSys3 = mSceneMgr->createParticleSystem("fountain2",
|
---|
2923 | "Examples/PurpleFountain");
|
---|
2924 | // Point the fountain at an angle
|
---|
2925 | fNode = rootNode->createChildSceneNode();
|
---|
2926 | fNode->translate(-200,-100,0);
|
---|
2927 | fNode->rotate(Vector3::UNIT_Z, Degree(-20));
|
---|
2928 | fNode->attachObject(pSys3);
|
---|
2929 |
|
---|
2930 |
|
---|
2931 |
|
---|
2932 | // oriented_common billboards
|
---|
2933 | ParticleSystem* pSys4 = mSceneMgr->createParticleSystem("rain",
|
---|
2934 | "Examples/Rain");
|
---|
2935 | SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
2936 | rNode->translate(0,1000,0);
|
---|
2937 | rNode->attachObject(pSys4);
|
---|
2938 | // Fast-forward the rain so it looks more natural
|
---|
2939 | pSys4->fastForward(5);
|
---|
2940 |
|
---|
2941 |
|
---|
2942 | mCamera->setPosition(-50, 100, 500);
|
---|
2943 | mCamera->lookAt(0,0,0);
|
---|
2944 | }
|
---|
2945 |
|
---|
2946 | void testManualObjectNonIndexed()
|
---|
2947 | {
|
---|
2948 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
2949 | Vector3 dir(-1, -1, 0.5);
|
---|
2950 | dir.normalise();
|
---|
2951 | Light* l = mSceneMgr->createLight("light1");
|
---|
2952 | l->setType(Light::LT_DIRECTIONAL);
|
---|
2953 | l->setDirection(dir);
|
---|
2954 |
|
---|
2955 | Plane plane;
|
---|
2956 | plane.normal = Vector3::UNIT_Y;
|
---|
2957 | plane.d = 100;
|
---|
2958 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
2959 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
2960 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
2961 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
2962 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
2963 | pPlaneEnt->setCastShadows(false);
|
---|
2964 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
2965 |
|
---|
2966 | ManualObject* man = static_cast<ManualObject*>(
|
---|
2967 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
|
---|
2968 |
|
---|
2969 | man->begin("Examples/OgreLogo");
|
---|
2970 | // Define a 40x40 plane, non-indexed
|
---|
2971 | man->position(-20, 20, 20);
|
---|
2972 | man->normal(0, 0, 1);
|
---|
2973 | man->textureCoord(0, 0);
|
---|
2974 |
|
---|
2975 | man->position(-20, -20, 20);
|
---|
2976 | man->normal(0, 0, 1);
|
---|
2977 | man->textureCoord(0, 1);
|
---|
2978 |
|
---|
2979 | man->position(20, 20, 20);
|
---|
2980 | man->normal(0, 0, 1);
|
---|
2981 | man->textureCoord(1, 0);
|
---|
2982 |
|
---|
2983 | man->position(-20, -20, 20);
|
---|
2984 | man->normal(0, 0, 1);
|
---|
2985 | man->textureCoord(0, 1);
|
---|
2986 |
|
---|
2987 | man->position(20, -20, 20);
|
---|
2988 | man->normal(0, 0, 1);
|
---|
2989 | man->textureCoord(1, 1);
|
---|
2990 |
|
---|
2991 | man->position(20, 20, 20);
|
---|
2992 | man->normal(0, 0, 1);
|
---|
2993 | man->textureCoord(1, 0);
|
---|
2994 |
|
---|
2995 | man->end();
|
---|
2996 |
|
---|
2997 | man->begin("Examples/BumpyMetal");
|
---|
2998 |
|
---|
2999 | // Define a 40x40 plane, non-indexed
|
---|
3000 | man->position(-20, 20, 20);
|
---|
3001 | man->normal(0, 1, 0);
|
---|
3002 | man->textureCoord(0, 0);
|
---|
3003 |
|
---|
3004 | man->position(20, 20, 20);
|
---|
3005 | man->normal(0, 1, 0);
|
---|
3006 | man->textureCoord(0, 1);
|
---|
3007 |
|
---|
3008 | man->position(20, 20, -20);
|
---|
3009 | man->normal(0, 1, 0);
|
---|
3010 | man->textureCoord(1, 1);
|
---|
3011 |
|
---|
3012 | man->position(20, 20, -20);
|
---|
3013 | man->normal(0, 1, 0);
|
---|
3014 | man->textureCoord(1, 1);
|
---|
3015 |
|
---|
3016 | man->position(-20, 20, -20);
|
---|
3017 | man->normal(0, 1, 0);
|
---|
3018 | man->textureCoord(1, 0);
|
---|
3019 |
|
---|
3020 | man->position(-20, 20, 20);
|
---|
3021 | man->normal(0, 1, 0);
|
---|
3022 | man->textureCoord(0, 0);
|
---|
3023 |
|
---|
3024 | man->end();
|
---|
3025 |
|
---|
3026 |
|
---|
3027 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
|
---|
3028 |
|
---|
3029 | }
|
---|
3030 |
|
---|
3031 | void testManualObjectIndexed()
|
---|
3032 | {
|
---|
3033 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
3034 | Vector3 dir(-1, -1, 0.5);
|
---|
3035 | dir.normalise();
|
---|
3036 | Light* l = mSceneMgr->createLight("light1");
|
---|
3037 | l->setType(Light::LT_DIRECTIONAL);
|
---|
3038 | l->setDirection(dir);
|
---|
3039 |
|
---|
3040 | Plane plane;
|
---|
3041 | plane.normal = Vector3::UNIT_Y;
|
---|
3042 | plane.d = 100;
|
---|
3043 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
3044 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3045 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
3046 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
3047 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
3048 | pPlaneEnt->setCastShadows(false);
|
---|
3049 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
3050 |
|
---|
3051 | ManualObject* man = static_cast<ManualObject*>(
|
---|
3052 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
|
---|
3053 |
|
---|
3054 | man->begin("Examples/OgreLogo");
|
---|
3055 | // Define a 40x40 plane, indexed
|
---|
3056 | man->position(-20, 20, 20);
|
---|
3057 | man->normal(0, 0, 1);
|
---|
3058 | man->textureCoord(0, 0);
|
---|
3059 |
|
---|
3060 | man->position(-20, -20, 20);
|
---|
3061 | man->normal(0, 0, 1);
|
---|
3062 | man->textureCoord(0, 1);
|
---|
3063 |
|
---|
3064 | man->position(20, -20, 20);
|
---|
3065 | man->normal(0, 0, 1);
|
---|
3066 | man->textureCoord(1, 1);
|
---|
3067 |
|
---|
3068 | man->position(20, 20, 20);
|
---|
3069 | man->normal(0, 0, 1);
|
---|
3070 | man->textureCoord(1, 0);
|
---|
3071 |
|
---|
3072 | man->quad(0, 1, 2, 3);
|
---|
3073 |
|
---|
3074 | man->end();
|
---|
3075 |
|
---|
3076 | man->begin("Examples/BumpyMetal");
|
---|
3077 |
|
---|
3078 | // Define a 40x40 plane, indexed
|
---|
3079 | man->position(-20, 20, 20);
|
---|
3080 | man->normal(0, 1, 0);
|
---|
3081 | man->textureCoord(0, 0);
|
---|
3082 |
|
---|
3083 | man->position(20, 20, 20);
|
---|
3084 | man->normal(0, 1, 0);
|
---|
3085 | man->textureCoord(0, 1);
|
---|
3086 |
|
---|
3087 | man->position(20, 20, -20);
|
---|
3088 | man->normal(0, 1, 0);
|
---|
3089 | man->textureCoord(1, 1);
|
---|
3090 |
|
---|
3091 | man->position(-20, 20, -20);
|
---|
3092 | man->normal(0, 1, 0);
|
---|
3093 | man->textureCoord(1, 0);
|
---|
3094 |
|
---|
3095 | man->quad(0, 1, 2, 3);
|
---|
3096 |
|
---|
3097 | man->end();
|
---|
3098 |
|
---|
3099 |
|
---|
3100 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
|
---|
3101 |
|
---|
3102 | }
|
---|
3103 |
|
---|
3104 | void testBillboardChain()
|
---|
3105 | {
|
---|
3106 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
3107 | Vector3 dir(-1, -1, 0.5);
|
---|
3108 | dir.normalise();
|
---|
3109 | Light* l = mSceneMgr->createLight("light1");
|
---|
3110 | l->setType(Light::LT_DIRECTIONAL);
|
---|
3111 | l->setDirection(dir);
|
---|
3112 |
|
---|
3113 | Plane plane;
|
---|
3114 | plane.normal = Vector3::UNIT_Y;
|
---|
3115 | plane.d = 100;
|
---|
3116 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
3117 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3118 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
3119 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
3120 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
3121 | pPlaneEnt->setCastShadows(false);
|
---|
3122 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
3123 |
|
---|
3124 | BillboardChain* chain = static_cast<BillboardChain*>(
|
---|
3125 | mSceneMgr->createMovableObject("1", "BillboardChain"));
|
---|
3126 | chain->setUseTextureCoords(true);
|
---|
3127 | chain->setUseVertexColours(false);
|
---|
3128 | /*
|
---|
3129 | BillboardChain::Element elem;
|
---|
3130 | elem.width = 10;
|
---|
3131 | elem.texCoord = 0;
|
---|
3132 | elem.position = Vector3(0,20,0);
|
---|
3133 | chain->addChainElement(0, elem);
|
---|
3134 | elem.position = Vector3(20,0,0);
|
---|
3135 | elem.texCoord = 1.0;
|
---|
3136 | chain->addChainElement(0, elem);
|
---|
3137 | elem.position = Vector3(40,10,0);
|
---|
3138 | elem.texCoord = 2.0;
|
---|
3139 | chain->addChainElement(0, elem);
|
---|
3140 | elem.position = Vector3(60,20,0);
|
---|
3141 | elem.texCoord = 3.0;
|
---|
3142 | chain->addChainElement(0, elem);
|
---|
3143 | elem.position = Vector3(80,40,0);
|
---|
3144 | elem.texCoord = 4.0;
|
---|
3145 | chain->addChainElement(0, elem);
|
---|
3146 | elem.position = Vector3(100,70,0);
|
---|
3147 | elem.texCoord = 5.0;
|
---|
3148 | chain->addChainElement(0, elem);
|
---|
3149 | */
|
---|
3150 | chain->setMaterialName("Examples/RustySteel");
|
---|
3151 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(chain);
|
---|
3152 |
|
---|
3153 | mSceneMgr->showBoundingBoxes(true);
|
---|
3154 | }
|
---|
3155 |
|
---|
3156 | void testRibbonTrail()
|
---|
3157 | {
|
---|
3158 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
3159 | Vector3 dir(-1, -1, 0.5);
|
---|
3160 | dir.normalise();
|
---|
3161 | Light* l = mSceneMgr->createLight("light1");
|
---|
3162 | l->setType(Light::LT_DIRECTIONAL);
|
---|
3163 | l->setDirection(dir);
|
---|
3164 |
|
---|
3165 | NameValuePairList pairList;
|
---|
3166 | pairList["numberOfChains"] = "2";
|
---|
3167 | pairList["maxElements"] = "80";
|
---|
3168 | RibbonTrail* trail = static_cast<RibbonTrail*>(
|
---|
3169 | mSceneMgr->createMovableObject("1", "RibbonTrail", &pairList));
|
---|
3170 | trail->setMaterialName("Examples/LightRibbonTrail");
|
---|
3171 | trail->setTrailLength(400);
|
---|
3172 |
|
---|
3173 |
|
---|
3174 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(trail);
|
---|
3175 |
|
---|
3176 | // Create 3 nodes for trail to follow
|
---|
3177 | SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
3178 | animNode->setPosition(0,20,0);
|
---|
3179 | Animation* anim = mSceneMgr->createAnimation("an1", 10);
|
---|
3180 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
3181 | NodeAnimationTrack* track = anim->createNodeTrack(1, animNode);
|
---|
3182 | TransformKeyFrame* kf = track->createNodeKeyFrame(0);
|
---|
3183 | kf->setTranslate(Vector3::ZERO);
|
---|
3184 | kf = track->createNodeKeyFrame(2);
|
---|
3185 | kf->setTranslate(Vector3(100, 0, 0));
|
---|
3186 | kf = track->createNodeKeyFrame(4);
|
---|
3187 | kf->setTranslate(Vector3(200, 0, 300));
|
---|
3188 | kf = track->createNodeKeyFrame(6);
|
---|
3189 | kf->setTranslate(Vector3(0, 20, 500));
|
---|
3190 | kf = track->createNodeKeyFrame(8);
|
---|
3191 | kf->setTranslate(Vector3(-100, 10, 100));
|
---|
3192 | kf = track->createNodeKeyFrame(10);
|
---|
3193 | kf->setTranslate(Vector3::ZERO);
|
---|
3194 |
|
---|
3195 | AnimationState* animState = mSceneMgr->createAnimationState("an1");
|
---|
3196 | animState->setEnabled(true);
|
---|
3197 | mAnimStateList.push_back(animState);
|
---|
3198 |
|
---|
3199 | trail->addNode(animNode);
|
---|
3200 | trail->setInitialColour(0, 1.0, 0.8, 0);
|
---|
3201 | trail->setColourChange(0, 0.5, 0.5, 0.5, 0.5);
|
---|
3202 | trail->setInitialWidth(0, 5);
|
---|
3203 |
|
---|
3204 | // Add light
|
---|
3205 | Light* l2 = mSceneMgr->createLight("l2");
|
---|
3206 | l2->setDiffuseColour(trail->getInitialColour(0));
|
---|
3207 | animNode->attachObject(l2);
|
---|
3208 |
|
---|
3209 | // Add billboard
|
---|
3210 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1);
|
---|
3211 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0));
|
---|
3212 | bbs->setMaterialName("Examples/Flare");
|
---|
3213 | animNode->attachObject(bbs);
|
---|
3214 |
|
---|
3215 | animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
3216 | animNode->setPosition(-50,10,0);
|
---|
3217 | anim = mSceneMgr->createAnimation("an2", 10);
|
---|
3218 | anim->setInterpolationMode(Animation::IM_SPLINE);
|
---|
3219 | track = anim->createNodeTrack(1, animNode);
|
---|
3220 | kf = track->createNodeKeyFrame(0);
|
---|
3221 | kf->setTranslate(Vector3::ZERO);
|
---|
3222 | kf = track->createNodeKeyFrame(2);
|
---|
3223 | kf->setTranslate(Vector3(-100, 150, -30));
|
---|
3224 | kf = track->createNodeKeyFrame(4);
|
---|
3225 | kf->setTranslate(Vector3(-200, 0, 40));
|
---|
3226 | kf = track->createNodeKeyFrame(6);
|
---|
3227 | kf->setTranslate(Vector3(0, -150, 70));
|
---|
3228 | kf = track->createNodeKeyFrame(8);
|
---|
3229 | kf->setTranslate(Vector3(50, 0, 30));
|
---|
3230 | kf = track->createNodeKeyFrame(10);
|
---|
3231 | kf->setTranslate(Vector3::ZERO);
|
---|
3232 |
|
---|
3233 | animState = mSceneMgr->createAnimationState("an2");
|
---|
3234 | animState->setEnabled(true);
|
---|
3235 | mAnimStateList.push_back(animState);
|
---|
3236 |
|
---|
3237 | trail->addNode(animNode);
|
---|
3238 | trail->setInitialColour(1, 0.0, 1.0, 0.4);
|
---|
3239 | trail->setColourChange(1, 0.5, 0.5, 0.5, 0.5);
|
---|
3240 | trail->setInitialWidth(1, 5);
|
---|
3241 |
|
---|
3242 |
|
---|
3243 | // Add light
|
---|
3244 | l2 = mSceneMgr->createLight("l3");
|
---|
3245 | l2->setDiffuseColour(trail->getInitialColour(1));
|
---|
3246 | animNode->attachObject(l2);
|
---|
3247 |
|
---|
3248 | // Add billboard
|
---|
3249 | bbs = mSceneMgr->createBillboardSet("bb2", 1);
|
---|
3250 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1));
|
---|
3251 | bbs->setMaterialName("Examples/Flare");
|
---|
3252 | animNode->attachObject(bbs);
|
---|
3253 |
|
---|
3254 |
|
---|
3255 |
|
---|
3256 | //mSceneMgr->showBoundingBoxes(true);
|
---|
3257 |
|
---|
3258 | }
|
---|
3259 |
|
---|
3260 | void testBlendDiffuseColour()
|
---|
3261 | {
|
---|
3262 | MaterialPtr mat = MaterialManager::getSingleton().create(
|
---|
3263 | "testBlendDiffuseColour", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3264 | Pass* pass = mat->getTechnique(0)->getPass(0);
|
---|
3265 | // no lighting, it will mess up vertex colours
|
---|
3266 | pass->setLightingEnabled(false);
|
---|
3267 | // Make sure we pull in vertex colour as diffuse
|
---|
3268 | pass->setVertexColourTracking(TVC_DIFFUSE);
|
---|
3269 | // Base layer
|
---|
3270 | TextureUnitState* t = pass->createTextureUnitState("BeachStones.jpg");
|
---|
3271 | // don't want to bring in vertex diffuse on base layer
|
---|
3272 | t->setColourOperation(LBO_REPLACE);
|
---|
3273 | // Second layer (lerp based on colour)
|
---|
3274 | t = pass->createTextureUnitState("terr_dirt-grass.jpg");
|
---|
3275 | t->setColourOperationEx(LBX_BLEND_DIFFUSE_COLOUR);
|
---|
3276 | // third layer (lerp based on alpha)
|
---|
3277 | ManualObject* man = mSceneMgr->createManualObject("quad");
|
---|
3278 | man->begin("testBlendDiffuseColour");
|
---|
3279 | man->position(-100, 100, 0);
|
---|
3280 | man->textureCoord(0,0);
|
---|
3281 | man->colour(0, 0, 0);
|
---|
3282 | man->position(-100, -100, 0);
|
---|
3283 | man->textureCoord(0,1);
|
---|
3284 | man->colour(0.5, 0.5, 0.5);
|
---|
3285 | man->position(100, -100, 0);
|
---|
3286 | man->textureCoord(1,1);
|
---|
3287 | man->colour(1, 1, 1);
|
---|
3288 | man->position(100, 100, 0);
|
---|
3289 | man->textureCoord(1,0);
|
---|
3290 | man->colour(0.5, 0.5, 0.5);
|
---|
3291 | man->quad(0, 1, 2, 3);
|
---|
3292 | man->end();
|
---|
3293 |
|
---|
3294 | mSceneMgr->getRootSceneNode()->attachObject(man);
|
---|
3295 |
|
---|
3296 | }
|
---|
3297 |
|
---|
3298 | void testSplitPassesTooManyTexUnits()
|
---|
3299 | {
|
---|
3300 | MaterialPtr mat = MaterialManager::getSingleton().create(
|
---|
3301 | "Test", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3302 |
|
---|
3303 | Pass* p = mat->getTechnique(0)->getPass(0);
|
---|
3304 | p->createTextureUnitState("gras_02.png");
|
---|
3305 | p->createTextureUnitState("gras_02.png");
|
---|
3306 | p->createTextureUnitState("gras_02.png");
|
---|
3307 | p->createTextureUnitState("gras_02.png");
|
---|
3308 | p->createTextureUnitState("gras_02.png");
|
---|
3309 | p->createTextureUnitState("gras_02.png");
|
---|
3310 | p->createTextureUnitState("gras_02.png");
|
---|
3311 | p->createTextureUnitState("gras_02.png");
|
---|
3312 | p->createTextureUnitState("gras_02.png");
|
---|
3313 |
|
---|
3314 | mat->compile();
|
---|
3315 |
|
---|
3316 | }
|
---|
3317 |
|
---|
3318 | void testCustomProjectionMatrix()
|
---|
3319 | {
|
---|
3320 | testLotsAndLotsOfEntities();
|
---|
3321 | Matrix4 mat = mCamera->getProjectionMatrix();
|
---|
3322 | mCamera->setCustomProjectionMatrix(true, mat);
|
---|
3323 | mat = mCamera->getProjectionMatrix();
|
---|
3324 |
|
---|
3325 | }
|
---|
3326 |
|
---|
3327 | void testPointSprites()
|
---|
3328 | {
|
---|
3329 | MaterialPtr mat = MaterialManager::getSingleton().create("spriteTest1",
|
---|
3330 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3331 | Pass* p = mat->getTechnique(0)->getPass(0);
|
---|
3332 | p->setPointSpritesEnabled(true);
|
---|
3333 | p->createTextureUnitState("flare.png");
|
---|
3334 | p->setLightingEnabled(false);
|
---|
3335 | p->setDepthWriteEnabled(false);
|
---|
3336 | p->setSceneBlending(SBT_ADD);
|
---|
3337 | p->setPointAttenuation(true);
|
---|
3338 | p->setPointSize(1);
|
---|
3339 | srand((unsigned)time( NULL ) );
|
---|
3340 |
|
---|
3341 | ManualObject* man = mSceneMgr->createManualObject("man");
|
---|
3342 | man->begin("spriteTest1", RenderOperation::OT_POINT_LIST);
|
---|
3343 | /*
|
---|
3344 | for (size_t i = 0; i < 1000; ++i)
|
---|
3345 | {
|
---|
3346 | man->position(Math::SymmetricRandom() * 500,
|
---|
3347 | Math::SymmetricRandom() * 500,
|
---|
3348 | Math::SymmetricRandom() * 500);
|
---|
3349 | man->colour(Math::RangeRandom(0.5f, 1.0f),
|
---|
3350 | Math::RangeRandom(0.5f, 1.0f), Math::RangeRandom(0.5f, 1.0f));
|
---|
3351 | }
|
---|
3352 | */
|
---|
3353 | for (size_t i = 0; i < 20; ++i)
|
---|
3354 | {
|
---|
3355 | for (size_t j = 0; j < 20; ++j)
|
---|
3356 | {
|
---|
3357 | for (size_t k = 0; k < 20; ++k)
|
---|
3358 | {
|
---|
3359 | man->position(i * 30, j * 30, k * 30);
|
---|
3360 | }
|
---|
3361 | }
|
---|
3362 | }
|
---|
3363 |
|
---|
3364 | man->end();
|
---|
3365 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
|
---|
3366 |
|
---|
3367 | }
|
---|
3368 |
|
---|
3369 | void testSuppressedShadows(ShadowTechnique shadowTech)
|
---|
3370 | {
|
---|
3371 | mSceneMgr->setShadowTechnique(shadowTech);
|
---|
3372 |
|
---|
3373 | // Setup lighting
|
---|
3374 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
3375 | Light* light = mSceneMgr->createLight("MainLight");
|
---|
3376 | light->setType(Light::LT_DIRECTIONAL);
|
---|
3377 | Vector3 dir(-1, -1, 0.5);
|
---|
3378 | dir.normalise();
|
---|
3379 | light->setDirection(dir);
|
---|
3380 |
|
---|
3381 | // Create a skydome
|
---|
3382 | //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
3383 |
|
---|
3384 | // Create a floor plane mesh
|
---|
3385 | Plane plane(Vector3::UNIT_Y, 0.0);
|
---|
3386 | MeshManager::getSingleton().createPlane(
|
---|
3387 | "FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
3388 | plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z);
|
---|
3389 |
|
---|
3390 |
|
---|
3391 | // Add a floor to the scene
|
---|
3392 | Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
3393 | entity->setMaterialName("Examples/RustySteel");
|
---|
3394 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
|
---|
3395 | entity->setCastShadows(false);
|
---|
3396 |
|
---|
3397 | // Add the mandatory ogre head
|
---|
3398 | entity = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
3399 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity);
|
---|
3400 |
|
---|
3401 | // Position and orient the camera
|
---|
3402 | mCamera->setPosition(-100.0, 50.0, 90.0);
|
---|
3403 | mCamera->lookAt(0.0, 10.0, -35.0);
|
---|
3404 |
|
---|
3405 | // Add an additional viewport on top of the other one
|
---|
3406 | Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3);
|
---|
3407 |
|
---|
3408 | // Create a render queue invocation sequence for the pip viewport
|
---|
3409 | RenderQueueInvocationSequence* invocationSequence =
|
---|
3410 | mRoot->createRenderQueueInvocationSequence("pip");
|
---|
3411 |
|
---|
3412 | // Add an invocation to the sequence
|
---|
3413 | RenderQueueInvocation* invocation =
|
---|
3414 | invocationSequence->add(RENDER_QUEUE_MAIN, "main");
|
---|
3415 |
|
---|
3416 | // Disable render state changes and shadows for that invocation
|
---|
3417 | //invocation->setSuppressRenderStateChanges(true);
|
---|
3418 | invocation->setSuppressShadows(true);
|
---|
3419 |
|
---|
3420 | // Set the render queue invocation sequence for the pip viewport
|
---|
3421 | pip->setRenderQueueInvocationSequenceName("pip");
|
---|
3422 | }
|
---|
3423 |
|
---|
3424 | void testViewportNoShadows(ShadowTechnique shadowTech)
|
---|
3425 | {
|
---|
3426 | mSceneMgr->setShadowTechnique(shadowTech);
|
---|
3427 |
|
---|
3428 | // Setup lighting
|
---|
3429 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
3430 | Light* light = mSceneMgr->createLight("MainLight");
|
---|
3431 | light->setType(Light::LT_DIRECTIONAL);
|
---|
3432 | Vector3 dir(-1, -1, 0.5);
|
---|
3433 | dir.normalise();
|
---|
3434 | light->setDirection(dir);
|
---|
3435 |
|
---|
3436 | // Create a skydome
|
---|
3437 | //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
|
---|
3438 |
|
---|
3439 | // Create a floor plane mesh
|
---|
3440 | Plane plane(Vector3::UNIT_Y, 0.0);
|
---|
3441 | MeshManager::getSingleton().createPlane(
|
---|
3442 | "FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
3443 | plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z);
|
---|
3444 |
|
---|
3445 |
|
---|
3446 | // Add a floor to the scene
|
---|
3447 | Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane");
|
---|
3448 | entity->setMaterialName("Examples/RustySteel");
|
---|
3449 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
|
---|
3450 | entity->setCastShadows(false);
|
---|
3451 |
|
---|
3452 | // Add the mandatory ogre head
|
---|
3453 | entity = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
3454 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity);
|
---|
3455 |
|
---|
3456 | // Position and orient the camera
|
---|
3457 | mCamera->setPosition(-100.0, 50.0, 90.0);
|
---|
3458 | mCamera->lookAt(0.0, 10.0, -35.0);
|
---|
3459 |
|
---|
3460 | // Add an additional viewport on top of the other one
|
---|
3461 | Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3);
|
---|
3462 | pip->setShadowsEnabled(false);
|
---|
3463 |
|
---|
3464 | }
|
---|
3465 |
|
---|
3466 | void testSerialisedColour()
|
---|
3467 | {
|
---|
3468 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
3469 | Vector3 dir(-1, -1, 0.5);
|
---|
3470 | dir.normalise();
|
---|
3471 | Light* l = mSceneMgr->createLight("light1");
|
---|
3472 | l->setType(Light::LT_DIRECTIONAL);
|
---|
3473 | l->setDirection(dir);
|
---|
3474 |
|
---|
3475 | Plane plane;
|
---|
3476 | plane.normal = Vector3::UNIT_Y;
|
---|
3477 | plane.d = 100;
|
---|
3478 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
3479 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3480 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
3481 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
3482 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
3483 | pPlaneEnt->setCastShadows(false);
|
---|
3484 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
3485 |
|
---|
3486 | /*
|
---|
3487 | ManualObject* man = static_cast<ManualObject*>(
|
---|
3488 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME));
|
---|
3489 |
|
---|
3490 | man->begin("BaseWhiteNoLighting");
|
---|
3491 | // Define a 40x40 plane, non-indexed
|
---|
3492 | // Define a 40x40 plane, indexed
|
---|
3493 | man->position(-20, 20, 20);
|
---|
3494 | man->colour(1, 0, 0);
|
---|
3495 |
|
---|
3496 | man->position(-20, -20, 20);
|
---|
3497 | man->colour(1, 0, 0);
|
---|
3498 |
|
---|
3499 | man->position(20, -20, 20);
|
---|
3500 | man->colour(1, 0, 0);
|
---|
3501 |
|
---|
3502 | man->position(20, 20, 20);
|
---|
3503 | man->colour(1, 0, 0);
|
---|
3504 |
|
---|
3505 | man->quad(0, 1, 2, 3);
|
---|
3506 | man->end();
|
---|
3507 |
|
---|
3508 | MeshPtr mesh = man->convertToMesh("colourtest.mesh");
|
---|
3509 | MeshSerializer ms;
|
---|
3510 | ms.exportMesh(mesh.getPointer(), "colourtest.mesh");
|
---|
3511 |
|
---|
3512 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man);
|
---|
3513 | */
|
---|
3514 | Entity* c = mSceneMgr->createEntity("1", "colourtest.mesh");
|
---|
3515 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(c);
|
---|
3516 |
|
---|
3517 |
|
---|
3518 |
|
---|
3519 | }
|
---|
3520 |
|
---|
3521 | void testBillboardAccurateFacing()
|
---|
3522 | {
|
---|
3523 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
3524 | Vector3 dir(-1, -1, 0.5);
|
---|
3525 | dir.normalise();
|
---|
3526 | Light* l = mSceneMgr->createLight("light1");
|
---|
3527 | l->setType(Light::LT_DIRECTIONAL);
|
---|
3528 | l->setDirection(dir);
|
---|
3529 |
|
---|
3530 | Plane plane;
|
---|
3531 | plane.normal = Vector3::UNIT_Y;
|
---|
3532 | plane.d = 100;
|
---|
3533 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
3534 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3535 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
3536 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
3537 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
3538 | pPlaneEnt->setCastShadows(false);
|
---|
3539 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
3540 |
|
---|
3541 | BillboardSet* bbs = mSceneMgr->createBillboardSet("1");
|
---|
3542 | bbs->setDefaultDimensions(50,50);
|
---|
3543 | bbs->createBillboard(-150, 25, 0);
|
---|
3544 | bbs->setBillboardType(BBT_ORIENTED_COMMON);
|
---|
3545 | bbs->setCommonDirection(Vector3::UNIT_Y);
|
---|
3546 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
|
---|
3547 |
|
---|
3548 | bbs = mSceneMgr->createBillboardSet("2");
|
---|
3549 | bbs->setDefaultDimensions(50,50);
|
---|
3550 | bbs->createBillboard(150, 25, 0);
|
---|
3551 | bbs->setUseAccurateFacing(true);
|
---|
3552 | bbs->setBillboardType(BBT_ORIENTED_COMMON);
|
---|
3553 | bbs->setCommonDirection(Vector3::UNIT_Y);
|
---|
3554 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs);
|
---|
3555 | }
|
---|
3556 |
|
---|
3557 | void testMultiSceneManagersSimple()
|
---|
3558 | {
|
---|
3559 | // Create a secondary scene manager with it's own camera
|
---|
3560 | SceneManager* sm2 = Root::getSingleton().createSceneManager(ST_GENERIC);
|
---|
3561 | camera2 = sm2->createCamera("cam2");
|
---|
3562 | camera2->setPosition(0,0,-500);
|
---|
3563 | camera2->lookAt(Vector3::ZERO);
|
---|
3564 | Entity* ent = sm2->createEntity("knot2", "knot.mesh");
|
---|
3565 | sm2->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3566 | Light* l = sm2->createLight("l2");
|
---|
3567 | l->setPosition(100,50,-100);
|
---|
3568 | l->setDiffuseColour(ColourValue::Green);
|
---|
3569 | sm2->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
3570 |
|
---|
3571 | Viewport* vp = mWindow->addViewport(camera2, 1, 0.67, 0, 0.33, 0.25);
|
---|
3572 | vp->setOverlaysEnabled(false);
|
---|
3573 |
|
---|
3574 | // Use original SM for normal scene
|
---|
3575 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
3576 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3577 | l = mSceneMgr->createLight("l2"); // note same name, will work since different SM
|
---|
3578 | l->setPosition(100,50,-100);
|
---|
3579 | l->setDiffuseColour(ColourValue::Red);
|
---|
3580 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
|
---|
3581 |
|
---|
3582 |
|
---|
3583 | }
|
---|
3584 |
|
---|
3585 | void testMultiSceneManagersComplex()
|
---|
3586 | {
|
---|
3587 | // Create a secondary scene manager with it's own camera
|
---|
3588 | SceneManager* sm2 = Root::getSingleton().createSceneManager("TerrainSceneManager");
|
---|
3589 | camera2 = sm2->createCamera("cam2");
|
---|
3590 |
|
---|
3591 | Viewport* vp = mWindow->addViewport(camera2, 1, 0.5, 0, 0.5, 0.5);
|
---|
3592 | vp->setOverlaysEnabled(false);
|
---|
3593 | // Fog
|
---|
3594 | // NB it's VERY important to set this before calling setWorldGeometry
|
---|
3595 | // because the vertex program picked will be different
|
---|
3596 | ColourValue fadeColour(0.93, 0.86, 0.76);
|
---|
3597 | sm2->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
|
---|
3598 | vp->setBackgroundColour(fadeColour);
|
---|
3599 |
|
---|
3600 | sm2->setWorldGeometry("terrain.cfg");
|
---|
3601 | // Infinite far plane?
|
---|
3602 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
|
---|
3603 | {
|
---|
3604 | camera2->setFarClipDistance(0);
|
---|
3605 | }
|
---|
3606 | // Set a nice viewpoint
|
---|
3607 | camera2->setPosition(707,3500,528);
|
---|
3608 | camera2->lookAt(Vector3::ZERO);
|
---|
3609 | camera2->setNearClipDistance( 1 );
|
---|
3610 | camera2->setFarClipDistance( 1000 );
|
---|
3611 |
|
---|
3612 |
|
---|
3613 | // Create a tertiary scene manager with it's own camera
|
---|
3614 | SceneManager* sm3 = Root::getSingleton().createSceneManager("BspSceneManager");
|
---|
3615 | Camera* camera3 = sm3->createCamera("cam3");
|
---|
3616 |
|
---|
3617 | vp = mWindow->addViewport(camera3, 2, 0.5, 0.5, 0.5, 0.5);
|
---|
3618 | vp->setOverlaysEnabled(false);
|
---|
3619 |
|
---|
3620 | // Load Quake3 locations from a file
|
---|
3621 | ConfigFile cf;
|
---|
3622 |
|
---|
3623 | cf.load("quake3settings.cfg");
|
---|
3624 |
|
---|
3625 | String pk3 = cf.getSetting("Pak0Location");
|
---|
3626 | String level = cf.getSetting("Map");
|
---|
3627 |
|
---|
3628 | ExampleApplication::setupResources();
|
---|
3629 | ResourceGroupManager::getSingleton().createResourceGroup("BSP");
|
---|
3630 | ResourceGroupManager::getSingleton().setWorldResourceGroupName("BSP");
|
---|
3631 | ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
3632 | pk3, "Zip", ResourceGroupManager::getSingleton().getWorldResourceGroupName());
|
---|
3633 | ResourceGroupManager::getSingleton().initialiseResourceGroup("BSP");
|
---|
3634 | sm3->setWorldGeometry(level);
|
---|
3635 | // modify camera for close work
|
---|
3636 | camera3->setNearClipDistance(4);
|
---|
3637 | camera3->setFarClipDistance(4000);
|
---|
3638 |
|
---|
3639 | // Also change position, and set Quake-type orientation
|
---|
3640 | // Get random player start point
|
---|
3641 | ViewPoint viewp = sm3->getSuggestedViewpoint(true);
|
---|
3642 | camera3->setPosition(viewp.position);
|
---|
3643 | camera3->pitch(Degree(90)); // Quake uses X/Y horizon, Z up
|
---|
3644 | camera3->rotate(viewp.orientation);
|
---|
3645 | // Don't yaw along variable axis, causes leaning
|
---|
3646 | camera3->setFixedYawAxis(true, Vector3::UNIT_Z);
|
---|
3647 | camera3->yaw(Degree(-90));
|
---|
3648 |
|
---|
3649 |
|
---|
3650 |
|
---|
3651 |
|
---|
3652 |
|
---|
3653 | // Use original SM for normal scene
|
---|
3654 | testTextureShadows(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
3655 |
|
---|
3656 | }
|
---|
3657 |
|
---|
3658 | void testManualBoneMovement(void)
|
---|
3659 | {
|
---|
3660 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
|
---|
3661 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3662 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
|
---|
3663 |
|
---|
3664 | //ent->setMaterialName("Examples/Rocky");
|
---|
3665 |
|
---|
3666 | SkeletonInstance* skel = ent->getSkeleton();
|
---|
3667 | Animation* anim = skel->getAnimation("Walk");
|
---|
3668 | manuallyControlledBone = skel->getBone("Joint10");
|
---|
3669 | manuallyControlledBone->setManuallyControlled(true);
|
---|
3670 | anim->destroyNodeTrack(manuallyControlledBone->getHandle());
|
---|
3671 |
|
---|
3672 | //AnimationState* animState = ent->getAnimationState("Walk");
|
---|
3673 | //animState->setEnabled(true);
|
---|
3674 |
|
---|
3675 |
|
---|
3676 |
|
---|
3677 | }
|
---|
3678 |
|
---|
3679 | void testMaterialSchemes()
|
---|
3680 | {
|
---|
3681 |
|
---|
3682 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
|
---|
3683 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3684 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
|
---|
3685 |
|
---|
3686 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
|
---|
3687 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3688 | // default scheme
|
---|
3689 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
|
---|
3690 |
|
---|
3691 | Technique* t = mat->createTechnique();
|
---|
3692 | t->setSchemeName("newscheme");
|
---|
3693 | t->createPass()->createTextureUnitState("rockwall.tga");
|
---|
3694 | ent->setMaterialName("schemetest");
|
---|
3695 |
|
---|
3696 | // create a second viewport using alternate scheme
|
---|
3697 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
|
---|
3698 | vp->setMaterialScheme("newscheme");
|
---|
3699 | vp->setOverlaysEnabled(false);
|
---|
3700 |
|
---|
3701 | }
|
---|
3702 | void testMaterialSchemesWithLOD()
|
---|
3703 | {
|
---|
3704 |
|
---|
3705 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
|
---|
3706 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3707 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
|
---|
3708 |
|
---|
3709 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
|
---|
3710 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3711 | // default scheme
|
---|
3712 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
|
---|
3713 |
|
---|
3714 | // LOD 0, newscheme
|
---|
3715 | Technique* t = mat->createTechnique();
|
---|
3716 | t->setSchemeName("newscheme");
|
---|
3717 | t->createPass()->createTextureUnitState("rockwall.tga");
|
---|
3718 | ent->setMaterialName("schemetest");
|
---|
3719 |
|
---|
3720 | // LOD 1, default
|
---|
3721 | t = mat->createTechnique();
|
---|
3722 | t->setLodIndex(1);
|
---|
3723 | t->createPass()->createTextureUnitState("WeirdEye.png");
|
---|
3724 |
|
---|
3725 | // LOD 1, newscheme
|
---|
3726 | t = mat->createTechnique();
|
---|
3727 | t->setLodIndex(1);
|
---|
3728 | t->createPass()->createTextureUnitState("r2skin.jpg");
|
---|
3729 | t->setSchemeName("newscheme");
|
---|
3730 |
|
---|
3731 | Material::LodDistanceList ldl;
|
---|
3732 | ldl.push_back(500.0f);
|
---|
3733 | mat->setLodLevels(ldl);
|
---|
3734 |
|
---|
3735 |
|
---|
3736 | ent->setMaterialName("schemetest");
|
---|
3737 |
|
---|
3738 | // create a second viewport using alternate scheme
|
---|
3739 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
|
---|
3740 | vp->setMaterialScheme("newscheme");
|
---|
3741 | vp->setOverlaysEnabled(false);
|
---|
3742 |
|
---|
3743 | }
|
---|
3744 | void testMaterialSchemesWithMismatchedLOD()
|
---|
3745 | {
|
---|
3746 |
|
---|
3747 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh");
|
---|
3748 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
|
---|
3749 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8));
|
---|
3750 |
|
---|
3751 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest",
|
---|
3752 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
---|
3753 | // default scheme
|
---|
3754 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg");
|
---|
3755 |
|
---|
3756 | // LOD 0, newscheme
|
---|
3757 | Technique* t = mat->createTechnique();
|
---|
3758 | t->setSchemeName("newscheme");
|
---|
3759 | t->createPass()->createTextureUnitState("rockwall.tga");
|
---|
3760 | ent->setMaterialName("schemetest");
|
---|
3761 |
|
---|
3762 | // LOD 1, default
|
---|
3763 | t = mat->createTechnique();
|
---|
3764 | t->setLodIndex(1);
|
---|
3765 | t->createPass()->createTextureUnitState("WeirdEye.png");
|
---|
3766 |
|
---|
3767 | // LOD 2, default
|
---|
3768 | t = mat->createTechnique();
|
---|
3769 | t->setLodIndex(2);
|
---|
3770 | t->createPass()->createTextureUnitState("clouds.jpg");
|
---|
3771 |
|
---|
3772 | // LOD 1, newscheme
|
---|
3773 | t = mat->createTechnique();
|
---|
3774 | t->setLodIndex(1);
|
---|
3775 | t->createPass()->createTextureUnitState("r2skin.jpg");
|
---|
3776 | t->setSchemeName("newscheme");
|
---|
3777 |
|
---|
3778 | // No LOD 2 for newscheme! Should fallback on LOD 1
|
---|
3779 |
|
---|
3780 | Material::LodDistanceList ldl;
|
---|
3781 | ldl.push_back(250.0f);
|
---|
3782 | ldl.push_back(500.0f);
|
---|
3783 | mat->setLodLevels(ldl);
|
---|
3784 |
|
---|
3785 |
|
---|
3786 | ent->setMaterialName("schemetest");
|
---|
3787 |
|
---|
3788 | // create a second viewport using alternate scheme
|
---|
3789 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25);
|
---|
3790 | vp->setMaterialScheme("newscheme");
|
---|
3791 | vp->setOverlaysEnabled(false);
|
---|
3792 |
|
---|
3793 | }
|
---|
3794 | void testSkeletonAnimationOptimise(void)
|
---|
3795 | {
|
---|
3796 | mSceneMgr->setShadowTextureSize(512);
|
---|
3797 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
|
---|
3798 | mSceneMgr->setShadowFarDistance(1500);
|
---|
3799 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35));
|
---|
3800 | //mSceneMgr->setShadowFarDistance(800);
|
---|
3801 | // Set ambient light
|
---|
3802 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
|
---|
3803 |
|
---|
3804 | mLight = mSceneMgr->createLight("MainLight");
|
---|
3805 |
|
---|
3806 | /*/
|
---|
3807 | // Directional test
|
---|
3808 | mLight->setType(Light::LT_DIRECTIONAL);
|
---|
3809 | Vector3 vec(-1,-1,0);
|
---|
3810 | vec.normalise();
|
---|
3811 | mLight->setDirection(vec);
|
---|
3812 | /*/
|
---|
3813 | // Point test
|
---|
3814 | mLight->setType(Light::LT_POINT);
|
---|
3815 | mLight->setPosition(0, 200, 0);
|
---|
3816 | //*/
|
---|
3817 |
|
---|
3818 | Entity* pEnt;
|
---|
3819 |
|
---|
3820 | // Hardware animation
|
---|
3821 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" );
|
---|
3822 | mAnimState = pEnt->getAnimationState("Walk");
|
---|
3823 | mAnimState->setEnabled(true);
|
---|
3824 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
3825 | mTestNode[0]->attachObject( pEnt );
|
---|
3826 | mTestNode[0]->translate(+100,-100,0);
|
---|
3827 |
|
---|
3828 | // Software animation
|
---|
3829 | pEnt = mSceneMgr->createEntity( "2", "robot.mesh" );
|
---|
3830 | pEnt->setMaterialName("BaseWhite");
|
---|
3831 | /*/
|
---|
3832 | mAnimState = pEnt->getAnimationState("Walk");
|
---|
3833 | mAnimState->setEnabled(true);
|
---|
3834 | /*/
|
---|
3835 | pEnt->getAnimationState("Walk")->setEnabled(true);
|
---|
3836 | //*/
|
---|
3837 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
---|
3838 | mTestNode[1]->attachObject( pEnt );
|
---|
3839 | mTestNode[1]->translate(-100,-100,0);
|
---|
3840 |
|
---|
3841 |
|
---|
3842 | Plane plane;
|
---|
3843 | plane.normal = Vector3::UNIT_Y;
|
---|
3844 | plane.d = 100;
|
---|
3845 | MeshManager::getSingleton().createPlane("Myplane",
|
---|
3846 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
|
---|
3847 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
|
---|
3848 | Entity* pPlaneEnt;
|
---|
3849 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
|
---|
3850 | pPlaneEnt->setMaterialName("2 - Default");
|
---|
3851 | pPlaneEnt->setCastShadows(false);
|
---|
3852 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
|
---|
3853 | }
|
---|
3854 | // Just override the mandatory create scene method
|
---|
3855 | void createScene(void)
|
---|
3856 | {
|
---|
3857 |
|
---|
3858 | AnyNumeric anyInt1(43);
|
---|
3859 | AnyNumeric anyInt2(5);
|
---|
3860 | AnyNumeric anyInt3 = anyInt1 + anyInt2;
|
---|
3861 |
|
---|
3862 | std::cout << anyInt3;
|
---|
3863 | //Any anyString("test");
|
---|
3864 |
|
---|
3865 | //testMatrices();
|
---|
3866 | //testBsp();
|
---|
3867 | //testAlpha();
|
---|
3868 | //testAnimation();
|
---|
3869 |
|
---|
3870 | //testGpuPrograms();
|
---|
3871 | //testMultiViewports();
|
---|
3872 | //testDistortion();
|
---|
3873 | //testEdgeBuilderSingleIndexBufSingleVertexBuf();
|
---|
3874 | //testEdgeBuilderMultiIndexBufSingleVertexBuf();
|
---|
3875 | //testEdgeBuilderMultiIndexBufMultiVertexBuf();
|
---|
3876 | //testPrepareShadowVolume();
|
---|
3877 | //testWindowedViewportMode();
|
---|
3878 | //testSubEntityVisibility();
|
---|
3879 | //testAttachObjectsToBones();
|
---|
3880 | //testSkeletalAnimation();
|
---|
3881 | //testOrtho();
|
---|
3882 | //testClearScene();
|
---|
3883 |
|
---|
3884 | //testProjection();
|
---|
3885 | //testStencilShadows(SHADOWTYPE_STENCIL_ADDITIVE, true, true);
|
---|
3886 | //testStencilShadows(SHADOWTYPE_STENCIL_MODULATIVE, false, true);
|
---|
3887 | //testTextureShadows(SHADOWTYPE_TEXTURE_ADDITIVE);
|
---|
3888 | //testTextureShadows(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
3889 | //testSplitPassesTooManyTexUnits();
|
---|
3890 | //testOverlayZOrder();
|
---|
3891 | //testReflectedBillboards();
|
---|
3892 | //testBlendDiffuseColour();
|
---|
3893 |
|
---|
3894 | //testRaySceneQuery();
|
---|
3895 | //testIntersectionSceneQuery();
|
---|
3896 |
|
---|
3897 | //test2Spotlights();
|
---|
3898 |
|
---|
3899 | //testManualLOD();
|
---|
3900 | //testGeneratedLOD();
|
---|
3901 | //testLotsAndLotsOfEntities();
|
---|
3902 | //testSimpleMesh();
|
---|
3903 | //test2Windows();
|
---|
3904 | //testStaticGeometry();
|
---|
3905 | //testBillboardTextureCoords();
|
---|
3906 | //testReloadResources();
|
---|
3907 | //testTransparencyMipMaps();
|
---|
3908 | //testRadixSort();
|
---|
3909 | //testMorphAnimation();
|
---|
3910 | //testPoseAnimation();
|
---|
3911 | //testPoseAnimation2();
|
---|
3912 | //testBug();
|
---|
3913 | //testManualObjectNonIndexed();
|
---|
3914 | //testManualObjectIndexed();
|
---|
3915 | //testCustomProjectionMatrix();
|
---|
3916 | //testPointSprites();
|
---|
3917 | //testFallbackResourceGroup();
|
---|
3918 | //testSuppressedShadows(SHADOWTYPE_TEXTURE_ADDITIVE);
|
---|
3919 | //testViewportNoShadows(SHADOWTYPE_TEXTURE_ADDITIVE);
|
---|
3920 | //testBillboardChain();
|
---|
3921 | //testRibbonTrail();
|
---|
3922 | //testSerialisedColour();
|
---|
3923 | //testBillboardAccurateFacing();
|
---|
3924 | //testMultiSceneManagersSimple();
|
---|
3925 | //testMultiSceneManagersComplex();
|
---|
3926 | //testManualBoneMovement();
|
---|
3927 | //testMaterialSchemes();
|
---|
3928 | //testMaterialSchemesWithLOD();
|
---|
3929 | //testMaterialSchemesWithMismatchedLOD();
|
---|
3930 | testSkeletonAnimationOptimise();
|
---|
3931 |
|
---|
3932 |
|
---|
3933 | }
|
---|
3934 | // Create new frame listener
|
---|
3935 | void createFrameListener(void)
|
---|
3936 | {
|
---|
3937 | mFrameListener= new PlayPenListener(mSceneMgr, mWindow, mCamera);
|
---|
3938 | mFrameListener->showDebugOverlay(true);
|
---|
3939 | mRoot->addFrameListener(mFrameListener);
|
---|
3940 | //FrameListener* fl = new UberSimpleFrameListener(mWindow, mCamera);
|
---|
3941 | //mRoot->addFrameListener(fl);
|
---|
3942 |
|
---|
3943 | }
|
---|
3944 |
|
---|
3945 |
|
---|
3946 | public:
|
---|
3947 | void go(void)
|
---|
3948 | {
|
---|
3949 | if (!setup())
|
---|
3950 | return;
|
---|
3951 |
|
---|
3952 | mRoot->startRendering();
|
---|
3953 | }
|
---|
3954 |
|
---|
3955 |
|
---|
3956 | };
|
---|
3957 |
|
---|
3958 |
|
---|
3959 | //-----------------------------------------------------------------------------
|
---|
3960 | //-----------------------------------------------------------------------------
|
---|
3961 | bool gReload;
|
---|
3962 |
|
---|
3963 | // Listener class for frame updates
|
---|
3964 | class MemoryTestFrameListener : public FrameListener, public KeyListener
|
---|
3965 | {
|
---|
3966 | protected:
|
---|
3967 | Real time;
|
---|
3968 | EventProcessor* mEventProcessor;
|
---|
3969 | InputReader* mInputDevice;
|
---|
3970 | public:
|
---|
3971 | MemoryTestFrameListener(RenderWindow * win)
|
---|
3972 | {
|
---|
3973 | time = 0;
|
---|
3974 | mEventProcessor = new EventProcessor();
|
---|
3975 | mEventProcessor->initialise(win);
|
---|
3976 | mEventProcessor->startProcessingEvents();
|
---|
3977 | mEventProcessor->addKeyListener(this);
|
---|
3978 | mInputDevice = mEventProcessor->getInputReader();
|
---|
3979 | }
|
---|
3980 | virtual ~MemoryTestFrameListener()
|
---|
3981 | {
|
---|
3982 | time = 0;
|
---|
3983 | delete mEventProcessor;
|
---|
3984 | }
|
---|
3985 |
|
---|
3986 | bool frameStarted(const FrameEvent& evt)
|
---|
3987 | {
|
---|
3988 | if( mInputDevice->isKeyDown( KC_ESCAPE) )
|
---|
3989 | {
|
---|
3990 | gReload = false;
|
---|
3991 | return false;
|
---|
3992 | }
|
---|
3993 |
|
---|
3994 | time += evt.timeSinceLastFrame;
|
---|
3995 | if(time>5)
|
---|
3996 | {
|
---|
3997 | LogManager::getSingleton().logMessage("Reloading scene after 5 seconds");
|
---|
3998 | gReload = true;
|
---|
3999 | time=0;
|
---|
4000 | return false;
|
---|
4001 | }
|
---|
4002 | else
|
---|
4003 | {
|
---|
4004 | gReload = false;
|
---|
4005 | return true;
|
---|
4006 | }
|
---|
4007 | }
|
---|
4008 |
|
---|
4009 | void keyClicked(KeyEvent* e) {};
|
---|
4010 | void keyPressed(KeyEvent* e) {};
|
---|
4011 | void keyReleased(KeyEvent* e) {};
|
---|
4012 | void keyFocusIn(KeyEvent* e) {}
|
---|
4013 | void keyFocusOut(KeyEvent* e) {}
|
---|
4014 | };
|
---|
4015 |
|
---|
4016 | /** Application class */
|
---|
4017 | class MemoryTestApplication : public ExampleApplication
|
---|
4018 | {
|
---|
4019 | protected:
|
---|
4020 | MemoryTestFrameListener * mTestFrameListener;
|
---|
4021 | public:
|
---|
4022 |
|
---|
4023 | void go(void)
|
---|
4024 | {
|
---|
4025 | mRoot = 0;
|
---|
4026 | if (!setup())
|
---|
4027 | return;
|
---|
4028 |
|
---|
4029 | mRoot->startRendering();
|
---|
4030 |
|
---|
4031 | while(gReload)
|
---|
4032 | {
|
---|
4033 | // clean up
|
---|
4034 | destroyScene();
|
---|
4035 | destroyResources();
|
---|
4036 | if (!setup())
|
---|
4037 | return;
|
---|
4038 | mRoot->startRendering();
|
---|
4039 | }
|
---|
4040 | // clean up
|
---|
4041 | destroyScene();
|
---|
4042 | }
|
---|
4043 |
|
---|
4044 | bool setup(void)
|
---|
4045 | {
|
---|
4046 | if(!gReload)
|
---|
4047 | mRoot = new Root();
|
---|
4048 |
|
---|
4049 | setupResources();
|
---|
4050 |
|
---|
4051 | if(!gReload)
|
---|
4052 | {
|
---|
4053 | bool carryOn = configure();
|
---|
4054 | if (!carryOn)
|
---|
4055 | return false;
|
---|
4056 |
|
---|
4057 | chooseSceneManager();
|
---|
4058 | createCamera();
|
---|
4059 | createViewports();
|
---|
4060 |
|
---|
4061 | // Set default mipmap level (NB some APIs ignore this)
|
---|
4062 | TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
---|
4063 |
|
---|
4064 | // Create any resource listeners (for loading screens)
|
---|
4065 | createResourceListener();
|
---|
4066 |
|
---|
4067 | createFrameListener();
|
---|
4068 | }
|
---|
4069 | // Load resources
|
---|
4070 | loadResources();
|
---|
4071 |
|
---|
4072 | // Create the scene
|
---|
4073 | createScene();
|
---|
4074 |
|
---|
4075 | return true;
|
---|
4076 |
|
---|
4077 | }
|
---|
4078 |
|
---|
4079 | /// Method which will define the source of resources (other than current folder)
|
---|
4080 | virtual void setupResources(void)
|
---|
4081 | {
|
---|
4082 | // Custom setup
|
---|
4083 | ResourceGroupManager::getSingleton().createResourceGroup("CustomResourceGroup");
|
---|
4084 | ResourceGroupManager::getSingleton().addResourceLocation(
|
---|
4085 | "../../../media/ogrehead.zip", "Zip", "CustomResourceGroup");
|
---|
4086 | }
|
---|
4087 | void loadResources(void)
|
---|
4088 | {
|
---|
4089 | // Initialise, parse scripts etc
|
---|
4090 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
---|
4091 | }
|
---|
4092 | void destroyResources()
|
---|
4093 | {
|
---|
4094 | LogManager::getSingleton().logMessage("Destroying resources");
|
---|
4095 | ResourceGroupManager::getSingleton().removeResourceLocation(
|
---|
4096 | "../../../media/ogrehead.zip");
|
---|
4097 | ResourceGroupManager::getSingleton().destroyResourceGroup("CustomResourceGroup");
|
---|
4098 | }
|
---|
4099 |
|
---|
4100 | void createScene(void)
|
---|
4101 | {
|
---|
4102 | // Set a very low level of ambient lighting
|
---|
4103 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1));
|
---|
4104 |
|
---|
4105 | // Load ogre head
|
---|
4106 | MeshManager::getSingleton().load("ogrehead.mesh","CustomResourceGroup");
|
---|
4107 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
|
---|
4108 |
|
---|
4109 | // Attach the head to the scene
|
---|
4110 | mSceneMgr->getRootSceneNode()->attachObject(head);
|
---|
4111 |
|
---|
4112 | }
|
---|
4113 |
|
---|
4114 | void createFrameListener(void)
|
---|
4115 | {
|
---|
4116 | // This is where we instantiate our own frame listener
|
---|
4117 | mTestFrameListener= new MemoryTestFrameListener(mWindow);
|
---|
4118 | mRoot->addFrameListener(mTestFrameListener);
|
---|
4119 | /*if(!gReload)
|
---|
4120 | {
|
---|
4121 | ExampleApplication::createFrameListener();
|
---|
4122 | }*/
|
---|
4123 | }
|
---|
4124 |
|
---|
4125 | void destroyScene(void)
|
---|
4126 | {
|
---|
4127 | LogManager::getSingleton().logMessage("Clearing scene");
|
---|
4128 | mSceneMgr->clearScene();
|
---|
4129 | }
|
---|
4130 | };
|
---|
4131 |
|
---|
4132 |
|
---|
4133 |
|
---|
4134 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
4135 | #define WIN32_LEAN_AND_MEAN
|
---|
4136 | #include "windows.h"
|
---|
4137 |
|
---|
4138 |
|
---|
4139 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
|
---|
4140 | #else
|
---|
4141 | int main(int argc, char **argv)
|
---|
4142 | #endif
|
---|
4143 | {
|
---|
4144 | // Create application object
|
---|
4145 | PlayPenApplication app;
|
---|
4146 | //MemoryTestApplication app;
|
---|
4147 |
|
---|
4148 | try {
|
---|
4149 | app.go();
|
---|
4150 | } catch( Exception& e ) {
|
---|
4151 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
4152 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
---|
4153 | #else
|
---|
4154 | std::cerr << "An exception has occured: " << e.getFullDescription();
|
---|
4155 | #endif
|
---|
4156 | }
|
---|
4157 |
|
---|
4158 |
|
---|
4159 | return 0;
|
---|
4160 | }
|
---|
4161 |
|
---|
4162 |
|
---|
4163 |
|
---|
4164 |
|
---|
4165 |
|
---|
4166 |
|
---|
4167 |
|
---|