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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | /* |
---|
30 | ----------------------------------------------------------------------------- |
---|
31 | Filename: PlayPen.cpp |
---|
32 | Description: Somewhere to play in the sand... |
---|
33 | ----------------------------------------------------------------------------- |
---|
34 | */ |
---|
35 | |
---|
36 | #include "ExampleApplication.h" |
---|
37 | #include "OgreProgressiveMesh.h" |
---|
38 | #include "OgreEdgeListBuilder.h" |
---|
39 | #include "OgreBillboardChain.h" |
---|
40 | #include "OgreTextAreaOverlayElement.h" |
---|
41 | #include "AnimationBlender.h" |
---|
42 | #include "OgreErrorDialog.h" |
---|
43 | #include "OgreFontManager.h" |
---|
44 | // Static plugins declaration section |
---|
45 | // Note that every entry in here adds an extra header / library dependency |
---|
46 | #ifdef OGRE_STATIC_LIB |
---|
47 | # define ENABLE_PLUGIN_GL |
---|
48 | # if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
49 | # define ENABLE_PLUGIN_Direct3D9 |
---|
50 | # endif |
---|
51 | # define ENABLE_PLUGIN_OctreeSceneManager |
---|
52 | # define ENABLE_PLUGIN_BSPSceneManager |
---|
53 | # define ENABLE_PLUGIN_ParticleFX |
---|
54 | # define ENABLE_PLUGIN_CgProgramManager |
---|
55 | #endif |
---|
56 | #include "StaticPluginLoader.h" |
---|
57 | |
---|
58 | /* |
---|
59 | #include "OgreNoMemoryMacros.h" |
---|
60 | #include <ode/odecpp.h> |
---|
61 | #include <ode/odecpp_collision.h> |
---|
62 | #include "OgreMemoryMacros.h" |
---|
63 | */ |
---|
64 | |
---|
65 | /* |
---|
66 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
67 | #include "OgreNoMemoryMacros.h" |
---|
68 | #include <crtdbg.h> |
---|
69 | #endi*/ |
---|
70 | |
---|
71 | #define NUM_TEST_NODES 5 |
---|
72 | SceneNode* mTestNode[NUM_TEST_NODES] = {0,0,0,0,0}; |
---|
73 | SceneNode* mLightNode = 0; |
---|
74 | SceneNode* mRootNode; |
---|
75 | SceneNode* camNode; |
---|
76 | Entity* mEntity; |
---|
77 | Real animTime = 0; |
---|
78 | Animation* mAnim = 0; |
---|
79 | std::vector<AnimationState*> mAnimStateList; |
---|
80 | AnimationState* mAnimState = 0; |
---|
81 | Overlay* mpOverlay; |
---|
82 | Entity* pPlaneEnt; |
---|
83 | Camera* testCam = 0; |
---|
84 | SceneNode* camPlaneNode[6]; |
---|
85 | Light* mLight; |
---|
86 | IntersectionSceneQuery* intersectionQuery = 0; |
---|
87 | RaySceneQuery* rayQuery = 0; |
---|
88 | Entity* ball = 0; |
---|
89 | Vector3 ballVector; |
---|
90 | bool testreload = false; |
---|
91 | String testBackgroundLoadGroup; |
---|
92 | Sphere* projectionSphere = 0; |
---|
93 | ManualObject* scissorRect = 0; |
---|
94 | |
---|
95 | // Hacky globals |
---|
96 | GpuProgramParametersSharedPtr fragParams; |
---|
97 | GpuProgramParametersSharedPtr vertParams; |
---|
98 | MaterialPtr skin; |
---|
99 | Frustum* frustum = 0; |
---|
100 | Camera* theCam; |
---|
101 | Camera* reflectCam = 0; |
---|
102 | Camera* camera2 = 0; |
---|
103 | Bone* manuallyControlledBone = 0; |
---|
104 | AnimationBlender* animBlender = 0; |
---|
105 | String animBlendTarget[2]; |
---|
106 | int animBlendTargetIndex; |
---|
107 | MovablePlane movablePlane("APlane"); |
---|
108 | |
---|
109 | |
---|
110 | static const char* HeadPoses[] = {"upperboth", "upperleft", "upperright", "jaw", "face1", "face2"}; |
---|
111 | static const char* PoseAnimationStateName = "HeadPoses"; |
---|
112 | enum eHeadPose { DMG_BOTH, DMG_UPPER_LEFT, DMG_UPPER_RIGHT, DMG_JAW, FACE_1, FACE_2, NUM_HEAD_POSES }; |
---|
113 | |
---|
114 | using namespace OIS; |
---|
115 | |
---|
116 | class RefractionTextureListener : public RenderTargetListener |
---|
117 | { |
---|
118 | public: |
---|
119 | void preRenderTargetUpdate(const RenderTargetEvent& evt) |
---|
120 | { |
---|
121 | pPlaneEnt->setVisible(false); |
---|
122 | |
---|
123 | } |
---|
124 | void postRenderTargetUpdate(const RenderTargetEvent& evt) |
---|
125 | { |
---|
126 | pPlaneEnt->setVisible(true); |
---|
127 | } |
---|
128 | |
---|
129 | }; |
---|
130 | class ReflectionTextureListener : public RenderTargetListener |
---|
131 | { |
---|
132 | public: |
---|
133 | void preRenderTargetUpdate(const RenderTargetEvent& evt) |
---|
134 | { |
---|
135 | static Plane reflectPlane(Vector3::UNIT_Y, -100); |
---|
136 | pPlaneEnt->setVisible(false); |
---|
137 | theCam->enableReflection(reflectPlane); |
---|
138 | |
---|
139 | } |
---|
140 | void postRenderTargetUpdate(const RenderTargetEvent& evt) |
---|
141 | { |
---|
142 | pPlaneEnt->setVisible(true); |
---|
143 | theCam->disableReflection(); |
---|
144 | } |
---|
145 | |
---|
146 | }; |
---|
147 | |
---|
148 | |
---|
149 | class PlayPenListener : public ExampleFrameListener, public ResourceBackgroundQueue::Listener |
---|
150 | { |
---|
151 | protected: |
---|
152 | SceneManager* mSceneMgr; |
---|
153 | public: |
---|
154 | PlayPenListener(SceneManager* mgr, RenderWindow* win, Camera* cam) |
---|
155 | : ExampleFrameListener(win, cam),mSceneMgr(mgr) |
---|
156 | { |
---|
157 | } |
---|
158 | |
---|
159 | /// Background load completed |
---|
160 | void operationCompleted(BackgroundProcessTicket ticket) |
---|
161 | { |
---|
162 | mDebugText = "Background load complete"; |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | bool frameStarted(const FrameEvent& evt) |
---|
167 | { |
---|
168 | //mMoveSpeed = 0.2; |
---|
169 | |
---|
170 | if (!vertParams.isNull()) |
---|
171 | { |
---|
172 | Matrix4 scaleMat = Matrix4::IDENTITY; |
---|
173 | scaleMat[0][0] = 0.5f; |
---|
174 | scaleMat[1][1] = -0.5f; |
---|
175 | scaleMat[2][2] = 0.5f; |
---|
176 | scaleMat[0][3] = 0.5f; |
---|
177 | scaleMat[1][3] = 0.5f; |
---|
178 | scaleMat[2][3] = 0.5f; |
---|
179 | Matrix4 mat = frustum->getProjectionMatrixWithRSDepth() * |
---|
180 | frustum->getViewMatrix(); |
---|
181 | |
---|
182 | |
---|
183 | mat = scaleMat * mat; |
---|
184 | |
---|
185 | vertParams->setNamedConstant("texViewProjMatrix", mat); |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | } |
---|
190 | |
---|
191 | if (manuallyControlledBone) |
---|
192 | { |
---|
193 | manuallyControlledBone->yaw(Degree(evt.timeSinceLastFrame*100)); |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | static float reloadtime = 10.0f; |
---|
198 | if (testreload) |
---|
199 | { |
---|
200 | reloadtime -= evt.timeSinceLastFrame; |
---|
201 | if (reloadtime <= 0) |
---|
202 | { |
---|
203 | Entity* e = mSceneMgr->getEntity("1"); |
---|
204 | e->getParentSceneNode()->detachObject("1"); |
---|
205 | e = mSceneMgr->getEntity("2"); |
---|
206 | e->getParentSceneNode()->detachObject("2"); |
---|
207 | mSceneMgr->destroyAllEntities(); |
---|
208 | ResourceGroupManager::getSingleton().unloadResourceGroup("Sinbad"); |
---|
209 | ResourceGroupManager::getSingleton().loadResourceGroup("Sinbad"); |
---|
210 | |
---|
211 | testreload = false; |
---|
212 | |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | static float backgroundLoadTime = 5.0f; |
---|
217 | if (!testBackgroundLoadGroup.empty()) |
---|
218 | { |
---|
219 | backgroundLoadTime -= evt.timeSinceLastFrame; |
---|
220 | if (backgroundLoadTime < 0) |
---|
221 | { |
---|
222 | ResourceBackgroundQueue::getSingleton().loadResourceGroup(testBackgroundLoadGroup, this); |
---|
223 | testBackgroundLoadGroup.clear(); |
---|
224 | mDebugText = "Background load queued"; |
---|
225 | } |
---|
226 | |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | bool ret = ExampleFrameListener::frameStarted(evt); |
---|
233 | |
---|
234 | if (reflectCam) |
---|
235 | { |
---|
236 | reflectCam->setOrientation(mCamera->getOrientation()); |
---|
237 | reflectCam->setPosition(mCamera->getPosition()); |
---|
238 | } |
---|
239 | if (camera2) |
---|
240 | { |
---|
241 | camera2->setOrientation(mCamera->getOrientation()); |
---|
242 | camera2->setPosition(mCamera->getPosition()); |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | if (projectionSphere && scissorRect) |
---|
247 | { |
---|
248 | Real left, top, right, bottom; |
---|
249 | mCamera->projectSphere(*projectionSphere, &left, &top, &right, &bottom); |
---|
250 | |
---|
251 | scissorRect->beginUpdate(0); |
---|
252 | scissorRect->position(left, top, 0); |
---|
253 | scissorRect->position(right, top, 0); |
---|
254 | scissorRect->position(right, bottom, 0); |
---|
255 | scissorRect->position(left, bottom, 0); |
---|
256 | scissorRect->position(left, top, 0); |
---|
257 | scissorRect->end(); |
---|
258 | |
---|
259 | |
---|
260 | } |
---|
261 | |
---|
262 | return ret; |
---|
263 | |
---|
264 | } |
---|
265 | |
---|
266 | |
---|
267 | bool frameEnded(const FrameEvent& evt) |
---|
268 | { |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | // local just to stop toggles flipping too fast |
---|
273 | static Real timeUntilNextToggle = 0; |
---|
274 | static bool animate = true; |
---|
275 | static bool rotate = false; |
---|
276 | |
---|
277 | static bool firstTime = true; |
---|
278 | |
---|
279 | if (!firstTime) |
---|
280 | { |
---|
281 | //mCamera->yaw(20); |
---|
282 | } |
---|
283 | firstTime = false; |
---|
284 | |
---|
285 | if (timeUntilNextToggle >= 0) |
---|
286 | timeUntilNextToggle -= evt.timeSinceLastFrame; |
---|
287 | |
---|
288 | static bool mWireframe = false; |
---|
289 | if (mKeyboard->isKeyDown(KC_G) && timeUntilNextToggle <= 0) |
---|
290 | { |
---|
291 | mWireframe = !mWireframe; |
---|
292 | if (mWireframe) |
---|
293 | { |
---|
294 | mCamera->setPolygonMode(PM_WIREFRAME); |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | mCamera->setPolygonMode(PM_SOLID); |
---|
299 | } |
---|
300 | timeUntilNextToggle = 0.5; |
---|
301 | |
---|
302 | } |
---|
303 | |
---|
304 | if (mKeyboard->isKeyDown(KC_MINUS) && timeUntilNextToggle <= 0) |
---|
305 | { |
---|
306 | if (mWindow->isFullScreen()) |
---|
307 | { |
---|
308 | mWindow->setFullscreen(false, 800, 600); |
---|
309 | } |
---|
310 | else |
---|
311 | { |
---|
312 | mWindow->setFullscreen(true, 1024, 768); |
---|
313 | } |
---|
314 | timeUntilNextToggle = 0.5; |
---|
315 | |
---|
316 | } |
---|
317 | if (mKeyboard->isKeyDown(KC_EQUALS) && timeUntilNextToggle <= 0) |
---|
318 | { |
---|
319 | mWindow->setFullscreen(true, 800, 600); |
---|
320 | timeUntilNextToggle = 0.5; |
---|
321 | |
---|
322 | } |
---|
323 | |
---|
324 | |
---|
325 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Core/StatsBlockBorder/Up"); |
---|
326 | mat->setDepthCheckEnabled(true); |
---|
327 | mat->setDepthWriteEnabled(true); |
---|
328 | |
---|
329 | for (int i = 0; i < NUM_TEST_NODES; ++i) |
---|
330 | { |
---|
331 | if (mTestNode[i] && rotate) |
---|
332 | mTestNode[i]->yaw(Degree(evt.timeSinceLastFrame * 15)); |
---|
333 | } |
---|
334 | |
---|
335 | if (mAnimState && animate) |
---|
336 | mAnimState->addTime(evt.timeSinceLastFrame); |
---|
337 | |
---|
338 | if (animBlender && animate) |
---|
339 | { |
---|
340 | if (animBlender->getProgress() <= 0.0f) |
---|
341 | { |
---|
342 | animBlender->init(animBlendTarget[animBlendTargetIndex]); |
---|
343 | animBlendTargetIndex = (animBlendTargetIndex + 1) % 2; |
---|
344 | animBlender->blend(animBlendTarget[animBlendTargetIndex], AnimationBlender::BlendWhileAnimating, 10, false); |
---|
345 | } |
---|
346 | else |
---|
347 | { |
---|
348 | animBlender->addTime(evt.timeSinceLastFrame); |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | std::vector<AnimationState*>::iterator animi; |
---|
353 | for (animi = mAnimStateList.begin(); animi != mAnimStateList.end(); ++animi) |
---|
354 | { |
---|
355 | (*animi)->addTime(evt.timeSinceLastFrame); |
---|
356 | } |
---|
357 | |
---|
358 | if (mKeyboard->isKeyDown(KC_R) && timeUntilNextToggle <= 0) |
---|
359 | { |
---|
360 | rotate = !rotate; |
---|
361 | timeUntilNextToggle = 0.5; |
---|
362 | } |
---|
363 | if (mKeyboard->isKeyDown(KC_1) && timeUntilNextToggle <= 0) |
---|
364 | { |
---|
365 | animate = !animate; |
---|
366 | timeUntilNextToggle = 0.5; |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | if (rayQuery) |
---|
371 | { |
---|
372 | static std::set<Entity*> lastEnts; |
---|
373 | rayQuery->setRay(mCamera->getCameraToViewportRay(0.5, 0.5)); |
---|
374 | |
---|
375 | // Reset last set |
---|
376 | for (std::set<Entity*>::iterator lasti = lastEnts.begin(); |
---|
377 | lasti != lastEnts.end(); ++lasti) |
---|
378 | { |
---|
379 | (*lasti)->setMaterialName("Examples/OgreLogo"); |
---|
380 | } |
---|
381 | lastEnts.clear(); |
---|
382 | |
---|
383 | |
---|
384 | RaySceneQueryResult& results = rayQuery->execute(); |
---|
385 | for (RaySceneQueryResult::iterator mov = results.begin(); |
---|
386 | mov != results.end(); ++mov) |
---|
387 | { |
---|
388 | if (mov->movable) |
---|
389 | { |
---|
390 | if (mov->movable->getMovableType() == "Entity") |
---|
391 | { |
---|
392 | Entity* ent = static_cast<Entity*>(mov->movable); |
---|
393 | lastEnts.insert(ent); |
---|
394 | ent->setMaterialName("Examples/TextureEffect2"); |
---|
395 | |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | if (intersectionQuery) |
---|
402 | { |
---|
403 | static std::set<Entity*> lastEnts; |
---|
404 | |
---|
405 | // Reset last set |
---|
406 | for (std::set<Entity*>::iterator lasti = lastEnts.begin(); |
---|
407 | lasti != lastEnts.end(); ++lasti) |
---|
408 | { |
---|
409 | (*lasti)->setMaterialName("Examples/OgreLogo"); |
---|
410 | } |
---|
411 | lastEnts.clear(); |
---|
412 | |
---|
413 | |
---|
414 | IntersectionSceneQueryResult& results = intersectionQuery->execute(); |
---|
415 | for (SceneQueryMovableIntersectionList::iterator mov = results.movables2movables.begin(); |
---|
416 | mov != results.movables2movables.end(); ++mov) |
---|
417 | { |
---|
418 | SceneQueryMovableObjectPair& thepair = *mov; |
---|
419 | if (thepair.first->getMovableType() == "Entity") |
---|
420 | { |
---|
421 | Entity* ent = static_cast<Entity*>(thepair.first); |
---|
422 | lastEnts.insert(ent); |
---|
423 | ent->setMaterialName("Examples/TextureEffect2"); |
---|
424 | |
---|
425 | } |
---|
426 | if (thepair.second->getMovableType() == "Entity") |
---|
427 | { |
---|
428 | Entity* ent = static_cast<Entity*>(thepair.second); |
---|
429 | lastEnts.insert(ent); |
---|
430 | ent->setMaterialName("Examples/TextureEffect2"); |
---|
431 | |
---|
432 | } |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | /* |
---|
437 | if (mKeyboard->isKeyDown(KC_V) && timeUntilNextToggle <= 0) |
---|
438 | { |
---|
439 | static bool isVP = false; |
---|
440 | if (!isVP) |
---|
441 | { |
---|
442 | skin->getTechnique(0)->getPass(0)->setVertexProgram("SimpleVP"); |
---|
443 | skin->getTechnique(0)->getPass(0)->setVertexProgramParameters(vertParams); |
---|
444 | isVP = true; |
---|
445 | } |
---|
446 | else |
---|
447 | { |
---|
448 | skin->getTechnique(0)->getPass(0)->setVertexProgram(""); |
---|
449 | isVP = false; |
---|
450 | } |
---|
451 | timeUntilNextToggle = 0.5; |
---|
452 | } |
---|
453 | */ |
---|
454 | |
---|
455 | if (mKeyboard->isKeyDown(KC_P)) |
---|
456 | { |
---|
457 | mTestNode[0]->yaw(Degree(-evt.timeSinceLastFrame * 30)); |
---|
458 | } |
---|
459 | if (mKeyboard->isKeyDown(KC_O)) |
---|
460 | { |
---|
461 | mTestNode[0]->yaw(Degree(evt.timeSinceLastFrame * 30)); |
---|
462 | } |
---|
463 | if (mKeyboard->isKeyDown(KC_K)) |
---|
464 | { |
---|
465 | mTestNode[0]->roll(Degree(-evt.timeSinceLastFrame * 30)); |
---|
466 | } |
---|
467 | if (mKeyboard->isKeyDown(KC_L)) |
---|
468 | { |
---|
469 | mTestNode[0]->roll(Degree(evt.timeSinceLastFrame * 30)); |
---|
470 | } |
---|
471 | if (mKeyboard->isKeyDown(KC_U)) |
---|
472 | { |
---|
473 | mTestNode[0]->translate(0,0,-evt.timeSinceLastFrame * 30); |
---|
474 | } |
---|
475 | if (mKeyboard->isKeyDown(KC_J)) |
---|
476 | { |
---|
477 | mTestNode[0]->translate(0,0,evt.timeSinceLastFrame * 30); |
---|
478 | } |
---|
479 | if (mKeyboard->isKeyDown(KC_M)) |
---|
480 | { |
---|
481 | mTestNode[0]->translate(0,evt.timeSinceLastFrame * 30, 0); |
---|
482 | } |
---|
483 | if (mKeyboard->isKeyDown(KC_N)) |
---|
484 | { |
---|
485 | mTestNode[0]->translate(0,-evt.timeSinceLastFrame * 30, 0); |
---|
486 | } |
---|
487 | |
---|
488 | if (mKeyboard->isKeyDown(KC_0) && timeUntilNextToggle <= 0) |
---|
489 | { |
---|
490 | mAnimState->setEnabled(!mAnimState->getEnabled()); |
---|
491 | timeUntilNextToggle = 0.5; |
---|
492 | } |
---|
493 | |
---|
494 | if (mEntity && mKeyboard->isKeyDown(KC_SPACE) && timeUntilNextToggle <= 0) |
---|
495 | { |
---|
496 | mSceneMgr->destroyEntity(mEntity); |
---|
497 | //mLight->setCastShadows(true); |
---|
498 | mEntity = mSceneMgr->createEntity("newEnt", "robot.mesh"); |
---|
499 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mEntity); |
---|
500 | mAnimStateList.clear(); |
---|
501 | AnimationState* anim = mEntity->getAnimationState("Walk"); |
---|
502 | anim->setEnabled(true); |
---|
503 | mAnimStateList.push_back(anim); |
---|
504 | } |
---|
505 | |
---|
506 | |
---|
507 | /** Hack to test frustum vols |
---|
508 | if (testCam) |
---|
509 | { |
---|
510 | // reposition the camera planes |
---|
511 | PlaneBoundedVolumeList volList = mLight->_getFrustumClipVolumes(testCam); |
---|
512 | |
---|
513 | PlaneBoundedVolume& vol = volList[1]; |
---|
514 | for (int p = 0; p < 6; ++p) |
---|
515 | { |
---|
516 | Plane& pl = vol.planes[p]; |
---|
517 | camPlaneNode[p]->setOrientation(Vector3::UNIT_Z.getRotationTo(pl.normal)); |
---|
518 | camPlaneNode[p]->setPosition(0,0,0); |
---|
519 | camPlaneNode[p]->translate(0,0, pl.d, Node::TS_LOCAL); |
---|
520 | } |
---|
521 | |
---|
522 | vol.intersects(mEntity->getWorldBoundingBox()); |
---|
523 | } |
---|
524 | */ |
---|
525 | |
---|
526 | // Print camera details |
---|
527 | //mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + |
---|
528 | // "O: " + StringConverter::toString(mCamera->getDerivedOrientation())); |
---|
529 | return ExampleFrameListener::frameStarted(evt) && ExampleFrameListener::frameEnded(evt); |
---|
530 | |
---|
531 | } |
---|
532 | |
---|
533 | |
---|
534 | }; |
---|
535 | |
---|
536 | class PlayPenApplication : public ExampleApplication |
---|
537 | { |
---|
538 | protected: |
---|
539 | RefractionTextureListener mRefractionListener; |
---|
540 | ReflectionTextureListener mReflectionListener; |
---|
541 | StaticPluginLoader mStaticPluginLoader; |
---|
542 | public: |
---|
543 | PlayPenApplication() { |
---|
544 | |
---|
545 | |
---|
546 | } |
---|
547 | |
---|
548 | ~PlayPenApplication() |
---|
549 | { |
---|
550 | if (frustum) |
---|
551 | delete frustum; |
---|
552 | // Early delete so we can destroy static plugins |
---|
553 | if (mFrameListener) |
---|
554 | { |
---|
555 | delete mFrameListener; |
---|
556 | mFrameListener = 0; |
---|
557 | } |
---|
558 | if (mRoot) |
---|
559 | { |
---|
560 | delete mRoot; |
---|
561 | mRoot = 0; |
---|
562 | } |
---|
563 | #ifdef OGRE_STATIC_LIB |
---|
564 | mStaticPluginLoader.unload(); |
---|
565 | #endif |
---|
566 | } |
---|
567 | protected: |
---|
568 | |
---|
569 | void chooseSceneManager(void) |
---|
570 | { |
---|
571 | // DefaultSceneManager |
---|
572 | //mSceneMgr = mRoot->createSceneManager("DefaultSceneManager", "PlayPenSMInstance"); |
---|
573 | |
---|
574 | // BspSceneManager |
---|
575 | //mSceneMgr = mRoot->createSceneManager("BspSceneManager", "PlayPenSMInstance"); |
---|
576 | |
---|
577 | // OctreeSceneManager |
---|
578 | //mSceneMgr = mRoot->createSceneManager("OctreeSceneManager", "PlayPenSMInstance"); |
---|
579 | |
---|
580 | // TerrainSceneManager |
---|
581 | mSceneMgr = mRoot->createSceneManager("TerrainSceneManager", "PlayPenSMInstance"); |
---|
582 | } |
---|
583 | |
---|
584 | |
---|
585 | void createTestBugPlaneMesh3Streams(const String& testMeshName) |
---|
586 | { |
---|
587 | Plane plane(Vector3::UNIT_Z, 0); |
---|
588 | Real width = 258; |
---|
589 | Real height = 171; |
---|
590 | int xsegments = 50; |
---|
591 | int ysegments = 50; |
---|
592 | Real xTile = 1.0f; |
---|
593 | Real yTile = 1.0f; |
---|
594 | const Vector3& upVector = Vector3::UNIT_Y; |
---|
595 | MeshPtr pMesh = MeshManager::getSingleton().createManual(testMeshName, |
---|
596 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
597 | SubMesh *pSub = pMesh->createSubMesh(); |
---|
598 | |
---|
599 | // Set up vertex data |
---|
600 | // Use a single shared buffer |
---|
601 | pMesh->sharedVertexData = new VertexData(); |
---|
602 | VertexData* vertexData = pMesh->sharedVertexData; |
---|
603 | // Set up Vertex Declaration |
---|
604 | VertexDeclaration* vertexDecl = vertexData->vertexDeclaration; |
---|
605 | // We always need positions |
---|
606 | vertexDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
607 | vertexDecl->addElement(1, 0, VET_FLOAT3, VES_NORMAL); |
---|
608 | vertexDecl->addElement(2, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); |
---|
609 | |
---|
610 | vertexData->vertexCount = (xsegments + 1) * (ysegments + 1); |
---|
611 | |
---|
612 | // Allocate vertex buffers |
---|
613 | HardwareVertexBufferSharedPtr vbufpos = |
---|
614 | HardwareBufferManager::getSingleton(). |
---|
615 | createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, |
---|
616 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); |
---|
617 | HardwareVertexBufferSharedPtr vbufnorm = |
---|
618 | HardwareBufferManager::getSingleton(). |
---|
619 | createVertexBuffer(vertexDecl->getVertexSize(1), vertexData->vertexCount, |
---|
620 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); |
---|
621 | HardwareVertexBufferSharedPtr vbuftex = |
---|
622 | HardwareBufferManager::getSingleton(). |
---|
623 | createVertexBuffer(vertexDecl->getVertexSize(2), vertexData->vertexCount, |
---|
624 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); |
---|
625 | |
---|
626 | // Set up the binding (one source only) |
---|
627 | VertexBufferBinding* binding = vertexData->vertexBufferBinding; |
---|
628 | binding->setBinding(0, vbufpos); |
---|
629 | binding->setBinding(1, vbufnorm); |
---|
630 | binding->setBinding(2, vbuftex); |
---|
631 | |
---|
632 | // Work out the transform required |
---|
633 | // Default orientation of plane is normal along +z, distance 0 |
---|
634 | Matrix4 xlate, xform, rot; |
---|
635 | Matrix3 rot3; |
---|
636 | xlate = rot = Matrix4::IDENTITY; |
---|
637 | // Determine axes |
---|
638 | Vector3 zAxis, yAxis, xAxis; |
---|
639 | zAxis = plane.normal; |
---|
640 | zAxis.normalise(); |
---|
641 | yAxis = upVector; |
---|
642 | yAxis.normalise(); |
---|
643 | xAxis = yAxis.crossProduct(zAxis); |
---|
644 | |
---|
645 | rot3.FromAxes(xAxis, yAxis, zAxis); |
---|
646 | rot = rot3; |
---|
647 | |
---|
648 | // Set up standard xform from origin |
---|
649 | xlate.setTrans(plane.normal * -plane.d); |
---|
650 | |
---|
651 | // concatenate |
---|
652 | xform = xlate * rot; |
---|
653 | |
---|
654 | // Generate vertex data |
---|
655 | // Lock the whole buffer |
---|
656 | float* pPos = static_cast<float*>( |
---|
657 | vbufpos->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
658 | float* pNorm = static_cast<float*>( |
---|
659 | vbufnorm->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
660 | float* pTex = static_cast<float*>( |
---|
661 | vbuftex->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
662 | Real xSpace = width / xsegments; |
---|
663 | Real ySpace = height / ysegments; |
---|
664 | Real halfWidth = width / 2; |
---|
665 | Real halfHeight = height / 2; |
---|
666 | Real xTex = (1.0f * xTile) / xsegments; |
---|
667 | Real yTex = (1.0f * yTile) / ysegments; |
---|
668 | Vector3 vec; |
---|
669 | Vector3 min, max; |
---|
670 | Real maxSquaredLength; |
---|
671 | bool firstTime = true; |
---|
672 | |
---|
673 | for (int y = 0; y < ysegments + 1; ++y) |
---|
674 | { |
---|
675 | for (int x = 0; x < xsegments + 1; ++x) |
---|
676 | { |
---|
677 | // Work out centered on origin |
---|
678 | vec.x = (x * xSpace) - halfWidth; |
---|
679 | vec.y = (y * ySpace) - halfHeight; |
---|
680 | vec.z = 0.0f; |
---|
681 | // Transform by orientation and distance |
---|
682 | vec = xform * vec; |
---|
683 | // Assign to geometry |
---|
684 | *pPos++ = vec.x; |
---|
685 | *pPos++ = vec.y; |
---|
686 | *pPos++ = vec.z; |
---|
687 | |
---|
688 | // Build bounds as we go |
---|
689 | if (firstTime) |
---|
690 | { |
---|
691 | min = vec; |
---|
692 | max = vec; |
---|
693 | maxSquaredLength = vec.squaredLength(); |
---|
694 | firstTime = false; |
---|
695 | } |
---|
696 | else |
---|
697 | { |
---|
698 | min.makeFloor(vec); |
---|
699 | max.makeCeil(vec); |
---|
700 | maxSquaredLength = std::max(maxSquaredLength, vec.squaredLength()); |
---|
701 | } |
---|
702 | |
---|
703 | // Default normal is along unit Z |
---|
704 | vec = Vector3::UNIT_Z; |
---|
705 | // Rotate |
---|
706 | vec = rot * vec; |
---|
707 | |
---|
708 | *pNorm++ = vec.x; |
---|
709 | *pNorm++ = vec.y; |
---|
710 | *pNorm++ = vec.z; |
---|
711 | |
---|
712 | *pTex++ = x * xTex; |
---|
713 | *pTex++ = 1 - (y * yTex); |
---|
714 | |
---|
715 | |
---|
716 | } // x |
---|
717 | } // y |
---|
718 | |
---|
719 | // Unlock |
---|
720 | vbufpos->unlock(); |
---|
721 | vbufnorm->unlock(); |
---|
722 | vbuftex->unlock(); |
---|
723 | // Generate face list |
---|
724 | pSub->useSharedVertices = true; |
---|
725 | //tesselate2DMesh(pSub, xsegments + 1, ysegments + 1, false, indexBufferUsage, indexShadowBuffer); |
---|
726 | SubMesh* sm = pSub; |
---|
727 | int meshWidth = xsegments + 1; |
---|
728 | int meshHeight = ysegments + 1; |
---|
729 | bool doubleSided = false; |
---|
730 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY; |
---|
731 | bool indexShadowBuffer = true; |
---|
732 | // The mesh is built, just make a list of indexes to spit out the triangles |
---|
733 | int vInc, uInc, v, u, iterations; |
---|
734 | int vCount, uCount; |
---|
735 | |
---|
736 | if (doubleSided) |
---|
737 | { |
---|
738 | iterations = 2; |
---|
739 | vInc = 1; |
---|
740 | v = 0; // Start with front |
---|
741 | } |
---|
742 | else |
---|
743 | { |
---|
744 | iterations = 1; |
---|
745 | vInc = 1; |
---|
746 | v = 0; |
---|
747 | } |
---|
748 | |
---|
749 | // Allocate memory for faces |
---|
750 | // Num faces, width*height*2 (2 tris per square), index count is * 3 on top |
---|
751 | sm->indexData->indexCount = (meshWidth-1) * (meshHeight-1) * 2 * iterations * 3; |
---|
752 | sm->indexData->indexBuffer = HardwareBufferManager::getSingleton(). |
---|
753 | createIndexBuffer(HardwareIndexBuffer::IT_16BIT, |
---|
754 | sm->indexData->indexCount, indexBufferUsage, indexShadowBuffer); |
---|
755 | |
---|
756 | int v1, v2, v3; |
---|
757 | //bool firstTri = true; |
---|
758 | HardwareIndexBufferSharedPtr ibuf = sm->indexData->indexBuffer; |
---|
759 | // Lock the whole buffer |
---|
760 | unsigned short* pIndexes = static_cast<unsigned short*>( |
---|
761 | ibuf->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
762 | |
---|
763 | while (iterations--) |
---|
764 | { |
---|
765 | // Make tris in a zigzag pattern (compatible with strips) |
---|
766 | u = 0; |
---|
767 | uInc = 1; // Start with moving +u |
---|
768 | |
---|
769 | vCount = meshHeight - 1; |
---|
770 | while (vCount--) |
---|
771 | { |
---|
772 | uCount = meshWidth - 1; |
---|
773 | while (uCount--) |
---|
774 | { |
---|
775 | // First Tri in cell |
---|
776 | // ----------------- |
---|
777 | v1 = ((v + vInc) * meshWidth) + u; |
---|
778 | v2 = (v * meshWidth) + u; |
---|
779 | v3 = ((v + vInc) * meshWidth) + (u + uInc); |
---|
780 | // Output indexes |
---|
781 | *pIndexes++ = v1; |
---|
782 | *pIndexes++ = v2; |
---|
783 | *pIndexes++ = v3; |
---|
784 | // Second Tri in cell |
---|
785 | // ------------------ |
---|
786 | v1 = ((v + vInc) * meshWidth) + (u + uInc); |
---|
787 | v2 = (v * meshWidth) + u; |
---|
788 | v3 = (v * meshWidth) + (u + uInc); |
---|
789 | // Output indexes |
---|
790 | *pIndexes++ = v1; |
---|
791 | *pIndexes++ = v2; |
---|
792 | *pIndexes++ = v3; |
---|
793 | |
---|
794 | // Next column |
---|
795 | u += uInc; |
---|
796 | } |
---|
797 | // Next row |
---|
798 | v += vInc; |
---|
799 | u = 0; |
---|
800 | |
---|
801 | |
---|
802 | } |
---|
803 | |
---|
804 | // Reverse vInc for double sided |
---|
805 | v = meshHeight - 1; |
---|
806 | vInc = -vInc; |
---|
807 | |
---|
808 | } |
---|
809 | // Unlock |
---|
810 | ibuf->unlock(); |
---|
811 | |
---|
812 | //pMesh->_updateBounds(); |
---|
813 | pMesh->_setBounds(AxisAlignedBox(min, max)); |
---|
814 | pMesh->_setBoundingSphereRadius(Math::Sqrt(maxSquaredLength)); |
---|
815 | // load |
---|
816 | pMesh->load(); |
---|
817 | pMesh->touch(); |
---|
818 | } |
---|
819 | |
---|
820 | void stressTestStaticGeometry(void) |
---|
821 | { |
---|
822 | |
---|
823 | // Set ambient light |
---|
824 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
825 | |
---|
826 | // Create a point light |
---|
827 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
828 | l->setType(Light::LT_DIRECTIONAL); |
---|
829 | Vector3 dir(1, -1, -1.5); |
---|
830 | dir.normalise(); |
---|
831 | l->setDirection(dir); |
---|
832 | l->setDiffuseColour(1.0, 0.7, 0.0); |
---|
833 | |
---|
834 | |
---|
835 | Plane plane; |
---|
836 | plane.normal = Vector3::UNIT_Y; |
---|
837 | plane.d = 0; |
---|
838 | MeshManager::getSingleton().createPlane("Myplane", |
---|
839 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
840 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
841 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
842 | pPlaneEnt->setMaterialName("Examples/GrassFloor"); |
---|
843 | pPlaneEnt->setCastShadows(false); |
---|
844 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
845 | |
---|
846 | Vector3 min(-2000,0,-2000); |
---|
847 | Vector3 max(2000,0,2000); |
---|
848 | |
---|
849 | |
---|
850 | Entity* e = mSceneMgr->createEntity("1", "ogrehead.mesh"); |
---|
851 | StaticGeometry* s = 0; |
---|
852 | |
---|
853 | unsigned int count = 10; |
---|
854 | while(count--) |
---|
855 | { |
---|
856 | if(s) mSceneMgr->destroyStaticGeometry(s); |
---|
857 | s = mSceneMgr->createStaticGeometry("bing"); |
---|
858 | |
---|
859 | s->addEntity(e, Vector3(100, 100, 100)); |
---|
860 | |
---|
861 | s->build(); |
---|
862 | } |
---|
863 | |
---|
864 | |
---|
865 | //s->setRenderingDistance(1000); |
---|
866 | //s->dump("static.txt"); |
---|
867 | //mSceneMgr->showBoundingBoxes(true); |
---|
868 | mCamera->setLodBias(0.5); |
---|
869 | |
---|
870 | |
---|
871 | } |
---|
872 | |
---|
873 | void testManualBlend() |
---|
874 | { |
---|
875 | // create material |
---|
876 | MaterialPtr mat = MaterialManager::getSingleton().create("TestMat", |
---|
877 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
878 | Pass * p = mat->getTechnique(0)->getPass(0); |
---|
879 | p->setLightingEnabled(false); |
---|
880 | p->createTextureUnitState("Dirt.jpg"); |
---|
881 | TextureUnitState* t = p->createTextureUnitState("PoolFloorLightingMap.png"); |
---|
882 | t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, |
---|
883 | ColourValue::White, ColourValue::White, 0.75); |
---|
884 | |
---|
885 | Entity *planeEnt = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
886 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt); |
---|
887 | planeEnt->setMaterialName("TestManual"); |
---|
888 | |
---|
889 | |
---|
890 | |
---|
891 | } |
---|
892 | |
---|
893 | void testProjectSphere() |
---|
894 | { |
---|
895 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
896 | |
---|
897 | |
---|
898 | Plane plane; |
---|
899 | plane.normal = Vector3::UNIT_Y; |
---|
900 | plane.d = 0; |
---|
901 | MeshManager::getSingleton().createPlane("Myplane", |
---|
902 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
903 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
904 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
905 | pPlaneEnt->setMaterialName("Examples/GrassFloor"); |
---|
906 | pPlaneEnt->setCastShadows(false); |
---|
907 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
908 | |
---|
909 | projectionSphere = new Sphere(Vector3(0, 30.0, 0), 10.0); |
---|
910 | |
---|
911 | ManualObject* debugSphere = mSceneMgr->createManualObject("debugSphere"); |
---|
912 | debugSphere->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); |
---|
913 | for (int i = 0; i <= 20; ++i) |
---|
914 | { |
---|
915 | Vector3 basePos(projectionSphere->getRadius(), 0, 0); |
---|
916 | Quaternion quat; |
---|
917 | quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y); |
---|
918 | basePos = quat * basePos; |
---|
919 | debugSphere->position(basePos); |
---|
920 | } |
---|
921 | for (int i = 0; i <= 20; ++i) |
---|
922 | { |
---|
923 | Vector3 basePos(projectionSphere->getRadius(), 0, 0); |
---|
924 | Quaternion quat; |
---|
925 | quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Z); |
---|
926 | basePos = quat * basePos; |
---|
927 | debugSphere->position(basePos); |
---|
928 | } |
---|
929 | debugSphere->end(); |
---|
930 | |
---|
931 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,30,0))->attachObject(debugSphere); |
---|
932 | |
---|
933 | scissorRect = mSceneMgr->createManualObject("scissorrect"); |
---|
934 | scissorRect->setUseIdentityProjection(true); |
---|
935 | scissorRect->setUseIdentityView(true); |
---|
936 | AxisAlignedBox aabb; |
---|
937 | aabb.setInfinite(); |
---|
938 | scissorRect->setBoundingBox(aabb); |
---|
939 | scissorRect->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); |
---|
940 | scissorRect->position(Vector3::ZERO); |
---|
941 | scissorRect->position(Vector3::ZERO); |
---|
942 | scissorRect->position(Vector3::ZERO); |
---|
943 | scissorRect->position(Vector3::ZERO); |
---|
944 | scissorRect->position(Vector3::ZERO); |
---|
945 | scissorRect->end(); |
---|
946 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(scissorRect); |
---|
947 | |
---|
948 | |
---|
949 | |
---|
950 | |
---|
951 | } |
---|
952 | |
---|
953 | void testBug() |
---|
954 | { |
---|
955 | /** Bren's problem |
---|
956 | |
---|
957 | Ogre::Mesh* mesh = Ogre::MeshManager::getSingleton().load("male_civ_head.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).getPointer(); |
---|
958 | assert(mesh); |
---|
959 | Ogre::PoseList pose_list = mesh->getPoseList(); |
---|
960 | unsigned int num_subs = mesh->getNumSubMeshes(); |
---|
961 | |
---|
962 | int cur_pose_index = 0; |
---|
963 | Animation* anim = mesh->createAnimation(PoseAnimationStateName, (Real)NUM_HEAD_POSES); |
---|
964 | for (unsigned int cur_sub = 1; cur_sub <= num_subs; ++cur_sub) |
---|
965 | { |
---|
966 | Ogre::VertexAnimationTrack* track = anim->createVertexTrack(cur_sub, VAT_POSE); |
---|
967 | |
---|
968 | for (int cur_pose = 0; cur_pose < NUM_HEAD_POSES; ++cur_pose) |
---|
969 | { |
---|
970 | Ogre::VertexPoseKeyFrame* key = track->createVertexPoseKeyFrame((Real)cur_pose); |
---|
971 | |
---|
972 | bool done = false; |
---|
973 | |
---|
974 | for (unsigned int cur_key = 0; cur_key < NUM_HEAD_POSES && !done; ++cur_key) |
---|
975 | { |
---|
976 | if (pose_list[cur_key]->getName().compare(HeadPoses[cur_pose]) == 0 && |
---|
977 | pose_list[cur_key]->getTarget() == cur_sub - 1) |
---|
978 | { |
---|
979 | key->addPoseReference(cur_pose_index, 1.f); |
---|
980 | ++cur_pose_index; |
---|
981 | done = true; |
---|
982 | } |
---|
983 | } |
---|
984 | } |
---|
985 | } |
---|
986 | |
---|
987 | Entity* ent = mSceneMgr->createEntity("1", mesh->getName()); |
---|
988 | num_subs = ent->getNumSubEntities(); |
---|
989 | SubEntity* mStump; |
---|
990 | for (int i = 0; i < num_subs; ++i) |
---|
991 | { |
---|
992 | Ogre::SubEntity* sub_ent = ent->getSubEntity(i); |
---|
993 | assert(sub_ent); |
---|
994 | |
---|
995 | if (sub_ent->getMaterialName().compare(0, strlen("male_civ/neckstump_"), "male_civ/neckstump_") == 0) |
---|
996 | mStump = sub_ent; |
---|
997 | } |
---|
998 | |
---|
999 | assert(mStump && "Couldn't find head stump sub entity!"); |
---|
1000 | |
---|
1001 | mStump->setVisible(false); |
---|
1002 | |
---|
1003 | AnimationState* animState = ent->getAnimationState(PoseAnimationStateName); |
---|
1004 | animState->setLoop(false); // else mTimePos becomes undefined? |
---|
1005 | animState->setEnabled(true); |
---|
1006 | animState->setTimePosition((Real)2); |
---|
1007 | |
---|
1008 | */ |
---|
1009 | |
---|
1010 | Entity* ent = mSceneMgr->createEntity("test", "fs_raiden03b.mesh"); |
---|
1011 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
1012 | mAnimState = ent->getAnimationState("Default"); |
---|
1013 | mAnimState->setEnabled(true); |
---|
1014 | |
---|
1015 | } |
---|
1016 | |
---|
1017 | void testMaterialSerializer() |
---|
1018 | { |
---|
1019 | MaterialSerializer ser; |
---|
1020 | |
---|
1021 | // simple material |
---|
1022 | MaterialPtr m = MaterialManager::getSingleton().getByName("Examples/EnvMappedRustySteel"); |
---|
1023 | ser.queueForExport(m); |
---|
1024 | |
---|
1025 | // scheme-based but otherwise simple material |
---|
1026 | m = MaterialManager::getSingleton().getByName("Examples/MorningSkyBox"); |
---|
1027 | ser.queueForExport(m); |
---|
1028 | |
---|
1029 | // fairly simple shader, with custom param & default params |
---|
1030 | m = MaterialManager::getSingleton().getByName("Examples/CelShading"); |
---|
1031 | ser.queueForExport(m); |
---|
1032 | |
---|
1033 | // More complex shader |
---|
1034 | m = MaterialManager::getSingleton().getByName("Examples/BumpMapping/SingleLight"); |
---|
1035 | ser.queueForExport(m); |
---|
1036 | |
---|
1037 | // more complex shader, with light iteration |
---|
1038 | m = MaterialManager::getSingleton().getByName("Examples/BumpMapping/MultiLight"); |
---|
1039 | ser.queueForExport(m); |
---|
1040 | |
---|
1041 | // With a unified program |
---|
1042 | m = MaterialManager::getSingleton().getByName("jaiqua"); |
---|
1043 | ser.queueForExport(m); |
---|
1044 | |
---|
1045 | |
---|
1046 | // export |
---|
1047 | ser.exportQueued("testexport.material", true); |
---|
1048 | |
---|
1049 | |
---|
1050 | |
---|
1051 | |
---|
1052 | } |
---|
1053 | |
---|
1054 | void testTransparencyMipMaps() |
---|
1055 | { |
---|
1056 | MaterialPtr mat = MaterialManager::getSingleton().create("test", |
---|
1057 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
1058 | // known png with alpha |
---|
1059 | Pass* pass = mat->getTechnique(0)->getPass(0); |
---|
1060 | pass->createTextureUnitState("ogretext.png"); |
---|
1061 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
1062 | // alpha blend |
---|
1063 | pass->setDepthWriteEnabled(false); |
---|
1064 | |
---|
1065 | // alpha reject |
---|
1066 | //pass->setDepthWriteEnabled(true); |
---|
1067 | //pass->setAlphaRejectSettings(CMPF_LESS, 128); |
---|
1068 | |
---|
1069 | // Define a floor plane mesh |
---|
1070 | Plane p; |
---|
1071 | p.normal = Vector3::UNIT_Y; |
---|
1072 | p.d = 200; |
---|
1073 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
1074 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1075 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z); |
---|
1076 | |
---|
1077 | // Create an entity (the floor) |
---|
1078 | Entity* ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
1079 | ent->setMaterialName("test"); |
---|
1080 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
1081 | |
---|
1082 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
1083 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
1084 | |
---|
1085 | |
---|
1086 | { |
---|
1087 | |
---|
1088 | Real alphaLevel = 0.5f; |
---|
1089 | MaterialPtr alphamat = MaterialManager::getSingleton().create("testy", |
---|
1090 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
1091 | Pass* pass = alphamat->getTechnique(0)->getPass(0); |
---|
1092 | pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
1093 | pass->setDepthWriteEnabled(false); |
---|
1094 | TextureUnitState* t = pass->createTextureUnitState(); |
---|
1095 | t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alphaLevel); |
---|
1096 | |
---|
1097 | ent = mSceneMgr->createEntity("asd", "ogrehead.mesh"); |
---|
1098 | ent->setMaterialName("testy"); |
---|
1099 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
1100 | |
---|
1101 | } |
---|
1102 | |
---|
1103 | } |
---|
1104 | |
---|
1105 | void testCthNewBlending(void) |
---|
1106 | { |
---|
1107 | // Set ambient light |
---|
1108 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1109 | |
---|
1110 | // Create a point light |
---|
1111 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1112 | l->setType(Light::LT_DIRECTIONAL); |
---|
1113 | l->setDirection(-Vector3::UNIT_Y); |
---|
1114 | |
---|
1115 | // Accept default settings: point light, white diffuse, just set position |
---|
1116 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with |
---|
1117 | // other objects, but I don't |
---|
1118 | //l->setPosition(20,80,50); |
---|
1119 | |
---|
1120 | |
---|
1121 | Entity *ent = mSceneMgr->createEntity("head", "ogrehead_2.mesh"); |
---|
1122 | |
---|
1123 | // Add entity to the root scene node |
---|
1124 | mRootNode = mSceneMgr->getRootSceneNode(); |
---|
1125 | static_cast<SceneNode*>(mRootNode->createChild())->attachObject(ent); |
---|
1126 | |
---|
1127 | mTestNode[0] = static_cast<SceneNode*>( |
---|
1128 | mRootNode->createChild("TestNode", Vector3(100,0,0))); |
---|
1129 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh"); |
---|
1130 | mTestNode[0]->attachObject(ent); |
---|
1131 | |
---|
1132 | mTestNode[0]->attachObject(l); |
---|
1133 | |
---|
1134 | |
---|
1135 | // Create a skydome |
---|
1136 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
1137 | |
---|
1138 | // Define a floor plane mesh |
---|
1139 | Plane p; |
---|
1140 | p.normal = Vector3::UNIT_Y; |
---|
1141 | p.d = 200; |
---|
1142 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
1143 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1144 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z); |
---|
1145 | |
---|
1146 | // Create an entity (the floor) |
---|
1147 | ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
1148 | ent->setMaterialName("Block/Material1"); |
---|
1149 | |
---|
1150 | mRootNode->attachObject(ent); |
---|
1151 | |
---|
1152 | mCamera->setPosition(0,0,200); |
---|
1153 | mCamera->setDirection(0,0,-1); |
---|
1154 | |
---|
1155 | //mSceneMgr->setDisplaySceneNodes(true); |
---|
1156 | |
---|
1157 | } |
---|
1158 | |
---|
1159 | void testMatrices(void) |
---|
1160 | { |
---|
1161 | mCamera->setPosition(0,0,500); |
---|
1162 | mCamera->lookAt(0,0,0); |
---|
1163 | const Matrix4& view = mCamera->getViewMatrix(); |
---|
1164 | const Matrix4& proj = mCamera->getProjectionMatrix(); |
---|
1165 | |
---|
1166 | Matrix4 viewproj = proj * view; |
---|
1167 | |
---|
1168 | Vector3 point3d(100,100,0); |
---|
1169 | |
---|
1170 | Vector3 projPoint = viewproj * point3d; |
---|
1171 | |
---|
1172 | point3d = Vector3(100,100,400); |
---|
1173 | projPoint = viewproj * point3d; |
---|
1174 | } |
---|
1175 | void testBasicPlane() |
---|
1176 | { |
---|
1177 | /* |
---|
1178 | // Create a light |
---|
1179 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1180 | // Accept default settings: point light, white diffuse, just set position |
---|
1181 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with |
---|
1182 | // other objects, but I don't |
---|
1183 | l->setPosition(20,80,50); |
---|
1184 | */ |
---|
1185 | |
---|
1186 | // Create a point light |
---|
1187 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1188 | l->setType(Light::LT_DIRECTIONAL); |
---|
1189 | l->setDirection(-Vector3::UNIT_Y); |
---|
1190 | Entity *ent; |
---|
1191 | |
---|
1192 | // Define a floor plane mesh |
---|
1193 | Plane p; |
---|
1194 | p.normal = Vector3::UNIT_Y; |
---|
1195 | p.d = 200; |
---|
1196 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
1197 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1198 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z); |
---|
1199 | |
---|
1200 | // Create an entity (the floor) |
---|
1201 | ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
1202 | ent->setMaterialName("Examples/RustySteel"); |
---|
1203 | |
---|
1204 | mSceneMgr->getRootSceneNode()->attachObject(ent); |
---|
1205 | |
---|
1206 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh"); |
---|
1207 | |
---|
1208 | mRootNode = mSceneMgr->getRootSceneNode(); |
---|
1209 | SceneNode* node = mSceneMgr->createSceneNode(); |
---|
1210 | node->attachObject(sphereEnt); |
---|
1211 | mRootNode->addChild(node); |
---|
1212 | |
---|
1213 | } |
---|
1214 | |
---|
1215 | void testAlpha() |
---|
1216 | { |
---|
1217 | /* |
---|
1218 | // Create a light |
---|
1219 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1220 | // Accept default settings: point light, white diffuse, just set position |
---|
1221 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with |
---|
1222 | // other objects, but I don't |
---|
1223 | l->setPosition(20,80,50); |
---|
1224 | */ |
---|
1225 | |
---|
1226 | // Create a point light |
---|
1227 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1228 | l->setType(Light::LT_DIRECTIONAL); |
---|
1229 | l->setDirection(-Vector3::UNIT_Y); |
---|
1230 | Entity *ent; |
---|
1231 | |
---|
1232 | // Define a floor plane mesh |
---|
1233 | Plane p; |
---|
1234 | p.normal = Vector3::UNIT_Y; |
---|
1235 | p.d = 200; |
---|
1236 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
1237 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1238 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z); |
---|
1239 | |
---|
1240 | p.normal = Vector3::UNIT_Z; |
---|
1241 | p.d = 200; |
---|
1242 | MeshManager::getSingleton().createPlane("WallPlane", |
---|
1243 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1244 | p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Y); |
---|
1245 | |
---|
1246 | // Create an entity (the floor) |
---|
1247 | ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
1248 | ent->setMaterialName("Core/StatsBlockBorder/Up"); |
---|
1249 | |
---|
1250 | mSceneMgr->getRootSceneNode()->attachObject(ent); |
---|
1251 | |
---|
1252 | ent = mSceneMgr->createEntity("wall", "WallPlane"); |
---|
1253 | ent->setMaterialName("Core/StatsBlockBorder/Up"); |
---|
1254 | |
---|
1255 | mSceneMgr->getRootSceneNode()->attachObject(ent); |
---|
1256 | |
---|
1257 | |
---|
1258 | Entity* sphereEnt = mSceneMgr->createEntity("ogre", "ogrehead.mesh"); |
---|
1259 | |
---|
1260 | mRootNode = mSceneMgr->getRootSceneNode(); |
---|
1261 | SceneNode* node = mSceneMgr->createSceneNode(); |
---|
1262 | node->attachObject(sphereEnt); |
---|
1263 | mRootNode->addChild(node); |
---|
1264 | |
---|
1265 | mSceneMgr->showBoundingBoxes(true); |
---|
1266 | |
---|
1267 | } |
---|
1268 | void testBsp() |
---|
1269 | { |
---|
1270 | // Load Quake3 locations from a file |
---|
1271 | ConfigFile cf; |
---|
1272 | |
---|
1273 | cf.load("quake3settings.cfg"); |
---|
1274 | |
---|
1275 | String quakePk3 = cf.getSetting("Pak0Location"); |
---|
1276 | String quakeLevel = cf.getSetting("Map"); |
---|
1277 | |
---|
1278 | ResourceGroupManager::getSingleton().addResourceLocation(quakePk3, "Zip"); |
---|
1279 | |
---|
1280 | |
---|
1281 | // Load world geometry |
---|
1282 | mSceneMgr->setWorldGeometry(quakeLevel); |
---|
1283 | |
---|
1284 | // modify camera for close work |
---|
1285 | mCamera->setNearClipDistance(4); |
---|
1286 | mCamera->setFarClipDistance(4000); |
---|
1287 | |
---|
1288 | // Also change position, and set Quake-type orientation |
---|
1289 | // Get random player start point |
---|
1290 | ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true); |
---|
1291 | mCamera->setPosition(vp.position); |
---|
1292 | mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up |
---|
1293 | mCamera->rotate(vp.orientation); |
---|
1294 | // Don't yaw along variable axis, causes leaning |
---|
1295 | mCamera->setFixedYawAxis(true, Vector3::UNIT_Z); |
---|
1296 | |
---|
1297 | } |
---|
1298 | |
---|
1299 | void testAnimation() |
---|
1300 | { |
---|
1301 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1302 | l->setPosition(200,110,0); |
---|
1303 | l->setType(Light::LT_POINT); |
---|
1304 | Entity *ent; |
---|
1305 | |
---|
1306 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.4)); |
---|
1307 | |
---|
1308 | // Create an entity (the plant) |
---|
1309 | ent = mSceneMgr->createEntity("1", "skeletonandpose.mesh"); |
---|
1310 | |
---|
1311 | SceneNode* node = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild(Vector3(-50,0,0))); |
---|
1312 | node->attachObject(ent); |
---|
1313 | node->scale(2,2,2); |
---|
1314 | |
---|
1315 | mAnimState = ent->getAnimationState("pose2_Clip"); |
---|
1316 | mAnimState->setEnabled(true); |
---|
1317 | |
---|
1318 | mWindow->getViewport(0)->setBackgroundColour(ColourValue(1,0,0)); |
---|
1319 | |
---|
1320 | |
---|
1321 | } |
---|
1322 | |
---|
1323 | void testAnimationBlend() |
---|
1324 | { |
---|
1325 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1326 | l->setPosition(200,110,0); |
---|
1327 | l->setType(Light::LT_POINT); |
---|
1328 | Entity *ent; |
---|
1329 | |
---|
1330 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
1331 | |
---|
1332 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.4)); |
---|
1333 | |
---|
1334 | // Create an entity (the plant) |
---|
1335 | ent = mSceneMgr->createEntity("1", "sticky.mesh"); |
---|
1336 | |
---|
1337 | SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1338 | node->attachObject(ent); |
---|
1339 | node->scale(2,2,2); |
---|
1340 | |
---|
1341 | //mAnimState = ent->getAnimationState("triangle"); |
---|
1342 | //mAnimState->setEnabled(true); |
---|
1343 | |
---|
1344 | animBlender = new AnimationBlender(ent); |
---|
1345 | animBlendTarget[0] = "still"; |
---|
1346 | animBlendTarget[1] = "triangle"; |
---|
1347 | animBlendTargetIndex = 1; |
---|
1348 | animBlender->init(animBlendTarget[0]); |
---|
1349 | animBlender->blend(animBlendTarget[1], AnimationBlender::BlendWhileAnimating, 10, false); |
---|
1350 | |
---|
1351 | mCamera->setPosition(-50,0,0); |
---|
1352 | mCamera->lookAt(0,0,0); |
---|
1353 | |
---|
1354 | |
---|
1355 | } |
---|
1356 | |
---|
1357 | void testGpuPrograms(void) |
---|
1358 | { |
---|
1359 | // Set ambient light |
---|
1360 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1361 | |
---|
1362 | // Create a point light |
---|
1363 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1364 | l->setType(Light::LT_DIRECTIONAL); |
---|
1365 | l->setDirection(-Vector3::UNIT_Y); |
---|
1366 | |
---|
1367 | Entity* pEnt = mSceneMgr->createEntity( "1", "robot.mesh" ); |
---|
1368 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt); |
---|
1369 | |
---|
1370 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1371 | |
---|
1372 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" ); |
---|
1373 | mTestNode[0]->attachObject( pEnt ); |
---|
1374 | mTestNode[0]->translate(100,0,0); |
---|
1375 | |
---|
1376 | // Rejig the ogre skin material |
---|
1377 | // Load the programs first |
---|
1378 | |
---|
1379 | pEnt->getSubEntity(1)->setMaterialName("SimpleTest"); |
---|
1380 | |
---|
1381 | } |
---|
1382 | void testProjection(void) |
---|
1383 | { |
---|
1384 | // Set ambient light |
---|
1385 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1386 | |
---|
1387 | // Create a point light |
---|
1388 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1389 | l->setType(Light::LT_DIRECTIONAL); |
---|
1390 | l->setDirection(-Vector3::UNIT_Y); |
---|
1391 | |
---|
1392 | Entity* pEnt; |
---|
1393 | //pEnt = mSceneMgr->createEntity( "1", "knot.mesh" ); |
---|
1394 | //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt); |
---|
1395 | //pEnt->setMaterialName("Examples/OgreLogo"); |
---|
1396 | |
---|
1397 | // Define a floor plane mesh |
---|
1398 | Plane p; |
---|
1399 | p.normal = Vector3::UNIT_Z; |
---|
1400 | p.d = 200; |
---|
1401 | MeshManager::getSingleton().createPlane("WallPlane", |
---|
1402 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1403 | p,1500,1500,1,1,true,1,5,5,Vector3::UNIT_Y); |
---|
1404 | pEnt = mSceneMgr->createEntity( "5", "WallPlane" ); |
---|
1405 | pEnt->setMaterialName("Examples/OgreLogo"); |
---|
1406 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pEnt); |
---|
1407 | |
---|
1408 | |
---|
1409 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1410 | |
---|
1411 | //pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" ); |
---|
1412 | //mTestNode[0]->attachObject( pEnt ); |
---|
1413 | mTestNode[0]->translate(0, 0, 750); |
---|
1414 | |
---|
1415 | frustum = new Frustum(); |
---|
1416 | frustum->setVisible(true); |
---|
1417 | frustum->setFarClipDistance(5000); |
---|
1418 | frustum->setNearClipDistance(200); |
---|
1419 | frustum->setAspectRatio(1); |
---|
1420 | //frustum->setProjectionType(PT_ORTHOGRAPHIC); |
---|
1421 | mTestNode[0]->attachObject(frustum); |
---|
1422 | |
---|
1423 | // Hook the frustum up to the material |
---|
1424 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/OgreLogo"); |
---|
1425 | TextureUnitState *t = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0); |
---|
1426 | t->setProjectiveTexturing(true, frustum); |
---|
1427 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
1428 | |
---|
1429 | } |
---|
1430 | |
---|
1431 | void testMultiViewports(void) |
---|
1432 | { |
---|
1433 | // Set ambient light |
---|
1434 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1435 | |
---|
1436 | // Create a point light |
---|
1437 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1438 | l->setType(Light::LT_DIRECTIONAL); |
---|
1439 | l->setDirection(-Vector3::UNIT_Y); |
---|
1440 | |
---|
1441 | Entity* pEnt = mSceneMgr->createEntity( "1", "knot.mesh" ); |
---|
1442 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-30,0,-50))->attachObject(pEnt); |
---|
1443 | |
---|
1444 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1445 | |
---|
1446 | pEnt = mSceneMgr->createEntity( "2", "ogrehead.mesh" ); |
---|
1447 | mTestNode[0]->attachObject( pEnt ); |
---|
1448 | mTestNode[0]->translate(0, 0, 200); |
---|
1449 | |
---|
1450 | frustum = new Frustum(); |
---|
1451 | //frustum->setVisible(true); |
---|
1452 | frustum->setFarClipDistance(5000); |
---|
1453 | frustum->setNearClipDistance(100); |
---|
1454 | mTestNode[0]->attachObject(frustum); |
---|
1455 | |
---|
1456 | Viewport* vp = mRoot->getAutoCreatedWindow()->addViewport(mCamera, 1, 0.5, 0.5, 0.5, 0.5); |
---|
1457 | vp->setOverlaysEnabled(false); |
---|
1458 | vp->setBackgroundColour(ColourValue(1,0,0)); |
---|
1459 | |
---|
1460 | } |
---|
1461 | |
---|
1462 | |
---|
1463 | // Just override the mandatory create scene method |
---|
1464 | void testSceneNodeTracking(void) |
---|
1465 | { |
---|
1466 | |
---|
1467 | // Set ambient light |
---|
1468 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
1469 | |
---|
1470 | // Create a skydome |
---|
1471 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
1472 | |
---|
1473 | // Create a light |
---|
1474 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1475 | // Accept default settings: point light, white diffuse, just set position |
---|
1476 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with |
---|
1477 | // other objects, but I don't |
---|
1478 | l->setPosition(20,80,50); |
---|
1479 | |
---|
1480 | Entity *ent; |
---|
1481 | |
---|
1482 | // Define a floor plane mesh |
---|
1483 | Plane p; |
---|
1484 | p.normal = Vector3::UNIT_Y; |
---|
1485 | p.d = 200; |
---|
1486 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
1487 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1488 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z); |
---|
1489 | |
---|
1490 | // Create an entity (the floor) |
---|
1491 | ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
1492 | ent->setMaterialName("Examples/RustySteel"); |
---|
1493 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2) |
---|
1494 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
1495 | |
---|
1496 | // Add a head, give it it's own node |
---|
1497 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1498 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
1499 | headNode->attachObject(ent); |
---|
1500 | |
---|
1501 | // Add another head, give it it's own node |
---|
1502 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1503 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh"); |
---|
1504 | headNode2->attachObject(ent); |
---|
1505 | |
---|
1506 | // Make sure the head node tracks the root |
---|
1507 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z); |
---|
1508 | //headNode->setFixedYawAxis(true); |
---|
1509 | |
---|
1510 | // Create the camera node & attach camera |
---|
1511 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1512 | //camNode->attachObject(mCamera); |
---|
1513 | |
---|
1514 | // set up spline animation of node |
---|
1515 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10); |
---|
1516 | // Spline it for nice curves |
---|
1517 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
1518 | // Create a track to animate the head's node |
---|
1519 | NodeAnimationTrack* track = anim->createNodeTrack(0, headNode); |
---|
1520 | // Setup keyframes |
---|
1521 | TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition |
---|
1522 | key = track->createNodeKeyFrame(2.5); |
---|
1523 | key->setTranslate(Vector3(500,500,-1000)); |
---|
1524 | key = track->createNodeKeyFrame(5); |
---|
1525 | key->setTranslate(Vector3(-1500,1000,-600)); |
---|
1526 | key = track->createNodeKeyFrame(7.5); |
---|
1527 | key->setTranslate(Vector3(0,-100,0)); |
---|
1528 | key = track->createNodeKeyFrame(10); |
---|
1529 | key->setTranslate(Vector3(0,0,0)); |
---|
1530 | // Create a track to animate the second head's node |
---|
1531 | track = anim->createNodeTrack(1, headNode2); |
---|
1532 | // Setup keyframes |
---|
1533 | key = track->createNodeKeyFrame(0); // startposition |
---|
1534 | key = track->createNodeKeyFrame(2.5); |
---|
1535 | key->setTranslate(Vector3(-500,600,-100)); |
---|
1536 | key = track->createNodeKeyFrame(5); |
---|
1537 | key->setTranslate(Vector3(800,200,-600)); |
---|
1538 | key = track->createNodeKeyFrame(7.5); |
---|
1539 | key->setTranslate(Vector3(200,-1000,0)); |
---|
1540 | key = track->createNodeKeyFrame(10); |
---|
1541 | key->setTranslate(Vector3(30,70,110)); |
---|
1542 | // Create a new animation state to track this |
---|
1543 | mAnimState = mSceneMgr->createAnimationState("CameraTrack"); |
---|
1544 | mAnimState->setEnabled(true); |
---|
1545 | |
---|
1546 | // Put in a bit of fog for the hell of it |
---|
1547 | mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002); |
---|
1548 | |
---|
1549 | } |
---|
1550 | |
---|
1551 | |
---|
1552 | |
---|
1553 | void testDistortion(void) |
---|
1554 | { |
---|
1555 | theCam = mCamera; |
---|
1556 | // Set ambient light |
---|
1557 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1558 | |
---|
1559 | // Create a point light |
---|
1560 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1561 | l->setType(Light::LT_DIRECTIONAL); |
---|
1562 | l->setDirection(-Vector3::UNIT_Y); |
---|
1563 | |
---|
1564 | Entity* pEnt; |
---|
1565 | |
---|
1566 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "Refraction", 512, 512 ); |
---|
1567 | { |
---|
1568 | Viewport *v = rttTex->addViewport( mCamera ); |
---|
1569 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); |
---|
1570 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction"); |
---|
1571 | v->setOverlaysEnabled(false); |
---|
1572 | rttTex->addListener(&mRefractionListener); |
---|
1573 | } |
---|
1574 | |
---|
1575 | rttTex = mRoot->getRenderSystem()->createRenderTexture( "Reflection", 512, 512 ); |
---|
1576 | { |
---|
1577 | Viewport *v = rttTex->addViewport( mCamera ); |
---|
1578 | MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); |
---|
1579 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection"); |
---|
1580 | v->setOverlaysEnabled(false); |
---|
1581 | rttTex->addListener(&mReflectionListener); |
---|
1582 | } |
---|
1583 | // Define a floor plane mesh |
---|
1584 | Plane p; |
---|
1585 | p.normal = Vector3::UNIT_Y; |
---|
1586 | p.d = 100; |
---|
1587 | MeshManager::getSingleton().createPlane("WallPlane", |
---|
1588 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
1589 | p,1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
1590 | pPlaneEnt = mSceneMgr->createEntity( "5", "WallPlane" ); |
---|
1591 | pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction"); |
---|
1592 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
1593 | |
---|
1594 | |
---|
1595 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
1596 | |
---|
1597 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1598 | int i; |
---|
1599 | for (i = 0; i < 10; ++i) |
---|
1600 | { |
---|
1601 | pEnt = mSceneMgr->createEntity( "ogre" + StringConverter::toString(i), "ogrehead.mesh" ); |
---|
1602 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, -75, 0))->attachObject(pEnt); |
---|
1603 | pEnt = mSceneMgr->createEntity( "knot" + StringConverter::toString(i), "knot.mesh" ); |
---|
1604 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(i*100 - 500, 140, 0))->attachObject(pEnt); |
---|
1605 | } |
---|
1606 | |
---|
1607 | |
---|
1608 | |
---|
1609 | } |
---|
1610 | |
---|
1611 | |
---|
1612 | void testEdgeBuilderSingleIndexBufSingleVertexBuf() |
---|
1613 | { |
---|
1614 | /* This tests the edge builders ability to find shared edges in the simple case |
---|
1615 | of a single index buffer referencing a single vertex buffer |
---|
1616 | */ |
---|
1617 | VertexData vd; |
---|
1618 | IndexData id; |
---|
1619 | // Test pyramid |
---|
1620 | vd.vertexCount = 4; |
---|
1621 | vd.vertexStart = 0; |
---|
1622 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1623 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1624 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true); |
---|
1625 | vd.vertexBufferBinding->setBinding(0, vbuf); |
---|
1626 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1627 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1628 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1629 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ; |
---|
1630 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50; |
---|
1631 | vbuf->unlock(); |
---|
1632 | |
---|
1633 | id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1634 | HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true); |
---|
1635 | id.indexCount = 12; |
---|
1636 | id.indexStart = 0; |
---|
1637 | unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1638 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2; |
---|
1639 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3; |
---|
1640 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2; |
---|
1641 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1; |
---|
1642 | id.indexBuffer->unlock(); |
---|
1643 | |
---|
1644 | EdgeListBuilder edgeBuilder; |
---|
1645 | edgeBuilder.addVertexData(&vd); |
---|
1646 | edgeBuilder.addIndexData(&id); |
---|
1647 | EdgeData* edgeData = edgeBuilder.build(); |
---|
1648 | |
---|
1649 | edgeData->log(LogManager::getSingleton().getDefaultLog()); |
---|
1650 | |
---|
1651 | delete edgeData; |
---|
1652 | |
---|
1653 | |
---|
1654 | } |
---|
1655 | |
---|
1656 | void testEdgeBuilderMultiIndexBufSingleVertexBuf() |
---|
1657 | { |
---|
1658 | /* This tests the edge builders ability to find shared edges when there are |
---|
1659 | multiple index sets (submeshes) using a single vertex buffer. |
---|
1660 | */ |
---|
1661 | VertexData vd; |
---|
1662 | IndexData id[4]; |
---|
1663 | // Test pyramid |
---|
1664 | vd.vertexCount = 4; |
---|
1665 | vd.vertexStart = 0; |
---|
1666 | vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1667 | vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1668 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true); |
---|
1669 | vd.vertexBufferBinding->setBinding(0, vbuf); |
---|
1670 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1671 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1672 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1673 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ; |
---|
1674 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50; |
---|
1675 | vbuf->unlock(); |
---|
1676 | |
---|
1677 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1678 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1679 | id[0].indexCount = 3; |
---|
1680 | id[0].indexStart = 0; |
---|
1681 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1682 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2; |
---|
1683 | id[0].indexBuffer->unlock(); |
---|
1684 | |
---|
1685 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1686 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1687 | id[1].indexCount = 3; |
---|
1688 | id[1].indexStart = 0; |
---|
1689 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1690 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3; |
---|
1691 | id[1].indexBuffer->unlock(); |
---|
1692 | |
---|
1693 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1694 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1695 | id[2].indexCount = 3; |
---|
1696 | id[2].indexStart = 0; |
---|
1697 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1698 | *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2; |
---|
1699 | id[2].indexBuffer->unlock(); |
---|
1700 | |
---|
1701 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1702 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1703 | id[3].indexCount = 3; |
---|
1704 | id[3].indexStart = 0; |
---|
1705 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1706 | *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1; |
---|
1707 | id[3].indexBuffer->unlock(); |
---|
1708 | |
---|
1709 | EdgeListBuilder edgeBuilder; |
---|
1710 | edgeBuilder.addVertexData(&vd); |
---|
1711 | edgeBuilder.addIndexData(&id[0]); |
---|
1712 | edgeBuilder.addIndexData(&id[1]); |
---|
1713 | edgeBuilder.addIndexData(&id[2]); |
---|
1714 | edgeBuilder.addIndexData(&id[3]); |
---|
1715 | EdgeData* edgeData = edgeBuilder.build(); |
---|
1716 | |
---|
1717 | edgeData->log(LogManager::getSingleton().getDefaultLog()); |
---|
1718 | |
---|
1719 | delete edgeData; |
---|
1720 | |
---|
1721 | |
---|
1722 | } |
---|
1723 | |
---|
1724 | |
---|
1725 | void testEdgeBuilderMultiIndexBufMultiVertexBuf() |
---|
1726 | { |
---|
1727 | /* This tests the edge builders ability to find shared edges when there are |
---|
1728 | both multiple index sets (submeshes) each using a different vertex buffer |
---|
1729 | (not using shared geoemtry). |
---|
1730 | */ |
---|
1731 | |
---|
1732 | VertexData vd[4]; |
---|
1733 | IndexData id[4]; |
---|
1734 | // Test pyramid |
---|
1735 | vd[0].vertexCount = 3; |
---|
1736 | vd[0].vertexStart = 0; |
---|
1737 | vd[0].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1738 | vd[0].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1739 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true); |
---|
1740 | vd[0].vertexBufferBinding->setBinding(0, vbuf); |
---|
1741 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1742 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1743 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1744 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ; |
---|
1745 | vbuf->unlock(); |
---|
1746 | |
---|
1747 | vd[1].vertexCount = 3; |
---|
1748 | vd[1].vertexStart = 0; |
---|
1749 | vd[1].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1750 | vd[1].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1751 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true); |
---|
1752 | vd[1].vertexBufferBinding->setBinding(0, vbuf); |
---|
1753 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1754 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1755 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ; |
---|
1756 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50; |
---|
1757 | vbuf->unlock(); |
---|
1758 | |
---|
1759 | vd[2].vertexCount = 3; |
---|
1760 | vd[2].vertexStart = 0; |
---|
1761 | vd[2].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1762 | vd[2].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1763 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true); |
---|
1764 | vd[2].vertexBufferBinding->setBinding(0, vbuf); |
---|
1765 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1766 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1767 | *pFloat++ = 0 ; *pFloat++ = 100; *pFloat++ = 0 ; |
---|
1768 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50; |
---|
1769 | vbuf->unlock(); |
---|
1770 | |
---|
1771 | vd[3].vertexCount = 3; |
---|
1772 | vd[3].vertexStart = 0; |
---|
1773 | vd[3].vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); |
---|
1774 | vd[3].vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION); |
---|
1775 | vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 3, HardwareBuffer::HBU_STATIC,true); |
---|
1776 | vd[3].vertexBufferBinding->setBinding(0, vbuf); |
---|
1777 | pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1778 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1779 | *pFloat++ = 50 ; *pFloat++ = 0 ; *pFloat++ = 0 ; |
---|
1780 | *pFloat++ = 0 ; *pFloat++ = 0 ; *pFloat++ = -50; |
---|
1781 | vbuf->unlock(); |
---|
1782 | |
---|
1783 | id[0].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1784 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1785 | id[0].indexCount = 3; |
---|
1786 | id[0].indexStart = 0; |
---|
1787 | unsigned short* pIdx = static_cast<unsigned short*>(id[0].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1788 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2; |
---|
1789 | id[0].indexBuffer->unlock(); |
---|
1790 | |
---|
1791 | id[1].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1792 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1793 | id[1].indexCount = 3; |
---|
1794 | id[1].indexStart = 0; |
---|
1795 | pIdx = static_cast<unsigned short*>(id[1].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1796 | *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2; |
---|
1797 | id[1].indexBuffer->unlock(); |
---|
1798 | |
---|
1799 | id[2].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1800 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1801 | id[2].indexCount = 3; |
---|
1802 | id[2].indexStart = 0; |
---|
1803 | pIdx = static_cast<unsigned short*>(id[2].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1804 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1; |
---|
1805 | id[2].indexBuffer->unlock(); |
---|
1806 | |
---|
1807 | id[3].indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( |
---|
1808 | HardwareIndexBuffer::IT_16BIT, 3, HardwareBuffer::HBU_STATIC, true); |
---|
1809 | id[3].indexCount = 3; |
---|
1810 | id[3].indexStart = 0; |
---|
1811 | pIdx = static_cast<unsigned short*>(id[3].indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); |
---|
1812 | *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 1; |
---|
1813 | id[3].indexBuffer->unlock(); |
---|
1814 | |
---|
1815 | EdgeListBuilder edgeBuilder; |
---|
1816 | edgeBuilder.addVertexData(&vd[0]); |
---|
1817 | edgeBuilder.addVertexData(&vd[1]); |
---|
1818 | edgeBuilder.addVertexData(&vd[2]); |
---|
1819 | edgeBuilder.addVertexData(&vd[3]); |
---|
1820 | edgeBuilder.addIndexData(&id[0], 0); |
---|
1821 | edgeBuilder.addIndexData(&id[1], 1); |
---|
1822 | edgeBuilder.addIndexData(&id[2], 2); |
---|
1823 | edgeBuilder.addIndexData(&id[3], 3); |
---|
1824 | EdgeData* edgeData = edgeBuilder.build(); |
---|
1825 | |
---|
1826 | edgeData->log(LogManager::getSingleton().getDefaultLog()); |
---|
1827 | |
---|
1828 | delete edgeData; |
---|
1829 | |
---|
1830 | |
---|
1831 | } |
---|
1832 | |
---|
1833 | void testSkeletalAnimation() |
---|
1834 | { |
---|
1835 | // Set ambient light |
---|
1836 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1837 | //mWindow->getViewport(0)->setBackgroundColour(ColourValue::White); |
---|
1838 | |
---|
1839 | |
---|
1840 | |
---|
1841 | Entity *ent = mSceneMgr->createEntity("robot", "test.mesh"); |
---|
1842 | // Uncomment the below to test software skinning |
---|
1843 | //ent->setMaterialName("Examples/Rocky"); |
---|
1844 | // Add entity to the scene node |
---|
1845 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
1846 | mAnimState = ent->getAnimationState("Default"); |
---|
1847 | mAnimState->setEnabled(true); |
---|
1848 | |
---|
1849 | // Give it a little ambience with lights |
---|
1850 | Light* l; |
---|
1851 | l = mSceneMgr->createLight("BlueLight"); |
---|
1852 | l->setPosition(-200,-80,-100); |
---|
1853 | l->setDiffuseColour(0.5, 0.5, 1.0); |
---|
1854 | |
---|
1855 | l = mSceneMgr->createLight("GreenLight"); |
---|
1856 | l->setPosition(0,0,-100); |
---|
1857 | l->setDiffuseColour(0.5, 1.0, 0.5); |
---|
1858 | |
---|
1859 | // Position the camera |
---|
1860 | mCamera->setPosition(100,50,100); |
---|
1861 | mCamera->lookAt(-50,50,0); |
---|
1862 | |
---|
1863 | // Report whether hardware skinning is enabled or not |
---|
1864 | Technique* t = ent->getSubEntity(0)->getMaterial()->getBestTechnique(); |
---|
1865 | Pass* p = t->getPass(0); |
---|
1866 | OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); |
---|
1867 | if (p->hasVertexProgram() && |
---|
1868 | p->getVertexProgram()->isSkeletalAnimationIncluded()) |
---|
1869 | { |
---|
1870 | guiDbg->setCaption("Hardware skinning is enabled"); |
---|
1871 | } |
---|
1872 | else |
---|
1873 | { |
---|
1874 | guiDbg->setCaption("Software skinning is enabled"); |
---|
1875 | } |
---|
1876 | |
---|
1877 | |
---|
1878 | } |
---|
1879 | |
---|
1880 | |
---|
1881 | void testPrepareShadowVolume(void) |
---|
1882 | { |
---|
1883 | |
---|
1884 | // Set ambient light |
---|
1885 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1886 | |
---|
1887 | // Create a point light |
---|
1888 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1889 | l->setType(Light::LT_DIRECTIONAL); |
---|
1890 | l->setDirection(-Vector3::UNIT_Y); |
---|
1891 | |
---|
1892 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild(); |
---|
1893 | |
---|
1894 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" ); |
---|
1895 | mTestNode[0]->attachObject( pEnt ); |
---|
1896 | |
---|
1897 | pEnt->getMesh()->prepareForShadowVolume(); |
---|
1898 | |
---|
1899 | } |
---|
1900 | |
---|
1901 | void testWindowedViewportMode() |
---|
1902 | { |
---|
1903 | // Set ambient light |
---|
1904 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1905 | |
---|
1906 | // Create a point light |
---|
1907 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1908 | l->setType(Light::LT_DIRECTIONAL); |
---|
1909 | l->setDirection(-Vector3::UNIT_Y); |
---|
1910 | |
---|
1911 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild(); |
---|
1912 | |
---|
1913 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" ); |
---|
1914 | mTestNode[0]->attachObject( pEnt ); |
---|
1915 | |
---|
1916 | mCamera->setWindow(0,0,0.5,0.5); |
---|
1917 | |
---|
1918 | } |
---|
1919 | void testSubEntityVisibility() |
---|
1920 | { |
---|
1921 | // Set ambient light |
---|
1922 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
1923 | |
---|
1924 | // Create a point light |
---|
1925 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1926 | l->setType(Light::LT_DIRECTIONAL); |
---|
1927 | l->setDirection(-Vector3::UNIT_Y); |
---|
1928 | |
---|
1929 | mTestNode[0] = (SceneNode*)mSceneMgr->getRootSceneNode()->createChild(); |
---|
1930 | |
---|
1931 | Entity* pEnt = mSceneMgr->createEntity( "1", "ogrehead.mesh" ); |
---|
1932 | mTestNode[0]->attachObject( pEnt ); |
---|
1933 | |
---|
1934 | pEnt->getSubEntity(1)->setVisible(false); |
---|
1935 | |
---|
1936 | |
---|
1937 | } |
---|
1938 | |
---|
1939 | void testAttachObjectsToBones() |
---|
1940 | { |
---|
1941 | Entity *ent; |
---|
1942 | for (int i = 0; i < 12; ++i) |
---|
1943 | { |
---|
1944 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh"); |
---|
1945 | if (false)//i % 2) |
---|
1946 | { |
---|
1947 | Entity* ent2 = mSceneMgr->createEntity("plane" + StringConverter::toString(i), "razor.mesh"); |
---|
1948 | ent->attachObjectToBone("Joint8", ent2); |
---|
1949 | } |
---|
1950 | else |
---|
1951 | { |
---|
1952 | ParticleSystem* psys = mSceneMgr->createParticleSystem("psys" + StringConverter::toString(i), "Examples/PurpleFountain"); |
---|
1953 | psys->getEmitter(0)->setTimeToLive(0.2); |
---|
1954 | ent->attachObjectToBone("Joint15", psys); |
---|
1955 | } |
---|
1956 | // Add entity to the scene node |
---|
1957 | mSceneMgr->getRootSceneNode()->createChildSceneNode( |
---|
1958 | Vector3(0,0,(i*200)-(12*200/2)))->attachObject(ent); |
---|
1959 | |
---|
1960 | ent->getParentNode()->yaw(Degree(i * 45)); |
---|
1961 | } |
---|
1962 | mAnimState = ent->getAnimationState("Walk"); |
---|
1963 | mAnimState->setEnabled(true); |
---|
1964 | |
---|
1965 | |
---|
1966 | |
---|
1967 | // Give it a little ambience with lights |
---|
1968 | Light* l; |
---|
1969 | l = mSceneMgr->createLight("BlueLight"); |
---|
1970 | l->setPosition(-200,-80,-100); |
---|
1971 | l->setDiffuseColour(0.5, 0.5, 1.0); |
---|
1972 | |
---|
1973 | l = mSceneMgr->createLight("GreenLight"); |
---|
1974 | l->setPosition(0,0,-100); |
---|
1975 | l->setDiffuseColour(0.5, 1.0, 0.5); |
---|
1976 | |
---|
1977 | // Position the camera |
---|
1978 | mCamera->setPosition(100,50,100); |
---|
1979 | mCamera->lookAt(-50,50,0); |
---|
1980 | |
---|
1981 | mSceneMgr->setAmbientLight(ColourValue(1,1,1,1)); |
---|
1982 | mSceneMgr->showBoundingBoxes(true); |
---|
1983 | |
---|
1984 | } |
---|
1985 | void testOrtho() |
---|
1986 | { |
---|
1987 | // Set ambient light |
---|
1988 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0)); |
---|
1989 | |
---|
1990 | // Create a point light |
---|
1991 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
1992 | l->setPosition(800,600,0); |
---|
1993 | |
---|
1994 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1995 | mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
1996 | |
---|
1997 | Entity* pEnt = mSceneMgr->createEntity( "3", "knot.mesh" ); |
---|
1998 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200)); |
---|
1999 | mTestNode[1]->attachObject( pEnt ); |
---|
2000 | |
---|
2001 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" ); |
---|
2002 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200)); |
---|
2003 | mTestNode[2]->attachObject( pEnt ); |
---|
2004 | |
---|
2005 | |
---|
2006 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
2007 | |
---|
2008 | |
---|
2009 | Plane plane; |
---|
2010 | plane.normal = Vector3::UNIT_Y; |
---|
2011 | plane.d = 100; |
---|
2012 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2013 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
2014 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
2015 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2016 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2017 | pPlaneEnt->setCastShadows(false); |
---|
2018 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2019 | |
---|
2020 | mCamera->setFixedYawAxis(false); |
---|
2021 | mCamera->setProjectionType(PT_ORTHOGRAPHIC); |
---|
2022 | mCamera->setPosition(0,10000,0); |
---|
2023 | mCamera->lookAt(0,0,0); |
---|
2024 | mCamera->setNearClipDistance(1000); |
---|
2025 | |
---|
2026 | } |
---|
2027 | |
---|
2028 | void testManualLOD() |
---|
2029 | { |
---|
2030 | MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("robot.mesh", |
---|
2031 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2032 | |
---|
2033 | msh1->createManualLodLevel(200, "razor.mesh"); |
---|
2034 | msh1->createManualLodLevel(500, "sphere.mesh"); |
---|
2035 | |
---|
2036 | Entity *ent; |
---|
2037 | for (int i = 0; i < 5; ++i) |
---|
2038 | { |
---|
2039 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh"); |
---|
2040 | // Add entity to the scene node |
---|
2041 | mSceneMgr->getRootSceneNode()->createChildSceneNode( |
---|
2042 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent); |
---|
2043 | } |
---|
2044 | mAnimState = ent->getAnimationState("Walk"); |
---|
2045 | mAnimState->setEnabled(true); |
---|
2046 | |
---|
2047 | |
---|
2048 | |
---|
2049 | // Give it a little ambience with lights |
---|
2050 | Light* l; |
---|
2051 | l = mSceneMgr->createLight("BlueLight"); |
---|
2052 | l->setPosition(-200,-80,-100); |
---|
2053 | l->setDiffuseColour(0.5, 0.5, 1.0); |
---|
2054 | |
---|
2055 | l = mSceneMgr->createLight("GreenLight"); |
---|
2056 | l->setPosition(0,0,-100); |
---|
2057 | l->setDiffuseColour(0.5, 1.0, 0.5); |
---|
2058 | |
---|
2059 | // Position the camera |
---|
2060 | mCamera->setPosition(100,50,100); |
---|
2061 | mCamera->lookAt(-50,50,0); |
---|
2062 | |
---|
2063 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
2064 | |
---|
2065 | } |
---|
2066 | |
---|
2067 | void testFallbackResourceGroup() |
---|
2068 | { |
---|
2069 | // Load all textures from new resource group "Test" |
---|
2070 | ResourceGroupManager::getSingleton().removeResourceLocation("../../../Media/materials/textures"); |
---|
2071 | ResourceGroupManager::getSingleton().removeResourceLocation("../../../Media/models"); |
---|
2072 | ResourceGroupManager::getSingleton().createResourceGroup("Test"); |
---|
2073 | ResourceGroupManager::getSingleton().addResourceLocation("../../../Media/materials/textures", "FileSystem", "Test"); |
---|
2074 | ResourceGroupManager::getSingleton().addResourceLocation("../../../Media/models", "FileSystem", "Test"); |
---|
2075 | |
---|
2076 | // Load a texture from default group (won't be found there, but should fall back) |
---|
2077 | TextureManager::getSingleton().load("dirt01.jpg", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2078 | |
---|
2079 | ResourceGroupManager::getSingleton().unloadUnreferencedResourcesInGroup("Test"); |
---|
2080 | |
---|
2081 | // Add a few robots for fun |
---|
2082 | Entity *ent; |
---|
2083 | for (int i = 0; i < 5; ++i) |
---|
2084 | { |
---|
2085 | ent = mSceneMgr->createEntity("robot" + StringConverter::toString(i), "robot.mesh"); |
---|
2086 | // Add entity to the scene node |
---|
2087 | mSceneMgr->getRootSceneNode()->createChildSceneNode( |
---|
2088 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent); |
---|
2089 | } |
---|
2090 | // Give it a little ambience with lights |
---|
2091 | Light* l; |
---|
2092 | l = mSceneMgr->createLight("BlueLight"); |
---|
2093 | l->setPosition(-200,-80,-100); |
---|
2094 | l->setDiffuseColour(0.5, 0.5, 1.0); |
---|
2095 | |
---|
2096 | l = mSceneMgr->createLight("GreenLight"); |
---|
2097 | l->setPosition(0,0,-100); |
---|
2098 | l->setDiffuseColour(0.5, 1.0, 0.5); |
---|
2099 | |
---|
2100 | // Position the camera |
---|
2101 | mCamera->setPosition(100,50,100); |
---|
2102 | mCamera->lookAt(-50,50,0); |
---|
2103 | |
---|
2104 | } |
---|
2105 | |
---|
2106 | void testGeneratedLOD() |
---|
2107 | { |
---|
2108 | MeshPtr msh1 = (MeshPtr)MeshManager::getSingleton().load("barrel.mesh", |
---|
2109 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2110 | |
---|
2111 | msh1->removeLodLevels(); |
---|
2112 | |
---|
2113 | Mesh::LodDistanceList lodList; |
---|
2114 | lodList.push_back(50); |
---|
2115 | lodList.push_back(100); |
---|
2116 | lodList.push_back(150); |
---|
2117 | lodList.push_back(200); |
---|
2118 | lodList.push_back(250); |
---|
2119 | lodList.push_back(300); |
---|
2120 | |
---|
2121 | msh1->generateLodLevels(lodList, ProgressiveMesh::VRQ_PROPORTIONAL, 0.3); |
---|
2122 | |
---|
2123 | Entity *ent; |
---|
2124 | for (int i = 0; i < 1; ++i) |
---|
2125 | { |
---|
2126 | ent = mSceneMgr->createEntity("tst" + StringConverter::toString(i), "barrel.mesh"); |
---|
2127 | // Add entity to the scene node |
---|
2128 | mSceneMgr->getRootSceneNode()->createChildSceneNode( |
---|
2129 | Vector3(0,0,(i*50)-(5*50/2)))->attachObject(ent); |
---|
2130 | } |
---|
2131 | |
---|
2132 | // Give it a little ambience with lights |
---|
2133 | Light* l; |
---|
2134 | l = mSceneMgr->createLight("BlueLight"); |
---|
2135 | l->setPosition(-200,-80,-100); |
---|
2136 | l->setDiffuseColour(0.5, 0.5, 1.0); |
---|
2137 | |
---|
2138 | l = mSceneMgr->createLight("GreenLight"); |
---|
2139 | l->setPosition(0,0,-100); |
---|
2140 | l->setDiffuseColour(0.5, 1.0, 0.5); |
---|
2141 | |
---|
2142 | // Position the camera |
---|
2143 | mCamera->setPosition(100,50,100); |
---|
2144 | mCamera->lookAt(-50,50,0); |
---|
2145 | |
---|
2146 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
2147 | |
---|
2148 | } |
---|
2149 | |
---|
2150 | void clearSceneSetup() |
---|
2151 | { |
---|
2152 | bool showOctree = true; |
---|
2153 | mSceneMgr->setOption("ShowOctree", &showOctree); |
---|
2154 | |
---|
2155 | // Set ambient light |
---|
2156 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
2157 | |
---|
2158 | // Create a skydome |
---|
2159 | mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
2160 | |
---|
2161 | // Create a light |
---|
2162 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
2163 | // Accept default settings: point light, white diffuse, just set position |
---|
2164 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with |
---|
2165 | // other objects, but I don't |
---|
2166 | l->setPosition(20,80,50); |
---|
2167 | |
---|
2168 | Entity *ent; |
---|
2169 | |
---|
2170 | // Create an entity (the floor) |
---|
2171 | ent = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
2172 | ent->setMaterialName("Examples/RustySteel"); |
---|
2173 | // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2) |
---|
2174 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
2175 | |
---|
2176 | // Add a head, give it it's own node |
---|
2177 | SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2178 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
2179 | headNode->attachObject(ent); |
---|
2180 | |
---|
2181 | // Add another head, give it it's own node |
---|
2182 | SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2183 | ent = mSceneMgr->createEntity("head2", "ogrehead.mesh"); |
---|
2184 | headNode2->attachObject(ent); |
---|
2185 | |
---|
2186 | // Make sure the head node tracks the root |
---|
2187 | headNode->setAutoTracking(true, headNode2, Vector3::UNIT_Z); |
---|
2188 | //headNode->setFixedYawAxis(true); |
---|
2189 | |
---|
2190 | // Create the camera node & attach camera |
---|
2191 | //SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2192 | //camNode->attachObject(mCamera); |
---|
2193 | |
---|
2194 | // set up spline animation of node |
---|
2195 | Animation* anim = mSceneMgr->createAnimation("CameraTrack", 10); |
---|
2196 | // Spline it for nice curves |
---|
2197 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
2198 | // Create a track to animate the head's node |
---|
2199 | NodeAnimationTrack* track = anim->createNodeTrack(0, headNode); |
---|
2200 | // Setup keyframes |
---|
2201 | TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition |
---|
2202 | key = track->createNodeKeyFrame(2.5); |
---|
2203 | key->setTranslate(Vector3(500,500,-1000)); |
---|
2204 | key = track->createNodeKeyFrame(5); |
---|
2205 | key->setTranslate(Vector3(-1500,1000,-600)); |
---|
2206 | key = track->createNodeKeyFrame(7.5); |
---|
2207 | key->setTranslate(Vector3(0,-100,0)); |
---|
2208 | key = track->createNodeKeyFrame(10); |
---|
2209 | key->setTranslate(Vector3(0,0,0)); |
---|
2210 | // Create a track to animate the second head's node |
---|
2211 | track = anim->createNodeTrack(1, headNode2); |
---|
2212 | // Setup keyframes |
---|
2213 | key = track->createNodeKeyFrame(0); // startposition |
---|
2214 | key = track->createNodeKeyFrame(2.5); |
---|
2215 | key->setTranslate(Vector3(-500,600,-100)); |
---|
2216 | key = track->createNodeKeyFrame(5); |
---|
2217 | key->setTranslate(Vector3(800,200,-600)); |
---|
2218 | key = track->createNodeKeyFrame(7.5); |
---|
2219 | key->setTranslate(Vector3(200,-1000,0)); |
---|
2220 | key = track->createNodeKeyFrame(10); |
---|
2221 | key->setTranslate(Vector3(30,70,110)); |
---|
2222 | // Create a new animation state to track this |
---|
2223 | mAnimState = mSceneMgr->createAnimationState("CameraTrack"); |
---|
2224 | mAnimState->setEnabled(true); |
---|
2225 | } |
---|
2226 | class ClearSceneListener : public FrameListener |
---|
2227 | { |
---|
2228 | protected: |
---|
2229 | SceneManager* mSceneMgr; |
---|
2230 | PlayPenApplication* ppApp; |
---|
2231 | |
---|
2232 | public: |
---|
2233 | ClearSceneListener(SceneManager* sm, PlayPenApplication* target) |
---|
2234 | { |
---|
2235 | mSceneMgr = sm; |
---|
2236 | ppApp = target; |
---|
2237 | } |
---|
2238 | bool frameStarted(const FrameEvent& evt) |
---|
2239 | { |
---|
2240 | static Real timeElapsed = 0; |
---|
2241 | |
---|
2242 | timeElapsed += evt.timeSinceLastFrame; |
---|
2243 | if (timeElapsed > 15) |
---|
2244 | { |
---|
2245 | mSceneMgr->clearScene(); |
---|
2246 | ppApp->clearSceneSetup(); |
---|
2247 | timeElapsed = 0; |
---|
2248 | } |
---|
2249 | return true; |
---|
2250 | } |
---|
2251 | }; |
---|
2252 | ClearSceneListener* csListener; |
---|
2253 | void testClearScene() |
---|
2254 | { |
---|
2255 | // Define a floor plane mesh |
---|
2256 | Plane p; |
---|
2257 | p.normal = Vector3::UNIT_Y; |
---|
2258 | p.d = 200; |
---|
2259 | MeshManager::getSingleton().createPlane("FloorPlane", |
---|
2260 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2261 | p,200000,200000,20,20,true,1,50,50,Vector3::UNIT_Z); |
---|
2262 | |
---|
2263 | |
---|
2264 | // leak here I know |
---|
2265 | csListener = new ClearSceneListener(mSceneMgr, this); |
---|
2266 | Root::getSingleton().addFrameListener(csListener); |
---|
2267 | clearSceneSetup(); |
---|
2268 | } |
---|
2269 | |
---|
2270 | void testStencilShadows(ShadowTechnique tech, bool pointLight, bool directionalLight) |
---|
2271 | { |
---|
2272 | mSceneMgr->setShadowTechnique(tech); |
---|
2273 | //mSceneMgr->setShowDebugShadows(true); |
---|
2274 | mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000); |
---|
2275 | //mSceneMgr->setShadowColour(ColourValue(0.4, 0.25, 0.25)); |
---|
2276 | |
---|
2277 | //mSceneMgr->setShadowFarDistance(800); |
---|
2278 | // Set ambient light |
---|
2279 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0)); |
---|
2280 | |
---|
2281 | // Point light |
---|
2282 | if(pointLight) |
---|
2283 | { |
---|
2284 | mLight = mSceneMgr->createLight("MainLight"); |
---|
2285 | mLight->setPosition(-400,400,-300); |
---|
2286 | mLight->setDiffuseColour(0.9, 0.9, 1); |
---|
2287 | mLight->setSpecularColour(0.9, 0.9, 1); |
---|
2288 | mLight->setAttenuation(6000,1,0.001,0); |
---|
2289 | } |
---|
2290 | // Directional light |
---|
2291 | if (directionalLight) |
---|
2292 | { |
---|
2293 | mLight = mSceneMgr->createLight("Light2"); |
---|
2294 | Vector3 dir(-1,-1,0); |
---|
2295 | dir.normalise(); |
---|
2296 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
2297 | mLight->setDirection(dir); |
---|
2298 | mLight->setDiffuseColour(1, 1, 0.8); |
---|
2299 | mLight->setSpecularColour(1, 1, 1); |
---|
2300 | } |
---|
2301 | |
---|
2302 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2303 | |
---|
2304 | // Hardware skin |
---|
2305 | Entity* pEnt; |
---|
2306 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" ); |
---|
2307 | AnimationState* anim = pEnt->getAnimationState("Walk"); |
---|
2308 | anim->setEnabled(true); |
---|
2309 | mAnimStateList.push_back(anim); |
---|
2310 | mTestNode[0]->attachObject( pEnt ); |
---|
2311 | |
---|
2312 | // Software skin |
---|
2313 | pEnt = mSceneMgr->createEntity( "12", "robot.mesh" ); |
---|
2314 | anim = pEnt->getAnimationState("Walk"); |
---|
2315 | anim->setEnabled(true); |
---|
2316 | mAnimStateList.push_back(anim); |
---|
2317 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 0))->attachObject(pEnt); |
---|
2318 | pEnt->setMaterialName("Examples/Rocky"); |
---|
2319 | |
---|
2320 | // test object |
---|
2321 | //pEnt = mSceneMgr->createEntity("tst", "building.mesh"); |
---|
2322 | //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(300, 0, 0))->attachObject(pEnt); |
---|
2323 | |
---|
2324 | |
---|
2325 | // Does not receive shadows |
---|
2326 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" ); |
---|
2327 | pEnt->setMaterialName("Examples/EnvMappedRustySteel"); |
---|
2328 | MaterialPtr mat2 = MaterialManager::getSingleton().getByName("Examples/EnvMappedRustySteel"); |
---|
2329 | mat2->setReceiveShadows(false); |
---|
2330 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200)); |
---|
2331 | mTestNode[2]->attachObject( pEnt ); |
---|
2332 | |
---|
2333 | // Transparent object |
---|
2334 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" ); |
---|
2335 | pEnt->setMaterialName("Examples/TransparentTest"); |
---|
2336 | MaterialPtr mat3 = MaterialManager::getSingleton().getByName("Examples/TransparentTest"); |
---|
2337 | pEnt->setCastShadows(false); |
---|
2338 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200)); |
---|
2339 | mTestNode[3]->attachObject( pEnt ); |
---|
2340 | |
---|
2341 | // User test |
---|
2342 | /* |
---|
2343 | pEnt = mSceneMgr->createEntity( "3.6", "ogre_male_endCaps.mesh" ); |
---|
2344 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0, 0, 100))->attachObject( pEnt ); |
---|
2345 | */ |
---|
2346 | |
---|
2347 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", |
---|
2348 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2349 | unsigned short src, dest; |
---|
2350 | if (!msh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) |
---|
2351 | { |
---|
2352 | msh->buildTangentVectors(VES_TANGENT, src, dest); |
---|
2353 | } |
---|
2354 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" ); |
---|
2355 | pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular"); |
---|
2356 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200)); |
---|
2357 | mTestNode[2]->attachObject( pEnt ); |
---|
2358 | |
---|
2359 | // controller based material |
---|
2360 | pEnt = mSceneMgr->createEntity( "432", "knot.mesh" ); |
---|
2361 | pEnt->setMaterialName("Examples/TextureEffect2"); |
---|
2362 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 200, 200))->attachObject( pEnt ); |
---|
2363 | |
---|
2364 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke", |
---|
2365 | "Examples/Smoke"); |
---|
2366 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200)); |
---|
2367 | mTestNode[4]->attachObject(pSys2); |
---|
2368 | |
---|
2369 | |
---|
2370 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
2371 | |
---|
2372 | |
---|
2373 | Plane plane; |
---|
2374 | plane.normal = Vector3::UNIT_Y; |
---|
2375 | plane.d = 100; |
---|
2376 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2377 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
2378 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
2379 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2380 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2381 | pPlaneEnt->setCastShadows(false); |
---|
2382 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2383 | |
---|
2384 | mCamera->setPosition(180, 34, 223); |
---|
2385 | mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791)); |
---|
2386 | |
---|
2387 | // Create a render texture |
---|
2388 | TexturePtr rtt = TextureManager::getSingleton().createManual("rtt0", |
---|
2389 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2390 | TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET); |
---|
2391 | rtt->getBuffer()->getRenderTarget()->addViewport(mCamera); |
---|
2392 | // Create an overlay showing the rtt |
---|
2393 | MaterialPtr debugMat = MaterialManager::getSingleton().create( |
---|
2394 | "DebugRTT", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2395 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
2396 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("rtt0"); |
---|
2397 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
2398 | OverlayContainer* debugPanel = (OverlayContainer*) |
---|
2399 | (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel")); |
---|
2400 | debugPanel->_setPosition(0.6, 0); |
---|
2401 | debugPanel->_setDimensions(0.4, 0.6); |
---|
2402 | debugPanel->setMaterialName("DebugRTT"); |
---|
2403 | Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); |
---|
2404 | debugOverlay->add2D(debugPanel); |
---|
2405 | |
---|
2406 | |
---|
2407 | } |
---|
2408 | |
---|
2409 | void testStencilShadowsMixedOpSubMeshes(bool pointLight, bool directionalLight) |
---|
2410 | { |
---|
2411 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE); |
---|
2412 | //mSceneMgr->setShowDebugShadows(true); |
---|
2413 | mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000); |
---|
2414 | |
---|
2415 | //mSceneMgr->setShadowFarDistance(800); |
---|
2416 | // Set ambient light |
---|
2417 | mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0)); |
---|
2418 | |
---|
2419 | // Point light |
---|
2420 | if(pointLight) |
---|
2421 | { |
---|
2422 | mLight = mSceneMgr->createLight("MainLight"); |
---|
2423 | mLight->setPosition(-400,400,-300); |
---|
2424 | mLight->setDiffuseColour(0.9, 0.9, 1); |
---|
2425 | mLight->setSpecularColour(0.9, 0.9, 1); |
---|
2426 | mLight->setAttenuation(6000,1,0.001,0); |
---|
2427 | } |
---|
2428 | // Directional light |
---|
2429 | if (directionalLight) |
---|
2430 | { |
---|
2431 | mLight = mSceneMgr->createLight("Light2"); |
---|
2432 | Vector3 dir(-1,-1,0); |
---|
2433 | dir.normalise(); |
---|
2434 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
2435 | mLight->setDirection(dir); |
---|
2436 | mLight->setDiffuseColour(1, 1, 0.8); |
---|
2437 | mLight->setSpecularColour(1, 1, 1); |
---|
2438 | } |
---|
2439 | |
---|
2440 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
2441 | |
---|
2442 | |
---|
2443 | Plane plane; |
---|
2444 | plane.normal = Vector3::UNIT_Y; |
---|
2445 | plane.d = 100; |
---|
2446 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2447 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
2448 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
2449 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2450 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2451 | pPlaneEnt->setCastShadows(false); |
---|
2452 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2453 | |
---|
2454 | mCamera->setPosition(180, 34, 223); |
---|
2455 | mCamera->setOrientation(Quaternion(0.7265, -0.2064, 0.6304, 0.1791)); |
---|
2456 | |
---|
2457 | |
---|
2458 | ManualObject* man = mSceneMgr->createManualObject("testMO"); |
---|
2459 | man->begin("2 - Default"); |
---|
2460 | man->position(0, 200, 0); |
---|
2461 | man->position(0, 50, 100); |
---|
2462 | man->position(100, 50, -100); |
---|
2463 | man->position(-100, 50, -100); |
---|
2464 | man->triangle(0, 1, 2); |
---|
2465 | man->triangle(0, 2, 3); |
---|
2466 | man->triangle(0, 3, 1); |
---|
2467 | man->end(); |
---|
2468 | man->begin("2 - Default", RenderOperation::OT_LINE_STRIP); |
---|
2469 | man->position(0, 200, 0); |
---|
2470 | man->position(50, 250, 0); |
---|
2471 | man->position(200, 300, 0); |
---|
2472 | man->index(0); |
---|
2473 | man->index(1); |
---|
2474 | man->index(2); |
---|
2475 | man->end(); |
---|
2476 | MeshPtr msh = man->convertToMesh("testMO.mesh"); |
---|
2477 | |
---|
2478 | Entity* e = mSceneMgr->createEntity("34", "testMO.mesh"); |
---|
2479 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
2480 | |
---|
2481 | |
---|
2482 | |
---|
2483 | } |
---|
2484 | void test2Spotlights() |
---|
2485 | { |
---|
2486 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); |
---|
2487 | |
---|
2488 | mLight = mSceneMgr->createLight("MainLight"); |
---|
2489 | // Spotlight test |
---|
2490 | mLight->setType(Light::LT_SPOTLIGHT); |
---|
2491 | mLight->setDiffuseColour(1.0, 0.0, 0.8); |
---|
2492 | mLight->setSpotlightRange(Degree(30), Degree(40)); |
---|
2493 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2494 | mTestNode[0]->setPosition(800,600,0); |
---|
2495 | mTestNode[0]->lookAt(Vector3(800,0,0), Node::TS_WORLD, Vector3::UNIT_Z); |
---|
2496 | mTestNode[0]->attachObject(mLight); |
---|
2497 | |
---|
2498 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2499 | mLight = mSceneMgr->createLight("AnotherLight"); |
---|
2500 | // Spotlight test |
---|
2501 | mLight->setType(Light::LT_SPOTLIGHT); |
---|
2502 | mLight->setDiffuseColour(0, 1.0, 0.8); |
---|
2503 | mLight->setSpotlightRange(Degree(30), Degree(40)); |
---|
2504 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2505 | mTestNode[1]->setPosition(0,600,800); |
---|
2506 | mTestNode[1]->lookAt(Vector3(0,0,800), Node::TS_WORLD, Vector3::UNIT_Z); |
---|
2507 | mTestNode[1]->attachObject(mLight); |
---|
2508 | |
---|
2509 | |
---|
2510 | Plane plane; |
---|
2511 | plane.normal = Vector3::UNIT_Y; |
---|
2512 | plane.d = 100; |
---|
2513 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2514 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
2515 | 3500,3500,100,100,true,1,5,5,Vector3::UNIT_Z); |
---|
2516 | Entity* pPlaneEnt; |
---|
2517 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2518 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2519 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2520 | |
---|
2521 | } |
---|
2522 | |
---|
2523 | void addTextureShadowDebugOverlay(size_t num) |
---|
2524 | { |
---|
2525 | Overlay* debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); |
---|
2526 | |
---|
2527 | for (size_t i = 0; i < num; ++i) |
---|
2528 | { |
---|
2529 | // Set up a debug panel to display the shadow |
---|
2530 | MaterialPtr debugMat = MaterialManager::getSingleton().create( |
---|
2531 | "Ogre/DebugShadowMap" + StringConverter::toString(i), |
---|
2532 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2533 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
2534 | TexturePtr shadowTex = mSceneMgr->getShadowTexture(i); |
---|
2535 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(shadowTex->getName()); |
---|
2536 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
2537 | //t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("spot_shadow_fade.png"); |
---|
2538 | //t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
2539 | //t->setColourOperation(LBO_ADD); |
---|
2540 | |
---|
2541 | OverlayContainer* debugPanel = (OverlayContainer*) |
---|
2542 | (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugShadowPanel" + StringConverter::toString(i))); |
---|
2543 | debugPanel->_setPosition(0.8, i*0.3); |
---|
2544 | debugPanel->_setDimensions(0.2, 0.28); |
---|
2545 | debugPanel->setMaterialName(debugMat->getName()); |
---|
2546 | debugOverlay->add2D(debugPanel); |
---|
2547 | |
---|
2548 | } |
---|
2549 | |
---|
2550 | } |
---|
2551 | |
---|
2552 | |
---|
2553 | void testTextureShadows(ShadowTechnique tech) |
---|
2554 | { |
---|
2555 | mSceneMgr->setShadowTextureSize(1024); |
---|
2556 | mSceneMgr->setShadowTechnique(tech); |
---|
2557 | |
---|
2558 | FocusedShadowCameraSetup* lispsmSetup = new FocusedShadowCameraSetup(); |
---|
2559 | //lispsmSetup->setOptimalAdjustFactor(2); |
---|
2560 | mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(lispsmSetup)); |
---|
2561 | |
---|
2562 | mSceneMgr->setShadowFarDistance(10000); |
---|
2563 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35)); |
---|
2564 | //mSceneMgr->setShadowFarDistance(800); |
---|
2565 | // Set ambient light |
---|
2566 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); |
---|
2567 | |
---|
2568 | mLight = mSceneMgr->createLight("MainLight"); |
---|
2569 | |
---|
2570 | |
---|
2571 | // Directional test |
---|
2572 | |
---|
2573 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
2574 | Vector3 vec(-1,-1,0); |
---|
2575 | vec.normalise(); |
---|
2576 | mLight->setDirection(vec); |
---|
2577 | |
---|
2578 | |
---|
2579 | // Spotlight test |
---|
2580 | /* |
---|
2581 | mLight->setType(Light::LT_SPOTLIGHT); |
---|
2582 | mLight->setDiffuseColour(1.0, 1.0, 0.8); |
---|
2583 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2584 | mTestNode[0]->setPosition(800,600,0); |
---|
2585 | mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD, Vector3::UNIT_Z); |
---|
2586 | mTestNode[0]->attachObject(mLight); |
---|
2587 | */ |
---|
2588 | |
---|
2589 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2590 | |
---|
2591 | |
---|
2592 | Entity* pEnt; |
---|
2593 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" ); |
---|
2594 | //pEnt->setRenderingDistance(100); |
---|
2595 | mAnimState = pEnt->getAnimationState("Walk"); |
---|
2596 | mAnimState->setEnabled(true); |
---|
2597 | //pEnt->setMaterialName("2 - Default"); |
---|
2598 | mTestNode[1]->attachObject( pEnt ); |
---|
2599 | mTestNode[1]->translate(0,-100,0); |
---|
2600 | |
---|
2601 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" ); |
---|
2602 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200)); |
---|
2603 | mTestNode[2]->attachObject( pEnt ); |
---|
2604 | |
---|
2605 | createRandomEntityClones(pEnt, 20, Vector3(-1000,0,-1000), Vector3(1000,0,1000)); |
---|
2606 | |
---|
2607 | |
---|
2608 | // Transparent object (can force cast shadows) |
---|
2609 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" ); |
---|
2610 | MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency", |
---|
2611 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2612 | tmat->setTransparencyCastsShadows(true); |
---|
2613 | Pass* tpass = tmat->getTechnique(0)->getPass(0); |
---|
2614 | tpass->setAlphaRejectSettings(CMPF_GREATER, 150); |
---|
2615 | tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
2616 | tpass->createTextureUnitState("gras_02.png"); |
---|
2617 | tpass->setCullingMode(CULL_NONE); |
---|
2618 | |
---|
2619 | pEnt->setMaterialName("TestAlphaTransparency"); |
---|
2620 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200)); |
---|
2621 | mTestNode[3]->attachObject( pEnt ); |
---|
2622 | |
---|
2623 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", |
---|
2624 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2625 | msh->buildTangentVectors(VES_TANGENT, 0, 0); |
---|
2626 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" ); |
---|
2627 | //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular"); |
---|
2628 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200)); |
---|
2629 | mTestNode[2]->attachObject( pEnt ); |
---|
2630 | |
---|
2631 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
2632 | |
---|
2633 | |
---|
2634 | |
---|
2635 | movablePlane.normal = Vector3::UNIT_Y; |
---|
2636 | movablePlane.d = 100; |
---|
2637 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2638 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, movablePlane, |
---|
2639 | 2500,2500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
2640 | Entity* pPlaneEnt; |
---|
2641 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2642 | if (tech & SHADOWDETAILTYPE_INTEGRATED) |
---|
2643 | { |
---|
2644 | pPlaneEnt->setMaterialName("Examples/Plane/IntegratedShadows"); |
---|
2645 | } |
---|
2646 | else |
---|
2647 | { |
---|
2648 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2649 | } |
---|
2650 | pPlaneEnt->setCastShadows(false); |
---|
2651 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2652 | |
---|
2653 | addTextureShadowDebugOverlay(1); |
---|
2654 | |
---|
2655 | |
---|
2656 | /* |
---|
2657 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke", |
---|
2658 | "Examples/Smoke"); |
---|
2659 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200)); |
---|
2660 | mTestNode[4]->attachObject(pSys2); |
---|
2661 | */ |
---|
2662 | |
---|
2663 | mCamera->setPosition(0, 1000, 0); |
---|
2664 | mCamera->setFixedYawAxis(false); |
---|
2665 | mCamera->lookAt(0,0,0); |
---|
2666 | |
---|
2667 | |
---|
2668 | } |
---|
2669 | |
---|
2670 | void testTextureShadowsCustomCasterMat(ShadowTechnique tech) |
---|
2671 | { |
---|
2672 | |
---|
2673 | testTextureShadows(tech); |
---|
2674 | |
---|
2675 | String customCasterMatVp = |
---|
2676 | "void customCasterVp(float4 position : POSITION,\n" |
---|
2677 | "out float4 oPosition : POSITION,\n" |
---|
2678 | "uniform float4x4 worldViewProj)\n" |
---|
2679 | "{\n" |
---|
2680 | " oPosition = mul(worldViewProj, position);\n" |
---|
2681 | "}\n"; |
---|
2682 | String customCasterMatFp = |
---|
2683 | "void customCasterFp(\n" |
---|
2684 | "out float4 oColor : COLOR)\n" |
---|
2685 | "{\n" |
---|
2686 | " oColor = float4(1,1,0,1); // just a test\n" |
---|
2687 | "}\n"; |
---|
2688 | |
---|
2689 | HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton() |
---|
2690 | .createProgram("CustomShadowCasterVp", |
---|
2691 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2692 | "cg", GPT_VERTEX_PROGRAM); |
---|
2693 | vp->setSource(customCasterMatVp); |
---|
2694 | vp->setParameter("profiles", "vs_1_1 arbvp1"); |
---|
2695 | vp->setParameter("entry_point", "customCasterVp"); |
---|
2696 | vp->load(); |
---|
2697 | |
---|
2698 | HighLevelGpuProgramPtr fp = HighLevelGpuProgramManager::getSingleton() |
---|
2699 | .createProgram("CustomShadowCasterFp", |
---|
2700 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2701 | "cg", GPT_FRAGMENT_PROGRAM); |
---|
2702 | fp->setSource(customCasterMatFp); |
---|
2703 | fp->setParameter("profiles", "ps_1_1 arbfp1"); |
---|
2704 | fp->setParameter("entry_point", "customCasterFp"); |
---|
2705 | fp->load(); |
---|
2706 | |
---|
2707 | MaterialPtr mat = MaterialManager::getSingleton().create("CustomShadowCaster", |
---|
2708 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2709 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
2710 | p->setVertexProgram("CustomShadowCasterVp"); |
---|
2711 | p->getVertexProgramParameters()->setNamedAutoConstant( |
---|
2712 | "worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); |
---|
2713 | p->setFragmentProgram("CustomShadowCasterFp"); |
---|
2714 | |
---|
2715 | mSceneMgr->setShadowTextureCasterMaterial("CustomShadowCaster"); |
---|
2716 | |
---|
2717 | |
---|
2718 | |
---|
2719 | |
---|
2720 | |
---|
2721 | } |
---|
2722 | |
---|
2723 | void testTextureShadowsCustomReceiverMat(ShadowTechnique tech) |
---|
2724 | { |
---|
2725 | testTextureShadows(tech); |
---|
2726 | |
---|
2727 | String customReceiverMatVp = |
---|
2728 | "void customReceiverVp(float4 position : POSITION,\n" |
---|
2729 | "out float4 oPosition : POSITION,\n" |
---|
2730 | "out float2 oUV : TEXCOORD0,\n" |
---|
2731 | "uniform float4x4 texViewProj,\n" |
---|
2732 | "uniform float4x4 worldViewProj)\n" |
---|
2733 | "{\n" |
---|
2734 | " oPosition = mul(worldViewProj, position);\n" |
---|
2735 | " float4 suv = mul(texViewProj, position);\n" |
---|
2736 | " oUV = suv.xy / suv.w;\n" |
---|
2737 | "}\n"; |
---|
2738 | String customReceiverMatFp = |
---|
2739 | "void customReceiverFp(\n" |
---|
2740 | "float2 uv : TEXCOORD0,\n" |
---|
2741 | "uniform sampler2D shadowTex : register(s0),\n" |
---|
2742 | "out float4 oColor : COLOR)\n" |
---|
2743 | "{\n" |
---|
2744 | " float4 shadow = tex2D(shadowTex, uv);\n" |
---|
2745 | " oColor = shadow * float4(1,0,1,1); // just a test\n" |
---|
2746 | "}\n"; |
---|
2747 | |
---|
2748 | HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton() |
---|
2749 | .createProgram("CustomShadowReceiverVp", |
---|
2750 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2751 | "cg", GPT_VERTEX_PROGRAM); |
---|
2752 | vp->setSource(customReceiverMatVp); |
---|
2753 | vp->setParameter("profiles", "vs_1_1 arbvp1"); |
---|
2754 | vp->setParameter("entry_point", "customReceiverVp"); |
---|
2755 | vp->load(); |
---|
2756 | |
---|
2757 | HighLevelGpuProgramPtr fp = HighLevelGpuProgramManager::getSingleton() |
---|
2758 | .createProgram("CustomShadowReceiverFp", |
---|
2759 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
2760 | "cg", GPT_FRAGMENT_PROGRAM); |
---|
2761 | fp->setSource(customReceiverMatFp); |
---|
2762 | fp->setParameter("profiles", "ps_1_1 arbfp1"); |
---|
2763 | fp->setParameter("entry_point", "customReceiverFp"); |
---|
2764 | fp->load(); |
---|
2765 | |
---|
2766 | MaterialPtr mat = MaterialManager::getSingleton().create("CustomShadowReceiver", |
---|
2767 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2768 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
2769 | p->setVertexProgram("CustomShadowReceiverVp"); |
---|
2770 | p->getVertexProgramParameters()->setNamedAutoConstant( |
---|
2771 | "worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); |
---|
2772 | p->getVertexProgramParameters()->setNamedAutoConstant( |
---|
2773 | "texViewProj", GpuProgramParameters::ACT_TEXTURE_VIEWPROJ_MATRIX); |
---|
2774 | p->setFragmentProgram("CustomShadowReceiverFp"); |
---|
2775 | p->createTextureUnitState(); // shadow texture will populate |
---|
2776 | |
---|
2777 | mSceneMgr->setShadowTextureReceiverMaterial("CustomShadowReceiver"); |
---|
2778 | |
---|
2779 | |
---|
2780 | |
---|
2781 | } |
---|
2782 | |
---|
2783 | |
---|
2784 | //--------------------------------------------------------------------------- |
---|
2785 | class GaussianListener: public Ogre::CompositorInstance::Listener |
---|
2786 | { |
---|
2787 | protected: |
---|
2788 | int mVpWidth, mVpHeight; |
---|
2789 | // Array params - have to pack in groups of 4 since this is how Cg generates them |
---|
2790 | // also prevents dependent texture read problems if ops don't require swizzle |
---|
2791 | float mBloomTexWeights[15][4]; |
---|
2792 | float mBloomTexOffsetsHorz[15][4]; |
---|
2793 | float mBloomTexOffsetsVert[15][4]; |
---|
2794 | public: |
---|
2795 | GaussianListener() {} |
---|
2796 | virtual ~GaussianListener() {} |
---|
2797 | void notifyViewportSize(int width, int height) |
---|
2798 | { |
---|
2799 | mVpWidth = width; |
---|
2800 | mVpHeight = height; |
---|
2801 | // Calculate gaussian texture offsets & weights |
---|
2802 | float deviation = 3.0f; |
---|
2803 | float texelSize = 1.0f / (float)std::min(mVpWidth, mVpHeight); |
---|
2804 | |
---|
2805 | // central sample, no offset |
---|
2806 | mBloomTexOffsetsHorz[0][0] = 0.0f; |
---|
2807 | mBloomTexOffsetsHorz[0][1] = 0.0f; |
---|
2808 | mBloomTexWeights[0][0] = mBloomTexWeights[0][1] = |
---|
2809 | mBloomTexWeights[0][2] = Ogre::Math::gaussianDistribution(0, 0, deviation); |
---|
2810 | mBloomTexWeights[0][3] = 1.0f; |
---|
2811 | |
---|
2812 | // 'pre' samples |
---|
2813 | for(int i = 1; i < 8; ++i) |
---|
2814 | { |
---|
2815 | mBloomTexWeights[i][0] = mBloomTexWeights[i][1] = |
---|
2816 | mBloomTexWeights[i][2] = Ogre::Math::gaussianDistribution(i, 0, deviation); |
---|
2817 | mBloomTexWeights[i][3] = 1.0f; |
---|
2818 | mBloomTexOffsetsHorz[i][0] = i * texelSize; |
---|
2819 | mBloomTexOffsetsHorz[i][1] = 0.0f; |
---|
2820 | mBloomTexOffsetsVert[i][0] = 0.0f; |
---|
2821 | mBloomTexOffsetsVert[i][1] = i * texelSize; |
---|
2822 | } |
---|
2823 | // 'post' samples |
---|
2824 | for(int i = 8; i < 15; ++i) |
---|
2825 | { |
---|
2826 | mBloomTexWeights[i][0] = mBloomTexWeights[i][1] = |
---|
2827 | mBloomTexWeights[i][2] = mBloomTexWeights[i - 7][0]; |
---|
2828 | mBloomTexWeights[i][3] = 1.0f; |
---|
2829 | |
---|
2830 | mBloomTexOffsetsHorz[i][0] = -mBloomTexOffsetsHorz[i - 7][0]; |
---|
2831 | mBloomTexOffsetsHorz[i][1] = 0.0f; |
---|
2832 | mBloomTexOffsetsVert[i][0] = 0.0f; |
---|
2833 | mBloomTexOffsetsVert[i][1] = -mBloomTexOffsetsVert[i - 7][1]; |
---|
2834 | } |
---|
2835 | |
---|
2836 | } |
---|
2837 | virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat) |
---|
2838 | { |
---|
2839 | // Prepare the fragment params offsets |
---|
2840 | switch(pass_id) |
---|
2841 | { |
---|
2842 | case 701: // blur horz |
---|
2843 | { |
---|
2844 | // horizontal bloom |
---|
2845 | mat->load(); |
---|
2846 | Ogre::GpuProgramParametersSharedPtr fparams = |
---|
2847 | mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters(); |
---|
2848 | const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName(); |
---|
2849 | fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsHorz[0], 15); |
---|
2850 | fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15); |
---|
2851 | |
---|
2852 | break; |
---|
2853 | } |
---|
2854 | case 700: // blur vert |
---|
2855 | { |
---|
2856 | // vertical bloom |
---|
2857 | mat->load(); |
---|
2858 | Ogre::GpuProgramParametersSharedPtr fparams = |
---|
2859 | mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters(); |
---|
2860 | const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName(); |
---|
2861 | fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15); |
---|
2862 | fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15); |
---|
2863 | |
---|
2864 | break; |
---|
2865 | } |
---|
2866 | } |
---|
2867 | |
---|
2868 | } |
---|
2869 | virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat) |
---|
2870 | { |
---|
2871 | |
---|
2872 | } |
---|
2873 | }; |
---|
2874 | GaussianListener gaussianListener; |
---|
2875 | |
---|
2876 | void testCompositorTextureShadows(ShadowTechnique tech) |
---|
2877 | { |
---|
2878 | mSceneMgr->setShadowTextureSize(512); |
---|
2879 | mSceneMgr->setShadowTechnique(tech); |
---|
2880 | mSceneMgr->setShadowFarDistance(1500); |
---|
2881 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35)); |
---|
2882 | //mSceneMgr->setShadowFarDistance(800); |
---|
2883 | // Set ambient light |
---|
2884 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); |
---|
2885 | |
---|
2886 | mLight = mSceneMgr->createLight("MainLight"); |
---|
2887 | |
---|
2888 | /* |
---|
2889 | // Directional test |
---|
2890 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
2891 | Vector3 vec(-1,-1,0); |
---|
2892 | vec.normalise(); |
---|
2893 | mLight->setDirection(vec); |
---|
2894 | |
---|
2895 | */ |
---|
2896 | // Spotlight test |
---|
2897 | mLight->setType(Light::LT_SPOTLIGHT); |
---|
2898 | mLight->setDiffuseColour(1.0, 1.0, 0.8); |
---|
2899 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2900 | mTestNode[0]->setPosition(800,600,0); |
---|
2901 | mTestNode[0]->lookAt(Vector3(0,0,0), Node::TS_WORLD, Vector3::UNIT_Z); |
---|
2902 | mTestNode[0]->attachObject(mLight); |
---|
2903 | |
---|
2904 | |
---|
2905 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
2906 | |
---|
2907 | |
---|
2908 | Entity* pEnt; |
---|
2909 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" ); |
---|
2910 | //pEnt->setRenderingDistance(100); |
---|
2911 | mAnimState = pEnt->getAnimationState("Walk"); |
---|
2912 | mAnimState->setEnabled(true); |
---|
2913 | //pEnt->setMaterialName("2 - Default"); |
---|
2914 | mTestNode[1]->attachObject( pEnt ); |
---|
2915 | mTestNode[1]->translate(0,-100,0); |
---|
2916 | |
---|
2917 | pEnt = mSceneMgr->createEntity( "3", "knot.mesh" ); |
---|
2918 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-200, 0, -200)); |
---|
2919 | mTestNode[2]->attachObject( pEnt ); |
---|
2920 | |
---|
2921 | // Transparent object (can force cast shadows) |
---|
2922 | pEnt = mSceneMgr->createEntity( "3.5", "knot.mesh" ); |
---|
2923 | MaterialPtr tmat = MaterialManager::getSingleton().create("TestAlphaTransparency", |
---|
2924 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2925 | tmat->setTransparencyCastsShadows(true); |
---|
2926 | Pass* tpass = tmat->getTechnique(0)->getPass(0); |
---|
2927 | tpass->setAlphaRejectSettings(CMPF_GREATER, 150); |
---|
2928 | tpass->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
2929 | tpass->createTextureUnitState("gras_02.png"); |
---|
2930 | tpass->setCullingMode(CULL_NONE); |
---|
2931 | |
---|
2932 | pEnt->setMaterialName("TestAlphaTransparency"); |
---|
2933 | mTestNode[3] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(350, 0, -200)); |
---|
2934 | mTestNode[3]->attachObject( pEnt ); |
---|
2935 | |
---|
2936 | MeshPtr msh = MeshManager::getSingleton().load("knot.mesh", |
---|
2937 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
2938 | msh->buildTangentVectors(VES_TANGENT, 0, 0); |
---|
2939 | pEnt = mSceneMgr->createEntity( "4", "knot.mesh" ); |
---|
2940 | //pEnt->setMaterialName("Examples/BumpMapping/MultiLightSpecular"); |
---|
2941 | mTestNode[2] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100, 0, 200)); |
---|
2942 | mTestNode[2]->attachObject( pEnt ); |
---|
2943 | |
---|
2944 | mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); |
---|
2945 | |
---|
2946 | |
---|
2947 | Plane plane; |
---|
2948 | plane.normal = Vector3::UNIT_Y; |
---|
2949 | plane.d = 100; |
---|
2950 | MeshManager::getSingleton().createPlane("Myplane", |
---|
2951 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
2952 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
2953 | Entity* pPlaneEnt; |
---|
2954 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
2955 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
2956 | pPlaneEnt->setCastShadows(false); |
---|
2957 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
2958 | |
---|
2959 | // Set up a debug panel to display the shadow |
---|
2960 | addTextureShadowDebugOverlay(1); |
---|
2961 | |
---|
2962 | |
---|
2963 | |
---|
2964 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("smoke", |
---|
2965 | "Examples/Smoke"); |
---|
2966 | mTestNode[4] = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-300, -100, 200)); |
---|
2967 | mTestNode[4]->attachObject(pSys2); |
---|
2968 | |
---|
2969 | TexturePtr shadowTex = mSceneMgr->getShadowTexture(0); |
---|
2970 | RenderTarget* shadowRtt = shadowTex->getBuffer()->getRenderTarget(); |
---|
2971 | Viewport* vp = shadowRtt->getViewport(0); |
---|
2972 | Ogre::CompositorInstance *instance = |
---|
2973 | CompositorManager::getSingleton().addCompositor(vp, "Gaussian Blur"); |
---|
2974 | CompositorManager::getSingleton().setCompositorEnabled( |
---|
2975 | vp, "Gaussian Blur", true); |
---|
2976 | instance->addListener(&gaussianListener); |
---|
2977 | gaussianListener.notifyViewportSize(vp->getActualWidth(), vp->getActualHeight()); |
---|
2978 | |
---|
2979 | |
---|
2980 | |
---|
2981 | |
---|
2982 | |
---|
2983 | } |
---|
2984 | |
---|
2985 | void testOverlayZOrder(void) |
---|
2986 | { |
---|
2987 | Overlay* o = OverlayManager::getSingleton().getByName("Test/Overlay3"); |
---|
2988 | o->show(); |
---|
2989 | o = OverlayManager::getSingleton().getByName("Test/Overlay2"); |
---|
2990 | o->show(); |
---|
2991 | o = OverlayManager::getSingleton().getByName("Test/Overlay1"); |
---|
2992 | o->show(); |
---|
2993 | } |
---|
2994 | |
---|
2995 | void createRandomEntityClones(Entity* ent, size_t cloneCount, |
---|
2996 | const Vector3& min, const Vector3& max) |
---|
2997 | { |
---|
2998 | Entity *cloneEnt; |
---|
2999 | for (size_t n = 0; n < cloneCount; ++n) |
---|
3000 | { |
---|
3001 | // Create a new node under the root |
---|
3002 | SceneNode* node = mSceneMgr->createSceneNode(); |
---|
3003 | // Random translate |
---|
3004 | Vector3 nodePos; |
---|
3005 | nodePos.x = Math::RangeRandom(min.x, max.x); |
---|
3006 | nodePos.y = Math::RangeRandom(min.y, max.y); |
---|
3007 | nodePos.z = Math::RangeRandom(min.z, max.z); |
---|
3008 | node->setPosition(nodePos); |
---|
3009 | mSceneMgr->getRootSceneNode()->addChild(node); |
---|
3010 | cloneEnt = ent->clone(ent->getName() + "_clone" + StringConverter::toString(n)); |
---|
3011 | // Attach to new node |
---|
3012 | node->attachObject(cloneEnt); |
---|
3013 | |
---|
3014 | } |
---|
3015 | } |
---|
3016 | |
---|
3017 | void testIntersectionSceneQuery() |
---|
3018 | { |
---|
3019 | // Set ambient light |
---|
3020 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3021 | |
---|
3022 | // Create a point light |
---|
3023 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3024 | l->setType(Light::LT_DIRECTIONAL); |
---|
3025 | l->setDirection(-Vector3::UNIT_Y); |
---|
3026 | |
---|
3027 | // Create a set of random balls |
---|
3028 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh"); |
---|
3029 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3030 | createRandomEntityClones(ent, 500, Vector3(-5000,-5000,-5000), Vector3(5000,5000,5000)); |
---|
3031 | |
---|
3032 | intersectionQuery = mSceneMgr->createIntersectionQuery(); |
---|
3033 | } |
---|
3034 | |
---|
3035 | void testRaySceneQuery() |
---|
3036 | { |
---|
3037 | // Set ambient light |
---|
3038 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3039 | |
---|
3040 | // Create a point light |
---|
3041 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3042 | l->setType(Light::LT_DIRECTIONAL); |
---|
3043 | l->setDirection(-Vector3::UNIT_Y); |
---|
3044 | |
---|
3045 | // Create a set of random balls |
---|
3046 | Entity* ent = mSceneMgr->createEntity("Ball", "sphere.mesh"); |
---|
3047 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3048 | createRandomEntityClones(ent, 100, Vector3(-1000,-1000,-1000), Vector3(1000,1000,1000)); |
---|
3049 | |
---|
3050 | rayQuery = mSceneMgr->createRayQuery( |
---|
3051 | mCamera->getCameraToViewportRay(0.5, 0.5)); |
---|
3052 | rayQuery->setSortByDistance(true, 1); |
---|
3053 | |
---|
3054 | bool val = true; |
---|
3055 | mSceneMgr->setOption("ShowOctree", &val); |
---|
3056 | |
---|
3057 | //mCamera->setFarClipDistance(0); |
---|
3058 | |
---|
3059 | } |
---|
3060 | |
---|
3061 | void testLotsAndLotsOfEntities() |
---|
3062 | { |
---|
3063 | // Set ambient light |
---|
3064 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3065 | |
---|
3066 | // Create a point light |
---|
3067 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3068 | l->setType(Light::LT_DIRECTIONAL); |
---|
3069 | l->setDirection(-Vector3::UNIT_Y); |
---|
3070 | |
---|
3071 | // Create a set of random balls |
---|
3072 | Entity* ent = mSceneMgr->createEntity("Ball", "ogrehead.mesh"); |
---|
3073 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3074 | createRandomEntityClones(ent, 400, Vector3(-2000,-2000,-2000), Vector3(2000,2000,2000)); |
---|
3075 | |
---|
3076 | //bool val = true; |
---|
3077 | //mSceneMgr->setOption("ShowOctree", &val); |
---|
3078 | |
---|
3079 | } |
---|
3080 | |
---|
3081 | void testSimpleMesh() |
---|
3082 | { |
---|
3083 | // Set ambient light |
---|
3084 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3085 | |
---|
3086 | // Create a point light |
---|
3087 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3088 | l->setType(Light::LT_DIRECTIONAL); |
---|
3089 | Vector3 dir(1, -1, 0); |
---|
3090 | dir.normalise(); |
---|
3091 | l->setDirection(dir); |
---|
3092 | |
---|
3093 | // Create a set of random balls |
---|
3094 | Entity* ent = mSceneMgr->createEntity("test", "xsicylinder.mesh"); |
---|
3095 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3096 | |
---|
3097 | } |
---|
3098 | |
---|
3099 | void testGLSLTangent() |
---|
3100 | { |
---|
3101 | |
---|
3102 | Entity* ent = mSceneMgr->createEntity("test", "athene.mesh"); |
---|
3103 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3104 | ent->setMaterialName("testglsl"); |
---|
3105 | } |
---|
3106 | |
---|
3107 | void testInfiniteAAB() |
---|
3108 | { |
---|
3109 | // When using the BspSceneManager |
---|
3110 | //mSceneMgr->setWorldGeometry("ogretestmap.bsp"); |
---|
3111 | |
---|
3112 | // When using the TerrainSceneManager |
---|
3113 | mSceneMgr->setWorldGeometry("terrain.cfg"); |
---|
3114 | |
---|
3115 | AxisAlignedBox b1; // null |
---|
3116 | assert( b1.isNull() ); |
---|
3117 | |
---|
3118 | AxisAlignedBox b2(Vector3::ZERO, 5.0 * Vector3::UNIT_SCALE); // finite |
---|
3119 | assert( b2.isFinite() ); |
---|
3120 | |
---|
3121 | AxisAlignedBox b3; |
---|
3122 | b3.setInfinite(); |
---|
3123 | assert( b3.isInfinite() ); |
---|
3124 | |
---|
3125 | { |
---|
3126 | // Create background material |
---|
3127 | MaterialPtr material = MaterialManager::getSingleton().create("Background", "General"); |
---|
3128 | material->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga"); |
---|
3129 | material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); |
---|
3130 | material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); |
---|
3131 | material->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
3132 | |
---|
3133 | // Create left background rectangle |
---|
3134 | // NOTE: Uses finite aab |
---|
3135 | Rectangle2D* rect1 = new Rectangle2D(true); |
---|
3136 | rect1->setCorners(-0.5, 0.1, -0.1, -0.1); |
---|
3137 | // Hacky, set small bounding box, to show problem |
---|
3138 | rect1->setBoundingBox(AxisAlignedBox(-10.0*Vector3::UNIT_SCALE, 10.0*Vector3::UNIT_SCALE)); |
---|
3139 | rect1->setMaterial("Background"); |
---|
3140 | rect1->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1); |
---|
3141 | SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background1"); |
---|
3142 | node->attachObject(rect1); |
---|
3143 | |
---|
3144 | // Create right background rectangle |
---|
3145 | // NOTE: Uses infinite aab |
---|
3146 | Rectangle2D* rect2 = new Rectangle2D(true); |
---|
3147 | rect2->setCorners(0.1, 0.1, 0.5, -0.1); |
---|
3148 | AxisAlignedBox aabInf; aabInf.setInfinite(); |
---|
3149 | rect2->setBoundingBox(aabInf); |
---|
3150 | rect2->setMaterial("Background"); |
---|
3151 | rect2->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1); |
---|
3152 | node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background2"); |
---|
3153 | node->attachObject(rect2); |
---|
3154 | |
---|
3155 | // Create a manual object for 2D |
---|
3156 | ManualObject* manual = mSceneMgr->createManualObject("manual"); |
---|
3157 | manual->setUseIdentityProjection(true); |
---|
3158 | manual->setUseIdentityView(true); |
---|
3159 | manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); |
---|
3160 | manual->position(-0.2, -0.2, 0.0); |
---|
3161 | manual->position( 0.2, -0.2, 0.0); |
---|
3162 | manual->position( 0.2, 0.2, 0.0); |
---|
3163 | manual->position(-0.2, 0.2, 0.0); |
---|
3164 | manual->index(0); |
---|
3165 | manual->index(1); |
---|
3166 | manual->index(2); |
---|
3167 | manual->index(3); |
---|
3168 | manual->index(0); |
---|
3169 | manual->end(); |
---|
3170 | manual->setBoundingBox(aabInf); // Use infinite aab to always stay visible |
---|
3171 | rect2->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1); |
---|
3172 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual); |
---|
3173 | } |
---|
3174 | |
---|
3175 | mSceneMgr->showBoundingBoxes(true); |
---|
3176 | |
---|
3177 | Entity* ent = mSceneMgr->createEntity("test", "ogrehead.mesh"); |
---|
3178 | mSceneMgr->getRootSceneNode()->createChildSceneNode( |
---|
3179 | "test", 50.0 * Vector3::UNIT_X)->attachObject(ent); |
---|
3180 | } |
---|
3181 | |
---|
3182 | void test2Windows(void) |
---|
3183 | { |
---|
3184 | // Set ambient light |
---|
3185 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3186 | |
---|
3187 | // Create a point light |
---|
3188 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3189 | l->setType(Light::LT_DIRECTIONAL); |
---|
3190 | Vector3 dir(1, -1, 0); |
---|
3191 | dir.normalise(); |
---|
3192 | l->setDirection(dir); |
---|
3193 | |
---|
3194 | Entity* ent = mSceneMgr->createEntity("head", "robot.mesh"); |
---|
3195 | AnimationState* a = ent->getAnimationState("Walk"); |
---|
3196 | a->setEnabled(true); |
---|
3197 | mAnimStateList.push_back(a); |
---|
3198 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
3199 | |
---|
3200 | NameValuePairList valuePair; |
---|
3201 | valuePair["top"] = StringConverter::toString(0); |
---|
3202 | valuePair["left"] = StringConverter::toString(0); |
---|
3203 | |
---|
3204 | RenderWindow* win2 = mRoot->createRenderWindow("window2", 800,600, true, &valuePair); |
---|
3205 | win2->addViewport(mCamera); |
---|
3206 | |
---|
3207 | |
---|
3208 | |
---|
3209 | } |
---|
3210 | |
---|
3211 | void testStaticGeometry(void) |
---|
3212 | { |
---|
3213 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); |
---|
3214 | //mSceneMgr->setShowDebugShadows(true); |
---|
3215 | |
---|
3216 | mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox"); |
---|
3217 | // Set ambient light |
---|
3218 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3219 | |
---|
3220 | // Create a point light |
---|
3221 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3222 | l->setType(Light::LT_DIRECTIONAL); |
---|
3223 | Vector3 dir(0, -1, -1.5); |
---|
3224 | dir.normalise(); |
---|
3225 | l->setDirection(dir); |
---|
3226 | l->setDiffuseColour(1.0, 0.7, 0.0); |
---|
3227 | |
---|
3228 | |
---|
3229 | Plane plane; |
---|
3230 | plane.normal = Vector3::UNIT_Y; |
---|
3231 | plane.d = 0; |
---|
3232 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3233 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3234 | 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3235 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3236 | pPlaneEnt->setMaterialName("Examples/GrassFloor"); |
---|
3237 | pPlaneEnt->setCastShadows(false); |
---|
3238 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3239 | |
---|
3240 | Vector3 min(-2000,0,-2000); |
---|
3241 | Vector3 max(2000,0,2000); |
---|
3242 | |
---|
3243 | |
---|
3244 | Entity* e = mSceneMgr->createEntity("1", "column.mesh"); |
---|
3245 | //createRandomEntityClones(e, 1000, min, max); |
---|
3246 | |
---|
3247 | StaticGeometry* s = mSceneMgr->createStaticGeometry("bing"); |
---|
3248 | s->setCastShadows(true); |
---|
3249 | s->setRegionDimensions(Vector3(500,500,500)); |
---|
3250 | for (int i = 0; i < 100; ++i) |
---|
3251 | { |
---|
3252 | Vector3 pos; |
---|
3253 | pos.x = Math::RangeRandom(min.x, max.x); |
---|
3254 | pos.y = Math::RangeRandom(min.y, max.y); |
---|
3255 | pos.z = Math::RangeRandom(min.z, max.z); |
---|
3256 | |
---|
3257 | s->addEntity(e, pos, Quaternion::IDENTITY); |
---|
3258 | |
---|
3259 | } |
---|
3260 | |
---|
3261 | s->build(); |
---|
3262 | //s->setRenderingDistance(1000); |
---|
3263 | //s->dump("static.txt"); |
---|
3264 | //mSceneMgr->showBoundingBoxes(true); |
---|
3265 | mCamera->setLodBias(0.5); |
---|
3266 | |
---|
3267 | |
---|
3268 | |
---|
3269 | |
---|
3270 | } |
---|
3271 | |
---|
3272 | void testReloadResources() |
---|
3273 | { |
---|
3274 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
3275 | ResourceGroupManager::getSingleton().createResourceGroup("Sinbad"); |
---|
3276 | Root::getSingleton().addResourceLocation("../../../Media/models", "FileSystem", "Sinbad"); |
---|
3277 | MeshManager& mmgr = MeshManager::getSingleton(); |
---|
3278 | mmgr.load("robot.mesh", "Sinbad"); |
---|
3279 | mmgr.load("knot.mesh", "Sinbad"); |
---|
3280 | |
---|
3281 | Entity* e = mSceneMgr->createEntity("1", "robot.mesh"); |
---|
3282 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
3283 | e = mSceneMgr->createEntity("2", "robot.mesh"); |
---|
3284 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0))->attachObject(e); |
---|
3285 | e = mSceneMgr->createEntity("3", "knot.mesh"); |
---|
3286 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,300,0))->attachObject(e); |
---|
3287 | |
---|
3288 | testreload = true; |
---|
3289 | |
---|
3290 | } |
---|
3291 | |
---|
3292 | void testBillboardTextureCoords() |
---|
3293 | { |
---|
3294 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
3295 | |
---|
3296 | BillboardSet* bbs = mSceneMgr->createBillboardSet("test"); |
---|
3297 | BillboardSet* bbs2 = mSceneMgr->createBillboardSet("test2"); |
---|
3298 | float xsegs = 3; |
---|
3299 | float ysegs = 3; |
---|
3300 | float width = 300; |
---|
3301 | float height = 300; |
---|
3302 | float gap = 20; |
---|
3303 | |
---|
3304 | // set up texture coords |
---|
3305 | bbs->setTextureStacksAndSlices(ysegs, xsegs); |
---|
3306 | bbs->setDefaultDimensions(width/xsegs, height/xsegs); |
---|
3307 | bbs2->setDefaultDimensions(width/xsegs, height/xsegs); |
---|
3308 | |
---|
3309 | for (float y = 0; y < ysegs; ++y) |
---|
3310 | { |
---|
3311 | for (float x = 0; x < xsegs; ++x) |
---|
3312 | { |
---|
3313 | Vector3 midPoint; |
---|
3314 | midPoint.x = (x * width / xsegs) + ((x-1) * gap); |
---|
3315 | midPoint.y = (y * height / ysegs) + ((y-1) * gap); |
---|
3316 | midPoint.z = 0; |
---|
3317 | Billboard* bb = bbs->createBillboard(midPoint); |
---|
3318 | bb->setTexcoordIndex((ysegs - y - 1)*xsegs + x); |
---|
3319 | Billboard* bb2 = bbs2->createBillboard(midPoint); |
---|
3320 | bb2->setTexcoordRect( |
---|
3321 | FloatRect((x + 0) / xsegs, (ysegs - y - 1) / ysegs, |
---|
3322 | (x + 1) / xsegs, (ysegs - y - 0) / ysegs)); |
---|
3323 | } |
---|
3324 | } |
---|
3325 | |
---|
3326 | bbs->setMaterialName("Examples/OgreLogo"); |
---|
3327 | bbs2->setMaterialName("Examples/OgreLogo"); |
---|
3328 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs); |
---|
3329 | mSceneMgr->getRootSceneNode() |
---|
3330 | ->createChildSceneNode(Vector3(- (width + xsegs * gap), 0, 0)) |
---|
3331 | ->attachObject(bbs2); |
---|
3332 | |
---|
3333 | } |
---|
3334 | |
---|
3335 | class SortFunctor |
---|
3336 | { |
---|
3337 | public: |
---|
3338 | int operator()(const int& p) const |
---|
3339 | { |
---|
3340 | return p; |
---|
3341 | } |
---|
3342 | |
---|
3343 | }; |
---|
3344 | void testRadixSort() |
---|
3345 | { |
---|
3346 | RadixSort<std::list<int>, int, int> rs; |
---|
3347 | SortFunctor f; |
---|
3348 | |
---|
3349 | std::list<int> particles; |
---|
3350 | for (int r = 0; r < 20; ++r) |
---|
3351 | { |
---|
3352 | particles.push_back((int)Math::RangeRandom(-1e3f, 1e3f)); |
---|
3353 | } |
---|
3354 | |
---|
3355 | std::list<int>::iterator i; |
---|
3356 | LogManager::getSingleton().logMessage("BEFORE"); |
---|
3357 | for (i = particles.begin(); i != particles.end(); ++i) |
---|
3358 | { |
---|
3359 | StringUtil::StrStreamType str; |
---|
3360 | str << *i; |
---|
3361 | LogManager::getSingleton().logMessage(str.str()); |
---|
3362 | } |
---|
3363 | |
---|
3364 | rs.sort(particles, f); |
---|
3365 | |
---|
3366 | |
---|
3367 | LogManager::getSingleton().logMessage("AFTER"); |
---|
3368 | for (i = particles.begin(); i != particles.end(); ++i) |
---|
3369 | { |
---|
3370 | StringUtil::StrStreamType str; |
---|
3371 | str << *i; |
---|
3372 | LogManager::getSingleton().logMessage(str.str()); |
---|
3373 | } |
---|
3374 | |
---|
3375 | |
---|
3376 | |
---|
3377 | } |
---|
3378 | |
---|
3379 | void testMorphAnimation() |
---|
3380 | { |
---|
3381 | bool testStencil = true; |
---|
3382 | |
---|
3383 | if (testStencil) |
---|
3384 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE); |
---|
3385 | |
---|
3386 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3387 | Vector3 dir(-1, -1, 0.5); |
---|
3388 | dir.normalise(); |
---|
3389 | Light* l = mSceneMgr->createLight("light1"); |
---|
3390 | l->setType(Light::LT_DIRECTIONAL); |
---|
3391 | l->setDirection(dir); |
---|
3392 | |
---|
3393 | |
---|
3394 | MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", |
---|
3395 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
3396 | |
---|
3397 | SubMesh* sm = mesh->getSubMesh(0); |
---|
3398 | // Re-organise geometry since this mesh has no animation and all |
---|
3399 | // vertex elements are packed into one buffer |
---|
3400 | VertexDeclaration* newDecl = |
---|
3401 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true); |
---|
3402 | sm->vertexData->reorganiseBuffers(newDecl); |
---|
3403 | if (testStencil) |
---|
3404 | sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised |
---|
3405 | // get the position buffer (which should now be separate); |
---|
3406 | const VertexElement* posElem = |
---|
3407 | sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION); |
---|
3408 | HardwareVertexBufferSharedPtr origbuf = |
---|
3409 | sm->vertexData->vertexBufferBinding->getBuffer( |
---|
3410 | posElem->getSource()); |
---|
3411 | |
---|
3412 | // Create a new position buffer with updated values |
---|
3413 | HardwareVertexBufferSharedPtr newbuf = |
---|
3414 | HardwareBufferManager::getSingleton().createVertexBuffer( |
---|
3415 | VertexElement::getTypeSize(VET_FLOAT3), |
---|
3416 | sm->vertexData->vertexCount, |
---|
3417 | HardwareBuffer::HBU_STATIC, true); |
---|
3418 | float* pSrc = static_cast<float*>(origbuf->lock(HardwareBuffer::HBL_READ_ONLY)); |
---|
3419 | float* pDst = static_cast<float*>(newbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
3420 | |
---|
3421 | for (size_t v = 0; v < sm->vertexData->vertexCount; ++v) |
---|
3422 | { |
---|
3423 | // x |
---|
3424 | *pDst++ = *pSrc++; |
---|
3425 | // y (translate) |
---|
3426 | *pDst++ = (*pSrc++) + 100.0f; |
---|
3427 | // z |
---|
3428 | *pDst++ = *pSrc++; |
---|
3429 | } |
---|
3430 | |
---|
3431 | origbuf->unlock(); |
---|
3432 | newbuf->unlock(); |
---|
3433 | |
---|
3434 | // create a morph animation |
---|
3435 | Animation* anim = mesh->createAnimation("testAnim", 10.0f); |
---|
3436 | VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_MORPH); |
---|
3437 | // re-use start positions for frame 0 |
---|
3438 | VertexMorphKeyFrame* kf = vt->createVertexMorphKeyFrame(0); |
---|
3439 | kf->setVertexBuffer(origbuf); |
---|
3440 | |
---|
3441 | // Use translated buffer for mid frame |
---|
3442 | kf = vt->createVertexMorphKeyFrame(5.0f); |
---|
3443 | kf->setVertexBuffer(newbuf); |
---|
3444 | |
---|
3445 | // re-use start positions for final frame |
---|
3446 | kf = vt->createVertexMorphKeyFrame(10.0f); |
---|
3447 | kf->setVertexBuffer(origbuf); |
---|
3448 | |
---|
3449 | // write |
---|
3450 | MeshSerializer ser; |
---|
3451 | ser.exportMesh(mesh.get(), "../../../Media/testmorph.mesh"); |
---|
3452 | |
---|
3453 | |
---|
3454 | Entity* e = mSceneMgr->createEntity("test", "testmorph.mesh"); |
---|
3455 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
3456 | AnimationState* animState = e->getAnimationState("testAnim"); |
---|
3457 | animState->setEnabled(true); |
---|
3458 | animState->setWeight(1.0f); |
---|
3459 | mAnimStateList.push_back(animState); |
---|
3460 | |
---|
3461 | e = mSceneMgr->createEntity("test2", "testmorph.mesh"); |
---|
3462 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(100,0,0))->attachObject(e); |
---|
3463 | // test hardware morph |
---|
3464 | e->setMaterialName("Examples/HardwareMorphAnimation"); |
---|
3465 | animState = e->getAnimationState("testAnim"); |
---|
3466 | animState->setEnabled(true); |
---|
3467 | animState->setWeight(1.0f); |
---|
3468 | mAnimStateList.push_back(animState); |
---|
3469 | |
---|
3470 | mCamera->setNearClipDistance(0.5); |
---|
3471 | //mSceneMgr->setShowDebugShadows(true); |
---|
3472 | |
---|
3473 | Plane plane; |
---|
3474 | plane.normal = Vector3::UNIT_Y; |
---|
3475 | plane.d = 200; |
---|
3476 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3477 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3478 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3479 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3480 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
3481 | pPlaneEnt->setCastShadows(false); |
---|
3482 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3483 | |
---|
3484 | |
---|
3485 | |
---|
3486 | } |
---|
3487 | |
---|
3488 | |
---|
3489 | void testPoseAnimation() |
---|
3490 | { |
---|
3491 | bool testStencil = false; |
---|
3492 | |
---|
3493 | if (testStencil) |
---|
3494 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE); |
---|
3495 | |
---|
3496 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3497 | Vector3 dir(-1, -1, 0.5); |
---|
3498 | dir.normalise(); |
---|
3499 | Light* l = mSceneMgr->createLight("light1"); |
---|
3500 | l->setType(Light::LT_DIRECTIONAL); |
---|
3501 | l->setDirection(dir); |
---|
3502 | |
---|
3503 | MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", |
---|
3504 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
3505 | |
---|
3506 | SubMesh* sm = mesh->getSubMesh(0); |
---|
3507 | // Re-organise geometry since this mesh has no animation and all |
---|
3508 | // vertex elements are packed into one buffer |
---|
3509 | VertexDeclaration* newDecl = |
---|
3510 | sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true); |
---|
3511 | sm->vertexData->reorganiseBuffers(newDecl); |
---|
3512 | if (testStencil) |
---|
3513 | sm->vertexData->prepareForShadowVolume(); // need to re-prep since reorganised |
---|
3514 | // get the position buffer (which should now be separate); |
---|
3515 | const VertexElement* posElem = |
---|
3516 | sm->vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION); |
---|
3517 | HardwareVertexBufferSharedPtr origbuf = |
---|
3518 | sm->vertexData->vertexBufferBinding->getBuffer( |
---|
3519 | posElem->getSource()); |
---|
3520 | |
---|
3521 | |
---|
3522 | // create 2 poses |
---|
3523 | Pose* pose = mesh->createPose(1, "pose1"); |
---|
3524 | // Pose1 moves vertices 0, 1, 2 and 3 upward |
---|
3525 | Vector3 offset1(0, 50, 0); |
---|
3526 | pose->addVertex(0, offset1); |
---|
3527 | pose->addVertex(1, offset1); |
---|
3528 | pose->addVertex(2, offset1); |
---|
3529 | pose->addVertex(3, offset1); |
---|
3530 | |
---|
3531 | pose = mesh->createPose(1, "pose2"); |
---|
3532 | // Pose2 moves vertices 3, 4, and 5 to the right |
---|
3533 | // Note 3 gets affected by both |
---|
3534 | Vector3 offset2(100, 0, 0); |
---|
3535 | pose->addVertex(3, offset2); |
---|
3536 | pose->addVertex(4, offset2); |
---|
3537 | pose->addVertex(5, offset2); |
---|
3538 | |
---|
3539 | |
---|
3540 | Animation* anim = mesh->createAnimation("poseanim", 20.0f); |
---|
3541 | VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE); |
---|
3542 | |
---|
3543 | // Frame 0 - no effect |
---|
3544 | VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(0); |
---|
3545 | |
---|
3546 | // Frame 1 - bring in pose 1 (index 0) |
---|
3547 | kf = vt->createVertexPoseKeyFrame(3); |
---|
3548 | kf->addPoseReference(0, 1.0f); |
---|
3549 | |
---|
3550 | // Frame 2 - remove all |
---|
3551 | kf = vt->createVertexPoseKeyFrame(6); |
---|
3552 | |
---|
3553 | // Frame 3 - bring in pose 2 (index 1) |
---|
3554 | kf = vt->createVertexPoseKeyFrame(9); |
---|
3555 | kf->addPoseReference(1, 1.0f); |
---|
3556 | |
---|
3557 | // Frame 4 - remove all |
---|
3558 | kf = vt->createVertexPoseKeyFrame(12); |
---|
3559 | |
---|
3560 | |
---|
3561 | // Frame 5 - bring in pose 1 at 50%, pose 2 at 100% |
---|
3562 | kf = vt->createVertexPoseKeyFrame(15); |
---|
3563 | kf->addPoseReference(0, 0.5f); |
---|
3564 | kf->addPoseReference(1, 1.0f); |
---|
3565 | |
---|
3566 | // Frame 6 - bring in pose 1 at 100%, pose 2 at 50% |
---|
3567 | kf = vt->createVertexPoseKeyFrame(18); |
---|
3568 | kf->addPoseReference(0, 1.0f); |
---|
3569 | kf->addPoseReference(1, 0.5f); |
---|
3570 | |
---|
3571 | // Frame 7 - reset |
---|
3572 | kf = vt->createVertexPoseKeyFrame(20); |
---|
3573 | |
---|
3574 | // write |
---|
3575 | MeshSerializer ser; |
---|
3576 | ser.exportMesh(mesh.get(), "../../../Media/testpose.mesh"); |
---|
3577 | |
---|
3578 | |
---|
3579 | Entity* e; |
---|
3580 | AnimationState* animState; |
---|
3581 | // software pose |
---|
3582 | e = mSceneMgr->createEntity("test2", "testpose.mesh"); |
---|
3583 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e); |
---|
3584 | animState = e->getAnimationState("poseanim"); |
---|
3585 | animState->setEnabled(true); |
---|
3586 | animState->setWeight(1.0f); |
---|
3587 | mAnimStateList.push_back(animState); |
---|
3588 | |
---|
3589 | // test hardware pose |
---|
3590 | e = mSceneMgr->createEntity("test", "testpose.mesh"); |
---|
3591 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
3592 | e->setMaterialName("Examples/HardwarePoseAnimation"); |
---|
3593 | animState = e->getAnimationState("poseanim"); |
---|
3594 | animState->setEnabled(true); |
---|
3595 | animState->setWeight(1.0f); |
---|
3596 | mAnimStateList.push_back(animState); |
---|
3597 | |
---|
3598 | |
---|
3599 | mCamera->setNearClipDistance(0.5); |
---|
3600 | mSceneMgr->setShowDebugShadows(true); |
---|
3601 | |
---|
3602 | Plane plane; |
---|
3603 | plane.normal = Vector3::UNIT_Y; |
---|
3604 | plane.d = 200; |
---|
3605 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3606 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3607 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3608 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3609 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
3610 | pPlaneEnt->setCastShadows(false); |
---|
3611 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3612 | |
---|
3613 | mCamera->setPosition(0,0,-300); |
---|
3614 | mCamera->lookAt(0,0,0); |
---|
3615 | |
---|
3616 | |
---|
3617 | |
---|
3618 | } |
---|
3619 | |
---|
3620 | void testPoseAnimation2() |
---|
3621 | { |
---|
3622 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3623 | Vector3 dir(-1, -1, -0.5); |
---|
3624 | dir.normalise(); |
---|
3625 | Light* l = mSceneMgr->createLight("light1"); |
---|
3626 | l->setType(Light::LT_DIRECTIONAL); |
---|
3627 | l->setDirection(dir); |
---|
3628 | |
---|
3629 | /* |
---|
3630 | MeshPtr mesh = MeshManager::getSingleton().load("facial.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
3631 | Animation* anim = mesh->createAnimation("pose", 20); |
---|
3632 | VertexAnimationTrack* track = anim->createVertexTrack(4, VAT_POSE); |
---|
3633 | // Frame 0 - no effect |
---|
3634 | VertexPoseKeyFrame* kf = track->createVertexPoseKeyFrame(0); |
---|
3635 | |
---|
3636 | // bring in pose 4 (happy) |
---|
3637 | kf = track->createVertexPoseKeyFrame(5); |
---|
3638 | kf->addPoseReference(4, 1.0f); |
---|
3639 | |
---|
3640 | // bring in pose 5 (sad) |
---|
3641 | kf = track->createVertexPoseKeyFrame(10); |
---|
3642 | kf->addPoseReference(5, 1.0f); |
---|
3643 | |
---|
3644 | // bring in pose 6 (mad) |
---|
3645 | kf = track->createVertexPoseKeyFrame(15); |
---|
3646 | kf->addPoseReference(6, 1.0f); |
---|
3647 | |
---|
3648 | kf = track->createVertexPoseKeyFrame(20); |
---|
3649 | */ |
---|
3650 | |
---|
3651 | // software pose |
---|
3652 | Entity* e = mSceneMgr->createEntity("test2", "facial.mesh"); |
---|
3653 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e); |
---|
3654 | AnimationState* animState = e->getAnimationState("Speak"); |
---|
3655 | animState->setEnabled(true); |
---|
3656 | animState->setWeight(1.0f); |
---|
3657 | mAnimStateList.push_back(animState); |
---|
3658 | |
---|
3659 | |
---|
3660 | /* |
---|
3661 | // test hardware pose |
---|
3662 | e = mSceneMgr->createEntity("test", "testpose.mesh"); |
---|
3663 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
3664 | e->setMaterialName("Examples/HardwarePoseAnimation"); |
---|
3665 | animState = e->getAnimationState("poseanim"); |
---|
3666 | animState->setEnabled(true); |
---|
3667 | animState->setWeight(1.0f); |
---|
3668 | mAnimStateList.push_back(animState); |
---|
3669 | */ |
---|
3670 | |
---|
3671 | |
---|
3672 | mCamera->setNearClipDistance(0.5); |
---|
3673 | mSceneMgr->setShowDebugShadows(true); |
---|
3674 | |
---|
3675 | Plane plane; |
---|
3676 | plane.normal = Vector3::UNIT_Y; |
---|
3677 | plane.d = 200; |
---|
3678 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3679 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3680 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3681 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3682 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
3683 | pPlaneEnt->setCastShadows(false); |
---|
3684 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3685 | |
---|
3686 | } |
---|
3687 | |
---|
3688 | |
---|
3689 | void testReflectedBillboards() |
---|
3690 | { |
---|
3691 | // Set ambient light |
---|
3692 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
3693 | |
---|
3694 | // Create a light |
---|
3695 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
3696 | l->setType(Light::LT_DIRECTIONAL); |
---|
3697 | Vector3 dir(0.5, -1, 0); |
---|
3698 | dir.normalise(); |
---|
3699 | l->setDirection(dir); |
---|
3700 | l->setDiffuseColour(1.0f, 1.0f, 0.8f); |
---|
3701 | l->setSpecularColour(1.0f, 1.0f, 1.0f); |
---|
3702 | |
---|
3703 | |
---|
3704 | // Create a prefab plane |
---|
3705 | Plane plane; |
---|
3706 | plane.d = 0; |
---|
3707 | plane.normal = Vector3::UNIT_Y; |
---|
3708 | MeshManager::getSingleton().createPlane("ReflectionPlane", |
---|
3709 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
3710 | plane, 2000, 2000, |
---|
3711 | 1, 1, true, 1, 1, 1, Vector3::UNIT_Z); |
---|
3712 | Entity* planeEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" ); |
---|
3713 | |
---|
3714 | // Attach the rtt entity to the root of the scene |
---|
3715 | SceneNode* rootNode = mSceneMgr->getRootSceneNode(); |
---|
3716 | SceneNode* planeNode = rootNode->createChildSceneNode(); |
---|
3717 | |
---|
3718 | // Attach both the plane entity, and the plane definition |
---|
3719 | planeNode->attachObject(planeEnt); |
---|
3720 | |
---|
3721 | RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "RttTex", 512, 512, TEX_TYPE_2D, PF_R8G8B8 ); |
---|
3722 | { |
---|
3723 | reflectCam = mSceneMgr->createCamera("ReflectCam"); |
---|
3724 | reflectCam->setNearClipDistance(mCamera->getNearClipDistance()); |
---|
3725 | reflectCam->setFarClipDistance(mCamera->getFarClipDistance()); |
---|
3726 | reflectCam->setAspectRatio( |
---|
3727 | (Real)mWindow->getViewport(0)->getActualWidth() / |
---|
3728 | (Real)mWindow->getViewport(0)->getActualHeight()); |
---|
3729 | |
---|
3730 | Viewport *v = rttTex->addViewport( reflectCam ); |
---|
3731 | v->setClearEveryFrame( true ); |
---|
3732 | v->setBackgroundColour( ColourValue::Black ); |
---|
3733 | |
---|
3734 | MaterialPtr mat = MaterialManager::getSingleton().create("RttMat", |
---|
3735 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
3736 | TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg"); |
---|
3737 | t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex"); |
---|
3738 | // Blend with base texture |
---|
3739 | t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White, |
---|
3740 | ColourValue::White, 0.25); |
---|
3741 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
3742 | t->setProjectiveTexturing(true, reflectCam); |
---|
3743 | |
---|
3744 | // set up linked reflection |
---|
3745 | reflectCam->enableReflection(plane); |
---|
3746 | // Also clip |
---|
3747 | reflectCam->enableCustomNearClipPlane(plane); |
---|
3748 | } |
---|
3749 | |
---|
3750 | // Give the plane a texture |
---|
3751 | planeEnt->setMaterialName("RttMat"); |
---|
3752 | |
---|
3753 | |
---|
3754 | // point billboards |
---|
3755 | ParticleSystem* pSys2 = mSceneMgr->createParticleSystem("fountain1", |
---|
3756 | "Examples/Smoke"); |
---|
3757 | // Point the fountain at an angle |
---|
3758 | SceneNode* fNode = static_cast<SceneNode*>(rootNode->createChild()); |
---|
3759 | fNode->attachObject(pSys2); |
---|
3760 | |
---|
3761 | // oriented_self billboards |
---|
3762 | ParticleSystem* pSys3 = mSceneMgr->createParticleSystem("fountain2", |
---|
3763 | "Examples/PurpleFountain"); |
---|
3764 | // Point the fountain at an angle |
---|
3765 | fNode = rootNode->createChildSceneNode(); |
---|
3766 | fNode->translate(-200,-100,0); |
---|
3767 | fNode->rotate(Vector3::UNIT_Z, Degree(-20)); |
---|
3768 | fNode->attachObject(pSys3); |
---|
3769 | |
---|
3770 | |
---|
3771 | |
---|
3772 | // oriented_common billboards |
---|
3773 | ParticleSystem* pSys4 = mSceneMgr->createParticleSystem("rain", |
---|
3774 | "Examples/Rain"); |
---|
3775 | SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
3776 | rNode->translate(0,1000,0); |
---|
3777 | rNode->attachObject(pSys4); |
---|
3778 | // Fast-forward the rain so it looks more natural |
---|
3779 | pSys4->fastForward(5); |
---|
3780 | |
---|
3781 | |
---|
3782 | mCamera->setPosition(-50, 100, 500); |
---|
3783 | mCamera->lookAt(0,0,0); |
---|
3784 | } |
---|
3785 | |
---|
3786 | void testManualObjectNonIndexed() |
---|
3787 | { |
---|
3788 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3789 | Vector3 dir(-1, -1, 0.5); |
---|
3790 | dir.normalise(); |
---|
3791 | Light* l = mSceneMgr->createLight("light1"); |
---|
3792 | l->setType(Light::LT_DIRECTIONAL); |
---|
3793 | l->setDirection(dir); |
---|
3794 | |
---|
3795 | Plane plane; |
---|
3796 | plane.normal = Vector3::UNIT_Y; |
---|
3797 | plane.d = 100; |
---|
3798 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3799 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3800 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3801 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3802 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
3803 | pPlaneEnt->setCastShadows(false); |
---|
3804 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3805 | |
---|
3806 | ManualObject* man = static_cast<ManualObject*>( |
---|
3807 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
3808 | |
---|
3809 | man->begin("Examples/OgreLogo"); |
---|
3810 | // Define a 40x40 plane, non-indexed |
---|
3811 | man->position(-20, 20, 20); |
---|
3812 | man->normal(0, 0, 1); |
---|
3813 | man->textureCoord(0, 0); |
---|
3814 | |
---|
3815 | man->position(-20, -20, 20); |
---|
3816 | man->normal(0, 0, 1); |
---|
3817 | man->textureCoord(0, 1); |
---|
3818 | |
---|
3819 | man->position(20, 20, 20); |
---|
3820 | man->normal(0, 0, 1); |
---|
3821 | man->textureCoord(1, 0); |
---|
3822 | |
---|
3823 | man->position(-20, -20, 20); |
---|
3824 | man->normal(0, 0, 1); |
---|
3825 | man->textureCoord(0, 1); |
---|
3826 | |
---|
3827 | man->position(20, -20, 20); |
---|
3828 | man->normal(0, 0, 1); |
---|
3829 | man->textureCoord(1, 1); |
---|
3830 | |
---|
3831 | man->position(20, 20, 20); |
---|
3832 | man->normal(0, 0, 1); |
---|
3833 | man->textureCoord(1, 0); |
---|
3834 | |
---|
3835 | man->end(); |
---|
3836 | |
---|
3837 | man->begin("Examples/BumpyMetal"); |
---|
3838 | |
---|
3839 | // Define a 40x40 plane, non-indexed |
---|
3840 | man->position(-20, 20, 20); |
---|
3841 | man->normal(0, 1, 0); |
---|
3842 | man->textureCoord(0, 0); |
---|
3843 | |
---|
3844 | man->position(20, 20, 20); |
---|
3845 | man->normal(0, 1, 0); |
---|
3846 | man->textureCoord(0, 1); |
---|
3847 | |
---|
3848 | man->position(20, 20, -20); |
---|
3849 | man->normal(0, 1, 0); |
---|
3850 | man->textureCoord(1, 1); |
---|
3851 | |
---|
3852 | man->position(20, 20, -20); |
---|
3853 | man->normal(0, 1, 0); |
---|
3854 | man->textureCoord(1, 1); |
---|
3855 | |
---|
3856 | man->position(-20, 20, -20); |
---|
3857 | man->normal(0, 1, 0); |
---|
3858 | man->textureCoord(1, 0); |
---|
3859 | |
---|
3860 | man->position(-20, 20, 20); |
---|
3861 | man->normal(0, 1, 0); |
---|
3862 | man->textureCoord(0, 0); |
---|
3863 | |
---|
3864 | man->end(); |
---|
3865 | |
---|
3866 | |
---|
3867 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man); |
---|
3868 | |
---|
3869 | } |
---|
3870 | |
---|
3871 | void testManualObjectNonIndexedUpdateSmaller() |
---|
3872 | { |
---|
3873 | testManualObjectNonIndexed(); |
---|
3874 | ManualObject* man = static_cast<ManualObject*>( |
---|
3875 | mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
3876 | |
---|
3877 | // Redefine but make smaller (one tri less) |
---|
3878 | man->beginUpdate(0); |
---|
3879 | man->position(-30, 30, 30); |
---|
3880 | man->normal(0, 0, 1); |
---|
3881 | man->textureCoord(0, 0); |
---|
3882 | |
---|
3883 | man->position(-30, -30, 30); |
---|
3884 | man->normal(0, 0, 1); |
---|
3885 | man->textureCoord(0, 1); |
---|
3886 | |
---|
3887 | man->position(30, 30, 30); |
---|
3888 | man->normal(0, 0, 1); |
---|
3889 | man->textureCoord(1, 0); |
---|
3890 | |
---|
3891 | |
---|
3892 | man->end(); |
---|
3893 | |
---|
3894 | } |
---|
3895 | |
---|
3896 | void testManualObjectNonIndexedUpdateLarger() |
---|
3897 | { |
---|
3898 | testManualObjectNonIndexed(); |
---|
3899 | ManualObject* man = static_cast<ManualObject*>( |
---|
3900 | mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
3901 | |
---|
3902 | // Redefine but make larger (2 more tri) |
---|
3903 | man->beginUpdate(0); |
---|
3904 | |
---|
3905 | man->position(-20, 20, 20); |
---|
3906 | man->normal(0, 0, 1); |
---|
3907 | man->textureCoord(0, 0); |
---|
3908 | |
---|
3909 | man->position(-20, -20, 20); |
---|
3910 | man->normal(0, 0, 1); |
---|
3911 | man->textureCoord(0, 1); |
---|
3912 | |
---|
3913 | man->position(20, 20, 20); |
---|
3914 | man->normal(0, 0, 1); |
---|
3915 | man->textureCoord(1, 0); |
---|
3916 | |
---|
3917 | man->position(-20, -20, 20); |
---|
3918 | man->normal(0, 0, 1); |
---|
3919 | man->textureCoord(0, 1); |
---|
3920 | |
---|
3921 | man->position(20, -20, 20); |
---|
3922 | man->normal(0, 0, 1); |
---|
3923 | man->textureCoord(1, 1); |
---|
3924 | |
---|
3925 | man->position(20, 20, 20); |
---|
3926 | man->normal(0, 0, 1); |
---|
3927 | man->textureCoord(1, 0); |
---|
3928 | |
---|
3929 | |
---|
3930 | man->position(-20, 40, 20); |
---|
3931 | man->normal(0, 0, 1); |
---|
3932 | man->textureCoord(0, 0); |
---|
3933 | |
---|
3934 | man->position(-20, 20, 20); |
---|
3935 | man->normal(0, 0, 1); |
---|
3936 | man->textureCoord(0, 1); |
---|
3937 | |
---|
3938 | man->position(20, 40, 20); |
---|
3939 | man->normal(0, 0, 1); |
---|
3940 | man->textureCoord(1, 0); |
---|
3941 | |
---|
3942 | man->position(-20, 20, 20); |
---|
3943 | man->normal(0, 0, 1); |
---|
3944 | man->textureCoord(0, 1); |
---|
3945 | |
---|
3946 | man->position(20, 20, 20); |
---|
3947 | man->normal(0, 0, 1); |
---|
3948 | man->textureCoord(1, 1); |
---|
3949 | |
---|
3950 | man->position(20, 40, 20); |
---|
3951 | man->normal(0, 0, 1); |
---|
3952 | man->textureCoord(1, 0); |
---|
3953 | |
---|
3954 | |
---|
3955 | man->end(); |
---|
3956 | |
---|
3957 | } |
---|
3958 | void testManualObjectIndexed() |
---|
3959 | { |
---|
3960 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
3961 | Vector3 dir(-1, -1, 0.5); |
---|
3962 | dir.normalise(); |
---|
3963 | Light* l = mSceneMgr->createLight("light1"); |
---|
3964 | l->setType(Light::LT_DIRECTIONAL); |
---|
3965 | l->setDirection(dir); |
---|
3966 | |
---|
3967 | Plane plane; |
---|
3968 | plane.normal = Vector3::UNIT_Y; |
---|
3969 | plane.d = 100; |
---|
3970 | MeshManager::getSingleton().createPlane("Myplane", |
---|
3971 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
3972 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
3973 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
3974 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
3975 | pPlaneEnt->setCastShadows(false); |
---|
3976 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
3977 | |
---|
3978 | ManualObject* man = static_cast<ManualObject*>( |
---|
3979 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
3980 | |
---|
3981 | man->begin("Examples/OgreLogo"); |
---|
3982 | // Define a 40x40 plane, indexed |
---|
3983 | man->position(-20, 20, 20); |
---|
3984 | man->normal(0, 0, 1); |
---|
3985 | man->textureCoord(0, 0); |
---|
3986 | |
---|
3987 | man->position(-20, -20, 20); |
---|
3988 | man->normal(0, 0, 1); |
---|
3989 | man->textureCoord(0, 1); |
---|
3990 | |
---|
3991 | man->position(20, -20, 20); |
---|
3992 | man->normal(0, 0, 1); |
---|
3993 | man->textureCoord(1, 1); |
---|
3994 | |
---|
3995 | man->position(20, 20, 20); |
---|
3996 | man->normal(0, 0, 1); |
---|
3997 | man->textureCoord(1, 0); |
---|
3998 | |
---|
3999 | man->quad(0, 1, 2, 3); |
---|
4000 | |
---|
4001 | man->end(); |
---|
4002 | |
---|
4003 | man->begin("Examples/BumpyMetal"); |
---|
4004 | |
---|
4005 | // Define a 40x40 plane, indexed |
---|
4006 | man->position(-20, 20, 20); |
---|
4007 | man->normal(0, 1, 0); |
---|
4008 | man->textureCoord(0, 0); |
---|
4009 | |
---|
4010 | man->position(20, 20, 20); |
---|
4011 | man->normal(0, 1, 0); |
---|
4012 | man->textureCoord(0, 1); |
---|
4013 | |
---|
4014 | man->position(20, 20, -20); |
---|
4015 | man->normal(0, 1, 0); |
---|
4016 | man->textureCoord(1, 1); |
---|
4017 | |
---|
4018 | man->position(-20, 20, -20); |
---|
4019 | man->normal(0, 1, 0); |
---|
4020 | man->textureCoord(1, 0); |
---|
4021 | |
---|
4022 | man->quad(0, 1, 2, 3); |
---|
4023 | |
---|
4024 | man->end(); |
---|
4025 | |
---|
4026 | |
---|
4027 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man); |
---|
4028 | |
---|
4029 | |
---|
4030 | |
---|
4031 | } |
---|
4032 | |
---|
4033 | void testManualObjectIndexedUpdateSmaller() |
---|
4034 | { |
---|
4035 | testManualObjectIndexed(); |
---|
4036 | ManualObject* man = static_cast<ManualObject*>( |
---|
4037 | mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
4038 | |
---|
4039 | |
---|
4040 | man->beginUpdate(0); |
---|
4041 | // 1 tri smaller |
---|
4042 | man->position(-20, 20, 20); |
---|
4043 | man->normal(0, 0, 1); |
---|
4044 | man->textureCoord(0, 0); |
---|
4045 | |
---|
4046 | man->position(-20, -20, 20); |
---|
4047 | man->normal(0, 0, 1); |
---|
4048 | man->textureCoord(0, 1); |
---|
4049 | |
---|
4050 | man->position(20, -20, 20); |
---|
4051 | man->normal(0, 0, 1); |
---|
4052 | man->textureCoord(1, 1); |
---|
4053 | |
---|
4054 | man->triangle(0, 1, 2); |
---|
4055 | |
---|
4056 | man->end(); |
---|
4057 | |
---|
4058 | } |
---|
4059 | |
---|
4060 | void testManualObjectIndexedUpdateLarger() |
---|
4061 | { |
---|
4062 | testManualObjectIndexed(); |
---|
4063 | ManualObject* man = static_cast<ManualObject*>( |
---|
4064 | mSceneMgr->getMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
4065 | |
---|
4066 | |
---|
4067 | man->beginUpdate(0); |
---|
4068 | // 1 quad larger |
---|
4069 | man->position(-20, 20, 20); |
---|
4070 | man->normal(0, 0, 1); |
---|
4071 | man->textureCoord(0, 0); |
---|
4072 | |
---|
4073 | man->position(-20, -20, 20); |
---|
4074 | man->normal(0, 0, 1); |
---|
4075 | man->textureCoord(0, 1); |
---|
4076 | |
---|
4077 | man->position(20, -20, 20); |
---|
4078 | man->normal(0, 0, 1); |
---|
4079 | man->textureCoord(1, 1); |
---|
4080 | |
---|
4081 | man->position(20, 20, 20); |
---|
4082 | man->normal(0, 0, 1); |
---|
4083 | man->textureCoord(1, 0); |
---|
4084 | |
---|
4085 | |
---|
4086 | man->position(-20, 40, 20); |
---|
4087 | man->normal(0, 0, 1); |
---|
4088 | man->textureCoord(0, 0); |
---|
4089 | |
---|
4090 | man->position(-20, 20, 20); |
---|
4091 | man->normal(0, 0, 1); |
---|
4092 | man->textureCoord(0, 1); |
---|
4093 | |
---|
4094 | man->position(20, 20, 20); |
---|
4095 | man->normal(0, 0, 1); |
---|
4096 | man->textureCoord(1, 1); |
---|
4097 | |
---|
4098 | man->position(20, 40, 20); |
---|
4099 | man->normal(0, 0, 1); |
---|
4100 | man->textureCoord(1, 0); |
---|
4101 | |
---|
4102 | man->quad(0, 1, 2, 3); |
---|
4103 | man->quad(4, 5, 6, 7); |
---|
4104 | |
---|
4105 | man->end(); |
---|
4106 | |
---|
4107 | } |
---|
4108 | |
---|
4109 | void testBillboardChain() |
---|
4110 | { |
---|
4111 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
4112 | Vector3 dir(-1, -1, 0.5); |
---|
4113 | dir.normalise(); |
---|
4114 | Light* l = mSceneMgr->createLight("light1"); |
---|
4115 | l->setType(Light::LT_DIRECTIONAL); |
---|
4116 | l->setDirection(dir); |
---|
4117 | |
---|
4118 | Plane plane; |
---|
4119 | plane.normal = Vector3::UNIT_Y; |
---|
4120 | plane.d = 100; |
---|
4121 | MeshManager::getSingleton().createPlane("Myplane", |
---|
4122 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
4123 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
4124 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
4125 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
4126 | pPlaneEnt->setCastShadows(false); |
---|
4127 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
4128 | |
---|
4129 | BillboardChain* chain = static_cast<BillboardChain*>( |
---|
4130 | mSceneMgr->createMovableObject("1", "BillboardChain")); |
---|
4131 | chain->setUseTextureCoords(true); |
---|
4132 | chain->setUseVertexColours(false); |
---|
4133 | /* |
---|
4134 | BillboardChain::Element elem; |
---|
4135 | elem.width = 10; |
---|
4136 | elem.texCoord = 0; |
---|
4137 | elem.position = Vector3(0,20,0); |
---|
4138 | chain->addChainElement(0, elem); |
---|
4139 | elem.position = Vector3(20,0,0); |
---|
4140 | elem.texCoord = 1.0; |
---|
4141 | chain->addChainElement(0, elem); |
---|
4142 | elem.position = Vector3(40,10,0); |
---|
4143 | elem.texCoord = 2.0; |
---|
4144 | chain->addChainElement(0, elem); |
---|
4145 | elem.position = Vector3(60,20,0); |
---|
4146 | elem.texCoord = 3.0; |
---|
4147 | chain->addChainElement(0, elem); |
---|
4148 | elem.position = Vector3(80,40,0); |
---|
4149 | elem.texCoord = 4.0; |
---|
4150 | chain->addChainElement(0, elem); |
---|
4151 | elem.position = Vector3(100,70,0); |
---|
4152 | elem.texCoord = 5.0; |
---|
4153 | chain->addChainElement(0, elem); |
---|
4154 | */ |
---|
4155 | chain->setMaterialName("Examples/RustySteel"); |
---|
4156 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(chain); |
---|
4157 | |
---|
4158 | mSceneMgr->showBoundingBoxes(true); |
---|
4159 | } |
---|
4160 | |
---|
4161 | void testCubeDDS() |
---|
4162 | { |
---|
4163 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4164 | "../../../../Tests/Media", "FileSystem"); |
---|
4165 | |
---|
4166 | MaterialPtr mat = MaterialManager::getSingleton().create("testcube", |
---|
4167 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4168 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4169 | p->setLightingEnabled(false); |
---|
4170 | TextureUnitState* t = p->createTextureUnitState(); |
---|
4171 | t->setTextureName("grace_cube.dds", TEX_TYPE_CUBE_MAP); |
---|
4172 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
4173 | t->setEnvironmentMap(true, TextureUnitState::ENV_REFLECTION); |
---|
4174 | Entity* e = mSceneMgr->createEntity("1", "sphere.mesh"); |
---|
4175 | e->setMaterialName(mat->getName()); |
---|
4176 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4177 | |
---|
4178 | mCamera->setPosition(300,0,0); |
---|
4179 | mCamera->lookAt(Vector3::ZERO); |
---|
4180 | |
---|
4181 | } |
---|
4182 | |
---|
4183 | void testDxt1() |
---|
4184 | { |
---|
4185 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4186 | "../../../../Tests/Media", "FileSystem"); |
---|
4187 | |
---|
4188 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4189 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4190 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4191 | p->setLightingEnabled(false); |
---|
4192 | p->setCullingMode(CULL_NONE); |
---|
4193 | TextureUnitState* t = p->createTextureUnitState("BumpyMetal_dxt1.dds"); |
---|
4194 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4195 | e->setMaterialName(mat->getName()); |
---|
4196 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4197 | |
---|
4198 | mCamera->setPosition(0,0,-300); |
---|
4199 | mCamera->lookAt(Vector3::ZERO); |
---|
4200 | |
---|
4201 | } |
---|
4202 | void testDxt1FromMemory() |
---|
4203 | { |
---|
4204 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4205 | "../../../../Tests/Media", "FileSystem"); |
---|
4206 | |
---|
4207 | DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource("BumpyMetal_dxt1.dds"); |
---|
4208 | // manually load into image |
---|
4209 | Image img; |
---|
4210 | img.load(stream, "dds"); |
---|
4211 | TextureManager::getSingleton().loadImage("testdxtfrommem", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, img); |
---|
4212 | |
---|
4213 | |
---|
4214 | |
---|
4215 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4216 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4217 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4218 | p->setLightingEnabled(false); |
---|
4219 | p->setCullingMode(CULL_NONE); |
---|
4220 | TextureUnitState* t = p->createTextureUnitState("testdxtfrommem"); |
---|
4221 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4222 | e->setMaterialName(mat->getName()); |
---|
4223 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4224 | |
---|
4225 | mCamera->setPosition(0,0,-300); |
---|
4226 | mCamera->lookAt(Vector3::ZERO); |
---|
4227 | |
---|
4228 | } |
---|
4229 | void testDxt1Alpha() |
---|
4230 | { |
---|
4231 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4232 | "../../../../Tests/Media", "FileSystem"); |
---|
4233 | |
---|
4234 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4235 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4236 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4237 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4238 | p->setAlphaRejectSettings(CMPF_GREATER, 128); |
---|
4239 | p->setLightingEnabled(false); |
---|
4240 | p->setCullingMode(CULL_NONE); |
---|
4241 | TextureUnitState* t = p->createTextureUnitState("gras_02_dxt1.dds"); |
---|
4242 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4243 | e->setMaterialName(mat->getName()); |
---|
4244 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4245 | |
---|
4246 | mCamera->setPosition(0,0,300); |
---|
4247 | mCamera->lookAt(Vector3::ZERO); |
---|
4248 | |
---|
4249 | } |
---|
4250 | void testDxt3() |
---|
4251 | { |
---|
4252 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4253 | "../../../../Tests/Media", "FileSystem"); |
---|
4254 | |
---|
4255 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4256 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4257 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4258 | p->setLightingEnabled(false); |
---|
4259 | p->setCullingMode(CULL_NONE); |
---|
4260 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4261 | TextureUnitState* t = p->createTextureUnitState("ogreborderUp_dxt3.dds"); |
---|
4262 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4263 | e->setMaterialName(mat->getName()); |
---|
4264 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4265 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4266 | |
---|
4267 | mCamera->setPosition(0,0,300); |
---|
4268 | mCamera->lookAt(Vector3::ZERO); |
---|
4269 | |
---|
4270 | } |
---|
4271 | void testDxt3FromMemory() |
---|
4272 | { |
---|
4273 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4274 | "../../../../Tests/Media", "FileSystem"); |
---|
4275 | |
---|
4276 | DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource("ogreborderUp_dxt3.dds"); |
---|
4277 | // manually load into image |
---|
4278 | Image img; |
---|
4279 | img.load(stream, "dds"); |
---|
4280 | TextureManager::getSingleton().loadImage("testdxtfrommem", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, img); |
---|
4281 | |
---|
4282 | |
---|
4283 | |
---|
4284 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4285 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4286 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4287 | p->setLightingEnabled(false); |
---|
4288 | p->setCullingMode(CULL_NONE); |
---|
4289 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4290 | TextureUnitState* t = p->createTextureUnitState("testdxtfrommem"); |
---|
4291 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4292 | e->setMaterialName(mat->getName()); |
---|
4293 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4294 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4295 | |
---|
4296 | mCamera->setPosition(0,0,300); |
---|
4297 | mCamera->lookAt(Vector3::ZERO); |
---|
4298 | |
---|
4299 | } |
---|
4300 | void testDxt5() |
---|
4301 | { |
---|
4302 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4303 | "../../../../Tests/Media", "FileSystem"); |
---|
4304 | |
---|
4305 | MaterialPtr mat = MaterialManager::getSingleton().create("testdxt", |
---|
4306 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4307 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4308 | p->setLightingEnabled(false); |
---|
4309 | p->setCullingMode(CULL_NONE); |
---|
4310 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4311 | TextureUnitState* t = p->createTextureUnitState("ogreborderUp_dxt5.dds"); |
---|
4312 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4313 | e->setMaterialName(mat->getName()); |
---|
4314 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4315 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4316 | |
---|
4317 | mCamera->setPosition(0,0,300); |
---|
4318 | mCamera->lookAt(Vector3::ZERO); |
---|
4319 | |
---|
4320 | } |
---|
4321 | void testFloat64DDS() |
---|
4322 | { |
---|
4323 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4324 | "../../../../Tests/Media", "FileSystem"); |
---|
4325 | |
---|
4326 | MaterialPtr mat = MaterialManager::getSingleton().create("testdds", |
---|
4327 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4328 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4329 | p->setLightingEnabled(false); |
---|
4330 | p->setCullingMode(CULL_NONE); |
---|
4331 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4332 | TextureUnitState* t = p->createTextureUnitState("ogreborderUp_float64.dds"); |
---|
4333 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4334 | e->setMaterialName(mat->getName()); |
---|
4335 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4336 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4337 | |
---|
4338 | mCamera->setPosition(0,0,300); |
---|
4339 | mCamera->lookAt(Vector3::ZERO); |
---|
4340 | |
---|
4341 | } |
---|
4342 | void testFloat128DDS() |
---|
4343 | { |
---|
4344 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4345 | "../../../../Tests/Media", "FileSystem"); |
---|
4346 | |
---|
4347 | MaterialPtr mat = MaterialManager::getSingleton().create("testdds", |
---|
4348 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4349 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4350 | p->setLightingEnabled(false); |
---|
4351 | p->setCullingMode(CULL_NONE); |
---|
4352 | p->setSceneBlending(SBT_TRANSPARENT_ALPHA); |
---|
4353 | TextureUnitState* t = p->createTextureUnitState("ogreborderUp_float128.dds"); |
---|
4354 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4355 | e->setMaterialName(mat->getName()); |
---|
4356 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4357 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4358 | |
---|
4359 | mCamera->setPosition(0,0,300); |
---|
4360 | mCamera->lookAt(Vector3::ZERO); |
---|
4361 | |
---|
4362 | } |
---|
4363 | void testFloat16DDS() |
---|
4364 | { |
---|
4365 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4366 | "../../../../Tests/Media", "FileSystem"); |
---|
4367 | |
---|
4368 | MaterialPtr mat = MaterialManager::getSingleton().create("testdds", |
---|
4369 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4370 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4371 | p->setLightingEnabled(false); |
---|
4372 | p->setCullingMode(CULL_NONE); |
---|
4373 | TextureUnitState* t = p->createTextureUnitState("BumpyMetal_float16.dds"); |
---|
4374 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4375 | e->setMaterialName(mat->getName()); |
---|
4376 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4377 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4378 | |
---|
4379 | mCamera->setPosition(0,0,300); |
---|
4380 | mCamera->lookAt(Vector3::ZERO); |
---|
4381 | |
---|
4382 | } |
---|
4383 | void testFloat32DDS() |
---|
4384 | { |
---|
4385 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4386 | "../../../../Tests/Media", "FileSystem"); |
---|
4387 | |
---|
4388 | MaterialPtr mat = MaterialManager::getSingleton().create("testdds", |
---|
4389 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4390 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4391 | p->setLightingEnabled(false); |
---|
4392 | p->setCullingMode(CULL_NONE); |
---|
4393 | TextureUnitState* t = p->createTextureUnitState("BumpyMetal_float32.dds"); |
---|
4394 | Entity *e = mSceneMgr->createEntity("Plane", SceneManager::PT_PLANE); |
---|
4395 | e->setMaterialName(mat->getName()); |
---|
4396 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
4397 | mWindow->getViewport(0)->setBackgroundColour(ColourValue::Red); |
---|
4398 | |
---|
4399 | mCamera->setPosition(0,0,300); |
---|
4400 | mCamera->lookAt(Vector3::ZERO); |
---|
4401 | |
---|
4402 | } |
---|
4403 | |
---|
4404 | |
---|
4405 | |
---|
4406 | void testRibbonTrail() |
---|
4407 | { |
---|
4408 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
4409 | Vector3 dir(-1, -1, 0.5); |
---|
4410 | dir.normalise(); |
---|
4411 | Light* l = mSceneMgr->createLight("light1"); |
---|
4412 | l->setType(Light::LT_DIRECTIONAL); |
---|
4413 | l->setDirection(dir); |
---|
4414 | |
---|
4415 | NameValuePairList pairList; |
---|
4416 | pairList["numberOfChains"] = "2"; |
---|
4417 | pairList["maxElements"] = "80"; |
---|
4418 | RibbonTrail* trail = static_cast<RibbonTrail*>( |
---|
4419 | mSceneMgr->createMovableObject("1", "RibbonTrail", &pairList)); |
---|
4420 | trail->setMaterialName("Examples/LightRibbonTrail"); |
---|
4421 | trail->setTrailLength(400); |
---|
4422 | |
---|
4423 | |
---|
4424 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(trail); |
---|
4425 | |
---|
4426 | // Create 3 nodes for trail to follow |
---|
4427 | SceneNode* animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
4428 | animNode->setPosition(0,20,0); |
---|
4429 | Animation* anim = mSceneMgr->createAnimation("an1", 10); |
---|
4430 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
4431 | NodeAnimationTrack* track = anim->createNodeTrack(1, animNode); |
---|
4432 | TransformKeyFrame* kf = track->createNodeKeyFrame(0); |
---|
4433 | kf->setTranslate(Vector3::ZERO); |
---|
4434 | kf = track->createNodeKeyFrame(2); |
---|
4435 | kf->setTranslate(Vector3(100, 0, 0)); |
---|
4436 | kf = track->createNodeKeyFrame(4); |
---|
4437 | kf->setTranslate(Vector3(200, 0, 300)); |
---|
4438 | kf = track->createNodeKeyFrame(6); |
---|
4439 | kf->setTranslate(Vector3(0, 20, 500)); |
---|
4440 | kf = track->createNodeKeyFrame(8); |
---|
4441 | kf->setTranslate(Vector3(-100, 10, 100)); |
---|
4442 | kf = track->createNodeKeyFrame(10); |
---|
4443 | kf->setTranslate(Vector3::ZERO); |
---|
4444 | |
---|
4445 | AnimationState* animState = mSceneMgr->createAnimationState("an1"); |
---|
4446 | animState->setEnabled(true); |
---|
4447 | mAnimStateList.push_back(animState); |
---|
4448 | |
---|
4449 | trail->addNode(animNode); |
---|
4450 | trail->setInitialColour(0, 1.0, 0.8, 0); |
---|
4451 | trail->setColourChange(0, 0.5, 0.5, 0.5, 0.5); |
---|
4452 | trail->setInitialWidth(0, 5); |
---|
4453 | |
---|
4454 | // Add light |
---|
4455 | Light* l2 = mSceneMgr->createLight("l2"); |
---|
4456 | l2->setDiffuseColour(trail->getInitialColour(0)); |
---|
4457 | animNode->attachObject(l2); |
---|
4458 | |
---|
4459 | // Add billboard |
---|
4460 | BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1); |
---|
4461 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0)); |
---|
4462 | bbs->setMaterialName("Examples/Flare"); |
---|
4463 | animNode->attachObject(bbs); |
---|
4464 | |
---|
4465 | animNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
4466 | animNode->setPosition(-50,10,0); |
---|
4467 | anim = mSceneMgr->createAnimation("an2", 10); |
---|
4468 | anim->setInterpolationMode(Animation::IM_SPLINE); |
---|
4469 | track = anim->createNodeTrack(1, animNode); |
---|
4470 | kf = track->createNodeKeyFrame(0); |
---|
4471 | kf->setTranslate(Vector3::ZERO); |
---|
4472 | kf = track->createNodeKeyFrame(2); |
---|
4473 | kf->setTranslate(Vector3(-100, 150, -30)); |
---|
4474 | kf = track->createNodeKeyFrame(4); |
---|
4475 | kf->setTranslate(Vector3(-200, 0, 40)); |
---|
4476 | kf = track->createNodeKeyFrame(6); |
---|
4477 | kf->setTranslate(Vector3(0, -150, 70)); |
---|
4478 | kf = track->createNodeKeyFrame(8); |
---|
4479 | kf->setTranslate(Vector3(50, 0, 30)); |
---|
4480 | kf = track->createNodeKeyFrame(10); |
---|
4481 | kf->setTranslate(Vector3::ZERO); |
---|
4482 | |
---|
4483 | animState = mSceneMgr->createAnimationState("an2"); |
---|
4484 | animState->setEnabled(true); |
---|
4485 | mAnimStateList.push_back(animState); |
---|
4486 | |
---|
4487 | trail->addNode(animNode); |
---|
4488 | trail->setInitialColour(1, 0.0, 1.0, 0.4); |
---|
4489 | trail->setColourChange(1, 0.5, 0.5, 0.5, 0.5); |
---|
4490 | trail->setInitialWidth(1, 5); |
---|
4491 | |
---|
4492 | |
---|
4493 | // Add light |
---|
4494 | l2 = mSceneMgr->createLight("l3"); |
---|
4495 | l2->setDiffuseColour(trail->getInitialColour(1)); |
---|
4496 | animNode->attachObject(l2); |
---|
4497 | |
---|
4498 | // Add billboard |
---|
4499 | bbs = mSceneMgr->createBillboardSet("bb2", 1); |
---|
4500 | bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1)); |
---|
4501 | bbs->setMaterialName("Examples/Flare"); |
---|
4502 | animNode->attachObject(bbs); |
---|
4503 | |
---|
4504 | |
---|
4505 | |
---|
4506 | //mSceneMgr->showBoundingBoxes(true); |
---|
4507 | |
---|
4508 | } |
---|
4509 | |
---|
4510 | void testBlendDiffuseColour() |
---|
4511 | { |
---|
4512 | MaterialPtr mat = MaterialManager::getSingleton().create( |
---|
4513 | "testBlendDiffuseColour", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4514 | Pass* pass = mat->getTechnique(0)->getPass(0); |
---|
4515 | // no lighting, it will mess up vertex colours |
---|
4516 | pass->setLightingEnabled(false); |
---|
4517 | // Make sure we pull in vertex colour as diffuse |
---|
4518 | pass->setVertexColourTracking(TVC_DIFFUSE); |
---|
4519 | // Base layer |
---|
4520 | TextureUnitState* t = pass->createTextureUnitState("BeachStones.jpg"); |
---|
4521 | // don't want to bring in vertex diffuse on base layer |
---|
4522 | t->setColourOperation(LBO_REPLACE); |
---|
4523 | // Second layer (lerp based on colour) |
---|
4524 | t = pass->createTextureUnitState("terr_dirt-grass.jpg"); |
---|
4525 | t->setColourOperationEx(LBX_BLEND_DIFFUSE_COLOUR); |
---|
4526 | // third layer (lerp based on alpha) |
---|
4527 | ManualObject* man = mSceneMgr->createManualObject("quad"); |
---|
4528 | man->begin("testBlendDiffuseColour"); |
---|
4529 | man->position(-100, 100, 0); |
---|
4530 | man->textureCoord(0,0); |
---|
4531 | man->colour(0, 0, 0); |
---|
4532 | man->position(-100, -100, 0); |
---|
4533 | man->textureCoord(0,1); |
---|
4534 | man->colour(0.5, 0.5, 0.5); |
---|
4535 | man->position(100, -100, 0); |
---|
4536 | man->textureCoord(1,1); |
---|
4537 | man->colour(1, 1, 1); |
---|
4538 | man->position(100, 100, 0); |
---|
4539 | man->textureCoord(1,0); |
---|
4540 | man->colour(0.5, 0.5, 0.5); |
---|
4541 | man->quad(0, 1, 2, 3); |
---|
4542 | man->end(); |
---|
4543 | |
---|
4544 | mSceneMgr->getRootSceneNode()->attachObject(man); |
---|
4545 | |
---|
4546 | } |
---|
4547 | |
---|
4548 | void testSplitPassesTooManyTexUnits() |
---|
4549 | { |
---|
4550 | MaterialPtr mat = MaterialManager::getSingleton().create( |
---|
4551 | "Test", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4552 | |
---|
4553 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4554 | p->createTextureUnitState("gras_02.png"); |
---|
4555 | p->createTextureUnitState("gras_02.png"); |
---|
4556 | p->createTextureUnitState("gras_02.png"); |
---|
4557 | p->createTextureUnitState("gras_02.png"); |
---|
4558 | p->createTextureUnitState("gras_02.png"); |
---|
4559 | p->createTextureUnitState("gras_02.png"); |
---|
4560 | p->createTextureUnitState("gras_02.png"); |
---|
4561 | p->createTextureUnitState("gras_02.png"); |
---|
4562 | p->createTextureUnitState("gras_02.png"); |
---|
4563 | |
---|
4564 | mat->compile(); |
---|
4565 | |
---|
4566 | } |
---|
4567 | |
---|
4568 | void testCustomProjectionMatrix() |
---|
4569 | { |
---|
4570 | testLotsAndLotsOfEntities(); |
---|
4571 | Matrix4 mat = mCamera->getProjectionMatrix(); |
---|
4572 | mCamera->setCustomProjectionMatrix(true, mat); |
---|
4573 | mat = mCamera->getProjectionMatrix(); |
---|
4574 | |
---|
4575 | } |
---|
4576 | |
---|
4577 | void testPointSprites() |
---|
4578 | { |
---|
4579 | MaterialPtr mat = MaterialManager::getSingleton().create("spriteTest1", |
---|
4580 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4581 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
4582 | p->setPointSpritesEnabled(true); |
---|
4583 | p->createTextureUnitState("flare.png"); |
---|
4584 | p->setLightingEnabled(false); |
---|
4585 | p->setDepthWriteEnabled(false); |
---|
4586 | p->setSceneBlending(SBT_ADD); |
---|
4587 | p->setPointAttenuation(true); |
---|
4588 | p->setPointSize(1); |
---|
4589 | srand((unsigned)time( NULL ) ); |
---|
4590 | |
---|
4591 | ManualObject* man = mSceneMgr->createManualObject("man"); |
---|
4592 | man->begin("spriteTest1", RenderOperation::OT_POINT_LIST); |
---|
4593 | /* |
---|
4594 | for (size_t i = 0; i < 1000; ++i) |
---|
4595 | { |
---|
4596 | man->position(Math::SymmetricRandom() * 500, |
---|
4597 | Math::SymmetricRandom() * 500, |
---|
4598 | Math::SymmetricRandom() * 500); |
---|
4599 | man->colour(Math::RangeRandom(0.5f, 1.0f), |
---|
4600 | Math::RangeRandom(0.5f, 1.0f), Math::RangeRandom(0.5f, 1.0f)); |
---|
4601 | } |
---|
4602 | */ |
---|
4603 | for (size_t i = 0; i < 20; ++i) |
---|
4604 | { |
---|
4605 | for (size_t j = 0; j < 20; ++j) |
---|
4606 | { |
---|
4607 | for (size_t k = 0; k < 20; ++k) |
---|
4608 | { |
---|
4609 | man->position(i * 30, j * 30, k * 30); |
---|
4610 | } |
---|
4611 | } |
---|
4612 | } |
---|
4613 | |
---|
4614 | man->end(); |
---|
4615 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man); |
---|
4616 | |
---|
4617 | } |
---|
4618 | |
---|
4619 | void testSuppressedShadows(ShadowTechnique shadowTech) |
---|
4620 | { |
---|
4621 | mSceneMgr->setShadowTechnique(shadowTech); |
---|
4622 | |
---|
4623 | // Setup lighting |
---|
4624 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
4625 | Light* light = mSceneMgr->createLight("MainLight"); |
---|
4626 | light->setType(Light::LT_DIRECTIONAL); |
---|
4627 | Vector3 dir(-1, -1, 0.5); |
---|
4628 | dir.normalise(); |
---|
4629 | light->setDirection(dir); |
---|
4630 | |
---|
4631 | // Create a skydome |
---|
4632 | //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
4633 | |
---|
4634 | // Create a floor plane mesh |
---|
4635 | Plane plane(Vector3::UNIT_Y, 0.0); |
---|
4636 | MeshManager::getSingleton().createPlane( |
---|
4637 | "FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
4638 | plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z); |
---|
4639 | |
---|
4640 | |
---|
4641 | // Add a floor to the scene |
---|
4642 | Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
4643 | entity->setMaterialName("Examples/RustySteel"); |
---|
4644 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity); |
---|
4645 | entity->setCastShadows(false); |
---|
4646 | |
---|
4647 | // Add the mandatory ogre head |
---|
4648 | entity = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
4649 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity); |
---|
4650 | |
---|
4651 | // Position and orient the camera |
---|
4652 | mCamera->setPosition(-100.0, 50.0, 90.0); |
---|
4653 | mCamera->lookAt(0.0, 10.0, -35.0); |
---|
4654 | |
---|
4655 | // Add an additional viewport on top of the other one |
---|
4656 | Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3); |
---|
4657 | |
---|
4658 | // Create a render queue invocation sequence for the pip viewport |
---|
4659 | RenderQueueInvocationSequence* invocationSequence = |
---|
4660 | mRoot->createRenderQueueInvocationSequence("pip"); |
---|
4661 | |
---|
4662 | // Add an invocation to the sequence |
---|
4663 | RenderQueueInvocation* invocation = |
---|
4664 | invocationSequence->add(RENDER_QUEUE_MAIN, "main"); |
---|
4665 | |
---|
4666 | // Disable render state changes and shadows for that invocation |
---|
4667 | //invocation->setSuppressRenderStateChanges(true); |
---|
4668 | invocation->setSuppressShadows(true); |
---|
4669 | |
---|
4670 | // Set the render queue invocation sequence for the pip viewport |
---|
4671 | pip->setRenderQueueInvocationSequenceName("pip"); |
---|
4672 | } |
---|
4673 | |
---|
4674 | void testViewportNoShadows(ShadowTechnique shadowTech) |
---|
4675 | { |
---|
4676 | mSceneMgr->setShadowTechnique(shadowTech); |
---|
4677 | |
---|
4678 | // Setup lighting |
---|
4679 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
4680 | Light* light = mSceneMgr->createLight("MainLight"); |
---|
4681 | light->setType(Light::LT_DIRECTIONAL); |
---|
4682 | Vector3 dir(-1, -1, 0.5); |
---|
4683 | dir.normalise(); |
---|
4684 | light->setDirection(dir); |
---|
4685 | |
---|
4686 | // Create a skydome |
---|
4687 | //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); |
---|
4688 | |
---|
4689 | // Create a floor plane mesh |
---|
4690 | Plane plane(Vector3::UNIT_Y, 0.0); |
---|
4691 | MeshManager::getSingleton().createPlane( |
---|
4692 | "FloorPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
4693 | plane, 200000, 200000, 20, 20, true, 1, 500, 500, Vector3::UNIT_Z); |
---|
4694 | |
---|
4695 | |
---|
4696 | // Add a floor to the scene |
---|
4697 | Entity* entity = mSceneMgr->createEntity("floor", "FloorPlane"); |
---|
4698 | entity->setMaterialName("Examples/RustySteel"); |
---|
4699 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entity); |
---|
4700 | entity->setCastShadows(false); |
---|
4701 | |
---|
4702 | // Add the mandatory ogre head |
---|
4703 | entity = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
4704 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0.0, 10.0, 0.0))->attachObject(entity); |
---|
4705 | |
---|
4706 | // Position and orient the camera |
---|
4707 | mCamera->setPosition(-100.0, 50.0, 90.0); |
---|
4708 | mCamera->lookAt(0.0, 10.0, -35.0); |
---|
4709 | |
---|
4710 | // Add an additional viewport on top of the other one |
---|
4711 | Viewport* pip = mWindow->addViewport(mCamera, 1, 0.7, 0.0, 0.3, 0.3); |
---|
4712 | pip->setShadowsEnabled(false); |
---|
4713 | |
---|
4714 | } |
---|
4715 | |
---|
4716 | void testSerialisedColour() |
---|
4717 | { |
---|
4718 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
4719 | Vector3 dir(-1, -1, 0.5); |
---|
4720 | dir.normalise(); |
---|
4721 | Light* l = mSceneMgr->createLight("light1"); |
---|
4722 | l->setType(Light::LT_DIRECTIONAL); |
---|
4723 | l->setDirection(dir); |
---|
4724 | |
---|
4725 | Plane plane; |
---|
4726 | plane.normal = Vector3::UNIT_Y; |
---|
4727 | plane.d = 100; |
---|
4728 | MeshManager::getSingleton().createPlane("Myplane", |
---|
4729 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
4730 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
4731 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
4732 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
4733 | pPlaneEnt->setCastShadows(false); |
---|
4734 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
4735 | |
---|
4736 | /* |
---|
4737 | ManualObject* man = static_cast<ManualObject*>( |
---|
4738 | mSceneMgr->createMovableObject("test", ManualObjectFactory::FACTORY_TYPE_NAME)); |
---|
4739 | |
---|
4740 | man->begin("BaseWhiteNoLighting"); |
---|
4741 | // Define a 40x40 plane, non-indexed |
---|
4742 | // Define a 40x40 plane, indexed |
---|
4743 | man->position(-20, 20, 20); |
---|
4744 | man->colour(1, 0, 0); |
---|
4745 | |
---|
4746 | man->position(-20, -20, 20); |
---|
4747 | man->colour(1, 0, 0); |
---|
4748 | |
---|
4749 | man->position(20, -20, 20); |
---|
4750 | man->colour(1, 0, 0); |
---|
4751 | |
---|
4752 | man->position(20, 20, 20); |
---|
4753 | man->colour(1, 0, 0); |
---|
4754 | |
---|
4755 | man->quad(0, 1, 2, 3); |
---|
4756 | man->end(); |
---|
4757 | |
---|
4758 | MeshPtr mesh = man->convertToMesh("colourtest.mesh"); |
---|
4759 | MeshSerializer ms; |
---|
4760 | ms.exportMesh(mesh.getPointer(), "colourtest.mesh"); |
---|
4761 | |
---|
4762 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(man); |
---|
4763 | */ |
---|
4764 | Entity* c = mSceneMgr->createEntity("1", "colourtest.mesh"); |
---|
4765 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(c); |
---|
4766 | |
---|
4767 | |
---|
4768 | |
---|
4769 | } |
---|
4770 | |
---|
4771 | void testBillboardAccurateFacing() |
---|
4772 | { |
---|
4773 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
4774 | Vector3 dir(-1, -1, 0.5); |
---|
4775 | dir.normalise(); |
---|
4776 | Light* l = mSceneMgr->createLight("light1"); |
---|
4777 | l->setType(Light::LT_DIRECTIONAL); |
---|
4778 | l->setDirection(dir); |
---|
4779 | |
---|
4780 | Plane plane; |
---|
4781 | plane.normal = Vector3::UNIT_Y; |
---|
4782 | plane.d = 100; |
---|
4783 | MeshManager::getSingleton().createPlane("Myplane", |
---|
4784 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
4785 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
4786 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
4787 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
4788 | pPlaneEnt->setCastShadows(false); |
---|
4789 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
4790 | |
---|
4791 | BillboardSet* bbs = mSceneMgr->createBillboardSet("1"); |
---|
4792 | bbs->setDefaultDimensions(50,50); |
---|
4793 | bbs->createBillboard(-150, 25, 0); |
---|
4794 | bbs->setBillboardType(BBT_ORIENTED_COMMON); |
---|
4795 | bbs->setCommonDirection(Vector3::UNIT_Y); |
---|
4796 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs); |
---|
4797 | |
---|
4798 | bbs = mSceneMgr->createBillboardSet("2"); |
---|
4799 | bbs->setDefaultDimensions(50,50); |
---|
4800 | bbs->createBillboard(150, 25, 0); |
---|
4801 | bbs->setUseAccurateFacing(true); |
---|
4802 | bbs->setBillboardType(BBT_ORIENTED_COMMON); |
---|
4803 | bbs->setCommonDirection(Vector3::UNIT_Y); |
---|
4804 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs); |
---|
4805 | } |
---|
4806 | |
---|
4807 | void testMultiSceneManagersSimple() |
---|
4808 | { |
---|
4809 | // Create a secondary scene manager with it's own camera |
---|
4810 | SceneManager* sm2 = Root::getSingleton().createSceneManager(ST_GENERIC); |
---|
4811 | camera2 = sm2->createCamera("cam2"); |
---|
4812 | camera2->setPosition(0,0,-500); |
---|
4813 | camera2->lookAt(Vector3::ZERO); |
---|
4814 | Entity* ent = sm2->createEntity("knot2", "knot.mesh"); |
---|
4815 | sm2->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4816 | Light* l = sm2->createLight("l2"); |
---|
4817 | l->setPosition(100,50,-100); |
---|
4818 | l->setDiffuseColour(ColourValue::Green); |
---|
4819 | sm2->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
4820 | |
---|
4821 | Viewport* vp = mWindow->addViewport(camera2, 1, 0.67, 0, 0.33, 0.25); |
---|
4822 | vp->setOverlaysEnabled(false); |
---|
4823 | |
---|
4824 | // Use original SM for normal scene |
---|
4825 | ent = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
4826 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4827 | l = mSceneMgr->createLight("l2"); // note same name, will work since different SM |
---|
4828 | l->setPosition(100,50,-100); |
---|
4829 | l->setDiffuseColour(ColourValue::Red); |
---|
4830 | mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); |
---|
4831 | |
---|
4832 | |
---|
4833 | } |
---|
4834 | |
---|
4835 | void testMultiSceneManagersComplex() |
---|
4836 | { |
---|
4837 | // Create a secondary scene manager with it's own camera |
---|
4838 | SceneManager* sm2 = Root::getSingleton().createSceneManager("TerrainSceneManager"); |
---|
4839 | camera2 = sm2->createCamera("cam2"); |
---|
4840 | |
---|
4841 | Viewport* vp = mWindow->addViewport(camera2, 1, 0.5, 0, 0.5, 0.5); |
---|
4842 | vp->setOverlaysEnabled(false); |
---|
4843 | // Fog |
---|
4844 | // NB it's VERY important to set this before calling setWorldGeometry |
---|
4845 | // because the vertex program picked will be different |
---|
4846 | ColourValue fadeColour(0.93, 0.86, 0.76); |
---|
4847 | sm2->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); |
---|
4848 | vp->setBackgroundColour(fadeColour); |
---|
4849 | |
---|
4850 | sm2->setWorldGeometry("terrain.cfg"); |
---|
4851 | // Infinite far plane? |
---|
4852 | if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE)) |
---|
4853 | { |
---|
4854 | camera2->setFarClipDistance(0); |
---|
4855 | } |
---|
4856 | // Set a nice viewpoint |
---|
4857 | camera2->setPosition(707,3500,528); |
---|
4858 | camera2->lookAt(Vector3::ZERO); |
---|
4859 | camera2->setNearClipDistance( 1 ); |
---|
4860 | camera2->setFarClipDistance( 1000 ); |
---|
4861 | |
---|
4862 | |
---|
4863 | // Create a tertiary scene manager with it's own camera |
---|
4864 | SceneManager* sm3 = Root::getSingleton().createSceneManager("BspSceneManager"); |
---|
4865 | Camera* camera3 = sm3->createCamera("cam3"); |
---|
4866 | |
---|
4867 | vp = mWindow->addViewport(camera3, 2, 0.5, 0.5, 0.5, 0.5); |
---|
4868 | vp->setOverlaysEnabled(false); |
---|
4869 | |
---|
4870 | // Load Quake3 locations from a file |
---|
4871 | ConfigFile cf; |
---|
4872 | |
---|
4873 | cf.load("quake3settings.cfg"); |
---|
4874 | |
---|
4875 | String pk3 = cf.getSetting("Pak0Location"); |
---|
4876 | String level = cf.getSetting("Map"); |
---|
4877 | |
---|
4878 | ExampleApplication::setupResources(); |
---|
4879 | ResourceGroupManager::getSingleton().createResourceGroup("BSP"); |
---|
4880 | ResourceGroupManager::getSingleton().setWorldResourceGroupName("BSP"); |
---|
4881 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
4882 | pk3, "Zip", ResourceGroupManager::getSingleton().getWorldResourceGroupName()); |
---|
4883 | ResourceGroupManager::getSingleton().initialiseResourceGroup("BSP"); |
---|
4884 | sm3->setWorldGeometry(level); |
---|
4885 | // modify camera for close work |
---|
4886 | camera3->setNearClipDistance(4); |
---|
4887 | camera3->setFarClipDistance(4000); |
---|
4888 | |
---|
4889 | // Also change position, and set Quake-type orientation |
---|
4890 | // Get random player start point |
---|
4891 | ViewPoint viewp = sm3->getSuggestedViewpoint(true); |
---|
4892 | camera3->setPosition(viewp.position); |
---|
4893 | camera3->pitch(Degree(90)); // Quake uses X/Y horizon, Z up |
---|
4894 | camera3->rotate(viewp.orientation); |
---|
4895 | // Don't yaw along variable axis, causes leaning |
---|
4896 | camera3->setFixedYawAxis(true, Vector3::UNIT_Z); |
---|
4897 | camera3->yaw(Degree(-90)); |
---|
4898 | |
---|
4899 | |
---|
4900 | |
---|
4901 | |
---|
4902 | |
---|
4903 | // Use original SM for normal scene |
---|
4904 | testTextureShadows(SHADOWTYPE_TEXTURE_MODULATIVE); |
---|
4905 | |
---|
4906 | } |
---|
4907 | |
---|
4908 | void testManualBoneMovement(void) |
---|
4909 | { |
---|
4910 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh"); |
---|
4911 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4912 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8)); |
---|
4913 | |
---|
4914 | //ent->setMaterialName("Examples/Rocky"); |
---|
4915 | |
---|
4916 | SkeletonInstance* skel = ent->getSkeleton(); |
---|
4917 | Animation* anim = skel->getAnimation("Walk"); |
---|
4918 | manuallyControlledBone = skel->getBone("Joint10"); |
---|
4919 | manuallyControlledBone->setManuallyControlled(true); |
---|
4920 | anim->destroyNodeTrack(manuallyControlledBone->getHandle()); |
---|
4921 | |
---|
4922 | //AnimationState* animState = ent->getAnimationState("Walk"); |
---|
4923 | //animState->setEnabled(true); |
---|
4924 | |
---|
4925 | |
---|
4926 | |
---|
4927 | } |
---|
4928 | |
---|
4929 | void testMaterialSchemes() |
---|
4930 | { |
---|
4931 | |
---|
4932 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh"); |
---|
4933 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4934 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8)); |
---|
4935 | |
---|
4936 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest", |
---|
4937 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4938 | // default scheme |
---|
4939 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg"); |
---|
4940 | |
---|
4941 | Technique* t = mat->createTechnique(); |
---|
4942 | t->setSchemeName("newscheme"); |
---|
4943 | t->createPass()->createTextureUnitState("rockwall.tga"); |
---|
4944 | ent->setMaterialName("schemetest"); |
---|
4945 | |
---|
4946 | // create a second viewport using alternate scheme |
---|
4947 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25); |
---|
4948 | vp->setMaterialScheme("newscheme"); |
---|
4949 | vp->setOverlaysEnabled(false); |
---|
4950 | |
---|
4951 | } |
---|
4952 | void testMaterialSchemesWithLOD() |
---|
4953 | { |
---|
4954 | |
---|
4955 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh"); |
---|
4956 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4957 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8)); |
---|
4958 | |
---|
4959 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest", |
---|
4960 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
4961 | // default scheme |
---|
4962 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg"); |
---|
4963 | |
---|
4964 | // LOD 0, newscheme |
---|
4965 | Technique* t = mat->createTechnique(); |
---|
4966 | t->setSchemeName("newscheme"); |
---|
4967 | t->createPass()->createTextureUnitState("rockwall.tga"); |
---|
4968 | ent->setMaterialName("schemetest"); |
---|
4969 | |
---|
4970 | // LOD 1, default |
---|
4971 | t = mat->createTechnique(); |
---|
4972 | t->setLodIndex(1); |
---|
4973 | t->createPass()->createTextureUnitState("WeirdEye.png"); |
---|
4974 | |
---|
4975 | // LOD 1, newscheme |
---|
4976 | t = mat->createTechnique(); |
---|
4977 | t->setLodIndex(1); |
---|
4978 | t->createPass()->createTextureUnitState("r2skin.jpg"); |
---|
4979 | t->setSchemeName("newscheme"); |
---|
4980 | |
---|
4981 | Material::LodDistanceList ldl; |
---|
4982 | ldl.push_back(500.0f); |
---|
4983 | mat->setLodLevels(ldl); |
---|
4984 | |
---|
4985 | |
---|
4986 | ent->setMaterialName("schemetest"); |
---|
4987 | |
---|
4988 | // create a second viewport using alternate scheme |
---|
4989 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25); |
---|
4990 | vp->setMaterialScheme("newscheme"); |
---|
4991 | vp->setOverlaysEnabled(false); |
---|
4992 | |
---|
4993 | } |
---|
4994 | void testMaterialSchemesWithMismatchedLOD() |
---|
4995 | { |
---|
4996 | |
---|
4997 | Entity *ent = mSceneMgr->createEntity("robot", "robot.mesh"); |
---|
4998 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
4999 | mSceneMgr->setAmbientLight(ColourValue(0.8, 0.8, 0.8)); |
---|
5000 | |
---|
5001 | MaterialPtr mat = MaterialManager::getSingleton().create("schemetest", |
---|
5002 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5003 | // default scheme |
---|
5004 | mat->getTechnique(0)->getPass(0)->createTextureUnitState("GreenSkin.jpg"); |
---|
5005 | |
---|
5006 | // LOD 0, newscheme |
---|
5007 | Technique* t = mat->createTechnique(); |
---|
5008 | t->setSchemeName("newscheme"); |
---|
5009 | t->createPass()->createTextureUnitState("rockwall.tga"); |
---|
5010 | ent->setMaterialName("schemetest"); |
---|
5011 | |
---|
5012 | // LOD 1, default |
---|
5013 | t = mat->createTechnique(); |
---|
5014 | t->setLodIndex(1); |
---|
5015 | t->createPass()->createTextureUnitState("WeirdEye.png"); |
---|
5016 | |
---|
5017 | // LOD 2, default |
---|
5018 | t = mat->createTechnique(); |
---|
5019 | t->setLodIndex(2); |
---|
5020 | t->createPass()->createTextureUnitState("clouds.jpg"); |
---|
5021 | |
---|
5022 | // LOD 1, newscheme |
---|
5023 | t = mat->createTechnique(); |
---|
5024 | t->setLodIndex(1); |
---|
5025 | t->createPass()->createTextureUnitState("r2skin.jpg"); |
---|
5026 | t->setSchemeName("newscheme"); |
---|
5027 | |
---|
5028 | // No LOD 2 for newscheme! Should fallback on LOD 1 |
---|
5029 | |
---|
5030 | Material::LodDistanceList ldl; |
---|
5031 | ldl.push_back(250.0f); |
---|
5032 | ldl.push_back(500.0f); |
---|
5033 | mat->setLodLevels(ldl); |
---|
5034 | |
---|
5035 | |
---|
5036 | ent->setMaterialName("schemetest"); |
---|
5037 | |
---|
5038 | // create a second viewport using alternate scheme |
---|
5039 | Viewport* vp = mWindow->addViewport(mCamera, 1, 0.75, 0, 0.25, 0.25); |
---|
5040 | vp->setMaterialScheme("newscheme"); |
---|
5041 | vp->setOverlaysEnabled(false); |
---|
5042 | |
---|
5043 | } |
---|
5044 | void testSkeletonAnimationOptimise(void) |
---|
5045 | { |
---|
5046 | mSceneMgr->setShadowTextureSize(512); |
---|
5047 | mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); |
---|
5048 | mSceneMgr->setShadowFarDistance(1500); |
---|
5049 | mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35)); |
---|
5050 | //mSceneMgr->setShadowFarDistance(800); |
---|
5051 | // Set ambient light |
---|
5052 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); |
---|
5053 | |
---|
5054 | mLight = mSceneMgr->createLight("MainLight"); |
---|
5055 | |
---|
5056 | /*/ |
---|
5057 | // Directional test |
---|
5058 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
5059 | Vector3 vec(-1,-1,0); |
---|
5060 | vec.normalise(); |
---|
5061 | mLight->setDirection(vec); |
---|
5062 | /*/ |
---|
5063 | // Point test |
---|
5064 | mLight->setType(Light::LT_POINT); |
---|
5065 | mLight->setPosition(0, 200, 0); |
---|
5066 | //*/ |
---|
5067 | |
---|
5068 | Entity* pEnt; |
---|
5069 | |
---|
5070 | // Hardware animation |
---|
5071 | pEnt = mSceneMgr->createEntity( "1", "robot.mesh" ); |
---|
5072 | mAnimState = pEnt->getAnimationState("Walk"); |
---|
5073 | mAnimState->setEnabled(true); |
---|
5074 | mTestNode[0] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5075 | mTestNode[0]->attachObject( pEnt ); |
---|
5076 | mTestNode[0]->translate(+100,-100,0); |
---|
5077 | |
---|
5078 | // Software animation |
---|
5079 | pEnt = mSceneMgr->createEntity( "2", "robot.mesh" ); |
---|
5080 | pEnt->setMaterialName("BaseWhite"); |
---|
5081 | /*/ |
---|
5082 | mAnimState = pEnt->getAnimationState("Walk"); |
---|
5083 | mAnimState->setEnabled(true); |
---|
5084 | /*/ |
---|
5085 | pEnt->getAnimationState("Walk")->setEnabled(true); |
---|
5086 | //*/ |
---|
5087 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5088 | mTestNode[1]->attachObject( pEnt ); |
---|
5089 | mTestNode[1]->translate(-100,-100,0); |
---|
5090 | |
---|
5091 | |
---|
5092 | Plane plane; |
---|
5093 | plane.normal = Vector3::UNIT_Y; |
---|
5094 | plane.d = 100; |
---|
5095 | MeshManager::getSingleton().createPlane("Myplane", |
---|
5096 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5097 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
5098 | Entity* pPlaneEnt; |
---|
5099 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5100 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
5101 | pPlaneEnt->setCastShadows(false); |
---|
5102 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5103 | } |
---|
5104 | |
---|
5105 | void testBuildTangentOnAnimatedMesh(void) |
---|
5106 | { |
---|
5107 | //mSceneMgr->setShadowTextureSize(512); |
---|
5108 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); |
---|
5109 | //mSceneMgr->setShadowFarDistance(1500); |
---|
5110 | //mSceneMgr->setShadowColour(ColourValue(0.35, 0.35, 0.35)); |
---|
5111 | //mSceneMgr->setShadowFarDistance(800); |
---|
5112 | // Set ambient light |
---|
5113 | mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); |
---|
5114 | |
---|
5115 | mLight = mSceneMgr->createLight("MainLight"); |
---|
5116 | |
---|
5117 | /*/ |
---|
5118 | // Directional test |
---|
5119 | mLight->setType(Light::LT_DIRECTIONAL); |
---|
5120 | Vector3 vec(-1,-1,0); |
---|
5121 | vec.normalise(); |
---|
5122 | mLight->setDirection(vec); |
---|
5123 | /*/ |
---|
5124 | // Point test |
---|
5125 | mLight->setType(Light::LT_POINT); |
---|
5126 | mLight->setPosition(0, 200, 0); |
---|
5127 | //*/ |
---|
5128 | MeshPtr pMesh = MeshManager::getSingleton().load("ninja.mesh", |
---|
5129 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME/*, |
---|
5130 | HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, |
---|
5131 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, |
---|
5132 | true, true*/); //so we can still read it |
---|
5133 | // Build tangent vectors, all our meshes use only 1 texture coordset |
---|
5134 | unsigned short src, dest; |
---|
5135 | if (!pMesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) |
---|
5136 | { |
---|
5137 | pMesh->buildTangentVectors(VES_TANGENT, src, dest); |
---|
5138 | } |
---|
5139 | |
---|
5140 | Entity* pEnt = mSceneMgr->createEntity("Ninja", "ninja.mesh"); |
---|
5141 | |
---|
5142 | /*/ |
---|
5143 | mAnimState = pEnt->getAnimationState("Walk"); |
---|
5144 | mAnimState->setEnabled(true); |
---|
5145 | /*/ |
---|
5146 | pEnt->getAnimationState("Walk")->setEnabled(true); |
---|
5147 | //*/ |
---|
5148 | mTestNode[1] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5149 | mTestNode[1]->attachObject( pEnt ); |
---|
5150 | mTestNode[1]->translate(-100,-100,0); |
---|
5151 | |
---|
5152 | |
---|
5153 | Plane plane; |
---|
5154 | plane.normal = Vector3::UNIT_Y; |
---|
5155 | plane.d = 100; |
---|
5156 | MeshManager::getSingleton().createPlane("Myplane", |
---|
5157 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5158 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
5159 | Entity* pPlaneEnt; |
---|
5160 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5161 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
5162 | pPlaneEnt->setCastShadows(false); |
---|
5163 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5164 | } |
---|
5165 | void testVertexTexture() |
---|
5166 | { |
---|
5167 | |
---|
5168 | // NOTE: DirectX only right now |
---|
5169 | |
---|
5170 | Light* l = mSceneMgr->createLight("MainLight"); |
---|
5171 | l->setType(Light::LT_POINT); |
---|
5172 | l->setPosition(0, 200, 0); |
---|
5173 | |
---|
5174 | |
---|
5175 | // Create single-channel floating point texture, no mips |
---|
5176 | TexturePtr tex = TextureManager::getSingleton().createManual( |
---|
5177 | "vertexTexture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, |
---|
5178 | 128, 128, 0, PF_FLOAT32_R); |
---|
5179 | float* pData = static_cast<float*>( |
---|
5180 | tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD)); |
---|
5181 | // write concentric circles into the texture |
---|
5182 | for (int y = -64; y < 64; ++y) |
---|
5183 | { |
---|
5184 | for (int x = -64; x < 64; ++x) |
---|
5185 | { |
---|
5186 | |
---|
5187 | float val = Math::Sqrt(x*x + y*y); |
---|
5188 | // repeat every 20 pixels |
---|
5189 | val = val * Math::TWO_PI / 20.0f; |
---|
5190 | *pData++ = Math::Sin(val); |
---|
5191 | } |
---|
5192 | } |
---|
5193 | tex->getBuffer()->unlock(); |
---|
5194 | |
---|
5195 | String progSource = |
---|
5196 | "void main(\n" |
---|
5197 | "float4 pos : POSITION,\n" |
---|
5198 | "float2 uv1 : TEXCOORD0,\n" |
---|
5199 | "uniform float4x4 world, \n" |
---|
5200 | "uniform float4x4 viewProj,\n" |
---|
5201 | "uniform float heightscale,\n" |
---|
5202 | "uniform sampler2D heightmap,\n" |
---|
5203 | "out float4 oPos : POSITION,\n" |
---|
5204 | "out float2 oUv1 : TEXCOORD1,\n" |
---|
5205 | "out float4 col : COLOR)\n" |
---|
5206 | "{\n" |
---|
5207 | "oPos = mul(world, pos);\n" |
---|
5208 | "// tex2Dlod since no mip\n" |
---|
5209 | "float4 t = float4(0,0,0,0);\n" |
---|
5210 | "t.xy = uv1.xy;\n" |
---|
5211 | "float height = tex2Dlod(heightmap, t);\n" |
---|
5212 | "oPos.y = oPos.y + (height * heightscale);\n" |
---|
5213 | "oPos = mul(viewProj, oPos);\n" |
---|
5214 | "oUv1 = uv1;\n" |
---|
5215 | "col = float4(1,1,1,1);\n" |
---|
5216 | "}\n"; |
---|
5217 | HighLevelGpuProgramPtr prog = HighLevelGpuProgramManager::getSingleton().createProgram( |
---|
5218 | "TestVertexTextureFetch", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
5219 | "hlsl", GPT_VERTEX_PROGRAM); |
---|
5220 | prog->setSource(progSource); |
---|
5221 | prog->setParameter("target", "vs_3_0"); |
---|
5222 | prog->setVertexTextureFetchRequired(true); |
---|
5223 | prog->setParameter("entry_point", "main"); |
---|
5224 | prog->load(); |
---|
5225 | |
---|
5226 | |
---|
5227 | MaterialPtr mat = MaterialManager::getSingleton().create("TestVertexTexture", |
---|
5228 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5229 | Pass* pass = mat->getTechnique(0)->getPass(0); |
---|
5230 | pass->setLightingEnabled(false); |
---|
5231 | pass->setVertexProgram("TestVertexTextureFetch"); |
---|
5232 | GpuProgramParametersSharedPtr vp = pass->getVertexProgramParameters(); |
---|
5233 | vp->setNamedAutoConstant("world", GpuProgramParameters::ACT_WORLD_MATRIX); |
---|
5234 | vp->setNamedAutoConstant("viewProj", GpuProgramParameters::ACT_VIEWPROJ_MATRIX); |
---|
5235 | vp->setNamedConstant("heightscale", 30.0f); |
---|
5236 | // vertex texture |
---|
5237 | TextureUnitState* t = pass->createTextureUnitState("vertexTexture"); |
---|
5238 | t->setBindingType(TextureUnitState::BT_VERTEX); |
---|
5239 | // regular texture |
---|
5240 | pass->createTextureUnitState("BumpyMetal.jpg"); |
---|
5241 | |
---|
5242 | Plane plane; |
---|
5243 | plane.normal = Vector3::UNIT_Y; |
---|
5244 | plane.d = 100; |
---|
5245 | // 128 x 128 segment plane |
---|
5246 | MeshManager::getSingleton().createPlane("Myplane", |
---|
5247 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5248 | 1500,1500,128,128,true,1,1,1,Vector3::UNIT_Z); |
---|
5249 | Entity* pPlaneEnt; |
---|
5250 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5251 | pPlaneEnt->setMaterialName("TestVertexTexture"); |
---|
5252 | pPlaneEnt->setCastShadows(false); |
---|
5253 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5254 | |
---|
5255 | |
---|
5256 | } |
---|
5257 | |
---|
5258 | void testBackgroundLoadResourceGroup() |
---|
5259 | { |
---|
5260 | ResourceGroupManager& rgm = ResourceGroupManager::getSingleton(); |
---|
5261 | TextureManager& tm = TextureManager::getSingleton(); |
---|
5262 | MeshManager& mm = MeshManager::getSingleton(); |
---|
5263 | |
---|
5264 | testBackgroundLoadGroup = "Deferred"; |
---|
5265 | |
---|
5266 | rgm.createResourceGroup(testBackgroundLoadGroup); |
---|
5267 | |
---|
5268 | // define a bunch of textures as deferred loading |
---|
5269 | rgm.declareResource("egyptrockyfull.jpg", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5270 | rgm.declareResource("fw12b.jpg", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5271 | rgm.declareResource("grass_1024.jpg", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5272 | rgm.declareResource("GreenSkin.jpg", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5273 | rgm.declareResource("MtlPlat2.jpg", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5274 | rgm.declareResource("NMBumpsOut.png", tm.getResourceType(), testBackgroundLoadGroup); |
---|
5275 | rgm.declareResource("ogrehead.mesh", mm.getResourceType(), testBackgroundLoadGroup); |
---|
5276 | // Note: initialise resource group in main thread for this test |
---|
5277 | // We will be able to initialise in the background thread too eventually, |
---|
5278 | // once resources can be created thread safely as well as loaded |
---|
5279 | rgm.initialiseResourceGroup(testBackgroundLoadGroup); |
---|
5280 | |
---|
5281 | // we won't load it yet, we'll wait for 5 seconds |
---|
5282 | |
---|
5283 | |
---|
5284 | // Create a basic plane to have something in the scene to look at |
---|
5285 | Plane plane; |
---|
5286 | plane.normal = Vector3::UNIT_Y; |
---|
5287 | plane.d = 100; |
---|
5288 | MeshManager::getSingleton().createPlane("Myplane", |
---|
5289 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5290 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
5291 | Entity* pPlaneEnt; |
---|
5292 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5293 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
5294 | pPlaneEnt->setCastShadows(false); |
---|
5295 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5296 | |
---|
5297 | |
---|
5298 | |
---|
5299 | |
---|
5300 | } |
---|
5301 | |
---|
5302 | |
---|
5303 | |
---|
5304 | void testOverlayRelativeMode() |
---|
5305 | { |
---|
5306 | |
---|
5307 | Overlay* o = OverlayManager::getSingleton().create("Test"); |
---|
5308 | OverlayContainer* c = (OverlayContainer*)OverlayManager::getSingleton().createOverlayElement("Panel", "panel1"); |
---|
5309 | c->setMetricsMode(GMM_RELATIVE); |
---|
5310 | c->setDimensions(1.0, 1.0); |
---|
5311 | c->setMaterialName("Core/StatsBlockCenter"); |
---|
5312 | c->setPosition(0.0, 0.0); |
---|
5313 | |
---|
5314 | TextAreaOverlayElement* t = (TextAreaOverlayElement*)OverlayManager::getSingleton().createOverlayElement("TextArea", "text1"); |
---|
5315 | t->setMetricsMode(GMM_RELATIVE); |
---|
5316 | t->setCaption("Hello"); |
---|
5317 | t->setPosition(0,0); |
---|
5318 | t->setFontName("BlueHighway"); |
---|
5319 | t->setDimensions(0.2, 0.5); |
---|
5320 | t->setCharHeight(0.2); |
---|
5321 | c->addChild(t); |
---|
5322 | |
---|
5323 | o->add2D(c); |
---|
5324 | o->show(); |
---|
5325 | |
---|
5326 | } |
---|
5327 | |
---|
5328 | void testBillboardOrigins() |
---|
5329 | { |
---|
5330 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); |
---|
5331 | Vector3 dir(-1, -1, 0.5); |
---|
5332 | dir.normalise(); |
---|
5333 | Light* l = mSceneMgr->createLight("light1"); |
---|
5334 | l->setType(Light::LT_DIRECTIONAL); |
---|
5335 | l->setDirection(dir); |
---|
5336 | |
---|
5337 | Plane plane; |
---|
5338 | plane.normal = Vector3::UNIT_Y; |
---|
5339 | plane.d = 0; |
---|
5340 | MeshManager::getSingleton().createPlane("Myplane", |
---|
5341 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5342 | 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z); |
---|
5343 | Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5344 | pPlaneEnt->setMaterialName("2 - Default"); |
---|
5345 | pPlaneEnt->setCastShadows(false); |
---|
5346 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5347 | |
---|
5348 | BillboardSet* bbs = mSceneMgr->createBillboardSet("1"); |
---|
5349 | bbs->setDefaultDimensions(50,50); |
---|
5350 | bbs->createBillboard(0, 0, 0); |
---|
5351 | bbs->setBillboardOrigin(BBO_TOP_LEFT); |
---|
5352 | //bbs->setBillboardType(BBT_ORIENTED_COMMON); |
---|
5353 | bbs->setCommonDirection(Vector3::UNIT_Y); |
---|
5354 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(bbs); |
---|
5355 | |
---|
5356 | } |
---|
5357 | |
---|
5358 | void testDepthBias() |
---|
5359 | { |
---|
5360 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
5361 | "../../../../Tests/Media", "FileSystem"); |
---|
5362 | |
---|
5363 | mSceneMgr->setAmbientLight(ColourValue::White); |
---|
5364 | |
---|
5365 | MaterialPtr mat = MaterialManager::getSingleton().create("mat1", |
---|
5366 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5367 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
5368 | p->createTextureUnitState("BumpyMetal.jpg"); |
---|
5369 | |
---|
5370 | const String meshName("cube.mesh"); |
---|
5371 | Entity* entity = mSceneMgr->createEntity("base", meshName); |
---|
5372 | entity->setMaterialName("mat1"); |
---|
5373 | mSceneMgr->getRootSceneNode()->attachObject(entity); |
---|
5374 | |
---|
5375 | |
---|
5376 | entity = mSceneMgr->createEntity("base2", meshName); |
---|
5377 | entity->setMaterialName("Examples/EnvMappedRustySteel"); |
---|
5378 | SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5379 | n->setPosition(-30, 0, 0); |
---|
5380 | n->yaw(Degree(45)); |
---|
5381 | n->attachObject(entity); |
---|
5382 | |
---|
5383 | for (size_t i = 0; i <= 6;++i) |
---|
5384 | { |
---|
5385 | String name("decal"); |
---|
5386 | name += StringConverter::toString(i); |
---|
5387 | |
---|
5388 | MaterialPtr pMat = static_cast<MaterialPtr>(MaterialManager::getSingleton().create( |
---|
5389 | name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)); |
---|
5390 | |
---|
5391 | pMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
5392 | pMat->getTechnique(0)->getPass(0)->setAlphaRejectSettings(CMPF_GREATER_EQUAL, 128); |
---|
5393 | pMat->getTechnique(0)->getPass(0)->setDepthBias(i); |
---|
5394 | pMat->getTechnique(0)->getPass(0)->createTextureUnitState(name + ".png"); |
---|
5395 | |
---|
5396 | entity = mSceneMgr->createEntity(name, meshName); |
---|
5397 | entity->setMaterialName(name); |
---|
5398 | mSceneMgr->getRootSceneNode()->attachObject(entity); |
---|
5399 | } |
---|
5400 | |
---|
5401 | |
---|
5402 | |
---|
5403 | mCamera->setPosition(0,0,200); |
---|
5404 | mCamera->lookAt(Vector3::ZERO); |
---|
5405 | |
---|
5406 | |
---|
5407 | } |
---|
5408 | |
---|
5409 | |
---|
5410 | void testTextureShadowsIntegrated() |
---|
5411 | { |
---|
5412 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); |
---|
5413 | //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); |
---|
5414 | MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC); |
---|
5415 | MaterialManager::getSingleton().setDefaultAnisotropy(5); |
---|
5416 | |
---|
5417 | mSceneMgr->setShadowTextureSettings(1024, 2); |
---|
5418 | |
---|
5419 | mSceneMgr->setAmbientLight(ColourValue::Black); |
---|
5420 | Light* l = mSceneMgr->createLight("Spot1"); |
---|
5421 | l->setType(Light::LT_SPOTLIGHT); |
---|
5422 | l->setAttenuation(5000,1,0,0); |
---|
5423 | l->setSpotlightRange(Degree(30),Degree(45),1.0f); |
---|
5424 | SceneNode* lightNode1 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5425 | lightNode1->attachObject(l); |
---|
5426 | lightNode1->setPosition(400, 250, 500); |
---|
5427 | lightNode1->lookAt(Vector3(0,-200,0), Node::TS_WORLD); |
---|
5428 | l->setDirection(Vector3::NEGATIVE_UNIT_Z); |
---|
5429 | l->setDiffuseColour(0.7, 0.7, 0.5); |
---|
5430 | |
---|
5431 | l = mSceneMgr->createLight("Spot2"); |
---|
5432 | l->setAttenuation(5000,1,0,0); |
---|
5433 | /* // spotlight */ |
---|
5434 | l->setType(Light::LT_SPOTLIGHT); |
---|
5435 | l->setSpotlightRange(Degree(30),Degree(45),1.0f); |
---|
5436 | /**/ |
---|
5437 | // point |
---|
5438 | SceneNode* lightNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5439 | lightNode2->attachObject(l); |
---|
5440 | lightNode2->setPosition(-500, 200, 500); |
---|
5441 | lightNode2->lookAt(Vector3(0,-200,0), Node::TS_WORLD); |
---|
5442 | l->setDirection(Vector3::NEGATIVE_UNIT_Z); |
---|
5443 | /* // directional |
---|
5444 | l->setType(Light::LT_DIRECTIONAL); |
---|
5445 | Vector3 dir(0.5, -1, 0.5); |
---|
5446 | dir.normalise(); |
---|
5447 | l->setDirection(dir); |
---|
5448 | */ |
---|
5449 | l->setDiffuseColour(1, 0.2, 0.2); |
---|
5450 | |
---|
5451 | /* |
---|
5452 | // Test spot 3 |
---|
5453 | l = mSceneMgr->createLight("Spot3"); |
---|
5454 | l->setType(Light::LT_SPOTLIGHT); |
---|
5455 | l->setAttenuation(5000,1,0,0); |
---|
5456 | l->setSpotlightRange(Degree(30),Degree(45),1.0f); |
---|
5457 | SceneNode* lightNode3 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5458 | lightNode3->attachObject(l); |
---|
5459 | lightNode3->setPosition(700, 250, 500); |
---|
5460 | lightNode3->lookAt(Vector3(0,-200,0), Node::TS_WORLD); |
---|
5461 | l->setDirection(Vector3::NEGATIVE_UNIT_Z); |
---|
5462 | l->setDiffuseColour(0.0, 0.7, 1.0); |
---|
5463 | */ |
---|
5464 | |
---|
5465 | // Create a basic plane to have something in the scene to look at |
---|
5466 | Plane plane; |
---|
5467 | plane.normal = Vector3::UNIT_Y; |
---|
5468 | plane.d = 100; |
---|
5469 | MeshPtr msh = MeshManager::getSingleton().createPlane("Myplane", |
---|
5470 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, |
---|
5471 | 4500,4500,100,100,true,1,40,40,Vector3::UNIT_Z); |
---|
5472 | msh->buildTangentVectors(VES_TANGENT); |
---|
5473 | Entity* pPlaneEnt; |
---|
5474 | pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); |
---|
5475 | //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular"); |
---|
5476 | pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows"); |
---|
5477 | pPlaneEnt->setCastShadows(false); |
---|
5478 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); |
---|
5479 | |
---|
5480 | pPlaneEnt = mSceneMgr->createEntity( "plane2", "Myplane" ); |
---|
5481 | //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular"); |
---|
5482 | pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows"); |
---|
5483 | pPlaneEnt->setCastShadows(false); |
---|
5484 | SceneNode* n = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5485 | n->roll(Degree(90)); |
---|
5486 | n->translate(100,0,0); |
---|
5487 | //n->attachObject(pPlaneEnt); |
---|
5488 | |
---|
5489 | pPlaneEnt = mSceneMgr->createEntity( "plane3", "Myplane" ); |
---|
5490 | //pPlaneEnt->setMaterialName("Examples/OffsetMapping/Specular"); |
---|
5491 | pPlaneEnt->setMaterialName("Examples/OffsetMapping/IntegratedShadows"); |
---|
5492 | pPlaneEnt->setCastShadows(false); |
---|
5493 | n = mSceneMgr->getRootSceneNode()->createChildSceneNode(); |
---|
5494 | n->pitch(Degree(90)); |
---|
5495 | n->yaw(Degree(-90)); |
---|
5496 | n->translate(0,0,-100); |
---|
5497 | n->attachObject(pPlaneEnt); |
---|
5498 | |
---|
5499 | mCamera->setPosition(-50, 500, 1000); |
---|
5500 | mCamera->lookAt(Vector3(-50,-100,0)); |
---|
5501 | |
---|
5502 | Entity* ent = mSceneMgr->createEntity("athene", "athene.mesh"); |
---|
5503 | ent->setMaterialName("Examples/Athene/NormalMapped"); |
---|
5504 | mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,-20,0))->attachObject(ent); |
---|
5505 | |
---|
5506 | //addTextureShadowDebugOverlay(2); |
---|
5507 | |
---|
5508 | |
---|
5509 | |
---|
5510 | } |
---|
5511 | |
---|
5512 | void testTimeCreateDestroyObject() |
---|
5513 | { |
---|
5514 | int iterationCount = 100000; |
---|
5515 | |
---|
5516 | // Create names ahead of time |
---|
5517 | StringVector nameList; |
---|
5518 | nameList.reserve(iterationCount); |
---|
5519 | for (int i = 0; i < iterationCount; ++i) |
---|
5520 | { |
---|
5521 | nameList.push_back("somerelativelylongtestname" + StringConverter::toString(i)); |
---|
5522 | } |
---|
5523 | |
---|
5524 | Timer timer; |
---|
5525 | StringVector::iterator nameIt = nameList.begin(); |
---|
5526 | timer.reset(); |
---|
5527 | for (int i = 0; i < iterationCount; ++i, ++nameIt) |
---|
5528 | { |
---|
5529 | ManualObject* man = mSceneMgr->createManualObject(*nameIt); |
---|
5530 | } |
---|
5531 | unsigned long createTime = timer.getMilliseconds(); |
---|
5532 | |
---|
5533 | nameIt = nameList.begin(); |
---|
5534 | timer.reset(); |
---|
5535 | for (int i = 0; i < iterationCount; ++i, ++nameIt) |
---|
5536 | { |
---|
5537 | ManualObject* man = mSceneMgr->getManualObject(*nameIt); |
---|
5538 | // do something so compiler doesn't think I'm doing nothing |
---|
5539 | man->setVisible(true); |
---|
5540 | } |
---|
5541 | unsigned long lookupTime = timer.getMilliseconds(); |
---|
5542 | |
---|
5543 | nameIt = nameList.begin(); |
---|
5544 | timer.reset(); |
---|
5545 | for (int i = 0; i < iterationCount; ++i, ++nameIt) |
---|
5546 | { |
---|
5547 | mSceneMgr->destroyManualObject(*nameIt); |
---|
5548 | } |
---|
5549 | unsigned long destroyTime = timer.getMilliseconds(); |
---|
5550 | |
---|
5551 | nameIt = nameList.begin(); |
---|
5552 | timer.reset(); |
---|
5553 | for (int i = 0; i < iterationCount; ++i, ++nameIt) |
---|
5554 | { |
---|
5555 | mSceneMgr->createSceneNode(*nameIt); |
---|
5556 | } |
---|
5557 | unsigned long sncreateTime = timer.getMilliseconds(); |
---|
5558 | |
---|
5559 | nameIt = nameList.begin(); |
---|
5560 | timer.reset(); |
---|
5561 | for (int i = 0; i < iterationCount; ++i, ++nameIt) |
---|
5562 | { |
---|
5563 | mSceneMgr->destroySceneNode(*nameIt); |
---|
5564 | } |
---|
5565 | unsigned long sndestroyTime = timer.getMilliseconds(); |
---|
5566 | |
---|
5567 | StringUtil::StrStreamType str; |
---|
5568 | str << "Object create time: " << ((float)createTime / 1000.0f) << " secs" << std::endl; |
---|
5569 | str << "Object lookup time: " << ((float)lookupTime / 1000.0f) << " secs" << std::endl; |
---|
5570 | str << "Object destroy time: " << ((float)destroyTime / 1000.0f) << " secs" << std::endl; |
---|
5571 | str << "SceneNode create time: " << ((float)sncreateTime / 1000.0f) << " secs" << std::endl; |
---|
5572 | str << "SceneNode destroy time: " << ((float)sndestroyTime / 1000.0f) << " secs" << std::endl; |
---|
5573 | LogManager::getSingleton().logMessage(str.str()); |
---|
5574 | |
---|
5575 | |
---|
5576 | } |
---|
5577 | |
---|
5578 | |
---|
5579 | void testMRT() |
---|
5580 | { |
---|
5581 | TexturePtr Tex[2]; |
---|
5582 | MultiRenderTarget* mrtTex; |
---|
5583 | |
---|
5584 | Viewport* viewport = mWindow->getViewport(0); |
---|
5585 | uint width = viewport->getActualWidth(); |
---|
5586 | uint height = viewport->getActualHeight(); |
---|
5587 | |
---|
5588 | Tex[0] = TextureManager::getSingleton().createManual("diffusemap", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, |
---|
5589 | width,height,0,PF_R8G8B8A8,TU_RENDERTARGET); |
---|
5590 | Tex[1] = TextureManager::getSingleton().createManual("normalmap",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, |
---|
5591 | width,height,0,PF_R8G8B8A8,TU_RENDERTARGET); |
---|
5592 | |
---|
5593 | // assert(Tex[0]->getFormat() == PF_FLOAT16_RGBA); |
---|
5594 | |
---|
5595 | mrtTex = Ogre::Root::getSingleton().getRenderSystem()->createMultiRenderTarget("MRT"); |
---|
5596 | RenderTexture* rTex[2]; |
---|
5597 | rTex[0] = Tex[0]->getBuffer()->getRenderTarget(); |
---|
5598 | rTex[1] = Tex[1]->getBuffer()->getRenderTarget(); |
---|
5599 | |
---|
5600 | rTex[0]->setAutoUpdated(false); |
---|
5601 | rTex[1]->setAutoUpdated(false); |
---|
5602 | mrtTex->bindSurface(0, rTex[0]); |
---|
5603 | mrtTex->bindSurface(1, rTex[1]); |
---|
5604 | mrtTex->setAutoUpdated(true); |
---|
5605 | |
---|
5606 | Viewport *v = mrtTex->addViewport(mCamera); |
---|
5607 | v->setMaterialScheme("MRT"); |
---|
5608 | v->setClearEveryFrame(true); |
---|
5609 | v->setOverlaysEnabled(false); |
---|
5610 | v->setSkiesEnabled(false); |
---|
5611 | v->setBackgroundColour(ColourValue(0,0,0,0)); |
---|
5612 | |
---|
5613 | // Create texture overlay here |
---|
5614 | Overlay *debugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); |
---|
5615 | MaterialPtr debugMat = MaterialManager::getSingleton().create("DebugRTTMat1", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5616 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
5617 | TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("normalmap"); |
---|
5618 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
5619 | OverlayContainer *debugPanel = (OverlayContainer *) (OverlayManager::getSingleton().createOverlayElement("Panel","DebugRTTPanel1")); |
---|
5620 | debugPanel->_setPosition(0.8,0); |
---|
5621 | debugPanel->_setDimensions(0.2,0.3); |
---|
5622 | debugPanel->setMaterialName(debugMat->getName()); |
---|
5623 | debugOverlay->add2D(debugPanel); |
---|
5624 | |
---|
5625 | debugMat = MaterialManager::getSingleton().create("DebugRTTMat2", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5626 | debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); |
---|
5627 | t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState("diffusemap"); |
---|
5628 | t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); |
---|
5629 | debugPanel = (OverlayContainer *) (OverlayManager::getSingleton().createOverlayElement("Panel","DebugRTTPanel2")); |
---|
5630 | debugPanel->_setPosition(0.8,0.3); |
---|
5631 | debugPanel->_setDimensions(0.2,0.3); |
---|
5632 | debugPanel->setMaterialName(debugMat->getName()); |
---|
5633 | debugOverlay->add2D(debugPanel); |
---|
5634 | // Create scene items |
---|
5635 | |
---|
5636 | // Create a material to render differently to MRT compared to main viewport |
---|
5637 | MaterialPtr mat = MaterialManager::getSingleton().create("MRTTest", |
---|
5638 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5639 | // normal technique (0), leave as default |
---|
5640 | Technique* mrtTech = mat->createTechnique(); |
---|
5641 | mrtTech->setSchemeName("MRT"); |
---|
5642 | Pass* mrtPass = mrtTech->createPass(); |
---|
5643 | mrtPass->setVertexProgram("DeferredShading/material/hlsl/vs"); |
---|
5644 | mrtPass->setFragmentProgram("DeferredShading/material/hlsl/ps"); |
---|
5645 | mrtPass->createTextureUnitState("rockwall.tga"); |
---|
5646 | mat->load(); |
---|
5647 | |
---|
5648 | Entity* ent = mSceneMgr->createEntity("knot", "knot.mesh"); |
---|
5649 | ent->setMaterialName("MRTTest"); |
---|
5650 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); |
---|
5651 | |
---|
5652 | mCamera->setPosition(0, 0, 200); |
---|
5653 | mCamera->lookAt(Vector3::ZERO); |
---|
5654 | |
---|
5655 | |
---|
5656 | |
---|
5657 | } |
---|
5658 | |
---|
5659 | void test16Textures() |
---|
5660 | { |
---|
5661 | |
---|
5662 | HighLevelGpuProgramPtr frag; |
---|
5663 | if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL*")) |
---|
5664 | { |
---|
5665 | frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
5666 | "glsl", GPT_FRAGMENT_PROGRAM); |
---|
5667 | frag->setSource(" \ |
---|
5668 | uniform sampler2D tex0; \ |
---|
5669 | uniform sampler2D tex1; \ |
---|
5670 | uniform sampler2D tex2; \ |
---|
5671 | uniform sampler2D tex3; \ |
---|
5672 | uniform sampler2D tex4; \ |
---|
5673 | uniform sampler2D tex5; \ |
---|
5674 | uniform sampler2D tex6; \ |
---|
5675 | uniform sampler2D tex7; \ |
---|
5676 | uniform sampler2D tex8; \ |
---|
5677 | uniform sampler2D tex9; \ |
---|
5678 | uniform sampler2D tex10; \ |
---|
5679 | uniform sampler2D tex11; \ |
---|
5680 | uniform sampler2D tex12; \ |
---|
5681 | uniform sampler2D tex13; \ |
---|
5682 | uniform sampler2D tex14; \ |
---|
5683 | uniform sampler2D tex15; \ |
---|
5684 | void main() \ |
---|
5685 | { \ |
---|
5686 | gl_FragColor = texture2D(tex15, gl_TexCoord[0].xy); \ |
---|
5687 | } \ |
---|
5688 | "); |
---|
5689 | |
---|
5690 | } |
---|
5691 | else |
---|
5692 | { |
---|
5693 | // DirectX |
---|
5694 | frag = HighLevelGpuProgramManager::getSingleton().createProgram("frag16", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
---|
5695 | "hlsl", GPT_FRAGMENT_PROGRAM); |
---|
5696 | frag->setParameter("target", "ps_2_0"); |
---|
5697 | frag->setParameter("entry_point", "main"); |
---|
5698 | frag->setSource(" \ |
---|
5699 | float4 main( \ |
---|
5700 | float2 uv : TEXCOORD0, \ |
---|
5701 | uniform sampler2D tex0 : register(s0), \ |
---|
5702 | uniform sampler2D tex1 : register(s1), \ |
---|
5703 | uniform sampler2D tex2 : register(s2), \ |
---|
5704 | uniform sampler2D tex3 : register(s3), \ |
---|
5705 | uniform sampler2D tex4 : register(s4), \ |
---|
5706 | uniform sampler2D tex5 : register(s5), \ |
---|
5707 | uniform sampler2D tex6 : register(s6), \ |
---|
5708 | uniform sampler2D tex7 : register(s7), \ |
---|
5709 | uniform sampler2D tex8 : register(s8), \ |
---|
5710 | uniform sampler2D tex9 : register(s9), \ |
---|
5711 | uniform sampler2D tex10 : register(s10), \ |
---|
5712 | uniform sampler2D tex11 : register(s11), \ |
---|
5713 | uniform sampler2D tex12 : register(s12), \ |
---|
5714 | uniform sampler2D tex13 : register(s13), \ |
---|
5715 | uniform sampler2D tex14 : register(s14), \ |
---|
5716 | uniform sampler2D tex15 : register(s15) \ |
---|
5717 | ) : COLOR \ |
---|
5718 | { \ |
---|
5719 | return tex2D(tex15, uv); \ |
---|
5720 | } \ |
---|
5721 | "); |
---|
5722 | } |
---|
5723 | frag->load(); |
---|
5724 | |
---|
5725 | MaterialPtr mat = MaterialManager::getSingleton().create("test16", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
---|
5726 | Pass* p = mat->getTechnique(0)->getPass(0); |
---|
5727 | p->setVertexProgram("Ogre/BasicVertexPrograms/AmbientOneTextureUnified"); |
---|
5728 | p->setFragmentProgram(frag->getName()); |
---|
5729 | // create 15 textures the same |
---|
5730 | for (int i = 0; i < 15; ++i) |
---|
5731 | { |
---|
5732 | p->createTextureUnitState("Dirt.jpg"); |
---|
5733 | } |
---|
5734 | // create 16th texture differently |
---|
5735 | p->createTextureUnitState("ogrelogo.png"); |
---|
5736 | if (StringUtil::match(Root::getSingleton().getRenderSystem()->getName(), "*GL*")) |
---|
5737 | { |
---|
5738 | // map samplers |
---|
5739 | GpuProgramParametersSharedPtr params = p->getFragmentProgramParameters(); |
---|
5740 | for (int i = 0; i < 16; ++i) |
---|
5741 | { |
---|
5742 | params->setNamedConstant(String("tex") + StringConverter::toString(i), i); |
---|
5743 | } |
---|
5744 | |
---|
5745 | } |
---|
5746 | |
---|
5747 | mat->load(); |
---|
5748 | |
---|
5749 | Entity* e = mSceneMgr->createEntity("1", "knot.mesh"); |
---|
5750 | e->setMaterialName(mat->getName()); |
---|
5751 | mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e); |
---|
5752 | |
---|
5753 | mCamera->setPosition(0,0,200); |
---|
5754 | mCamera->lookAt(0,0,0); |
---|
5755 | |
---|
5756 | |
---|
5757 | } |
---|
5758 | struct Foo; |
---|
5759 | typedef Ogre::SharedPtr<Foo> FooPtr; |
---|
5760 | struct Foo { FooPtr ptr; }; |
---|
5761 | |
---|
5762 | void createScene(void) |
---|
5763 | { |
---|
5764 | // In main() or someplace: |
---|
5765 | FooPtr foo(new Foo); |
---|
5766 | foo->ptr.bind(new Foo); |
---|
5767 | foo = foo->ptr; |
---|
5768 | // foo now contains a wild pointer! |
---|
5769 | // Just override the mandatory create scene method |
---|
5770 | ErrorDialog e; |
---|
5771 | |
---|
5772 | MeshPtr m; |
---|
5773 | ResourcePtr p = m; |
---|
5774 | |
---|
5775 | Real d = std::numeric_limits<Real>::infinity(); |
---|
5776 | d = std::max(1e10f, d); |
---|
5777 | d = std::min(1e5f, d); |
---|
5778 | /* |
---|
5779 | AnyNumeric anyInt1(43); |
---|
5780 | AnyNumeric anyInt2(5); |
---|
5781 | AnyNumeric anyInt3 = anyInt1 + anyInt2; |
---|
5782 | |
---|
5783 | bool tst = StringConverter::isNumber("3"); |
---|
5784 | tst = StringConverter::isNumber("-0.3"); |
---|
5785 | tst = StringConverter::isNumber(""); |
---|
5786 | tst = StringConverter::isNumber(" "); |
---|
5787 | tst = StringConverter::isNumber(" -0.3 "); |
---|
5788 | tst = StringConverter::isNumber(" a-0.3 "); |
---|
5789 | |
---|
5790 | const StringVector& l = mCamera->getAnimableValueNames(); |
---|
5791 | |
---|
5792 | std::cout << anyInt3; |
---|
5793 | |
---|
5794 | //Any anyString("test"); |
---|
5795 | */ |
---|
5796 | |
---|
5797 | //testMatrices(); |
---|
5798 | //testBsp(); |
---|
5799 | //testAlpha(); |
---|
5800 | //testAnimation(); |
---|
5801 | //testAnimationBlend(); |
---|
5802 | |
---|
5803 | //testGpuPrograms(); |
---|
5804 | //testMultiViewports(); |
---|
5805 | //testDistortion(); |
---|
5806 | //testEdgeBuilderSingleIndexBufSingleVertexBuf(); |
---|
5807 | //testEdgeBuilderMultiIndexBufSingleVertexBuf(); |
---|
5808 | //testEdgeBuilderMultiIndexBufMultiVertexBuf(); |
---|
5809 | //testPrepareShadowVolume(); |
---|
5810 | //testWindowedViewportMode(); |
---|
5811 | //testSubEntityVisibility(); |
---|
5812 | //testAttachObjectsToBones(); |
---|
5813 | //testSkeletalAnimation(); |
---|
5814 | //testOrtho(); |
---|
5815 | //testClearScene(); |
---|
5816 | //testInfiniteAAB(); |
---|
5817 | |
---|
5818 | //testProjection(); |
---|
5819 | //testStencilShadows(SHADOWTYPE_STENCIL_ADDITIVE, true, true); |
---|
5820 | //testStencilShadows(SHADOWTYPE_STENCIL_MODULATIVE, false, true); |
---|
5821 | //testTextureShadows(SHADOWTYPE_TEXTURE_ADDITIVE); |
---|
5822 | //testTextureShadows(SHADOWTYPE_TEXTURE_MODULATIVE); |
---|
5823 | //testTextureShadowsIntegrated(); |
---|
5824 | //testStencilShadowsMixedOpSubMeshes(false, true); |
---|
5825 | |
---|
5826 | //testTextureShadowsCustomCasterMat(SHADOWTYPE_TEXTURE_ADDITIVE); |
---|
5827 | //testTextureShadowsCustomReceiverMat(SHADOWTYPE_TEXTURE_MODULATIVE); |
---|
5828 | //testCompositorTextureShadows(SHADOWTYPE_TEXTURE_MODULATIVE); |
---|
5829 | //testSplitPassesTooManyTexUnits(); |
---|
5830 | //testOverlayZOrder(); |
---|
5831 | //testReflectedBillboards(); |
---|
5832 | //testBlendDiffuseColour(); |
---|
5833 | |
---|
5834 | //testRaySceneQuery(); |
---|
5835 | //testMaterialSerializer(); |
---|
5836 | //testIntersectionSceneQuery(); |
---|
5837 | |
---|
5838 | //test2Spotlights(); |
---|
5839 | //testDepthBias(); |
---|
5840 | |
---|
5841 | //testManualLOD(); |
---|
5842 | //testGeneratedLOD(); |
---|
5843 | //testLotsAndLotsOfEntities(); |
---|
5844 | //testSimpleMesh(); |
---|
5845 | //test2Windows(); |
---|
5846 | //testStaticGeometry(); |
---|
5847 | //testBillboardTextureCoords(); |
---|
5848 | //testBillboardOrigins(); |
---|
5849 | //testReloadResources(); |
---|
5850 | //testTransparencyMipMaps(); |
---|
5851 | //testRadixSort(); |
---|
5852 | //testMorphAnimation(); |
---|
5853 | //testPoseAnimation(); |
---|
5854 | //testPoseAnimation2(); |
---|
5855 | //testBug(); |
---|
5856 | //test16Textures(); |
---|
5857 | //testProjectSphere(); |
---|
5858 | //testTimeCreateDestroyObject(); |
---|
5859 | //testManualBlend(); |
---|
5860 | //testManualObjectNonIndexed(); |
---|
5861 | //testManualObjectIndexed(); |
---|
5862 | //testManualObjectNonIndexedUpdateSmaller(); |
---|
5863 | //testManualObjectNonIndexedUpdateLarger(); |
---|
5864 | //testManualObjectIndexedUpdateSmaller(); |
---|
5865 | //testManualObjectIndexedUpdateLarger(); |
---|
5866 | //testCustomProjectionMatrix(); |
---|
5867 | //testPointSprites(); |
---|
5868 | //testFallbackResourceGroup(); |
---|
5869 | //testSuppressedShadows(SHADOWTYPE_TEXTURE_ADDITIVE); |
---|
5870 | //testViewportNoShadows(SHADOWTYPE_TEXTURE_ADDITIVE); |
---|
5871 | //testBillboardChain(); |
---|
5872 | //testRibbonTrail(); |
---|
5873 | //testSerialisedColour(); |
---|
5874 | //testBillboardAccurateFacing(); |
---|
5875 | //testMultiSceneManagersSimple(); |
---|
5876 | //testMultiSceneManagersComplex(); |
---|
5877 | //testManualBoneMovement(); |
---|
5878 | //testMaterialSchemes(); |
---|
5879 | //testMaterialSchemesWithLOD(); |
---|
5880 | //testMaterialSchemesWithMismatchedLOD(); |
---|
5881 | //testSkeletonAnimationOptimise(); |
---|
5882 | //testBuildTangentOnAnimatedMesh(); |
---|
5883 | //testOverlayRelativeMode(); |
---|
5884 | |
---|
5885 | //testCubeDDS(); |
---|
5886 | //testDxt1(); |
---|
5887 | //testDxt1FromMemory(); |
---|
5888 | testDxt3FromMemory(); |
---|
5889 | //testDxt1Alpha(); |
---|
5890 | //testDxt3(); |
---|
5891 | //testDxt5(); |
---|
5892 | //testFloat64DDS(); |
---|
5893 | //testFloat128DDS(); |
---|
5894 | //testFloat16DDS(); |
---|
5895 | //testFloat32DDS(); |
---|
5896 | |
---|
5897 | //testVertexTexture(); |
---|
5898 | //testGLSLTangent(); |
---|
5899 | //testBackgroundLoadResourceGroup(); |
---|
5900 | //testMRT(); |
---|
5901 | |
---|
5902 | } |
---|
5903 | // Create new frame listener |
---|
5904 | void createFrameListener(void) |
---|
5905 | { |
---|
5906 | mFrameListener= new PlayPenListener(mSceneMgr, mWindow, mCamera); |
---|
5907 | mFrameListener->showDebugOverlay(true); |
---|
5908 | mRoot->addFrameListener(mFrameListener); |
---|
5909 | //mRoot->addFrameListener(fl); |
---|
5910 | |
---|
5911 | } |
---|
5912 | |
---|
5913 | |
---|
5914 | public: |
---|
5915 | void go(void) |
---|
5916 | { |
---|
5917 | if (!setup()) |
---|
5918 | return; |
---|
5919 | |
---|
5920 | mRoot->startRendering(); |
---|
5921 | } |
---|
5922 | |
---|
5923 | bool setup() |
---|
5924 | { |
---|
5925 | String pluginsPath = mResourcePath + "plugins.cfg"; |
---|
5926 | // only use plugins.cfg if not static |
---|
5927 | #ifdef OGRE_STATIC_LIB |
---|
5928 | mRoot = new Root(StringUtil::BLANK, |
---|
5929 | mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log"); |
---|
5930 | mStaticPluginLoader.load(*mRoot); |
---|
5931 | #else |
---|
5932 | mRoot = new Root(pluginsPath, |
---|
5933 | mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log"); |
---|
5934 | #endif |
---|
5935 | setupResources(); |
---|
5936 | |
---|
5937 | bool carryOn = configure(); |
---|
5938 | if (!carryOn) return false; |
---|
5939 | |
---|
5940 | chooseSceneManager(); |
---|
5941 | createCamera(); |
---|
5942 | createViewports(); |
---|
5943 | |
---|
5944 | // Set default mipmap level (NB some APIs ignore this) |
---|
5945 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
5946 | |
---|
5947 | // Create any resource listeners (for loading screens) |
---|
5948 | createResourceListener(); |
---|
5949 | // Load resources |
---|
5950 | loadResources(); |
---|
5951 | |
---|
5952 | // Create the scene |
---|
5953 | createScene(); |
---|
5954 | |
---|
5955 | createFrameListener(); |
---|
5956 | |
---|
5957 | return true; |
---|
5958 | |
---|
5959 | } |
---|
5960 | |
---|
5961 | |
---|
5962 | |
---|
5963 | }; |
---|
5964 | |
---|
5965 | |
---|
5966 | //----------------------------------------------------------------------------- |
---|
5967 | //----------------------------------------------------------------------------- |
---|
5968 | bool gReload; |
---|
5969 | |
---|
5970 | // Listener class for frame updates |
---|
5971 | class MemoryTestFrameListener : public FrameListener |
---|
5972 | { |
---|
5973 | protected: |
---|
5974 | Real time; |
---|
5975 | Keyboard* mKeyboard; |
---|
5976 | public: |
---|
5977 | MemoryTestFrameListener(RenderWindow * win) |
---|
5978 | { |
---|
5979 | time = 0; |
---|
5980 | ParamList pl; |
---|
5981 | size_t windowHnd = 0; |
---|
5982 | std::ostringstream windowHndStr; |
---|
5983 | |
---|
5984 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
5985 | windowHndStr << windowHnd; |
---|
5986 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
5987 | |
---|
5988 | InputManager &im = *InputManager::createInputSystem( pl ); |
---|
5989 | |
---|
5990 | //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) |
---|
5991 | mKeyboard = static_cast<Keyboard*>(im.createInputObject( OISKeyboard, false )); |
---|
5992 | } |
---|
5993 | virtual ~MemoryTestFrameListener() |
---|
5994 | { |
---|
5995 | time = 0; |
---|
5996 | } |
---|
5997 | |
---|
5998 | bool frameStarted(const FrameEvent& evt) |
---|
5999 | { |
---|
6000 | if( mKeyboard->isKeyDown( KC_ESCAPE) ) |
---|
6001 | { |
---|
6002 | gReload = false; |
---|
6003 | return false; |
---|
6004 | } |
---|
6005 | |
---|
6006 | time += evt.timeSinceLastFrame; |
---|
6007 | if(time>5) |
---|
6008 | { |
---|
6009 | LogManager::getSingleton().logMessage("Reloading scene after 5 seconds"); |
---|
6010 | gReload = true; |
---|
6011 | time=0; |
---|
6012 | return false; |
---|
6013 | } |
---|
6014 | else |
---|
6015 | { |
---|
6016 | gReload = false; |
---|
6017 | return true; |
---|
6018 | } |
---|
6019 | } |
---|
6020 | |
---|
6021 | void keyClicked(KeyEvent* e) {}; |
---|
6022 | void keyPressed(KeyEvent* e) {}; |
---|
6023 | void keyReleased(KeyEvent* e) {}; |
---|
6024 | void keyFocusIn(KeyEvent* e) {} |
---|
6025 | void keyFocusOut(KeyEvent* e) {} |
---|
6026 | }; |
---|
6027 | |
---|
6028 | /** Application class */ |
---|
6029 | class MemoryTestApplication : public ExampleApplication |
---|
6030 | { |
---|
6031 | protected: |
---|
6032 | MemoryTestFrameListener * mTestFrameListener; |
---|
6033 | public: |
---|
6034 | |
---|
6035 | void go(void) |
---|
6036 | { |
---|
6037 | mRoot = 0; |
---|
6038 | if (!setup()) |
---|
6039 | return; |
---|
6040 | |
---|
6041 | mRoot->startRendering(); |
---|
6042 | |
---|
6043 | while(gReload) |
---|
6044 | { |
---|
6045 | // clean up |
---|
6046 | destroyScene(); |
---|
6047 | destroyResources(); |
---|
6048 | if (!setup()) |
---|
6049 | return; |
---|
6050 | mRoot->startRendering(); |
---|
6051 | } |
---|
6052 | // clean up |
---|
6053 | destroyScene(); |
---|
6054 | } |
---|
6055 | |
---|
6056 | bool setup(void) |
---|
6057 | { |
---|
6058 | if(!gReload) |
---|
6059 | { |
---|
6060 | String pluginsPath = mResourcePath + "plugins.cfg"; |
---|
6061 | mRoot = new Root(pluginsPath, |
---|
6062 | mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log"); |
---|
6063 | } |
---|
6064 | |
---|
6065 | setupResources(); |
---|
6066 | |
---|
6067 | if(!gReload) |
---|
6068 | { |
---|
6069 | |
---|
6070 | bool carryOn = configure(); |
---|
6071 | if (!carryOn) |
---|
6072 | return false; |
---|
6073 | |
---|
6074 | chooseSceneManager(); |
---|
6075 | createCamera(); |
---|
6076 | createViewports(); |
---|
6077 | |
---|
6078 | // Set default mipmap level (NB some APIs ignore this) |
---|
6079 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
6080 | |
---|
6081 | // Create any resource listeners (for loading screens) |
---|
6082 | createResourceListener(); |
---|
6083 | |
---|
6084 | createFrameListener(); |
---|
6085 | } |
---|
6086 | // Load resources |
---|
6087 | loadResources(); |
---|
6088 | |
---|
6089 | // Create the scene |
---|
6090 | createScene(); |
---|
6091 | |
---|
6092 | return true; |
---|
6093 | |
---|
6094 | } |
---|
6095 | |
---|
6096 | /// Method which will define the source of resources (other than current folder) |
---|
6097 | virtual void setupResources(void) |
---|
6098 | { |
---|
6099 | // Custom setup |
---|
6100 | ResourceGroupManager::getSingleton().createResourceGroup("CustomResourceGroup"); |
---|
6101 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
6102 | "../../../media/ogrehead.zip", "Zip", "CustomResourceGroup"); |
---|
6103 | } |
---|
6104 | void loadResources(void) |
---|
6105 | { |
---|
6106 | // Initialise, parse scripts etc |
---|
6107 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
6108 | } |
---|
6109 | void destroyResources() |
---|
6110 | { |
---|
6111 | LogManager::getSingleton().logMessage("Destroying resources"); |
---|
6112 | ResourceGroupManager::getSingleton().removeResourceLocation( |
---|
6113 | "../../../media/ogrehead.zip"); |
---|
6114 | ResourceGroupManager::getSingleton().destroyResourceGroup("CustomResourceGroup"); |
---|
6115 | } |
---|
6116 | |
---|
6117 | void createScene(void) |
---|
6118 | { |
---|
6119 | // Set a very low level of ambient lighting |
---|
6120 | mSceneMgr->setAmbientLight(ColourValue(0.1, 0.1, 0.1)); |
---|
6121 | |
---|
6122 | // Load ogre head |
---|
6123 | MeshManager::getSingleton().load("ogrehead.mesh","CustomResourceGroup"); |
---|
6124 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
6125 | |
---|
6126 | // Attach the head to the scene |
---|
6127 | mSceneMgr->getRootSceneNode()->attachObject(head); |
---|
6128 | |
---|
6129 | } |
---|
6130 | |
---|
6131 | void createFrameListener(void) |
---|
6132 | { |
---|
6133 | // This is where we instantiate our own frame listener |
---|
6134 | mTestFrameListener= new MemoryTestFrameListener(mWindow); |
---|
6135 | mRoot->addFrameListener(mTestFrameListener); |
---|
6136 | /*if(!gReload) |
---|
6137 | { |
---|
6138 | ExampleApplication::createFrameListener(); |
---|
6139 | }*/ |
---|
6140 | } |
---|
6141 | |
---|
6142 | void destroyScene(void) |
---|
6143 | { |
---|
6144 | LogManager::getSingleton().logMessage("Clearing scene"); |
---|
6145 | mSceneMgr->clearScene(); |
---|
6146 | } |
---|
6147 | }; |
---|
6148 | |
---|
6149 | |
---|
6150 | |
---|
6151 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
6152 | #define WIN32_LEAN_AND_MEAN |
---|
6153 | #include "windows.h" |
---|
6154 | |
---|
6155 | // External embedded window test |
---|
6156 | INT WINAPI EmbeddedMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ); |
---|
6157 | |
---|
6158 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) |
---|
6159 | #else |
---|
6160 | int main(int argc, char **argv) |
---|
6161 | #endif |
---|
6162 | { |
---|
6163 | //EmbeddedMain(hInst, 0, strCmdLine, 0); |
---|
6164 | |
---|
6165 | // Create application object |
---|
6166 | PlayPenApplication app; |
---|
6167 | //MemoryTestApplication app; |
---|
6168 | |
---|
6169 | try { |
---|
6170 | app.go(); |
---|
6171 | } catch( Ogre::Exception& e ) { |
---|
6172 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
6173 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
6174 | #else |
---|
6175 | std::cerr << "An exception has occured: " << e.getFullDescription(); |
---|
6176 | #endif |
---|
6177 | } |
---|
6178 | |
---|
6179 | |
---|
6180 | return 0; |
---|
6181 | } |
---|
6182 | |
---|
6183 | |
---|
6184 | |
---|
6185 | |
---|
6186 | |
---|
6187 | |
---|
6188 | |
---|