Delta3d 简单的控制物体例子

来源:互联网 发布:网络安全法 实施细则 编辑:程序博客网 时间:2024/06/05 12:56
//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 thereApplication::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 cameramMotionModel = 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 filedtCore::RefPtr<HelloWorldApp> app = new HelloWorldApp("config.xml");app->Config(); //configuring the applicationapp->Run(); // running the simulation loopreturn 0;}