From ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Thu, 30 Apr 2009 13:04:20 -0500 Subject: Second Life viewer sources 1.23.0-RC --- linden/indra/llwindow/lldxhardware.cpp | 3 +- linden/indra/llwindow/lldxhardware.h | 3 +- linden/indra/llwindow/llkeyboard.cpp | 3 +- linden/indra/llwindow/llkeyboard.h | 3 +- linden/indra/llwindow/llkeyboardmacosx.cpp | 3 +- linden/indra/llwindow/llkeyboardmacosx.h | 3 +- linden/indra/llwindow/llkeyboardsdl.cpp | 3 +- linden/indra/llwindow/llkeyboardsdl.h | 3 +- linden/indra/llwindow/llkeyboardwin32.cpp | 3 +- linden/indra/llwindow/llkeyboardwin32.h | 3 +- linden/indra/llwindow/llmousehandler.h | 3 +- linden/indra/llwindow/llpreeditor.h | 3 +- linden/indra/llwindow/llwindow.cpp | 13 +- linden/indra/llwindow/llwindow.h | 48 +- linden/indra/llwindow/llwindowheadless.cpp | 3 +- linden/indra/llwindow/llwindowheadless.h | 3 +- linden/indra/llwindow/llwindowmacosx-objc.h | 3 +- linden/indra/llwindow/llwindowmacosx-objc.mm | 3 +- linden/indra/llwindow/llwindowmacosx.cpp | 14 +- linden/indra/llwindow/llwindowmacosx.h | 5 +- linden/indra/llwindow/llwindowmesaheadless.cpp | 3 +- linden/indra/llwindow/llwindowmesaheadless.h | 3 +- linden/indra/llwindow/llwindowsdl.cpp | 767 ++++++------------------- linden/indra/llwindow/llwindowsdl.h | 17 +- linden/indra/llwindow/llwindowwin32.cpp | 60 +- linden/indra/llwindow/llwindowwin32.h | 5 +- 26 files changed, 272 insertions(+), 711 deletions(-) (limited to 'linden/indra/llwindow') diff --git a/linden/indra/llwindow/lldxhardware.cpp b/linden/indra/llwindow/lldxhardware.cpp index deb7901..beab131 100644 --- a/linden/indra/llwindow/lldxhardware.cpp +++ b/linden/indra/llwindow/lldxhardware.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/lldxhardware.h b/linden/indra/llwindow/lldxhardware.h index 449a06f..0ce218b 100644 --- a/linden/indra/llwindow/lldxhardware.h +++ b/linden/indra/llwindow/lldxhardware.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboard.cpp b/linden/indra/llwindow/llkeyboard.cpp index 16c89ca..02b4ed1 100644 --- a/linden/indra/llwindow/llkeyboard.cpp +++ b/linden/indra/llwindow/llkeyboard.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboard.h b/linden/indra/llwindow/llkeyboard.h index 4556dfd..0261bcb 100644 --- a/linden/indra/llwindow/llkeyboard.h +++ b/linden/indra/llwindow/llkeyboard.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardmacosx.cpp b/linden/indra/llwindow/llkeyboardmacosx.cpp index 4038f17..ec82032 100644 --- a/linden/indra/llwindow/llkeyboardmacosx.cpp +++ b/linden/indra/llwindow/llkeyboardmacosx.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardmacosx.h b/linden/indra/llwindow/llkeyboardmacosx.h index 8cde53b..47159af 100644 --- a/linden/indra/llwindow/llkeyboardmacosx.h +++ b/linden/indra/llwindow/llkeyboardmacosx.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardsdl.cpp b/linden/indra/llwindow/llkeyboardsdl.cpp index 86894b1..8a6b6d6 100644 --- a/linden/indra/llwindow/llkeyboardsdl.cpp +++ b/linden/indra/llwindow/llkeyboardsdl.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardsdl.h b/linden/indra/llwindow/llkeyboardsdl.h index e8c6961..e597788 100644 --- a/linden/indra/llwindow/llkeyboardsdl.h +++ b/linden/indra/llwindow/llkeyboardsdl.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardwin32.cpp b/linden/indra/llwindow/llkeyboardwin32.cpp index 8d45dcb..a06f191 100644 --- a/linden/indra/llwindow/llkeyboardwin32.cpp +++ b/linden/indra/llwindow/llkeyboardwin32.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llkeyboardwin32.h b/linden/indra/llwindow/llkeyboardwin32.h index c709f71..a213875 100644 --- a/linden/indra/llwindow/llkeyboardwin32.h +++ b/linden/indra/llwindow/llkeyboardwin32.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llmousehandler.h b/linden/indra/llwindow/llmousehandler.h index dba1fc1..f3a2edd 100644 --- a/linden/indra/llwindow/llmousehandler.h +++ b/linden/indra/llwindow/llmousehandler.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llpreeditor.h b/linden/indra/llwindow/llpreeditor.h index 2180654..370f76c 100644 --- a/linden/indra/llwindow/llpreeditor.h +++ b/linden/indra/llwindow/llpreeditor.h @@ -19,7 +19,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindow.cpp b/linden/indra/llwindow/llwindow.cpp index 44908fb..fb4770e 100644 --- a/linden/indra/llwindow/llwindow.cpp +++ b/linden/indra/llwindow/llwindow.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -308,16 +309,16 @@ void *LLWindow::getMediaWindow() } // static -std::string LLWindow::getFontListSans() +std::vector LLWindow::getDynamicFallbackFontList() { #if LL_WINDOWS - return LLWindowWin32::getFontListSans(); + return LLWindowWin32::getDynamicFallbackFontList(); #elif LL_DARWIN - return LLWindowMacOSX::getFontListSans(); + return LLWindowMacOSX::getDynamicFallbackFontList(); #elif LL_SDL - return LLWindowSDL::getFontListSans(); + return LLWindowSDL::getDynamicFallbackFontList(); #else - return ""; + return std::vector(); #endif } diff --git a/linden/indra/llwindow/llwindow.h b/linden/indra/llwindow/llwindow.h index ffc117f..9e01596 100644 --- a/linden/indra/llwindow/llwindow.h +++ b/linden/indra/llwindow/llwindow.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -35,48 +36,7 @@ #include "llrect.h" #include "llcoord.h" #include "llstring.h" - - -enum ECursorType { - UI_CURSOR_ARROW, - UI_CURSOR_WAIT, - UI_CURSOR_HAND, - UI_CURSOR_IBEAM, - UI_CURSOR_CROSS, - UI_CURSOR_SIZENWSE, - UI_CURSOR_SIZENESW, - UI_CURSOR_SIZEWE, - UI_CURSOR_SIZENS, - UI_CURSOR_NO, - UI_CURSOR_WORKING, - UI_CURSOR_TOOLGRAB, - UI_CURSOR_TOOLLAND, - UI_CURSOR_TOOLFOCUS, - UI_CURSOR_TOOLCREATE, - UI_CURSOR_ARROWDRAG, - UI_CURSOR_ARROWCOPY, // drag with copy - UI_CURSOR_ARROWDRAGMULTI, - UI_CURSOR_ARROWCOPYMULTI, // drag with copy - UI_CURSOR_NOLOCKED, - UI_CURSOR_ARROWLOCKED, - UI_CURSOR_GRABLOCKED, - UI_CURSOR_TOOLTRANSLATE, - UI_CURSOR_TOOLROTATE, - UI_CURSOR_TOOLSCALE, - UI_CURSOR_TOOLCAMERA, - UI_CURSOR_TOOLPAN, - UI_CURSOR_TOOLZOOMIN, - UI_CURSOR_TOOLPICKOBJECT3, - UI_CURSOR_TOOLSIT, - UI_CURSOR_TOOLBUY, - UI_CURSOR_TOOLPAY, - UI_CURSOR_TOOLOPEN, - UI_CURSOR_TOOLPLAY, - UI_CURSOR_TOOLPAUSE, - UI_CURSOR_TOOLMEDIAOPEN, - UI_CURSOR_PIPETTE, - UI_CURSOR_COUNT // Number of elements in this enum (NOT a cursor) -}; +#include "llcursortypes.h" class LLSplashScreen; @@ -238,7 +198,7 @@ public: virtual void interruptLanguageTextInput() {} virtual void spawnWebBrowser(const std::string& escaped_url) {}; - static std::string getFontListSans(); + static std::vector getDynamicFallbackFontList(); protected: LLWindow(BOOL fullscreen, U32 flags); diff --git a/linden/indra/llwindow/llwindowheadless.cpp b/linden/indra/llwindow/llwindowheadless.cpp index 7f671cc..3742846 100644 --- a/linden/indra/llwindow/llwindowheadless.cpp +++ b/linden/indra/llwindow/llwindowheadless.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowheadless.h b/linden/indra/llwindow/llwindowheadless.h index 8153e67..4353d15 100644 --- a/linden/indra/llwindow/llwindowheadless.h +++ b/linden/indra/llwindow/llwindowheadless.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowmacosx-objc.h b/linden/indra/llwindow/llwindowmacosx-objc.h index 9a552e2..ed5d7b1 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.h +++ b/linden/indra/llwindow/llwindowmacosx-objc.h @@ -18,7 +18,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowmacosx-objc.mm b/linden/indra/llwindow/llwindowmacosx-objc.mm index 7315072..da01c2a 100644 --- a/linden/indra/llwindow/llwindowmacosx-objc.mm +++ b/linden/indra/llwindow/llwindowmacosx-objc.mm @@ -18,7 +18,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowmacosx.cpp b/linden/indra/llwindow/llwindowmacosx.cpp index 3ddf5e6..4f6df0f 100644 --- a/linden/indra/llwindow/llwindowmacosx.cpp +++ b/linden/indra/llwindow/llwindowmacosx.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -701,7 +702,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits "Radeon DDR", "Radeon VE", "GDI Generic" }; - const S32 CARD_COUNT = sizeof(CARD_LIST)/sizeof(char*); + const S32 CARD_COUNT = LL_ARRAY_SIZE(CARD_LIST); // Future candidates: // ProSavage/Twister @@ -3357,10 +3358,9 @@ void LLWindowMacOSX::interruptLanguageTextInput() } //static -std::string LLWindowMacOSX::getFontListSans() +std::vector LLWindowMacOSX::getDynamicFallbackFontList() { - // This is a fairly complete Japanese font that ships with Mac OS X. - // The first filename is in UTF8, but it shows up in the font menu as "Hiragino Kaku Gothic Pro W3". - // The third filename is in UTF8, but it shows up in the font menu as "STHeiti Light" - return "\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 Pro W3.otf;\xE3\x83\x92\xE3\x83\xA9\xE3\x82\xAD\xE3\x82\x99\xE3\x83\x8E\xE8\xA7\x92\xE3\x82\xB3\xE3\x82\x99 ProN W3.otf;AppleGothic.dfont;AppleGothic.ttf;\xe5\x8d\x8e\xe6\x96\x87\xe7\xbb\x86\xe9\xbb\x91.ttf"; + // Fonts previously in getFontListSans() have moved to fonts.xml. + return std::vector(); } + diff --git a/linden/indra/llwindow/llwindowmacosx.h b/linden/indra/llwindow/llwindowmacosx.h index 246151c..3886782 100644 --- a/linden/indra/llwindow/llwindowmacosx.h +++ b/linden/indra/llwindow/llwindowmacosx.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -112,7 +113,7 @@ public: /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url); - static std::string getFontListSans(); + static std::vector getDynamicFallbackFontList(); protected: LLWindowMacOSX( diff --git a/linden/indra/llwindow/llwindowmesaheadless.cpp b/linden/indra/llwindow/llwindowmesaheadless.cpp index 993bd7b..c1f9d20 100644 --- a/linden/indra/llwindow/llwindowmesaheadless.cpp +++ b/linden/indra/llwindow/llwindowmesaheadless.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowmesaheadless.h b/linden/indra/llwindow/llwindowmesaheadless.h index ce05216..ab562d9 100644 --- a/linden/indra/llwindow/llwindowmesaheadless.h +++ b/linden/indra/llwindow/llwindowmesaheadless.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, diff --git a/linden/indra/llwindow/llwindowsdl.cpp b/linden/indra/llwindow/llwindowsdl.cpp index 777b32d..d6ee7ac 100644 --- a/linden/indra/llwindow/llwindowsdl.cpp +++ b/linden/indra/llwindow/llwindowsdl.cpp @@ -1,6 +1,7 @@ /** * @file llwindowsdl.cpp * @brief SDL implementation of LLWindow class + * @author This module has many fathers, and it shows. * * $LicenseInfo:firstyear=2001&license=viewergpl$ * @@ -17,7 +18,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -83,8 +85,6 @@ static bool ATIbug = false; // be only one object of this class at any time. Currently this is true. static LLWindowSDL *gWindowImplementation = NULL; -static BOOL was_fullscreen = FALSE; - void maybe_lock_display(void) { @@ -154,6 +154,8 @@ bool LLWindowSDL::ll_try_gtk_init(void) llwarns << "- GTK COMPATIBILITY WARNING: " << gtk_warning << llendl; gtk_is_good = FALSE; + } else { + llinfos << "- GTK version is good." << llendl; } done_gtk_diag = TRUE; @@ -186,11 +188,12 @@ Display* LLWindowSDL::get_SDL_Display(void) LLWindowSDL::LLWindowSDL(const std::string& title, S32 x, S32 y, S32 width, - S32 height, U32 flags, - BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, U32 fsaa_samples) - : LLWindow(fullscreen, flags), mGamma(1.0f) + S32 height, U32 flags, + BOOL fullscreen, BOOL clearBg, + BOOL disable_vsync, BOOL use_gl, + BOOL ignore_pixel_depth, U32 fsaa_samples) + : LLWindow(fullscreen, flags), Lock_Display(NULL), + Unlock_Display(NULL), mGamma(1.0f) { // Initialize the keyboard gKeyboard = new LLKeyboardSDL(); @@ -198,10 +201,6 @@ LLWindowSDL::LLWindowSDL(const std::string& title, S32 x, S32 y, S32 width, // Ignore use_gl for now, only used for drones on PC mWindow = NULL; - mCursorDecoupled = FALSE; - mCursorLastEventDeltaX = 0; - mCursorLastEventDeltaY = 0; - mCursorIgnoreNextDelta = FALSE; mNeedsResize = FALSE; mOverrideAspectRatio = 0.f; mGrabbyKeyFlags = 0; @@ -270,7 +269,7 @@ static SDL_Surface *Load_BMP_Resource(const char *basename) #if LL_X11 // This is an XFree86/XOrg-specific hack for detecting the amount of Video RAM // on this machine. It works by searching /var/log/var/log/Xorg.?.log or -// /var/log/XFree86.?.log for a ': (VideoRAM|Memory): (%d+) kB' regex, where +// /var/log/XFree86.?.log for a ': (VideoRAM ?|Memory): (%d+) kB' regex, where // '?' is the X11 display number derived from $DISPLAY static int x11_detect_VRAM_kb_fp(FILE *fp, const char *prefix_str) { @@ -284,6 +283,8 @@ static int x11_detect_VRAM_kb_fp(FILE *fp, const char *prefix_str) // favourite regex implementation - libboost_regex - is // quite a heavy and troublesome dependency for the client, so // it seems a shame to introduce it for such a simple task. + // *FIXME: libboost_regex is a dependency now anyway, so we may + // as well use it instead of this hand-rolled nonsense. const char *part1_template = prefix_str; const char part2_template[] = " kB"; char *part1 = strstr(line_buf, part1_template); @@ -321,8 +322,7 @@ static int x11_detect_VRAM_kb_fp(FILE *fp, const char *prefix_str) static int x11_detect_VRAM_kb() { -#if LL_SOLARIS -#error Can this be done without an explicit architecture test, ie a test FOR xorg? Was followed by: && defined(__sparc) +#if LL_SOLARIS && defined(__sparc) // NOTE: there's no Xorg server on SPARC so just return 0 // and allow SDL to attempt to get the amount of VRAM return(0); @@ -361,8 +361,17 @@ static int x11_detect_VRAM_kb() fp = fopen(fname.c_str(), "r"); if (fp) { - rtn = x11_detect_VRAM_kb_fp(fp, ": Memory: "); + rtn = x11_detect_VRAM_kb_fp(fp, ": Video RAM: "); fclose(fp); + if (0 == rtn) + { + fp = fopen(fname.c_str(), "r"); + if (fp) + { + rtn = x11_detect_VRAM_kb_fp(fp, ": Memory: "); + fclose(fp); + } + } } } } @@ -418,7 +427,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B if (SDL_Init(SDL_INIT_VIDEO) < 0) { llinfos << "sdl_init() failed! " << SDL_GetError() << llendl; - setupFailure("window creation error", "error", OSMB_OK); + setupFailure("sdl_init() failure, window creation error", "error", OSMB_OK); return false; } @@ -439,7 +448,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B if (!videoInfo) { llinfos << "SDL_GetVideoInfo() failed! " << SDL_GetError() << llendl; - setupFailure("Window creation error", "Error", OSMB_OK); + setupFailure("SDL_GetVideoInfo() failed, Window creation error", "Error", OSMB_OK); return FALSE; } @@ -495,7 +504,6 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // *FIX: try to toggle vsync here? mFullscreen = fullscreen; - was_fullscreen = fullscreen; int sdlflags = SDL_OPENGL | SDL_RESIZABLE | SDL_ANYFORMAT; @@ -571,7 +579,6 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B if (mWindow) { mFullscreen = TRUE; - was_fullscreen = TRUE; mFullscreenWidth = mWindow->w; mFullscreenHeight = mWindow->h; mFullscreenBits = mWindow->format->BitsPerPixel; @@ -588,7 +595,6 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B llwarns << "createContext: fullscreen creation failure. SDL: " << SDL_GetError() << llendl; // No fullscreen support mFullscreen = FALSE; - was_fullscreen = FALSE; mFullscreenWidth = -1; mFullscreenHeight = -1; mFullscreenBits = -1; @@ -670,8 +676,8 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // fixme: actually, it's REALLY important for picking that we get at // least 8 bits each of red,green,blue. Alpha we can be a bit more // relaxed about if we have to. -#if LL_SOLARIS -#error && defined(__sparc) +#if LL_SOLARIS && defined(__sparc) +// again the __sparc required because Xsun support, 32bit are very pricey on SPARC if(colorBits < 24) //HACK: on SPARC allow 24-bit color #else if (colorBits < 32) @@ -679,8 +685,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B { close(); setupFailure( -#if LL_SOLARIS -#error && defined(__sparc) +#if LL_SOLARIS && defined(__sparc) "Second Life requires at least 24-bit color on SPARC to run in a window.\n" "Please use fbconfig to set your default color depth to 24 bits.\n" "You may also need to adjust the X11 setting in SMF. To do so use\n" @@ -715,9 +720,33 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B #endif #if LL_X11 - init_x11clipboard(); + /* Grab the window manager specific information */ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if ( SDL_GetWMInfo(&info) ) + { + /* Save the information for later use */ + if ( info.subsystem == SDL_SYSWM_X11 ) + { + mSDL_Display = info.info.x11.display; + mSDL_XWindowID = info.info.x11.wmwindow; + Lock_Display = info.info.x11.lock_func; + Unlock_Display = info.info.x11.unlock_func; + } + else + { + llwarns << "We're not running under X11? Wild." + << llendl; + } + } + else + { + llwarns << "We're not running under any known WM. Wild." + << llendl; + } #endif // LL_X11 + //make sure multisampling is disabled by default glDisable(GL_MULTISAMPLE_ARB); @@ -761,8 +790,12 @@ BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL void LLWindowSDL::destroyContext() { llinfos << "destroyContext begins" << llendl; + #if LL_X11 - quit_x11clipboard(); + mSDL_Display = NULL; + mSDL_XWindowID = None; + Lock_Display = NULL; + Unlock_Display = NULL; #endif // LL_X11 // Clean up remaining GL state before blowing away window @@ -896,7 +929,6 @@ BOOL LLWindowSDL::getSize(LLCoordScreen *size) return (TRUE); } - llwarns << "LLWindowSDL::getPosition(): no window and not fullscreen!" << llendl; return (FALSE); } @@ -909,7 +941,6 @@ BOOL LLWindowSDL::getSize(LLCoordWindow *size) return (TRUE); } - llwarns << "LLWindowSDL::getPosition(): no window and not fullscreen!" << llendl; return (FALSE); } @@ -928,11 +959,18 @@ BOOL LLWindowSDL::setSize(const LLCoordScreen size) { if(mWindow) { - // *FIX: (???) - //SizeWindow(mWindow, size.mX, size.mY, true); - } + // Push a resize event onto SDL's queue - we'll handle it + // when it comes out again. + SDL_Event event; + event.type = SDL_VIDEORESIZE; + event.resize.w = size.mX; + event.resize.h = size.mY; + SDL_PushEvent(&event); // copied into queue - return TRUE; + return TRUE; + } + + return FALSE; } void LLWindowSDL::swapBuffers() @@ -982,11 +1020,7 @@ BOOL LLWindowSDL::isCursorHidden() // Constrains the mouse to the window. void LLWindowSDL::setMouseClipping( BOOL b ) { - //llinfos << "LLWindowSDL::setMouseClipping " << b << llendl; - // Just stash the requested state. We'll simulate this when the cursor is hidden by decoupling. - mIsMouseClipping = b; //SDL_WM_GrabInput(b ? SDL_GRAB_ON : SDL_GRAB_OFF); - adjustCursorDecouple(); } BOOL LLWindowSDL::setCursorPosition(const LLCoordWindow position) @@ -1001,10 +1035,10 @@ BOOL LLWindowSDL::setCursorPosition(const LLCoordWindow position) //llinfos << "setCursorPosition(" << screen_pos.mX << ", " << screen_pos.mY << ")" << llendl; - SDL_WarpMouse(screen_pos.mX, screen_pos.mY); - - // Under certain circumstances, this will trigger us to decouple the cursor. - adjustCursorDecouple(true); + // do the actual forced cursor move. + SDL_WarpMouse(screen_pos.mX, screen_pos.mY); + + //llinfos << llformat("llcw %d,%d -> scr %d,%d", position.mX, position.mY, screen_pos.mX, screen_pos.mY) << llendl; return result; } @@ -1024,33 +1058,6 @@ BOOL LLWindowSDL::getCursorPosition(LLCoordWindow *position) return convertCoords(screen_pos, position); } -void LLWindowSDL::adjustCursorDecouple(bool warpingMouse) -{ - if(mIsMouseClipping && mCursorHidden) - { - if(warpingMouse) - { - // The cursor should be decoupled. Make sure it is. - if(!mCursorDecoupled) - { - // llinfos << "adjustCursorDecouple: decoupling cursor" << llendl; - //CGAssociateMouseAndMouseCursorPosition(false); - mCursorDecoupled = true; - mCursorIgnoreNextDelta = TRUE; - } - } - } - else - { - // The cursor should not be decoupled. Make sure it isn't. - if(mCursorDecoupled) - { - // llinfos << "adjustCursorDecouple: recoupling cursor" << llendl; - //CGAssociateMouseAndMouseCursorPosition(true); - mCursorDecoupled = false; - } - } -} F32 LLWindowSDL::getNativeAspectRatio() { @@ -1107,24 +1114,28 @@ F32 LLWindowSDL::getPixelAspectRatio() } -// some of this stuff is to support 'temporarily windowed' mode so that -// dialogs are still usable in fullscreen. HOWEVER! - it's not enabled/working -// yet. -static LLCoordScreen old_size; -static BOOL old_fullscreen; +// This is to support 'temporarily windowed' mode so that +// dialogs are still usable in fullscreen. void LLWindowSDL::beforeDialog() { + bool running_x11 = false; +#if LL_X11 + running_x11 = (mSDL_XWindowID != None); +#endif //LL_X11 + llinfos << "LLWindowSDL::beforeDialog()" << llendl; - if (SDLReallyCaptureInput(FALSE) // must ungrab input so popup works! - && getSize(&old_size)) + if (SDLReallyCaptureInput(FALSE)) // must ungrab input so popup works! { - old_fullscreen = was_fullscreen; - - if (old_fullscreen) + if (mFullscreen) { - // NOT YET WORKING - //switchContext(FALSE, old_size, TRUE); + // need to temporarily go non-fullscreen; bless SDL + // for providing a SDL_WM_ToggleFullScreen() - though + // it only works in X11 + if (running_x11 && mWindow) + { + SDL_WM_ToggleFullScreen(mWindow); + } } } @@ -1150,17 +1161,24 @@ void LLWindowSDL::beforeDialog() void LLWindowSDL::afterDialog() { + bool running_x11 = false; +#if LL_X11 + running_x11 = (mSDL_XWindowID != None); +#endif //LL_X11 + llinfos << "LLWindowSDL::afterDialog()" << llendl; maybe_unlock_display(); - if (old_fullscreen && !was_fullscreen) + if (mFullscreen) { - // *FIX: NOT YET WORKING (see below) - //switchContext(TRUE, old_size, TRUE); + // need to restore fullscreen mode after dialog - only works + // in X11 + if (running_x11 && mWindow) + { + SDL_WM_ToggleFullScreen(mWindow); + } } - // *FIX: we need to restore the GL context using - // LLViewerWindow::restoreGL() - but how?? } @@ -1210,506 +1228,50 @@ void LLWindowSDL::flashIcon(F32 seconds) #endif // LL_X11 } -#if LL_X11 -/* Lots of low-level X11 stuff to handle X11 copy-and-paste */ - -/* Our X11 clipboard support is a bit bizarre in various - organically-grown ways. Ideally it should be fixed to do - real string-type negotiation (this would make pasting to - xterm faster and pasting to UTF-8 emacs work properly), but - right now it has the rare and desirable trait of being - generally stable and working. */ - -typedef Atom x11clipboard_type; - -/* PRIMARY and CLIPBOARD are the two main kinds of - X11 clipboard. A third are the CUT_BUFFERs which an - obsolete holdover from X10 days and use a quite orthogonal - mechanism. CLIPBOARD is the type whose design most - closely matches SL's own win32-alike explicit copy-and-paste - paradigm. - - Pragmatically we support all three to varying degrees. When - we paste into SL, it is strictly from CLIPBOARD. When we copy, - we support (to as full an extent as the clipboard content type - allows) CLIPBOARD, PRIMARY, and CUT_BUFFER0. - */ -static x11clipboard_type get_x11_readwrite_clipboard_type(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "CLIPBOARD", False); -} - -static x11clipboard_type get_x11_write_clipboard_type(void) -{ - return XA_PRIMARY; -} - -/* This is where our own private cutbuffer goes - we don't use - a regular cutbuffer (XA_CUT_BUFFER0 etc) for intermediate - storage because their use isn't really defined for holding UTF8. */ -static x11clipboard_type get_x11_cutbuffer_clipboard_type(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "SECONDLIFE_CUTBUFFER", False); -} - -/* Some X11 atom-generators */ -static Atom get_x11_targets_atom(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "TARGETS", False); -} - -static Atom get_x11_text_atom(void) -{ - return XInternAtom(LLWindowSDL::get_SDL_Display(), "TEXT", False); -} - -/* These defines, and convert_data/convert_x11clipboard, - mostly exist to support non-text or unusually-encoded - clipboard data, which we don't really have a need for at - the moment. */ -#define SDLCLIPTYPE(A, B, C, D) (int)(((A)<<24)|((B)<<16)|((C)<<8)|((D)<<0)) -#define FORMAT_PREFIX "SECONDLIFE_x11clipboard_0x" - -static -x11clipboard_type convert_format(int type) -{ - if (!gWindowImplementation) - { - llwarns << "!gWindowImplementation in convert_format()" - << llendl; - return XA_STRING; - } - - switch (type) - { - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - // old-style X11 clipboard, strictly only ISO 8859-1 encoding - return XA_STRING; - case SDLCLIPTYPE('U', 'T', 'F', '8'): - // newer de-facto UTF8 clipboard atom - return XInternAtom(gWindowImplementation->mSDL_Display, - "UTF8_STRING", False); - default: - { - /* completely arbitrary clipboard types... we don't actually use - these right now, and support is skeletal. */ - char format[sizeof(FORMAT_PREFIX)+8+1]; /* Flawfinder: ignore */ - - snprintf(format, sizeof(format), "%s%08lx", FORMAT_PREFIX, (unsigned long)type); - return XInternAtom(gWindowImplementation->mSDL_Display, - format, False); - } - } -} - -/* convert platform string to x11 clipboard format. for our - purposes this is pretty trivial right now. */ -static int -convert_data(int type, char *dst, const char *src, int srclen) -{ - int dstlen; - - dstlen = 0; - switch (type) - { - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - case SDLCLIPTYPE('U', 'T', 'F', '8'): - if (src == NULL) - { - break; - } - if ( srclen == 0 ) - srclen = strlen(src); /* Flawfinder: ignore */ - - dstlen = srclen + 1; - - if ( dst ) // assume caller made it big enough by asking us - { - memcpy(dst, src, srclen); /* Flawfinder: ignore */ - dst[srclen] = '\0'; - } - break; - - default: - llwarns << "convert_data: Unknown medium type" << llendl; - break; - } - return(dstlen); -} - -/* Convert x11clipboard data to platform string. This too is - pretty trivial for our needs right now, and just about identical - to above. */ -static int -convert_x11clipboard(int type, char *dst, const char *src, int srclen) -{ - int dstlen; - - dstlen = 0; - switch (type) - { - case SDLCLIPTYPE('U', 'T', 'F', '8'): - case SDLCLIPTYPE('T', 'E', 'X', 'T'): - if (src == NULL) - { - break; - } - if ( srclen == 0 ) - srclen = strlen(src); /* Flawfinder: ignore */ - - dstlen = srclen + 1; - - if ( dst ) // assume caller made it big enough by asking us - { - memcpy(dst, src, srclen); /* Flawfinder: ignore */ - dst[srclen] = '\0'; - } - break; - - default: - llwarns << "convert_x11clipboard: Unknown medium type" << llendl; - break; - } - return dstlen; -} - -int -LLWindowSDL::is_empty_x11clipboard(void) -{ - int retval; - - maybe_lock_display(); - retval = ( XGetSelectionOwner(mSDL_Display, get_x11_readwrite_clipboard_type()) == None ); - maybe_unlock_display(); - - return(retval); -} -void -LLWindowSDL::put_x11clipboard(int type, int srclen, const char *src) +#if LL_GTK +BOOL LLWindowSDL::isClipboardTextAvailable() { - x11clipboard_type format; - int dstlen; - char *dst; - - format = convert_format(type); - dstlen = convert_data(type, NULL, src, srclen); - - dst = (char *)malloc(dstlen); - if ( dst != NULL ) + if (ll_try_gtk_init()) { - maybe_lock_display(); - Window root = DefaultRootWindow(mSDL_Display); - convert_data(type, dst, src, srclen); - // Cutbuffers are only allowed to have STRING atom types, - // but Emacs puts UTF8 inside them anyway. We cautiously - // don't. - if (type == SDLCLIPTYPE('T','E','X','T')) - { - // dstlen-1 so we don't include the trailing \0 - llinfos << "X11: Populating cutbuffer." <event.xevent; - - if ( (xevent.type == SelectionNotify)&& - (xevent.xselection.requestor == owner) ) - selection_response = 1; - } - } else { - llinfos << "X11: Waiting for SYSWM event..." << llendl; - } - } - llinfos << "X11: Clipboard arrived." <type != SDL_SYSWMEVENT ) - { - return(1); - } - - /* Handle window-manager specific clipboard events */ - switch (event->syswm.msg->event.xevent.type) { - /* Copy the selection from SECONDLIFE_CUTBUFFER to the requested property */ - case SelectionRequest: { - XSelectionRequestEvent *req; - XEvent sevent; - int seln_format; - unsigned long nbytes; - unsigned long overflow; - unsigned char *seln_data; - - req = &event->syswm.msg->event.xevent.xselectionrequest; - sevent.xselection.type = SelectionNotify; - sevent.xselection.display = req->display; - sevent.xselection.selection = req->selection; - sevent.xselection.target = None; - sevent.xselection.property = None; - sevent.xselection.requestor = req->requestor; - sevent.xselection.time = req->time; - if ( XGetWindowProperty(LLWindowSDL::get_SDL_Display(), DefaultRootWindow(LLWindowSDL::get_SDL_Display()), - get_x11_cutbuffer_clipboard_type(), 0, INT_MAX/4, False, req->target, - &sevent.xselection.target, &seln_format, - &nbytes, &overflow, &seln_data) == Success ) - { - if ( sevent.xselection.target == req->target) - { - if ( sevent.xselection.target == XA_STRING || - sevent.xselection.target == - convert_format(SDLCLIPTYPE('U','T','F','8')) ) - { - if ( seln_data[nbytes-1] == '\0' ) - --nbytes; - } - XChangeProperty(LLWindowSDL::get_SDL_Display(), req->requestor, req->property, - req->target, seln_format, PropModeReplace, - seln_data, nbytes); - sevent.xselection.property = req->property; - } else if (get_x11_targets_atom() == req->target) { - /* only advertise what we currently support */ - const int num_supported = 3; - Atom supported[num_supported] = { - XA_STRING, // will be over-written below - get_x11_text_atom(), - get_x11_targets_atom() - }; - supported[0] = sevent.xselection.target; - XChangeProperty(LLWindowSDL::get_SDL_Display(), req->requestor, - req->property, XA_ATOM, 32, PropModeReplace, - (unsigned char*)supported, - num_supported); - sevent.xselection.property = req->property; - llinfos << "Clipboard: An app asked us what selections format we offer." << llendl; - } else { - llinfos << "Clipboard: An app requested an unsupported selection format " << req->target << ", we have " << sevent.xselection.target << llendl; - sevent.xselection.target = None; - } - XFree(seln_data); + text = LLWString(utf8str_to_wstring(data)); + g_free(data); + return TRUE; } - int sendret = - XSendEvent(LLWindowSDL::get_SDL_Display(),req->requestor,False,0,&sevent); - if ((sendret==BadValue) || (sendret==BadWindow)) - llwarns << "Clipboard SendEvent failed" << llendl; - XSync(LLWindowSDL::get_SDL_Display(), False); - } - break; } - - /* Post the event for X11 clipboard reading above */ - return(1); + return FALSE; // failure } -int -LLWindowSDL::init_x11clipboard(void) +BOOL LLWindowSDL::copyTextToClipboard(const LLWString &text) { - SDL_SysWMinfo info; - int retval; - - /* Grab the window manager specific information */ - retval = -1; - SDL_SetError("SDL is not running on known window manager"); - - SDL_VERSION(&info.version); - if ( SDL_GetWMInfo(&info) ) + if (ll_try_gtk_init()) { - /* Save the information for later use */ - if ( info.subsystem == SDL_SYSWM_X11 ) - { - mSDL_Display = info.info.x11.display; - mSDL_XWindowID = info.info.x11.wmwindow; - Lock_Display = info.info.x11.lock_func; - Unlock_Display = info.info.x11.unlock_func; - - /* Enable the special window hook events */ - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(clipboard_filter_callback); - - retval = 0; - } - else - { - SDL_SetError("SDL is not running on X11"); - } - } - return(retval); -} - -void -LLWindowSDL::quit_x11clipboard(void) -{ - mSDL_Display = NULL; - mSDL_XWindowID = None; - Lock_Display = NULL; - Unlock_Display = NULL; - - SDL_SetEventFilter(NULL); // Stop custom event filtering -} - -/************************************************/ - -BOOL LLWindowSDL::isClipboardTextAvailable() -{ - return !is_empty_x11clipboard(); -} - -BOOL LLWindowSDL::pasteTextFromClipboard(LLWString &dst) -{ - int cliplen; // seems 1 or 2 bytes longer than expected - char *cliptext = NULL; - get_x11clipboard(SDLCLIPTYPE('U','T','F','8'), &cliplen, &cliptext); - if (cliptext) - { - llinfos << "X11: Got UTF8 clipboard text." << llendl; - // at some future time we can use cliplen instead of relying on \0, - // if we ever grok non-ascii, non-utf8 encodings on the clipboard. - std::string clip_str(cliptext); - // we can't necessarily trust the incoming text to be valid UTF-8, - // but utf8str_to_wstring() seems to do an appropriate level of - // validation for avoiding over-reads. - dst = utf8str_to_wstring(clip_str); - /*llinfos << "X11 pasteTextFromClipboard: cliplen=" << cliplen << - " strlen(cliptext)=" << strlen(cliptext) << - " clip_str.length()=" << clip_str.length() << - " dst.length()=" << dst.length() << - llendl;*/ - free(cliptext); - return TRUE; // success - } - get_x11clipboard(SDLCLIPTYPE('T','E','X','T'), &cliplen, &cliptext); - if (cliptext) - { - llinfos << "X11: Got ISO 8859-1 clipboard text." << llendl; - std::string clip_str(cliptext); - std::string utf8_str = rawstr_to_utf8(clip_str); - dst = utf8str_to_wstring(utf8_str); - free(cliptext); + const std::string utf8 = wstring_to_utf8str(text); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + gtk_clipboard_set_text(clipboard, utf8.c_str(), utf8.length()); + return TRUE; } return FALSE; // failure } -BOOL LLWindowSDL::copyTextToClipboard(const LLWString &s) -{ - std::string utf8text = wstring_to_utf8str(s); - const char* cstr = utf8text.c_str(); - if (cstr == NULL) - { - return FALSE; - } - int cstrlen = strlen(cstr); /* Flawfinder: ignore */ - int i; - for (i=0; ihandleMouseDown(this, openGlCoord, mask); } - else if (event.button.button == SDL_BUTTON_RIGHT) // right ... yes, it's 3, not 2, in SDL... + else if (event.button.button == SDL_BUTTON_RIGHT) // right { - // right double click isn't handled right now in Second Life ... if (isDoubleClick) - mCallbacks->handleRightMouseDown(this, openGlCoord, mask); + mCallbacks->handleRightMouseDown(this, openGlCoord, mask); } else if (event.button.button == SDL_BUTTON_MIDDLE) // middle @@ -2110,13 +1673,11 @@ void LLWindowSDL::gatherInput() MASK mask = gKeyboard->currentMask(TRUE); if (event.button.button == SDL_BUTTON_LEFT) // left - mCallbacks->handleMouseUp(this, openGlCoord, mask); - else if (event.button.button == SDL_BUTTON_RIGHT) // right ... yes, it's 3, not 2, in SDL... - mCallbacks->handleRightMouseUp(this, openGlCoord, mask); + mCallbacks->handleMouseUp(this, openGlCoord, mask); + else if (event.button.button == SDL_BUTTON_RIGHT) // right + mCallbacks->handleRightMouseUp(this, openGlCoord, mask); else if (event.button.button == SDL_BUTTON_MIDDLE) // middle - { mCallbacks->handleMiddleMouseUp(this, openGlCoord, mask); - } // don't handle mousewheel here... break; @@ -2160,12 +1721,12 @@ void LLWindowSDL::gatherInput() // which confuses the focus code [SL-24071]. if (event.active.gain != mHaveInputFocus) { - if (event.active.gain) + mHaveInputFocus = !!event.active.gain; + + if (mHaveInputFocus) mCallbacks->handleFocus(this); else mCallbacks->handleFocusLost(this); - - mHaveInputFocus = !!event.active.gain; } } if (event.active.state & SDL_APPACTIVE) @@ -2173,10 +1734,10 @@ void LLWindowSDL::gatherInput() // Change in iconification/minimization state. if ((!event.active.gain) != mIsMinimized) { - mCallbacks->handleActivate(this, !!event.active.gain); - llinfos << "SDL deiconification state switched to " << BOOL(event.active.gain) << llendl; - mIsMinimized = (!event.active.gain); + + mCallbacks->handleActivate(this, !mIsMinimized); + llinfos << "SDL deiconification state switched to " << BOOL(event.active.gain) << llendl; } else { @@ -2424,8 +1985,6 @@ void LLWindowSDL::hideCursor() { // llinfos << "hideCursor: already hidden" << llendl; } - - adjustCursorDecouple(); } void LLWindowSDL::showCursor() @@ -2441,8 +2000,6 @@ void LLWindowSDL::showCursor() { // llinfos << "showCursor: already visible" << llendl; } - - adjustCursorDecouple(); } void LLWindowSDL::showCursorFromMouseMove() @@ -2508,10 +2065,7 @@ S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 typ if(gWindowImplementation != NULL) gWindowImplementation->beforeDialog(); - if (LLWindowSDL::ll_try_gtk_init() - // We can NOT expect to combine GTK and SDL's aggressive fullscreen - && ((NULL==gWindowImplementation) || (!was_fullscreen)) - ) + if (LLWindowSDL::ll_try_gtk_init()) { GtkWidget *win = NULL; @@ -2616,10 +2170,7 @@ BOOL LLWindowSDL::dialog_color_picker ( F32 *r, F32 *g, F32 *b) beforeDialog(); - if (ll_try_gtk_init() - // We can NOT expect to combine GTK and SDL's aggressive fullscreen - && !was_fullscreen - ) + if (ll_try_gtk_init()) { GtkWidget *win = NULL; @@ -2802,7 +2353,7 @@ void LLWindowSDL::bringToFront() } //static -std::string LLWindowSDL::getFontListSans() +std::vector LLWindowSDL::getDynamicFallbackFontList() { // Use libfontconfig to find us a nice ordered list of fallback fonts // specific to this system. @@ -2819,7 +2370,7 @@ std::string LLWindowSDL::getFontListSans() // renderable range if for some reason our FreeType actually fails // to use some of the fonts we want it to. const bool elide_unicode_coverage = true; - std::string rtn; + std::vector rtns; FcFontSet *fs = NULL; FcPattern *sortpat = NULL; int font_count = 0; @@ -2853,7 +2404,8 @@ std::string LLWindowSDL::getFontListSans() if (!FcInit()) { llwarns << "FontConfig failed to initialize." << llendl; - return final_fallback; + rtns.push_back(final_fallback); + return rtns; } sortpat = FcNameParse((FcChar8*) sort_order.c_str()); @@ -2878,17 +2430,24 @@ std::string LLWindowSDL::getFontListSans() &filename) && filename) { - rtn += std::string((const char*)filename)+";"; + rtns.push_back(std::string((const char*)filename)); ++font_count; } } FcFontSetDestroy (fs); } - lldebugs << "Using font list: " << rtn << llendl; + lldebugs << "Using font list: " << llendl; + for (std::vector::iterator it = rtns.begin(); + it != rtns.end(); + ++it) + { + lldebugs << " file: " << *it << llendl; + } llinfos << "Using " << font_count << " system font(s)." << llendl; - return rtn + final_fallback; + rtns.push_back(final_fallback); + return rtns; } #endif // LL_SDL diff --git a/linden/indra/llwindow/llwindowsdl.h b/linden/indra/llwindow/llwindowsdl.h index 36baec6..cebb151 100644 --- a/linden/indra/llwindow/llwindowsdl.h +++ b/linden/indra/llwindow/llwindowsdl.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -118,12 +119,11 @@ public: /*virtual*/ void spawnWebBrowser(const std::string& escaped_url); - static std::string getFontListSans(); + static std::vector getDynamicFallbackFontList(); // Not great that these are public, but they have to be accessible // by non-class code and it's better than making them global. #if LL_X11 - // These are set up by the X11 clipboard initialization code Window mSDL_XWindowID; Display *mSDL_Display; #endif @@ -173,7 +173,6 @@ protected: BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync); void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); - void adjustCursorDecouple(bool warpingMouse = false); void fixWindowSize(void); U32 SDLCheckGrabbyKeys(SDLKey keysym, BOOL gain); BOOL SDLReallyCaptureInput(BOOL capture); @@ -186,10 +185,6 @@ protected: SDL_Surface * mWindow; std::string mWindowTitle; double mOriginalAspectRatio; - BOOL mCursorDecoupled; - S32 mCursorLastEventDeltaX; - S32 mCursorLastEventDeltaY; - BOOL mCursorIgnoreNextDelta; BOOL mNeedsResize; // Constructor figured out the window is too big, it needs a resize. LLCoordScreen mNeedsResizeSize; F32 mOverrideAspectRatio; @@ -206,12 +201,6 @@ protected: #if LL_X11 private: - // more X11 clipboard stuff - int init_x11clipboard(void); - void quit_x11clipboard(void); - int is_empty_x11clipboard(void); - void put_x11clipboard(int type, int srclen, const char *src); - void get_x11clipboard(int type, int *dstlen, char **dst); void x11_set_urgent(BOOL urgent); BOOL mFlashing; LLTimer mFlashTimer; diff --git a/linden/indra/llwindow/llwindowwin32.cpp b/linden/indra/llwindow/llwindowwin32.cpp index 2944511..6280868 100644 --- a/linden/indra/llwindow/llwindowwin32.cpp +++ b/linden/indra/llwindow/llwindowwin32.cpp @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -372,6 +373,8 @@ LLWindowWin32::LLWindowWin32(const std::string& title, const std::string& name, mMousePositionModified = FALSE; mInputProcessingPaused = FALSE; mPreeditor = NULL; + mhDC = NULL; + mhRC = NULL; // Initialize the keyboard gKeyboard = new LLKeyboardWin32(); @@ -417,7 +420,7 @@ LLWindowWin32::LLWindowWin32(const std::string& title, const std::string& name, mhInstance = GetModuleHandle(NULL); mWndProc = NULL; - mSwapMethod = SWAP_METHOD_EXCHANGE; + mSwapMethod = SWAP_METHOD_UNDEFINED; // No WPARAM yet. mLastSizeWParam = 0; @@ -843,8 +846,13 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, BO RECT window_rect; S32 width = size.mX; S32 height = size.mY; + BOOL auto_show = FALSE; - resetDisplayResolution(); + if (mhRC) + { + auto_show = TRUE; + resetDisplayResolution(); + } if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode)) { @@ -1182,8 +1190,28 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, BO LL_INFOS("Window") << "Choosing pixel formats: " << num_formats << " pixel formats returned" << LL_ENDL; } - pixel_format = pixel_formats[0]; + + + S32 swap_method = 0; + S32 cur_format = num_formats-1; + GLint swap_query = WGL_SWAP_METHOD_ARB; + + BOOL found_format = FALSE; + while (!found_format && wglGetPixelFormatAttribivARB(mhDC, pixel_format, 0, 1, &swap_query, &swap_method)) + { + if (swap_method == WGL_SWAP_UNDEFINED_ARB || cur_format <= 0) + { + found_format = TRUE; + } + else + { + --cur_format; + } + } + + pixel_format = pixel_formats[cur_format]; + if (mhDC != 0) // Does The Window Have A Device Context? { wglMakeCurrent(mhDC, 0); // Set The Current Active Rendering Context To Zero @@ -1226,9 +1254,6 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, BO return FALSE; } - int swap_method = 0; - GLint swap_query = WGL_SWAP_METHOD_ARB; - if (wglGetPixelFormatAttribivARB(mhDC, pixel_format, 0, 1, &swap_query, &swap_method)) { switch (swap_method) @@ -1341,13 +1366,21 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, BO } SetWindowLong(mWindowHandle, GWL_USERDATA, (U32)this); - show(); - + //register joystick timer callback SetTimer( mWindowHandle, 0, 1000 / 30, NULL ); // 30 fps timer // ok to post quit messages now mPostQuit = TRUE; + + if (auto_show) + { + show(); + glClearColor(0.0f, 0.0f, 0.0f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + swapBuffers(); + } + return TRUE; } @@ -2930,7 +2963,7 @@ void LLWindowWin32::spawnWebBrowser(const std::string& escaped_url ) /* std::string reg_path_str = gURLProtocolWhitelistHandler[i] + "\\shell\\open\\command"; WCHAR reg_path_wstr[256]; - mbstowcs(reg_path_wstr, reg_path_str.c_str(), sizeof(reg_path_wstr)/sizeof(reg_path_wstr[0])); + mbstowcs( reg_path_wstr, reg_path_str.c_str(), LL_ARRAY_SIZE(reg_path_wstr) ); HKEY key; WCHAR browser_open_wstr[1024]; @@ -3621,11 +3654,10 @@ BOOL LLWindowWin32::handleImeRequests(U32 request, U32 param, LRESULT *result) } //static -std::string LLWindowWin32::getFontListSans() +std::vector LLWindowWin32::getDynamicFallbackFontList() { - // Lists Japanese, Korean, and Chinese sanserif fonts available in - // Windows XP and Vista, as well as "Arial Unicode MS". - return "MSGOTHIC.TTC;gulim.ttc;simhei.ttf;ArialUni.ttf"; + // Fonts previously in getFontListSans() have moved to fonts.xml. + return std::vector(); } diff --git a/linden/indra/llwindow/llwindowwin32.h b/linden/indra/llwindow/llwindowwin32.h index 795fc79..237f834 100644 --- a/linden/indra/llwindow/llwindowwin32.h +++ b/linden/indra/llwindow/llwindowwin32.h @@ -17,7 +17,8 @@ * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, @@ -111,7 +112,7 @@ public: /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url); - static std::string getFontListSans(); + static std::vector getDynamicFallbackFontList(); protected: LLWindowWin32( -- cgit v1.1 From b2627d927f1642bea84b92adfccd9403676e1341 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 24 May 2009 02:59:24 -0500 Subject: Second Life viewer sources 1.23.2-RC --- linden/indra/llwindow/lldxhardware.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'linden/indra/llwindow') diff --git a/linden/indra/llwindow/lldxhardware.cpp b/linden/indra/llwindow/lldxhardware.cpp index beab131..e0cb82d 100644 --- a/linden/indra/llwindow/lldxhardware.cpp +++ b/linden/indra/llwindow/lldxhardware.cpp @@ -624,7 +624,37 @@ LLSD LLDXHardware::getDisplayInfo() ret["DeviceName"] = device_name; std::string device_driver= get_string(device_containerp, L"szDriverVersion"); ret["DriverVersion"] = device_driver; - } + + // ATI has a slightly different version string + if(device_name.length() >= 4 && device_name.substr(0,4) == "ATI ") + { + // get the key + HKEY hKey; + const DWORD RV_SIZE = 100; + WCHAR release_version[RV_SIZE]; + + // Hard coded registry entry. Using this since it's simpler for now. + // And using EnumDisplayDevices to get a registry key also requires + // a hard coded Query value. + if(ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\ATI Technologies\\CBT"), &hKey)) + { + // get the value + DWORD dwType = REG_SZ; + DWORD dwSize = sizeof(WCHAR) * RV_SIZE; + if(ERROR_SUCCESS == RegQueryValueEx(hKey, TEXT("ReleaseVersion"), + NULL, &dwType, (LPBYTE)release_version, &dwSize)) + { + // print the value + // windows doesn't guarantee to be null terminated + release_version[RV_SIZE - 1] = NULL; + ret["DriverVersion"] = utf16str_to_utf8str(release_version); + + } + RegCloseKey(hKey); + } + } + } + LCleanup: SAFE_RELEASE(file_containerp); SAFE_RELEASE(driver_containerp); -- cgit v1.1 From 0517fe4322443bdc317f8185590a63134e3f8394 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sat, 13 Jun 2009 13:17:14 -0500 Subject: Second Life viewer sources 1.23.3-RC --- linden/indra/llwindow/glh/glh_linear.h | 1621 ++++++++++++++++++++++++++++++++ 1 file changed, 1621 insertions(+) create mode 100755 linden/indra/llwindow/glh/glh_linear.h (limited to 'linden/indra/llwindow') diff --git a/linden/indra/llwindow/glh/glh_linear.h b/linden/indra/llwindow/glh/glh_linear.h new file mode 100755 index 0000000..04ae1bd --- /dev/null +++ b/linden/indra/llwindow/glh/glh_linear.h @@ -0,0 +1,1621 @@ +/* + glh - is a platform-indepenedent C++ OpenGL helper library + + + Copyright (c) 2000 Cass Everitt + Copyright (c) 2000 NVIDIA Corporation + 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. + + * The names of contributors to this software may not 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 + REGENTS 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. + + + Cass Everitt - cass@r3.nu +*/ + +/* +glh_linear.h +*/ + +// Author: Cass W. Everitt + +#ifndef GLH_LINEAR_H +#define GLH_LINEAR_H + +#include +#include +#include + +// only supports float for now... +#define GLH_REAL_IS_FLOAT + +#ifdef GLH_REAL_IS_FLOAT +# define GLH_REAL float +# define GLH_REAL_NAMESPACE ns_float +#endif + +#define GLH_QUATERNION_NORMALIZATION_THRESHOLD 64 + +#define GLH_RAD_TO_DEG GLH_REAL(57.2957795130823208767981548141052) +#define GLH_DEG_TO_RAD GLH_REAL(0.0174532925199432957692369076848861) +#define GLH_ZERO GLH_REAL(0.0) +#define GLH_ONE GLH_REAL(1.0) +#define GLH_TWO GLH_REAL(2.0) +#define GLH_EPSILON GLH_REAL(10e-6) +#define GLH_PI GLH_REAL(3.1415926535897932384626433832795) + +#define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false) + +namespace glh +{ + + inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; } + inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; } + + // forward declarations for friend template functions. + template class vec; + + // forward declarations for friend template functions. + template + bool operator == ( const vec & v1, const vec & v2 ); + + // forward declarations for friend template functions. + template + bool operator != ( const vec & v1, const vec & v2 ); + + template + class vec + { + public: + int size() const { return N; } + + vec(const T & t = T()) + { for(int i = 0; i < N; i++) v[i] = t; } + vec(const T * tp) + { for(int i = 0; i < N; i++) v[i] = tp[i]; } + + const T * get_value() const + { return v; } + + + T dot( const vec & rhs ) const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*rhs.v[i]; + return r; + } + + T length() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return T(sqrt(r)); + } + + T square_norm() const + { + T r = 0; + for(int i = 0; i < N; i++) r += v[i]*v[i]; + return r; + } + + void negate() + { for(int i = 0; i < N; i++) v[i] = -v[i]; } + + + T normalize() + { + T sum(0); + for(int i = 0; i < N; i++) + sum += v[i]*v[i]; + sum = T(sqrt(sum)); + if (sum > GLH_EPSILON) + for(int i = 0; i < N; i++) + v[i] /= sum; + return sum; + } + + + vec & set_value( const T * rhs ) + { for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; } + + T & operator [] ( int i ) + { return v[i]; } + + const T & operator [] ( int i ) const + { return v[i]; } + + vec & operator *= ( T d ) + { for(int i = 0; i < N; i++) v[i] *= d; return *this;} + + vec & operator *= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;} + + vec & operator /= ( T d ) + { if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;} + + vec & operator += ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;} + + vec & operator -= ( const vec & u ) + { for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;} + + + vec operator - () const + { vec rv = v; rv.negate(); return rv; } + + vec operator + ( const vec &v) const + { vec rt(*this); return rt += v; } + + vec operator - ( const vec &v) const + { vec rt(*this); return rt -= v; } + + vec operator * ( T d) const + { vec rt(*this); return rt *= d; } + + friend bool operator == <> ( const vec &v1, const vec &v2 ); + friend bool operator != <> ( const vec &v1, const vec &v2 ); + + + //protected: + T v[N]; + }; + + + + // vector friend operators + + template inline + vec operator * ( const vec & b, T d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator * ( T d, const vec & b ) + { return b*d; } + + template inline + vec operator * ( const vec & b, const vec & d ) + { + vec rt(b); + return rt *= d; + } + + template inline + vec operator / ( const vec & b, T d ) + { vec rt(b); return rt /= d; } + + template inline + vec operator + ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt += v2; } + + template inline + vec operator - ( const vec & v1, const vec & v2 ) + { vec rt(v1); return rt -= v2; } + + + template inline + bool operator == ( const vec & v1, const vec & v2 ) + { + for(int i = 0; i < N; i++) + if(v1.v[i] != v2.v[i]) + return false; + return true; + } + + template inline + bool operator != ( const vec & v1, const vec & v2 ) + { return !(v1 == v2); } + + + typedef vec<3,unsigned char> vec3ub; + typedef vec<4,unsigned char> vec4ub; + + + + + + namespace GLH_REAL_NAMESPACE + { + typedef GLH_REAL real; + + class line; + class plane; + class matrix4; + class quaternion; + typedef quaternion rotation; + + class vec2 : public vec<2,real> + { + public: + vec2(const real & t = real()) : vec<2,real>(t) + {} + vec2(const vec<2,real> & t) : vec<2,real>(t) + {} + vec2(const real * tp) : vec<2,real>(tp) + {} + + vec2(real x, real y ) + { v[0] = x; v[1] = y; } + + void get_value(real & x, real & y) const + { x = v[0]; y = v[1]; } + + vec2 & set_value( const real & x, const real & y) + { v[0] = x; v[1] = y; return *this; } + + }; + + + class vec3 : public vec<3,real> + { + public: + vec3(const real & t = real()) : vec<3,real>(t) + {} + vec3(const vec<3,real> & t) : vec<3,real>(t) + {} + vec3(const real * tp) : vec<3,real>(tp) + {} + + vec3(real x, real y, real z) + { v[0] = x; v[1] = y; v[2] = z; } + + void get_value(real & x, real & y, real & z) const + { x = v[0]; y = v[1]; z = v[2]; } + + vec3 cross( const vec3 &rhs ) const + { + vec3 rt; + rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1]; + rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2]; + rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0]; + return rt; + } + + vec3 & set_value( const real & x, const real & y, const real & z) + { v[0] = x; v[1] = y; v[2] = z; return *this; } + + }; + + + class vec4 : public vec<4,real> + { + public: + vec4(const real & t = real()) : vec<4,real>(t) + {} + vec4(const vec<4,real> & t) : vec<4,real>(t) + {} + + vec4(const vec<3,real> & t, real fourth) + + { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; } + vec4(const real * tp) : vec<4,real>(tp) + {} + vec4(real x, real y, real z, real w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; } + + void get_value(real & x, real & y, real & z, real & w) const + { x = v[0]; y = v[1]; z = v[2]; w = v[3]; } + + vec4 & set_value( const real & x, const real & y, const real & z, const real & w) + { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; } + }; + + inline + vec3 homogenize(const vec4 & v) + { + vec3 rt; + assert(v.v[3] != GLH_ZERO); + rt.v[0] = v.v[0]/v.v[3]; + rt.v[1] = v.v[1]/v.v[3]; + rt.v[2] = v.v[2]/v.v[3]; + return rt; + } + + + + class line + { + public: + + line() + { set_value(vec3(0,0,0),vec3(0,0,1)); } + + line( const vec3 & p0, const vec3 &p1) + { set_value(p0,p1); } + + void set_value( const vec3 &p0, const vec3 &p1) + { + position = p0; + direction = p1-p0; + direction.normalize(); + } + + bool get_closest_points(const line &line2, + vec3 &pointOnThis, + vec3 &pointOnThat) + { + + // quick check to see if parallel -- if so, quit. + if(fabs(direction.dot(line2.direction)) == 1.0) + return 0; + line l2 = line2; + + // Algorithm: Brian Jean + // + register real u; + register real v; + vec3 Vr = direction; + vec3 Vs = l2.direction; + register real Vr_Dot_Vs = Vr.dot(Vs); + register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs)); + vec3 C = l2.position - position; + register real C_Dot_Vr = C.dot(Vr); + register real C_Dot_Vs = C.dot(Vs); + + u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA; + v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA; + + pointOnThis = position; + pointOnThis += direction * u; + pointOnThat = l2.position; + pointOnThat += l2.direction * v; + + return 1; + } + + vec3 get_closest_point(const vec3 &point) + { + vec3 np = point - position; + vec3 rp = direction*direction.dot(np)+position; + return rp; + } + + const vec3 & get_position() const {return position;} + + const vec3 & get_direction() const {return direction;} + + //protected: + vec3 position; + vec3 direction; + }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // matrix + + + class matrix4 + { + + public: + + matrix4() { make_identity(); } + + matrix4( real r ) + { set_value(r); } + + matrix4( real * m ) + { set_value(m); } + + matrix4( real a00, real a01, real a02, real a03, + real a10, real a11, real a12, real a13, + real a20, real a21, real a22, real a23, + real a30, real a31, real a32, real a33 ) + { + element(0,0) = a00; + element(0,1) = a01; + element(0,2) = a02; + element(0,3) = a03; + + element(1,0) = a10; + element(1,1) = a11; + element(1,2) = a12; + element(1,3) = a13; + + element(2,0) = a20; + element(2,1) = a21; + element(2,2) = a22; + element(2,3) = a23; + + element(3,0) = a30; + element(3,1) = a31; + element(3,2) = a32; + element(3,3) = a33; + } + + + void get_value( real * mp ) const + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + mp[c++] = element(i,j); + } + + + const real * get_value() const + { return m; } + + void set_value( real * mp) + { + int c = 0; + for(int j=0; j < 4; j++) + for(int i=0; i < 4; i++) + element(i,j) = mp[c++]; + } + + void set_value( real r ) + { + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + element(i,j) = r; + } + + void make_identity() + { + element(0,0) = 1.0; + element(0,1) = 0.0; + element(0,2) = 0.0; + element(0,3) = 0.0; + + element(1,0) = 0.0; + element(1,1) = 1.0; + element(1,2) = 0.0; + element(1,3) = 0.0; + + element(2,0) = 0.0; + element(2,1) = 0.0; + element(2,2) = 1.0; + element(2,3) = 0.0; + + element(3,0) = 0.0; + element(3,1) = 0.0; + element(3,2) = 0.0; + element(3,3) = 1.0; + } + + + static matrix4 identity() + { + static matrix4 mident ( + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 ); + return mident; + } + + + void set_scale( real s ) + { + element(0,0) = s; + element(1,1) = s; + element(2,2) = s; + } + + void set_scale( const vec3 & s ) + { + element(0,0) = s.v[0]; + element(1,1) = s.v[1]; + element(2,2) = s.v[2]; + } + + + void set_translate( const vec3 & t ) + { + element(0,3) = t.v[0]; + element(1,3) = t.v[1]; + element(2,3) = t.v[2]; + } + + void set_row(int r, const vec4 & t) + { + element(r,0) = t.v[0]; + element(r,1) = t.v[1]; + element(r,2) = t.v[2]; + element(r,3) = t.v[3]; + } + + void set_column(int c, const vec4 & t) + { + element(0,c) = t.v[0]; + element(1,c) = t.v[1]; + element(2,c) = t.v[2]; + element(3,c) = t.v[3]; + } + + + void get_row(int r, vec4 & t) const + { + t.v[0] = element(r,0); + t.v[1] = element(r,1); + t.v[2] = element(r,2); + t.v[3] = element(r,3); + } + + vec4 get_row(int r) const + { + vec4 v; get_row(r, v); + return v; + } + + void get_column(int c, vec4 & t) const + { + t.v[0] = element(0,c); + t.v[1] = element(1,c); + t.v[2] = element(2,c); + t.v[3] = element(3,c); + } + + vec4 get_column(int c) const + { + vec4 v; get_column(c, v); + return v; + } + + matrix4 inverse() const + { + matrix4 minv; + + real r1[8], r2[8], r3[8], r4[8]; + real *s[4], *tmprow; + + s[0] = &r1[0]; + s[1] = &r2[0]; + s[2] = &r3[0]; + s[3] = &r4[0]; + + register int i,j,p,jj; + for(i=0;i<4;i++) + { + for(j=0;j<4;j++) + { + s[i][j] = element(i,j); + if(i==j) s[i][j+4] = 1.0; + else s[i][j+4] = 0.0; + } + } + real scp[4]; + for(i=0;i<4;i++) + { + scp[i] = real(fabs(s[i][0])); + for(j=1;j<4;j++) + if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j])); + if(scp[i] == 0.0) return minv; // singular matrix! + } + + int pivot_to; + real scp_max; + for(i=0;i<4;i++) + { + // select pivot row + pivot_to = i; + scp_max = real(fabs(s[i][i]/scp[i])); + // find out which row should be on top + for(p=i+1;p<4;p++) + if(real(fabs(s[p][i]/scp[p])) > scp_max) + { scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; } + // Pivot if necessary + if(pivot_to != i) + { + tmprow = s[i]; + s[i] = s[pivot_to]; + s[pivot_to] = tmprow; + real tmpscp; + tmpscp = scp[i]; + scp[i] = scp[pivot_to]; + scp[pivot_to] = tmpscp; + } + + real mji; + // perform gaussian elimination + for(j=i+1;j<4;j++) + { + mji = s[j][i]/s[i][i]; + s[j][i] = 0.0; + for(jj=i+1;jj<8;jj++) + s[j][jj] -= mji*s[i][jj]; + } + } + if(s[3][3] == 0.0) return minv; // singular matrix! + + // + // Now we have an upper triangular matrix. + // + // x x x x | y y y y + // 0 x x x | y y y y + // 0 0 x x | y y y y + // 0 0 0 x | y y y y + // + // we'll back substitute to get the inverse + // + // 1 0 0 0 | z z z z + // 0 1 0 0 | z z z z + // 0 0 1 0 | z z z z + // 0 0 0 1 | z z z z + // + + real mij; + for(i=3;i>0;i--) + { + for(j=i-1;j > -1; j--) + { + mij = s[j][i]/s[i][i]; + for(jj=j+1;jj<8;jj++) + s[j][jj] -= mij*s[i][jj]; + } + } + + for(i=0;i<4;i++) + for(j=0;j<4;j++) + minv(i,j) = s[i][j+4] / s[i][i]; + + return minv; + } + + + matrix4 transpose() const + { + matrix4 mtrans; + + for(int i=0;i<4;i++) + for(int j=0;j<4;j++) + mtrans(i,j) = element(j,i); + return mtrans; + } + + matrix4 & mult_right( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += mt(i,c) * b(c,j); + return *this; + } + + matrix4 & mult_left( const matrix4 & b ) + { + matrix4 mt(*this); + set_value(real(0)); + + for(int i=0; i < 4; i++) + for(int j=0; j < 4; j++) + for(int c=0; c < 4; c++) + element(i,j) += b(i,c) * mt(c,j); + return *this; + } + + // dst = M * src + void mult_matrix_vec( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + element(0,3) ) / w; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + element(1,3) ) / w; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + element(2,3) ) / w; + } + + void mult_matrix_vec( vec3 & src_and_dst) const + { mult_matrix_vec(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec3 &src, vec3 &dst ) const + { + real w = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + element(3,3) ); + + assert(w != GLH_ZERO); + + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + element(3,0) ) / w; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + element(3,1) ) / w; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + element(3,2) ) / w; + } + + + void mult_vec_matrix( vec3 & src_and_dst) const + { mult_vec_matrix(vec3(src_and_dst), src_and_dst); } + + // dst = M * src + void mult_matrix_vec( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) + + src.v[3] * element(0,3)); + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) + + src.v[3] * element(1,3)); + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) + + src.v[3] * element(2,3)); + dst.v[3] = ( + src.v[0] * element(3,0) + + src.v[1] * element(3,1) + + src.v[2] * element(3,2) + + src.v[3] * element(3,3)); + } + + void mult_matrix_vec( vec4 & src_and_dst) const + { mult_matrix_vec(vec4(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_vec_matrix( const vec4 &src, vec4 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) + + src.v[3] * element(3,0)); + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) + + src.v[3] * element(3,1)); + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) + + src.v[3] * element(3,2)); + dst.v[3] = ( + src.v[0] * element(0,3) + + src.v[1] * element(1,3) + + src.v[2] * element(2,3) + + src.v[3] * element(3,3)); + } + + + void mult_vec_matrix( vec4 & src_and_dst) const + { mult_vec_matrix(vec4(src_and_dst), src_and_dst); } + + + // dst = M * src + void mult_matrix_dir( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(0,1) + + src.v[2] * element(0,2) ) ; + dst.v[1] = ( + src.v[0] * element(1,0) + + src.v[1] * element(1,1) + + src.v[2] * element(1,2) ) ; + dst.v[2] = ( + src.v[0] * element(2,0) + + src.v[1] * element(2,1) + + src.v[2] * element(2,2) ) ; + } + + + void mult_matrix_dir( vec3 & src_and_dst) const + { mult_matrix_dir(vec3(src_and_dst), src_and_dst); } + + + // dst = src * M + void mult_dir_matrix( const vec3 &src, vec3 &dst ) const + { + dst.v[0] = ( + src.v[0] * element(0,0) + + src.v[1] * element(1,0) + + src.v[2] * element(2,0) ) ; + dst.v[1] = ( + src.v[0] * element(0,1) + + src.v[1] * element(1,1) + + src.v[2] * element(2,1) ) ; + dst.v[2] = ( + src.v[0] * element(0,2) + + src.v[1] * element(1,2) + + src.v[2] * element(2,2) ) ; + } + + + void mult_dir_matrix( vec3 & src_and_dst) const + { mult_dir_matrix(vec3(src_and_dst), src_and_dst); } + + + real & operator () (int row, int col) + { return element(row,col); } + + const real & operator () (int row, int col) const + { return element(row,col); } + + real & element (int row, int col) + { return m[row | (col<<2)]; } + + const real & element (int row, int col) const + { return m[row | (col<<2)]; } + + matrix4 & operator *= ( const matrix4 & mat ) + { + mult_right( mat ); + return *this; + } + + matrix4 & operator *= ( const real & r ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) *= r; + element(1,i) *= r; + element(2,i) *= r; + element(3,i) *= r; + } + return *this; + } + + matrix4 & operator += ( const matrix4 & mat ) + { + for (int i = 0; i < 4; ++i) + { + element(0,i) += mat.element(0,i); + element(1,i) += mat.element(1,i); + element(2,i) += mat.element(2,i); + element(3,i) += mat.element(3,i); + } + return *this; + } + + friend matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator == ( const matrix4 & m1, const matrix4 & m2 ); + friend bool operator != ( const matrix4 & m1, const matrix4 & m2 ); + + //protected: + real m[16]; + }; + + inline + matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 ) + { + matrix4 product; + + product = m1; + product.mult_right(m2); + + return product; + } + + inline + bool operator ==( const matrix4 &m1, const matrix4 &m2 ) + { + return ( + m1(0,0) == m2(0,0) && + m1(0,1) == m2(0,1) && + m1(0,2) == m2(0,2) && + m1(0,3) == m2(0,3) && + m1(1,0) == m2(1,0) && + m1(1,1) == m2(1,1) && + m1(1,2) == m2(1,2) && + m1(1,3) == m2(1,3) && + m1(2,0) == m2(2,0) && + m1(2,1) == m2(2,1) && + m1(2,2) == m2(2,2) && + m1(2,3) == m2(2,3) && + m1(3,0) == m2(3,0) && + m1(3,1) == m2(3,1) && + m1(3,2) == m2(3,2) && + m1(3,3) == m2(3,3) ); + } + + inline + bool operator != ( const matrix4 & m1, const matrix4 & m2 ) + { return !( m1 == m2 ); } + + + + + + + + + + + + + + class quaternion + { + public: + + quaternion() + { + *this = identity(); + } + + quaternion( const real v[4] ) + { + set_value( v ); + } + + + quaternion( real q0, real q1, real q2, real q3 ) + { + set_value( q0, q1, q2, q3 ); + } + + + quaternion( const matrix4 & m ) + { + set_value( m ); + } + + + quaternion( const vec3 &axis, real radians ) + { + set_value( axis, radians ); + } + + + quaternion( const vec3 &rotateFrom, const vec3 &rotateTo ) + { + set_value( rotateFrom, rotateTo ); + } + + quaternion( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3& to_up) + { + set_value(from_look, from_up, to_look, to_up); + } + + const real * get_value() const + { + return &q[0]; + } + + void get_value( real &q0, real &q1, real &q2, real &q3 ) const + { + q0 = q[0]; + q1 = q[1]; + q2 = q[2]; + q3 = q[3]; + } + + quaternion & set_value( real q0, real q1, real q2, real q3 ) + { + q[0] = q0; + q[1] = q1; + q[2] = q2; + q[3] = q3; + counter = 0; + return *this; + } + + void get_value( vec3 &axis, real &radians ) const + { + radians = real(acos( q[3] ) * GLH_TWO); + if ( radians == GLH_ZERO ) + axis = vec3( 0.0, 0.0, 1.0 ); + else + { + axis.v[0] = q[0]; + axis.v[1] = q[1]; + axis.v[2] = q[2]; + axis.normalize(); + } + } + + void get_value( matrix4 & m ) const + { + real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz; + + real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; + + s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm ); + + xs = q[0] * s; + ys = q[1] * s; + zs = q[2] * s; + + wx = q[3] * xs; + wy = q[3] * ys; + wz = q[3] * zs; + + xx = q[0] * xs; + xy = q[0] * ys; + xz = q[0] * zs; + + yy = q[1] * ys; + yz = q[1] * zs; + zz = q[2] * zs; + + m(0,0) = real( GLH_ONE - ( yy + zz )); + m(1,0) = real ( xy + wz ); + m(2,0) = real ( xz - wy ); + + m(0,1) = real ( xy - wz ); + m(1,1) = real ( GLH_ONE - ( xx + zz )); + m(2,1) = real ( yz + wx ); + + m(0,2) = real ( xz + wy ); + m(1,2) = real ( yz - wx ); + m(2,2) = real ( GLH_ONE - ( xx + yy )); + + m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO; + m(3,3) = GLH_ONE; + } + + quaternion & set_value( const real * qp ) + { + memcpy(q,qp,sizeof(real) * 4); + + counter = 0; + return *this; + } + + quaternion & set_value( const matrix4 & m ) + { + real tr, s; + int i, j, k; + const int nxt[3] = { 1, 2, 0 }; + + tr = m(0,0) + m(1,1) + m(2,2); + + if ( tr > GLH_ZERO ) + { + s = real(sqrt( tr + m(3,3) )); + q[3] = real ( s * 0.5 ); + s = real(0.5) / s; + + q[0] = real ( ( m(1,2) - m(2,1) ) * s ); + q[1] = real ( ( m(2,0) - m(0,2) ) * s ); + q[2] = real ( ( m(0,1) - m(1,0) ) * s ); + } + else + { + i = 0; + if ( m(1,1) > m(0,0) ) + i = 1; + + if ( m(2,2) > m(i,i) ) + i = 2; + + j = nxt[i]; + k = nxt[j]; + + s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE )); + + q[i] = real ( s * 0.5 ); + s = real(0.5 / s); + + q[3] = real ( ( m(j,k) - m(k,j) ) * s ); + q[j] = real ( ( m(i,j) + m(j,i) ) * s ); + q[k] = real ( ( m(i,k) + m(k,i) ) * s ); + } + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 &axis, real theta ) + { + real sqnorm = axis.square_norm(); + + if (sqnorm <= GLH_EPSILON) + { + // axis too small. + x = y = z = 0.0; + w = 1.0; + } + else + { + theta *= real(0.5); + real sin_theta = real(sin(theta)); + + if (!equivalent(sqnorm,GLH_ONE)) + sin_theta /= real(sqrt(sqnorm)); + x = sin_theta * axis.v[0]; + y = sin_theta * axis.v[1]; + z = sin_theta * axis.v[2]; + w = real(cos(theta)); + } + return *this; + } + + quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo ) + { + vec3 p1, p2; + real alpha; + + p1 = rotateFrom; + p1.normalize(); + p2 = rotateTo; + p2.normalize(); + + alpha = p1.dot(p2); + + if(equivalent(alpha,GLH_ONE)) + { + *this = identity(); + return *this; + } + + // ensures that the anti-parallel case leads to a positive dot + if(equivalent(alpha,-GLH_ONE)) + { + vec3 v; + + if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2]) + v = vec3(p1.v[1], p1.v[2], p1.v[0]); + else + v = vec3(-p1.v[0], p1.v[1], p1.v[2]); + + v -= p1 * p1.dot(v); + v.normalize(); + + set_value(v, GLH_PI); + return *this; + } + + p1 = p1.cross(p2); + p1.normalize(); + set_value(p1,real(acos(alpha))); + + counter = 0; + return *this; + } + + quaternion & set_value( const vec3 & from_look, const vec3 & from_up, + const vec3 & to_look, const vec3 & to_up) + { + quaternion r_look = quaternion(from_look, to_look); + + vec3 rotated_from_up(from_up); + r_look.mult_vec(rotated_from_up); + + quaternion r_twist = quaternion(rotated_from_up, to_up); + + *this = r_twist; + *this *= r_look; + return *this; + } + + quaternion & operator *= ( const quaternion & qr ) + { + quaternion ql(*this); + + w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z; + x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y; + y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z; + z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x; + + counter += qr.counter; + counter++; + counter_normalize(); + return *this; + } + + void normalize() + { + real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z)); + if (equivalent(rnorm, GLH_ZERO)) + return; + x *= rnorm; + y *= rnorm; + z *= rnorm; + w *= rnorm; + counter = 0; + } + + friend bool operator == ( const quaternion & q1, const quaternion & q2 ); + + friend bool operator != ( const quaternion & q1, const quaternion & q2 ); + + friend quaternion operator * ( const quaternion & q1, const quaternion & q2 ); + + bool equals( const quaternion & r, real tolerance ) const + { + real t; + + t = ( + (q[0]-r.q[0])*(q[0]-r.q[0]) + + (q[1]-r.q[1])*(q[1]-r.q[1]) + + (q[2]-r.q[2])*(q[2]-r.q[2]) + + (q[3]-r.q[3])*(q[3]-r.q[3]) ); + if(t > GLH_EPSILON) + return false; + return 1; + } + + quaternion & conjugate() + { + q[0] *= -GLH_ONE; + q[1] *= -GLH_ONE; + q[2] *= -GLH_ONE; + return *this; + } + + quaternion & invert() + { + return conjugate(); + } + + quaternion inverse() const + { + quaternion r = *this; + return r.invert(); + } + + // + // Quaternion multiplication with cartesian vector + // v' = q*v*q(star) + // + void mult_vec( const vec3 &src, vec3 &dst ) const + { + real v_coef = w * w - x * x - y * y - z * z; + real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z); + real c_coef = GLH_TWO * w; + + dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]); + dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]); + dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]); + } + + void mult_vec( vec3 & src_and_dst) const + { + mult_vec(vec3(src_and_dst), src_and_dst); + } + + void scale_angle( real scaleFactor ) + { + vec3 axis; + real radians; + + get_value(axis, radians); + radians *= scaleFactor; + set_value(axis, radians); + } + + static quaternion slerp( const quaternion & p, const quaternion & q, real alpha ) + { + quaternion r; + + real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; + // if B is on opposite hemisphere from A, use -B instead + + int bflip; + if ( ( bflip = (cos_omega < GLH_ZERO)) ) + cos_omega = -cos_omega; + + // complementary interpolation parameter + real beta = GLH_ONE - alpha; + + if(cos_omega <= GLH_ONE - GLH_EPSILON) + return p; + + real omega = real(acos(cos_omega)); + real one_over_sin_omega = GLH_ONE / real(sin(omega)); + + beta = real(sin(omega*beta) * one_over_sin_omega); + alpha = real(sin(omega*alpha) * one_over_sin_omega); + + if (bflip) + alpha = -alpha; + + r.x = beta * p.q[0]+ alpha * q.q[0]; + r.y = beta * p.q[1]+ alpha * q.q[1]; + r.z = beta * p.q[2]+ alpha * q.q[2]; + r.w = beta * p.q[3]+ alpha * q.q[3]; + return r; + } + + static quaternion identity() + { + static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE ); + return ident; + } + + real & operator []( int i ) + { + assert(i < 4); + return q[i]; + } + + const real & operator []( int i ) const + { + assert(i < 4); + return q[i]; + } + + protected: + + void counter_normalize() + { + if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD) + normalize(); + } + + union + { + struct + { + real q[4]; + }; + struct + { + real x; + real y; + real z; + real w; + }; + }; + + // renormalization counter + unsigned char counter; + }; + + inline + bool operator == ( const quaternion & q1, const quaternion & q2 ) + { + return (equivalent(q1.x, q2.x) && + equivalent(q1.y, q2.y) && + equivalent(q1.z, q2.z) && + equivalent(q1.w, q2.w) ); + } + + inline + bool operator != ( const quaternion & q1, const quaternion & q2 ) + { + return ! ( q1 == q2 ); + } + + inline + quaternion operator * ( const quaternion & q1, const quaternion & q2 ) + { + quaternion r(q1); + r *= q2; + return r; + } + + + + + + + + + + + class plane + { + public: + + plane() + { + planedistance = 0.0; + planenormal.set_value( 0.0, 0.0, 1.0 ); + } + + + plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 ) + { + vec3 v0 = p1 - p0; + vec3 v1 = p2 - p0; + planenormal = v0.cross(v1); + planenormal.normalize(); + planedistance = p0.dot(planenormal); + } + + plane( const vec3 &normal, real distance ) + { + planedistance = distance; + planenormal = normal; + planenormal.normalize(); + } + + plane( const vec3 &normal, const vec3 &point ) + { + planenormal = normal; + planenormal.normalize(); + planedistance = point.dot(planenormal); + } + + void offset( real d ) + { + planedistance += d; + } + + bool intersect( const line &l, vec3 &intersection ) const + { + vec3 pos, dir; + vec3 pn = planenormal; + real pd = planedistance; + + pos = l.get_position(); + dir = l.get_direction(); + + if(dir.dot(pn) == 0.0) return 0; + pos -= pn*pd; + // now we're talking about a plane passing through the origin + if(pos.dot(pn) < 0.0) pn.negate(); + if(dir.dot(pn) > 0.0) dir.negate(); + vec3 ppos = pn * pos.dot(pn); + pos = (ppos.length()/dir.dot(-pn))*dir; + intersection = l.get_position(); + intersection += pos; + return 1; + } + void transform( const matrix4 &matrix ) + { + matrix4 invtr = matrix.inverse(); + invtr = invtr.transpose(); + + vec3 pntOnplane = planenormal * planedistance; + vec3 newPntOnplane; + vec3 newnormal; + + invtr.mult_dir_matrix(planenormal, newnormal); + matrix.mult_vec_matrix(pntOnplane, newPntOnplane); + + newnormal.normalize(); + planenormal = newnormal; + planedistance = newPntOnplane.dot(planenormal); + } + + bool is_in_half_space( const vec3 &point ) const + { + + if(( point.dot(planenormal) - planedistance) < 0.0) + return 0; + return 1; + } + + + real distance( const vec3 & point ) const + { + return planenormal.dot(point - planenormal*planedistance); + } + + const vec3 &get_normal() const + { + return planenormal; + } + + + real get_distance_from_origin() const + { + return planedistance; + } + + + friend bool operator == ( const plane & p1, const plane & p2 ); + + + friend bool operator != ( const plane & p1, const plane & p2 ); + + //protected: + vec3 planenormal; + real planedistance; + }; + + inline + bool operator == (const plane & p1, const plane & p2 ) + { + return ( p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal); + } + + inline + bool operator != ( const plane & p1, const plane & p2 ) + { return ! (p1 == p2); } + + + + } // "ns_##GLH_REAL" + + // make common typedefs... +#ifdef GLH_REAL_IS_FLOAT + typedef GLH_REAL_NAMESPACE::vec2 vec2f; + typedef GLH_REAL_NAMESPACE::vec3 vec3f; + typedef GLH_REAL_NAMESPACE::vec4 vec4f; + typedef GLH_REAL_NAMESPACE::quaternion quaternionf; + typedef GLH_REAL_NAMESPACE::quaternion rotationf; + typedef GLH_REAL_NAMESPACE::line linef; + typedef GLH_REAL_NAMESPACE::plane planef; + typedef GLH_REAL_NAMESPACE::matrix4 matrix4f; +#endif + + + + +} // namespace glh + + + +#endif + -- cgit v1.1