From 97c3dc3b2f9b8c7c465a5dd0e64516861ed8a4ac Mon Sep 17 00:00:00 2001 From: Antoine Chavasse Date: Tue, 3 Jul 2007 02:46:16 +0200 Subject: [PATCH] Math: renamed Rect to Rectf, implemented Vector2u32 and Rectu32. Scenegraph: implemented viewport and camera. --- app/startup.lua | 2 +- gui/BoringTheme/ButtonDecorator.cpp | 4 +-- gui/BoringTheme/WindowDecorator.cpp | 8 ++--- gui/HGroup.cpp | 4 +-- gui/SimpleContainer.cpp | 2 +- gui/SimpleContainer.h | 2 +- gui/VGroup.cpp | 4 +-- gui/Widget.cpp | 2 +- gui/Widget.h | 8 ++--- gui/Window.cpp | 4 +-- gui/Window.h | 2 +- gui/gui.aidl | 2 +- math/Matrix44f.cpp | 60 ++++++++++++++++++++++++++++++++++ math/Matrix44f.h | 5 +++ math/{Rect.h => Rectf.h} | 12 +++---- math/Rectu32.h | 47 +++++++++++++++++++++++++++ math/Vector2u32.h | 62 +++++++++++++++++++++++++++++++++++ math/math.aidl | 33 ++++++++++++++++--- renderer/Context.h | 4 +-- renderer/renderer.aidl | 2 +- scenegraph/Camera.h | 64 +++++++++++++++++++++++++++++++++++++ scenegraph/RenderContext.cpp | 2 ++ scenegraph/RenderContext.h | 12 ++++++- scenegraph/ViewPort.h | 59 ++++++++++++++++++++++++++++++++++ scenegraph/scenegraph.aidl | 20 ++++++++++++ 25 files changed, 390 insertions(+), 36 deletions(-) rename math/{Rect.h => Rectf.h} (80%) create mode 100644 math/Rectu32.h create mode 100644 math/Vector2u32.h create mode 100644 scenegraph/Camera.h create mode 100644 scenegraph/ViewPort.h diff --git a/app/startup.lua b/app/startup.lua index 960a376..5e0b299 100644 --- a/app/startup.lua +++ b/app/startup.lua @@ -20,7 +20,7 @@ guiroot = awful.gui.SimpleContainer( theme ) -- Create a window containg a layout group window = awful.gui.Window( guiroot ) -window.Rect = awful.math.Rect( 50, 70, 0, 0 ) +window.Rect = awful.math.Rectf( 50, 70, 0, 0 ) vg = awful.gui.VGroup( window ) awful.gui.Button( vg, "Tubgirl" ) awful.gui.Button( vg, "Goatse" ) diff --git a/gui/BoringTheme/ButtonDecorator.cpp b/gui/BoringTheme/ButtonDecorator.cpp index 6b34950..45fe75b 100644 --- a/gui/BoringTheme/ButtonDecorator.cpp +++ b/gui/BoringTheme/ButtonDecorator.cpp @@ -25,7 +25,7 @@ void BoringButtonDecorator::calcMinMax() void BoringButtonDecorator::layout() { const std::string& label( m_pButton->getLabel() ); - const math::Rect& rect( m_pButton->getRect() ); + const math::Rectf& rect( m_pButton->getRect() ); m_labelx = ( rect.width() - m_pFont->getTextWidth( label ) ) / 2.f; m_labely = ( rect.height() - m_pFont->getHeight() ) / 2.f; @@ -34,7 +34,7 @@ void BoringButtonDecorator::layout() void BoringButtonDecorator::render( Pointer< renderer::Context > pContext ) { const std::string& label( m_pButton->getLabel() ); - const math::Rect& rect( m_pButton->getRect() ); + const math::Rectf& rect( m_pButton->getRect() ); switch( m_pButton->getState() ) { diff --git a/gui/BoringTheme/WindowDecorator.cpp b/gui/BoringTheme/WindowDecorator.cpp index 5ada681..2dcff1c 100644 --- a/gui/BoringTheme/WindowDecorator.cpp +++ b/gui/BoringTheme/WindowDecorator.cpp @@ -34,8 +34,8 @@ void BoringWindowDecorator::layout() if( !pContent ) return; - const math::Rect& wrect( m_pWindow->getRect() ); - math::Rect r; + const math::Rectf& wrect( m_pWindow->getRect() ); + math::Rectf r; //r.width() = wrect.width(); //r.height() = 10.f; @@ -61,7 +61,7 @@ void BoringWindowDecorator::render( Pointer< renderer::Context > pContext_ ) { pContext_->setColor( 0.0, 0.0, 1.0 ); - const math::Rect& rect( m_pWindow->getRect() ); + const math::Rectf& rect( m_pWindow->getRect() ); pContext_->drawRectangle( 0.f, 0.f, rect.width(), rect.height() ); Pointer< Widget > pContent = m_pWindow->getContent(); @@ -95,7 +95,7 @@ void BoringWindowDecorator::sizing( math::Vector2f pos, math::Vector2f ) if( maxsize.y() && maxsize.y() < newsize.y() ) newsize.y() = maxsize.y(); - math::Rect rect( m_pWindow->getRect() ); + math::Rectf rect( m_pWindow->getRect() ); if( newsize == rect.size() ) return; diff --git a/gui/HGroup.cpp b/gui/HGroup.cpp index 06d7f34..0ee4346 100644 --- a/gui/HGroup.cpp +++ b/gui/HGroup.cpp @@ -63,7 +63,7 @@ void HGroup::layout() { WidgetList::size_type numchildren = m_Children.size(); - const math::Rect& r( getRect() ); + const math::Rectf& r( getRect() ); float FreeSpace = r.width() - m_Spacing * static_cast< float >( numchildren - 1 ); // Currently, all children have a weight of 1. I'll implement weighted layout @@ -144,7 +144,7 @@ void HGroup::layout() } } while( it != m_Children.end() ); - math::Rect crect; + math::Rectf crect; for( it = m_Children.begin(), i = 0; it != m_Children.end(); ++it, ++i ) { diff --git a/gui/SimpleContainer.cpp b/gui/SimpleContainer.cpp index 213321f..6233c70 100644 --- a/gui/SimpleContainer.cpp +++ b/gui/SimpleContainer.cpp @@ -111,7 +111,7 @@ void SimpleContainer::render( Pointer< renderer::Context > pContext_ ) } } -void SimpleContainer::setRect( const math::Rect& r ) +void SimpleContainer::setRect( const math::Rectf& r ) { Widget::setRect( r ); WidgetList::const_iterator it; diff --git a/gui/SimpleContainer.h b/gui/SimpleContainer.h index 6a41f85..f6948a8 100644 --- a/gui/SimpleContainer.h +++ b/gui/SimpleContainer.h @@ -18,7 +18,7 @@ namespace awful { namespace gui virtual bool mouseMotionEvent( const math::Vector2f& pos, const math::Vector2f& rel ); virtual bool mouseButtonEvent( const math::Vector2f& pos, e_MouseButton Button, bool bPressed ); - virtual void setRect( const math::Rect& r ); + virtual void setRect( const math::Rectf& r ); virtual void setAbsPos( const math::Vector2f& p ); virtual void calcMinMax(); diff --git a/gui/VGroup.cpp b/gui/VGroup.cpp index 55688d8..95fa5e1 100644 --- a/gui/VGroup.cpp +++ b/gui/VGroup.cpp @@ -63,7 +63,7 @@ void VGroup::layout() { WidgetList::size_type numchildren = m_Children.size(); - const math::Rect& r( getRect() ); + const math::Rectf& r( getRect() ); float FreeSpace = r.height() - m_Spacing * static_cast< float >( numchildren - 1 ); // Currently, all children have a weight of 1. I'll implement weighted layout @@ -144,7 +144,7 @@ void VGroup::layout() } } while( it != m_Children.end() ); - math::Rect crect; + math::Rectf crect; for( it = m_Children.begin(), i = 0; it != m_Children.end(); ++it, ++i ) { diff --git a/gui/Widget.cpp b/gui/Widget.cpp index 5774150..25f9d3f 100644 --- a/gui/Widget.cpp +++ b/gui/Widget.cpp @@ -21,7 +21,7 @@ Widget::Widget( ContainerWidget* pParent_ ) : pParent_->addChild( this ); } -void Widget::setRect( const math::Rect& r ) +void Widget::setRect( const math::Rectf& r ) { m_Rect = r; m_AbsPos = m_Rect.position(); diff --git a/gui/Widget.h b/gui/Widget.h index f71150b..adcd7a1 100644 --- a/gui/Widget.h +++ b/gui/Widget.h @@ -2,7 +2,7 @@ #define AWFUL_GUI_WIDGET_H_ #include "EventHandler.h" -#include "math/Rect.h" +#include "math/Rectf.h" #include "math/Vector2f.h" #include "renderer/Context.h" #include "core/core.h" @@ -31,8 +31,8 @@ namespace awful { namespace gui layout(); } - const math::Rect& getRect() const { return m_Rect; } - virtual void setRect( const math::Rect& r ); + const math::Rectf& getRect() const { return m_Rect; } + virtual void setRect( const math::Rectf& r ); const math::Vector2f& getMinSize() const { return m_MinSize; } void setMinSize( const math::Vector2f& x ) { m_MinSize = x; } @@ -55,7 +55,7 @@ namespace awful { namespace gui } protected: - math::Rect m_Rect; + math::Rectf m_Rect; math::Vector2f m_MinSize; math::Vector2f m_MaxSize; math::Vector2f m_AbsPos; diff --git a/gui/Window.cpp b/gui/Window.cpp index 73398c9..085342f 100644 --- a/gui/Window.cpp +++ b/gui/Window.cpp @@ -83,7 +83,7 @@ void Window::setDecoratorPos() const m_pDecorator->setAbsPos( getAbsPos() ); } -void Window::setRect( const math::Rect& r ) +void Window::setRect( const math::Rectf& r ) { Widget::setRect( r ); setDecoratorPos(); @@ -119,7 +119,7 @@ void Window::calcMinMax() // Force the current size to match the min/max requirements const math::Vector2f& minsize = getMinSize(); - math::Rect rect( getRect() ); + math::Rectf rect( getRect() ); if( rect.width() < minsize.x() ) rect.width() = minsize.x(); diff --git a/gui/Window.h b/gui/Window.h index c7c1d4d..df72b0b 100644 --- a/gui/Window.h +++ b/gui/Window.h @@ -18,7 +18,7 @@ namespace awful { namespace gui virtual bool mouseMotionEvent( const math::Vector2f& pos, const math::Vector2f& rel ); virtual bool mouseButtonEvent( const math::Vector2f& pos, e_MouseButton Button, bool bPressed ); - virtual void setRect( const math::Rect& r ); + virtual void setRect( const math::Rectf& r ); virtual void setAbsPos( const math::Vector2f& p ); virtual void calcMinMax(); diff --git a/gui/gui.aidl b/gui/gui.aidl index bde9a08..33e0898 100644 --- a/gui/gui.aidl +++ b/gui/gui.aidl @@ -32,7 +32,7 @@ namespace awful { namespace gui [ unmutable=true ] math::Vector2f AbsPos; - math::Rect Rect; + math::Rectf Rect; [ readonly=true ] math::Vector2f MinSize; diff --git a/math/Matrix44f.cpp b/math/Matrix44f.cpp index b67bb24..54f6ded 100644 --- a/math/Matrix44f.cpp +++ b/math/Matrix44f.cpp @@ -95,3 +95,63 @@ Matrix44f awful::math::operator*( const Matrix44f& a, const Matrix44f& b ) return Res; } + +bool Matrix44f::inverse( Matrix44f& Dest_ ) const +{ + return false; +} + + +/* +bool Matrix::inverse( Matrix* _pResult ) const +{ + float Det; + + float D12, D13, D23, D24, D34, D41; + D12 = ( M31 * M42 - M41 * M32 ); + D13 = ( M31 * M43 - M41 * M33 ); + D23 = ( M32 * M43 - M42 * M33 ); + D24 = ( M32 * M44 - M42 * M34 ); + D34 = ( M33 * M44 - M43 * M34 ); + D41 = ( M34 * M41 - M44 * M31 ); + + _pResult->M11 = ( M22 * D34 - M23 * D24 + M24 * D23 ); + _pResult->M21 = -( M21 * D34 + M23 * D41 + M24 * D13 ); + _pResult->M31 = ( M21 * D24 + M22 * D41 + M24 * D12 ); +// _pResult->M41 = -( M21 * D23 - M22 * D13 + M23 * D12 ); + + Det = M11 * _pResult->M11 + M12 * _pResult->M21 + M13 * _pResult->M31; + //+ M14 * _pResult->M41; + + if( Det == 0.f ) + return false; + + _pResult->M12 = -( M12 * D34 - M13 * D24 + M14 * D23 ); + _pResult->M22 = ( M11 * D34 + M13 * D41 + M14 * D13 ); + _pResult->M32 = -( M11 * D24 + M12 * D41 + M14 * D12 ); +// _pResult->M42 = ( M11 * D23 - M12 * D13 + M13 * D12 ); + + D12 = M11 * M22 - M21 * M12; + D13 = M11 * M23 - M21 * M13; + D23 = M12 * M23 - M22 * M13; + D24 = M12 * M24 - M22 * M14; + D34 = M13 * M24 - M23 * M14; + D41 = M14 * M21 - M24 * M11; + + _pResult->M13 = ( M42 * D34 - M43 * D24 + M44 * D23 ); + _pResult->M23 = -( M41 * D34 + M43 * D41 + M44 * D13 ); + _pResult->M33 = ( M41 * D24 + M42 * D41 + M44 * D12 ); +// _pResult->M43 = -( M41 * D23 - M42 * D13 + M43 * D12 ); + + _pResult->M14 = -( M32 * D34 - M33 * D24 + M34 * D23 ); + _pResult->M24 = ( M31 * D34 + M33 * D41 + M34 * D13 ); + _pResult->M34 = -( M31 * D24 + M32 * D41 + M34 * D12 ); +// _pResult->M44 = ( M31 * D23 - M32 * D13 + M33 * D12 ); + + Det = 1.f / Det; + + _pResult->right *= Det; + _pResult->up *= Det; + _pResult->back *= Det; + _pResult->pos *= Det; +}*/ diff --git a/math/Matrix44f.h b/math/Matrix44f.h index 54b89f9..f9d6f41 100644 --- a/math/Matrix44f.h +++ b/math/Matrix44f.h @@ -44,6 +44,11 @@ namespace awful { namespace math const Vector4f& forward() const { return m_v2; } const Vector4f& up() const { return m_v3; } + // Operations + + // Inversion + bool inverse( Matrix44f& Dest_ ) const; + private: Vector4f m_v1; Vector4f m_v2; diff --git a/math/Rect.h b/math/Rectf.h similarity index 80% rename from math/Rect.h rename to math/Rectf.h index 86bc279..56c6962 100644 --- a/math/Rect.h +++ b/math/Rectf.h @@ -1,22 +1,22 @@ -#ifndef AWFUL_MATH_RECT_H_ -#define AWFUL_MATH_RECT_H_ +#ifndef AWFUL_MATH_RECTF_H_ +#define AWFUL_MATH_RECTF_H_ #include "Vector2f.h" #include "core/core.h" namespace awful { namespace math { - struct Rect + struct Rectf { - Rect() {} + Rectf() {} - Rect( const Vector2f& position_, const Vector2f& size_ ) : + Rectf( const Vector2f& position_, const Vector2f& size_ ) : m_position( position_ ), m_size( size_ ) { } - Rect( float left_, float top_, float width_, float height_ ) : + Rectf( float left_, float top_, float width_, float height_ ) : m_position( left_, top_ ), m_size( width_, height_ ) { diff --git a/math/Rectu32.h b/math/Rectu32.h new file mode 100644 index 0000000..e9f0381 --- /dev/null +++ b/math/Rectu32.h @@ -0,0 +1,47 @@ +#ifndef AWFUL_MATH_RECTU32_H_ +#define AWFUL_MATH_RECTU32_H_ + +#include "Vector2u32.h" +#include "core/core.h" + +namespace awful { namespace math +{ + struct Rectu32 + { + Rectu32() {} + + Rectu32( const Vector2u32& position_, const Vector2u32& size_ ) : + m_position( position_ ), + m_size( size_ ) + { + } + + Rectu32( uint32_t left_, uint32_t top_, uint32_t width_, uint32_t height_ ) : + m_position( left_, top_ ), + m_size( width_, height_ ) + { + } + + Vector2u32& position() { return m_position; } + Vector2u32& size() { return m_size; } + + uint32_t& left() { return m_position.x(); } + uint32_t& top() { return m_position.y(); } + uint32_t& width() { return m_size.x(); } + uint32_t& height() { return m_size.y(); } + + const Vector2u32& position() const { return m_position; } + const Vector2u32& size() const { return m_size; } + + const uint32_t& left() const { return m_position.x(); } + const uint32_t& top() const { return m_position.y(); } + const uint32_t& width() const { return m_size.x(); } + const uint32_t& height() const { return m_size.y(); } + + private: + Vector2u32 m_position; + Vector2u32 m_size; + }; +}} + +#endif diff --git a/math/Vector2u32.h b/math/Vector2u32.h new file mode 100644 index 0000000..857272e --- /dev/null +++ b/math/Vector2u32.h @@ -0,0 +1,62 @@ +#ifndef AWFUL_MATH_VECTOR2U32_H_ +#define AWFUL_MATH_VECTOR2U32_H_ + +#include "core/core.h" + +namespace awful { namespace math +{ + struct Vector2u32 + { + Vector2u32() : + m_x( 0.f ), + m_y( 0.f ) + { + } + + Vector2u32( uint32_t x_, uint32_t y_ ) : + m_x( x_ ), + m_y( y_ ) + { + } + + uint32_t& x() { return m_x; } + uint32_t& y() { return m_y; } + const uint32_t& x() const { return m_x; } + const uint32_t& y() const { return m_y; } + + Vector2u32 operator+( const Vector2u32& b ) const + { + return Vector2u32( m_x + b.m_x, m_y + b.m_y ); + } + + Vector2u32 operator-( const Vector2u32& b ) const + { + return Vector2u32( m_x - b.m_x, m_y - b.m_y ); + } + + const Vector2u32& operator+=( const Vector2u32& b ) + { + m_x += b.m_x; + m_y += b.m_y; + return *this; + } + + const Vector2u32& operator-=( const Vector2u32& b ) + { + m_x -= b.m_x; + m_y -= b.m_y; + return *this; + } + + bool operator==( const Vector2u32& b ) const + { + return m_x == b.m_x && m_y == b.m_y; + } + + private: + uint32_t m_x; + uint32_t m_y; + }; +}} + +#endif diff --git a/math/math.aidl b/math/math.aidl index 81a77ec..6c6fc89 100644 --- a/math/math.aidl +++ b/math/math.aidl @@ -8,6 +8,14 @@ namespace awful { namespace math float y; }; + struct Vector2u32 + { + Vector2u32(); + Vector2u32( uint32_t x, uint32_t y ); + uint32_t x; + uint32_t y; + }; + struct Vector3f { Vector3f(); @@ -67,11 +75,11 @@ namespace awful { namespace math Vector4f position; }; - struct Rect + struct Rectf { - Rect(); - Rect( Vector2f position_, Vector2f size_ ); - Rect( float left, float top, float width, float height ); + Rectf(); + Rectf( Vector2f position_, Vector2f size_ ); + Rectf( float left, float top, float width, float height ); Vector2f position; Vector2f size; @@ -83,4 +91,21 @@ namespace awful { namespace math float width; float height; }; + + struct Rectu32 + { + Rectu32(); + Rectu32( Vector2u32 position_, Vector2u32 size_ ); + Rectu32( uint32_t left, uint32_t top, uint32_t width, uint32_t height ); + + Vector2u32 position; + Vector2u32 size; + + // Aliases for direct fine grained access to the above. + [ storable=false ] + uint32_t left; + uint32_t top; + uint32_t width; + uint32_t height; + }; }} diff --git a/renderer/Context.h b/renderer/Context.h index 8750d66..94c9128 100644 --- a/renderer/Context.h +++ b/renderer/Context.h @@ -3,7 +3,7 @@ #include "Font.h" #include "math/Vector2f.h" -#include "math/Rect.h" +#include "math/Rectf.h" #include "core/core.h" #include @@ -33,7 +33,7 @@ namespace awful { namespace renderer } void drawRectangle( float Left, float Top, float Width, float Height ) const; - void drawRectangle( const math::Rect& rect ) const + void drawRectangle( const math::Rectf& rect ) const { drawRectangle( rect.left(), rect.top(), rect.width(), rect.height() ); } diff --git a/renderer/renderer.aidl b/renderer/renderer.aidl index 4f97811..9464fc4 100644 --- a/renderer/renderer.aidl +++ b/renderer/renderer.aidl @@ -33,7 +33,7 @@ namespace awful { namespace renderer Pointer< Font > Font; void drawRectangle( float Left, float Top, float Width, float Height ) const; - void drawRectangle( math::Rect rectangle ) const; + void drawRectangle( math::Rectf rectangle ) const; void renderingOffset( math::Vector2f p ); math::Vector2f Offset; diff --git a/scenegraph/Camera.h b/scenegraph/Camera.h new file mode 100644 index 0000000..7526425 --- /dev/null +++ b/scenegraph/Camera.h @@ -0,0 +1,64 @@ +#ifndef AWFUL_SCENEGRAPH_CAMERA_H_ +#define AWFUL_SCENEGRAPH_CAMERA_H_ + +#include "core/core.h" +#include "Frame.h" +#include + +namespace awful { namespace scenegraph +{ + class Camera : public Serializable + { + public: + Camera( const Pointer< Frame >& pFrame ) : + m_pFrame( pFrame ), + m_FOV( 60.f ) + { + } + + Camera( const Serialization_tag& ) {} + + const Pointer< Frame >& getpFrame() const { return m_pFrame; } + void setpFrame( const Pointer< Frame >& x ) { m_pFrame = x; } + + const float& getFOV() const { return m_FOV; } + void setFOV( const float& x ) { m_FOV = x; } + + void renderSetup() const + { + math::Matrix44f invmat; + m_pFrame->getLocalToWorld().inverse( invmat ); + + GLfloat m[16]; + + m[0] = invmat.v1().x(); + m[1] = invmat.v1().y(); + m[2] = invmat.v1().z(); + m[3] = invmat.v1().w(); + + m[4] = invmat.v2().x(); + m[5] = invmat.v2().y(); + m[6] = invmat.v2().z(); + m[7] = invmat.v2().w(); + + m[8] = invmat.v3().x(); + m[9] = invmat.v3().y(); + m[10] = invmat.v3().z(); + m[11] = invmat.v3().w(); + + m[12] = invmat.v4().x(); + m[13] = invmat.v4().y(); + m[14] = invmat.v4().z(); + m[15] = invmat.v4().w(); + + glLoadMatrixf( m ); + } + + private: + template< class C, typename T > friend struct awful::attribute_traits; + Pointer< Frame > m_pFrame; + float m_FOV; + }; +}} + +#endif diff --git a/scenegraph/RenderContext.cpp b/scenegraph/RenderContext.cpp index 320b57b..afe4f94 100644 --- a/scenegraph/RenderContext.cpp +++ b/scenegraph/RenderContext.cpp @@ -19,6 +19,8 @@ void RenderContext::ClearAll() void RenderContext::render() const { + m_pViewPort->renderSetup(); + RenderMap::const_iterator mapit; for( mapit = m_RenderMap.begin(); mapit != m_RenderMap.end(); ++mapit ) { diff --git a/scenegraph/RenderContext.h b/scenegraph/RenderContext.h index 0b5d68b..0671933 100644 --- a/scenegraph/RenderContext.h +++ b/scenegraph/RenderContext.h @@ -4,6 +4,7 @@ #include "core/core.h" #include "Material.h" #include "Drawable.h" +#include "ViewPort.h" #include #include @@ -14,6 +15,11 @@ namespace awful { namespace scenegraph class RenderContext : public RefCounted { public: + RenderContext( const Pointer< ViewPort >& pViewPort ) : + m_pViewPort( pViewPort ) + { + } + void addGeometry( Pointer< Drawable > pDrawable_ ) { MaterialKey key( pDrawable_->getpMaterial() ); @@ -29,10 +35,12 @@ namespace awful { namespace scenegraph static void ClearAll(); void clear(); + const Pointer< ViewPort >& getpViewPort() const { return m_pViewPort; } + void setpViewPort( const Pointer< ViewPort >& x ) { m_pViewPort = x; } + private: void render() const; - typedef std::list< ConstPointer< RenderContext > > ContextList; static ContextList ms_RenderList; @@ -54,6 +62,8 @@ namespace awful { namespace scenegraph }; + Pointer< ViewPort > m_pViewPort; + typedef std::list< ConstPointer< Drawable > > Bucket; typedef std::map< MaterialKey, Bucket > RenderMap; RenderMap m_RenderMap; diff --git a/scenegraph/ViewPort.h b/scenegraph/ViewPort.h new file mode 100644 index 0000000..850ca7a --- /dev/null +++ b/scenegraph/ViewPort.h @@ -0,0 +1,59 @@ +#ifndef AWFUL_SCENEGRAPH_VIEWPORT_H_ +#define AWFUL_SCENEGRAPH_VIEWPORT_H_ + +#include "core/core.h" +#include "Camera.h" +#include "math/Rectu32.h" +#include +#include + +namespace awful { namespace scenegraph +{ + class ViewPort : public Serializable + { + public: + ViewPort( const Pointer< Camera >& pCamera ) : + m_pCamera( pCamera ), + m_ZNear( 0.1f ), + m_ZFar( 50.f ) + { + } + + ViewPort( const Serialization_tag& ) {} + + const Pointer< Camera >& getpCamera() const { return m_pCamera; } + void setpCamera( const Pointer< Camera >& x ) { m_pCamera = x; } + + const math::Rectu32& getRect() const { return m_Rect; } + math::Rectu32& getRect() { return m_Rect; } + void setRect( const math::Rectu32& x ) { m_Rect = x; } + + const float& getZNear() const { return m_ZNear; } + void setZNear( const float& x ) { m_ZNear = x; } + + const float& getZFar() const { return m_ZFar; } + void setZFar( const float& x ) { m_ZFar = x; } + + + void renderSetup() const + { + glViewport( m_Rect.left(), m_Rect.top(), m_Rect.width(), m_Rect.height() ); + + float ratio = static_cast< float >( m_Rect.width() ) / + static_cast< float >( m_Rect.height() ); + + glMatrixMode( GL_PROJECTION ); + m_pCamera->renderSetup(); + gluPerspective( m_pCamera->getFOV(), ratio, m_ZNear, m_ZFar ); + } + + private: + template< class C, typename T > friend struct awful::attribute_traits; + Pointer< Camera > m_pCamera; + math::Rectu32 m_Rect; + float m_ZNear; + float m_ZFar; + }; +}} + +#endif diff --git a/scenegraph/scenegraph.aidl b/scenegraph/scenegraph.aidl index 3b26c1b..b0a3501 100644 --- a/scenegraph/scenegraph.aidl +++ b/scenegraph/scenegraph.aidl @@ -17,9 +17,13 @@ namespace awful { namespace scenegraph [ storable=false ] class RenderContext { + RenderContext( Pointer< ViewPort > pViewPort ); + static void RenderAll(); static void ClearAll(); void clear(); + + Pointer< ViewPort > pViewPort; }; [ default ] @@ -60,4 +64,20 @@ namespace awful { namespace scenegraph //vector< Input > Uniforms; }; + + class Camera + { + Camera( Pointer< Frame > pFrame ); + Pointer< Frame > pFrame; + float FOV; + }; + + class ViewPort + { + ViewPort( Pointer< Camera > pCamera ); + Pointer< Camera > pCamera; + math::Rectu32 Rect; + float ZNear; + float ZFar; + }; }} -- 2.11.4.GIT