source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreTerrainContentGenerator.cpp @ 2278

Revision 2278, 3.3 KB checked in by mattausch, 18 years ago (diff)

worked on randomupdatemanager

Line 
1#include "OgreTerrainContentGenerator.h"
2
3
4namespace Ogre {
5
6/*************************************************/
7/*         RayQueryExecutor implementation       */
8/*************************************************/
9
10//-----------------------------------------------------------------------
11RayQueryExecutor::RayQueryExecutor(SceneManager *sm)
12{
13        mRaySceneQuery = sm->createRayQuery(Ray());
14}
15//-----------------------------------------------------------------------
16RayQueryExecutor::~RayQueryExecutor()
17{
18        OGRE_DELETE(mRaySceneQuery);
19}
20//-----------------------------------------------------------------------
21bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Vector3 &pos,
22                                                                           const Vector3 &dir)
23{
24        return executeRayQuery(result, Ray(pos, dir));
25}
26//-----------------------------------------------------------------------
27bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Ray &ray)
28{
29    mRaySceneQuery->setRay(ray);
30
31    // Perform the scene query
32    RaySceneQueryResult &queryResult = mRaySceneQuery->execute();
33    RaySceneQueryResult::iterator it = queryResult.begin();
34
35        if (it != queryResult.end() && it->worldFragment)
36        {
37                SceneQuery::WorldFragment* wf = it->worldFragment;
38
39                *result = wf->singleIntersection;
40                return true;
41        }
42
43        return false;
44}
45
46
47/*******************************************************/
48/*     TerrainContentGenerator implementation          */
49/*******************************************************/
50
51//-----------------------------------------------------------------------
52TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm):
53SceneContentGenerator(sm), mOffset(0)
54{
55        mMinPos = Vector3(0.0f, MAX_HEIGHT, 0.0f);
56        mMaxPos = Vector3(3000.0f, MAX_HEIGHT, 3000.0f);
57
58        mMinAngle = Vector3(0.0f, 0.0f, 0.0f);
59        mMaxAngle = Vector3(360.0f, 0.0f, 0.0f);
60
61        mRayQueryExecutor = new RayQueryExecutor(sm);
62}
63//-----------------------------------------------------------------------
64TerrainContentGenerator::~TerrainContentGenerator()
65{
66        delete mRayQueryExecutor;
67}
68//-----------------------------------------------------------------------
69SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position,
70                                         const Vector3 &rotation, const String& objName, const bool clampToTerrain)
71{       
72        if (clampToTerrain)
73                return GenerateSceneObject(position, rotation, objName);
74       
75        return SceneContentGenerator::GenerateSceneObject(position, rotation, objName);
76}
77//-----------------------------------------------------------------------
78SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position,
79                                         const Vector3 &rotation, const String& objName)
80{
81        Vector3 queryResult;
82        // set y to max height so we are sure to be over terrain
83        Vector3 pos(position.x, MAX_HEIGHT, position.z);
84
85        if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
86        {
87                // reject if height is too high
88                if (queryResult.y < mMaxPos.y)
89                {
90                        // add offset so object is over terrain
91                        queryResult.y += mOffset;
92
93                        return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
94                }
95        }
96       
97        return NULL;
98}
99//-----------------------------------------------------------------------
100void TerrainContentGenerator::SetOffset(Real offset)
101{
102        mOffset = offset;
103}
104
105} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.