OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / saisei-1.0 / src / Demo2.cpp
1 #include "Demo2.hpp"
2 #include "configure.hpp"
3 #include "mof/EventScheduler.hpp"
4 #include "mof/mofInput.hpp"
5 #include "mof/mofGraphics.hpp"
6 #include "mof/Application.hpp"
7 #include "mof/utilities.hpp"
8 #include "mof/widgets.hpp"
9 #include "resource.hpp"
10 #include <mof/streams.hpp>
11 #include <mof/FactoryMethod.hpp>
12 #include <boost/bind.hpp> 
13 #include <memory> 
14 #include <mof/ConsoleIO.hpp>
15 #include <mof/script/LuaInterpreter.hpp>
16 #include "script/MyEnvironment.hpp"
17
18 #include "CharacterBoard.hpp"
19
20 using namespace mof::widget;
21 using namespace boost;
22
23 namespace
24 {
25         
26         std::shared_ptr<mof::script::LuaInterpreter> interpreter_;
27         std::shared_ptr<mof::script::Environment> environment_;
28         std::shared_ptr<mof::InputReceiver> m_pInputReceiver;
29         mof::Graphics3D::ptr field_;
30         mof::EventScheduler m_scheduler;
31         mof::Camera::ptr camera_;
32         mof::Light::ptr light_;
33 }
34         
35 namespace Demo2
36 {
37 //{{{ initialize
38     void initialize()
39     {
40                 mof::Application::InputMode mode = mof::Application::input_mode();
41                 if (mode == mof::Application::INPUT_MODE_DEVICE) {
42                 m_pInputReceiver = std::shared_ptr<mof::InputReceiver>(mof::InputDevice::getInputReceiver());
43                 }
44                 else if (mode == mof::Application::INPUT_MODE_LOGGING) {
45                 m_pInputReceiver = std::make_shared<mof::LoggingInputReceiver>((TCHAR*)_T("inputLog.txt"));
46                 }
47                 else if (mode == mof::Application::INPUT_MODE_LOGGED) {
48                 m_pInputReceiver = std::make_shared<mof::LoggedInputReceiver>((TCHAR*)_T("inputLog.txt"));
49                 }
50
51                 environment_ = std::make_shared<script::MyEnvironment>(m_pInputReceiver);
52                 interpreter_ = std::make_shared<mof::script::LuaInterpreter>(_T("script/effect_test.lua"));
53                 interpreter_->start("main");
54                 interpreter_->bind(environment_);
55             mof::GraphicsDevice::lightEnable(false);
56             mof::GraphicsDevice::setAlphaBlendingMode(mof::GraphicsDevice::BLENDING_MODE_ALPHA);
57    
58                 field_ = std::shared_ptr<mof::Graphics3D>(mof::MeshBuilder("model/floor.x").construct());
59
60                 // 3D\83V\81[\83\93\82Ì\90Ý\92è
61         //mof::GraphicsDevice::lightEnable(true);
62                 camera_ = std::make_shared<mof::Camera>(mof::Vector3D(0, 1, -2), mof::Vector3D(0, 0, 0), mof::Vector3D(0, 1, 0));
63         //light_ = std::make_shared<mof::AmbientLight>(mof::Color4f(mof::createColor(255 , 255 , 255)));
64
65         }
66 //}}}
67 //{{{ finalize
68     void finalize( )
69     {
70     }
71 //}}} 
72     
73
74     void update()
75     {
76         m_scheduler.update();
77         m_pInputReceiver->update();
78
79                 if(!environment_->isWaiting()) interpreter_->update();
80                 environment_->update();
81                 field_->update();
82                 camera_->update();
83     }
84
85     void draw()
86     {
87                 mof::Rectangle<int> cr = mof::GraphicsDevice::getClientRegion();
88             mof::VertexXYZRHWC vertices[] = 
89             {
90                 mof::VertexXYZRHWC(mof::Vector2D(0 , 0) , mof::createColor(127 , 127 , 127)) ,
91                 mof::VertexXYZRHWC(mof::Vector2D(cr.getWidth() , 0) , mof::createColor(127 , 127 , 127)) ,
92                 mof::VertexXYZRHWC(mof::Vector2D(0 , cr.getHeight()) , mof::createColor(255 , 255 , 255)) ,
93                 mof::VertexXYZRHWC(mof::Vector2D(cr.getWidth() , cr.getHeight()) , mof::createColor(255 , 255 , 255))
94             };
95                 mof::GraphicsDevice::setViewTransform(camera_->getViewMatrix());
96             mof::GraphicsDevice::setTexture(NULL);
97             mof::GraphicsDevice::drawVertexArray(vertices[0] , vertices[3] , mof::PRIMITIVE_TYPE_TRIANGLESTRIP );
98         mof::GraphicsDevice::clearZBuffer();
99                 field_->draw();
100                 environment_->draw();
101     }
102
103 } // namespace Demo2
104
105