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

Revision 164, 3.3 KB checked in by mattausch, 19 years ago (diff)

bug fix (deleting while animation)

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/*     TerrainContentGenerator implementation          */
48/*******************************************************/
49
50//-----------------------------------------------------------------------
51TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm):
52SceneContentGenerator(sm), mOffset(0)
53{
54        mMinPos = Vector3(0.0f, MAX_HEIGHT, 0.0f);
55        mMaxPos = Vector3(3000.0f, MAX_HEIGHT, 3000.0f);
56
57        mMinAngle = Vector3(0.0f, 0.0f, 0.0f);
58        mMaxAngle = Vector3(360.0f, 0.0f, 0.0f);
59
60        mRayQueryExecutor = new RayQueryExecutor(sm);
61}
62//-----------------------------------------------------------------------
63TerrainContentGenerator::~TerrainContentGenerator()
64{
65        delete mRayQueryExecutor;
66}
67//-----------------------------------------------------------------------
68SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position,
69                                         const Vector3 &rotation, const String& objName, const bool clampToTerrain)
70{       
71        if (clampToTerrain)
72                return GenerateSceneObject(position, rotation, objName);
73       
74        return SceneContentGenerator::GenerateSceneObject(position, rotation, objName);
75}
76//-----------------------------------------------------------------------
77SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position,
78                                         const Vector3 &rotation, const String& objName)
79{
80        Vector3 queryResult;
81        // set y to max height so we are sure to be over terrain
82        Vector3 pos(position.x, MAX_HEIGHT, position.z);
83
84        if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
85        {
86                // reject if height is too high
87                if (queryResult.y < mMaxPos.y)
88                {
89                        // add offset so object is over terrain
90                        queryResult.y += mOffset;
91
92                        return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
93                }
94        }
95       
96        return NULL;
97}
98//-----------------------------------------------------------------------
99void TerrainContentGenerator::SetOffset(Real offset)
100{
101        mOffset = offset;
102}
103
104} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.