|
From: <axl...@us...> - 2009-05-16 02:41:32
|
Revision: 252
http://hgengine.svn.sourceforge.net/hgengine/?rev=252&view=rev
Author: axlecrusher
Date: 2009-05-16 02:41:31 +0000 (Sat, 16 May 2009)
Log Message:
-----------
updates for billboards (broken)
Modified Paths:
--------------
Mercury2/src/BillboardNode.cpp
Mercury2/src/Frustum.cpp
Mercury2/src/RenderGraph.cpp
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Mercury2/src/Viewport.cpp
Mercury2/src/Viewport.h
Modified: Mercury2/src/BillboardNode.cpp
===================================================================
--- Mercury2/src/BillboardNode.cpp 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/BillboardNode.cpp 2009-05-16 02:41:31 UTC (rev 252)
@@ -6,30 +6,28 @@
MercuryMatrix Billboard::ManipulateMatrix(const MercuryMatrix& matrix)
{
- MercuryMatrix m = matrix;
-// m.Transpose();
+ MercuryMatrix m = RenderableNode::ManipulateMatrix( matrix );
- //manually transposed
- MercuryVertex center(m[3][0], m[3][1], m[3][2]);
+ MercuryVertex center(m.Ptr()[3], m.Ptr()[7], m.Ptr()[11]);
- const MercuryVertex& eye = FRUSTUM->GetEye();
- const MercuryVector& lookAt = FRUSTUM->GetLookAt();
-
- MercuryVector v = (eye - center).Normalize();
- MercuryVector up = lookAt.CrossProduct( v );
- float angleCos = lookAt.DotProduct(v);
+ MercuryVector v = (EYE - center).Normalize();
+ MercuryVector up = LOOKAT.CrossProduct( v );
+ float angleCos = LOOKAT.DotProduct(v);
+
+// VIEWMATRIX.Ptr()[3];
+// EYE.Print();
+// center.Print();
+// printf("angleCos %f\n",angleCos);
+
if ((angleCos < 0.99990) && (angleCos > -0.9999))
{
float f = ACOS(angleCos)*RADDEG;
// printf("billboard!!! %f %f %f\n",up[0]*f, up[1]*f, up[2]*f );
-// MercuryMatrix m;
-// m.RotateXYZ(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2])
-// glRotatef(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2]);
m.RotateXYZ(up[0]*f, up[1]*f, up[2]*f);
}
-// m.Transpose();
+
return m;
}
Modified: Mercury2/src/Frustum.cpp
===================================================================
--- Mercury2/src/Frustum.cpp 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/Frustum.cpp 2009-05-16 02:41:31 UTC (rev 252)
@@ -2,6 +2,7 @@
void Frustum::SetPerspective( float fov, float aspect, float znear, float zfar )
{
+ //Should go in projection matrix
float xmin, xmax, ymin, ymax;
m_fov = fov;
@@ -24,6 +25,7 @@
void Frustum::ComputeFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
{
+ //Should go in projection matrix
float near2 = 2*zNear;
float rml = right-left;
float tmb = top - bottom;
Modified: Mercury2/src/RenderGraph.cpp
===================================================================
--- Mercury2/src/RenderGraph.cpp 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/RenderGraph.cpp 2009-05-16 02:41:31 UTC (rev 252)
@@ -9,11 +9,11 @@
if (m_node)
{
+ m_node->PreRender( *m_matrix );
m = m_node->ManipulateMatrix( *m_matrix );
if ( m_node->IsHidden() || m_node->IsCulled(m) ) return;
m.Transpose();
glLoadMatrixf( m.Ptr() );
- m_node->PreRender( m );
m_node->Render( m );
}
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/RenderableNode.cpp 2009-05-16 02:41:31 UTC (rev 252)
@@ -160,7 +160,7 @@
MercuryMatrix RenderableNode::ManipulateMatrix(const MercuryMatrix& matrix)
{
- return matrix;
+ return VIEWMATRIX * matrix;
}
/***************************************************************************
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/RenderableNode.h 2009-05-16 02:41:31 UTC (rev 252)
@@ -24,8 +24,11 @@
void AddRender(MercuryAsset* asset);
void AddPostRender(MercuryAsset* asset);
+ ///This will get the world space matrix
virtual void PreRender(const MercuryMatrix& matrix);
+
virtual void Render(const MercuryMatrix& matrix);
+
virtual void PostRender(const MercuryMatrix& matrix);
virtual void LoadFromXML(const XMLNode& node);
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/Viewport.cpp 2009-05-16 02:41:31 UTC (rev 252)
@@ -4,30 +4,41 @@
REGISTER_NODE_TYPE(Viewport);
const Frustum* FRUSTUM;
+MercuryMatrix VIEWMATRIX;
+MercuryVertex EYE;
+MercuryVector LOOKAT;
Viewport::Viewport()
:m_xFactor(1), m_yFactor(0.5), m_minx(0), m_miny(0)
{
}
-void Viewport::Render(const MercuryMatrix& matrix)
+void Viewport::PreRender(const MercuryMatrix& matrix)
{
FRUSTUM = &m_frustum;
MercuryWindow* w = MercuryWindow::GetCurrentWindow();
glViewport(m_minx, m_miny, (GLsizei)(w->Width()*m_xFactor), (GLsizei)(w->Height()*m_yFactor));
+ //Load the frustum into the projection
+ //"eye" position does not go into projection
glMatrixMode(GL_PROJECTION);
-
MercuryMatrix f = m_frustum.GetMatrix();
f.Transpose();
-
- glLoadMatrixf( (matrix * f).Ptr() );
- //The following 2 are equivelent to above
-// glLoadMatrixf( m_frustum.Ptr() );
-// glMultMatrixf( m.Ptr() );
+ glLoadMatrixf( f.Ptr() );
glMatrixMode(GL_MODELVIEW);
+
+ VIEWMATRIX = matrix;
+ EYE[0] = matrix[0][3];
+ EYE[1] = matrix[1][3];
+ EYE[2] = matrix[2][3];
+ EYE *= -1;
+
+ MercuryVector l(0,0,1);
+// l += EYE;
+ LOOKAT = (matrix * l).Normalize();
+// LOOKAT.Print();
}
void Viewport::LoadFromXML(const XMLNode& node)
Modified: Mercury2/src/Viewport.h
===================================================================
--- Mercury2/src/Viewport.h 2009-05-16 00:41:20 UTC (rev 251)
+++ Mercury2/src/Viewport.h 2009-05-16 02:41:31 UTC (rev 252)
@@ -8,12 +8,15 @@
#include <Frustum.h>
extern const Frustum* FRUSTUM;
+extern MercuryMatrix VIEWMATRIX;
+extern MercuryVertex EYE;
+extern MercuryVector LOOKAT;
class Viewport : public RenderableNode
{
public:
Viewport();
- virtual void Render(const MercuryMatrix& matrix);
+ virtual void PreRender(const MercuryMatrix& matrix);
virtual void LoadFromXML(const XMLNode& node);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|