/** \file SceneContentGenerator.cpp \brief Creates content for a scene. */ #include "SceneContentGenerator.h" namespace Ogre { /*******************************************************/ /* SceneContentGenerator implementation */ /*******************************************************/ //----------------------------------------------------------------------- SceneContentGenerator::SceneContentGenerator(SceneManager *sm): mSceneMgr(sm), mCount(0), mMinPos(Vector3(-70.0f, -70.0f, 0.0f)), mMaxPos(Vector3(70.0f, 70.0f, 600.0f)), mMinAngle(Vector3(0.0f, 0.0f, 0.0f)), mMaxAngle(Vector3(360, 360, 360)), mScale(0.1, 0.1, 0.1) { } //----------------------------------------------------------------------- void SceneContentGenerator::GenerateScene(int numObjects, const String &objName) { // initialise random generator srand (time(0)); Vector3 rotationRatio; Vector3 translationRatio; int currentCount = mCount; int limit = 0; //-- create random values between zero and one while ((mCount - currentCount < numObjects) && (limit < 50000)) { rotationRatio.x = rand() / (float) RAND_MAX; rotationRatio.y = rand() / (float) RAND_MAX; rotationRatio.z = rand() / (float) RAND_MAX; translationRatio.x = rand() / (float) RAND_MAX; translationRatio.y = rand() / (float) RAND_MAX; translationRatio.z = rand() / (float) RAND_MAX; // Setup the ray scene query Vector3 rotation = mMinAngle + rotationRatio * (mMaxAngle - mMinAngle); Vector3 position = mMinPos + translationRatio * (mMaxPos - mMinPos); (void)GenerateSceneObject(position, rotation, objName); ++limit; // just in case: to avoid endless loop } } //----------------------------------------------------------------------- SceneNode *SceneContentGenerator::GenerateSceneObject(const Vector3 &position, const Vector3 &rotation, const String& objName) { char name[25]; sprintf(name, "Entity%d", mCount++); Entity *ent = mSceneMgr->createEntity(name, objName); SceneNode *currentObject = mSceneMgr->getRootSceneNode()-> createChildSceneNode(String(name) + "Node", position); currentObject->attachObject(ent); currentObject->setScale(mScale); currentObject->yaw(Degree(rotation.x)); currentObject->pitch(Degree(rotation.y)); currentObject->roll(Degree(rotation.z)); /* char msg[100]; sprintf(msg, "pos: %3.3f %3.3f %3.3f\n", position.x, position.y, position.z); OutputDebugString(msg); */ return currentObject; } //----------------------------------------------------------------------- void SceneContentGenerator::SetMinAngle(Vector3 minAngle) { mMinAngle = minAngle; } //----------------------------------------------------------------------- void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle) { mMaxAngle = maxAngle; } //----------------------------------------------------------------------- void SceneContentGenerator::SetMinPos(Vector3 minPos) { mMinPos = minPos; } //----------------------------------------------------------------------- void SceneContentGenerator::SetMaxPos(Vector3 maxPos) { mMaxPos = maxPos; } //----------------------------------------------------------------------- int SceneContentGenerator::GetObjectCount() { return mCount; } //----------------------------------------------------------------------- void SceneContentGenerator::SetScale(Vector3 scale) { mScale = scale; } } // namespace Ogre