|
SilverLining for Android
1.0
Skies, 3D clouds, and weather for Android
|
You may also develop apps entirely in C++, using the static libraries provided for SilverLining as part of the SDK and the Android NDK.
As an example, import the SilverLiningNativeActivityDemo directory of the SDK into your workspace (File / New / Android Project / Create Project from Existing Source for Eclipse Indigo, or Import / Android / Existing Android Code into Workspace for Eclipse Juno.) Right click the resulting activity, and select Run As / Android Application to deploy it to your tethered OpenGL 2.0 ES capable device. You should see the following:
To include SilverLining in your native activity, you'll need to include it as part of your Android.mk file. For example:
include $(CLEAR_VARS) LOCAL_MODULE := silverlining_prebuilt LOCAL_SRC_FILES := ../../static_lib_stlport/$(TARGET_ARCH_ABI)/libsilverlining_static.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include include $(PREBUILT_STATIC_LIBRARY)
In this example, we've specified the STLPORT version of the SilverLining static libraries under the SilverLining SDK's static_lib_stlport directory. If your app is built against GNU STL instead, you'll also find a static_lib_gnustl for you.
With this block in place, you can then add silverlining_prebuilt to your LOCAL_STATIC_LIBRARIES line for your own activity, and automatically have the necessary libraries and header files available to your NDK project.
The full C++ API for SilverLining is at your disposal, documented at http://www.sundog-soft.com/docs/html/index.html .
Explore the main.cpp file in the JNI directory of the native activity demo for an overview of how to use SilverLining from C++ code under Android. The C++ API documention above will walk you through the process of initializing and updating SilverLining in your app, or you can pick it up from this demo code.
The Android-specific piece is providing a ResourceLoader implementation for SilverLining to allow it to access its textures, configuration, and models through Android's asset manager. Make sure the assets/Resources directory from the demo is copied into your own project. We provide an AndroidResourceLoader class as part of our static libraries to make this easy. For example, here's what initialization of SilverLining looks like from an Android native activity:
#include "SilverLining.h" atm = SL_NEW Atmosphere("user name", "license code"); AndroidResourceLoader *rl = SL_NEW AndroidResourceLoader(engine->app->activity->assetManager); atm->SetResourceLoader(rl); int errcode = atm->Initialize(Atmosphere::OPENGLES2, "Resources", true, 0); if (errcode != Atmosphere::E_NOERROR) { LOGW("Did not intialize atmosphere. Error %d", errcode); }
After initialization, you'll want to specify a time and location to simulate. For example:
Location loc;
loc.SetLatitude(45);
loc.SetLongitude(-122);
LocalTime tm;
tm.SetYear(1971);
tm.SetMonth(8);
tm.SetDay(7);
tm.SetHour(30);
tm.SetMinutes(30);
tm.SetSeconds(0);
tm.SetObservingDaylightSavingsTime(true);
tm.SetTimeZone(PST);
atm->GetConditions()->SetTime(tm);
atm->GetConditions()->SetLocation(loc);
You'll probably want some clouds in your scene as well. Here's an example of setting up a layer of cumulus congestus clouds:
CloudLayer *cumulusCongestusLayer;
cumulusCongestusLayer = CloudLayerFactory::Create(CUMULUS_CONGESTUS);
cumulusCongestusLayer->SetIsInfinite(true);
cumulusCongestusLayer->SetBaseAltitude(1500);
cumulusCongestusLayer->SetThickness(100);
cumulusCongestusLayer->SetBaseLength(30000);
cumulusCongestusLayer->SetBaseWidth(30000);
cumulusCongestusLayer->SetDensity(0.4);
cumulusCongestusLayer->SetLayerPosition(0, 0);
cumulusCongestusLayer->SetCloudAnimationEffects(0.1, false);
cumulusCongestusLayer->SeedClouds(*atm);
cumulusCongestusLayer->GenerateShadowMaps(false);
atm->GetConditions()->AddCloudLayer(cumulusCongestusLayer);
Much more is possible, and we encourage you to read the C++ documentation at http://www.sundog-soft.com/docs/html/index.html to learn more.
1.7.5