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

Revision 82, 3.1 KB checked in by mattausch, 19 years ago (diff)

worked on the demos

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))
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(0.1f, 0.1f, 0.1f);
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];
77        sprintf(msg, "pos: %3.3f %3.3f %3.3f\n", position.x, position.y, position.z);
78        OutputDebugString(msg);
79        */
80
81        return currentObject;
82}
83//-----------------------------------------------------------------------
84void SceneContentGenerator::SetMinAngle(Vector3 minAngle)
85{
86        mMinAngle = minAngle;
87}
88//-----------------------------------------------------------------------
89void SceneContentGenerator::SetMaxAngle(Vector3 maxAngle)
90{
91        mMaxAngle = maxAngle;
92}
93//-----------------------------------------------------------------------
94void SceneContentGenerator::SetMinPos(Vector3 minPos)
95{
96        mMinPos = minPos;
97}
98//-----------------------------------------------------------------------
99void SceneContentGenerator::SetMaxPos(Vector3 maxPos)
100{
101        mMaxPos = maxPos;
102}
103
104} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.