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