Making this work
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <OgreMeshLodGenerator.h>
|
||||
#include <OgreCompositorManager.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
#include <OgreBullet.h>
|
||||
#include "water.h"
|
||||
|
||||
/* TODO: use blender glb model for water shape.
|
||||
@@ -20,12 +21,19 @@ Water::Water()
|
||||
, mWindow(nullptr)
|
||||
, mCameraNode(nullptr)
|
||||
, mWaterPlane(Ogre::Vector3::UNIT_Y, 0)
|
||||
, mReflectionPlane(Ogre::Vector3(0.0, 1.0, 0.0), 0.0f /* water height */)
|
||||
, mReflectionClipPlaneAbove(Ogre::Vector3(0.0, 1.0, 0.0), 0.0f /* water height */ - 2.0f)
|
||||
, mReflectionClipPlaneBelow(Ogre::Vector3(0.0, -1.0, 0.0), -(0.0f /* water height */ + 2.0))
|
||||
, mRefractionClipPlaneAbove(Ogre::Vector3(0.0, -1.0, 0.0), -(0.0f /* water height */ + 2.0))
|
||||
, mRefractionClipPlaneBelow(Ogre::Vector3(0.0, 1.0, 0.0), 0.0f /* water height */ - 2.0)
|
||||
, mReflectionPlane(Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */)
|
||||
, mReflectionClipPlaneAbove(Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */ - 2.0f)
|
||||
, mReflectionClipPlaneBelow(Ogre::Vector3(0.0, -1.0, 0.0),
|
||||
-(0.0f /* water height */ + 2.0))
|
||||
, mRefractionClipPlaneAbove(Ogre::Vector3(0.0, -1.0, 0.0),
|
||||
-(0.0f /* water height */ + 2.0))
|
||||
, mRefractionClipPlaneBelow(Ogre::Vector3(0.0, 1.0, 0.0),
|
||||
0.0f /* water height */ - 2.0)
|
||||
, mAbove(true)
|
||||
, mWaterBody(nullptr)
|
||||
, mDynWorld(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,8 +41,16 @@ Water::~Water()
|
||||
{
|
||||
if (mWaterNode)
|
||||
mScnMgr->destroySceneNode(mWaterNode);
|
||||
if(mReflectionTexture)
|
||||
if (mReflectionTexture)
|
||||
mReflectionTexture->removeAllListeners();
|
||||
if (mWaterBody) {
|
||||
if (mWaterBody->getWorldArrayIndex() >= 0)
|
||||
if (mDynWorld)
|
||||
mDynWorld->getBtWorld()->removeCollisionObject(
|
||||
mWaterBody);
|
||||
delete mWaterBody;
|
||||
mWaterBody = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Water::create_cameras()
|
||||
@@ -48,9 +64,11 @@ void Water::create_cameras()
|
||||
mReflectionCamera->enableCustomNearClipPlane(mReflectionClipPlaneAbove);
|
||||
mReflectionCamera->enableReflection(mReflectionPlane);
|
||||
|
||||
Ogre::Viewport * reflectionViewport = mReflectionTexture->addViewport(mReflectionCamera, 0, 0, 0, 0.5f, 1.0f);
|
||||
Ogre::Viewport *reflectionViewport = mReflectionTexture->addViewport(
|
||||
mReflectionCamera, 0, 0, 0, 0.5f, 1.0f);
|
||||
reflectionViewport->setClearEveryFrame(true);
|
||||
reflectionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 1.0, 1.0));
|
||||
reflectionViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.0, 1.0, 1.0));
|
||||
reflectionViewport->setOverlaysEnabled(false);
|
||||
reflectionViewport->setSkiesEnabled(true);
|
||||
reflectionViewport->setAutoUpdated(false);
|
||||
@@ -63,9 +81,11 @@ void Water::create_cameras()
|
||||
mRefractionCamera->setFarClipDistance(mCamera->getFarClipDistance());
|
||||
mRefractionCamera->enableCustomNearClipPlane(mRefractionClipPlaneAbove);
|
||||
|
||||
Ogre::Viewport * refractionViewport = mReflectionTexture->addViewport(mRefractionCamera, 1, 0.5, 0, 0.5f, 1.0f);
|
||||
Ogre::Viewport *refractionViewport = mReflectionTexture->addViewport(
|
||||
mRefractionCamera, 1, 0.5, 0, 0.5f, 1.0f);
|
||||
refractionViewport->setClearEveryFrame(true);
|
||||
refractionViewport->setBackgroundColour(Ogre::ColourValue(0.0, 0.5, 1.0, 1.0));
|
||||
refractionViewport->setBackgroundColour(
|
||||
Ogre::ColourValue(0.0, 0.5, 1.0, 1.0));
|
||||
refractionViewport->setOverlaysEnabled(false);
|
||||
refractionViewport->setSkiesEnabled(false);
|
||||
refractionViewport->setAutoUpdated(false);
|
||||
@@ -74,13 +94,12 @@ void Water::create_cameras()
|
||||
|
||||
void Water::create_textures()
|
||||
{
|
||||
Ogre::TexturePtr reflectionTexture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"ReflectionRefractionTexture",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, 512, 512,
|
||||
0,
|
||||
Ogre::PF_R8G8B8A8,
|
||||
Ogre::TU_RENDERTARGET);
|
||||
Ogre::TexturePtr reflectionTexture =
|
||||
Ogre::TextureManager::getSingleton().createManual(
|
||||
"ReflectionRefractionTexture",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8A8,
|
||||
Ogre::TU_RENDERTARGET);
|
||||
|
||||
mReflectionTexture = reflectionTexture->getBuffer()->getRenderTarget();
|
||||
mReflectionTexture->setAutoUpdated(false);
|
||||
@@ -115,10 +134,12 @@ void Water::init()
|
||||
{ -1, 0, 1 }, { 1, 0, -1 }, { 1, 0, 1 } };
|
||||
mWaterNode = mScnMgr->getRootSceneNode()->createChildSceneNode("Water");
|
||||
|
||||
auto mat = Ogre::MaterialManager::getSingleton().getByName("Water/Above");
|
||||
auto mat =
|
||||
Ogre::MaterialManager::getSingleton().getByName("Water/Above");
|
||||
mat->load();
|
||||
mat->setReceiveShadows(false);
|
||||
auto mat2 = Ogre::MaterialManager::getSingleton().getByName("Water/Below");
|
||||
auto mat2 =
|
||||
Ogre::MaterialManager::getSingleton().getByName("Water/Below");
|
||||
mat2->load();
|
||||
mat2->setReceiveShadows(false);
|
||||
#if 0
|
||||
@@ -146,9 +167,11 @@ void Water::init()
|
||||
water_ent->setMaterial(mat);
|
||||
mWaterNode->attachObject(water_ent);
|
||||
mWaterMeshes.push_back(water_ent);
|
||||
mDynWorld->attachCollisionObject(mWaterBody, water_ent, 1, 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void Water::createWater(Ogre::RenderWindow * window, Ogre::Camera *camera)
|
||||
void Water::createWater(Ogre::RenderWindow *window, Ogre::Camera *camera,
|
||||
Ogre::Bullet::DynamicsWorld *world)
|
||||
{
|
||||
int i;
|
||||
mCamera = camera;
|
||||
@@ -158,6 +181,17 @@ void Water::createWater(Ogre::RenderWindow * window, Ogre::Camera *camera)
|
||||
mWindow = window;
|
||||
mCameraPosition = mCameraNode->getPosition();
|
||||
create_textures();
|
||||
mDynWorld = world;
|
||||
mWaterBody = new btGhostObject;
|
||||
btBoxShape *boxShape = new btBoxShape(btVector3(1000, 1000, 1000));
|
||||
btCompoundShape *shape = new btCompoundShape;
|
||||
shape->addChildShape(
|
||||
btTransform(btQuaternion(), btVector3(0, -1000, 0)), boxShape);
|
||||
mWaterBody->setCollisionShape(shape);
|
||||
mWaterBody->setCollisionFlags(
|
||||
mWaterBody->getCollisionFlags() |
|
||||
btCollisionObject::CF_NO_CONTACT_RESPONSE |
|
||||
btCollisionObject::CF_STATIC_OBJECT);
|
||||
}
|
||||
|
||||
void Water::updateWater(float delta)
|
||||
|
||||
Reference in New Issue
Block a user