bmp410
03-04-2009 07:24:33
After some tweaking and a few choice swear words, I was able to get Hydrax to load in my game. It is actually running calculations because in debug mode the performance is terrrible whenever I enable it, however I cannot actually see the water. It is probably something very simple that I am overlooking due to my lack of sleep as of late. Can anyone see anything that I am doing incorrectly?
The code is the initialization for my player camera that follows the node passed in.
The code is the initialization for my player camera that follows the node passed in.
void PlayerCamera::Initialize(Ogre::SceneNode *inFocusNode){
focusNode = inFocusNode;
cameraCollisionMgr = Ogre::Singleton<GameCollisionManager>::getSingletonPtr();
cameraCollisionMgr->setSceneManager("Play");
//At least for now, this variable equals:
//cameraNodeName = MyPlayerCam
Ogre::String cameraNodeName = inFocusNode->getName()+ "Cam";
parentNode = Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getSceneManager("Play")->createSceneNode(cameraNodeName + "parent");
//create the camera node
node = parentNode->createChildSceneNode(cameraNodeName);
//create the camera
myCamera = Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getSceneManager("Play")->createCamera(cameraNodeName);
//put set viewport to this camera
Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getAutoCreatedWindow()->getViewport(1)->setCamera(myCamera);
//attach cam to node
node->setPosition( Ogre::Vector3(0, 0, -400));
node->rotate(Ogre::Vector3(0,1,0), Ogre::Degree(180));
node->attachObject(myCamera);
//myCamera->setAutoTracking(true,focusNode,Ogre::Vector3(0,50,0));
node->setAutoTracking(true, parentNode, Ogre::Vector3::NEGATIVE_UNIT_Z, Ogre::Vector3(0, 0, 0));
cameraRaySceneQuery = Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getSceneManager("Play")->createRayQuery(Ogre::Ray());
cameraRaySceneQuery->setSortByDistance(true);
//camera starting values
direction = Ogre::Vector3::ZERO;
rotate = 0.13;
move = 200;
cameraOffset = 400;
myCamera->setNearClipDistance(0.1);
// Create Hydrax object
mHydrax = new Hydrax::Hydrax(Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getSceneManager("Play"), myCamera,
Ogre::Singleton<Ogre::Root>::getSingletonPtr()->getAutoCreatedWindow()->getViewport(1));
mHydrax->setModule(static_cast<Hydrax::Module::Module*>(new Hydrax::Module::ProjectedGrid(// Hydrax parent pointer
mHydrax,
// Noise module
new Hydrax::Noise::Perlin(),
// Base plane
Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
// Normal mode
Hydrax::MaterialManager::NM_VERTEX,
// Projected grid options (Can be updated each frame -> setOptions(...))
Hydrax::Module::ProjectedGrid::Options(/* Default constructor */))));
mHydrax->setComponents(
static_cast<Hydrax::HydraxComponent>(Hydrax::HYDRAX_COMPONENT_SUN |
Hydrax::HYDRAX_COMPONENT_FOAM |
Hydrax::HYDRAX_COMPONENT_DEPTH |
Hydrax::HYDRAX_COMPONENT_SMOOTH |
Hydrax::HYDRAX_COMPONENT_CAUSTICS |
Hydrax::HYDRAX_COMPONENT_UNDERWATER |
Hydrax::HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS |
Hydrax::HYDRAX_COMPONENT_UNDERWATER_GODRAYS));
mHydrax->create();
bool PlayerCamera::frameStarted(const Ogre::FrameEvent& evt){
//translate camera to keep up with player
//node->setPosition( Ogre::Vector3(node->getPosition().x, 50, -cameraOffset));
mHydrax->update(evt.timeSinceLastFrame);
parentNode->setPosition(focusNode->getPosition() + Ogre::Vector3(0,50,0));
node->needUpdate(true);
cameraGroundCollisionCheck();
return true;
}