patches/secondlife-01-solaris.diff
author jurikm
Sun, 12 Feb 2012 14:04:10 +0000
changeset 8245 383896da4129
parent 2322 813958f80b98
permissions -rw-r--r--
SFEsauerbraten.spec: add IPS package name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2322
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     1
--- linden/indra/CMakeLists.txt-orig	2010-01-29 11:09:37.792624852 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     2
+++ linden/indra/CMakeLists.txt	2010-01-29 11:14:17.068124489 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     3
@@ -82,8 +82,8 @@ if (VIEWER)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     4
     # add_dependencies(viewer windows-updater windows-setup windows-crash-logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     5
     add_dependencies(viewer windows-updater windows-crash-logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     6
   elseif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     7
-    add_subdirectory(solaris_crash_logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     8
-    add_dependencies(viewer solaris-crash-logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     9
+    #add_subdirectory(solaris_crash_logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    10
+    #add_dependencies(viewer solaris-crash-logger)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    11
   endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    12
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    13
   add_subdirectory(${VIEWER_PREFIX}newview)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    14
--- linden/indra/llrender/llglheaders.h-orig	2010-01-29 11:10:20.876222615 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    15
+++ linden/indra/llrender/llglheaders.h	2010-01-29 11:14:17.083107375 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    16
@@ -237,6 +237,14 @@ extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPR
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    17
 extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    18
 extern PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    19
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    20
+// New functions we need to import for 1.23
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    21
+extern PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    22
+extern PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    23
+extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    24
+extern PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    25
+extern PFNGLBLITFRAMEBUFFEREXTPROC glBlitFramebufferEXT;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    26
+extern PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glRenderbufferStorageMultisampleEXT;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    27
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    28
 #elif LL_MESA
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    29
 //----------------------------------------------------------------------------
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    30
 // MESA headers
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    31
--- linden/indra/develop.py-orig	2010-01-29 11:09:46.037099557 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    32
+++ linden/indra/develop.py	2010-01-29 11:14:17.068714818 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    33
@@ -125,6 +125,7 @@ class PlatformSetup(object):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    34
         #if simple:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    35
         #    return 'cmake %(opts)s %(dir)r' % args
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    36
         return ('cmake -DCMAKE_BUILD_TYPE:STRING=%(type)s '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    37
+                '-DLL_SOLARIS=1'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    38
                 '-DSTANDALONE:BOOL=%(standalone)s '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    39
                 '-DUNATTENDED:BOOL=%(unattended)s '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    40
                 '-G %(generator)r %(opts)s %(dir)r' % args)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    41
@@ -250,6 +251,34 @@ class UnixSetup(PlatformSetup):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    42
             raise CommandError('the command %r %s' %
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    43
                                (name, event))
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    44
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    45
+    def run_build(self, opts, targets):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    46
+        if targets:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    47
+            targets = ' '.join(targets)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    48
+        else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    49
+            targets = 'all'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    50
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    51
+        for d in self.build_dirs():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    52
+            cmd = 'make -C %r %s %s' % (d, ' '.join(opts), targets)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    53
+            print 'Running %r' % cmd
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    54
+            self.run(cmd)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    55
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    56
+class SolarisSetup(UnixSetup):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    57
+    '''Solaris build instructions.'''
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    58
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    59
+    def os(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    60
+        return 'solaris'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    61
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    62
+    def run_build(self, opts, targets):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    63
+        if targets:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    64
+            targets = ' '.join(targets)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    65
+        else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    66
+            targets = 'all'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    67
+        numprocs = len(os.popen('/usr/sbin/psrinfo').readlines())
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    68
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    69
+        for d in self.build_dirs():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    70
+            cmd = 'make -j %d -C %r %s %s' % (numprocs, d, ' '.join(opts), targets)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    71
+            print 'Running %r' % cmd
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    72
+            self.run(cmd)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    73
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    74
 class LinuxSetup(UnixSetup):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    75
     def __init__(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    76
@@ -633,7 +662,8 @@ setup_platform = {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    77
     'darwin': DarwinSetup,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    78
     'linux2': LinuxSetup,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    79
     'win32' : WindowsSetup,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    80
-    'cygwin' : CygwinSetup
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    81
+    'cygwin' : CygwinSetup,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    82
+    'sunos5' : SolarisSetup
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    83
     }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    84
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    85
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    86
--- linden/indra/cmake/FindBerkeleyDB.cmake-orig	2010-01-29 11:08:35.595380962 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    87
+++ linden/indra/cmake/FindBerkeleyDB.cmake	2010-01-29 11:14:17.066472366 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    88
@@ -14,12 +14,13 @@ FIND_PATH(DB_INCLUDE_DIR db.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    89
 /usr/local/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    90
 /usr/include/db4
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    91
 /usr/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    92
+/usr/gnu/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    93
 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    94
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    95
 SET(DB_NAMES ${DB_NAMES} db)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    96
 FIND_LIBRARY(DB_LIBRARY
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    97
   NAMES ${DB_NAMES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    98
-  PATHS /usr/lib /usr/local/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    99
+  PATHS /usr/lib /usr/local/lib /usr/gnu/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   100
   )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   101
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   102
 IF (DB_LIBRARY AND DB_INCLUDE_DIR)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   103
--- linden/indra/cmake/OpenSSL.cmake-orig	2010-01-29 11:08:57.850769307 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   104
+++ linden/indra/cmake/OpenSSL.cmake	2010-01-29 11:14:17.067085760 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   105
@@ -16,8 +16,8 @@ else (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   106
   set(OPENSSL_INCLUDE_DIRS ${LIBS_PREBUILT_DIR}/${LL_ARCH_DIR}/include)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   107
 endif (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   108
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   109
-if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   110
+if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   111
   set(CRYPTO_LIBRARIES crypto)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   112
 elseif (DARWIN)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   113
   set(CRYPTO_LIBRARIES llcrypto)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   114
-endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   115
+endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   116
--- linden/indra/cmake/UI.cmake-orig	2010-01-29 11:09:05.423337850 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   117
+++ linden/indra/cmake/UI.cmake	2010-01-29 11:14:17.067504644 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   118
@@ -4,7 +4,7 @@ include(Prebuilt)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   119
 if (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   120
   include(FindPkgConfig)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   121
     
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   122
-  if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   123
+  if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   124
     set(PKGCONFIG_PACKAGES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   125
         atk
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   126
         cairo
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   127
@@ -21,7 +21,7 @@ if (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   128
         pangoxft
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   129
         sdl
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   130
         )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   131
-  endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   132
+  endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   133
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   134
   foreach(pkg ${PKGCONFIG_PACKAGES})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   135
     pkg_check_modules(${pkg} REQUIRED ${pkg})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   136
@@ -32,7 +32,7 @@ if (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   137
   endforeach(pkg)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   138
 else (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   139
   use_prebuilt_binary(gtk-atk-pango-glib)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   140
-  if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   141
+  if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   142
     set(UI_LIBRARIES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   143
         atk-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   144
         gdk-x11-2.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   145
@@ -48,7 +48,7 @@ else (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   146
         pangox-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   147
         pangoxft-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   148
         )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   149
-  endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   150
+  endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   151
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   152
   include_directories (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   153
       ${LIBS_PREBUILT_DIR}/${LL_ARCH_DIR}/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   154
@@ -59,6 +59,6 @@ else (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   155
   endforeach(include)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   156
 endif (STANDALONE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   157
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   158
-if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   159
+if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   160
   add_definitions(-DLL_GTK=1 -DLL_X11=1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   161
-endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   162
+endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   163
--- linden/indra/cmake/00-Common.cmake-orig	2010-01-29 11:07:55.578903634 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   164
+++ linden/indra/cmake/00-Common.cmake	2010-01-29 11:14:17.065779932 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   165
@@ -169,6 +169,30 @@ if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   166
 endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   167
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   168
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   169
+if (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   170
+  add_definitions(
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   171
+      -DLL_SOLARIS=1
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   172
+      -D_REENTRANT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   173
+      -fexceptions
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   174
+      -fno-math-errno
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   175
+      -fno-strict-aliasing
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   176
+      -fsigned-char
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   177
+      -g
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   178
+      )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   179
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   180
+  if (VIEWER)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   181
+    add_definitions(-DAPPID=secondlife)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   182
+    # don't catch SIGCHLD in our base application class for the viewer - some of our 3rd party libs may need their *own* SIGCHLD handler to work.  Sigh!  The viewer doesn't need to catch SIGCHLD anyway.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   183
+    add_definitions(-DLL_IGNORE_SIGCHLD)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   184
+  endif (VIEWER)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   185
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   186
+#  include_directories(/usr/apr/1.3/include /usr/local/include/boost-1_39)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   187
+#  link_directories(/usr/apr/1.3/lib)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   188
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   189
+  set(CMAKE_CXX_FLAGS_DEBUG "-fno-inline ${CMAKE_CXX_FLAGS_DEBUG}")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   190
+  set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${CMAKE_CXX_FLAGS_RELEASE}")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   191
+endif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   192
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   193
 if (DARWIN)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   194
   add_definitions(-DLL_DARWIN=1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   195
   set(CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names,-search_paths_first")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   196
--- linden/indra/cmake/Variables.cmake-orig	2010-01-29 11:09:19.238711718 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   197
+++ linden/indra/cmake/Variables.cmake	2010-01-29 11:14:17.067813869 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   198
@@ -55,6 +55,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux"
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   199
   set(LL_ARCH_DIR ${ARCH}-linux)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   200
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   201
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   202
+if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   203
+  set(SOLARIS ON BOOl FORCE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   204
+  execute_process(COMMAND uname -p
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   205
+                  OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   206
+  set(LL_ARCH ${ARCH}_solaris)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   207
+  set(LL_ARCH_DIR ${ARCH}-solaris)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   208
+endif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   209
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   210
 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   211
   set(DARWIN 1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   212
   # set this dynamically from the build system now -
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   213
@@ -82,7 +90,7 @@ set(VIEWER ON CACHE BOOL "Build Second L
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   214
 set(VIEWER_CHANNEL "Developer" CACHE STRING "Viewer Channel Name")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   215
 set(VIEWER_LOGIN_CHANNEL ${VIEWER_CHANNEL} CACHE STRING "Fake login channel for A/B Testing")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   216
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   217
-set(STANDALONE OFF CACHE BOOL "Do not use Linden-supplied prebuilt libraries.")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   218
+set(STANDALONE ON CACHE BOOL "Do not use Linden-supplied prebuilt libraries.")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   219
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   220
 if (NOT STANDALONE AND EXISTS ${CMAKE_SOURCE_DIR}/llphysics)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   221
     set(SERVER ON CACHE BOOL "Build Second Life server software.")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   222
--- linden/indra/cmake/Linking.cmake-orig	2010-01-29 11:08:44.421209512 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   223
+++ linden/indra/cmake/Linking.cmake	2010-01-29 11:14:17.066788374 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   224
@@ -30,6 +30,10 @@ else (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   225
   set(PTHREAD_LIBRARY "")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   226
 endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   227
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   228
+if (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   229
+  set(SOLARIS_LIBRARIES kstat)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   230
+endif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   231
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   232
 if (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   233
   set(WINDOWS_LIBRARIES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   234
       advapi32
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   235
@@ -47,4 +51,4 @@ else (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   236
   set(WINDOWS_LIBRARIES "")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   237
 endif (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   238
     
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   239
-mark_as_advanced(DL_LIBRARY PTHREAD_LIBRARY WINDOWS_LIBRARIES)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   240
+mark_as_advanced(DL_LIBRARY SOLARIS_LIBRARIES PTHREAD_LIBRARY WINDOWS_LIBRARIES)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   241
--- linden/indra/cmake/FindAPR.cmake-orig	2010-01-29 11:08:17.314175147 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   242
+++ linden/indra/cmake/FindAPR.cmake	2010-01-29 11:14:17.066164093 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   243
@@ -16,12 +16,13 @@ FIND_PATH(APR_INCLUDE_DIR apr.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   244
 /usr/local/include/apr-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   245
 /usr/include/apr-1
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   246
 /usr/include/apr-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   247
+/usr/apr/1.3/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   248
 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   249
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   250
 SET(APR_NAMES ${APR_NAMES} apr-1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   251
 FIND_LIBRARY(APR_LIBRARY
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   252
   NAMES ${APR_NAMES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   253
-  PATHS /usr/lib /usr/local/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   254
+  PATHS /usr/lib /usr/local/lib /usr/apr/1.3/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   255
   )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   256
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   257
 IF (APR_LIBRARY AND APR_INCLUDE_DIR)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   258
@@ -58,12 +59,13 @@ FIND_PATH(APRUTIL_INCLUDE_DIR apu.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   259
 /usr/local/include/apr-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   260
 /usr/include/apr-1
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   261
 /usr/include/apr-1.0
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   262
+/usr/apr-util/1.3/include
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   263
 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   264
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   265
 SET(APRUTIL_NAMES ${APRUTIL_NAMES} aprutil-1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   266
 FIND_LIBRARY(APRUTIL_LIBRARY
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   267
   NAMES ${APRUTIL_NAMES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   268
-  PATHS /usr/lib /usr/local/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   269
+  PATHS /usr/lib /usr/local/lib /usr/apr-util/1.3/lib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   270
   )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   271
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   272
 IF (APRUTIL_LIBRARY AND APRUTIL_INCLUDE_DIR)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   273
--- linden/indra/newview/CMakeLists.txt-orig	2010-01-29 11:10:50.042671388 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   274
+++ linden/indra/newview/CMakeLists.txt	2010-01-29 11:14:17.084572523 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   275
@@ -909,6 +909,15 @@ if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   276
         )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   277
 endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   278
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   279
+if (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   280
+    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux.cpp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   281
+    LIST(APPEND viewer_SOURCE_FILES llappviewerlinux_api_dbus.cpp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   282
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   283
+    set(viewer_LIBRARIES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   284
+        Xinerama
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   285
+        )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   286
+endif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   287
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   288
 if (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   289
     list(APPEND viewer_SOURCE_FILES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   290
          llappviewerwin32.cpp
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   291
@@ -1446,6 +1455,7 @@ target_link_libraries(${VIEWER_BINARY_NA
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   292
     ${UI_LIBRARIES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   293
     ${QUICKTIME_LIBRARY}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   294
     ${WINDOWS_LIBRARIES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   295
+    ${SOLARIS_LIBRARIES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   296
     ${XMLRPCEPI_LIBRARIES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   297
     ${ELFIO_LIBRARIES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   298
     )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   299
@@ -1456,10 +1466,10 @@ set(ARTWORK_DIR ${CMAKE_CURRENT_SOURCE_D
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   300
     "Path to artwork files.")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   301
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   302
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   303
-if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   304
+if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   305
   add_custom_command(
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   306
       OUTPUT secondlife-stripped
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   307
-      COMMAND strip
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   308
+      COMMAND /usr/gnu/bin/strip
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   309
       ARGS --strip-debug -o secondlife-stripped ${VIEWER_BINARY_NAME}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   310
       DEPENDS ${VIEWER_BINARY_NAME}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   311
       )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   312
@@ -1488,7 +1498,7 @@ if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   313
     add_custom_target(package ALL DEPENDS ${product}.tar.bz2)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   314
     add_dependencies(package linux-crash-logger-strip-target)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   315
   endif (NOT INSTALL)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   316
-endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   317
+endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   318
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   319
 if (DARWIN)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   320
   set(product "Second Life")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   321
--- linden/indra/newview/viewer_manifest.py-orig	2010-01-29 11:11:05.053024923 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   322
+++ linden/indra/newview/viewer_manifest.py	2010-01-29 11:14:17.085731156 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   323
@@ -580,6 +580,126 @@ class DarwinManifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   324
         self.package_file = finalname
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   325
         self.remove(sparsename)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   326
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   327
+class SolarisManifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   328
+    def construct(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   329
+#        super(LinuxManifest, self).construct()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   330
+        self.path("secondlife-stripped","bin/do-not-directly-run-secondlife-bin")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   331
+        self.path("licenses-linux.txt","licenses.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   332
+        self.path("res/ll_icon.png","secondlife_icon.png")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   333
+        if self.prefix("linux_tools", dst=""):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   334
+            self.path("client-readme.txt","README-linux.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   335
+            self.path("client-readme-voice.txt","README-linux-voice.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   336
+            self.path("client-readme-joystick.txt","README-linux-joystick.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   337
+            self.path("wrapper.sh","secondlife")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   338
+            self.path("handle_secondlifeprotocol.sh")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   339
+            self.path("register_secondlifeprotocol.sh")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   340
+            self.end_prefix("linux_tools")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   341
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   342
+        # Create an appropriate gridargs.dat for this package, denoting required grid.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   343
+        self.put_in_file(self.flags_list(), 'gridargs.dat')
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   344
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   345
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   346
+    def package_finish(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   347
+        if 'installer_name' in self.args:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   348
+            installer_name = self.args['installer_name']
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   349
+        else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   350
+            installer_name_components = ['SecondLife_', self.args.get('arch')]
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   351
+            installer_name_components.extend(self.args['version'])
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   352
+            installer_name = "_".join(installer_name_components)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   353
+            if self.default_channel():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   354
+                if not self.default_grid():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   355
+                    installer_name += '_' + self.args['grid'].upper()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   356
+            else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   357
+                installer_name += '_' + self.channel_oneword().upper()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   358
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   359
+        # Fix access permissions
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   360
+        self.run_command("""
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   361
+                find %(dst)s -type d | /usr/gnu/bin/xargs --no-run-if-empty chmod 755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   362
+                find %(dst)s -type f -perm 0700 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   363
+                find %(dst)s -type f -perm 0500 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0555;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   364
+                find %(dst)s -type f -perm 0600 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0644;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   365
+                find %(dst)s -type f -perm 0400 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0444;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   366
+                true""" %  {'dst':self.get_dst_prefix() })
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   367
+        self.package_file = installer_name + '.tar.bz2'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   368
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   369
+        # temporarily move directory tree so that it has the right
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   370
+        # name in the tarfile
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   371
+        self.run_command("mv %(dst)s %(inst)s" % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   372
+            'dst': self.get_dst_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   373
+            'inst': self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   374
+        try:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   375
+            # --numeric-owner hides the username of the builder for
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   376
+            # security etc.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   377
+            self.run_command('/usr/gnu/bin/tar -C %(dir)s --numeric-owner -cjf '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   378
+                             '%(inst_path)s.tar.bz2 %(inst_name)s' % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   379
+                'dir': self.get_build_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   380
+                'inst_name': installer_name,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   381
+                'inst_path':self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   382
+        finally:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   383
+            self.run_command("mv %(inst)s %(dst)s" % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   384
+                'dst': self.get_dst_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   385
+                'inst': self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   386
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   387
+class Solaris_i386Manifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   388
+    def construct(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   389
+#        super(LinuxManifest, self).construct()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   390
+        self.path("secondlife-stripped","bin/do-not-directly-run-secondlife-bin")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   391
+        self.path("licenses-linux.txt","licenses.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   392
+        self.path("res/ll_icon.png","secondlife_icon.png")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   393
+        if self.prefix("linux_tools", dst=""):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   394
+            self.path("client-readme.txt","README-linux.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   395
+            self.path("client-readme-voice.txt","README-linux-voice.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   396
+            self.path("client-readme-joystick.txt","README-linux-joystick.txt")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   397
+            self.path("wrapper.sh","secondlife")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   398
+            self.path("handle_secondlifeprotocol.sh")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   399
+            self.path("register_secondlifeprotocol.sh")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   400
+            self.end_prefix("linux_tools")
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   401
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   402
+        # Create an appropriate gridargs.dat for this package, denoting required grid.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   403
+        self.put_in_file(self.flags_list(), 'gridargs.dat')
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   404
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   405
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   406
+    def package_finish(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   407
+        if 'installer_name' in self.args:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   408
+            installer_name = self.args['installer_name']
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   409
+        else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   410
+            installer_name_components = ['SecondLife_', self.args.get('arch')]
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   411
+            installer_name_components.extend(self.args['version'])
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   412
+            installer_name = "_".join(installer_name_components)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   413
+            if self.default_channel():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   414
+                if not self.default_grid():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   415
+                    installer_name += '_' + self.args['grid'].upper()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   416
+            else:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   417
+                installer_name += '_' + self.channel_oneword().upper()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   418
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   419
+        # Fix access permissions
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   420
+        self.run_command("""
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   421
+                find %(dst)s -type d | /usr/gnu/bin/xargs --no-run-if-empty chmod 755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   422
+                find %(dst)s -type f -perm 0700 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   423
+                find %(dst)s -type f -perm 0500 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0555;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   424
+                find %(dst)s -type f -perm 0600 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0644;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   425
+                find %(dst)s -type f -perm 0400 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0444;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   426
+                true""" %  {'dst':self.get_dst_prefix() })
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   427
+        self.package_file = installer_name + '.tar.bz2'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   428
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   429
+        # temporarily move directory tree so that it has the right
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   430
+        # name in the tarfile
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   431
+        self.run_command("mv %(dst)s %(inst)s" % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   432
+            'dst': self.get_dst_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   433
+            'inst': self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   434
+        try:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   435
+            # --numeric-owner hides the username of the builder for
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   436
+            # security etc.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   437
+            self.run_command('/usr/gnu/bin/tar -C %(dir)s --numeric-owner -cjf '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   438
+                             '%(inst_path)s.tar.bz2 %(inst_name)s' % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   439
+                'dir': self.get_build_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   440
+                'inst_name': installer_name,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   441
+                'inst_path':self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   442
+        finally:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   443
+            self.run_command("mv %(inst)s %(dst)s" % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   444
+                'dst': self.get_dst_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   445
+                'inst': self.build_path_of(installer_name)})
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   446
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   447
 class LinuxManifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   448
     def construct(self):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   449
         super(LinuxManifest, self).construct()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   450
@@ -613,11 +733,11 @@ class LinuxManifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   451
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   452
         # Fix access permissions
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   453
         self.run_command("""
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   454
-                find %(dst)s -type d | xargs --no-run-if-empty chmod 755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   455
-                find %(dst)s -type f -perm 0700 | xargs --no-run-if-empty chmod 0755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   456
-                find %(dst)s -type f -perm 0500 | xargs --no-run-if-empty chmod 0555;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   457
-                find %(dst)s -type f -perm 0600 | xargs --no-run-if-empty chmod 0644;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   458
-                find %(dst)s -type f -perm 0400 | xargs --no-run-if-empty chmod 0444;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   459
+                find %(dst)s -type d | /usr/gnu/bin/xargs --no-run-if-empty chmod 755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   460
+                find %(dst)s -type f -perm 0700 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0755;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   461
+                find %(dst)s -type f -perm 0500 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0555;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   462
+                find %(dst)s -type f -perm 0600 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0644;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   463
+                find %(dst)s -type f -perm 0400 | /usr/gnu/bin/xargs --no-run-if-empty chmod 0444;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   464
                 true""" %  {'dst':self.get_dst_prefix() })
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   465
         self.package_file = installer_name + '.tar.bz2'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   466
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   467
@@ -629,7 +749,7 @@ class LinuxManifest(ViewerManifest):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   468
         try:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   469
             # --numeric-owner hides the username of the builder for
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   470
             # security etc.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   471
-            self.run_command('tar -C %(dir)s --numeric-owner -cjf '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   472
+            self.run_command('/usr/gnu/bin/tar -C %(dir)s --numeric-owner -cjf '
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   473
                              '%(inst_path)s.tar.bz2 %(inst_name)s' % {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   474
                 'dir': self.get_build_prefix(),
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   475
                 'inst_name': installer_name,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   476
--- linden/indra/llvfs/CMakeLists.txt-orig	2010-01-29 11:10:32.894768126 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   477
+++ linden/indra/llvfs/CMakeLists.txt	2010-01-29 11:14:17.083390931 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   478
@@ -47,6 +47,18 @@ if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   479
   endif (VIEWER AND INSTALL)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   480
 endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   481
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   482
+if (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   483
+  LIST(APPEND llvfs_SOURCE_FILES lldir_solaris.cpp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   484
+  LIST(APPEND llvfs_HEADER_FILES lldir_solaris.h)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   485
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   486
+  if (VIEWER AND INSTALL)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   487
+    set_source_files_properties(lldir_solaris.cpp
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   488
+                                PROPERTIES COMPILE_FLAGS
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   489
+                                "-DAPP_RO_DATA_DIR=\\\"${APP_SHARE_DIR}\\\""
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   490
+                                )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   491
+  endif (VIEWER AND INSTALL)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   492
+endif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   493
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   494
 if (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   495
   LIST(APPEND llvfs_SOURCE_FILES lldir_win32.cpp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   496
   LIST(APPEND llvfs_HEADER_FILES lldir_win32.h)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   497
--- linden/indra/llwindow/CMakeLists.txt-orig	2010-01-29 11:10:41.592412053 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   498
+++ linden/indra/llwindow/CMakeLists.txt	2010-01-29 11:14:17.083744714 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   499
@@ -75,7 +75,7 @@ if (DARWIN)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   500
       )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   501
 endif (DARWIN)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   502
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   503
-if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   504
+if (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   505
   list(APPEND viewer_SOURCE_FILES 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   506
        llkeyboardsdl.cpp 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   507
        llwindowsdl.cpp
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   508
@@ -84,7 +84,7 @@ if (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   509
        llkeyboardsdl.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   510
        llwindowsdl.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   511
        )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   512
-endif (LINUX)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   513
+endif (LINUX OR SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   514
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   515
 if (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   516
   list(APPEND llwindow_SOURCE_FILES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   517
@@ -99,15 +99,6 @@ if (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   518
        )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   519
 endif (WINDOWS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   520
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   521
-if (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   522
-  list(APPEND llwindow_SOURCE_FILES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   523
-       llwindowsolaris.cpp
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   524
-       )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   525
-  list(APPEND llwindow_HEADER_FILES
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   526
-       llwindowsolaris.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   527
-       )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   528
-endif (SOLARIS)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   529
-
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   530
 set_source_files_properties(${llwindow_HEADER_FILES}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   531
                             PROPERTIES HEADER_FILE_ONLY TRUE)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   532
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   533
--- linden/indra/lib/python/indra/base/lluuid.py-orig	2010-01-29 11:10:05.817408166 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   534
+++ linden/indra/lib/python/indra/base/lluuid.py	2010-01-29 11:14:17.069104814 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   535
@@ -26,7 +26,7 @@ THE SOFTWARE.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   536
 $/LicenseInfo$
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   537
 """
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   538
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   539
-import md5, random, socket, string, time, re
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   540
+import hashlib, random, socket, string, time, re
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   541
 import uuid
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   542
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   543
 def _int2binstr(i,l):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   544
--- linden/scripts/install.py-orig	2010-01-29 11:11:15.019904165 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   545
+++ linden/scripts/install.py	2010-01-29 11:14:17.086602680 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   546
@@ -64,7 +64,7 @@ def add_indra_lib_path():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   547
 base_dir = add_indra_lib_path()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   548
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   549
 import copy
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   550
-import md5
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   551
+import hashlib
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   552
 import optparse
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   553
 import os
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   554
 import platform
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   555
@@ -75,7 +75,7 @@ import tempfile
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   556
 import urllib2
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   557
 import urlparse
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   558
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   559
-from sets import Set as set, ImmutableSet as frozenset
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   560
+#from sets import Set as set, ImmutableSet as frozenset
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   561
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   562
 from indra.base import llsd
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   563
 from indra.util import helpformatter
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   564
@@ -771,7 +771,7 @@ def _get_platform():
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   565
         'linux2': 'linux',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   566
         'win32' : 'windows',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   567
         'cygwin' : 'windows',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   568
-        'solaris' : 'solaris'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   569
+        'sunos5' : 'solaris'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   570
         }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   571
     this_platform = platform_map[sys.platform]
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   572
     if this_platform == 'linux':
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   573
--- linden/indra/llcommon/lluuid.cpp-orig	2010-01-29 12:29:20.844939652 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   574
+++ linden/indra/llcommon/lluuid.cpp	2010-01-29 12:29:49.450327413 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   575
@@ -660,11 +660,6 @@ S32 LLUUID::getNodeID(unsigned char *nod
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   576
 	for (i = 0; i < n; i+= ifreq_size(*ifr) ) {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   577
 		ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   578
 		strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);		/* Flawfinder: ignore */
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   579
-#ifdef SIOCGIFHWADDR
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   580
-		if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   581
-			continue;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   582
-		a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   583
-#else
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   584
 #ifdef SIOCGENADDR
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   585
 		if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   586
 			continue;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   587
@@ -677,7 +672,6 @@ S32 LLUUID::getNodeID(unsigned char *nod
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   588
 		close(sd);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   589
 		return 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   590
 #endif /* SIOCGENADDR */
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   591
-#endif /* SIOCGIFHWADDR */
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   592
 		if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   593
 			continue;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   594
 		if (node_id) {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   595
--- linden/indra/lib/python/indra/util/llmanifest.py-orig	2010-01-31 14:37:45.187425944 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   596
+++ linden/indra/lib/python/indra/util/llmanifest.py	2010-01-31 15:16:58.499189180 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   597
@@ -72,7 +72,8 @@ def get_default_platform(dummy):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   598
             'linux1':'linux',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   599
             'cygwin':'windows',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   600
             'win32':'windows',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   601
-            'darwin':'darwin'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   602
+            'darwin':'darwin',
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   603
+            'sunos5':'solaris'
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   604
             }[sys.platform]
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   605
 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   606
 def get_default_version(srctree):
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   607
--- /dev/null	2010-01-31 19:18:37.000000000 -0600
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   608
+++ linden-old/indra/llwindow/glh/glh_linear.h	2009-10-14 14:09:25.000000000 -0500
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   609
@@ -0,0 +1,1621 @@
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   610
+/*
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   611
+    glh - is a platform-indepenedent C++ OpenGL helper library 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   612
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   613
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   614
+    Copyright (c) 2000 Cass Everitt
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   615
+	Copyright (c) 2000 NVIDIA Corporation
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   616
+    All rights reserved.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   617
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   618
+    Redistribution and use in source and binary forms, with or
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   619
+	without modification, are permitted provided that the following
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   620
+	conditions are met:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   621
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   622
+     * Redistributions of source code must retain the above
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   623
+	   copyright notice, this list of conditions and the following
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   624
+	   disclaimer.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   625
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   626
+     * Redistributions in binary form must reproduce the above
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   627
+	   copyright notice, this list of conditions and the following
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   628
+	   disclaimer in the documentation and/or other materials
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   629
+	   provided with the distribution.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   630
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   631
+     * The names of contributors to this software may not be used
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   632
+	   to endorse or promote products derived from this software
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   633
+	   without specific prior written permission. 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   634
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   635
+       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   636
+	   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   637
+	   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   638
+	   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   639
+	   REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   640
+	   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   641
+	   BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   642
+	   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   643
+	   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   644
+	   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   645
+	   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   646
+	   POSSIBILITY OF SUCH DAMAGE. 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   647
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   648
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   649
+    Cass Everitt - [email protected]
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   650
+*/
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   651
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   652
+/*
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   653
+glh_linear.h
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   654
+*/
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   655
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   656
+// Author:  Cass W. Everitt
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   657
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   658
+#ifndef GLH_LINEAR_H
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   659
+#define GLH_LINEAR_H
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   660
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   661
+#include <memory.h>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   662
+#include <math.h>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   663
+#include <assert.h>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   664
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   665
+// only supports float for now...
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   666
+#define GLH_REAL_IS_FLOAT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   667
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   668
+#ifdef GLH_REAL_IS_FLOAT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   669
+# define GLH_REAL float
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   670
+# define GLH_REAL_NAMESPACE ns_float
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   671
+#endif
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   672
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   673
+#define     GLH_QUATERNION_NORMALIZATION_THRESHOLD  64
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   674
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   675
+#define     GLH_RAD_TO_DEG      GLH_REAL(57.2957795130823208767981548141052)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   676
+#define     GLH_DEG_TO_RAD      GLH_REAL(0.0174532925199432957692369076848861)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   677
+#define     GLH_ZERO            GLH_REAL(0.0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   678
+#define     GLH_ONE             GLH_REAL(1.0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   679
+#define     GLH_TWO             GLH_REAL(2.0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   680
+#define     GLH_EPSILON         GLH_REAL(10e-6)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   681
+#define     GLH_PI              GLH_REAL(3.1415926535897932384626433832795)    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   682
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   683
+#define     equivalent(a,b)     (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   684
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   685
+namespace glh
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   686
+{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   687
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   688
+	inline GLH_REAL to_degrees(GLH_REAL radians) { return radians*GLH_RAD_TO_DEG; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   689
+	inline GLH_REAL to_radians(GLH_REAL degrees) { return degrees*GLH_DEG_TO_RAD; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   690
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   691
+	// forward declarations for friend template functions.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   692
+	template <int N, class T> class vec;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   693
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   694
+	// forward declarations for friend template functions.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   695
+	template <int N, class T>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   696
+		bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   697
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   698
+	// forward declarations for friend template functions.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   699
+	template <int N, class T>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   700
+		bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   701
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   702
+	template <int N, class T>	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   703
+	class vec
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   704
+	{				
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   705
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   706
+		int size() const { return N; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   707
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   708
+		vec(const T & t = T()) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   709
+		{ for(int i = 0; i < N; i++) v[i] = t; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   710
+		vec(const T * tp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   711
+		{ for(int i = 0; i < N; i++) v[i] = tp[i]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   712
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   713
+		const T * get_value() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   714
+		{ return v; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   715
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   716
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   717
+		T dot( const vec<N,T> & rhs ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   718
+		{ 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   719
+			T r = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   720
+			for(int i = 0; i < N; i++) r += v[i]*rhs.v[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   721
+			return r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   722
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   723
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   724
+		T length() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   725
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   726
+			T r = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   727
+			for(int i = 0; i < N; i++) r += v[i]*v[i]; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   728
+			return T(sqrt(r));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   729
+		}	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   730
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   731
+		T square_norm() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   732
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   733
+			T r = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   734
+			for(int i = 0; i < N; i++) r += v[i]*v[i]; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   735
+			return r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   736
+		}	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   737
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   738
+		void  negate()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   739
+		{ for(int i = 0; i < N; i++) v[i] = -v[i]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   740
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   741
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   742
+		T normalize() 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   743
+		{ 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   744
+			T sum(0);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   745
+			for(int i = 0; i < N; i++) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   746
+                sum += v[i]*v[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   747
+			sum = T(sqrt(sum));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   748
+            if (sum > GLH_EPSILON)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   749
+			    for(int i = 0; i < N; i++) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   750
+                    v[i] /= sum;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   751
+			return sum;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   752
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   753
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   754
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   755
+		vec<N,T> & set_value( const T * rhs )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   756
+		{ for(int i = 0; i < N; i++) v[i] = rhs[i]; return *this; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   757
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   758
+		T & operator [] ( int i )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   759
+		{ return v[i]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   760
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   761
+		const T & operator [] ( int i ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   762
+		{ return v[i]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   763
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   764
+		vec<N,T> & operator *= ( T d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   765
+		{ for(int i = 0; i < N; i++) v[i] *= d; return *this;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   766
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   767
+		vec<N,T> & operator *= ( const vec<N,T> & u )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   768
+		{ for(int i = 0; i < N; i++) v[i] *= u[i]; return *this;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   769
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   770
+		vec<N,T> & operator /= ( T d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   771
+		{ if(d == 0) return *this; for(int i = 0; i < N; i++) v[i] /= d; return *this;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   772
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   773
+		vec<N,T> & operator += ( const vec<N,T> & u )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   774
+		{ for(int i = 0; i < N; i++) v[i] += u.v[i]; return *this;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   775
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   776
+		vec<N,T> & operator -= ( const vec<N,T> & u )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   777
+		{ for(int i = 0; i < N; i++) v[i] -= u.v[i]; return *this;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   778
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   779
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   780
+		vec<N,T> operator - () const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   781
+		{ vec<N,T> rv = v; rv.negate(); return rv; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   782
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   783
+		vec<N,T> operator + ( const vec<N,T> &v) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   784
+		{ vec<N,T> rt(*this); return rt += v; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   785
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   786
+		vec<N,T> operator - ( const vec<N,T> &v) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   787
+		{ vec<N,T> rt(*this); return rt -= v; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   788
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   789
+		vec<N,T> operator * ( T d) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   790
+		{ vec<N,T> rt(*this); return rt *= d; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   791
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   792
+		friend bool operator == <> ( const vec<N,T> &v1, const vec<N,T> &v2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   793
+		friend bool operator != <> ( const vec<N,T> &v1, const vec<N,T> &v2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   794
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   795
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   796
+	//protected:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   797
+		T v[N];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   798
+	};
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   799
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   800
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   801
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   802
+	// vector friend operators
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   803
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   804
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   805
+		vec<N,T> operator * ( const vec<N,T> & b, T d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   806
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   807
+		vec<N,T> rt(b);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   808
+		return rt *= d;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   809
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   810
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   811
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   812
+		vec<N,T> operator * ( T d, const vec<N,T> & b )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   813
+	{ return b*d; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   814
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   815
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   816
+		vec<N,T> operator * ( const vec<N,T> & b, const vec<N,T> & d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   817
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   818
+		vec<N,T> rt(b);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   819
+		return rt *= d;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   820
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   821
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   822
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   823
+		vec<N,T> operator / ( const vec<N,T> & b, T d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   824
+	{ vec<N,T> rt(b); return rt /= d; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   825
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   826
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   827
+		vec<N,T> operator + ( const vec<N,T> & v1, const vec<N,T> & v2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   828
+	{ vec<N,T> rt(v1); return rt += v2; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   829
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   830
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   831
+		vec<N,T> operator - ( const vec<N,T> & v1, const vec<N,T> & v2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   832
+	{ vec<N,T> rt(v1); return rt -= v2; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   833
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   834
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   835
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   836
+		bool operator == ( const vec<N,T> & v1, const vec<N,T> & v2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   837
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   838
+		for(int i = 0; i < N; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   839
+			if(v1.v[i] != v2.v[i])
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   840
+				return false;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   841
+			return true;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   842
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   843
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   844
+	template <int N, class T> inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   845
+		bool operator != ( const vec<N,T> & v1, const vec<N,T> & v2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   846
+	{ return !(v1 == v2); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   847
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   848
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   849
+	typedef vec<3,unsigned char> vec3ub;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   850
+	typedef vec<4,unsigned char> vec4ub;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   851
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   852
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   853
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   854
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   855
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   856
+	namespace GLH_REAL_NAMESPACE
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   857
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   858
+	typedef GLH_REAL real;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   859
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   860
+	class line;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   861
+	class plane;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   862
+	class matrix4;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   863
+	class quaternion;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   864
+	typedef quaternion rotation; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   865
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   866
+	class vec2 : public vec<2,real>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   867
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   868
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   869
+		vec2(const real & t = real()) : vec<2,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   870
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   871
+		vec2(const vec<2,real> & t) : vec<2,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   872
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   873
+		vec2(const real * tp) : vec<2,real>(tp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   874
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   875
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   876
+		vec2(real x, real y )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   877
+		{ v[0] = x; v[1] = y; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   878
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   879
+		void get_value(real & x, real & y) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   880
+		{ x = v[0]; y = v[1]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   881
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   882
+		vec2 & set_value( const real & x, const real & y)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   883
+		{ v[0] = x; v[1] = y; return *this; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   884
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   885
+	};
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   886
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   887
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   888
+	class vec3 : public vec<3,real>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   889
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   890
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   891
+		vec3(const real & t = real()) : vec<3,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   892
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   893
+		vec3(const vec<3,real> & t) : vec<3,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   894
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   895
+		vec3(const real * tp) : vec<3,real>(tp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   896
+		{}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   897
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   898
+		vec3(real x, real y, real z)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   899
+		{ v[0] = x; v[1] = y; v[2] = z; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   900
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   901
+		void get_value(real & x, real & y, real & z) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   902
+		{ x = v[0]; y = v[1]; z = v[2]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   903
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   904
+		vec3 cross( const vec3 &rhs ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   905
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   906
+			vec3 rt;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   907
+			rt.v[0] = v[1]*rhs.v[2]-v[2]*rhs.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   908
+			rt.v[1] = v[2]*rhs.v[0]-v[0]*rhs.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   909
+			rt.v[2] = v[0]*rhs.v[1]-v[1]*rhs.v[0];	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   910
+			return rt;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   911
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   912
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   913
+		vec3 & set_value( const real & x, const real & y, const real & z)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   914
+		{ v[0] = x; v[1] = y; v[2] = z; return *this; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   915
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   916
+	};
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   917
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   918
+  		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   919
+    class vec4 : public vec<4,real>
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   920
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   921
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   922
+        vec4(const real & t = real()) : vec<4,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   923
+        {}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   924
+        vec4(const vec<4,real> & t) : vec<4,real>(t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   925
+        {}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   926
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   927
+        vec4(const vec<3,real> & t, real fourth)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   928
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   929
+        { v[0] = t.v[0]; v[1] = t.v[1]; v[2] = t.v[2]; v[3] = fourth; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   930
+        vec4(const real * tp) : vec<4,real>(tp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   931
+        {}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   932
+        vec4(real x, real y, real z, real w)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   933
+        { v[0] = x; v[1] = y; v[2] = z; v[3] = w; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   934
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   935
+        void get_value(real & x, real & y, real & z, real & w) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   936
+        { x = v[0]; y = v[1]; z = v[2]; w = v[3]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   937
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   938
+        vec4 & set_value( const real & x, const real & y, const real & z, const real & w)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   939
+        { v[0] = x; v[1] = y; v[2] = z; v[3] = w; return *this; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   940
+    };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   941
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   942
+    inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   943
+    vec3 homogenize(const vec4 & v)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   944
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   945
+      vec3 rt;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   946
+      assert(v.v[3] != GLH_ZERO);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   947
+      rt.v[0] = v.v[0]/v.v[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   948
+      rt.v[1] = v.v[1]/v.v[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   949
+      rt.v[2] = v.v[2]/v.v[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   950
+      return rt;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   951
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   952
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   953
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   954
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   955
+    class line
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   956
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   957
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   958
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   959
+        line()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   960
+        { set_value(vec3(0,0,0),vec3(0,0,1)); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   961
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   962
+        line( const vec3 & p0, const vec3 &p1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   963
+        { set_value(p0,p1); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   964
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   965
+        void set_value( const vec3 &p0, const vec3 &p1)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   966
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   967
+          position = p0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   968
+          direction = p1-p0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   969
+          direction.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   970
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   971
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   972
+        bool get_closest_points(const line &line2, 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   973
+					          vec3 &pointOnThis,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   974
+					          vec3 &pointOnThat)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   975
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   976
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   977
+          // quick check to see if parallel -- if so, quit.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   978
+          if(fabs(direction.dot(line2.direction)) == 1.0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   979
+	          return 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   980
+          line l2 = line2;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   981
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   982
+          // Algorithm: Brian Jean
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   983
+          // 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   984
+          register real u;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   985
+          register real v;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   986
+          vec3 Vr = direction;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   987
+          vec3 Vs = l2.direction;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   988
+          register real Vr_Dot_Vs = Vr.dot(Vs);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   989
+          register real detA = real(1.0 - (Vr_Dot_Vs * Vr_Dot_Vs));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   990
+          vec3 C = l2.position - position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   991
+          register real C_Dot_Vr =  C.dot(Vr);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   992
+          register real C_Dot_Vs =  C.dot(Vs);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   993
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   994
+          u = (C_Dot_Vr - Vr_Dot_Vs * C_Dot_Vs)/detA;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   995
+          v = (C_Dot_Vr * Vr_Dot_Vs - C_Dot_Vs)/detA;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   996
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   997
+          pointOnThis = position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   998
+          pointOnThis += direction * u;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   999
+          pointOnThat = l2.position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1000
+          pointOnThat += l2.direction * v;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1001
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1002
+          return 1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1003
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1004
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1005
+        vec3 get_closest_point(const vec3 &point)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1006
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1007
+          vec3 np = point - position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1008
+          vec3 rp = direction*direction.dot(np)+position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1009
+          return rp;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1010
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1011
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1012
+        const vec3 & get_position() const {return position;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1013
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1014
+        const vec3 & get_direction() const {return direction;}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1015
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1016
+    //protected:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1017
+        vec3 position;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1018
+        vec3 direction;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1019
+    };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1020
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1021
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1022
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1023
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1024
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1025
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1026
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1027
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1028
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1029
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1030
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1031
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1032
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1033
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1034
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1035
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1036
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1037
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1038
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1039
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1040
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1041
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1042
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1043
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1044
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1045
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1046
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1047
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1048
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1049
+  // matrix
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1050
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1051
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1052
+  class matrix4
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1053
+  {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1054
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1055
+  public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1056
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1057
+    matrix4() { make_identity(); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1058
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1059
+	matrix4( real r ) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1060
+	{ set_value(r); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1061
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1062
+	matrix4( real * m )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1063
+	{ set_value(m); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1064
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1065
+    matrix4( real a00, real a01, real a02, real a03,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1066
+	       real a10, real a11, real a12, real a13,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1067
+		   real a20, real a21, real a22, real a23,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1068
+		   real a30, real a31, real a32, real a33 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1069
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1070
+		element(0,0) = a00;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1071
+		element(0,1) = a01;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1072
+		element(0,2) = a02;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1073
+		element(0,3) = a03;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1074
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1075
+		element(1,0) = a10;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1076
+		element(1,1) = a11;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1077
+		element(1,2) = a12;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1078
+		element(1,3) = a13;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1079
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1080
+		element(2,0) = a20;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1081
+		element(2,1) = a21;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1082
+		element(2,2) = a22;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1083
+		element(2,3) = a23;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1084
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1085
+		element(3,0) = a30;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1086
+		element(3,1) = a31;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1087
+		element(3,2) = a32;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1088
+		element(3,3) = a33;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1089
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1090
+            
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1091
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1092
+    void get_value( real * mp ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1093
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1094
+		int c = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1095
+		for(int j=0; j < 4; j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1096
+			for(int i=0; i < 4; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1097
+				mp[c++] = element(i,j);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1098
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1099
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1100
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1101
+    const real * get_value() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1102
+	{ return m; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1103
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1104
+	void set_value( real * mp)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1105
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1106
+		int c = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1107
+		for(int j=0; j < 4; j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1108
+			for(int i=0; i < 4; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1109
+				element(i,j) = mp[c++];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1110
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1111
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1112
+	void set_value( real r ) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1113
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1114
+		for(int i=0; i < 4; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1115
+			for(int j=0; j < 4; j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1116
+				element(i,j) = r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1117
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1118
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1119
+    void make_identity()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1120
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1121
+		element(0,0) = 1.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1122
+		element(0,1) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1123
+		element(0,2) = 0.0; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1124
+		element(0,3) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1125
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1126
+		element(1,0) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1127
+		element(1,1) = 1.0; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1128
+		element(1,2) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1129
+		element(1,3) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1130
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1131
+		element(2,0) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1132
+		element(2,1) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1133
+		element(2,2) = 1.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1134
+		element(2,3) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1135
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1136
+		element(3,0) = 0.0; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1137
+		element(3,1) = 0.0; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1138
+		element(3,2) = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1139
+		element(3,3) = 1.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1140
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1141
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1142
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1143
+    static matrix4 identity()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1144
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1145
+		static matrix4 mident (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1146
+			1.0, 0.0, 0.0, 0.0,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1147
+			0.0, 1.0, 0.0, 0.0,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1148
+			0.0, 0.0, 1.0, 0.0,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1149
+			0.0, 0.0, 0.0, 1.0  );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1150
+		return mident;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1151
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1152
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1153
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1154
+    void set_scale( real s )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1155
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1156
+		element(0,0) = s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1157
+		element(1,1) = s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1158
+		element(2,2) = s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1159
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1160
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1161
+    void set_scale( const vec3 & s )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1162
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1163
+		element(0,0) = s.v[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1164
+		element(1,1) = s.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1165
+		element(2,2) = s.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1166
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1167
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1168
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1169
+    void set_translate( const vec3 & t )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1170
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1171
+		element(0,3) = t.v[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1172
+		element(1,3) = t.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1173
+		element(2,3) = t.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1174
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1175
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1176
+	void set_row(int r, const vec4 & t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1177
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1178
+		element(r,0) = t.v[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1179
+		element(r,1) = t.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1180
+		element(r,2) = t.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1181
+		element(r,3) = t.v[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1182
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1183
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1184
+	void set_column(int c, const vec4 & t)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1185
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1186
+		element(0,c) = t.v[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1187
+		element(1,c) = t.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1188
+		element(2,c) = t.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1189
+		element(3,c) = t.v[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1190
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1191
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1192
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1193
+	void get_row(int r, vec4 & t) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1194
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1195
+		t.v[0] = element(r,0);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1196
+		t.v[1] = element(r,1);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1197
+		t.v[2] = element(r,2);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1198
+		t.v[3] = element(r,3);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1199
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1200
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1201
+	vec4 get_row(int r) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1202
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1203
+		vec4 v; get_row(r, v);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1204
+		return v;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1205
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1206
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1207
+	void get_column(int c, vec4 & t) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1208
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1209
+		t.v[0] = element(0,c);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1210
+		t.v[1] = element(1,c);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1211
+		t.v[2] = element(2,c);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1212
+		t.v[3] = element(3,c);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1213
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1214
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1215
+	vec4 get_column(int c) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1216
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1217
+		vec4 v; get_column(c, v);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1218
+		return v;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1219
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1220
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1221
+    matrix4 inverse() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1222
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1223
+		matrix4 minv;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1224
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1225
+		real r1[8], r2[8], r3[8], r4[8];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1226
+		real *s[4], *tmprow;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1227
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1228
+		s[0] = &r1[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1229
+		s[1] = &r2[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1230
+		s[2] = &r3[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1231
+		s[3] = &r4[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1232
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1233
+		register int i,j,p,jj;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1234
+		for(i=0;i<4;i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1235
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1236
+			for(j=0;j<4;j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1237
+			{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1238
+				s[i][j] = element(i,j);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1239
+				if(i==j) s[i][j+4] = 1.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1240
+				else     s[i][j+4] = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1241
+			}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1242
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1243
+		real scp[4];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1244
+		for(i=0;i<4;i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1245
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1246
+			scp[i] = real(fabs(s[i][0]));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1247
+			for(j=1;j<4;j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1248
+				if(real(fabs(s[i][j])) > scp[i]) scp[i] = real(fabs(s[i][j]));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1249
+				if(scp[i] == 0.0) return minv; // singular matrix!
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1250
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1251
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1252
+		int pivot_to;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1253
+		real scp_max;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1254
+		for(i=0;i<4;i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1255
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1256
+			// select pivot row
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1257
+			pivot_to = i;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1258
+			scp_max = real(fabs(s[i][i]/scp[i]));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1259
+			// find out which row should be on top
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1260
+			for(p=i+1;p<4;p++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1261
+				if(real(fabs(s[p][i]/scp[p])) > scp_max)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1262
+				{ scp_max = real(fabs(s[p][i]/scp[p])); pivot_to = p; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1263
+				// Pivot if necessary
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1264
+				if(pivot_to != i)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1265
+				{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1266
+					tmprow = s[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1267
+					s[i] = s[pivot_to];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1268
+					s[pivot_to] = tmprow;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1269
+					real tmpscp;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1270
+					tmpscp = scp[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1271
+					scp[i] = scp[pivot_to];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1272
+					scp[pivot_to] = tmpscp;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1273
+				}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1274
+				
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1275
+				real mji;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1276
+				// perform gaussian elimination
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1277
+				for(j=i+1;j<4;j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1278
+				{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1279
+					mji = s[j][i]/s[i][i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1280
+					s[j][i] = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1281
+					for(jj=i+1;jj<8;jj++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1282
+						s[j][jj] -= mji*s[i][jj];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1283
+				}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1284
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1285
+		if(s[3][3] == 0.0) return minv; // singular matrix!
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1286
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1287
+		//
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1288
+		// Now we have an upper triangular matrix.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1289
+		//
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1290
+		//  x x x x | y y y y
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1291
+		//  0 x x x | y y y y 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1292
+		//  0 0 x x | y y y y
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1293
+		//  0 0 0 x | y y y y
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1294
+		//
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1295
+		//  we'll back substitute to get the inverse
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1296
+		//
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1297
+		//  1 0 0 0 | z z z z
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1298
+		//  0 1 0 0 | z z z z
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1299
+		//  0 0 1 0 | z z z z
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1300
+		//  0 0 0 1 | z z z z 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1301
+		//
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1302
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1303
+		real mij;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1304
+		for(i=3;i>0;i--)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1305
+		{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1306
+			for(j=i-1;j > -1; j--)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1307
+			{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1308
+				mij = s[j][i]/s[i][i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1309
+				for(jj=j+1;jj<8;jj++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1310
+					s[j][jj] -= mij*s[i][jj];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1311
+			}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1312
+		}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1313
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1314
+		for(i=0;i<4;i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1315
+			for(j=0;j<4;j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1316
+				minv(i,j) = s[i][j+4] / s[i][i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1317
+			
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1318
+			return minv;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1319
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1320
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1321
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1322
+    matrix4 transpose() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1323
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1324
+		matrix4 mtrans;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1325
+		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1326
+		for(int i=0;i<4;i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1327
+			for(int j=0;j<4;j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1328
+				mtrans(i,j) = element(j,i);		
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1329
+		return mtrans;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1330
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1331
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1332
+    matrix4 & mult_right( const matrix4 & b )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1333
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1334
+		matrix4 mt(*this);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1335
+		set_value(real(0));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1336
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1337
+		for(int i=0; i < 4; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1338
+			for(int j=0; j < 4; j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1339
+				for(int c=0; c < 4; c++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1340
+					element(i,j) += mt(i,c) * b(c,j);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1341
+		return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1342
+	}    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1343
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1344
+    matrix4 & mult_left( const matrix4 & b )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1345
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1346
+		matrix4 mt(*this);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1347
+		set_value(real(0));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1348
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1349
+		for(int i=0; i < 4; i++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1350
+			for(int j=0; j < 4; j++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1351
+				for(int c=0; c < 4; c++)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1352
+					element(i,j) += b(i,c) * mt(c,j);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1353
+		return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1354
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1355
+	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1356
+	// dst = M * src
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1357
+    void mult_matrix_vec( const vec3 &src, vec3 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1358
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1359
+		real w = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1360
+			src.v[0] * element(3,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1361
+			src.v[1] * element(3,1) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1362
+			src.v[2] * element(3,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1363
+			element(3,3)          );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1364
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1365
+        assert(w != GLH_ZERO);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1366
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1367
+        dst.v[0]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1368
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1369
+			src.v[1] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1370
+			src.v[2] * element(0,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1371
+			element(0,3)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1372
+		dst.v[1]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1373
+			src.v[0] * element(1,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1374
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1375
+			src.v[2] * element(1,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1376
+			element(1,3)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1377
+		dst.v[2]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1378
+			src.v[0] * element(2,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1379
+			src.v[1] * element(2,1) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1380
+			src.v[2] * element(2,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1381
+			element(2,3)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1382
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1383
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1384
+	void mult_matrix_vec( vec3 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1385
+	{ mult_matrix_vec(vec3(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1386
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1387
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1388
+    // dst = src * M
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1389
+    void mult_vec_matrix( const vec3 &src, vec3 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1390
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1391
+		real w = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1392
+			src.v[0] * element(0,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1393
+			src.v[1] * element(1,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1394
+			src.v[2] * element(2,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1395
+			element(3,3)          );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1396
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1397
+        assert(w != GLH_ZERO);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1398
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1399
+		dst.v[0]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1400
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1401
+			src.v[1] * element(1,0) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1402
+			src.v[2] * element(2,0) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1403
+			element(3,0)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1404
+		dst.v[1]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1405
+			src.v[0] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1406
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1407
+			src.v[2] * element(2,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1408
+			element(3,1)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1409
+		dst.v[2]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1410
+			src.v[0] * element(0,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1411
+			src.v[1] * element(1,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1412
+			src.v[2] * element(2,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1413
+			element(3,2)          ) / w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1414
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1415
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1416
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1417
+	void mult_vec_matrix( vec3 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1418
+	{ mult_vec_matrix(vec3(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1419
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1420
+	// dst = M * src
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1421
+    void mult_matrix_vec( const vec4 &src, vec4 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1422
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1423
+        dst.v[0]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1424
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1425
+			src.v[1] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1426
+			src.v[2] * element(0,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1427
+			src.v[3] * element(0,3));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1428
+		dst.v[1]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1429
+			src.v[0] * element(1,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1430
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1431
+			src.v[2] * element(1,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1432
+			src.v[3] * element(1,3));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1433
+		dst.v[2]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1434
+			src.v[0] * element(2,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1435
+			src.v[1] * element(2,1) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1436
+			src.v[2] * element(2,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1437
+			src.v[3] * element(2,3));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1438
+		dst.v[3] = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1439
+			src.v[0] * element(3,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1440
+			src.v[1] * element(3,1) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1441
+			src.v[2] * element(3,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1442
+			src.v[3] * element(3,3));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1443
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1444
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1445
+	void mult_matrix_vec( vec4 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1446
+	{ mult_matrix_vec(vec4(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1447
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1448
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1449
+    // dst = src * M
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1450
+    void mult_vec_matrix( const vec4 &src, vec4 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1451
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1452
+		dst.v[0]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1453
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1454
+			src.v[1] * element(1,0) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1455
+			src.v[2] * element(2,0) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1456
+			src.v[3] * element(3,0));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1457
+		dst.v[1]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1458
+			src.v[0] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1459
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1460
+			src.v[2] * element(2,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1461
+			src.v[3] * element(3,1));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1462
+		dst.v[2]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1463
+			src.v[0] * element(0,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1464
+			src.v[1] * element(1,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1465
+			src.v[2] * element(2,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1466
+			src.v[3] * element(3,2));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1467
+		dst.v[3] = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1468
+			src.v[0] * element(0,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1469
+			src.v[1] * element(1,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1470
+			src.v[2] * element(2,3) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1471
+			src.v[3] * element(3,3));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1472
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1473
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1474
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1475
+	void mult_vec_matrix( vec4 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1476
+	{ mult_vec_matrix(vec4(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1477
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1478
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1479
+    // dst = M * src
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1480
+    void mult_matrix_dir( const vec3 &src, vec3 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1481
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1482
+		dst.v[0]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1483
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1484
+			src.v[1] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1485
+			src.v[2] * element(0,2) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1486
+		dst.v[1]  = ( 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1487
+			src.v[0] * element(1,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1488
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1489
+			src.v[2] * element(1,2) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1490
+		dst.v[2]  = ( 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1491
+			src.v[0] * element(2,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1492
+			src.v[1] * element(2,1) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1493
+			src.v[2] * element(2,2) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1494
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1495
+        
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1496
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1497
+	void mult_matrix_dir( vec3 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1498
+	{ mult_matrix_dir(vec3(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1499
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1500
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1501
+	// dst = src * M
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1502
+    void mult_dir_matrix( const vec3 &src, vec3 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1503
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1504
+		dst.v[0]  = ( 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1505
+			src.v[0] * element(0,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1506
+			src.v[1] * element(1,0) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1507
+			src.v[2] * element(2,0) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1508
+		dst.v[1]  = ( 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1509
+			src.v[0] * element(0,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1510
+			src.v[1] * element(1,1) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1511
+			src.v[2] * element(2,1) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1512
+		dst.v[2]  = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1513
+			src.v[0] * element(0,2) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1514
+			src.v[1] * element(1,2) + 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1515
+			src.v[2] * element(2,2) ) ;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1516
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1517
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1518
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1519
+	void mult_dir_matrix( vec3 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1520
+	{ mult_dir_matrix(vec3(src_and_dst), src_and_dst); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1521
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1522
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1523
+    real & operator () (int row, int col)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1524
+    { return element(row,col); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1525
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1526
+    const real & operator () (int row, int col) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1527
+    { return element(row,col); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1528
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1529
+	real & element (int row, int col)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1530
+    { return m[row | (col<<2)]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1531
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1532
+    const real & element (int row, int col) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1533
+    { return m[row | (col<<2)]; }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1534
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1535
+    matrix4 & operator *= ( const matrix4 & mat )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1536
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1537
+		mult_right( mat );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1538
+		return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1539
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1540
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1541
+    matrix4 & operator *= ( const real & r )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1542
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1543
+		for (int i = 0; i < 4; ++i)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1544
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1545
+            element(0,i) *= r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1546
+            element(1,i) *= r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1547
+            element(2,i) *= r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1548
+            element(3,i) *= r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1549
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1550
+		return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1551
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1552
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1553
+    matrix4 & operator += ( const matrix4 & mat )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1554
+	{
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1555
+		for (int i = 0; i < 4; ++i)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1556
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1557
+            element(0,i) += mat.element(0,i);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1558
+            element(1,i) += mat.element(1,i);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1559
+            element(2,i) += mat.element(2,i);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1560
+            element(3,i) += mat.element(3,i);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1561
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1562
+		return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1563
+	}
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1564
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1565
+    friend matrix4 operator * ( const matrix4 & m1,	const matrix4 & m2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1566
+    friend bool operator == ( const matrix4 & m1, const matrix4 & m2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1567
+    friend bool operator != ( const matrix4 & m1, const matrix4 & m2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1568
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1569
+  //protected:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1570
+	  real m[16];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1571
+  };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1572
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1573
+  inline  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1574
+  matrix4 operator * ( const matrix4 & m1, const matrix4 & m2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1575
+  {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1576
+	  matrix4 product;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1577
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1578
+	  product = m1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1579
+	  product.mult_right(m2);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1580
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1581
+	  return product;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1582
+  }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1583
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1584
+  inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1585
+  bool operator ==( const matrix4 &m1, const matrix4 &m2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1586
+  {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1587
+	  return ( 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1588
+		  m1(0,0) == m2(0,0) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1589
+		  m1(0,1) == m2(0,1) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1590
+		  m1(0,2) == m2(0,2) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1591
+		  m1(0,3) == m2(0,3) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1592
+		  m1(1,0) == m2(1,0) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1593
+		  m1(1,1) == m2(1,1) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1594
+		  m1(1,2) == m2(1,2) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1595
+		  m1(1,3) == m2(1,3) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1596
+		  m1(2,0) == m2(2,0) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1597
+		  m1(2,1) == m2(2,1) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1598
+		  m1(2,2) == m2(2,2) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1599
+		  m1(2,3) == m2(2,3) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1600
+		  m1(3,0) == m2(3,0) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1601
+		  m1(3,1) == m2(3,1) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1602
+		  m1(3,2) == m2(3,2) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1603
+		  m1(3,3) == m2(3,3) );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1604
+  }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1605
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1606
+  inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1607
+  bool operator != ( const matrix4 & m1, const matrix4 & m2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1608
+  { return !( m1 == m2 ); }  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1609
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1610
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1611
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1612
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1613
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1614
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1615
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1616
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1617
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1618
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1619
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1620
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1621
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1622
+    class quaternion
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1623
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1624
+    public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1625
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1626
+    quaternion()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1627
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1628
+        *this = identity();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1629
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1630
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1631
+    quaternion( const real v[4] )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1632
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1633
+        set_value( v );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1634
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1635
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1636
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1637
+    quaternion( real q0, real q1, real q2, real q3 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1638
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1639
+        set_value( q0, q1, q2, q3 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1640
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1641
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1642
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1643
+    quaternion( const matrix4 & m )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1644
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1645
+        set_value( m );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1646
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1647
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1648
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1649
+    quaternion( const vec3 &axis, real radians )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1650
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1651
+        set_value( axis, radians );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1652
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1653
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1654
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1655
+    quaternion( const vec3 &rotateFrom, const vec3 &rotateTo )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1656
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1657
+        set_value( rotateFrom, rotateTo );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1658
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1659
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1660
+    quaternion( const vec3 & from_look, const vec3 & from_up,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1661
+		      const vec3 & to_look, const vec3& to_up)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1662
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1663
+	    set_value(from_look, from_up, to_look, to_up);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1664
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1665
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1666
+    const real * get_value() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1667
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1668
+        return  &q[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1669
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1670
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1671
+    void get_value( real &q0, real &q1, real &q2, real &q3 ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1672
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1673
+        q0 = q[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1674
+        q1 = q[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1675
+        q2 = q[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1676
+        q3 = q[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1677
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1678
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1679
+    quaternion & set_value( real q0, real q1, real q2, real q3 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1680
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1681
+        q[0] = q0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1682
+        q[1] = q1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1683
+        q[2] = q2;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1684
+        q[3] = q3;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1685
+        counter = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1686
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1687
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1688
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1689
+    void get_value( vec3 &axis, real &radians ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1690
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1691
+        radians = real(acos( q[3] ) * GLH_TWO);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1692
+        if ( radians == GLH_ZERO )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1693
+            axis = vec3( 0.0, 0.0, 1.0 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1694
+        else
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1695
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1696
+            axis.v[0] = q[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1697
+            axis.v[1] = q[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1698
+            axis.v[2] = q[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1699
+            axis.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1700
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1701
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1702
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1703
+    void get_value( matrix4 & m ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1704
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1705
+        real s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1706
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1707
+        real norm = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1708
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1709
+        s = (equivalent(norm,GLH_ZERO)) ? GLH_ZERO : ( GLH_TWO / norm );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1710
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1711
+        xs = q[0] * s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1712
+        ys = q[1] * s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1713
+        zs = q[2] * s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1714
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1715
+        wx = q[3] * xs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1716
+        wy = q[3] * ys;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1717
+        wz = q[3] * zs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1718
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1719
+        xx = q[0] * xs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1720
+        xy = q[0] * ys;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1721
+        xz = q[0] * zs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1722
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1723
+        yy = q[1] * ys;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1724
+        yz = q[1] * zs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1725
+        zz = q[2] * zs;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1726
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1727
+        m(0,0) = real( GLH_ONE - ( yy + zz ));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1728
+        m(1,0) = real ( xy + wz );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1729
+        m(2,0) = real ( xz - wy );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1730
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1731
+        m(0,1) = real ( xy - wz );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1732
+        m(1,1) = real ( GLH_ONE - ( xx + zz ));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1733
+        m(2,1) = real ( yz + wx );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1734
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1735
+        m(0,2) = real ( xz + wy );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1736
+        m(1,2) = real ( yz - wx );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1737
+        m(2,2) = real ( GLH_ONE - ( xx + yy ));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1738
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1739
+        m(3,0) = m(3,1) = m(3,2) = m(0,3) = m(1,3) = m(2,3) = GLH_ZERO;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1740
+        m(3,3) = GLH_ONE;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1741
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1742
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1743
+    quaternion & set_value( const real * qp )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1744
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1745
+        memcpy(q,qp,sizeof(real) * 4);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1746
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1747
+        counter = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1748
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1749
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1750
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1751
+    quaternion & set_value( const matrix4 & m )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1752
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1753
+        real tr, s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1754
+        int i, j, k;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1755
+        const int nxt[3] = { 1, 2, 0 };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1756
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1757
+        tr = m(0,0) + m(1,1) + m(2,2);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1758
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1759
+        if ( tr > GLH_ZERO )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1760
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1761
+            s = real(sqrt( tr + m(3,3) ));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1762
+            q[3] = real ( s * 0.5 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1763
+            s = real(0.5) / s;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1764
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1765
+            q[0] = real ( ( m(1,2) - m(2,1) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1766
+            q[1] = real ( ( m(2,0) - m(0,2) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1767
+            q[2] = real ( ( m(0,1) - m(1,0) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1768
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1769
+        else
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1770
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1771
+            i = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1772
+            if ( m(1,1) > m(0,0) )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1773
+              i = 1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1774
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1775
+            if ( m(2,2) > m(i,i) )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1776
+              i = 2;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1777
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1778
+            j = nxt[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1779
+            k = nxt[j];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1780
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1781
+            s = real(sqrt( ( m(i,j) - ( m(j,j) + m(k,k) )) + GLH_ONE ));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1782
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1783
+            q[i] = real ( s * 0.5 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1784
+            s = real(0.5 / s);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1785
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1786
+            q[3] = real ( ( m(j,k) - m(k,j) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1787
+            q[j] = real ( ( m(i,j) + m(j,i) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1788
+            q[k] = real ( ( m(i,k) + m(k,i) ) * s );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1789
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1790
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1791
+        counter = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1792
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1793
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1794
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1795
+    quaternion & set_value( const vec3 &axis, real theta )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1796
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1797
+        real sqnorm = axis.square_norm();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1798
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1799
+        if (sqnorm <= GLH_EPSILON)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1800
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1801
+            // axis too small.
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1802
+            x = y = z = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1803
+            w = 1.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1804
+        } 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1805
+        else 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1806
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1807
+            theta *= real(0.5);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1808
+            real sin_theta = real(sin(theta));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1809
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1810
+            if (!equivalent(sqnorm,GLH_ONE)) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1811
+              sin_theta /= real(sqrt(sqnorm));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1812
+            x = sin_theta * axis.v[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1813
+            y = sin_theta * axis.v[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1814
+            z = sin_theta * axis.v[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1815
+            w = real(cos(theta));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1816
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1817
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1818
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1819
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1820
+    quaternion & set_value( const vec3 & rotateFrom, const vec3 & rotateTo )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1821
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1822
+        vec3 p1, p2;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1823
+        real alpha;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1824
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1825
+        p1 = rotateFrom; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1826
+        p1.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1827
+        p2 = rotateTo;  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1828
+        p2.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1829
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1830
+        alpha = p1.dot(p2);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1831
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1832
+        if(equivalent(alpha,GLH_ONE))
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1833
+        { 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1834
+            *this = identity(); 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1835
+            return *this; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1836
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1837
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1838
+        // ensures that the anti-parallel case leads to a positive dot
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1839
+        if(equivalent(alpha,-GLH_ONE))
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1840
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1841
+            vec3 v;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1842
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1843
+            if(p1.v[0] != p1.v[1] || p1.v[0] != p1.v[2])
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1844
+    	        v = vec3(p1.v[1], p1.v[2], p1.v[0]);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1845
+            else
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1846
+    	        v = vec3(-p1.v[0], p1.v[1], p1.v[2]);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1847
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1848
+            v -= p1 * p1.dot(v);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1849
+            v.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1850
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1851
+            set_value(v, GLH_PI);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1852
+            return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1853
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1854
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1855
+        p1 = p1.cross(p2);  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1856
+        p1.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1857
+        set_value(p1,real(acos(alpha)));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1858
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1859
+        counter = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1860
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1861
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1862
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1863
+    quaternion & set_value( const vec3 & from_look, const vec3 & from_up,
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1864
+		      const vec3 & to_look, const vec3 & to_up)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1865
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1866
+	    quaternion r_look = quaternion(from_look, to_look);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1867
+	    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1868
+	    vec3 rotated_from_up(from_up);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1869
+	    r_look.mult_vec(rotated_from_up);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1870
+	    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1871
+	    quaternion r_twist = quaternion(rotated_from_up, to_up);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1872
+	    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1873
+	    *this = r_twist;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1874
+	    *this *= r_look;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1875
+	    return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1876
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1877
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1878
+    quaternion & operator *= ( const quaternion & qr )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1879
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1880
+        quaternion ql(*this);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1881
+   
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1882
+        w = ql.w * qr.w - ql.x * qr.x - ql.y * qr.y - ql.z * qr.z;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1883
+        x = ql.w * qr.x + ql.x * qr.w + ql.y * qr.z - ql.z * qr.y;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1884
+        y = ql.w * qr.y + ql.y * qr.w + ql.z * qr.x - ql.x * qr.z;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1885
+        z = ql.w * qr.z + ql.z * qr.w + ql.x * qr.y - ql.y * qr.x;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1886
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1887
+        counter += qr.counter;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1888
+        counter++;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1889
+        counter_normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1890
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1891
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1892
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1893
+    void normalize()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1894
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1895
+        real rnorm = GLH_ONE / real(sqrt(w * w + x * x + y * y + z * z));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1896
+        if (equivalent(rnorm, GLH_ZERO))
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1897
+            return;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1898
+        x *= rnorm;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1899
+        y *= rnorm;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1900
+        z *= rnorm;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1901
+        w *= rnorm;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1902
+        counter = 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1903
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1904
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1905
+    friend bool operator == ( const quaternion & q1, const quaternion & q2 );      
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1906
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1907
+    friend bool operator != ( const quaternion & q1, const quaternion & q2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1908
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1909
+    friend quaternion operator * ( const quaternion & q1, const quaternion & q2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1910
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1911
+    bool equals( const quaternion & r, real tolerance ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1912
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1913
+        real t;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1914
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1915
+        t = (
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1916
+			(q[0]-r.q[0])*(q[0]-r.q[0]) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1917
+            (q[1]-r.q[1])*(q[1]-r.q[1]) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1918
+            (q[2]-r.q[2])*(q[2]-r.q[2]) +
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1919
+            (q[3]-r.q[3])*(q[3]-r.q[3]) );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1920
+        if(t > GLH_EPSILON) 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1921
+            return false;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1922
+        return 1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1923
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1924
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1925
+    quaternion & conjugate()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1926
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1927
+        q[0] *= -GLH_ONE;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1928
+        q[1] *= -GLH_ONE;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1929
+        q[2] *= -GLH_ONE;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1930
+        return *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1931
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1932
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1933
+    quaternion & invert()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1934
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1935
+        return conjugate();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1936
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1937
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1938
+    quaternion inverse() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1939
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1940
+        quaternion r = *this;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1941
+        return r.invert();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1942
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1943
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1944
+    //
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1945
+    // Quaternion multiplication with cartesian vector
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1946
+    // v' = q*v*q(star)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1947
+    //
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1948
+    void mult_vec( const vec3 &src, vec3 &dst ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1949
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1950
+        real v_coef = w * w - x * x - y * y - z * z;                     
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1951
+        real u_coef = GLH_TWO * (src.v[0] * x + src.v[1] * y + src.v[2] * z);  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1952
+        real c_coef = GLH_TWO * w;                                       
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1953
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1954
+        dst.v[0] = v_coef * src.v[0] + u_coef * x + c_coef * (y * src.v[2] - z * src.v[1]);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1955
+        dst.v[1] = v_coef * src.v[1] + u_coef * y + c_coef * (z * src.v[0] - x * src.v[2]);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1956
+        dst.v[2] = v_coef * src.v[2] + u_coef * z + c_coef * (x * src.v[1] - y * src.v[0]);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1957
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1958
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1959
+    void mult_vec( vec3 & src_and_dst) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1960
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1961
+        mult_vec(vec3(src_and_dst), src_and_dst);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1962
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1963
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1964
+    void scale_angle( real scaleFactor )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1965
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1966
+        vec3 axis;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1967
+        real radians;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1968
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1969
+        get_value(axis, radians);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1970
+        radians *= scaleFactor;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1971
+        set_value(axis, radians);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1972
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1973
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1974
+    static quaternion slerp( const quaternion & p, const quaternion & q, real alpha )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1975
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1976
+        quaternion r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1977
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1978
+        real cos_omega = p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1979
+        // if B is on opposite hemisphere from A, use -B instead
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1980
+      
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1981
+        int bflip;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1982
+        if ( ( bflip = (cos_omega < GLH_ZERO)) )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1983
+            cos_omega = -cos_omega;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1984
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1985
+        // complementary interpolation parameter
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1986
+        real beta = GLH_ONE - alpha;     
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1987
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1988
+        if(cos_omega <= GLH_ONE - GLH_EPSILON)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1989
+            return p;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1990
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1991
+        real omega = real(acos(cos_omega));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1992
+        real one_over_sin_omega = GLH_ONE / real(sin(omega));
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1993
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1994
+        beta    = real(sin(omega*beta)  * one_over_sin_omega);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1995
+        alpha   = real(sin(omega*alpha) * one_over_sin_omega);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1996
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1997
+        if (bflip)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1998
+            alpha = -alpha;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  1999
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2000
+        r.x = beta * p.q[0]+ alpha * q.q[0];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2001
+        r.y = beta * p.q[1]+ alpha * q.q[1];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2002
+        r.z = beta * p.q[2]+ alpha * q.q[2];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2003
+        r.w = beta * p.q[3]+ alpha * q.q[3];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2004
+        return r;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2005
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2006
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2007
+    static quaternion identity()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2008
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2009
+        static quaternion ident( vec3( 0.0, 0.0, 0.0 ), GLH_ONE );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2010
+        return ident;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2011
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2012
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2013
+    real & operator []( int i )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2014
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2015
+        assert(i < 4);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2016
+        return q[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2017
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2018
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2019
+    const real & operator []( int i ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2020
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2021
+        assert(i < 4);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2022
+        return q[i];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2023
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2024
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2025
+    protected:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2026
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2027
+        void counter_normalize()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2028
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2029
+            if (counter > GLH_QUATERNION_NORMALIZATION_THRESHOLD)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2030
+                normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2031
+        }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2032
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2033
+        union 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2034
+        {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2035
+            struct 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2036
+            {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2037
+                real q[4];
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2038
+            };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2039
+            struct 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2040
+            {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2041
+                real x;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2042
+                real y;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2043
+                real z;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2044
+                real w;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2045
+            };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2046
+        };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2047
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2048
+        // renormalization counter
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2049
+        unsigned char counter;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2050
+    };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2051
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2052
+    inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2053
+    bool operator == ( const quaternion & q1, const quaternion & q2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2054
+    {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2055
+        return (equivalent(q1.x, q2.x) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2056
+		        equivalent(q1.y, q2.y) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2057
+		        equivalent(q1.z, q2.z) &&
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2058
+		        equivalent(q1.w, q2.w) );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2059
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2060
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2061
+    inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2062
+    bool operator != ( const quaternion & q1, const quaternion & q2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2063
+    { 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2064
+        return ! ( q1 == q2 ); 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2065
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2066
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2067
+    inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2068
+    quaternion operator * ( const quaternion & q1, const quaternion & q2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2069
+    {	
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2070
+        quaternion r(q1); 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2071
+        r *= q2; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2072
+        return r; 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2073
+    }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2074
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2075
+      
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2076
+    
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2077
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2078
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2079
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2080
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2081
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2082
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2083
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2084
+  class plane
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2085
+  {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2086
+  public:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2087
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2088
+	  plane()
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2089
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2090
+		  planedistance = 0.0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2091
+		  planenormal.set_value( 0.0, 0.0, 1.0 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2092
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2093
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2094
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2095
+	  plane( const vec3 &p0, const vec3 &p1, const vec3 &p2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2096
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2097
+		  vec3 v0 = p1 - p0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2098
+		  vec3 v1 = p2 - p0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2099
+		  planenormal = v0.cross(v1);  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2100
+		  planenormal.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2101
+		  planedistance = p0.dot(planenormal);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2102
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2103
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2104
+	  plane( const vec3 &normal, real distance )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2105
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2106
+		  planedistance = distance;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2107
+		  planenormal = normal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2108
+		  planenormal.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2109
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2110
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2111
+	  plane( const vec3 &normal, const vec3 &point )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2112
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2113
+		  planenormal = normal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2114
+		  planenormal.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2115
+		  planedistance = point.dot(planenormal);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2116
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2117
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2118
+	  void offset( real d )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2119
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2120
+		  planedistance += d;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2121
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2122
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2123
+	  bool intersect( const line &l, vec3 &intersection ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2124
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2125
+		  vec3 pos, dir;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2126
+		  vec3 pn = planenormal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2127
+		  real pd = planedistance;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2128
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2129
+		  pos = l.get_position();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2130
+		  dir = l.get_direction();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2131
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2132
+		  if(dir.dot(pn) == 0.0) return 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2133
+		  pos -= pn*pd;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2134
+		  // now we're talking about a plane passing through the origin
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2135
+		  if(pos.dot(pn) < 0.0) pn.negate();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2136
+		  if(dir.dot(pn) > 0.0) dir.negate();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2137
+		  vec3 ppos = pn * pos.dot(pn);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2138
+		  pos = (ppos.length()/dir.dot(-pn))*dir;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2139
+		  intersection = l.get_position();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2140
+		  intersection += pos;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2141
+		  return 1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2142
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2143
+	  void transform( const matrix4 &matrix )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2144
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2145
+		  matrix4 invtr = matrix.inverse();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2146
+		  invtr = invtr.transpose();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2147
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2148
+		  vec3 pntOnplane = planenormal * planedistance;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2149
+		  vec3 newPntOnplane;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2150
+		  vec3 newnormal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2151
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2152
+		  invtr.mult_dir_matrix(planenormal, newnormal);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2153
+		  matrix.mult_vec_matrix(pntOnplane, newPntOnplane);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2154
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2155
+		  newnormal.normalize();
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2156
+		  planenormal = newnormal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2157
+		  planedistance = newPntOnplane.dot(planenormal);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2158
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2159
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2160
+	  bool is_in_half_space( const vec3 &point ) const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2161
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2162
+		  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2163
+		  if(( point.dot(planenormal) - planedistance) < 0.0)
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2164
+			  return 0;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2165
+		  return 1;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2166
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2167
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2168
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2169
+	  real distance( const vec3 & point ) const 
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2170
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2171
+		  return planenormal.dot(point - planenormal*planedistance);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2172
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2173
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2174
+	  const vec3 &get_normal() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2175
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2176
+		  return planenormal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2177
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2178
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2179
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2180
+	  real get_distance_from_origin() const
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2181
+      {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2182
+		  return planedistance;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2183
+      }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2184
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2185
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2186
+	  friend bool operator == ( const plane & p1, const plane & p2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2187
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2188
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2189
+	  friend bool operator != ( const plane & p1, const plane & p2 );
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2190
+	  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2191
+  //protected:
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2192
+	  vec3 planenormal;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2193
+	  real planedistance;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2194
+  };
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2195
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2196
+  inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2197
+  bool operator == (const plane & p1, const plane & p2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2198
+  {
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2199
+	  return (  p1.planedistance == p2.planedistance && p1.planenormal == p2.planenormal);
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2200
+  }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2201
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2202
+  inline
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2203
+  bool operator != ( const plane & p1, const plane & p2 )
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2204
+  { return  ! (p1 == p2); }
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2205
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2206
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2207
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2208
+  } // "ns_##GLH_REAL"
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2209
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2210
+  // make common typedefs...
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2211
+#ifdef GLH_REAL_IS_FLOAT
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2212
+  typedef GLH_REAL_NAMESPACE::vec2 vec2f;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2213
+  typedef GLH_REAL_NAMESPACE::vec3 vec3f;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2214
+  typedef GLH_REAL_NAMESPACE::vec4 vec4f;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2215
+  typedef GLH_REAL_NAMESPACE::quaternion quaternionf;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2216
+  typedef GLH_REAL_NAMESPACE::quaternion rotationf;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2217
+  typedef GLH_REAL_NAMESPACE::line linef;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2218
+  typedef GLH_REAL_NAMESPACE::plane planef;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2219
+  typedef GLH_REAL_NAMESPACE::matrix4 matrix4f;
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2220
+#endif
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2221
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2222
+  
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2223
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2224
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2225
+}  // namespace glh
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2226
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2227
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2228
+
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2229
+#endif
813958f80b98 2010-02-01 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
  2230
+