#include <dtABC/application.h>
#include <dtCore/refptr.h>
#include <dtCore/object.h>
#include <dtCore/orbitmotionmodel.h>
#include <dtCore/deltawin.h>
#include <dtCore/transform.h>
#include<dtUtil/datapathutils.h>
class HelloWorldApp : public dtABC::Application
{
public:
HelloWorldApp(const std::string& configFilename);
// Override this function to setup your scene.
virtual void Config();
protected:
// Destructors for subclasses of dtCore::Base must have a protected
// destructor. Otherwise use of RefPtrs will cause some serious
// problems if the objects are allocated on the stack.
virtual ~HelloWorldApp();
private:
// dtCore::RefPtr is a template for a smart pointer that takes
// care of reference counting for objects allocated on the heap.
// It is good practice to store all objects that derive from
// dtCore::Base inside a RefPtr.
dtCore::RefPtr<dtCore::Object> mTerrainObject;
dtCore::RefPtr<dtCore::OrbitMotionModel> mMotionModel;
};
HelloWorldApp::HelloWorldApp(const std::string& configFilename)
: dtABC::Application(configFilename)
{
}
HelloWorldApp::~HelloWorldApp()
{
}void HelloWorldApp::Config()
{
Application::Config();
GetWindow()->SetWindowTitle("HelloWorldApp");
// Adjust the Camera position by instantiating a transform object to
// store the camera position and attitude.
dtCore::Transform camPosition(0.f, -100.f, 10.f, 0.f, 0.f, 0.f);
GetCamera()->SetTransform(camPosition);
// Setting a motion model for the camera
// Delta3D has a few stock motion models that can be used to move things in the scene
// based on user input. One of the most basic is OrbitMotionModel
// which gives the standard 3D "world-in-hand" type of control
mMotionModel = new dtCore::OrbitMotionModel(GetKeyboard(), GetMouse());
// Setting the camera as a target for the motion model. The terrain object
// will be static at 0,0,0 and the camera will move using
// the right clicked mouse.
mMotionModel->SetTarget(GetCamera());
// Allocate a dtCore::Object. This class will be your basic container
// for 3D meshes.
mTerrainObject = new dtCore::Object("Terrain");
// Load the model file, in this case an Open Scene Graph model (.ive)
mTerrainObject->LoadFile("models/terrain_simple.ive");
// Add the Object to the scene. Since the object is a RefPtr, we must
// pull the internal point out to pass it to the Scene.
AddDrawable(mTerrainObject.get());
}
int main(int arc, char **argv)
{
// Setup the data file search paths for the config file and the models files.
// This is best done in main prior to configuring app. That way the paths
// are ensured to be correct when loading data.
dtUtil::SetDataFilePathList( "..;" +
dtUtil::GetDeltaDataPathList() + ";" +
dtUtil::GetDeltaRootPath() + "/examples/data/;");
//Instantiate the application and look for the config file
dtCore::RefPtr<HelloWorldApp> app = new HelloWorldApp("config.xml");
app->Config(); //configuring the application
app->Run(); // running the simulation loop
return 0;
}
Delta3d 之 HelloWorld
最新推荐文章于 2021-10-07 18:49:05 发布