![]() |
VR-Forces 5.0.3 Developer's Guide
|
The Modify Weather Model example demonstrates the following:
Weather data is accessed from within VR-Forces using DtEnvironmentalStateManager. This manager, internally, uses a class called DtWeatherStateProvider to provide actual weather data. In its first tick the environmental state manager creates a DtWeatherStateProvider using the DtWeatherStateProviderFactory. The type of weather state provider created is determined by the weather-state-provider parameter in physicalWorldParameters.mtl.
In the default weather state provider, the weather data comes from the Global Weather Object, local Weather Objects, and Cloud Layer objects. These objects have state described in DtGlobalEnvironmentRepository, DtWeatherStateRepository, and DtCloudLayerStateRepository, respectively. Many of the weather attributes accessible through the environmental state manager come directly from these object repositories. However, the weather state provider can make other calculations; for example, the air temperature that the default weather state provider calculates uses a standard model of the atmosphere to provide an altitude-varying temperature.
To define a different weather model, override the DtWeatherStateProvider class and define new implementations of whichever weather attribute functions are to be calculated differently. The provider in this plugin, for example, estimates mean sea level temperature based on latitude and then applies the altitude-varying temperature model to that.
The DtWeatherStateProvider class includes an init() function that is called when the environmental state manager creates the object. It also includes a tick() function that is called from inside the environmental state manager tick(). Neither of these functions do anything in the default DtWeatherStateProvider, but they could be given tasks in a derived class.
The new weather model can make use of weather objects, cloud layers, constants, and configurations in the environmental state manager when it calculates weather attributes. For example, the provider could get the wind speed at a location this way:
To use the weather provider class, you must add it to the WeatherStateProviderFactory. To do this, call the addCreatorFcn() method in the DtInitializeVrfPlugin function, defined in plugin.cxx.
This example is loaded as a VR-Forces back-end plugin. It can be used in conjunction with the released VR-Forces application.
The name of the weather model to used is define in physicalWorldParameters.mtl in the SMS. Even after the plugin is loaded, the environmental state manager will use the default weather state provider unless the model name parameter is changed. Once VR-Forces is running with the plugin loaded, different models can be loaded without restarting VR-Forces if they use different SMSs. To run this example load the scenario data\scenarios\developer_toolkit_examples\modifyWeatherModel\modifyWeatherModel.scnx which uses a custom sms to specify in the physicalWorldParameters.mtl to use the "latitude-based-temperature" MyWeatherStateProvider class. Once loaded, in the View menu open the "Last Clicked Environment Panel" Now click at different latitudes and observe the air temperature change. For example, click in Mexico then click in Alaska. Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application
| MyWeatherStateProvider | Derived from DtWeatherStateProvider, modifies the airTemperature accessor function to estimate sea level temperature from the point latitude before calculating final temperature based on altitude. |
/*******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "vrfcgf/vrfPluginExtension.h"
#include "myWeatherStateProvider.h"
#include <vrfcgf/cgf.h>
#include <vrfcgf/factoryManager.h>
#include <vrfobjcore/weatherStateProviderFactory.h>
extern "C" {
DT_VRF_DLL_PLUGIN void DtPluginInformation(DtVrfPluginInformation& info)
{
info.pluginName = "Modify Weather Model";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
info.pluginDescription = "This plugin modifies the air temperature attribute in the weather model.\n"
"For the new model to take effect, change the weather-state-provider parameter in\n"
"physicalWorldParams.mtl to be \"latitude-based-temperature\".\n";
}
DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
{
//Register the creation function for our derived weather model with the
//DtWeatherStateProviderFactory. The name of the model must also be put
//in the physicalWorldParams.mtl file in the
//weather-state-provider entry.
cgf->factoryManager()->weatherStateProviderFactory()->addCreatorFcn(
"latitude-based-temperature", MyWeatherStateProvider::create);
return true;
}
}