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

Revision 87, 3.4 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#include <windows.h>
9
10namespace Ogre {
11
12/*******************************************************/
13/*     SceneContentGenerator implementation            */
14/*******************************************************/
15
16//-----------------------------------------------------------------------
17SceneContentGenerator::SceneContentGenerator(SceneManager *sm):
18mSceneMgr(sm), mCount(0),
19mMinPos(Vector3(-70.0f, -70.0f, 0.0f)),
20mMaxPos(Vector3(70.0f, 70.0f, 600.0f)),
21mMinAngle(Vector3(0.0f, 0.0f, 0.0f)),
22mMaxAngle(Vector3(360, 360, 360)),
23mScale(0.1, 0.1, 0.1)
24{
25}
26//-----------------------------------------------------------------------
27void 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//-----------------------------------------------------------------------
58SceneNode *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);
70        currentObject->setScale(mScale);
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];
78        sprintf(msg, "pos: %3.3f %3.3f %3.3f\n", position.x, position.y, position.z);
79        OutputDebugString(msg);
80        */
81
82        return currentObject;
83}
84//-----------------------------------------------------------------------
85void SceneContentGenerator::SetMinAngle(Vector3 minAngle)
86{
87        mMinAngle = minAngle;
88}
89//-----------------------------------------------------------------------
90void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle)
91{
92        mMaxAngle = maxAngle;
93}
94//-----------------------------------------------------------------------
95void SceneContentGenerator::SetMinPos(Vector3 minPos)
96{
97        mMinPos = minPos;
98}
99//-----------------------------------------------------------------------
100void SceneContentGenerator::SetMaxPos(Vector3 maxPos)
101{
102        mMaxPos = maxPos;
103}
104//-----------------------------------------------------------------------
105int SceneContentGenerator::GetObjectCount()
106{
107        return mCount;
108}
109//-----------------------------------------------------------------------
110void SceneContentGenerator::SetScale(Vector3 scale)
111{
112        mScale = scale;
113}
114} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.