38 Water::Water(Ogre::Vector3 terrn_size) :
39 m_map_size(terrn_size),
41 m_water_visible(true),
42 m_waterplane_mesh_scale(1.0f),
43 m_refract_rtt_viewport(0),
44 m_reflect_rtt_viewport(0),
48 m_waterplane_force_update_pos(false),
50 m_refract_rtt_target(0),
51 m_reflect_rtt_target(0),
64 FILE* fd = fopen(filepath.c_str(),
"r");
69 int res = fscanf(fd,
" %[^\n\r]", line);
72 float wl, amp, mx, dir;
73 res = sscanf(line,
"%f, %f, %f, %f", &wl, &, &mx, &dir);
140 #if 0 // Doesn't cut it with Ogre 1.11
156 #if 0 // Doesn't cut it with Ogre 1.11
171 Ogre::MeshManager::getSingleton().remove(
"ReflectPlane");
172 Ogre::MeshManager::getSingleton().remove(
"BottomPlane");
173 Ogre::MeshManager::getSingleton().remove(
"WaterPlane");
187 const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();
188 if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM)))
190 OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
"Your card does not support vertex and fragment programs, so cannot "
191 "run Water effects. Sorry!",
196 if (!GpuProgramManager::getSingleton().isSyntaxSupported(
"arbfp1") &&
197 !GpuProgramManager::getSingleton().isSyntaxSupported(
"ps_2_0") &&
198 !GpuProgramManager::getSingleton().isSyntaxSupported(
"ps_1_4")
201 OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
"Your card does not support advanced fragment programs, "
202 "so cannot run Water effects. Sorry!",
215 TexturePtr m_refract_rtt_targetPtr = Ogre::TextureManager::getSingleton ().getByName (
"Refraction");
230 MaterialPtr mat = MaterialManager::getSingleton().getByName(
"Examples/FresnelReflectionRefraction");
231 mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
"Refraction");
233 mat = MaterialManager::getSingleton().getByName(
"Examples/FresnelReflectionRefractioninverted");
234 mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
"Refraction");
248 TexturePtr m_reflect_rtt_targetPtr = Ogre::TextureManager::getSingleton ().getByName (
"Reflection");
266 mat = MaterialManager::getSingleton().getByName(
"Examples/FresnelReflectionRefraction");
267 mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
"Reflection");
269 mat = MaterialManager::getSingleton().getByName(
"Examples/FresnelReflectionRefractioninverted");
270 mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
"Reflection");
274 mat = MaterialManager::getSingleton().getByName(
"Examples/FresnelReflection");
275 mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
"Reflection");
292 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
305 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
323 MeshManager::getSingleton().createPlane(
"BottomPlane",
324 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
328 pE->setMaterialName(
"tracks/seabottom");
329 pE->setCastShadows(
false);
376 for (
int pz = 0; pz <
WAVEREZ + 1; pz++)
378 for (
int px = 0; px <
WAVEREZ + 1; px++)
385 for (
int pz = 0; pz <
WAVEREZ + 1; pz++)
387 for (
int px = 0; px <
WAVEREZ + 1; px++)
389 int left = std::max(0, px - 1);
390 int right = std::min(px + 1,
WAVEREZ);
391 int up = std::max(0, pz - 1);
392 int down = std::min(pz + 1,
WAVEREZ);
422 const Vector3 water_cam_pos(camera_pos.x,
m_water_height, camera_pos.z);
423 Vector3 sightPos(water_cam_pos);
425 Ogre::Vector3 cameraDir = camera_rot * -Ogre::Vector3::UNIT_Z;
427 Ray lineOfSight(camera_pos, cameraDir);
428 Plane waterPlane(Vector3::UNIT_Y, Vector3::UNIT_Y *
m_water_height);
430 std::pair<bool, Real> intersection = lineOfSight.intersects(waterPlane);
432 if (intersection.first && intersection.second > 0.0f)
433 sightPos = lineOfSight.getPoint(intersection.second);
435 Real offset = std::min(water_cam_pos.distance(sightPos), std::min(
m_map_size.x,
m_map_size.z) * 0.5f);
437 Vector3 waterPos = water_cam_pos + (sightPos - water_cam_pos).normalisedCopy() * offset;
565 return pos.y < waterheight;
571 return Vector3::ZERO;
576 return Vector3::ZERO;
578 Vector3 result(Vector3::ZERO);
587 result.y += speed * cos(coeff);
667 this->
scene_mgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(
false);
674 this->scene_mgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(
true);
675 this->waterplane_entity->setVisible(
true);
681 this->scene_mgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(
false);
682 this->waterplane_entity->setVisible(
false);
687 this->scene_mgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(
true);
688 this->waterplane_entity->setVisible(
true);