source: trunk/VUT/work/TestCullingTerrain/TerrainContentGenerator.cpp @ 97

Revision 97, 2.7 KB checked in by mattausch, 19 years ago (diff)

ogre: changed from occlusion_query_nv to occlusion_query_arb (in ogre_changes)

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