[79] | 1 | /**
|
---|
| 2 | \file
|
---|
| 3 | SceneContentGenerator.cpp
|
---|
| 4 | \brief
|
---|
| 5 | Creates content for a scene.
|
---|
| 6 | */
|
---|
| 7 | #include "SceneContentGenerator.h"
|
---|
| 8 | #include <windows.h>
|
---|
| 9 |
|
---|
| 10 | namespace Ogre {
|
---|
| 11 |
|
---|
| 12 | /*******************************************************/
|
---|
| 13 | /* SceneContentGenerator implementation */
|
---|
| 14 | /*******************************************************/
|
---|
| 15 |
|
---|
| 16 | //-----------------------------------------------------------------------
|
---|
| 17 | SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
|
---|
| 18 | mSceneMgr(sm), mCount(0),
|
---|
| 19 | mMinPos(Vector3(-70.0f, -70.0f, 0.0f)),
|
---|
| 20 | mMaxPos(Vector3(70.0f, 70.0f, 600.0f)),
|
---|
| 21 | mMinAngle(Vector3(0.0f, 0.0f, 0.0f)),
|
---|
[86] | 22 | mMaxAngle(Vector3(360, 360, 360)),
|
---|
[87] | 23 | mScale(0.1, 0.1, 0.1)
|
---|
[79] | 24 | {
|
---|
| 25 | }
|
---|
| 26 | //----------------------------------------------------------------------- |
---|
| 27 | void SceneContentGenerator::GenerateScene(int numObjects, const String &objName) |
---|
| 28 | { |
---|
| 29 | // initialise random generator |
---|
| 30 | srand (time(0)); |
---|
| 31 | |
---|
| 32 | Vector3 rotationRatio; |
---|
| 33 | Vector3 translationRatio; |
---|
| 34 | |
---|
| 35 | int currentCount = mCount; |
---|
| 36 | int limit = 0; |
---|
| 37 | |
---|
| 38 | //-- create random values between zero and one |
---|
| 39 | while ((mCount - currentCount < numObjects) && (limit < 50000)) |
---|
| 40 | { |
---|
| 41 | rotationRatio.x = rand() / (float) RAND_MAX; |
---|
| 42 | rotationRatio.y = rand() / (float) RAND_MAX; |
---|
| 43 | rotationRatio.z = rand() / (float) RAND_MAX; |
---|
| 44 | |
---|
| 45 | translationRatio.x = rand() / (float) RAND_MAX; |
---|
| 46 | translationRatio.y = rand() / (float) RAND_MAX; |
---|
| 47 | translationRatio.z = rand() / (float) RAND_MAX; |
---|
| 48 | |
---|
| 49 | // Setup the ray scene query
|
---|
| 50 | Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle); |
---|
| 51 | Vector3 position = mMinPos + translationRatio * (mMaxPos - mMinPos);
|
---|
| 52 | |
---|
| 53 | (void)GenerateSceneObject(position, rotation, objName); |
---|
| 54 | ++limit; // just in case: to avoid endless loop |
---|
| 55 | } |
---|
| 56 | }
|
---|
| 57 | //-----------------------------------------------------------------------
|
---|
| 58 | SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, |
---|
| 59 | const Vector3 &rotation, const String& objName)
|
---|
| 60 | {
|
---|
| 61 | char name[25];
|
---|
| 62 | sprintf(name, "Entity%d", mCount++);
|
---|
| 63 |
|
---|
| 64 | Entity *ent = mSceneMgr->createEntity(name, objName);
|
---|
| 65 |
|
---|
| 66 | SceneNode *currentObject = mSceneMgr->getRootSceneNode()->
|
---|
| 67 | createChildSceneNode(String(name) + "Node", position);
|
---|
| 68 |
|
---|
| 69 | currentObject->attachObject(ent);
|
---|
[86] | 70 | currentObject->setScale(mScale);
|
---|
[79] | 71 |
|
---|
| 72 | currentObject->yaw(Degree(rotation.x));
|
---|
| 73 | currentObject->pitch(Degree(rotation.y));
|
---|
| 74 | currentObject->roll(Degree(rotation.z));
|
---|
| 75 |
|
---|
| 76 | /*
|
---|
| 77 | char msg[100];
|
---|
[82] | 78 | sprintf(msg, "pos: %3.3f %3.3f %3.3f\n", position.x, position.y, position.z);
|
---|
[79] | 79 | OutputDebugString(msg);
|
---|
| 80 | */
|
---|
[82] | 81 |
|
---|
| 82 | return currentObject;
|
---|
[79] | 83 | }
|
---|
| 84 | //-----------------------------------------------------------------------
|
---|
| 85 | void SceneContentGenerator::SetMinAngle(Vector3 minAngle)
|
---|
| 86 | {
|
---|
| 87 | mMinAngle = minAngle;
|
---|
| 88 | }
|
---|
| 89 | //-----------------------------------------------------------------------
|
---|
| 90 | void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle)
|
---|
| 91 | {
|
---|
| 92 | mMaxAngle = maxAngle;
|
---|
| 93 | }
|
---|
| 94 | //-----------------------------------------------------------------------
|
---|
| 95 | void SceneContentGenerator::SetMinPos(Vector3 minPos)
|
---|
| 96 | {
|
---|
| 97 | mMinPos = minPos;
|
---|
| 98 | }
|
---|
| 99 | //-----------------------------------------------------------------------
|
---|
| 100 | void SceneContentGenerator::SetMaxPos(Vector3 maxPos)
|
---|
| 101 | {
|
---|
| 102 | mMaxPos = maxPos;
|
---|
| 103 | }
|
---|
[85] | 104 | //-----------------------------------------------------------------------
|
---|
| 105 | int SceneContentGenerator::GetObjectCount()
|
---|
| 106 | {
|
---|
| 107 | return mCount;
|
---|
| 108 | }
|
---|
[86] | 109 | //-----------------------------------------------------------------------
|
---|
| 110 | void SceneContentGenerator::SetScale(Vector3 scale)
|
---|
| 111 | {
|
---|
| 112 | mScale = scale;
|
---|
| 113 | }
|
---|
[79] | 114 | } // namespace Ogre |
---|