mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 16:45:34 +00:00
send a raycast through the physics engine to check if sun is visible
This commit is contained in:
parent
af83742e6f
commit
aad8f6605e
7 changed files with 62 additions and 4 deletions
|
@ -305,4 +305,9 @@ void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
|
|||
if (mSun) mSun->setPosition(direction);
|
||||
}
|
||||
|
||||
void RenderingManager::setGlare(bool glare)
|
||||
{
|
||||
mSkyManager->setGlare(glare);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -93,6 +93,7 @@ class RenderingManager: private RenderingInterface {
|
|||
void sunEnable();
|
||||
void sunDisable();
|
||||
|
||||
void setGlare(bool glare);
|
||||
void skyEnable ();
|
||||
void skyDisable ();
|
||||
void skySetHour (double hour);
|
||||
|
|
|
@ -54,6 +54,11 @@ void BillboardObject::setRenderQueue(unsigned int id)
|
|||
mBBSet->setRenderQueueGroup(id);
|
||||
}
|
||||
|
||||
SceneNode* BillboardObject::getNode()
|
||||
{
|
||||
return mNode;
|
||||
}
|
||||
|
||||
void BillboardObject::init(const String& textureName,
|
||||
const unsigned int initialSize,
|
||||
const Vector3& position,
|
||||
|
@ -276,8 +281,8 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera)
|
|||
|
||||
mViewport->setBackgroundColour(ColourValue(0.87, 0.87, 0.87));
|
||||
|
||||
mSun = new BillboardObject("textures\\tx_sun_05.dds", 1, Vector3(0.4, 0.4, 1.0), mRootNode);
|
||||
mSunGlare = new BillboardObject("textures\\tx_sun_flash_grey_05.dds", 3, Vector3(0.4, 0.4, 1.0), mRootNode);
|
||||
mSun = new BillboardObject("textures\\tx_sun_05.dds", 1, Vector3(0.4, 0.4, 0.4), mRootNode);
|
||||
mSunGlare = new BillboardObject("textures\\tx_sun_flash_grey_05.dds", 3, Vector3(0.4, 0.4, 0.4), mRootNode);
|
||||
mSunGlare->setRenderQueue(RENDER_QUEUE_SKIES_LATE);
|
||||
mMasser = new Moon("textures\\tx_masser_full.dds", 1, Vector3(-0.4, -0.4, 0.5), mRootNode);
|
||||
mSecunda = new Moon("textures\\tx_secunda_full.dds", 0.5, Vector3(0.4, -0.4, 0.5), mRootNode);
|
||||
|
@ -442,11 +447,13 @@ void SkyManager::update(float duration)
|
|||
void SkyManager::enable()
|
||||
{
|
||||
mRootNode->setVisible(true);
|
||||
mEnabled = true;
|
||||
}
|
||||
|
||||
void SkyManager::disable()
|
||||
{
|
||||
mRootNode->setVisible(false);
|
||||
mEnabled = false;
|
||||
}
|
||||
|
||||
void SkyManager::setMoonColour (bool red)
|
||||
|
@ -508,3 +515,13 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
|||
|
||||
mViewport->setBackgroundColour(weather.mFogColor);
|
||||
}
|
||||
|
||||
void SkyManager::setGlare(bool glare)
|
||||
{
|
||||
mSunGlare->setVisible(glare && mEnabled);
|
||||
}
|
||||
|
||||
Vector3 SkyManager::getRealSunPos()
|
||||
{
|
||||
return mSun->getNode()->_getDerivedPosition();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace MWRender
|
|||
void setVisible(const bool visible);
|
||||
void setRenderQueue(unsigned int id);
|
||||
|
||||
Ogre::SceneNode* getNode();
|
||||
|
||||
protected:
|
||||
virtual void init(const Ogre::String& textureName,
|
||||
const unsigned int size,
|
||||
|
@ -128,6 +130,9 @@ namespace MWRender
|
|||
|
||||
void setWeather(const MWWorld::WeatherResult& weather);
|
||||
|
||||
void setGlare(bool glare);
|
||||
Ogre::Vector3 getRealSunPos();
|
||||
|
||||
private:
|
||||
BillboardObject* mSun;
|
||||
BillboardObject* mSunGlare;
|
||||
|
@ -156,6 +161,8 @@ namespace MWRender
|
|||
float mRemainingTransitionTime;
|
||||
|
||||
void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType);
|
||||
|
||||
bool mEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,17 @@ namespace MWWorld
|
|||
|
||||
return mEngine->rayTest(from,to);
|
||||
}
|
||||
|
||||
bool PhysicsSystem::castRay(const Vector3& from, const Vector3& to)
|
||||
{
|
||||
btVector3 _from, _to;
|
||||
_from = btVector3(from.x, from.y, from.z);
|
||||
_to = btVector3(to.x, to.y, to.z);
|
||||
|
||||
std::pair<std::string, float> result = mEngine->rayTest(_from, _to);
|
||||
|
||||
return !(result.first == "");
|
||||
}
|
||||
|
||||
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > PhysicsSystem::doPhysics (float duration,
|
||||
|
|
|
@ -33,11 +33,15 @@ namespace MWWorld
|
|||
void scaleObject (const std::string& handle, float scale);
|
||||
|
||||
bool toggleCollisionMode();
|
||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||
|
||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||
|
||||
// cast ray, return true if it hit something
|
||||
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
||||
|
||||
void insertObjectPhysics(const MWWorld::Ptr& ptr, std::string model);
|
||||
|
||||
void insertActorPhysics(const MWWorld::Ptr&, std::string model);
|
||||
void insertActorPhysics(const MWWorld::Ptr&, std::string model);
|
||||
|
||||
OEngine::Physic::PhysicEngine* getEngine();
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "globals.hpp"
|
||||
#include "cellfunctors.hpp"
|
||||
|
||||
#include <OgreVector3.h>
|
||||
using namespace Ogre;
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
|
@ -413,6 +416,8 @@ namespace MWWorld
|
|||
mRendering->skySetDate (day, month);
|
||||
|
||||
mWeatherManager->setDate (day, month);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void World::setMonth (int month)
|
||||
|
@ -699,6 +704,14 @@ namespace MWWorld
|
|||
mWorldScene->update (duration);
|
||||
|
||||
mWeatherManager->update (duration);
|
||||
|
||||
// cast a ray from player to sun to detect if the sun is visible
|
||||
// this is temporary until we find a better place to put this code
|
||||
// currently its here because we need to access the physics system
|
||||
float* p = mPlayer->getPlayer().getRefData().getPosition().pos;
|
||||
Vector3 sun = mRendering->getSkyManager()->getRealSunPos();
|
||||
sun = Vector3(sun.x, -sun.z, sun.y);
|
||||
mRendering->getSkyManager()->setGlare(!mPhysics->castRay(Ogre::Vector3(p[0], p[1], p[2]), sun));
|
||||
}
|
||||
|
||||
bool World::isCellExterior() const
|
||||
|
|
Loading…
Reference in a new issue