source: trunk/VUT/work/TestCulling/SceneContentGenerator.cpp @ 104

Revision 104, 3.3 KB checked in by mattausch, 19 years ago (diff)
Line 
1/**
2    \file
3        SceneContentGenerator.cpp
4    \brief
5        Creates content for a scene.
6*/
7#include "SceneContentGenerator.h"
8
9namespace Ogre {
10
11/*******************************************************/
12/*     SceneContentGenerator implementation            */
13/*******************************************************/
14
15//-----------------------------------------------------------------------
16SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
17mSceneMgr(sm), mCount(0),
18mMinPos(Vector3(-70.0f, -70.0f, 0.0f)),
19mMaxPos(Vector3(70.0f, 70.0f, 600.0f)),
20mMinAngle(Vector3(0.0f, 0.0f, 0.0f)),
21mMaxAngle(Vector3(360, 360, 360)),
22mScale(0.1, 0.1, 0.1)
23{
24}
25//-----------------------------------------------------------------------
26void 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//-----------------------------------------------------------------------
57SceneNode *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);
69        currentObject->setScale(mScale);
70               
71        currentObject->yaw(Degree(rotation.x));
72        currentObject->pitch(Degree(rotation.y));
73        currentObject->roll(Degree(rotation.z));
74
75        return currentObject;
76}
77//-----------------------------------------------------------------------
78void SceneContentGenerator::SetMinAngle(Vector3 minAngle)
79{
80        mMinAngle = minAngle;
81}
82//-----------------------------------------------------------------------
83void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle)
84{
85        mMaxAngle = maxAngle;
86}
87//-----------------------------------------------------------------------
88void SceneContentGenerator::SetMinPos(Vector3 minPos)
89{
90        mMinPos = minPos;
91}
92//-----------------------------------------------------------------------
93void SceneContentGenerator::SetMaxPos(Vector3 maxPos)
94{
95        mMaxPos = maxPos;
96}
97//-----------------------------------------------------------------------
98int SceneContentGenerator::GetObjectCount()
99{
100        return mCount;
101}
102//-----------------------------------------------------------------------
103void SceneContentGenerator::SetScale(Vector3 scale)
104{
105        mScale = scale;
106}
107} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.