Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Client/App/App.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,10 @@
RelativePath=".\v8datamodel\JointInstance.cpp"
>
</File>
<File
RelativePath=".\v8datamodel\Lighting.cpp"
>
</File>
<File
RelativePath=".\v8datamodel\ModelInstance.cpp"
>
Expand Down
74 changes: 51 additions & 23 deletions Client/App/include/v8datamodel/Lighting.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "v8tree/Service.h"
#include <GLG3D/LightingParameters.h>
#include "v8tree/Service.h"
#include "v8datamodel/Sky.h"

namespace RBX
{
Expand All @@ -27,38 +28,65 @@ namespace RBX
//Lighting(const Lighting&);
Lighting();
public:
void replaceSky(Sky*);
void replaceSky(Sky* sky);
bool isSkySuppressed() const;
void suppressSky(const bool);
const G3D::LightingParameters& getSkyParameters() const;
const G3D::LightingParameters& getSkyParameters() const
{
return skyParameters;
}
G3D::Color4 getClearColor() const;
void setClearColor(G3D::Color4);
G3D::Color3 getLightColor() const;
void setLightColor(G3D::Color3);
G3D::Color3 getAmbientTop() const;
void setAmbientTop(G3D::Color3);
G3D::Color3 getAmbientBottom() const;
void setAmbientBottom(G3D::Color3);
void setClearColor(G3D::Color4 newClearColor);
G3D::Color3 getLightColor() const
{
return skyParameters.lightColor;
}
void setLightColor(G3D::Color3 newLightColor);
G3D::Color3 getAmbientTop() const
{
return ambientTop;
}
void setAmbientTop(G3D::Color3 newAmbientTop);
G3D::Color3 getAmbientBottom() const
{
return ambientBottom;
}
void setAmbientBottom(G3D::Color3 newAmbientBottom);
std::string getTimeStr() const;
void setTimeStr(const std::string&);
void setTime(const boost::posix_time::time_duration&);
void setTimeStr(const std::string& time);
void setTime(const boost::posix_time::time_duration& time);
double getGameTime() const;
double getMinutesAfterMidnight();
void setMinutesAfterMidnight(double);
float getMoonPhase();
void setMinutesAfterMidnight(double seconds);
float getMoonPhase()
{
return skyParameters.moonPhase;
}
G3D::Vector3 getMoonPosition();
G3D::Vector3 getSunPosition();
float getGeographicLatitude() const;
void setGeographicLatitude(float);
G3D::Color3 getClearColor3() const;
void setClearColor3(G3D::Color3);
float getGeographicLatitude() const
{
return skyParameters.geoLatitude;
}
void setGeographicLatitude(float newGeographicLatitude);
G3D::Color3 getClearColor3() const
{
return G3D::Color3(clearColor.r, clearColor.g, clearColor.b);
}
void setClearColor3(G3D::Color3 color)
{
setClearColor(G3D::Color4(color));
}
protected:
virtual void onChildAdded(Instance*);
virtual void onChildRemoving(Instance*);
virtual void onChildChanged(Instance*, const PropertyChanged&);
virtual bool askAddChild(const Instance*) const;
virtual void onChildAdded(Instance* instance);
virtual void onChildRemoving(Instance* instance);
virtual void onChildChanged(Instance* instance, const PropertyChanged& propEvent);
virtual bool askAddChild(const Instance* instance) const;
private:
void fireLightingChanged(bool);
void fireLightingChanged(bool value)
{
event_LightingChanged.fire(this, value);
}
public:
virtual ~Lighting();
public:
Expand Down
195 changes: 195 additions & 0 deletions Client/App/v8datamodel/Lighting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#include "v8datamodel/Lighting.h"
#include "util/RunStateOwner.h"

namespace RBX
{
const char* sLighting = "Lighting";

static const Reflection::PropDescriptor<Lighting, G3D::Color3> desc_AmbientTop("TopAmbientV9", "Appearance", &Lighting::getAmbientTop, &Lighting::setAmbientTop, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Lighting, G3D::Color3> desc_AmbientBottom("BottomAmbientV9", "Appearance", &Lighting::getAmbientBottom, &Lighting::setAmbientBottom, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Lighting, G3D::Color3> desc_LightColor("SpotLightV9", "Appearance", &Lighting::getLightColor, &Lighting::setLightColor, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Lighting, G3D::Color3> desc_ClearColor("ClearColor", "Appearance", &Lighting::getClearColor3, &Lighting::setClearColor3, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Lighting, std::string> prop_Time("TimeOfDay", "Data", &Lighting::getTimeStr, &Lighting::setTimeStr, Reflection::PropertyDescriptor::STANDARD);
static const Reflection::PropDescriptor<Lighting, float> prop_GeographicLatitude("GeographicLatitude", "Data", &Lighting::getGeographicLatitude, &Lighting::setGeographicLatitude, Reflection::PropertyDescriptor::STANDARD);

Lighting::Lighting()
: Base(),
ambientTop(209/255.0f, 208/255.0f, 217/255.0f),
ambientBottom(122/255.0f, 134/255.0f, 120/255.0f),
hasSky(true),
clearColor(G3D::Color3::white()),
timeOfDay(boost::posix_time::duration_from_string("14:00:00"))
{
skyParameters.lightColor = G3D::Color3(152/255.0f, 137/255.0f, 102/255.0f);
skyParameters.setTime(timeOfDay.total_seconds());
setName("Lighting");
}

Lighting::~Lighting()
{
}

G3D::Vector3 Lighting::getMoonPosition()
{
return (skyParameters.physicallyCorrect) ? skyParameters.trueMoonPosition : skyParameters.moonPosition;
}

G3D::Vector3 Lighting::getSunPosition()
{
return (skyParameters.physicallyCorrect) ? skyParameters.trueSunPosition : skyParameters.sunPosition;
}

void Lighting::replaceSky(Sky* sky)
{
Sky* currentSky = findFirstChildOfType<Sky>();
while (currentSky)
{
currentSky->setParent(NULL);
currentSky = findFirstChildOfType<Sky>();
}
sky->setParent(this);
}

std::string Lighting::getTimeStr() const
{
return boost::posix_time::to_simple_string(timeOfDay);
}

void Lighting::setTimeStr(const std::string &time)
{
setTime(boost::posix_time::duration_from_string(time));
}

void Lighting::setClearColor(G3D::Color4 newClearColor)
{
if (newClearColor != clearColor)
{
clearColor = newClearColor;
raisePropertyChanged(desc_ClearColor);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::setLightColor(G3D::Color3 newLightColor)
{
if (newLightColor != skyParameters.lightColor)
{
skyParameters.lightColor = newLightColor;
raisePropertyChanged(desc_LightColor);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::setAmbientBottom(G3D::Color3 newAmbientBottom)
{
if (newAmbientBottom != ambientBottom)
{
ambientBottom = newAmbientBottom;
raisePropertyChanged(desc_AmbientBottom);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::setAmbientTop(G3D::Color3 newAmbientTop)
{
if (newAmbientTop != ambientTop)
{
ambientTop = newAmbientTop;
raisePropertyChanged(desc_AmbientTop);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::setGeographicLatitude(float newGeographicLatitude)
{
if (newGeographicLatitude != skyParameters.geoLatitude)
{
skyParameters.geoLatitude = newGeographicLatitude;
raisePropertyChanged(prop_GeographicLatitude);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

//65.93% matching.
void Lighting::setTime(const boost::posix_time::time_duration& time)
{
if (timeOfDay != time)
{
timeOfDay = boost::posix_time::time_duration(0, 0, time.total_seconds());
skyParameters.setTime(timeOfDay.total_seconds());
raisePropertyChanged(prop_Time);
fireLightingChanged(false);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

double Lighting::getMinutesAfterMidnight()
{
return timeOfDay.total_milliseconds() / 60000.0;
}

void Lighting::setMinutesAfterMidnight(double seconds)
{
setTime(boost::posix_time::time_duration(0, 0, seconds * 60));
}

void Lighting::onChildAdded(Instance* instance)
{
Sky* newSky = fastDynamicCast<Sky>(instance);

if (newSky)
{
sky = shared_from(newSky);
fireLightingChanged(true);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::onChildRemoving(Instance* instance)
{
if (sky.get() == instance)
{
sky.reset();
fireLightingChanged(true);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

void Lighting::onChildChanged(Instance* instance, const PropertyChanged& propEvent)
{
Instance::onChildChanged(instance, propEvent);
if (sky.get() == instance)
{
fireLightingChanged(true);
RunService* runService = ServiceProvider::findServiceProvider(this)->find<RunService>();
if (runService)
runService->invalidateRunViews();
}
}

bool Lighting::askAddChild(const Instance* instance) const
{
return fastDynamicCast<const Sky>(instance) != NULL;
}
}