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"
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;
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))),
28 mof::Board::Board() : m_pImpl(new Impl()){
37 void mof::Board::setWorldMatrix(const mof::Manipulator<mof::Matrix3D>::Handler& handler){
38 m_pImpl->worldMatrix = handler;
42 mof::Matrix3D mof::Board::getWorldMatrix() const
44 return m_pImpl->worldMatrix->value(m_pImpl->m_frame);
47 mof::Vector3D mof::Board::getPosition() const
49 mof::Matrix3D m = getWorldMatrix();
50 return mof::Vector3D(m.at(3, 0), m.at(3, 1), m.at(3, 2) );
55 void mof::Board::setColor(const mof::Manipulator<mof::Color4f>::Handler& handler){
56 m_pImpl->color = handler;
62 void mof::Board::setTextureCoordinates(const mof::Manipulator<mof::Rectangle<float>>::Handler& handler){
63 m_pImpl->textureCoordinates = handler;
66 void mof::Board::setTextureCoordinates(const mof::Rectangle<float>& coordinates){
67 setTextureCoordinates(mof::makeConstantHandler(coordinates));
70 void mof::Board::setTexture( const std::shared_ptr<mof::Texture>& pTexture ){
71 m_pImpl->pTexture = pTexture;
75 bool mof::Board::isVisible() const{
79 void mof::Board::update(){
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;
92 vertices[0].color = color;
93 vertices[0].tu = textureCoordinates.beginX;
94 vertices[0].tv = textureCoordinates.beginY;
99 vertices[1].color = color;
100 vertices[1].tu = textureCoordinates.endX;
101 vertices[1].tv = textureCoordinates.beginY;
103 vertices[2].x = -0.5f;
104 vertices[2].y = -0.5f;
106 vertices[2].color = color;
107 vertices[2].tu = textureCoordinates.beginX;
108 vertices[2].tv = textureCoordinates.endY;
110 vertices[3].x = 0.5f;
111 vertices[3].y = -0.5f;
113 vertices[3].color = color;
114 vertices[3].tu = textureCoordinates.endX;
115 vertices[3].tv = textureCoordinates.endY;
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);
123 void mof::Board::setVisible(bool)
128 void mof::Board::setFrameNumber(mof::FrameNumber fn)
130 m_pImpl->m_frame = fn;