Adding the cookies sciprt that provide a simple ui useful for debug and exemple, complete the interface on the scene script interface to provide the getters

This commit is contained in:
Sam Gateau 2015-04-01 12:22:35 -07:00
parent 92c55f9cf0
commit 3b92910a91
6 changed files with 118 additions and 27 deletions

View file

@ -8,27 +8,82 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
var intensity = 1.0; Script.include("../../utilities/tools/cookies.js");
var day = 0.0;
var hour = 12.0;
var longitude = 115.0;
var latitude = 31.0;
var stageOrientation = Quat.fromPitchYawRollDegrees(0.0, 180.0, 0.0);
Scene.setStageDayTime(hour); var panel = new Panel(10, 400);
Scene.setStageOrientation(stageOrientation);
Scene.setStageLocation(longitude, latitude, 0.0); panel.newSlider("Origin Longitude", -180, 180,
/* function(value) { Scene.setStageLocation(value, Scene.getStageLocationLatitude(), Scene.getStageLocationAltitude()); },
function ticktack() { function() { return Scene.getStageLocationLongitude(); },
hour += 0.1; function(value) { return value.toFixed(0) + " deg"; }
//Scene.setSunIntensity(Math.cos(time)); );
if (hour > 24.0) {
hour = 0.0; panel.newSlider("Origin Latitude", -90, 90,
day++; function(value) { Scene.setStageLocation(Scene.getStageLocationLongitude(), value, Scene.getStageLocationAltitude()); },
Scene.setStageYearTime(day); function() { return Scene.getStageLocationLatitude(); },
function(value) { return value.toFixed(0) + " deg"; }
);
panel.newSlider("Origin Altitude", 0, 1000,
function(value) { Scene.setStageLocation(Scene.getStageLocationLongitude(), Scene.getStageLocationLatitude(), value); },
function() { return Scene.getStageLocationAltitude(); },
function(value) { return (value).toFixed(0) + " km"; }
);
panel.newSlider("Year Time", 0, 364,
function(value) { Scene.setStageYearTime(value); },
function() { return Scene.getStageYearTime(); },
function(value) {
var numDaysPerMonth = 365.0 / 12.0;
var monthly = (value / numDaysPerMonth);
var month = Math.floor(monthly);
return (month + 1).toFixed(0) + "/" + Math.ceil(0.5 + (monthly - month)*Math.ceil(numDaysPerMonth)).toFixed(0); }
);
panel.newSlider("Day Time", 0, 24,
function(value) { Scene.setStageDayTime(value); },
function() { return Scene.getStageDayTime(); },
function(value) {
var hour = Math.floor(value);
return (hour).toFixed(0) + ":" + ((value - hour)*60.0).toFixed(0);
} }
Scene.setStageDayTime(hour); );
}
Script.setInterval(ticktack, 41); var tickTackPeriod = 50;
*/ var tickTackSpeed = 0.0;
panel.newSlider("Tick tack time", -1.0, 1.0,
function(value) { tickTackSpeed = value; },
function() { return tickTackSpeed; },
function(value) { return (value).toFixed(2); }
);
function runStageTime() {
if (tickTackSpeed != 0.0) {
var hour = panel.get("Day Time");
hour += tickTackSpeed;
panel.set("Day Time", hour);
if (hour >= 24.0) {
panel.set("Year Time", panel.get("Year Time") + 1);
} else if (hour < 0.0) {
panel.set("Year Time", panel.get("Year Time") - 1);
}
}
}
Script.setInterval(runStageTime, tickTackPeriod);
panel.newSlider("Light Intensity", 0.0, 5,
function(value) { Scene.setSunIntensity(value); },
function() { return Scene.getSunIntensity(); },
function(value) { return (value).toFixed(2); }
);
Controller.mouseMoveEvent.connect(function panelMouseMoveEvent(event) { return panel.mouseMoveEvent(event); });
Controller.mousePressEvent.connect( function panelMousePressEvent(event) { return panel.mousePressEvent(event); });
Controller.mouseReleaseEvent.connect(function(event) { return panel.mouseReleaseEvent(event); });
function scriptEnding() {
Menu.removeMenu("Developer > Scene");
panel.destroy();
}
Script.scriptEnding.connect(scriptEnding);

View file

@ -256,6 +256,7 @@ bool setupEssentials(int& argc, char** argv) {
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>(); auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
#endif #endif
auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>(); auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>();
auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>();
return true; return true;
} }
@ -3586,6 +3587,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);
scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
#ifdef HAVE_RTMIDI #ifdef HAVE_RTMIDI
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance()); scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
#endif #endif

