#include "TerrainContentGenerator.h" #include namespace Ogre { /*************************************************/ /* RayQueryExecutor implementation */ /*************************************************/ //----------------------------------------------------------------------- RayQueryExecutor::RayQueryExecutor(SceneManager *sm) { mRaySceneQuery = sm->createRayQuery(Ray()); } //----------------------------------------------------------------------- RayQueryExecutor::~RayQueryExecutor() { delete mRaySceneQuery; } //----------------------------------------------------------------------- bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Vector3 &pos, const Vector3 &dir) { return executeRayQuery(result, Ray(pos, dir)); } //----------------------------------------------------------------------- bool RayQueryExecutor::executeRayQuery(Vector3 *result, const Ray &ray) { mRaySceneQuery->setRay(ray); // Perform the scene query RaySceneQueryResult &queryResult = mRaySceneQuery->execute(); RaySceneQueryResult::iterator it = queryResult.begin(); if (it != queryResult.end() && it->worldFragment) { SceneQuery::WorldFragment* wf = it->worldFragment; *result = wf->singleIntersection; return true; } return false; } /*******************************************************/ /* TerrainContentGenerator implementation */ /*******************************************************/ //----------------------------------------------------------------------- TerrainContentGenerator::TerrainContentGenerator(SceneManager *sm): SceneContentGenerator(sm), mMaxHeight(100) { mMinPos = Vector3(0.0f, 5000.0f, 0.0f); mMaxPos = Vector3(1000.0f, 5000.0f, 1000.0f); mMinAngle = Vector3(0.0f, 0.0f, 0.0f); mMaxAngle = Vector3(360.0f, 0.0f, 0.0f); mRayQueryExecutor = new RayQueryExecutor(sm); } //----------------------------------------------------------------------- TerrainContentGenerator::~TerrainContentGenerator() { delete mRayQueryExecutor; } //----------------------------------------------------------------------- SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, const Vector3 &rotation, const String& objName) { Vector3 queryResult; if (mRayQueryExecutor->executeRayQuery(&queryResult, position, Vector3::NEGATIVE_UNIT_Y)) { // reject if height is too high if(queryResult.y < mMaxHeight) { return SceneContentGenerator::GenerateSceneObject(queryResult, rotation, objName); } } return NULL; } //----------------------------------------------------------------------- void TerrainContentGenerator::SetMaxHeight(Real maxHeight) { mMaxHeight = maxHeight; } } // namespace Ogre