From: <axl...@us...> - 2009-03-02 19:46:14
|
Revision: 160 http://hgengine.svn.sourceforge.net/hgengine/?rev=160&view=rev Author: axlecrusher Date: 2009-03-02 19:46:08 +0000 (Mon, 02 Mar 2009) Log Message: ----------- update everything Modified Paths: -------------- Mercury2/mercury2.kdevelop Mercury2/scenegraph.xml Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryMath.cpp Mercury2/src/MercuryMath.h Mercury2/src/MercuryMatrix.cpp Mercury2/src/MercuryMatrix.h Mercury2/src/RenderableNode.cpp Mercury2/src/RenderableNode.h Mercury2/src/Viewport.cpp Mercury2/src/Viewport.h Modified: Mercury2/mercury2.kdevelop =================================================================== --- Mercury2/mercury2.kdevelop 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/mercury2.kdevelop 2009-03-02 19:46:08 UTC (rev 160) @@ -26,8 +26,8 @@ <run> <mainprogram>/home/josh/Mercury2/debug/src/mercury2</mainprogram> <terminal>false</terminal> - <programargs/> - <globaldebugarguments/> + <programargs></programargs> + <globaldebugarguments></globaldebugarguments> <globalcwd>/home/josh/Mercury2</globalcwd> <useglobalprogram>true</useglobalprogram> <autocompile>false</autocompile> @@ -59,16 +59,16 @@ <ccompiler>kdevgccoptions</ccompiler> <cxxcompiler>kdevgppoptions</cxxcompiler> <f77compiler>kdevg77options</f77compiler> - <cxxflags>-O2 -g -Wall</cxxflags> + <cxxflags>-O0 -g -Wall</cxxflags> <envvars/> - <topsourcedir/> - <cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER -DUSE_SSE</cppflags> + <topsourcedir></topsourcedir> + <cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER</cppflags> <ldflags>-lpthread -lX11 -lGL -lxml2 -lpng</ldflags> - <ccompilerbinary/> - <cxxcompilerbinary/> - <f77compilerbinary/> - <cflags>-O2 -g -Wall</cflags> - <f77flags/> + <ccompilerbinary></ccompilerbinary> + <cxxcompilerbinary></cxxcompilerbinary> + <f77compilerbinary></f77compilerbinary> + <cflags>-O0 -g -Wall</cflags> + <f77flags></f77flags> </debug> <default> <envvars/> Modified: Mercury2/scenegraph.xml =================================================================== --- Mercury2/scenegraph.xml 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/scenegraph.xml 2009-03-02 19:46:08 UTC (rev 160) @@ -1,5 +1,5 @@ <SceneGraph> - <node type="transformnode" movz="-1" roty="13"> + <node type="transformnode" movz="0" roty="0"> <node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100"/> </node> <node type="transformnode" movz="-3"> @@ -20,14 +20,8 @@ <asset type="quad"/> </node> </node> - <node type="rotatornode" movz="-2" scalex="0.25" scaley="0.25" scalez="0.25" > + <node type="rotatornode" movy="0" movz="-2" scalex="0.25" scaley="0.25" scalez="0.25" > <node type="renderablenode"> - <asset type="texture" file="test.bmp"/> - <asset type="hgmdlmodel" file="beerhall.hgmdl"/> - </node> - </node> - <node type="rotatornode" movz="-2" movx="2" scalex="0.25" scaley="0.25" scalez="0.25" > - <node type="renderablenode"> <asset type="texture" file="gunther.png"/> <asset type="hgmdlmodel" file="gunther.hgmdl"/> </node> Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/BoundingBox.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -2,6 +2,8 @@ #include <GL/glext.h> #include <BoundingBox.h> +#include <Viewport.h> + void BoundingBox::LoadFromBinary(char* data) { memcpy(m_center, data, sizeof(float)*3); @@ -15,6 +17,17 @@ void RenderableBoundingBox::Render(MercuryNode* node) { + const BoundingBox& bb = *m_bb; + + MercuryVertex c = GetGlobalMatrix() * m_bb->GetCenter(); + +// GetGlobalMatrix().Print(); +// c.Print(); + + BoundingBox gbb( c, bb.GetExtend() ); + +// printf("clip %d\n", FRUSTUM->Clip(gbb) ); + const float* center = m_bb->GetCenter(); const float* extend = m_bb->GetExtend(); Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/BoundingBox.h 2009-03-02 19:46:08 UTC (rev 160) @@ -2,16 +2,24 @@ #define BOUNDINGBOX_H #include <MercuryAsset.h> +#include <MercuryVertex.h> class BoundingBox { public: + BoundingBox() {}; + BoundingBox(const MercuryVertex& center, const MercuryVertex& extend) + :m_center(center), m_extend(extend) + {}; + void LoadFromBinary(char* data); - inline const float* GetCenter() const { return m_center; } - inline const float* GetExtend() const { return m_extend; } + + inline const MercuryVertex& GetCenter() const { return m_center; } + inline const MercuryVertex& GetExtend() const { return m_extend; } + private: - float m_center[3]; - float m_extend[3]; + MercuryVertex m_center; + MercuryVertex m_extend; }; class RenderableBoundingBox : public MercuryAsset Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryAsset.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -65,8 +65,14 @@ m_assetInstances.erase( asset ); printf("removed asset %s\n", key.c_str()); } + } +const MercuryMatrix& MercuryAsset::GetGlobalMatrix() const +{ + return GLOBALMATRIX; +} + std::map<MString, MercuryAsset*> AssetFactory::m_assetInstances; /*************************************************************************** Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryAsset.h 2009-03-02 19:46:08 UTC (rev 160) @@ -5,6 +5,7 @@ #include <MercuryNode.h> #include <MessageHandler.h> #include <map> +#include <MercuryMatrix.h> class MercuryAsset : public RefBase, MessageHandler { @@ -22,6 +23,7 @@ virtual void LoadFromXML(const XMLNode& node) {}; inline void IsInstanced(bool b) { m_isInstanced = b; } + const MercuryMatrix& GetGlobalMatrix() const; protected: bool m_isInstanced; }; Modified: Mercury2/src/MercuryMath.cpp =================================================================== --- Mercury2/src/MercuryMath.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryMath.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -170,6 +170,22 @@ out[3] = p[0] * m[12] + p[1] * m[13] + p[2] * m[14] + p[3] * m[15]; } +void Float2FloatRow(const float* f, FloatRow* r) +{ + *r[0] = f[0]; + *r[1] = f[1]; + *r[2] = f[2]; + *r[3] = f[3]; +} + +void FloatRow2Float( const FloatRow* fr, float* f) +{ + f[0] = (*fr)[0]; + f[1] = (*fr)[1]; + f[2] = (*fr)[2]; + f[3] = (*fr)[3]; +} + #else //inline __m128 Hadd4(__m128 x); @@ -289,6 +305,16 @@ r = (FloatRow)_mm_setzero_ps(); } +FloatRow Float2FloatRow(const float* f, , FloatRow* r) +{ + r = _mm_load_ps( f ); +} + +void FloatRow2Float( const FloatRow* fr, float* f) +{ + _mm_store_ps( f, *fr ); +} + #endif /* Modified: Mercury2/src/MercuryMath.h =================================================================== --- Mercury2/src/MercuryMath.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryMath.h 2009-03-02 19:46:08 UTC (rev 160) @@ -42,7 +42,7 @@ #define SQ(x) ((x)*(x)); -#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) +//#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) void Mul4f(const FloatRow* first, const FloatRow* second, FloatRow* out); void Div4f(const FloatRow* first, const FloatRow* second, FloatRow* out); @@ -55,6 +55,9 @@ void VectorMultiply4f(const FloatRow* matrix, const FloatRow* p, FloatRow* out ); void TransposeMatrix( FloatRow* m ); +void Float2FloatRow(const float* f, FloatRow* r); +void FloatRow2Float( const FloatRow* fr, float* f); + const FloatRow gfrZero = { 0.f, 0.f, 0.f, 0.f }; #endif Modified: Mercury2/src/MercuryMatrix.cpp =================================================================== --- Mercury2/src/MercuryMatrix.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryMatrix.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -39,27 +39,6 @@ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; Copy16f(&m_matrix[0], Identity ); -/* - (*this)[0][0] = 1; - (*this)[0][1] = 0; - (*this)[0][2] = 0; - (*this)[0][3] = 0; - - (*this)[1][0] = 0; - (*this)[1][1] = 1; - (*this)[1][2] = 0; - (*this)[1][3] = 0; - - (*this)[2][0] = 0; - (*this)[2][1] = 0; - (*this)[2][2] = 1; - (*this)[2][3] = 0; - - (*this)[3][0] = 0; - (*this)[3][1] = 0; - (*this)[3][2] = 0; - (*this)[3][3] = 1; - */ } void MercuryMatrix::Translate(float x, float y, float z) @@ -207,7 +186,7 @@ return *this; } -void MercuryMatrix::Print() +void MercuryMatrix::Print() const { for (int i = 0; i < 4; ++i) { @@ -216,6 +195,19 @@ printf("\n"); } +MercuryVector MercuryMatrix::operator*(const MercuryVector& v) const +{ + float tmp[4]; + v.ConvertToVector4( tmp ); + FloatRow r, tvo; + Float2FloatRow( tmp, &r ); + VectorMultiply4f( m_matrix, &r, &tvo); + FloatRow2Float( &tvo, tmp ); + MercuryVertex(tmp).Print(); + return MercuryVertex(tmp); +} + + /* * Copyright (c) 2006 Joshua Allen * All rights reserved. Modified: Mercury2/src/MercuryMatrix.h =================================================================== --- Mercury2/src/MercuryMatrix.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/MercuryMatrix.h 2009-03-02 19:46:08 UTC (rev 160) @@ -4,6 +4,7 @@ //This matrix will work identically to float[16] #include "MercuryMath.h" #include "MercuryUtil.h" +#include <MercuryVertex.h> class MercuryMatrix; @@ -27,6 +28,8 @@ MercuryMatrix operator*(const MercuryMatrix& m) const; MercuryMatrix& operator*=(const MercuryMatrix& m); + + MercuryVector operator*(const MercuryVertex& v) const; void Translate(float x, float y, float z); ///Rotate along the 3 primariy axes by given amounts (in deg) @@ -40,7 +43,7 @@ void Zero(); void Identity(); - void Print(); + void Print() const; } #if !defined( WIN32 ) || defined( _MSC_VER ) M_ALIGN(64); Modified: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/RenderableNode.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -10,6 +10,8 @@ uint64_t RenderWaited = 0; uint64_t UpdateWaited = 0; +MercuryMatrix GLOBALMATRIX; + RenderableNode::RenderableNode() :m_hidden(false) { @@ -45,7 +47,7 @@ if (m_hidden || IsCulled()) return; - MercuryMatrix m = FindGlobalMatrix(); + MercuryMatrix m = GLOBALMATRIX = FindGlobalMatrix(); m.Transpose(); glLoadMatrixf( m.Ptr() ); Modified: Mercury2/src/RenderableNode.h =================================================================== --- Mercury2/src/RenderableNode.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/RenderableNode.h 2009-03-02 19:46:08 UTC (rev 160) @@ -11,6 +11,7 @@ extern uint64_t RenderWaited; extern uint64_t UpdateWaited; +extern MercuryMatrix GLOBALMATRIX; class RenderableNode : public MercuryNode { Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/Viewport.cpp 2009-03-02 19:46:08 UTC (rev 160) @@ -3,15 +3,22 @@ REGISTER_NODE_TYPE(Viewport); +const Frustum* FRUSTUM = NULL; + void Viewport::Render() { + FRUSTUM = &m_frustum; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); MercuryMatrix m = FindGlobalMatrix(); m.Transpose(); + + MercuryMatrix f = m_frustum.GetMatrix(); + f.Transpose(); - glLoadMatrixf( (m * m_frustum.GetMatrix()).Ptr() ); + glLoadMatrixf( (m * f).Ptr() ); //The following 2 are equivelent to above // glLoadMatrixf( m_frustum.Ptr() ); // glMultMatrixf( m.Ptr() ); @@ -76,7 +83,7 @@ m_frustum[2][3] = D; m_frustum[3][2] = -1; - m_frustum.Transpose(); //XXX fix it to remove this +// m_frustum.Transpose(); //XXX fix it to remove this } void Frustum::LookAt(const MercuryVertex& eye, const MercuryVector& look, const MercuryVector& up) @@ -117,6 +124,17 @@ m_planes[PRIGHT].Setup(m_nc+X*m_nw,normal); } +bool Frustum::Clip(const BoundingBox& bb) const +{ + bool inView = false; + for (uint8_t i = 0; (i < 6) && !inView; ++i) + { + inView = m_planes[i].IsBehindPlane( bb )?inView:true; + } + + return !inView; +}; + /* void Frustum::LookAt() { Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-03-02 19:41:32 UTC (rev 159) +++ Mercury2/src/Viewport.h 2009-03-02 19:46:08 UTC (rev 160) @@ -6,17 +6,18 @@ #include <MercuryVertex.h> #include <MercuryPlane.h> +enum PlanePos +{ + PTOP = 0, + PBOTTOM, + PLEFT, + PRIGHT, + PNEAR, + PFAR +}; + class Frustum { - enum PlanePos - { - PTOP = 0, - PBOTTOM, - PLEFT, - PRIGHT, - PNEAR, - PFAR - }; public: void SetPerspective( float fov, float aspect, float znear, float zfar ); @@ -24,6 +25,10 @@ void ComputeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); void LookAt(const MercuryVertex& eye, const MercuryVector& look, const MercuryVector& up); + + bool Clip(const BoundingBox& bb) const; + + MercuryPlane m_planes[6]; private: MercuryMatrix m_frustum; @@ -31,9 +36,10 @@ float m_nh, m_nw, m_fh, m_fw; MercuryVector m_nc, m_fc; - MercuryPlane m_planes[6]; }; +extern const Frustum* FRUSTUM; + class Viewport : public RenderableNode { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |