1 | #include "TerrainContentGenerator.h"
|
---|
2 | #include <windows.h>
|
---|
3 |
|
---|
4 | namespace Ogre {
|
---|
5 |
|
---|
6 | /*************************************************/
|
---|
7 | /* RayQueryExecutor implementation */
|
---|
8 | /*************************************************/
|
---|
9 |
|
---|
10 | //-----------------------------------------------------------------------
|
---|
11 | RayQueryExecutor::RayQueryExecutor(SceneManager *sm)
|
---|
12 | {
|
---|
13 | mRaySceneQuery = sm->createRayQuery(Ray());
|
---|
14 | }
|
---|
15 | //-----------------------------------------------------------------------
|
---|
16 | RayQueryExecutor::~RayQueryExecutor()
|
---|
17 | {
|
---|
18 | delete mRaySceneQuery;
|
---|
19 | }
|
---|
20 | //-----------------------------------------------------------------------
|
---|
21 | bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Vector3 &pos,
|
---|
22 | const Vector3 &dir)
|
---|
23 | {
|
---|
24 | return executeRayQuery(result, Ray(pos, dir));
|
---|
25 | }
|
---|
26 | //-----------------------------------------------------------------------
|
---|
27 | bool 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 | //-----------------------------------------------------------------------
|
---|
51 | TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm):
|
---|
52 | SceneContentGenerator(sm), mMaxHeight(100)
|
---|
53 | {
|
---|
54 | mMinPos = Vector3(0.0f, 5000.0f, 0.0f);
|
---|
55 | mMaxPos = Vector3(1000.0f, 5000.0f, 1000.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 | //-----------------------------------------------------------------------
|
---|
63 | TerrainContentGenerator::~TerrainContentGenerator()
|
---|
64 | {
|
---|
65 | delete mRayQueryExecutor;
|
---|
66 | }
|
---|
67 | //-----------------------------------------------------------------------
|
---|
68 | SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, |
---|
69 | const Vector3 &rotation, const String& objName)
|
---|
70 | {
|
---|
71 | Vector3 queryResult;
|
---|
72 |
|
---|
73 | if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y))
|
---|
74 | {
|
---|
75 | // reject if height is too high
|
---|
76 | if(queryResult.y < mMaxHeight)
|
---|
77 | {
|
---|
78 | return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | return NULL;
|
---|
83 | }
|
---|
84 | //-----------------------------------------------------------------------
|
---|
85 | void TerrainContentGenerator::SetMaxHeight(Real maxHeight)
|
---|
86 | {
|
---|
87 | mMaxHeight = maxHeight;
|
---|
88 | }
|
---|
89 |
|
---|
90 | } // namespace Ogre |
---|