View file

@ -92,8 +92,8 @@ void EarthSunModel::setSurfaceOrientation(const Quat& orientation) {
double moduloRange(double val, double minVal, double maxVal) { double moduloRange(double val, double minVal, double maxVal) {
double range = maxVal - minVal; double range = maxVal - minVal;
double rval = (val - minVal) / range; double rval = (val - minVal) / range;
double intval; rval = rval - floor(rval);
return modf(rval, &intval) * range + minVal; return rval * range + minVal;
} }
const float MAX_LONGITUDE = 180.0f; const float MAX_LONGITUDE = 180.0f;

View file

@ -20,20 +20,47 @@ void SceneScriptingInterface::setStageLocation(float longitude, float latitude,
_skyStage->setOriginLocation(longitude, latitude, altitude); _skyStage->setOriginLocation(longitude, latitude, altitude);
} }
float SceneScriptingInterface::getStageLocationLongitude() const {
return _skyStage->getOriginLongitude();
}
float SceneScriptingInterface::getStageLocationLatitude() const {
return _skyStage->getOriginLatitude();
}
float SceneScriptingInterface::getStageLocationAltitude() const {
return _skyStage->getOriginSurfaceAltitude();
}
void SceneScriptingInterface::setStageDayTime(float hour) { void SceneScriptingInterface::setStageDayTime(float hour) {
_skyStage->setDayTime(hour); _skyStage->setDayTime(hour);
} }
float SceneScriptingInterface::getStageDayTime() const {
return _skyStage->getDayTime();
}
void SceneScriptingInterface::setStageYearTime(int day) { void SceneScriptingInterface::setStageYearTime(int day) {
_skyStage->setYearTime(day); _skyStage->setYearTime(day);
} }
int SceneScriptingInterface::getStageYearTime() const {
return _skyStage->getYearTime();
}
void SceneScriptingInterface::setSunColor(const glm::vec3& color) { void SceneScriptingInterface::setSunColor(const glm::vec3& color) {
_skyStage->setSunColor(color); _skyStage->setSunColor(color);
} }
const glm::vec3& SceneScriptingInterface::getSunColor() const {
return _skyStage->getSunColor();
}
void SceneScriptingInterface::setSunIntensity(float intensity) { void SceneScriptingInterface::setSunIntensity(float intensity) {
_skyStage->setSunIntensity(intensity); _skyStage->setSunIntensity(intensity);
} }
float SceneScriptingInterface::getSunIntensity() const {
return _skyStage->getSunIntensity();
}
model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const { model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const {
return _skyStage; return _skyStage;

View file

@ -24,12 +24,21 @@ class SceneScriptingInterface : public QObject, public Dependency {
public: public:
Q_INVOKABLE void setStageOrientation(const glm::quat& orientation); Q_INVOKABLE void setStageOrientation(const glm::quat& orientation);
Q_INVOKABLE void setStageLocation(float longitude, float latitude, float altitude); Q_INVOKABLE void setStageLocation(float longitude, float latitude, float altitude);
Q_INVOKABLE float getStageLocationLongitude() const;
Q_INVOKABLE float getStageLocationLatitude() const;
Q_INVOKABLE float getStageLocationAltitude() const;
Q_INVOKABLE void setStageDayTime(float hour); Q_INVOKABLE void setStageDayTime(float hour);
Q_INVOKABLE float getStageDayTime() const;
Q_INVOKABLE void setStageYearTime(int day); Q_INVOKABLE void setStageYearTime(int day);
Q_INVOKABLE int getStageYearTime() const;
Q_INVOKABLE void setSunColor(const glm::vec3& color); Q_INVOKABLE void setSunColor(const glm::vec3& color);
Q_INVOKABLE const glm::vec3& getSunColor() const;
Q_INVOKABLE void setSunIntensity(float intensity); Q_INVOKABLE void setSunIntensity(float intensity);
Q_INVOKABLE float getSunIntensity() const;
model::SunSkyStagePointer getSkyStage() const; model::SunSkyStagePointer getSkyStage() const;

View file

@ -305,8 +305,6 @@ void ScriptEngine::init() {
_isInitialized = true; _isInitialized = true;
auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>();
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
entityScriptingInterface->init(); entityScriptingInterface->init();
@ -350,7 +348,6 @@ void ScriptEngine::init() {
registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Vec3", &_vec3Library);
registerGlobalObject("Uuid", &_uuidLibrary); registerGlobalObject("Uuid", &_uuidLibrary);
registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
// constants // constants
globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));