From: <axl...@us...> - 2009-06-24 01:22:15
|
Revision: 368 http://hgengine.svn.sourceforge.net/hgengine/?rev=368&view=rev Author: axlecrusher Date: 2009-06-24 00:34:53 +0000 (Wed, 24 Jun 2009) Log Message: ----------- don't need to do this Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/RenderGraph.cpp Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-06-23 23:48:43 UTC (rev 367) +++ Mercury2/src/MercuryNode.cpp 2009-06-24 00:34:53 UTC (rev 368) @@ -105,7 +105,7 @@ child->RecursiveUpdate(dTime); } -void MercuryNode::RecursiveRender(bool doAlpha) +void MercuryNode::RecursiveRender() { MercuryMatrix modelView; ShaderAttribute sa; @@ -128,7 +128,7 @@ //call render on other render graph entries under me for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) { - if (child->m_useAlphaPath && !doAlpha) + if ( child->m_useAlphaPath ) CURRENTRENDERGRAPH->AddAlphaNode(child); else child->RecursiveRender(); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-06-23 23:48:43 UTC (rev 367) +++ Mercury2/src/MercuryNode.h 2009-06-24 00:34:53 UTC (rev 368) @@ -48,7 +48,7 @@ void ThreadedUpdate(float dTime); - void RecursiveRender(bool doAlpha = false); + void RecursiveRender(); ///Run on parent when a child is added virtual void OnAddChild() {}; @@ -89,7 +89,6 @@ virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-06-23 23:48:43 UTC (rev 367) +++ Mercury2/src/RenderGraph.cpp 2009-06-24 00:34:53 UTC (rev 368) @@ -96,7 +96,7 @@ (*i)->Render(srs.Node); } - srs.Node->RecursiveRender(true); + srs.Node->RecursiveRender(); for (i = srs.Assets.begin();i != srs.Assets.end(); ++i) (*i)->PostRender(srs.Node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-25 04:08:10
|
Revision: 374 http://hgengine.svn.sourceforge.net/hgengine/?rev=374&view=rev Author: cnlohr Date: 2009-06-25 04:08:08 +0000 (Thu, 25 Jun 2009) Log Message: ----------- add white (luminance) as well as white_alpha (luminance_alpha) This makes it possible to use our tighter packed textures and take up 1/2 the texture ram Modified Paths: -------------- Mercury2/src/PNGLoader.cpp Mercury2/src/RawImageData.h Mercury2/src/Texture.cpp Modified: Mercury2/src/PNGLoader.cpp =================================================================== --- Mercury2/src/PNGLoader.cpp 2009-06-25 03:29:06 UTC (rev 373) +++ Mercury2/src/PNGLoader.cpp 2009-06-25 04:08:08 UTC (rev 374) @@ -102,17 +102,43 @@ png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); - if (color_type & PNG_COLOR_MASK_ALPHA) - image->m_ColorByteType = RGBA; + if (color_type & PNG_COLOR_MASK_COLOR ) + if (color_type & PNG_COLOR_MASK_ALPHA) + image->m_ColorByteType = RGBA; + else + image->m_ColorByteType = RGB; else - image->m_ColorByteType = RGB; + if (color_type & PNG_COLOR_MASK_ALPHA) + image->m_ColorByteType = WHITE_ALPHA; + else + image->m_ColorByteType = WHITE; + // SAFE_DELETE(texture->m_data); image->m_data = new unsigned char[sizeof(unsigned char) * image->m_height * image->m_width * 4]; switch (image->m_ColorByteType) { + case WHITE: + for ( y=0; y < (unsigned)image->m_height; ++y) { + png_byte* row = row_pointers[y]; + for (unsigned long x = 0; x < image->m_width; ++x) { + png_byte* ptr = &(row[x]); + image->m_data[(x + y * image->m_width)] = ptr[0]; + } + } + break; + case WHITE_ALPHA: + for ( y=0; y < (unsigned)image->m_height; ++y) { + png_byte* row = row_pointers[y]; + for (unsigned long x = 0; x < image->m_width; ++x) { + png_byte* ptr = &(row[x*2]); + image->m_data[(x + y * image->m_width) * 2] = ptr[0]; + image->m_data[(x + y * image->m_width) * 2 + 1] = ptr[1]; + } + } + break; case RGBA: for ( y=0; y < (unsigned)image->m_height; ++y) { png_byte* row = row_pointers[y]; Modified: Mercury2/src/RawImageData.h =================================================================== --- Mercury2/src/RawImageData.h 2009-06-25 03:29:06 UTC (rev 373) +++ Mercury2/src/RawImageData.h 2009-06-25 04:08:08 UTC (rev 374) @@ -3,6 +3,8 @@ enum ColorByteType { + WHITE, + WHITE_ALPHA, RGB, RGBA }; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-06-25 03:29:06 UTC (rev 373) +++ Mercury2/src/Texture.cpp 2009-06-25 04:08:08 UTC (rev 374) @@ -52,6 +52,12 @@ switch (m_raw->m_ColorByteType) { + case WHITE: + ByteType = GL_LUMINANCE; + break; + case WHITE_ALPHA: + ByteType = GL_LUMINANCE_ALPHA; + break; case RGB: ByteType = GL_RGB; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-27 22:22:11
|
Revision: 378 http://hgengine.svn.sourceforge.net/hgengine/?rev=378&view=rev Author: cnlohr Date: 2009-06-27 22:22:09 +0000 (Sat, 27 Jun 2009) Log Message: ----------- Classify the mouse enumeration - there is an issue at global scope Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-06-27 22:17:04 UTC (rev 377) +++ Mercury2/src/MercuryInput.cpp 2009-06-27 22:22:09 UTC (rev 378) @@ -13,9 +13,9 @@ mi->dy = dy; uint8_t buttonMasks = 0; - buttonMasks |= (leftButton << MB_LEFT); //enable if true - buttonMasks |= (rightButton << MB_RIGHT); //enable if true - buttonMasks |= (centerButton << MB_CENTER); //enable if true + buttonMasks |= (leftButton << MOUSE_LEFT); //enable if true + buttonMasks |= (rightButton << MOUSE_RIGHT); //enable if true + buttonMasks |= (centerButton << MOUSE_CENTER); //enable if true mi->buttonMasks = buttonMasks; currentButtonMasks = buttonMasks; Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-06-27 22:17:04 UTC (rev 377) +++ Mercury2/src/MercuryInput.h 2009-06-27 22:22:09 UTC (rev 378) @@ -6,13 +6,6 @@ const MString INPUTEVENT_MOUSE = "MouseInputEvent"; const MString INPUTEVENT_KEYBOARD = "KeyboardInputEvent"; -enum MouseButton -{ - MB_NONE = 0, - MB_LEFT = 1, - MB_RIGHT = 2, - MB_CENTER = 3 -}; class MouseInput : public MessageData { @@ -22,6 +15,15 @@ MouseInput(); int32_t dx, dy; uint8_t buttonMasks; + + enum MouseButton + { + MOUSE_NONE = 0, + MOUSE_LEFT = 1, + MOUSE_RIGHT = 2, + MOUSE_CENTER = 3 + }; + private: static uint8_t currentButtonMasks; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-27 22:24:30
|
Revision: 381 http://hgengine.svn.sourceforge.net/hgengine/?rev=381&view=rev Author: cnlohr Date: 2009-06-27 22:24:29 +0000 (Sat, 27 Jun 2009) Log Message: ----------- Add necessary extensions. Modified Paths: -------------- Mercury2/src/OGLExtensions.cpp Mercury2/src/OGLExtensions.h Modified: Mercury2/src/OGLExtensions.cpp =================================================================== --- Mercury2/src/OGLExtensions.cpp 2009-06-27 22:23:00 UTC (rev 380) +++ Mercury2/src/OGLExtensions.cpp 2009-06-27 22:24:29 UTC (rev 381) @@ -30,12 +30,23 @@ PFNGLLINKPROGRAMARBPROC glLinkProgramARB; PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteriEXT; -PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; -PFNGLUNIFORM1IARBPROC glUniform1iARB; -PFNGLUNIFORM4FVARBPROC glUniform4fvARB; +PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; +PFNGLUNIFORM1IARBPROC glUniform1iARB; +PFNGLUNIFORM4FVARBPROC glUniform4fvARB; +PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; +PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; +PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; +PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; +PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; +PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; +PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; +PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; +PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; +PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; +PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB; +PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; - #define EXTENSION( proc, name ) \ name = (proc)wglGetProcAddress( #name ); \ if( !name ) \ @@ -68,7 +79,21 @@ EXTENSION( PFNGLLINKPROGRAMARBPROC,glLinkProgramARB ); EXTENSION( PFNGLGETUNIFORMLOCATIONARBPROC,glGetUniformLocationARB ); EXTENSION( PFNGLPROGRAMPARAMETERIEXTPROC,glProgramParameteriEXT ); -EXTENSION( PFNGLGETACTIVEUNIFORMARBPROC,glGetActiveUniformARB ); -EXTENSION( PFNGLUNIFORM1IARBPROC,glUniform1iARB ); +EXTENSION( PFNGLGETACTIVEUNIFORMARBPROC,glGetActiveUniformARB ); +EXTENSION( PFNGLUNIFORM1IARBPROC,glUniform1iARB ); EXTENSION( PFNGLUNIFORM4FVARBPROC,glUniform4fvARB ); +EXTENSION( PFNGLUNIFORMMATRIX4FVARBPROC, glUniformMatrix4fvARB ); + + +EXTENSION( PFNGLDELETEFRAMEBUFFERSEXTPROC, glDeleteFramebuffersEXT ); +EXTENSION( PFNGLGENRENDERBUFFERSEXTPROC, glGenRenderbuffersEXT ); +EXTENSION( PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffersEXT ); +EXTENSION( PFNGLGENFRAMEBUFFERSEXTPROC, glGenFramebuffersEXT ); +EXTENSION( PFNGLBINDRENDERBUFFEREXTPROC, glBindRenderbufferEXT ); +EXTENSION( PFNGLRENDERBUFFERSTORAGEEXTPROC, glRenderbufferStorageEXT ); +EXTENSION( PFNGLBINDFRAMEBUFFEREXTPROC, glBindFramebufferEXT ); +EXTENSION( PFNGLFRAMEBUFFERTEXTURE2DEXTPROC, glFramebufferTexture2DEXT ); +EXTENSION( PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC, glFramebufferRenderbufferEXT ); +EXTENSION( PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC, glCheckFramebufferStatusEXT ); +EXTENSION( PFNGLDRAWBUFFERSARBPROC, glDrawBuffersARB ); } Modified: Mercury2/src/OGLExtensions.h =================================================================== --- Mercury2/src/OGLExtensions.h 2009-06-27 22:23:00 UTC (rev 380) +++ Mercury2/src/OGLExtensions.h 2009-06-27 22:24:29 UTC (rev 381) @@ -25,10 +25,22 @@ extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; extern PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteriEXT; -extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; -extern PFNGLUNIFORM1IARBPROC glUniform1iARB; -extern PFNGLUNIFORM4FVARBPROC glUniform4fvARB; +extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; +extern PFNGLUNIFORM1IARBPROC glUniform1iARB; +extern PFNGLUNIFORM4FVARBPROC glUniform4fvARB; +extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; +extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; +extern PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; +extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; +extern PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; +extern PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; +extern PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; +extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; +extern PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; +extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; +extern PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; +extern PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB; void SetupOGLExtensions(); #endif \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-28 21:57:21
|
Revision: 385 http://hgengine.svn.sourceforge.net/hgengine/?rev=385&view=rev Author: cnlohr Date: 2009-06-28 21:57:18 +0000 (Sun, 28 Jun 2009) Log Message: ----------- add named resource (useful for making easily readable things) Added Paths: ----------- Mercury2/src/MercuryNamedResource.cpp Mercury2/src/MercuryNamedResource.h Added: Mercury2/src/MercuryNamedResource.cpp =================================================================== --- Mercury2/src/MercuryNamedResource.cpp (rev 0) +++ Mercury2/src/MercuryNamedResource.cpp 2009-06-28 21:57:18 UTC (rev 385) @@ -0,0 +1,110 @@ +#include <MercuryNamedResource.h> +#include <MercuryUtil.h> + + +MString MercuryNamedResource::GetValueS( const MString & sDataPointer ) +{ + MString ret; + GetValue( sDataPointer, ret ); + return ret; +} + +MString MercuryNamedResource::GetValueS( const MString & sDataPointer, MString sDefaultValue, bool bSetValue ) +{ + MString ret; + if( GetValue( sDataPointer, ret ) ) + return ret; + + if( bSetValue ) + SetValueS( sDataPointer, sDefaultValue ); + return sDefaultValue; +} + + +float MercuryNamedResource::GetValueF( const MString & sDataPointer, float fDefaultValue, bool bSetValue ) +{ + MString tmpret; + if( GetValue( sDataPointer, tmpret ) ) + return StrToFloat( tmpret ); + if( bSetValue ) + SetValueF( sDataPointer, fDefaultValue ); + + return fDefaultValue; +} + +void MercuryNamedResource::SetValueF( const MString & sDataPointer, float fValue ) +{ + char sset[64]; + snprintf( sset, 63, "%f", fValue ); + SetValueS( sDataPointer, sset ); +} + +bool MercuryNamedResource::GetValueB( const MString & sDataPointer, bool bDefaultValue, bool bSetValue ) +{ + MString tmpret; + if( GetValue( sDataPointer, tmpret ) ) + return StrToInt( tmpret ); + if( bSetValue ) + SetValueB( sDataPointer, bDefaultValue ); + + return bDefaultValue; +} + +void MercuryNamedResource::SetValueB( const MString & sDataPointer, bool bValue ) +{ + if( bValue ) + SetValueS( sDataPointer, "1" ); + else + SetValueS( sDataPointer, "0" ); +} + +int MercuryNamedResource::GetValueI( const MString & sDataPointer, int iDefaultValue, bool bSetValue ) +{ + MString tmpret; + if( GetValue( sDataPointer, tmpret ) ) + return StrToInt( tmpret ); + if( bSetValue ) + SetValueI( sDataPointer, iDefaultValue ); + + return iDefaultValue; +} + +void MercuryNamedResource::SetValueI( const MString & sDataPointer, int iValue ) +{ + char sset[64]; + snprintf( sset, 63, "%d", iValue ); + SetValueS( sDataPointer, sset ); +} + + +/**************************************************************************** + * Copyright (C) 2009 by Charles Lohr * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above * + * copyright notice, this list of conditions and the following * + * disclaimer in the documentation and/or other materials provided * + * with the distribution. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + ***************************************************************************/ Added: Mercury2/src/MercuryNamedResource.h =================================================================== --- Mercury2/src/MercuryNamedResource.h (rev 0) +++ Mercury2/src/MercuryNamedResource.h 2009-06-28 21:57:18 UTC (rev 385) @@ -0,0 +1,82 @@ +#ifndef _MERCURY_NAMED_RESOURCE +#define _MERCURY_NAMED_RESOURCE + +#include <MercuryString.h> + +///Base class for several named resources (I.e. Preferences, Theme, etc.) +class MercuryNamedResource +{ +public: + ///Get a Value + /** This function _must_ be overloaded by the base class, as there is no + mechanism for the named resource to figure this out. */ + virtual bool GetValue( const MString & sDataPointer, MString & sReturn ) = 0; + + ///Set a named value. + /** This function should be overloaded by the base class, unless you have no + means to write back. For instance, the theme will simply ignore this + function. */ + virtual void SetValueS( const MString & sDataPointer, const MString & sValToSet ) { } + + ///Retrieve a named value + /** This function can be overloaded by the base class, otherwise, it + just makes approprate calls to GetValue */ + virtual MString GetValueS( const MString & sDataPointer, MString sDefaultValue, bool bSetValue = false ); + + ///Shorthand for retrieving a named value (calls GetValueS with null Parameters) + /** This function may be overloaded if you wish to improve performance slightly + when users are simply doing reads and do not intend to set default values */ + virtual MString GetValueS( const MString & sDataPointer ); + + ///Retrieve a named value and convert it to a float. + float GetValueF( const MString & sDataPointer, float fDefaultValue = 0.0f, bool bSetValue = false ); + + ///Set a float value on a named resource. + void SetValueF( const MString & sDataPointer, float fValue ); + + ///Retrieve a named value and convert it to a boolean. + bool GetValueB( const MString & sDataPointer, bool bDefaultValue = false, bool bSetValue = false ); + + ///Set a float value on a named resource. + void SetValueB( const MString & sDataPointer, bool bValue ); + + ///Retrieve a named value and convert it to a float. + int GetValueI( const MString & sDataPointer, int iDefaultValue = 0, bool bSetValue = false ); + + ///Set a float value on a named resource. + void SetValueI( const MString & sDataPointer, int iValue ); +}; + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Charles Lohr * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above * + * copyright notice, this list of conditions and the following * + * disclaimer in the documentation and/or other materials provided * + * with the distribution. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + ***************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-28 21:59:33
|
Revision: 387 http://hgengine.svn.sourceforge.net/hgengine/?rev=387&view=rev Author: cnlohr Date: 2009-06-28 21:59:32 +0000 (Sun, 28 Jun 2009) Log Message: ----------- add utility String functions (this is taken mostly from HG1, these functions proved highly useful and did not appear to cause problems) Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-06-28 21:58:37 UTC (rev 386) +++ Mercury2/src/MercuryUtil.cpp 2009-06-28 21:59:32 UTC (rev 387) @@ -1,6 +1,7 @@ #include <MercuryUtil.h> #include <MercuryFile.h> #include <Mint.h> +#include <MercuryVector.h> MString ToUpper(const MString& s) { @@ -87,6 +88,55 @@ return (ith<0)?3:(ith>15)?GeneralUsePrimes[15]:GeneralUsePrimes[ith]; } +//String processing functions +long BytesUntil( const char* strin, const char * termin, long start, long slen, long termlen ) +{ + int i; + for ( i = start; i < slen; i++ ) + for ( int j = 0; j < termlen; j++ ) + if ( termin[j] == strin[i] ) + return i - start; + return i - start; +} + +long BytesNUntil( const char* strin, const char * termin, long start, long slen, long termlen ) +{ + int i; + for ( i = start; i < slen; i++ ) + { + bool found = false; + for ( int j = 0; j < termlen; j++ ) + { + if ( termin[j] == strin[i] ) + found = true; + } + if ( !found ) + return i - start; + } + return i - start; +} + +void SplitStrings( const MString & in, MVector < MString > & out, + const char * termin, const char * whitespace, + long termlen, long wslen ) +{ + const char * inStr = in.c_str(); + long curPos = 0; + long inLen = in.length(); + while ( curPos < inLen ) + { + curPos += BytesNUntil( inStr, whitespace, curPos, inLen, wslen ); + long NextPos = BytesUntil( inStr, termin, curPos, inLen, termlen ); + out.push_back( in.substr( curPos, NextPos ) ); + curPos += NextPos + 1; + } +} + + + + + + /* Copyright (c) 2009, Joshua Allen and Charles Lohr * All rights reserved. * Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-06-28 21:58:37 UTC (rev 386) +++ Mercury2/src/MercuryUtil.h 2009-06-28 21:59:32 UTC (rev 387) @@ -104,6 +104,24 @@ ///pattern is the next prime number that's roughly two times the last. int GetAPrime( int ith ); + + + +//String processing functions +//XXX: This may not be portable. We do not in fact need to include the header for MVector yet. +template<typename T> +class MVector; + +///Bytes until desired terminal +long BytesUntil( const char* strin, const char * termin, long start, long slen, long termlen ); + +///Bytes until something other than a terminal +long BytesNUntil( const char* strin, const char * termin, long start, long slen, long termlen ); + +///Split given string into other strings using delimiters from termin +void SplitStrings( const MString & in, MVector < MString > & out, const char * termin, const char * whitespace, long termlen, long wslen ); + + #endif /* Copyright (c) 2009, Joshua Allen and Charles Lohr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-28 22:00:29
|
Revision: 388 http://hgengine.svn.sourceforge.net/hgengine/?rev=388&view=rev Author: cnlohr Date: 2009-06-28 22:00:27 +0000 (Sun, 28 Jun 2009) Log Message: ----------- update the XML Parser to be able to handle .GetValue(), thus reaping all of the rewards of the named resource class. Modified Paths: -------------- Mercury2/src/XMLParser.cpp Mercury2/src/XMLParser.h Modified: Mercury2/src/XMLParser.cpp =================================================================== --- Mercury2/src/XMLParser.cpp 2009-06-28 21:59:32 UTC (rev 387) +++ Mercury2/src/XMLParser.cpp 2009-06-28 22:00:27 UTC (rev 388) @@ -1,13 +1,14 @@ #include <XMLParser.h> #include <MercuryFile.h> +#include <MercuryVector.h> #include <libxml/parser.h> #include <libxml/tree.h> -#if defined(WIN32) -# if defined(_MSC_VER) -# pragma comment(lib, "libxml2.lib") -# endif +#if defined(WIN32) +# if defined(_MSC_VER) +# pragma comment(lib, "libxml2.lib") +# endif #endif XMLNode::XMLNode(xmlNode* node, xmlDoc* doc) @@ -184,6 +185,33 @@ return *this; } +bool XMLNode::GetValue( const MString & sDataPointer, MString & sReturn ) +{ + MVector< MString > out; + SplitStrings( sDataPointer, out, ".", " ", 1, 1 ); + //Out now contains the input in a parsed form; + //a.b.c is now: + //out[0] = "a"; out[1] = "b"; out[2] = "c"; + XMLNode & rthis = *this; + for( unsigned i = 0; i < out.size() - 1; i++ ) + { + while( rthis.Name() != out[i] && rthis.IsValid() ) + rthis = rthis.NextNode(); + + if( !rthis.IsValid() ) + return false; + + if( i < out.size() - 2 ) + rthis = rthis.Child(); + + if( !rthis.IsValid() ) + return false; + } + + sReturn = rthis.Attribute( out[out.size()-1] ); + return true; +} + XMLDocument::XMLDocument() :m_doc(NULL) { Modified: Mercury2/src/XMLParser.h =================================================================== --- Mercury2/src/XMLParser.h 2009-06-28 21:59:32 UTC (rev 387) +++ Mercury2/src/XMLParser.h 2009-06-28 22:00:27 UTC (rev 388) @@ -2,6 +2,7 @@ #define XMLPARSER_H #include <MAutoPtr.h> +#include <MercuryNamedResource.h> struct _xmlNode; typedef struct _xmlNode xmlNode; @@ -14,7 +15,7 @@ private: }; -class XMLNode +class XMLNode : public MercuryNamedResource { public: XMLNode(xmlNode* node = NULL, xmlDoc* doc = NULL); @@ -35,6 +36,8 @@ XMLNode FindFallbackNode() const; const XMLNode& operator=(const XMLNode& n); + + virtual bool GetValue( const MString & sDataPointer, MString & sReturn ); private: XMLNode RecursiveFindFallbackNode(const MString& path) const; XMLNode FindParentWithName(const MString& name) const; @@ -62,26 +65,35 @@ #endif -/*************************************************************************** - * Copyright (C) 2008 by Joshua Allen * - * * - * * - * All rights reserved. * - * * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * - * * Neither the name of the Mercury developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above * + * copyright notice, this list of conditions and the following * + * disclaimer in the documentation and/or other materials provided * + * with the distribution. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-29 04:22:15
|
Revision: 389 http://hgengine.svn.sourceforge.net/hgengine/?rev=389&view=rev Author: cnlohr Date: 2009-06-29 04:22:13 +0000 (Mon, 29 Jun 2009) Log Message: ----------- cleanup the utility file Modified Paths: -------------- Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryHash.h Mercury2/src/MercuryUtil.h Mercury2/src/Shader.cpp Mercury2/src/Texture.cpp Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-06-28 22:00:27 UTC (rev 388) +++ Mercury2/src/MercuryFBO.cpp 2009-06-29 04:22:13 UTC (rev 389) @@ -1,6 +1,7 @@ #include <MercuryFBO.h> #include <GLHeaders.h> #include <MercuryWindow.h> +#include <assert.h> REGISTER_NODE_TYPE(MercuryFBO); Modified: Mercury2/src/MercuryHash.h =================================================================== --- Mercury2/src/MercuryHash.h 2009-06-28 22:00:27 UTC (rev 388) +++ Mercury2/src/MercuryHash.h 2009-06-29 04:22:13 UTC (rev 389) @@ -3,6 +3,7 @@ #include "global.h" #include <MercuryVector.h> +#include <assert.h> ///Mercury Hash Table for Strings template<typename T> Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-06-28 22:00:27 UTC (rev 388) +++ Mercury2/src/MercuryUtil.h 2009-06-29 04:22:13 UTC (rev 389) @@ -3,13 +3,9 @@ #include <stdlib.h> #include <MercuryString.h> -#include <assert.h> #include <global.h> +#include <stdio.h> -/*#ifndef NULL -#define NULL 0 -#endif*/ - #define SAFE_DELETE( x ) { if (x) { delete x; } x = NULL; } #define SAFE_DELETE_ARRAY( x ) { if (x) { delete[] x; } x = NULL; } #define SAFE_FREE(p) { if(p) { free(p); p=0; } } @@ -20,8 +16,6 @@ void* mmemalign(size_t align, size_t size, void*& mem); bool isAligned(size_t align, const void* mem); -#define ASSERT(x) assert(!x) - #if defined(__GNUC__) #define M_ALIGN(n) __attribute__((aligned(n))) #else @@ -56,7 +50,6 @@ //This counter is used with singletons to //ensure proper destruction order of the //singleton -#include <stdio.h> template<typename T> class InstanceCounter { Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-28 22:00:27 UTC (rev 388) +++ Mercury2/src/Shader.cpp 2009-06-29 04:22:13 UTC (rev 389) @@ -1,10 +1,8 @@ #include <Shader.h> #include <MercuryNode.h> #include <MercuryFile.h> - +#include <assert.h> #include <GLHeaders.h> - - #include <string.h> using namespace std; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-06-28 22:00:27 UTC (rev 388) +++ Mercury2/src/Texture.cpp 2009-06-29 04:22:13 UTC (rev 389) @@ -4,6 +4,7 @@ #include <MercuryNode.h> #include <GLHeaders.h> #include <Shader.h> +#include <assert.h> using namespace std; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-30 01:22:26
|
Revision: 391 http://hgengine.svn.sourceforge.net/hgengine/?rev=391&view=rev Author: cnlohr Date: 2009-06-30 01:22:24 +0000 (Tue, 30 Jun 2009) Log Message: ----------- add extra access to get to XML directly Modified Paths: -------------- Mercury2/src/MercuryPrefs.cpp Mercury2/src/MercuryPrefs.h Modified: Mercury2/src/MercuryPrefs.cpp =================================================================== --- Mercury2/src/MercuryPrefs.cpp 2009-06-30 01:15:53 UTC (rev 390) +++ Mercury2/src/MercuryPrefs.cpp 2009-06-30 01:22:24 UTC (rev 391) @@ -24,6 +24,11 @@ return m_PrefsDoc->GetRootNode().GetValue( sDataPointer, sReturn ); } +XMLNode MercuryPreferences::GetRootXML() +{ + return m_PrefsDoc->GetRootNode(); +} + /**************************************************************************** * Copyright (C) 2009 by Charles Lohr * * * Modified: Mercury2/src/MercuryPrefs.h =================================================================== --- Mercury2/src/MercuryPrefs.h 2009-06-30 01:15:53 UTC (rev 390) +++ Mercury2/src/MercuryPrefs.h 2009-06-30 01:22:24 UTC (rev 391) @@ -16,6 +16,8 @@ virtual bool GetValue( const MString & sDataPointer, MString & sReturn ); static MercuryPreferences & GetInstance(); + + XMLNode GetRootXML(); private: XMLDocument * m_PrefsDoc; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-06-30 02:53:12
|
Revision: 392 http://hgengine.svn.sourceforge.net/hgengine/?rev=392&view=rev Author: cnlohr Date: 2009-06-30 01:51:59 +0000 (Tue, 30 Jun 2009) Log Message: ----------- update preferences, crash mercury if something's wrong, handle booleans better. Modified Paths: -------------- Mercury2/src/MercuryNamedResource.cpp Mercury2/src/MercuryPrefs.cpp Mercury2/src/MercuryPrefs.h Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryNamedResource.cpp =================================================================== --- Mercury2/src/MercuryNamedResource.cpp 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/MercuryNamedResource.cpp 2009-06-30 01:51:59 UTC (rev 392) @@ -43,7 +43,18 @@ { MString tmpret; if( GetValue( sDataPointer, tmpret ) ) + { + tmpret = ToUpper( tmpret ); + if( tmpret.compare( "TRUE" ) == 0 ) return 1; + if( tmpret.compare( "FALSE" ) == 0 ) return 0; + if( tmpret.compare( "ON" ) == 0 ) return 1; + if( tmpret.compare( "OFF" ) == 0 ) return 0; + if( tmpret.compare( "YES" ) == 0 ) return 1; + if( tmpret.compare( "NO" ) == 0 ) return 0; + return StrToInt( tmpret ); + } + if( bSetValue ) SetValueB( sDataPointer, bDefaultValue ); Modified: Mercury2/src/MercuryPrefs.cpp =================================================================== --- Mercury2/src/MercuryPrefs.cpp 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/MercuryPrefs.cpp 2009-06-30 01:51:59 UTC (rev 392) @@ -12,6 +12,20 @@ MercuryPreferences::MercuryPreferences() { m_PrefsDoc = XMLDocument::Load("preferences.xml"); + if( !m_PrefsDoc ) + FAIL( "Could not load preferences.xml." ); + + m_PrefsNode = new XMLNode(); + + *m_PrefsNode = m_PrefsDoc->GetRootNode(); + + if( !m_PrefsNode->IsValid() ) + FAIL( "Could not get root node in Preferences." ); + + *m_PrefsNode = m_PrefsNode->Child(); + + if( !m_PrefsNode->IsValid() ) + FAIL( "Could not get Preferences node in Preferences." ); } MercuryPreferences::~MercuryPreferences() @@ -21,13 +35,9 @@ bool MercuryPreferences::GetValue( const MString & sDataPointer, MString & sReturn ) { - return m_PrefsDoc->GetRootNode().GetValue( sDataPointer, sReturn ); + return m_PrefsNode->GetValue( sDataPointer, sReturn ); } -XMLNode MercuryPreferences::GetRootXML() -{ - return m_PrefsDoc->GetRootNode(); -} /**************************************************************************** * Copyright (C) 2009 by Charles Lohr * Modified: Mercury2/src/MercuryPrefs.h =================================================================== --- Mercury2/src/MercuryPrefs.h 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/MercuryPrefs.h 2009-06-30 01:51:59 UTC (rev 392) @@ -17,9 +17,10 @@ static MercuryPreferences & GetInstance(); - XMLNode GetRootXML(); + XMLNode * GetRootXML() { return m_PrefsNode; } private: - XMLDocument * m_PrefsDoc; + XMLNode * m_PrefsNode; + XMLDocument * m_PrefsDoc; }; static InstanceCounter<MercuryPreferences> MPcounter("MercuryPreferences"); Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/MercuryUtil.cpp 2009-06-30 01:51:59 UTC (rev 392) @@ -36,6 +36,15 @@ #endif return x; } + + +void fail_m( const char * message, const char * file, int line ) +{ + //Probably should message box here somewhere in the event we're running on Windows. + fprintf( stderr, "Fatal Error: \"%s\" in %s:%d\n", message, file, line ); + exit(-1); +} + void* mmemalign(size_t align, size_t size, void*& mem) { uintptr_t mask = ~(uintptr_t)(align - 1); Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/MercuryUtil.h 2009-06-30 01:51:59 UTC (rev 392) @@ -12,6 +12,9 @@ #define TO_ENDIAN( x ) +void fail_m( const char * message, const char * file, int line ); +#define FAIL( message ) fail_m( message, __FILE__, __LINE__ ); + //returns an aligned pointer, mem is the actual (unaligned) pointer for freeing void* mmemalign(size_t align, size_t size, void*& mem); bool isAligned(size_t align, const void* mem); Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-06-30 01:22:24 UTC (rev 391) +++ Mercury2/src/X11Window.cpp 2009-06-30 01:51:59 UTC (rev 392) @@ -1,6 +1,7 @@ #include <X11Window.h> #include <MercuryMessageManager.h> #include <MercuryInput.h> +#include <MercuryPrefs.h> Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(X11Window::GenX11Window); //Register window generation callback @@ -91,7 +92,14 @@ MercuryWindow* X11Window::GenX11Window() { - return new X11Window("Mercury2 Tests", 640, 480, 24, 16, false); + return new X11Window( + PREFSMAN.GetValueS("Screen.Name", "Screen name not set." ), + PREFSMAN.GetValueI( "Screen.Width", 640 ), + PREFSMAN.GetValueI( "Screen.Height", 480 ), + 24, + PREFSMAN.GetValueI( "Screen.Depth", 16 ), + PREFSMAN.GetValueB( "Screen.FullScreen", 1 ) + ); } bool X11Window::SwapBuffers() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-07-04 06:23:29
|
Revision: 398 http://hgengine.svn.sourceforge.net/hgengine/?rev=398&view=rev Author: cnlohr Date: 2009-07-04 06:23:28 +0000 (Sat, 04 Jul 2009) Log Message: ----------- add FindNode() (to find children by name Modified Paths: -------------- Mercury2/src/MercuryMath.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryMath.h =================================================================== --- Mercury2/src/MercuryMath.h 2009-07-03 04:53:25 UTC (rev 397) +++ Mercury2/src/MercuryMath.h 2009-07-04 06:23:28 UTC (rev 398) @@ -15,6 +15,8 @@ #define INFINITY (std::numeric_limits<float>::infinity()) #endif +#define MAXINT (0x7FFFFFFF) + void ZeroFloatRow(FloatRow& r); #define DEGRAD 0.01745329251994329576f //degree to radian Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-03 04:53:25 UTC (rev 397) +++ Mercury2/src/MercuryNode.cpp 2009-07-04 06:23:28 UTC (rev 398) @@ -97,6 +97,30 @@ return child->PrevSibling(); } +MercuryNode* MercuryNode::FindChild( const MString & sNameOfNode, int depth ) +{ + if( depth >= 0 ) + { + for( std::list< MercuryNode* >::iterator i = m_children.begin(); i != m_children.end(); i++ ) + { + if( (*i)->GetName().compare( sNameOfNode ) == 0 ) + return (*i); + } + + for( std::list< MercuryNode* >::iterator i = m_children.begin(); i != m_children.end(); i++ ) + { + MercuryNode * ret; + if( ( ret = (*i)->FindChild( sNameOfNode, depth - 1 ) ) ) + { + if( (*i)->GetName().compare( sNameOfNode ) == 0 ) + return ret; + } + } + } + return NULL; +} + + void MercuryNode::RecursiveUpdate(float dTime) { Update(dTime); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-07-03 04:53:25 UTC (rev 397) +++ Mercury2/src/MercuryNode.h 2009-07-04 06:23:28 UTC (rev 398) @@ -42,7 +42,11 @@ MercuryNode* NextChild(const MercuryNode* n) const; ///Finds the next child in regards to n MercuryNode* PrevChild(const MercuryNode* n) const; ///Finds the previous child in regards to n const std::list< MercuryNode* >& Children() const { return m_children; } - + + ///Find a child node that has the name matching sNameOfNode. + /** The search order is breadth-first, however this may change without notice! */ + MercuryNode* FindChild( const MString & sNameOfNode, int depth = MAXINT ); + virtual void Update(float dTime) {}; virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-04 15:43:42
|
Revision: 404 http://hgengine.svn.sourceforge.net/hgengine/?rev=404&view=rev Author: axlecrusher Date: 2009-07-04 15:43:36 +0000 (Sat, 04 Jul 2009) Log Message: ----------- update Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-07-04 15:42:50 UTC (rev 403) +++ Mercury2/src/MercuryVertex.cpp 2009-07-04 15:43:36 UTC (rev 404) @@ -28,6 +28,13 @@ (*this)[i] = v[i]; } +MercuryVertex::MercuryVertex( const MercuryVertex& v, float w) +{ + for (unsigned int i = 0; i < 3; ++i) + (*this)[i] = v[i]; + (*this)[3] = w; +} + void MercuryVertex::NormalizeSelf() { float imag = 1.0f/Length(); Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-07-04 15:42:50 UTC (rev 403) +++ Mercury2/src/MercuryVertex.h 2009-07-04 15:43:36 UTC (rev 404) @@ -19,6 +19,7 @@ MercuryVertex( float ix, float iy, float iz, float iw = 0 ); MercuryVertex( const float * in ); MercuryVertex( const MercuryVertex& v); + MercuryVertex( const MercuryVertex& v, float w); ///Direct conversion to float* __inline__ operator float* () { return (float*)&m_xyzw; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-04 15:46:37
|
Revision: 405 http://hgengine.svn.sourceforge.net/hgengine/?rev=405&view=rev Author: axlecrusher Date: 2009-07-04 15:46:32 +0000 (Sat, 04 Jul 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/FullscreenQuad.cpp Mercury2/src/GLHeaders.h Modified: Mercury2/src/FullscreenQuad.cpp =================================================================== --- Mercury2/src/FullscreenQuad.cpp 2009-07-04 15:43:36 UTC (rev 404) +++ Mercury2/src/FullscreenQuad.cpp 2009-07-04 15:46:32 UTC (rev 405) @@ -14,7 +14,7 @@ { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glLoadMatrixf( m_matrix.Ptr() ); + glLoadMatrixf( m_matrix.Ptr() ); //this is OK glMatrixMode(GL_PROJECTION); glPushMatrix(); Modified: Mercury2/src/GLHeaders.h =================================================================== --- Mercury2/src/GLHeaders.h 2009-07-04 15:43:36 UTC (rev 404) +++ Mercury2/src/GLHeaders.h 2009-07-04 15:46:32 UTC (rev 405) @@ -19,6 +19,7 @@ #endif #include <GLHelpers.h> +#include <assert.h> #define GLERRORCHECK { \ uint32_t e = glGetError(); \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-04 16:01:20
|
Revision: 406 http://hgengine.svn.sourceforge.net/hgengine/?rev=406&view=rev Author: axlecrusher Date: 2009-07-04 16:01:19 +0000 (Sat, 04 Jul 2009) Log Message: ----------- new culling Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Mercury2/src/Mercury2.cpp Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryVBO.cpp Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-07-04 15:46:32 UTC (rev 405) +++ Mercury2/src/BoundingBox.cpp 2009-07-04 16:01:19 UTC (rev 406) @@ -35,27 +35,31 @@ void BoundingBox::ComputeNormals() { - MercuryVertex t(m_center); + //normals are probably just the cardinal axises +/* MercuryVertex t(m_center, 0); t.SetX( t.GetX() + m_extend.GetX() ); - m_normals[0] = (m_center - t).Normalize(); + m_normals[0] = t;//.Normalize(); t = m_center; t.SetY( t.GetY() + m_extend.GetY() ); - m_normals[1] = (m_center - t).Normalize(); + m_normals[1] = t;//.Normalize(); t = m_center; t.SetZ( t.GetZ() + m_extend.GetZ() ); - m_normals[2] = (m_center - t).Normalize(); + m_normals[2] = t;//.Normalize(); + */ } void BoundingBox::Transform( const MercuryMatrix& m ) { BoundingBox bb; - bb.m_extend = m_center; - bb.m_center = m * m_center; - bb.m_normals[0] = (m * m_normals[0]).Normalize(); - bb.m_normals[1] = (m * m_normals[1]).Normalize(); - bb.m_normals[2] = (m * m_normals[2]).Normalize(); + bb.m_extend = m_extend; + MercuryMatrix mm = m * FRUSTUM->GetMatrix(); + bb.m_center = mm * MercuryVertex(m_center, 1); + bb.m_normals[0] = (mm * MercuryVector(1.0f,0,0,0)).Normalize(); + bb.m_normals[1] = (mm * MercuryVector(0,1.0f,0,0)).Normalize(); + bb.m_normals[2] = (mm * MercuryVector(0,0,1.0f,0)).Normalize(); +// bb.Render(); *this = bb; } @@ -84,7 +88,121 @@ return !inView; } +bool BoundingBox::FrustumCull() const +{ + static float b[3]; + uint32_t samples; + const float* center = GetCenter(); + const float* extend = GetExtend(); + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); + glDisable(GL_CULL_FACE); + glFeedbackBuffer(3, GL_3D, b); + glRenderMode( GL_FEEDBACK ); + + glBegin(GL_QUADS); + //front + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + //back + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + + //top + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + //bottom + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + + //left + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + + //right + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + glEnd(); + samples = glRenderMode( GL_RENDER ); + glPopAttrib( ); + return samples==0; +} + +bool BoundingBox::OcclusionCull() const +{ + static uint32_t q; + uint32_t samples; + const float* center = GetCenter(); + const float* extend = GetExtend(); + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); + glDisable(GL_CULL_FACE); + glGenQueriesARB(1, &q); + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, q); + + glBegin(GL_QUADS); + + //front + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + //back + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + + //top + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + //bottom + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + + //left + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + + //right + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); + glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + + glEnd(); + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples); + + glPopAttrib( ); + + return samples==0; +} + void BoundingBox::Render() { // BoundingBox gbb = *this; @@ -95,6 +213,8 @@ const float* center = GetCenter(); const float* extend = GetExtend(); +// glPushMatrix(); +// glLoadIdentity(); glPushAttrib( GL_CURRENT_BIT ); glBegin(GL_LINES); glColor3f(0,1.0f,0); @@ -133,12 +253,34 @@ glEnd(); + //center glPointSize(4); glBegin(GL_POINTS); glVertex3f(center[0], center[1], center[2]); glEnd(); + //normals + MercuryVertex c; + glBegin(GL_LINES); + glColor3f(1.0f,0,0); + glVertex3f(center[0], center[1], center[2]); + c = center; + c += m_normals[0]; + glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glColor3f(0,1.0f,0); + glVertex3f(center[0], center[1], center[2]); + c = center; + c += m_normals[1]; + glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glColor3f(0,0,1.0f); + glVertex3f(center[0], center[1], center[2]); + c = center; + c += m_normals[2]; + glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glEnd(); + glPopAttrib( ); +// glPopMatrix(); } /**************************************************************************** Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-07-04 15:46:32 UTC (rev 405) +++ Mercury2/src/BoundingBox.h 2009-07-04 16:01:19 UTC (rev 406) @@ -20,6 +20,9 @@ virtual bool Clip( const MercuryPlane& p ) = 0; virtual bool Clip( const Frustum& f ) = 0; + + virtual bool FrustumCull() const = 0; + virtual bool OcclusionCull() const = 0; }; class BoundingBox : public BoundingVolume @@ -45,6 +48,9 @@ virtual bool Clip( const MercuryPlane& p ); virtual bool Clip( const Frustum& f ); + virtual bool FrustumCull() const; + virtual bool OcclusionCull() const; + private: void ComputeNormals(); Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-07-04 15:46:32 UTC (rev 405) +++ Mercury2/src/Mercury2.cpp 2009-07-04 16:01:19 UTC (rev 406) @@ -19,6 +19,7 @@ #include <ModuleManager.h> #include <MercuryFile.h> bool SHOWBOUNDINGVOLUME = false; +bool SHOWAXISES = false; MSemaphore UpdateLoopGo; void* UpdateThread(void* node) Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-04 15:46:32 UTC (rev 405) +++ Mercury2/src/MercuryNode.cpp 2009-07-04 16:01:19 UTC (rev 406) @@ -137,12 +137,13 @@ MercuryMatrix matrix = FindGlobalMatrix(); PreRender( matrix ); //calls on children assets + modelView = ManipulateMatrix( matrix ); - if ( IsHidden() || IsCulled(modelView) ) return; - modelView.Transpose(); +// if ( IsHidden() || IsCulled(modelView) ) return; + if ( IsHidden() ) return; + + glLoadMatrix( modelView ); - glLoadMatrixf( modelView.Ptr() ); - sa.type = ShaderAttribute::TYPE_MATRIX; sa.value.matrix = matrix.Ptr(); Shader::SetAttribute("HG_ModelMatrix", sa); @@ -158,7 +159,7 @@ child->RecursiveRender(); } - glLoadMatrixf( modelView.Ptr() ); + glLoadMatrix( modelView ); Shader::SetAttribute("HG_ModelMatrix", sa); PostRender( modelView ); //calls on children assets } @@ -217,9 +218,15 @@ void MercuryNode::Render(const MercuryMatrix& matrix) { + bool cull; list< MercuryAsset* >::iterator i; for (i = m_render.begin(); i != m_render.end(); ++i ) - (*i)->Render(this); + { + cull = false; + const BoundingVolume* bv = (*i)->GetBoundingVolume(); + if (bv) cull = bv->FrustumCull(); + if ( !cull ) (*i)->Render(this); + } } void MercuryNode::PostRender(const MercuryMatrix& matrix) @@ -283,22 +290,14 @@ bool MercuryNode::IsCulled(const MercuryMatrix& matrix) { bool clip = false; - +/* std::list< MAutoPtr< MercuryAsset > >::iterator i; for (i = m_assets.begin(); i != m_assets.end(); ++i ) { - const BoundingVolume* bv = (*i)->GetBoundingVolume(); - if (bv) - { - BoundingVolume* v = bv->SpawnClone(); - v->Transform( matrix ); - clip = v->Clip( *FRUSTUM ); - delete v; - if ( clip == false ) return false; - } - else - return false; + clip = (*i)->IsCulled( matrix ); + if ( clip == false ) return false; } + */ return clip; } Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-07-04 15:46:32 UTC (rev 405) +++ Mercury2/src/MercuryVBO.cpp 2009-07-04 16:01:19 UTC (rev 406) @@ -8,6 +8,7 @@ #define BUFFER_OFFSET(i) ((char*)NULL + (i)) extern bool SHOWBOUNDINGVOLUME; +extern bool SHOWAXISES; MercuryVBO::MercuryVBO() :MercuryAsset(), m_initiated(false) @@ -60,7 +61,7 @@ m_lastVBOrendered = this; if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); - DrawAxes(); + if ( SHOWAXISES ) DrawAxes(); } void MercuryVBO::InitVBO() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-05 13:09:49
|
Revision: 407 http://hgengine.svn.sourceforge.net/hgengine/?rev=407&view=rev Author: axlecrusher Date: 2009-07-05 12:55:17 +0000 (Sun, 05 Jul 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-07-04 16:01:19 UTC (rev 406) +++ Mercury2/src/BoundingBox.cpp 2009-07-05 12:55:17 UTC (rev 407) @@ -2,21 +2,32 @@ #include <BoundingBox.h> #include <string.h> #include <Viewport.h> +#include <Texture.h> #define SIGNED_DIST(x) m_normal.DotProduct(x) // origional algorithim was -x<0 #define BEHIND_PLANE(x) x>=0 +bool BoundingVolume::IsOccluded() +{ + uint32_t samples = 1; + if (m_occlusionQuery != 0) + glGetQueryObjectuivARB(m_occlusionQuery, GL_QUERY_RESULT_ARB, &samples); + return samples==0; +} + BoundingBox::BoundingBox(const MercuryVertex& center, const MercuryVertex& extend) :m_center(center), m_extend(extend) { + PopulateVertices(); ComputeNormals(); -}; +} BoundingBox::BoundingBox(const BoundingBox& bb) :m_center(bb.m_center), m_extend(bb.m_extend) { + PopulateVertices(); for (uint8_t i = 0; i < 3; ++i) m_normals[i] = bb.m_normals[i]; } @@ -94,113 +105,96 @@ uint32_t samples; const float* center = GetCenter(); const float* extend = GetExtend(); - + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); glDisable(GL_CULL_FACE); + + glPushMatrix(); + glTranslatef(center[0], center[1], center[2]); + glScalef(extend[0],extend[1],extend[2]); + + uint8_t tCount = Texture::NumberActiveTextures(); + for (uint8_t i = 0; i < tCount; ++i) + { + glActiveTexture( GL_TEXTURE0+i ); + glClientActiveTextureARB( GL_TEXTURE0+i ); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable( GL_TEXTURE_2D ); + } glFeedbackBuffer(3, GL_3D, b); glRenderMode( GL_FEEDBACK ); - - glBegin(GL_QUADS); - - //front - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); - - //back - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - - //top - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); - - //bottom - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - //left - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); + InitVBO(); - //right - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glVertexPointer(3, GL_FLOAT, 0, 0); + glDrawArrays(GL_QUADS, 0, 24); + + for (uint8_t i = 0; i < tCount; ++i) + { + glActiveTexture( GL_TEXTURE0+i ); + glClientActiveTextureARB(GL_TEXTURE0+i); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnable( GL_TEXTURE_2D ); + } - glEnd(); samples = glRenderMode( GL_RENDER ); + glPopMatrix(); glPopAttrib( ); + +// return false; return samples==0; } -bool BoundingBox::OcclusionCull() const +void BoundingBox::DoOcclusionTest() { - static uint32_t q; - uint32_t samples; const float* center = GetCenter(); const float* extend = GetExtend(); - - glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glDisable(GL_CULL_FACE); - glGenQueriesARB(1, &q); - glBeginQueryARB(GL_SAMPLES_PASSED_ARB, q); - glBegin(GL_QUADS); + glPushMatrix(); + glTranslatef(center[0], center[1], center[2]); + glScalef(extend[0],extend[1],extend[2]); +/* + uint8_t tCount = Texture::NumberActiveTextures(); + for (uint8_t i = 0; i < tCount; ++i) + { + glActiveTexture( GL_TEXTURE0+i ); + glClientActiveTextureARB( GL_TEXTURE0+i ); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable( GL_TEXTURE_2D ); + } +*/ + InitVBO(); + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glVertexPointer(3, GL_FLOAT, 0, 0); + + if (m_occlusionQuery == 0) glGenQueriesARB(1, &m_occlusionQuery); + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, m_occlusionQuery); - //front - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDepthMask(GL_FALSE); - //back - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - - //top - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); - - //bottom - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - - //left - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]-extend[0], center[1]+extend[1], center[2]+extend[2]); - - //right - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]-extend[2]); - glVertex3f(center[0]+extend[0], center[1]-extend[1], center[2]+extend[2]); - glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); - - glEnd(); + glDrawArrays(GL_QUADS, 0, 24); +/* + for (uint8_t i = 0; i < tCount; ++i) + { + glActiveTexture( GL_TEXTURE0+i ); + glClientActiveTextureARB(GL_TEXTURE0+i); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnable( GL_TEXTURE_2D ); + } +*/ glEndQueryARB(GL_SAMPLES_PASSED_ARB); - glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples); +// glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples); glPopAttrib( ); - - return samples==0; + glPopMatrix(); } void BoundingBox::Render() @@ -283,6 +277,64 @@ // glPopMatrix(); } +void BoundingBox::PopulateVertices() +{ + if (m_vertexData.Length() == 72) return; + m_vertexData.Allocate( 72 ); + + uint32_t i = 0; + + //back + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + + //front + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + + //left + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + + //right + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + + //top + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + + //bottom + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; +} + +void BoundingBox::InitVBO() +{ + if (m_vboID != 0) return; + + glGenBuffersARB(1, &m_vboID); + + //vertex VBO + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB); +} + +AlignedBuffer<float> BoundingBox::m_vertexData; +uint32_t BoundingBox::m_vboID = 0; + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-07-04 16:01:19 UTC (rev 406) +++ Mercury2/src/BoundingBox.h 2009-07-05 12:55:17 UTC (rev 407) @@ -8,9 +8,15 @@ #include <Mint.h> #include <MercuryPlane.h> +#include <AlignedBuffer.h> + class BoundingVolume { public: + BoundingVolume() + :m_occlusionQuery(0) + {} + virtual ~BoundingVolume() {}; virtual void LoadFromBinary(char* data) = 0; @@ -22,14 +28,25 @@ virtual bool Clip( const Frustum& f ) = 0; virtual bool FrustumCull() const = 0; - virtual bool OcclusionCull() const = 0; +// virtual bool OcclusionCull() const = 0; + bool IsOccluded(); + virtual void DoOcclusionTest() = 0; + + protected: + uint32_t m_occlusionQuery; }; class BoundingBox : public BoundingVolume { public: - BoundingBox() {}; + BoundingBox() + :BoundingVolume() + { + PopulateVertices(); + } + BoundingBox(const MercuryVertex& center, const MercuryVertex& extend); + BoundingBox(const BoundingBox& bb); virtual ~BoundingBox() {}; @@ -49,15 +66,21 @@ virtual bool Clip( const Frustum& f ); virtual bool FrustumCull() const; - virtual bool OcclusionCull() const; +// virtual bool OcclusionCull() const; + virtual void DoOcclusionTest(); private: void ComputeNormals(); - + static void PopulateVertices(); + static void InitVBO(); + MercuryVertex m_center; MercuryVertex m_extend; MercuryVector m_normals[3]; + + static AlignedBuffer<float> m_vertexData; + static uint32_t m_vboID; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-05 15:48:17
|
Revision: 408 http://hgengine.svn.sourceforge.net/hgengine/?rev=408&view=rev Author: axlecrusher Date: 2009-07-05 15:48:11 +0000 (Sun, 05 Jul 2009) Log Message: ----------- Add a much improved occlusion test. This required changing how rendering works. Specifically, PreRender() is now called on the entire render tree before any Render() commands are issued. Prerender tells openGL to do a very fast occlusion test before doing anything else with opengl. This can be extreamly useful if large occluding geometry is rendered first, followed by many smaller occluded objects. Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Mercury2/src/RenderBuffer.cpp Mercury2/src/RenderBuffer.h Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/BoundingBox.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -4,19 +4,29 @@ #include <Viewport.h> #include <Texture.h> +#include <MercuryVBO.h> + #define SIGNED_DIST(x) m_normal.DotProduct(x) // origional algorithim was -x<0 #define BEHIND_PLANE(x) x>=0 -bool BoundingVolume::IsOccluded() +OcclusionResult::~OcclusionResult() { - uint32_t samples = 1; - if (m_occlusionQuery != 0) - glGetQueryObjectuivARB(m_occlusionQuery, GL_QUERY_RESULT_ARB, &samples); - return samples==0; + if ( m_occlusionQuery != 0 ) + glDeleteQueriesARB( 1, &m_occlusionQuery ); + m_occlusionQuery = 0; } +uint32_t OcclusionResult::GetSamples() const +{ + if (m_occlusionQuery == 0) return ~0; + + uint32_t samples; + glGetQueryObjectuivARB(m_occlusionQuery, GL_QUERY_RESULT_ARB, &samples); + return samples; +} + BoundingBox::BoundingBox(const MercuryVertex& center, const MercuryVertex& extend) :m_center(center), m_extend(extend) { @@ -101,6 +111,11 @@ bool BoundingBox::FrustumCull() const { + /*feedback in openGL is probably depreciated + and is known to fallback to software + the OcclusionTest provides the same performence + it is probably best to avoid using this function */ + static float b[3]; uint32_t samples; const float* center = GetCenter(); @@ -147,49 +162,36 @@ return samples==0; } -void BoundingBox::DoOcclusionTest() +void BoundingBox::DoOcclusionTest( OcclusionResult& result ) { const float* center = GetCenter(); const float* extend = GetExtend(); - + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glDisable(GL_CULL_FACE); glPushMatrix(); glTranslatef(center[0], center[1], center[2]); glScalef(extend[0],extend[1],extend[2]); -/* - uint8_t tCount = Texture::NumberActiveTextures(); - for (uint8_t i = 0; i < tCount; ++i) + + if (m_vboID == 0) InitVBO(); + + if ( MercuryVBO::m_lastVBOrendered != &m_vboID ) { - glActiveTexture( GL_TEXTURE0+i ); - glClientActiveTextureARB( GL_TEXTURE0+i ); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable( GL_TEXTURE_2D ); + MercuryVBO::m_lastVBOrendered = &m_vboID; + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); // once + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); // once + glVertexPointer(3, GL_FLOAT, 0, 0); // once } -*/ - InitVBO(); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - glVertexPointer(3, GL_FLOAT, 0, 0); - - if (m_occlusionQuery == 0) glGenQueriesARB(1, &m_occlusionQuery); - glBeginQueryARB(GL_SAMPLES_PASSED_ARB, m_occlusionQuery); + if (result.GetQueryID() == 0) glGenQueriesARB(1, &result.GetQueryID()); + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, result.GetQueryID()); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glDrawArrays(GL_QUADS, 0, 24); -/* - for (uint8_t i = 0; i < tCount; ++i) - { - glActiveTexture( GL_TEXTURE0+i ); - glClientActiveTextureARB(GL_TEXTURE0+i); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable( GL_TEXTURE_2D ); - } -*/ + glEndQueryARB(GL_SAMPLES_PASSED_ARB); // glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples); @@ -323,8 +325,6 @@ void BoundingBox::InitVBO() { - if (m_vboID != 0) return; - glGenBuffersARB(1, &m_vboID); //vertex VBO Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/BoundingBox.h 2009-07-05 15:48:11 UTC (rev 408) @@ -10,6 +10,21 @@ #include <AlignedBuffer.h> +class OcclusionResult +{ + public: + OcclusionResult() + :m_occlusionQuery(0) + {} + ~OcclusionResult(); + + uint32_t GetSamples() const; + inline uint32_t IsOccluded() const { return GetSamples() == 0; } + inline uint32_t& GetQueryID() { return m_occlusionQuery; } + private: + uint32_t m_occlusionQuery; +}; + class BoundingVolume { public: @@ -27,10 +42,15 @@ virtual bool Clip( const MercuryPlane& p ) = 0; virtual bool Clip( const Frustum& f ) = 0; - virtual bool FrustumCull() const = 0; + virtual bool FrustumCull() const = 0; //Do not use // virtual bool OcclusionCull() const = 0; - bool IsOccluded(); - virtual void DoOcclusionTest() = 0; + + /** This uses openGL to do an occlusion test in hardware. + The answer is not immediately known, but this can be run on the GPU + while the CPU does something else. Get the anser later by calling + IsOccluded() on the result. + **/ + virtual void DoOcclusionTest(OcclusionResult& result) = 0; protected: uint32_t m_occlusionQuery; @@ -65,9 +85,9 @@ virtual bool Clip( const MercuryPlane& p ); virtual bool Clip( const Frustum& f ); - virtual bool FrustumCull() const; + virtual bool FrustumCull() const; //Do not use // virtual bool OcclusionCull() const; - virtual void DoOcclusionTest(); + virtual void DoOcclusionTest(OcclusionResult& result); private: void ComputeNormals(); Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/HGMDLModel.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -1,5 +1,5 @@ #include <HGMDLModel.h> - +#include <MercuryNode.h> REGISTER_ASSET_TYPE(HGMDLModel); const uint16_t EXPCTMJRV = 2; @@ -58,17 +58,21 @@ } } +void HGMDLModel::PreRender(const MercuryNode* node) +{ + if ( GetLoadState() != LOADING ) + for(uint16_t i = 0; i < m_meshes.size(); ++i) + m_meshes[i]->PreRender(node); +} + void HGMDLModel::Render(const MercuryNode* node) { - bool cull; if ( GetLoadState() != LOADING ) { for(uint16_t i = 0; i < m_meshes.size(); ++i) { - cull = false; - const BoundingVolume* bv = m_meshes[i]->GetBoundingVolume(); - if (bv) cull = bv->FrustumCull(); - if ( !cull ) m_meshes[i]->Render(node); + if ( !node->GetOcclusionResult().IsOccluded() ) + m_meshes[i]->Render(node); } } } Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/HGMDLModel.h 2009-07-05 15:48:11 UTC (rev 408) @@ -18,6 +18,8 @@ static void LoadModel(MercuryFile* hgmdl, HGMDLModel* model); static HGMDLModel* Generate(); + + virtual void PreRender(const MercuryNode* node); virtual void Render(const MercuryNode* node); private: Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/Mercury2.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -87,6 +87,7 @@ // renderGraph.Render(); // RenderableNode::RecursiveRender(root); // printf("\n"); + root->RecursivePreRender(); root->RecursiveRender(); renderGraph.RenderAlpha(); w->SwapBuffers(); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryAsset.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -16,6 +16,7 @@ void MercuryAsset::Init(MercuryNode* node) { // RenderableNode* rn; + if ( node ) node->AddPreRender(this); if ( node ) node->AddRender(this); } @@ -36,6 +37,13 @@ SetLoadState( LOADED ); } +void MercuryAsset::PreRender(const MercuryNode* node) +{ + MercuryNode* n = const_cast<MercuryNode*>(node); + if ( m_boundingVolume ) + m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); +} + void MercuryAsset::DrawAxes() { glBegin(GL_LINES); Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryAsset.h 2009-07-05 15:48:11 UTC (rev 408) @@ -32,8 +32,13 @@ virtual void Init(MercuryNode* node); - virtual void PreRender(const MercuryNode* node) {}; + /** PreRender should be called before any real openGL render commands. + It is used to handles things like frustum culling, and occlusion culling. + Currently only occlusion culling test is run here.**/ + virtual void PreRender(const MercuryNode* node); + virtual void Render(const MercuryNode* node) = 0; + virtual void PostRender(const MercuryNode* node) {}; ///Loads an asset from an XMLAsset representing itself @@ -43,7 +48,7 @@ inline void IsInstanced(bool b) { m_isInstanced = b; } - inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } + inline BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } inline const MString& Path() const { return m_path; } void DrawAxes(); Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryNode.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -129,25 +129,36 @@ child->RecursiveUpdate(dTime); } -void MercuryNode::RecursiveRender() +void MercuryNode::RecursivePreRender() { - MercuryMatrix modelView; - ShaderAttribute sa; + if ( IsHidden() ) return; MercuryMatrix matrix = FindGlobalMatrix(); + MercuryMatrix modelView = ManipulateMatrix( matrix ); + glLoadMatrix( modelView ); + PreRender( matrix ); //calls on children assets - - modelView = ManipulateMatrix( matrix ); + + for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) + child->RecursivePreRender(); +} + +void MercuryNode::RecursiveRender() +{ + if ( IsHidden() || m_occlusionResult.IsOccluded() ) return; + + MercuryMatrix matrix = FindGlobalMatrix(); + MercuryMatrix modelView = ManipulateMatrix( matrix ); // if ( IsHidden() || IsCulled(modelView) ) return; - if ( IsHidden() ) return; glLoadMatrix( modelView ); + ShaderAttribute sa; sa.type = ShaderAttribute::TYPE_MATRIX; sa.value.matrix = matrix.Ptr(); Shader::SetAttribute("HG_ModelMatrix", sa); - + Render( modelView ); //calls on children assets //call render on other render graph entries under me @@ -218,15 +229,9 @@ void MercuryNode::Render(const MercuryMatrix& matrix) { - bool cull; list< MercuryAsset* >::iterator i; for (i = m_render.begin(); i != m_render.end(); ++i ) - { - cull = false; - const BoundingVolume* bv = (*i)->GetBoundingVolume(); - if (bv) cull = bv->FrustumCull(); - if ( !cull ) (*i)->Render(this); - } + (*i)->Render(this); } void MercuryNode::PostRender(const MercuryMatrix& matrix) Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryNode.h 2009-07-05 15:48:11 UTC (rev 408) @@ -9,6 +9,7 @@ #include <MessageHandler.h> #include <MercuryAsset.h> +#include <BoundingBox.h> /** This is the basic node of the scene graph. It is not intended to be instanced. Each node exists as a single entity in the scene graph. @@ -52,6 +53,7 @@ void ThreadedUpdate(float dTime); + void RecursivePreRender(); void RecursiveRender(); ///Run on parent when a child is added @@ -92,7 +94,9 @@ bool IsHidden() { return m_hidden; } virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - + + inline OcclusionResult& GetOcclusionResult() { return m_occlusionResult; } + inline const OcclusionResult& GetOcclusionResult() const { return m_occlusionResult; } protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -106,6 +110,8 @@ private: bool IsInAssetList(MercuryAsset* asset) const; + OcclusionResult m_occlusionResult; + //The asset is actually stored here std::list< MAutoPtr< MercuryAsset > > m_assets; Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryVBO.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -27,19 +27,13 @@ uint8_t numTextures = Texture::NumberActiveTextures(); uint16_t stride = sizeof(float)*8; - if ( m_initiated ) - { - if ( this != m_lastVBOrendered) - { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]); - } - } - else - InitVBO(); + if ( !m_initiated ) InitVBO(); - if ( this != m_lastVBOrendered) + if ( this != m_lastVBOrendered ) { + m_lastVBOrendered = this; + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]); glVertexPointer(3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*5)); ++m_vboBinds; } @@ -57,9 +51,7 @@ glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL); m_vboBatches++; - - m_lastVBOrendered = this; - + if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); if ( SHOWAXISES ) DrawAxes(); } Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/MercuryVBO.h 2009-07-05 15:48:11 UTC (rev 408) @@ -24,12 +24,14 @@ float * GetVertexHandle() { return &m_vertexData[0]; } short unsigned int * GetIndexHandle() { return &m_indexData[0]; } + + static void* m_lastVBOrendered; + private: virtual void InitVBO(); unsigned int m_bufferIDs[2]; bool m_initiated; - static void* m_lastVBOrendered; protected: AlignedBuffer<float> m_vertexData; Modified: Mercury2/src/RenderBuffer.cpp =================================================================== --- Mercury2/src/RenderBuffer.cpp 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/RenderBuffer.cpp 2009-07-05 15:48:11 UTC (rev 408) @@ -24,18 +24,15 @@ RenderableNode* rn = RenderableNode::Cast( node ); if ( rn ) { - rn->AddPreRender( this ); +// rn->AddPreRender( this ); rn->AddPostRender( this ); } } -void RenderBuffer::PreRender(const MercuryNode* node) -{ - if ( !m_initiated ) InitRenderBuffer(); -} - void RenderBuffer::Render(const MercuryNode* node) { + if ( !m_initiated ) InitRenderBuffer(); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_bufferID); if ( NeedResize() ) AllocateSpace(); Modified: Mercury2/src/RenderBuffer.h =================================================================== --- Mercury2/src/RenderBuffer.h 2009-07-05 12:55:17 UTC (rev 407) +++ Mercury2/src/RenderBuffer.h 2009-07-05 15:48:11 UTC (rev 408) @@ -20,7 +20,6 @@ virtual void Init(MercuryNode* node); - virtual void PreRender(const MercuryNode* node); virtual void Render(const MercuryNode* node); virtual void PostRender(const MercuryNode* node); virtual void LoadFromXML(const XMLNode& node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-06 02:39:42
|
Revision: 410 http://hgengine.svn.sourceforge.net/hgengine/?rev=410&view=rev Author: axlecrusher Date: 2009-07-06 02:39:41 +0000 (Mon, 06 Jul 2009) Log Message: ----------- fix broken frustum plane calculations Modified Paths: -------------- Mercury2/src/Frustum.cpp Mercury2/src/Viewport.cpp Modified: Mercury2/src/Frustum.cpp =================================================================== --- Mercury2/src/Frustum.cpp 2009-07-05 21:15:50 UTC (rev 409) +++ Mercury2/src/Frustum.cpp 2009-07-06 02:39:41 UTC (rev 410) @@ -55,37 +55,40 @@ //Right now this only builds the frustum planes MercuryVector X,Y,Z; - Z = (eye - look).Normalize(); //direction behind camera + Z = look * -1; //direction opposite of look X = (up.CrossProduct(Z)).Normalize(); //X axis Y = Z.CrossProduct( X ); //real up - m_nc = (eye - Z) * m_zNear; - m_fc = (eye - Z) * m_zFar; + m_nc = eye - (Z * m_zNear); + m_fc = eye - (Z * m_zFar); - m_planes[PNEAR].Setup(m_nc, Z*(-1)); + //All the normals must face inwards + m_planes[PNEAR].Setup(m_nc, Z*-1); m_planes[PFAR].Setup(m_fc, Z); +// m_planes[PFAR].GetNormal().Print(); // m_fc.Print(); // Z.Print(); MercuryVector aux,normal; aux = (m_nc + Y*m_nh) - eye; aux.NormalizeSelf(); - normal = aux * X; + normal = aux.CrossProduct(X); m_planes[PTOP].Setup(m_nc+Y*m_nh,normal); - + aux = (m_nc - Y*m_nh) - eye; aux.NormalizeSelf(); - normal = X * aux; + normal = X.CrossProduct(aux); m_planes[PBOTTOM].Setup(m_nc-Y*m_nh,normal); aux = (m_nc - X*m_nw) - eye; aux.NormalizeSelf(); - normal = aux * Y; + normal = aux.CrossProduct(Y); m_planes[PLEFT].Setup(m_nc-X*m_nw,normal); aux = (m_nc + X*m_nw) - eye; aux.NormalizeSelf(); - normal = Y * aux; + normal = Y.CrossProduct(aux); + normal.Print(); m_planes[PRIGHT].Setup(m_nc+X*m_nw,normal); } Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-07-05 21:15:50 UTC (rev 409) +++ Mercury2/src/Viewport.cpp 2009-07-06 02:39:41 UTC (rev 410) @@ -33,8 +33,9 @@ VIEWMATRIX = matrix; - MercuryVector z(0,0,1); - LOOKAT = (matrix * z).Normalize(); + //the camera sets this (the calculation here is wrong) +// MercuryVector z(0,0,-1); //look down Z by default +// LOOKAT = (matrix * z).Normalize(); // matrix.Print(); // EYE.Print("Eye"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-06 16:12:54
|
Revision: 411 http://hgengine.svn.sourceforge.net/hgengine/?rev=411&view=rev Author: axlecrusher Date: 2009-07-06 16:12:53 +0000 (Mon, 06 Jul 2009) Log Message: ----------- function to read matrix from opengl Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-07-06 02:39:41 UTC (rev 410) +++ Mercury2/src/GLHelpers.cpp 2009-07-06 16:12:53 UTC (rev 411) @@ -47,6 +47,14 @@ glLoadMatrixf( l.Ptr() ); } +MercuryMatrix glGetMatrix(GLenum m) +{ + MercuryMatrix mm; + glGetFloatv(m, mm.Ptr()); + mm.Transpose(); + return mm; +} + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-07-06 02:39:41 UTC (rev 410) +++ Mercury2/src/GLHelpers.h 2009-07-06 16:12:53 UTC (rev 411) @@ -4,6 +4,7 @@ MString GlError2String(uint32_t e); void glLoadMatrix(const MercuryMatrix& m); +MercuryMatrix glGetMatrix(GLenum m); /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-06 16:18:19
|
Revision: 413 http://hgengine.svn.sourceforge.net/hgengine/?rev=413&view=rev Author: axlecrusher Date: 2009-07-06 16:18:18 +0000 (Mon, 06 Jul 2009) Log Message: ----------- simple bounding box frustum culling is working Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryPlane.cpp Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/BoundingBox.cpp 2009-07-06 16:18:18 UTC (rev 413) @@ -56,37 +56,77 @@ void BoundingBox::ComputeNormals() { - //normals are probably just the cardinal axises -/* MercuryVertex t(m_center, 0); + //these need to be the normals of each face + /* + MercuryVertex t(m_center, 0); t.SetX( t.GetX() + m_extend.GetX() ); - m_normals[0] = t;//.Normalize(); + m_normals[0] = (m_center - t).Normalize(); t = m_center; t.SetY( t.GetY() + m_extend.GetY() ); - m_normals[1] = t;//.Normalize(); + m_normals[1] = (m_center - t).Normalize(); t = m_center; t.SetZ( t.GetZ() + m_extend.GetZ() ); - m_normals[2] = t;//.Normalize(); + m_normals[2] = (m_center - t).Normalize(); + m_normals[0].Print(); */ } void BoundingBox::Transform( const MercuryMatrix& m ) { + //the frustum planes are defined in world space so + //these values need to be transformed into world space BoundingBox bb; - bb.m_extend = m_extend; - MercuryMatrix mm = m * FRUSTUM->GetMatrix(); - bb.m_center = mm * MercuryVertex(m_center, 1); - bb.m_normals[0] = (mm * MercuryVector(1.0f,0,0,0)).Normalize(); - bb.m_normals[1] = (mm * MercuryVector(0,1.0f,0,0)).Normalize(); - bb.m_normals[2] = (mm * MercuryVector(0,0,1.0f,0)).Normalize(); -// bb.Render(); + bb.m_extend = m * m_extend; //Rotate and scale + bb.m_center = m * MercuryVertex(m_center, 1); + + //transform the box axises into world axises + bb.m_normals[0] = (m * MercuryVector(1,0,0)).Normalize(); + bb.m_normals[1] = (m * MercuryVector(0,1,0)).Normalize(); + bb.m_normals[2] = (m * MercuryVector(0,0,1)).Normalize(); + *this = bb; } bool BoundingBox::Clip( const MercuryPlane& p ) { - MercuryVertex dp = p.GetNormal().DotProduct3(m_normals[0], m_normals[1], m_normals[2]); + //do a quick spherical test using the signed distance + float d = p.GetNormal().DotProduct( m_center - p.GetCenter() ); + if (d < -m_extend.Length()) return true; + return false; + + ///XXX everything below is broken + + MercuryVector dp; //plain normal in box space +// dp = p.GetNormal().DotProduct3(m_normals[0],m_normals[2],m_normals[3]); + dp[0] = m_normals[0].DotProduct( p.GetNormal() ); + dp[1] = m_normals[1].DotProduct( p.GetNormal() ); + dp[2] = m_normals[2].DotProduct( p.GetNormal() ); + dp.NormalizeSelf(); +// dp = p.GetNormal(); + + MercuryVertex P; //max + if (dp[0] >= 0) P[0] = m_center.GetX() + m_extend.GetX(); + if (dp[1] >= 0) P[1] = m_center.GetY() + m_extend.GetY(); + if (dp[2] >= 0) P[2] = m_center.GetZ() + m_extend.GetZ(); + + MercuryVertex N; //min + if (dp[0] >= 0) N[0] = m_center.GetX() - m_extend.GetX(); + if (dp[1] >= 0) N[1] = m_center.GetY() - m_extend.GetY(); + if (dp[2] >= 0) N[2] = m_center.GetZ() - m_extend.GetZ(); + + float x = dp.DotProduct( P ); + float y = dp.DotProduct( N ); +// printf("p %f n %f\n", x, y); + if ( x < 0) + return true; //max value outside + if ( y < 0) //is negative value outside + return false; //intersect + + return false; +/* + db * m_extend; float x = ABS( m_extend.GetX() * dp[0] ); x += ABS( m_extend.GetY() * dp[1] ); x += ABS( m_extend.GetZ() * dp[2] ); @@ -96,17 +136,22 @@ return false; return BEHIND_PLANE(d); //if we don't intersect, just see what side we are on + */ } bool BoundingBox::Clip( const Frustum& f ) { - bool inView = true; - for (uint8_t i = 0; (i < 6) && inView; ++i) + bool clipped = false; + for (uint8_t i = 0; (i < 6) && !clipped; ++i) { - inView = Clip( f.GetPlane(i) )?false:inView; + bool t = Clip( f.GetPlane(i) ); +// printf("p%d %d\n", i, t); + clipped = t; } +// printf("******\n"); +// return false; - return !inView; + return clipped; } //bool BoundingBox::FrustumCull() const @@ -166,8 +211,10 @@ bool BoundingBox::DoFrustumTest( const MercuryMatrix& m ) { BoundingBox bb(*this); +// bb.Render(); bb.Transform( m ); - return false; +// bb.Render(); + return bb.Clip( *FRUSTUM ); } void BoundingBox::DoOcclusionTest( OcclusionResult& result ) @@ -218,7 +265,7 @@ const float* center = GetCenter(); const float* extend = GetExtend(); -// glPushMatrix(); + glPushMatrix(); // glLoadIdentity(); glPushAttrib( GL_CURRENT_BIT ); glBegin(GL_LINES); @@ -258,34 +305,45 @@ glEnd(); - //center glPointSize(4); glBegin(GL_POINTS); + //center glVertex3f(center[0], center[1], center[2]); + //max point + glColor3f(1,1,0); + glVertex3f(center[0]+extend[0], center[1]+extend[1], center[2]+extend[2]); + //min point +// glColor3f(1,0,0); + glVertex3f(center[0]-extend[0], center[1]-extend[1], center[2]-extend[2]); glEnd(); + //normals MercuryVertex c; glBegin(GL_LINES); + glColor3f(1.0f,0,0); glVertex3f(center[0], center[1], center[2]); c = center; c += m_normals[0]; glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glColor3f(0,1.0f,0); glVertex3f(center[0], center[1], center[2]); c = center; c += m_normals[1]; glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glColor3f(0,0,1.0f); glVertex3f(center[0], center[1], center[2]); c = center; c += m_normals[2]; glVertex3f(c.GetX(), c.GetY(), c.GetZ()); + glEnd(); glPopAttrib( ); -// glPopMatrix(); + glPopMatrix(); } void BoundingBox::PopulateVertices() Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/HGMDLModel.cpp 2009-07-06 16:18:18 UTC (rev 413) @@ -58,6 +58,13 @@ } } +void HGMDLModel::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +{ + if ( GetLoadState() != LOADING ) + for(uint16_t i = 0; i < m_meshes.size(); ++i) + m_meshes[i]->DoCullingTests(n, matrix); +} + void HGMDLModel::PreRender(const MercuryNode* node) { if ( GetLoadState() != LOADING ) Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/HGMDLModel.h 2009-07-06 16:18:18 UTC (rev 413) @@ -19,6 +19,7 @@ static HGMDLModel* Generate(); + virtual void DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); virtual void PreRender(const MercuryNode* node); virtual void Render(const MercuryNode* node); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/MercuryAsset.cpp 2009-07-06 16:18:18 UTC (rev 413) @@ -37,8 +37,19 @@ SetLoadState( LOADED ); } +void MercuryAsset::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +{ + if ( m_boundingVolume ) + { + n->SetCulled( m_boundingVolume->DoFrustumTest(matrix) ); + if ( !n->IsCulled() ) + m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); + } +} + void MercuryAsset::PreRender(const MercuryNode* node) { + /* MercuryNode* n = const_cast<MercuryNode*>(node); if ( m_boundingVolume ) { @@ -46,6 +57,7 @@ if ( !n->IsCulled() ) m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); } + */ } void MercuryAsset::DrawAxes() Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/MercuryAsset.h 2009-07-06 16:18:18 UTC (rev 413) @@ -51,6 +51,7 @@ inline BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } inline const MString& Path() const { return m_path; } + virtual void DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); void DrawAxes(); protected: void SetLoadState(LoadState ls); //thread safe Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/MercuryNode.cpp 2009-07-06 16:18:18 UTC (rev 413) @@ -224,7 +224,10 @@ { list< MercuryAsset* >::iterator i; for (i = m_prerender.begin(); i != m_prerender.end(); ++i ) + { + (*i)->DoCullingTests( this, matrix ); (*i)->PreRender(this); + } } void MercuryNode::Render(const MercuryMatrix& matrix) Modified: Mercury2/src/MercuryPlane.cpp =================================================================== --- Mercury2/src/MercuryPlane.cpp 2009-07-06 16:14:59 UTC (rev 412) +++ Mercury2/src/MercuryPlane.cpp 2009-07-06 16:18:18 UTC (rev 413) @@ -2,14 +2,10 @@ #include <stdio.h> #include <MercuryMath.h> -#define SIGNED_DIST(x) m_normal.DotProduct(x) - -// origional algorithim was -x<0 -#define BEHIND_PLANE(x) x>=0 - bool MercuryPlane::IsBehindPlane(const MercuryVertex& point) const { - return BEHIND_PLANE( SIGNED_DIST( point+m_center ) ); + //signed distance between the plane and the point + return m_normal.DotProduct( point - m_center ) < 0; } /**************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-06 21:08:25
|
Revision: 414 http://hgengine.svn.sourceforge.net/hgengine/?rev=414&view=rev Author: axlecrusher Date: 2009-07-06 21:08:22 +0000 (Mon, 06 Jul 2009) Log Message: ----------- finish bounding box frustum cull Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-07-06 16:18:18 UTC (rev 413) +++ Mercury2/src/BoundingBox.cpp 2009-07-06 21:08:22 UTC (rev 414) @@ -86,140 +86,61 @@ bb.m_normals[1] = (m * MercuryVector(0,1,0)).Normalize(); bb.m_normals[2] = (m * MercuryVector(0,0,1)).Normalize(); + //compute box vertices into world coordinates + //it would be nice to do this without needing to save + //the result in the bounding box. + //XXX look into ways to optimize this + MercuryMatrix mm = m; + mm.Translate( m_center ); + mm.Scale( m_extend ); + + bb.v[0] = mm * MercuryVertex(-1, 1, 1, 1); + bb.v[1] = mm * MercuryVertex(-1, -1, 1, 1); + bb.v[2] = mm * MercuryVertex(1, -1, 1, 1); + bb.v[3] = mm * MercuryVertex(1, 1, 1, 1); + + bb.v[4] = mm * MercuryVertex(-1, 1, -1, 1); + bb.v[5] = mm * MercuryVertex(-1, -1, -1, 1); + bb.v[6] = mm * MercuryVertex(1, -1, -1, 1); + bb.v[7] = mm * MercuryVertex(1, 1, -1, 1); + *this = bb; } bool BoundingBox::Clip( const MercuryPlane& p ) { //do a quick spherical test using the signed distance + //from the center of the box float d = p.GetNormal().DotProduct( m_center - p.GetCenter() ); - if (d < -m_extend.Length()) return true; - return false; + if (d < -m_extend.Length()) return true; //sphere is further than radius distance behind plane - ///XXX everything below is broken + //all points must be behind a plane to be considered clipped + bool clip = true; + for (uint8_t i = 0; (i < 8) && clip; ++i) + clip = p.IsBehindPlane( v[i] ); - MercuryVector dp; //plain normal in box space -// dp = p.GetNormal().DotProduct3(m_normals[0],m_normals[2],m_normals[3]); - dp[0] = m_normals[0].DotProduct( p.GetNormal() ); - dp[1] = m_normals[1].DotProduct( p.GetNormal() ); - dp[2] = m_normals[2].DotProduct( p.GetNormal() ); - dp.NormalizeSelf(); -// dp = p.GetNormal(); - - MercuryVertex P; //max - if (dp[0] >= 0) P[0] = m_center.GetX() + m_extend.GetX(); - if (dp[1] >= 0) P[1] = m_center.GetY() + m_extend.GetY(); - if (dp[2] >= 0) P[2] = m_center.GetZ() + m_extend.GetZ(); - - MercuryVertex N; //min - if (dp[0] >= 0) N[0] = m_center.GetX() - m_extend.GetX(); - if (dp[1] >= 0) N[1] = m_center.GetY() - m_extend.GetY(); - if (dp[2] >= 0) N[2] = m_center.GetZ() - m_extend.GetZ(); - - float x = dp.DotProduct( P ); - float y = dp.DotProduct( N ); -// printf("p %f n %f\n", x, y); - if ( x < 0) - return true; //max value outside - if ( y < 0) //is negative value outside - return false; //intersect - - return false; -/* - db * m_extend; - float x = ABS( m_extend.GetX() * dp[0] ); - x += ABS( m_extend.GetY() * dp[1] ); - x += ABS( m_extend.GetZ() * dp[2] ); - - float d = p.GetNormal().DotProduct( m_center+p.GetCenter() ); //signed distance - if ( ABS(d) <= x ) //intersection - return false; - - return BEHIND_PLANE(d); //if we don't intersect, just see what side we are on - */ + return clip; } bool BoundingBox::Clip( const Frustum& f ) { bool clipped = false; for (uint8_t i = 0; (i < 6) && !clipped; ++i) - { - bool t = Clip( f.GetPlane(i) ); -// printf("p%d %d\n", i, t); - clipped = t; - } -// printf("******\n"); -// return false; + clipped = Clip( f.GetPlane(i) ); return clipped; } -//bool BoundingBox::FrustumCull() const -//{ - /*feedback in openGL is probably depreciated - and is known to fallback to software - the OcclusionTest provides the same performence - it is probably best to avoid using this function */ -/* - static float b[3]; - uint32_t samples; - const float* center = GetCenter(); - const float* extend = GetExtend(); - - glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); - glDisable(GL_CULL_FACE); - - glPushMatrix(); - glTranslatef(center[0], center[1], center[2]); - glScalef(extend[0],extend[1],extend[2]); - - uint8_t tCount = Texture::NumberActiveTextures(); - for (uint8_t i = 0; i < tCount; ++i) - { - glActiveTexture( GL_TEXTURE0+i ); - glClientActiveTextureARB( GL_TEXTURE0+i ); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable( GL_TEXTURE_2D ); - } - glFeedbackBuffer(3, GL_3D, b); - glRenderMode( GL_FEEDBACK ); - - InitVBO(); - - glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - glVertexPointer(3, GL_FLOAT, 0, 0); - glDrawArrays(GL_QUADS, 0, 24); - - for (uint8_t i = 0; i < tCount; ++i) - { - glActiveTexture( GL_TEXTURE0+i ); - glClientActiveTextureARB(GL_TEXTURE0+i); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable( GL_TEXTURE_2D ); - } - - samples = glRenderMode( GL_RENDER ); - glPopMatrix(); - glPopAttrib( ); - -// return false; - return samples==0; -} -*/ - bool BoundingBox::DoFrustumTest( const MercuryMatrix& m ) { BoundingBox bb(*this); // bb.Render(); bb.Transform( m ); -// bb.Render(); return bb.Clip( *FRUSTUM ); } void BoundingBox::DoOcclusionTest( OcclusionResult& result ) { - return; const float* center = GetCenter(); const float* extend = GetExtend(); Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-07-06 16:18:18 UTC (rev 413) +++ Mercury2/src/BoundingBox.h 2009-07-06 21:08:22 UTC (rev 414) @@ -99,6 +99,7 @@ static AlignedBuffer<float> m_vertexData; static uint32_t m_vboID; + MercuryVertex v[8]; }; #endif Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-07-06 16:18:18 UTC (rev 413) +++ Mercury2/src/Mercury2.cpp 2009-07-06 21:08:22 UTC (rev 414) @@ -20,6 +20,7 @@ #include <MercuryFile.h> bool SHOWBOUNDINGVOLUME = false; bool SHOWAXISES = false; +bool DOOCCLUSIONCULL = false; MSemaphore UpdateLoopGo; void* UpdateThread(void* node) Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-07-06 16:18:18 UTC (rev 413) +++ Mercury2/src/MercuryAsset.cpp 2009-07-06 21:08:22 UTC (rev 414) @@ -3,6 +3,8 @@ #include <MercuryNode.h> #include <GLHeaders.h> +extern bool DOOCCLUSIONCULL; + MercuryAsset::MercuryAsset() :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE) { @@ -42,7 +44,7 @@ if ( m_boundingVolume ) { n->SetCulled( m_boundingVolume->DoFrustumTest(matrix) ); - if ( !n->IsCulled() ) + if ( !n->IsCulled() && DOOCCLUSIONCULL) m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-07-08 05:27:15
|
Revision: 416 http://hgengine.svn.sourceforge.net/hgengine/?rev=416&view=rev Author: cnlohr Date: 2009-07-08 05:27:14 +0000 (Wed, 08 Jul 2009) Log Message: ----------- remove need for freeglut on Linux, and enable compilation and running on systems missing the not-universal glProgramParameteriEXT function. Modified Paths: -------------- Mercury2/src/GLHeaders.h Mercury2/src/Shader.cpp Modified: Mercury2/src/GLHeaders.h =================================================================== --- Mercury2/src/GLHeaders.h 2009-07-08 05:25:47 UTC (rev 415) +++ Mercury2/src/GLHeaders.h 2009-07-08 05:27:14 UTC (rev 416) @@ -15,7 +15,7 @@ #include <OGLExtensions.h> #else #include <GL/glext.h> -#include <GL/freeglut.h> +#include <GL/glu.h> #endif #include <GLHelpers.h> @@ -34,4 +34,4 @@ assert(0); } } -#endif \ No newline at end of file +#endif Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-07-08 05:25:47 UTC (rev 415) +++ Mercury2/src/Shader.cpp 2009-07-08 05:27:14 UTC (rev 416) @@ -5,12 +5,20 @@ #include <GLHeaders.h> #include <string.h> +//Because we need to dynamically check for glProgramParameteriEXT, even in Linux. +#include <GL/glx.h> + using namespace std; REGISTER_ASSET_TYPE( Shader ); Shader * Shader::CurrentShader = NULL; +//On many GL Implementations, this is super wonky. +//It may not even exist at all, so we make it optional. +bool IsCustomGLProgramParISet = false; +PFNGLPROGRAMPARAMETERIEXTPROC CustomGLProgramParI; + ShaderAttribute * ShaderAttributesSet::GetHandle( const MString & sName ) { ShaderAttribute * ret = m_AllShaderAttributes[sName]; @@ -31,6 +39,16 @@ iTimeCode[0] = 0; iTimeCode[1] = 0; iTimeCode[2] = 0; + +#ifdef WIN32 + CustomGLProgramParI = glProgramParameteriEXT; +#else + if( !IsCustomGLProgramParISet ) + { + CustomGLProgramParI = (PFNGLPROGRAMPARAMETERIEXTPROC)glXGetProcAddress( (GLubyte*)"glProgramParameteriEXT" ); + IsCustomGLProgramParISet = true; + } +#endif } Shader::~Shader() @@ -272,10 +290,10 @@ glLinkProgramARB( iProgramID ); //If we're using a geometry shader, we have to do a little extra. - if( geometryShader ) + if( CustomGLProgramParI && geometryShader ) { - glProgramParameteriEXT( iProgramID, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES ); - glProgramParameteriEXT( iProgramID, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP ); + CustomGLProgramParI( iProgramID, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES ); + CustomGLProgramParI( iProgramID, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP ); int ierror, i; GLint imaxvert; @@ -288,7 +306,7 @@ } for( i = 1; i < imaxvert; i++ ) { - glProgramParameteriEXT(iProgramID,GL_GEOMETRY_VERTICES_OUT_EXT,imaxvert/i); + CustomGLProgramParI(iProgramID,GL_GEOMETRY_VERTICES_OUT_EXT,imaxvert/i); if( glGetError() == 0 ) break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-07-13 05:33:33
|
Revision: 421 http://hgengine.svn.sourceforge.net/hgengine/?rev=421&view=rev Author: cnlohr Date: 2009-07-13 05:33:28 +0000 (Mon, 13 Jul 2009) Log Message: ----------- enable/disable mouse grabbing. This is nonintuitive at first, as HG1 only enabled grabbed input, however many non-FPS games (Even some 3rd person games) do not grab the mouse. This enables users to intuitively use their mouse at their own will for these games. Modified Paths: -------------- Mercury2/src/MercuryWindow.cpp Mercury2/src/MercuryWindow.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryWindow.cpp =================================================================== --- Mercury2/src/MercuryWindow.cpp 2009-07-10 03:36:11 UTC (rev 420) +++ Mercury2/src/MercuryWindow.cpp 2009-07-13 05:33:28 UTC (rev 421) @@ -1,7 +1,8 @@ #include "MercuryWindow.h" MercuryWindow::MercuryWindow(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) - :m_title(title), m_width(width), m_height(height), m_bits(bits), m_depthBits(depthBits), m_fullscreen(fullscreen) + :m_title(title), m_width(width), m_height(height), m_bits(bits), m_depthBits(depthBits), m_fullscreen(fullscreen), + m_bGrabbed(true) { } Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2009-07-10 03:36:11 UTC (rev 420) +++ Mercury2/src/MercuryWindow.h 2009-07-13 05:33:28 UTC (rev 421) @@ -32,10 +32,13 @@ inline int Width() const { return m_width; } inline int Height() const { return m_height; } + void SetGrabbedMouseMode( bool bGrabbed ) { m_bGrabbed = bGrabbed; } + bool GetGrabbedMouseMode( ) { return m_bGrabbed; } protected: static Callback0R< MercuryWindow* > genWindowClbk; static MercuryWindow* m_windowInstance; + bool m_bGrabbed; MString m_title; int m_width, m_height; uint8_t m_bits, m_depthBits; Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-07-10 03:36:11 UTC (rev 420) +++ Mercury2/src/X11Window.cpp 2009-07-13 05:33:28 UTC (rev 421) @@ -223,7 +223,7 @@ { XFocusChangeEvent*e = (XFocusChangeEvent*)&event; inFocus = (event.type == FocusIn); - if (inFocus) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + if (inFocus && m_bGrabbed ) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); break; } } @@ -263,14 +263,20 @@ left = e->state & Button1Mask; right = e->state & Button3Mask; center = e->state & Button2Mask; - x = m_width/2 - e->x; - y = m_height/2 - e->y; - if (x!=0 || y!=0) //prevent recursive XWarp + if( m_bGrabbed ) { - MouseInput::ProcessMouseInput(x, y, - left, right, center); - XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + x = m_width/2 - e->x; + y = m_height/2 - e->y; + if (x!=0 || y!=0) //prevent recursive XWarp + { + MouseInput::ProcessMouseInput(x, y, left, right, center); + XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + } } + else + { + MouseInput::ProcessMouseInput(e->x, e->y, left, right, center); + } break; } default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wil...@us...> - 2009-07-15 02:36:55
|
Revision: 423 http://hgengine.svn.sourceforge.net/hgengine/?rev=423&view=rev Author: willmurnane Date: 2009-07-15 02:36:45 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Use int instead of GLenum to avoid needing gl.h et al #included Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-07-15 01:59:15 UTC (rev 422) +++ Mercury2/src/GLHelpers.cpp 2009-07-15 02:36:45 UTC (rev 423) @@ -55,6 +55,29 @@ return mm; } +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y) +{ + GLfloat winX, winY, winZ; + GLdouble mouseX = 0, mouseY = 0, mouseZ = 0; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + + glGetIntegerv(GL_VIEWPORT, viewport); + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + glGetDoublev(GL_PROJECTION_MATRIX, projection); + + winX = (float)screen_x; + winY = (float)viewport[3] - (float)screen_y; + glReadPixels( screen_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); + + gluUnProject( + winX, winY, winZ, + modelview, projection, viewport, + &mouseX, &mouseY, &mouseZ); + return MercuryVertex( mouseX, mouseY, mouseZ ); +} + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-07-15 01:59:15 UTC (rev 422) +++ Mercury2/src/GLHelpers.h 2009-07-15 02:36:45 UTC (rev 423) @@ -4,7 +4,7 @@ MString GlError2String(uint32_t e); void glLoadMatrix(const MercuryMatrix& m); -MercuryMatrix glGetMatrix(GLenum m); +MercuryMatrix glGetMatrix(int m); /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wil...@us...> - 2009-07-15 04:23:25
|
Revision: 425 http://hgengine.svn.sourceforge.net/hgengine/?rev=425&view=rev Author: willmurnane Date: 2009-07-15 04:23:04 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Improved (?) X11 mouse handling: scroll wheel, buttons-by-name, stuff Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/MercuryInput.cpp 2009-07-15 04:23:04 UTC (rev 425) @@ -2,24 +2,25 @@ #include <MercuryMessageManager.h> MouseInput::MouseInput() - :MessageData(), dx(0), dy(0), buttonMasks(0) + :MessageData(), dx(0), dy(0) { + buttons.data = 0; } -void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton) +void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton, bool scrollUpButton, bool scrollDownButton) { MouseInput* mi = new MouseInput(); mi->dx = dx; mi->dy = dy; + buttonMask buttons = {0}; + buttons.left = leftButton; + buttons.right = rightButton; + buttons.center = centerButton; + buttons.scrollup = scrollUpButton; + buttons.scrolldown = scrollDownButton; + mi->buttons = buttons; + currentButtonMasks = buttons; - uint8_t buttonMasks = 0; - buttonMasks |= (leftButton << MOUSE_LEFT); //enable if true - buttonMasks |= (rightButton << MOUSE_RIGHT); //enable if true - buttonMasks |= (centerButton << MOUSE_CENTER); //enable if true - mi->buttonMasks = buttonMasks; - - currentButtonMasks = buttonMasks; - POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 ); } @@ -65,7 +66,7 @@ uint8_t KeyboardInput::m_keyStates[512]; -uint8_t MouseInput::currentButtonMasks; +MouseInput::buttonMask MouseInput::currentButtonMasks; /**************************************************************************** Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/MercuryInput.h 2009-07-15 04:23:04 UTC (rev 425) @@ -10,22 +10,25 @@ class MouseInput : public MessageData { public: - static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton); + typedef union + { + uint8_t data; + struct { + unsigned int left: 1; + unsigned int right: 1; + unsigned int center: 1; + unsigned int scrollup: 1; + unsigned int scrolldown: 1; + }; + } buttonMask; + static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton, bool scrollUpButton, bool scrollDownButton); MouseInput(); int32_t dx, dy; - uint8_t buttonMasks; + buttonMask buttons; - enum MouseButton - { - MOUSE_NONE = 0, - MOUSE_LEFT = 1, - MOUSE_RIGHT = 2, - MOUSE_CENTER = 3 - }; - private: - static uint8_t currentButtonMasks; + static buttonMask currentButtonMasks; }; class KeyboardInput : public MessageData Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/X11Window.cpp 2009-07-15 04:23:04 UTC (rev 425) @@ -3,6 +3,18 @@ #include <MercuryInput.h> #include <MercuryPrefs.h> +#define MOUSE_BTN_LEFT 1 +#define MOUSE_BTN_RIGHT 3 +#define MOUSE_BTN_CENTER 2 +#define MOUSE_BTN_SCROLL_UP 4 +#define MOUSE_BTN_SCROLL_DOWN 5 + +// Use X11_MASK(MOUSE_BTN_SCROLL_UP) to generate the token Button4Mask +#define X11_MASK(x) _X11_MASK(x) +// Sigh... second #define needed, because otherwise x doesn't get evaluated. +// That is, instead of giving you Button4Mask this would give ButtonMOUSE_BTN_SCROLL_UPMask +#define _X11_MASK(x) Button##x##Mask + Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(X11Window::GenX11Window); //Register window generation callback //XXX: THIS SECTION IS INCOMPLETE! IT NEEDS The right half of the keyboard (Bar arrow keys) + it needs the windows keys/sel keys mapped @@ -236,7 +248,19 @@ case ButtonRelease: { XButtonEvent* e = (XButtonEvent*)&event; - MouseInput::ProcessMouseInput(0, 0, e->button & Button1, e->button & Button3, e->button & Button2); + uint8_t left, right, center, su, sd; + left = (e->state & X11_MASK(MOUSE_BTN_LEFT)) ^ (e->button == MOUSE_BTN_LEFT); + right = (e->state & X11_MASK(MOUSE_BTN_RIGHT)) ^ (e->button == MOUSE_BTN_RIGHT); + center = (e->state & X11_MASK(MOUSE_BTN_CENTER)) ^ (e->button == MOUSE_BTN_CENTER); + su = (e->state & X11_MASK(MOUSE_BTN_SCROLL_UP)) ^ (e->button == MOUSE_BTN_SCROLL_UP); + sd = (e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN)) ^ (e->button == MOUSE_BTN_SCROLL_DOWN); + + MouseInput::ProcessMouseInput(0, 0, + e->state & X11_MASK(MOUSE_BTN_LEFT), + e->state & X11_MASK(MOUSE_BTN_RIGHT), + e->state & X11_MASK(MOUSE_BTN_CENTER), + e->state & X11_MASK(MOUSE_BTN_SCROLL_UP), + e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN)); break; } case KeyPress: @@ -257,25 +281,28 @@ } case MotionNotify: { + XMotionEvent* e = (XMotionEvent*)&event; int x, y; - bool left, right, center; - left = e->state & Button1Mask; - right = e->state & Button3Mask; - center = e->state & Button2Mask; + bool left, right, center, su, sd; + left = e->state & X11_MASK(MOUSE_BTN_LEFT); + right = e->state & X11_MASK(MOUSE_BTN_RIGHT); + center = e->state & X11_MASK(MOUSE_BTN_CENTER); + su = e->state & X11_MASK(MOUSE_BTN_SCROLL_UP); + sd = e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN); if( m_bGrabbed ) { x = m_width/2 - e->x; y = m_height/2 - e->y; if (x!=0 || y!=0) //prevent recursive XWarp { - MouseInput::ProcessMouseInput(x, y, left, right, center); + MouseInput::ProcessMouseInput(x, y, left, right, center, su, sd); XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); } } else { - MouseInput::ProcessMouseInput(e->x, e->y, left, right, center); + MouseInput::ProcessMouseInput(e->x, e->y, left, right, center, su, sd); } break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-07-15 14:33:27
|
Revision: 428 http://hgengine.svn.sourceforge.net/hgengine/?rev=428&view=rev Author: cnlohr Date: 2009-07-15 14:33:24 +0000 (Wed, 15 Jul 2009) Log Message: ----------- remove mercury point as per Josh's request... I don't really know what it was doing here, anyway. Removed Paths: ------------- Mercury2/src/MercuryPoint.cpp Mercury2/src/MercuryPoint.h Deleted: Mercury2/src/MercuryPoint.cpp =================================================================== --- Mercury2/src/MercuryPoint.cpp 2009-07-15 05:56:24 UTC (rev 427) +++ Mercury2/src/MercuryPoint.cpp 2009-07-15 14:33:24 UTC (rev 428) @@ -1,115 +0,0 @@ -#include <MercuryPoint.h> -#include <MercuryMath.h> - -const float MercuryPoint::operator[] ( const int rhs ) const -{ - switch (rhs) - { - case 0: return x; - case 1: return y; - case 2: return z; - } - return x; //haha we won't even get here. -} - -float & MercuryPoint::operator [] ( const int rhs ) -{ - switch (rhs) - { - case 0: return x; - case 1: return y; - case 2: return z; - } - return x; //haha we won't even get here. -} - -MercuryPoint MercuryPoint::operator*(const MercuryPoint& p) const -{ - MercuryPoint tmp; - tmp.x = x * p.x; - tmp.y = y * p.y; - tmp.z = z * p.z; - return tmp; -} - -MercuryPoint MercuryPoint::operator/(const MercuryPoint& p) const -{ - MercuryPoint tmp; - tmp.x = x / p.x; - tmp.y = y / p.y; - tmp.z = z / p.z; - return tmp; -} - -bool MercuryPoint::operator==(const MercuryPoint& p) const -{ - if ((x == p.x) && (y == p.y) && (z == p.z)) - return true; - - return false; -} - -bool MercuryPoint::operator==(const float f) const -{ - if ((x == f) && (y == f) && (z == f)) - return true; - - return false; -} - -MercuryPoint MercuryPoint::CrossProduct(const MercuryPoint& p) const -{ - MercuryPoint ret; - - ret[0] = y*p.z - z*p.y; - ret[1] = z*p.x - x*p.z; - ret[2] = x*p.y - y*p.x; - - return ret; -} - -void MercuryPoint::NormalizeSelf() -{ - float imag = 1.0f/Magnitude(); - x *= imag; y *= imag; z *= imag; -} - -const MercuryPoint MercuryPoint::Normalize() const -{ - MercuryPoint t(*this); - t.NormalizeSelf(); - return t; -} - -float MercuryPoint::Magnitude() const -{ - float length = 0; - length += x*x; - length += y*y; - length += z*z; - return SQRT(length); -} - -/*************************************************************************** - * Copyright (C) 2008 by Joshua Allen, Charles Lohr * - * * - * * - * All rights reserved. * - * * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * - * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ Deleted: Mercury2/src/MercuryPoint.h =================================================================== --- Mercury2/src/MercuryPoint.h 2009-07-15 05:56:24 UTC (rev 427) +++ Mercury2/src/MercuryPoint.h 2009-07-15 14:33:24 UTC (rev 428) @@ -1,107 +0,0 @@ -#ifndef MERCURYPOINT_H -#define MERCURYPOINT_H - -///A point in space/vector -class MercuryPoint -{ - public: - MercuryPoint() : x(0), y(0), z(0) { }; - MercuryPoint( float ix, float iy, float iz ) : x(ix), y(iy), z(iz) { }; - MercuryPoint( const float * in ) : x(in[0]), y(in[1]), z(in[2]) { }; - - ///Direct conversion to float* - operator float* () { return &x; } - ///Direct conversion to const float* - operator const float* () const { return &x; } - - ///Get X value - inline const float GetX() const { return x; } - ///Get Y value - inline const float GetY() const { return y; } - ///Get Z value - inline const float GetZ() const { return z; } - ///Set X value - inline bool SetX(const float ix) { if (ix == x) { return false; } x = ix; return true; } - ///Set Y value - inline bool SetY(const float iy) { if (iy == y) { return false; } y = iy; return true; } - ///Set Z value - inline bool SetZ(const float iz) { if (iz == z) { return false; } z = iz; return true; } - ///Zero the vector - inline void Clear() { x = 0; y = 0; z = 0; } - - //allow [] to access - float & operator[] ( const int rhs ); - const float operator[] ( const int rhs ) const; - - ///Normalize (make |point| = 1) - void NormalizeSelf(); - ///Return a normalized point - const MercuryPoint Normalize() const; - ///Return the magnitude of |this| - float Magnitude() const; - - float GetBiggestElement() const { if( x > y ) return (x>z)?x:z; else return (y>z)?y:z; } - - ///Write out to be = to this point - inline void ConvertToVector3( float* out ) const { out[0] = x; out[1] = y; out[2] = z; } - ///Write out to be = to this point, however the 4th element will be 0 - inline void ConvertToVector4( float* out ) const { out[0] = x; out[1] = y; out[2] = z; out[3] = 0; } - ///Write out to be = - to this point, however the 4th element will be 0 - inline void ConvertToIVector4( float* out ) const { out[0] = -x; out[1] = -y; out[2] = -z; out[3] = 0; } - - ///Component-wise multiply - MercuryPoint operator*(const MercuryPoint& p) const; - ///Component-wise divide - MercuryPoint operator/(const MercuryPoint& p) const; - - inline MercuryPoint& operator += ( const MercuryPoint& other ) { x+=other.x; y+=other.y; z+=other.z; return *this; } - inline MercuryPoint& operator -= ( const MercuryPoint& other ) { x-=other.x; y-=other.y; z-=other.z; return *this; } - inline MercuryPoint& operator *= ( float f ) { x*=f; y*=f; z*=f; return *this; } - inline MercuryPoint& operator /= ( float f ) { x/=f; y/=f; z/=f; return *this; } - - inline MercuryPoint operator + ( const MercuryPoint& other ) const { return MercuryPoint( x+other.x, y+other.y, z+other.z ); } - inline MercuryPoint operator - ( const MercuryPoint& other ) const { return MercuryPoint( x-other.x, y-other.y, z-other.z ); } - inline MercuryPoint operator * ( float f ) const { return MercuryPoint( x*f, y*f, z*f ); } - inline MercuryPoint operator / ( float f ) const { return MercuryPoint( x/f, y/f, z/f ); } - - friend MercuryPoint operator * ( float f, const MercuryPoint& other ) { return other*f; } - - bool operator==(const MercuryPoint& p) const; - inline bool operator!=(const MercuryPoint& p) const { return !(*this == p); } - - bool operator==(const float f) const; - inline bool operator!=(const float f) const { return !(*this == f); } - - ///Obtain the cross product (*this) x p - MercuryPoint CrossProduct(const MercuryPoint& p) const; - - float x; - float y; - float z; -}; - -#endif - -/*************************************************************************** - * Copyright (C) 2008 by Joshua Allen, Charles Lohr * - * * - * * - * All rights reserved. * - * * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * - * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - ***************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |