Delta3d 之 HelloWorld



#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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值