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