|
From: <axl...@us...> - 2009-04-14 01:05:01
|
Revision: 213
http://hgengine.svn.sourceforge.net/hgengine/?rev=213&view=rev
Author: axlecrusher
Date: 2009-04-14 01:04:54 +0000 (Tue, 14 Apr 2009)
Log Message:
-----------
updates to viewport calculations
Modified Paths:
--------------
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Mercury2/src/MercuryWindow.h
Mercury2/src/Viewport.cpp
Mercury2/src/Viewport.h
Mercury2/src/X11Window.cpp
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/MercuryUtil.cpp 2009-04-14 01:04:54 UTC (rev 213)
@@ -14,10 +14,10 @@
return t;
}
-float StrToFloat(const MString & s)
+float StrToFloat(const MString & s, float d)
{
- float x;
- sscanf(s.c_str(), "%f", &x);
+ float x = d;
+ if ( s.length() > 0) sscanf(s.c_str(), "%f", &x);
return x;
}
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/MercuryUtil.h 2009-04-14 01:04:54 UTC (rev 213)
@@ -29,7 +29,7 @@
MString ToUpper(const MString & s);
-float StrToFloat(const MString & s);
+float StrToFloat(const MString & s, float d = 0);
template<typename T>
const T& max(const T& t1, const T& t2)
Modified: Mercury2/src/MercuryWindow.h
===================================================================
--- Mercury2/src/MercuryWindow.h 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/MercuryWindow.h 2009-04-14 01:04:54 UTC (rev 213)
@@ -25,6 +25,9 @@
}
virtual void* GetProcAddress(const MString& x) = 0;
+
+ inline int Width() const { return m_width; }
+ inline int Height() const { return m_height; }
protected:
static Callback0R< MercuryWindow* > genWindowClbk;
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/Viewport.cpp 2009-04-14 01:04:54 UTC (rev 213)
@@ -1,13 +1,22 @@
#include <Viewport.h>
#include <GL/gl.h>
+#include <MercuryWindow.h>
REGISTER_NODE_TYPE(Viewport);
const Frustum* FRUSTUM;
+Viewport::Viewport()
+ :m_xFactor(1), m_yFactor(0.5), m_minx(0), m_miny(0)
+{
+}
+
void Viewport::Render(const MercuryMatrix& matrix)
{
FRUSTUM = &m_frustum;
+ MercuryWindow* w = MercuryWindow::GetCurrentWindow();
+ glViewport(m_minx, m_miny, w->Width()*m_xFactor, w->Height()*m_yFactor);
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
@@ -24,11 +33,19 @@
void Viewport::LoadFromXML(const XMLNode& node)
{
+ m_xFactor = StrToFloat(node.Attribute("xfactor"), 1.0f);
+ m_yFactor = StrToFloat(node.Attribute("yfactor"), 1.0f);
+ m_minx = StrToFloat(node.Attribute("minx"), 0);
+ m_miny = StrToFloat(node.Attribute("miny"), 0);
+
+ MercuryWindow* w = MercuryWindow::GetCurrentWindow();
+
m_frustum.SetPerspective( StrToFloat(node.Attribute("fov")),
- StrToFloat(node.Attribute("aspect")),
+ (w->Width()*m_xFactor)/(w->Height()*m_yFactor),
+// StrToFloat(node.Attribute("aspect")),
StrToFloat(node.Attribute("near")),
StrToFloat(node.Attribute("far")));
-
+
m_frustum.LookAt(MercuryVertex(), MercuryVertex(0,0,1), MercuryVertex(0,1,0));
RenderableNode::LoadFromXML(node);
Modified: Mercury2/src/Viewport.h
===================================================================
--- Mercury2/src/Viewport.h 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/Viewport.h 2009-04-14 01:04:54 UTC (rev 213)
@@ -12,6 +12,7 @@
class Viewport : public RenderableNode
{
public:
+ Viewport();
virtual void Render(const MercuryMatrix& matrix);
virtual void LoadFromXML(const XMLNode& node);
@@ -19,6 +20,8 @@
GENRTTI(Viewport);
private:
Frustum m_frustum;
+ float m_xFactor, m_yFactor;
+ int m_minx, m_miny;
};
#endif
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2009-04-13 10:51:03 UTC (rev 212)
+++ Mercury2/src/X11Window.cpp 2009-04-14 01:04:54 UTC (rev 213)
@@ -145,7 +145,8 @@
case ConfigureNotify:
{
XConfigureEvent* e = (XConfigureEvent*)&event;
- glViewport(0,0, e->width, e->height);
+ m_width = e->width;
+ m_height = e->height;
break;
}
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|