Delta3d 简单的控制物体例子

//In this tutorial, you will change the previous Hello World application to
//further your understanding of motion models. Previously you learned how to place a 
//camera in a scene and move the camera position via mouse and keyboard inputs.
//Now we will reverse this situation and move the object while the camera is static.
 


#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> mTextObject;
	dtCore::RefPtr<dtCore::OrbitMotionModel> mMotionModel;
};

HelloWorldApp::HelloWorldApp(const std::string& configFilename)
: dtABC::Application(configFilename)
{
}
HelloWorldApp::~HelloWorldApp()
{
} 
void HelloWorldApp::Config()
{
	// Call the parent class, in case something important is happening there
	Application::Config();

	GetWindow()->SetWindowTitle("HelloWorldApp2");

	// 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
	mMotionModel = new dtCore::OrbitMotionModel(GetKeyboard(), GetMouse());

	// Allocate a dtCore::Object. This class will be your basic container
	// for 3D meshes.
	mTextObject = new dtCore::Object("Text");

	// Load the model file, in this case an OpenFlight model (.flt)
	mTextObject->LoadFile("house1.ive");

	// Setting the camera as a target for the motion model. The camera will
	// will be static, and the camera will move the object using the right
	// clicked mouse.
	mMotionModel->SetTarget(mTextObject);

	// 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(mTextObject.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/models;"); 

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值