[81] | 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, const Vector3 &dir)
|
---|
| 22 | {
|
---|
| 23 | return executeRayQuery(result, Ray(pos, dir));
|
---|
| 24 | }
|
---|
| 25 | //-----------------------------------------------------------------------
|
---|
| 26 | bool 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 | //-----------------------------------------------------------------------
|
---|
| 50 | TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm):
|
---|
| 51 | SceneContentGenerator(sm), mMaxHeight(100)
|
---|
| 52 | {
|
---|
| 53 | mMinPos = Vector3(0.0f, 5000.0f, 0.0f);
|
---|
| 54 | mMaxPos =Vector3(1000.0f, 5000.0f, 1000.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 | //-----------------------------------------------------------------------
|
---|
| 62 | TerrainContentGenerator::~TerrainContentGenerator()
|
---|
| 63 | {
|
---|
| 64 | delete mRayQueryExecutor;
|
---|
| 65 | }
|
---|
| 66 | //-----------------------------------------------------------------------
|
---|
| 67 | SceneNode *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 too big
|
---|
| 75 | if(queryResult.y < mMaxHeight)
|
---|
| 76 | {
|
---|
| 77 | return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName);
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | return NULL;
|
---|
| 82 | }
|
---|
| 83 | //-----------------------------------------------------------------------
|
---|
| 84 | void TerrainContentGenerator::SetMaxHeight(Real maxHeight)
|
---|
| 85 | {
|
---|
| 86 | mMaxHeight = maxHeight;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | } // namespace Ogre |
---|