OSDN Git Service

fix build system ofmoflib1 and saisei1
[moflib/moflib.git] / moflib-1.0 / src / mof / Board.cpp
1 #include "mof/Board.hpp"
2 #include "mof/Camera.hpp"
3 #include "mof/private/GraphicsDeviceImpl.hpp"
4 #include "mof/ConsoleIO.hpp"
5 #include "mof/stream/Constant.hpp"
6
7 struct mof::Board::Impl{
8         std::shared_ptr<mof::Texture> pTexture;
9         mof::Manipulator<mof::Matrix3D>::Handler worldMatrix;
10         mof::Manipulator<mof::Color4f>::Handler color;
11         mof::Manipulator<mof::Rectangle<float>>::Handler textureCoordinates;
12         FrameNumber m_frame;
13
14         Impl( )
15                 : 
16                 worldMatrix(mof::makeConstantHandler(mof::Matrix3D::createIdentity())) ,
17                 textureCoordinates(mof::makeConstantHandler(mof::Rectangle<float>(0 , 0 , 1 , 1))) ,
18                 color(mof::makeConstantHandler(mof::Color4f(1 , 1 , 1))),
19                 m_frame(0)
20         {
21         }
22
23         ~Impl(){}
24 };
25
26
27
28 mof::Board::Board() : m_pImpl(new Impl()){
29 }
30
31 mof::Board::~Board(){
32 }
33         
34
35
36
37 void mof::Board::setWorldMatrix(const mof::Manipulator<mof::Matrix3D>::Handler& handler){
38         m_pImpl->worldMatrix = handler;
39
40 }
41
42 mof::Matrix3D mof::Board::getWorldMatrix() const
43 {
44         return m_pImpl->worldMatrix->value(m_pImpl->m_frame);
45 }
46
47 mof::Vector3D mof::Board::getPosition() const
48 {
49         mof::Matrix3D m = getWorldMatrix();
50         return mof::Vector3D(m.at(3, 0), m.at(3, 1), m.at(3, 2) );
51 }
52
53
54
55 void mof::Board::setColor(const mof::Manipulator<mof::Color4f>::Handler& handler){
56         m_pImpl->color = handler;
57 }
58
59
60
61
62 void mof::Board::setTextureCoordinates(const mof::Manipulator<mof::Rectangle<float>>::Handler& handler){
63         m_pImpl->textureCoordinates = handler;
64 }
65
66 void mof::Board::setTextureCoordinates(const mof::Rectangle<float>& coordinates){
67         setTextureCoordinates(mof::makeConstantHandler(coordinates));
68 }
69
70 void mof::Board::setTexture( const std::shared_ptr<mof::Texture>& pTexture ){
71         m_pImpl->pTexture = pTexture;
72 }
73
74
75 bool mof::Board::isVisible() const{
76         return true;
77 }
78
79 void mof::Board::update(){
80         m_pImpl->m_frame++;
81 }
82
83
84 void mof::Board::draw() const{
85         mof::FrameNumber frame = m_pImpl->m_frame;
86         mof::Rectangle<float> textureCoordinates = m_pImpl->textureCoordinates->value(frame);
87         mof::Color color = m_pImpl->color->value(frame).toColorCode();
88         static mof::VertexXYZCUV vertices[4];
89         vertices[0].x = -0.5f;
90         vertices[0].y = 0.5f;
91         vertices[0].z = 0;
92         vertices[0].color = color;
93         vertices[0].tu = textureCoordinates.beginX;
94         vertices[0].tv = textureCoordinates.beginY;
95
96         vertices[1].x = 0.5f;
97         vertices[1].y = 0.5f;
98         vertices[1].z = 0;
99         vertices[1].color = color;
100         vertices[1].tu = textureCoordinates.endX;
101         vertices[1].tv = textureCoordinates.beginY;
102
103         vertices[2].x = -0.5f;
104         vertices[2].y = -0.5f;
105         vertices[2].z = 0;
106         vertices[2].color = color;
107         vertices[2].tu = textureCoordinates.beginX;
108         vertices[2].tv = textureCoordinates.endY;
109
110         vertices[3].x = 0.5f;
111         vertices[3].y = -0.5f;
112         vertices[3].z = 0;
113         vertices[3].color = color;
114         vertices[3].tu = textureCoordinates.endX;
115         vertices[3].tv = textureCoordinates.endY;
116
117         mof::GraphicsDevice::setTexture(m_pImpl->pTexture.get());
118         mof::GraphicsDevice::setWorldTransform(m_pImpl->worldMatrix->value(frame));
119         mof::GraphicsDevice::drawVertexArray(vertices[0] , vertices[3] , PRIMITIVE_TYPE_TRIANGLESTRIP);
120         
121 }
122
123 void mof::Board::setVisible(bool)
124 {
125         // TODO
126 }
127
128 void mof::Board::setFrameNumber(mof::FrameNumber fn)
129 {
130         m_pImpl->m_frame = fn;
131 }
132