[Orxonox-commit 1068] r5789 - in sandbox_light: . cmake data src src/external src/external/ogremath src/external/ogremath/GLX src/external/ogremath/OSX src/external/ogremath/WIN32 src/libraries/core src/libraries/util src/orxonox
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Sep 26 00:44:50 CEST 2009
Author: rgrieder
Date: 2009-09-26 00:44:49 +0200 (Sat, 26 Sep 2009)
New Revision: 5789
Added:
sandbox_light/src/external/ogremath/
sandbox_light/src/external/ogremath/CMakeLists.txt
sandbox_light/src/external/ogremath/GLX/
sandbox_light/src/external/ogremath/GLX/OgreTimer.cpp
sandbox_light/src/external/ogremath/GLX/OgreTimerImp.h
sandbox_light/src/external/ogremath/OSX/
sandbox_light/src/external/ogremath/OSX/OgreTimer.cpp
sandbox_light/src/external/ogremath/OSX/OgreTimerImp.h
sandbox_light/src/external/ogremath/OgreBitwise.h
sandbox_light/src/external/ogremath/OgreColourValue.cpp
sandbox_light/src/external/ogremath/OgreColourValue.h
sandbox_light/src/external/ogremath/OgreConfig.h
sandbox_light/src/external/ogremath/OgreMath.cpp
sandbox_light/src/external/ogremath/OgreMath.h
sandbox_light/src/external/ogremath/OgreMatrix3.cpp
sandbox_light/src/external/ogremath/OgreMatrix3.h
sandbox_light/src/external/ogremath/OgreMatrix4.cpp
sandbox_light/src/external/ogremath/OgreMatrix4.h
sandbox_light/src/external/ogremath/OgrePlatform.h
sandbox_light/src/external/ogremath/OgrePrerequisites.h
sandbox_light/src/external/ogremath/OgreQuaternion.cpp
sandbox_light/src/external/ogremath/OgreQuaternion.h
sandbox_light/src/external/ogremath/OgreTimer.h
sandbox_light/src/external/ogremath/OgreVector2.cpp
sandbox_light/src/external/ogremath/OgreVector2.h
sandbox_light/src/external/ogremath/OgreVector3.cpp
sandbox_light/src/external/ogremath/OgreVector3.h
sandbox_light/src/external/ogremath/OgreVector4.cpp
sandbox_light/src/external/ogremath/OgreVector4.h
sandbox_light/src/external/ogremath/WIN32/
sandbox_light/src/external/ogremath/WIN32/OgreTimer.cpp
sandbox_light/src/external/ogremath/WIN32/OgreTimerImp.h
sandbox_light/src/external/ogremath/asm_math.h
Removed:
sandbox_light/README
sandbox_light/cmake/FindOGRE.cmake
sandbox_light/data/defaultConfig/
sandbox_light/src/libraries/core/BaseObject.cc
sandbox_light/src/libraries/core/BaseObject.h
sandbox_light/src/libraries/core/ClassFactory.h
sandbox_light/src/libraries/core/ConfigFileManager.cc
sandbox_light/src/libraries/core/ConfigFileManager.h
sandbox_light/src/libraries/core/ConfigValueContainer.cc
sandbox_light/src/libraries/core/ConfigValueContainer.h
sandbox_light/src/libraries/core/ConfigValueIncludes.h
sandbox_light/src/libraries/core/CoreIncludes.h
sandbox_light/src/libraries/core/CorePrecompiledHeaders.h
sandbox_light/src/libraries/core/DynLib.cc
sandbox_light/src/libraries/core/DynLib.h
sandbox_light/src/libraries/core/DynLibManager.cc
sandbox_light/src/libraries/core/DynLibManager.h
sandbox_light/src/libraries/core/Executor.cc
sandbox_light/src/libraries/core/Executor.h
sandbox_light/src/libraries/core/Factory.cc
sandbox_light/src/libraries/core/Factory.h
sandbox_light/src/libraries/core/Functor.h
sandbox_light/src/libraries/core/Game.cc
sandbox_light/src/libraries/core/Game.h
sandbox_light/src/libraries/core/GameState.cc
sandbox_light/src/libraries/core/GameState.h
sandbox_light/src/libraries/core/Identifier.cc
sandbox_light/src/libraries/core/Identifier.h
sandbox_light/src/libraries/core/Iterator.h
sandbox_light/src/libraries/core/Language.cc
sandbox_light/src/libraries/core/Language.h
sandbox_light/src/libraries/core/MetaObjectList.cc
sandbox_light/src/libraries/core/MetaObjectList.h
sandbox_light/src/libraries/core/ObjectList.h
sandbox_light/src/libraries/core/ObjectListBase.cc
sandbox_light/src/libraries/core/ObjectListBase.h
sandbox_light/src/libraries/core/ObjectListIterator.h
sandbox_light/src/libraries/core/OrxonoxClass.cc
sandbox_light/src/libraries/core/OrxonoxClass.h
sandbox_light/src/libraries/core/Thread.cc
sandbox_light/src/libraries/core/Thread.h
sandbox_light/src/libraries/core/ThreadPool.cc
sandbox_light/src/libraries/core/ThreadPool.h
sandbox_light/src/libraries/util/CRC32.cc
sandbox_light/src/libraries/util/CRC32.h
sandbox_light/src/libraries/util/ExprParser.cc
sandbox_light/src/libraries/util/ExprParser.h
sandbox_light/src/libraries/util/OrxEnum.h
sandbox_light/src/libraries/util/Scope.cc
sandbox_light/src/libraries/util/Scope.h
sandbox_light/src/libraries/util/ScopedSingleton.h
sandbox_light/src/libraries/util/mbool.h
sandbox_light/src/modules/
sandbox_light/src/orxonox/GSRoot.cc
sandbox_light/src/orxonox/GSRoot.h
Modified:
sandbox_light/CMakeLists.txt
sandbox_light/INSTALL
sandbox_light/cmake/InstallConfig.cmake
sandbox_light/cmake/LibraryConfig.cmake
sandbox_light/cmake/LibraryConfigTardis.cmake
sandbox_light/cmake/PackageConfig.cmake
sandbox_light/cmake/TargetUtilities.cmake
sandbox_light/data/CMakeLists.txt
sandbox_light/src/CMakeLists.txt
sandbox_light/src/OrxonoxConfig.h.in
sandbox_light/src/SpecialConfig.h.in
sandbox_light/src/external/CMakeLists.txt
sandbox_light/src/libraries/core/CMakeLists.txt
sandbox_light/src/libraries/core/Clock.cc
sandbox_light/src/libraries/core/CommandLine.cc
sandbox_light/src/libraries/core/Core.cc
sandbox_light/src/libraries/core/Core.h
sandbox_light/src/libraries/util/CMakeLists.txt
sandbox_light/src/libraries/util/Math.cc
sandbox_light/src/libraries/util/Math.h
sandbox_light/src/libraries/util/MultiType.h
sandbox_light/src/orxonox/CMakeLists.txt
sandbox_light/src/orxonox/Main.cc
Log:
Stripped sandbox further down to get a light version that excludes almost all core features.
Also, the Ogre dependency has been removed and a little ogremath library been added.
Modified: sandbox_light/CMakeLists.txt
===================================================================
--- sandbox_light/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -36,18 +36,10 @@
################ General Config #################
-# Version info
-SET(ORXONOX_VERSION_MAJOR 0)
-SET(ORXONOX_VERSION_MINOR 0)
-SET(ORXONOX_VERSION_PATCH 3)
-SET(ORXONOX_VERSION 0.0.3)
-SET(ORXONOX_VERSION_NAME "Arcturus")
-
# Standard path suffixes
SET(DEFAULT_RUNTIME_PATH bin)
SET(DEFAULT_LIBRARY_PATH lib)
SET(DEFAULT_ARCHIVE_PATH lib/static)
-SET(DEFAULT_MODULE_PATH lib/modules)
SET(DEFAULT_DOC_PATH doc)
SET(DEFAULT_DATA_PATH data)
SET(DEFAULT_CONFIG_PATH config)
@@ -57,15 +49,11 @@
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_RUNTIME_PATH})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_LIBRARY_PATH})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_ARCHIVE_PATH})
-SET(CMAKE_MODULE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_MODULE_PATH})
SET(CMAKE_DOC_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_DOC_PATH})
# Data directories are only inputs, no delclaration here
SET(CMAKE_CONFIG_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_CONFIG_PATH})
SET(CMAKE_LOG_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_LOG_PATH})
-# Set the extension of the dynamic modules
-SET(ORXONOX_MODULE_EXTENSION ".module")
-
# Sets where to find the external libraries like OgreMain.dll at runtime
# On Unix you should not have to change this at all.
# This only applies to development runs in the build tree
Modified: sandbox_light/INSTALL
===================================================================
--- sandbox_light/INSTALL 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/INSTALL 2009-09-25 22:44:49 UTC (rev 5789)
@@ -8,19 +8,4 @@
In order to compile Orxonox you will need the following libraries:
(for windows there are already precompiled packages on the website)
-OGRE 3D Graphics Engine 1.4 (1.6 not yet supported)
-CEGUI (Crazy Eddie's GUI System) 0.5
-Boost libraries 1.34
-ENet (Network library) 1.1
Lua (scripting language) 5.0 or 5.1
-Tcl (shell script language) 8.4 or 8.5
-OpenAL (audio) (no version requirements specified yet)
-ALUT (audio) (no version requirements specified yet)
-LibOgg (no version requirements specified yet)
-LibVorbis (no version requirements specified yet)
-ZLib (compression) (no version requirements specified yet)
-
-OGRE supports both OpenGL and DirectX9 rendering. You will also need OGRE for the dedicated server!
-
-Further information about installing and running this application can be found on
-http://www.orxonox.net/wiki/Running
Deleted: sandbox_light/README
===================================================================
--- sandbox_light/README 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/README 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,20 +0,0 @@
-Hi there,
-
-We are proud to present you Orxonox - the most ferious 3D space shooter ever to exist.
-
-This game is free, if you have paid for this, get your money back! The source code of this game is licensed under the GPL (GNU General Public License).
-The game content is licensed under the Creative Commons Attribution-Sharealike 2.5 license. For more information read LICENSE in the same folder you found this file.
-
-For directions to install this game, please check out the file INSTALL or http://www.orxonox.net/wiki/Running
-
-This application uses the Ogre Graphics Engine (http://www.ogre3d.org), if you haven't already downloaded a precompiled version of Ogre with this package. Visit our webpage to get your Orxonox compatible version of the Ogre libraries.
-
-This is an open source game. If you want to contribute check out http://www.orxonox.net/wiki/development to find more information how you could help us making the game better. We are always looking for programmers and content designers, who like to contribute.
-
-We hope you have fun playing the game. Check out http://www.orxonox.net for news and newer versions of the game.
-
-Please contact us in our forum ( http://forum.orxonox.net ) or check out our contact page ( http://www.orxonox.net/wiki/about#Contact ). We hope to hear from you and are looking forward to your feedback.
-
-
-Cheers,
-The Orxonox Development Team
Deleted: sandbox_light/cmake/FindOGRE.cmake
===================================================================
--- sandbox_light/cmake/FindOGRE.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/FindOGRE.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,55 +0,0 @@
-# Find OGRE includes and library
-#
-# This module defines
-# OGRE_INCLUDE_DIR
-# OGRE_LIBRARY, the library to link against to use OGRE.
-# OGRE_FOUND, If false, do not try to use OGRE
-#
-# Copyright © 2007, Matt Williams
-# Modified by Nicolas Schlumberger to make it work on the Tardis-Infrastucture
-# of the ETH Zurich (removed later on)
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-#
-# Several changes and additions by Fabian 'x3n' Landau
-# Lots of simplifications by Adrian Friedli
-# Version checking by Reto Grieder
-# > www.orxonox.net <
-
-INCLUDE(DetermineVersion)
-INCLUDE(FindPackageHandleAdvancedArgs)
-INCLUDE(HandleLibraryTypes)
-
-FIND_PATH(OGRE_INCLUDE_DIR Ogre.h
- PATHS $ENV{OGRE_HOME}
- PATH_SUFFIXES include include/OGRE Ogre.framework/Headers
-)
-FIND_LIBRARY(OGRE_LIBRARY_OPTIMIZED
- NAMES OgreMain Ogre
- PATHS $ENV{OGRE_HOME}
- PATH_SUFFIXES lib bin/Release bin/release Release release
-)
-FIND_LIBRARY(OGRE_LIBRARY_DEBUG
- NAMES OgreMaind OgreMain_d OgreMainD OgreMain_D Ogred Ogre_d OgreD Ogre_d
- PATHS $ENV{OGRE_HOME}
- PATH_SUFFIXES lib bin/Debug bin/debug Debug debug Versions/A
-)
-
-# Inspect OgrePrerquisites.h for the version number
-DETERMINE_VERSION(OGRE ${OGRE_INCLUDE_DIR}/OgrePrerequisites.h)
-
-# Handle the REQUIRED argument and set OGRE_FOUND
-# Also check the version requirements
-FIND_PACKAGE_HANDLE_ADVANCED_ARGS(OGRE DEFAULT_MSG ${OGRE_VERSION}
- OGRE_LIBRARY_OPTIMIZED
- OGRE_INCLUDE_DIR
-)
-
-# Collect optimized and debug libraries
-HANDLE_LIBRARY_TYPES(OGRE)
-
-MARK_AS_ADVANCED(
- OGRE_INCLUDE_DIR
- OGRE_LIBRARY_OPTIMIZED
- OGRE_LIBRARY_DEBUG
-)
Modified: sandbox_light/cmake/InstallConfig.cmake
===================================================================
--- sandbox_light/cmake/InstallConfig.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/InstallConfig.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -42,7 +42,6 @@
SET(RUNTIME_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_RUNTIME_PATH})
SET(LIBRARY_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_LIBRARY_PATH})
SET(ARCHIVE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_ARCHIVE_PATH})
-SET(MODULE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_MODULE_PATH})
SET(DOC_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_DOC_PATH})
SET(DATA_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_DATA_PATH})
SET(CONFIG_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${DEFAULT_CONFIG_PATH})
@@ -54,7 +53,6 @@
SET(RUNTIME_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
SET(LIBRARY_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/orxonox)
SET(ARCHIVE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/orxonox/static)
- SET(MODULE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/orxonox/modules)
SET(DOC_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/doc/orxonox)
SET(DATA_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/orxonox)
ENDIF()
Modified: sandbox_light/cmake/LibraryConfig.cmake
===================================================================
--- sandbox_light/cmake/LibraryConfig.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/LibraryConfig.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -72,7 +72,6 @@
############### Library finding #################
# Performs the search and sets the variables #
-FIND_PACKAGE(OGRE 1.4 REQUIRED)
##### Lua #####
IF(CEGUILUA_USE_EXTERNAL_LIBRARY)
COMPARE_VERSION_STRINGS(${CEGUI_VERSION} "0.6" _version_comparison)
@@ -101,7 +100,6 @@
# Note: Default option in the libraries vary, but our default option is dynamic
IF(WIN32)
OPTION(LINK_BOOST_DYNAMIC "Link Boost dynamically on Windows" TRUE)
- OPTION(LINK_OGRE_DYNAMIC "Link OGRE dynamically on Windows" TRUE)
COMPARE_VERSION_STRINGS("${LUA_VERSION}" "5.1" _version_comparison)
IF(_version_comparison LESS 0)
OPTION(LINK_LUA_DYNAMIC "Link Lua dynamically on Windows" FALSE)
@@ -112,7 +110,6 @@
IF(DEPENDENCY_PACKAGE_ENABLE)
MARK_AS_ADVANCED(
LINK_BOOST_DYNAMIC
- LINK_OGRE_DYNAMIC
LINK_LUA_DYNAMIC
)
ENDIF()
Modified: sandbox_light/cmake/LibraryConfigTardis.cmake
===================================================================
--- sandbox_light/cmake/LibraryConfigTardis.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/LibraryConfigTardis.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -44,5 +44,4 @@
SET(BOOST_INCLUDEDIR "/usr/pack/boost-1.36.0-sd/include/boost-1_36")
SET(BOOST_LIBRARYDIR "/usr/pack/boost-1.36.0-sd/i686-debian-linux4.0/lib")
SET(ENV{LUA_DIR} "/usr/pack/lua-5.1.4-sd;/usr/pack/lua-5.1.4-sd/i686-debian-linux4.0")
- SET(ENV{OGRE_HOME} "/usr/pack/ogre-1.4.9-sd;/usr/pack/ogre-1.4.9-sd/i686-debian-linux4.0")
ENDIF(TARDIS)
Modified: sandbox_light/cmake/PackageConfig.cmake
===================================================================
--- sandbox_light/cmake/PackageConfig.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/PackageConfig.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -58,7 +58,6 @@
# Include paths and other special treatments
SET(ENV{BOOST_ROOT} ${DEP_INCLUDE_DIR}/boost)
SET(ENV{LUA_DIR} ${DEP_INCLUDE_DIR}/lua)
-SET(ENV{OGRE_HOME} ${DEP_INCLUDE_DIR}/ogre)
### INSTALL ###
Modified: sandbox_light/cmake/TargetUtilities.cmake
===================================================================
--- sandbox_light/cmake/TargetUtilities.cmake 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/cmake/TargetUtilities.cmake 2009-09-25 22:44:49 UTC (rev 5789)
@@ -187,8 +187,6 @@
# VERSION
IF(_arg_VERSION)
SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
- ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
- SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
ENDIF()
# OUTPUT_NAME
Modified: sandbox_light/data/CMakeLists.txt
===================================================================
--- sandbox_light/data/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/data/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -20,8 +20,7 @@
# Author:
# Reto Grieder
# Description:
- # Finds the external data directory and configures the data installation.
- # Default search paths are: ../../data and ../data_extern
+ # Connfigures the data installation.
#
# For dev runs we've got two data directory. The one from the other repository root folder
Modified: sandbox_light/src/CMakeLists.txt
===================================================================
--- sandbox_light/src/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -38,15 +38,12 @@
# If no defines are specified, these libs get linked statically
ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" WIN32 LINK_BOOST_DYNAMIC)
ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL" WIN32 LINK_LUA_DYNAMIC)
-# If no defines are specified, these libs get linked dynamically
-ADD_COMPILER_FLAGS("-DOGRE_STATIC_LIB" WIN32 NOT LINK_OGRE_DYNAMIC)
############## Include Directories ##############
# Set the search paths for include files
INCLUDE_DIRECTORIES(
# External
- ${OGRE_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${LUA_INCLUDE_DIR}
${VLD_INCLUDE_DIR}
@@ -73,7 +70,6 @@
ADD_SUBDIRECTORY(external)
ADD_SUBDIRECTORY(libraries)
ADD_SUBDIRECTORY(orxonox)
-ADD_SUBDIRECTORY(modules)
################ Executable ################
Modified: sandbox_light/src/OrxonoxConfig.h.in
===================================================================
--- sandbox_light/src/OrxonoxConfig.h.in 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/OrxonoxConfig.h.in 2009-09-25 22:44:49 UTC (rev 5789)
@@ -107,41 +107,6 @@
/*---------------------------------
- * Version information
- *-------------------------------*/
-#define ORXONOX_VERSION_MAJOR @ORXONOX_VERSION_MAJOR@
-#define ORXONOX_VERSION_MINOR @ORXONOX_VERSION_MINOR@
-#define ORXONOX_VERSION_PATCH @ORXONOX_VERSION_PATCH@
-#define ORXONOX_VERSION_NAME "@ORXONOX_VERSION_NAME@"
-
-//! Defines version info encoded as 0xMMIIPP (M: Major version, I: Minor version, P: Patch version, all as hex)
-#define ORXONOX_VERSION \
- ((ORXONOX_VERSION_MAJOR << 16) | (ORXONOX_VERSION_MINOR << 8) | ORXONOX_VERSION_PATCH)
-
-
-/*---------------------------------
- * Unix settings
- *-------------------------------*/
-#ifdef ORXONOX_PLATFORM_UNIX
-
-// TODO: Check what this actually is and whether we need it or not
-#if 0
-# ifdef ORXONOX_PLATFORM_APPLE
-# define ORXONOX_PLATFORM_LIB "OrxonoxPlatform.bundle"
-# else // ORXONOX_PLATFORM_LINUX
-# define ORXONOX_PLATFORM_LIB "libOrxonoxPlatform.so"
-# endif
-#endif
-
-#endif /* Patform Unix */
-
-
-/*---------------------------------
- * Apple Settings
- *-------------------------------*/
-
-
-/*---------------------------------
* Options
*-------------------------------*/
/**
Modified: sandbox_light/src/SpecialConfig.h.in
===================================================================
--- sandbox_light/src/SpecialConfig.h.in 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/SpecialConfig.h.in 2009-09-25 22:44:49 UTC (rev 5789)
@@ -69,7 +69,6 @@
const char defaultRuntimePath[] = "@DEFAULT_RUNTIME_PATH@";
const char defaultLibraryPath[] = "@DEFAULT_LIBRARY_PATH@";
const char defaultArchivePath[] = "@DEFAULT_ARCHIVE_PATH@";
- const char defaultModulePath[] = "@DEFAULT_MODULE_PATH@";
const char defaultDocPath[] = "@DEFAULT_DOC_PATH@";
const char defaultDataPath[] = "@DEFAULT_DATA_PATH@";
const char defaultConfigPath[] = "@DEFAULT_CONFIG_PATH@";
@@ -78,17 +77,14 @@
#ifndef INSTALL_COPYABLE
// INSTALLATION PATHS
const char dataInstallDirectory[] = "@DATA_INSTALL_DIRECTORY@";
- const char moduleInstallDirectory[] = "@MODULE_INSTALL_DIRECTORY@";
#endif
// DEVELOPMENT RUN PATHS
const char dataDevDirectory[] = "@DATA_DIRECTORY@";
#ifdef CMAKE_CONFIGURATION_TYPES
- const char moduleDevDirectory[] = "@CMAKE_MODULE_OUTPUT_DIRECTORY@/" BOOST_PP_STRINGIZE(CMAKE_BUILD_TYPE);
const char configDevDirectory[] = "@CMAKE_CONFIG_OUTPUT_DIRECTORY@/" BOOST_PP_STRINGIZE(CMAKE_BUILD_TYPE);
const char logDevDirectory[] = "@CMAKE_LOG_OUTPUT_DIRECTORY@/" BOOST_PP_STRINGIZE(CMAKE_BUILD_TYPE);
#else
- const char moduleDevDirectory[] = "@CMAKE_MODULE_OUTPUT_DIRECTORY@";
const char configDevDirectory[] = "@CMAKE_CONFIG_OUTPUT_DIRECTORY@";
const char logDevDirectory[] = "@CMAKE_LOG_OUTPUT_DIRECTORY@";
#endif
@@ -96,9 +92,6 @@
#ifdef DEPENDENCY_PACKAGE_ENABLE
const char dependencyLibraryDirectory[] = "@DEP_LIBRARY_DIR@";
#endif
-
- // Module extension
- const char moduleExtension[] = "@ORXONOX_MODULE_EXTENSION@";
} }
/**
Modified: sandbox_light/src/external/CMakeLists.txt
===================================================================
--- sandbox_light/src/external/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/external/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -19,4 +19,5 @@
################ Sub Directories ################
+ADD_SUBDIRECTORY(ogremath)
ADD_SUBDIRECTORY(tolua)
Added: sandbox_light/src/external/ogremath/CMakeLists.txt
===================================================================
--- sandbox_light/src/external/ogremath/CMakeLists.txt (rev 0)
+++ sandbox_light/src/external/ogremath/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,46 @@
+ #
+ # ORXONOX - the hottest 3D action shooter ever to exist
+ # > www.orxonox.net <
+ #
+ # This program is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU General Public License
+ # as published by the Free Software Foundation; either version 2
+ # of the License, or (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License along
+ # with this program; if not, write to the Free Software Foundation,
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ #
+
+SET(OGREMATH_SRC_FILES
+ OgreColourValue.cpp
+ OgreMath.cpp
+ OgreMatrix3.cpp
+ OgreMatrix4.cpp
+ OgreQuaternion.cpp
+ OgreVector2.cpp
+ OgreVector3.cpp
+ OgreVector4.cpp
+)
+
+IF(WIN32)
+ LIST(APPEND OGREMATH_SRC_FILES WIN32/OgreTimer.cpp)
+ELSEIF(APPLE)
+ LIST(APPEND OGREMATH_SRC_FILES OSX/OgreTimer.cpp)
+ELSEIF(UNIX)
+ LIST(APPEND OGREMATH_SRC_FILES GLX/OgreTimer.cpp)
+ENDIF()
+
+ORXONOX_ADD_LIBRARY(ogremath_orxonox
+ ORXONOX_EXTERNAL
+ FIND_HEADER_FILES
+ DEFINE_SYMBOL
+ "OGRE_NONCLIENT_BUILD"
+ SOURCE_FILES
+ ${OGREMATH_SRC_FILES}
+)
Property changes on: sandbox_light/src/external/ogremath/CMakeLists.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/GLX/OgreTimer.cpp
===================================================================
--- sandbox_light/src/external/ogremath/GLX/OgreTimer.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/GLX/OgreTimer.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,80 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreTimer.h"
+#include <sys/time.h>
+
+using namespace Ogre;
+
+//--------------------------------------------------------------------------------//
+Timer::Timer()
+{
+ reset();
+}
+
+//--------------------------------------------------------------------------------//
+Timer::~Timer()
+{
+}
+
+//--------------------------------------------------------------------------------//
+void Timer::reset()
+{
+ zeroClock = clock();
+ gettimeofday(&start, NULL);
+}
+
+//--------------------------------------------------------------------------------//
+unsigned long Timer::getMilliseconds()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
+}
+
+//--------------------------------------------------------------------------------//
+unsigned long Timer::getMicroseconds()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec-start.tv_sec)*1000000+(now.tv_usec-start.tv_usec);
+}
+
+//-- Common Across All Timers ----------------------------------------------------//
+unsigned long Timer::getMillisecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000.0)) ;
+}
+
+//-- Common Across All Timers ----------------------------------------------------//
+unsigned long Timer::getMicrosecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000000.0)) ;
+}
Property changes on: sandbox_light/src/external/ogremath/GLX/OgreTimer.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/GLX/OgreTimerImp.h
===================================================================
--- sandbox_light/src/external/ogremath/GLX/OgreTimerImp.h (rev 0)
+++ sandbox_light/src/external/ogremath/GLX/OgreTimerImp.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,79 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+#ifndef __GLXTimer_H__
+#define __GLXTimer_H__
+
+#include "OgrePrerequisites.h"
+
+namespace Ogre
+{
+ /** Timer class */
+ class _OgreExport Timer : public TimerAlloc
+ {
+ private:
+ struct timeval start;
+ clock_t zeroClock;
+ public:
+ Timer();
+ ~Timer();
+
+ /** Method for setting a specific option of the Timer. These options are usually
+ specific for a certain implementation of the Timer class, and may (and probably
+ will) not exist across different implementations. reset() must be called after
+ all setOption() calls.
+ @param
+ strKey The name of the option to set
+ @param
+ pValue A pointer to the value - the size should be calculated by the timer
+ based on the key
+ @return
+ On success, true is returned.
+ @par
+ On failure, false is returned.
+ */
+ bool setOption( const String& strKey, const void* pValue ) { return false; }
+
+ /** Resets timer */
+ void reset();
+
+ /** Returns milliseconds since initialisation or last reset */
+ unsigned long getMilliseconds();
+
+ /** Returns microseconds since initialisation or last reset */
+ unsigned long getMicroseconds();
+
+ /** Returns milliseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMillisecondsCPU();
+
+ /** Returns microseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMicrosecondsCPU();
+ };
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/GLX/OgreTimerImp.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OSX/OgreTimer.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OSX/OgreTimer.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OSX/OgreTimer.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,80 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreTimer.h"
+#include <sys/time.h>
+
+using namespace Ogre;
+
+//--------------------------------------------------------------------------------//
+Timer::Timer()
+{
+ reset();
+}
+
+//--------------------------------------------------------------------------------//
+Timer::~Timer()
+{
+}
+
+//--------------------------------------------------------------------------------//
+void Timer::reset()
+{
+ zeroClock = clock();
+ gettimeofday(&start, NULL);
+}
+
+//--------------------------------------------------------------------------------//
+unsigned long Timer::getMilliseconds()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
+}
+
+//--------------------------------------------------------------------------------//
+unsigned long Timer::getMicroseconds()
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec-start.tv_sec)*1000000+(now.tv_usec-start.tv_usec);
+}
+
+//-- Common Across All Timers ----------------------------------------------------//
+unsigned long Timer::getMillisecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000.0)) ;
+}
+
+//-- Common Across All Timers ----------------------------------------------------//
+unsigned long Timer::getMicrosecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000000.0)) ;
+}
Property changes on: sandbox_light/src/external/ogremath/OSX/OgreTimer.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OSX/OgreTimerImp.h
===================================================================
--- sandbox_light/src/external/ogremath/OSX/OgreTimerImp.h (rev 0)
+++ sandbox_light/src/external/ogremath/OSX/OgreTimerImp.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,79 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+#ifndef __OSXTimer_H__
+#define __OSXTimer_H__
+
+#include <Ogre/OgrePrerequisites.h>
+
+namespace Ogre
+{
+ /** Timer class */
+ class Timer : public TimerAlloc
+ {
+ private:
+ struct timeval start;
+ clock_t zeroClock;
+ public:
+ Timer();
+ ~Timer();
+
+ /** Method for setting a specific option of the Timer. These options are usually
+ specific for a certain implementation of the Timer class, and may (and probably
+ will) not exist across different implementations. reset() must be called after
+ all setOption() calls.
+ @param
+ strKey The name of the option to set
+ @param
+ pValue A pointer to the value - the size should be calculated by the timer
+ based on the key
+ @return
+ On success, true is returned.
+ @par
+ On failure, false is returned.
+ */
+ bool setOption( const String& strKey, const void* pValue ) { return false; }
+
+ /** Resets timer */
+ void reset();
+
+ /** Returns milliseconds since initialisation or last reset */
+ unsigned long getMilliseconds();
+
+ /** Returns microseconds since initialisation or last reset */
+ unsigned long getMicroseconds();
+
+ /** Returns milliseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMillisecondsCPU();
+
+ /** Returns microseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMicrosecondsCPU();
+ };
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OSX/OgreTimerImp.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreBitwise.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreBitwise.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreBitwise.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,323 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef _Bitwise_H__
+#define _Bitwise_H__
+
+#include "OgrePrerequisites.h"
+
+namespace Ogre {
+
+ /** Class for manipulating bit patterns.
+ */
+ class Bitwise {
+ public:
+ /** Returns the most significant bit set in a value.
+ */
+ static FORCEINLINE unsigned int mostSignificantBitSet(unsigned int value)
+ {
+ unsigned int result = 0;
+ while (value != 0) {
+ ++result;
+ value >>= 1;
+ }
+ return result-1;
+ }
+ /** Returns the closest power-of-two number greater or equal to value.
+ @note 0 and 1 are powers of two, so
+ firstPO2From(0)==0 and firstPO2From(1)==1.
+ */
+ static FORCEINLINE uint32 firstPO2From(uint32 n)
+ {
+ --n;
+ n |= n >> 16;
+ n |= n >> 8;
+ n |= n >> 4;
+ n |= n >> 2;
+ n |= n >> 1;
+ ++n;
+ return n;
+ }
+ /** Determines whether the number is power-of-two or not.
+ @note 0 and 1 are tread as power of two.
+ */
+ template<typename T>
+ static FORCEINLINE bool isPO2(T n)
+ {
+ return (n & (n-1)) == 0;
+ }
+ /** Returns the number of bits a pattern must be shifted right by to
+ remove right-hand zeros.
+ */
+ template<typename T>
+ static FORCEINLINE unsigned int getBitShift(T mask)
+ {
+ if (mask == 0)
+ return 0;
+
+ unsigned int result = 0;
+ while ((mask & 1) == 0) {
+ ++result;
+ mask >>= 1;
+ }
+ return result;
+ }
+
+ /** Takes a value with a given src bit mask, and produces another
+ value with a desired bit mask.
+ @remarks
+ This routine is useful for colour conversion.
+ */
+ template<typename SrcT, typename DestT>
+ static inline DestT convertBitPattern(SrcT srcValue, SrcT srcBitMask, DestT destBitMask)
+ {
+ // Mask off irrelevant source value bits (if any)
+ srcValue = srcValue & srcBitMask;
+
+ // Shift source down to bottom of DWORD
+ const unsigned int srcBitShift = getBitShift(srcBitMask);
+ srcValue >>= srcBitShift;
+
+ // Get max value possible in source from srcMask
+ const SrcT srcMax = srcBitMask >> srcBitShift;
+
+ // Get max available in dest
+ const unsigned int destBitShift = getBitShift(destBitMask);
+ const DestT destMax = destBitMask >> destBitShift;
+
+ // Scale source value into destination, and shift back
+ DestT destValue = (srcValue * destMax) / srcMax;
+ return (destValue << destBitShift);
+ }
+
+ /**
+ * Convert N bit colour channel value to P bits. It fills P bits with the
+ * bit pattern repeated. (this is /((1<<n)-1) in fixed point)
+ */
+ static inline unsigned int fixedToFixed(uint32 value, unsigned int n, unsigned int p)
+ {
+ if(n > p)
+ {
+ // Less bits required than available; this is easy
+ value >>= n-p;
+ }
+ else if(n < p)
+ {
+ // More bits required than are there, do the fill
+ // Use old fashioned division, probably better than a loop
+ if(value == 0)
+ value = 0;
+ else if(value == (static_cast<unsigned int>(1)<<n)-1)
+ value = (1<<p)-1;
+ else value = value*(1<<p)/((1<<n)-1);
+ }
+ return value;
+ }
+
+ /**
+ * Convert floating point colour channel value between 0.0 and 1.0 (otherwise clamped)
+ * to integer of a certain number of bits. Works for any value of bits between 0 and 31.
+ */
+ static inline unsigned int floatToFixed(const float value, const unsigned int bits)
+ {
+ if(value <= 0.0f) return 0;
+ else if (value >= 1.0f) return (1<<bits)-1;
+ else return (unsigned int)(value * (1<<bits));
+ }
+
+ /**
+ * Fixed point to float
+ */
+ static inline float fixedToFloat(unsigned value, unsigned int bits)
+ {
+ return (float)value/(float)((1<<bits)-1);
+ }
+
+ /**
+ * Write a n*8 bits integer value to memory in native endian.
+ */
+ static inline void intWrite(void *dest, const int n, const unsigned int value)
+ {
+ switch(n) {
+ case 1:
+ ((uint8*)dest)[0] = (uint8)value;
+ break;
+ case 2:
+ ((uint16*)dest)[0] = (uint16)value;
+ break;
+ case 3:
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ ((uint8*)dest)[0] = (uint8)((value >> 16) & 0xFF);
+ ((uint8*)dest)[1] = (uint8)((value >> 8) & 0xFF);
+ ((uint8*)dest)[2] = (uint8)(value & 0xFF);
+#else
+ ((uint8*)dest)[2] = (uint8)((value >> 16) & 0xFF);
+ ((uint8*)dest)[1] = (uint8)((value >> 8) & 0xFF);
+ ((uint8*)dest)[0] = (uint8)(value & 0xFF);
+#endif
+ break;
+ case 4:
+ ((uint32*)dest)[0] = (uint32)value;
+ break;
+ }
+ }
+ /**
+ * Read a n*8 bits integer value to memory in native endian.
+ */
+ static inline unsigned int intRead(const void *src, int n) {
+ switch(n) {
+ case 1:
+ return ((uint8*)src)[0];
+ case 2:
+ return ((uint16*)src)[0];
+ case 3:
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ return ((uint32)((uint8*)src)[0]<<16)|
+ ((uint32)((uint8*)src)[1]<<8)|
+ ((uint32)((uint8*)src)[2]);
+#else
+ return ((uint32)((uint8*)src)[0])|
+ ((uint32)((uint8*)src)[1]<<8)|
+ ((uint32)((uint8*)src)[2]<<16);
+#endif
+ case 4:
+ return ((uint32*)src)[0];
+ }
+ return 0; // ?
+ }
+
+ /** Convert a float32 to a float16 (NV_half_float)
+ Courtesy of OpenEXR
+ */
+ static inline uint16 floatToHalf(float i)
+ {
+ union { float f; uint32 i; } v;
+ v.f = i;
+ return floatToHalfI(v.i);
+ }
+ /** Converts float in uint32 format to a a half in uint16 format
+ */
+ static inline uint16 floatToHalfI(uint32 i)
+ {
+ register int s = (i >> 16) & 0x00008000;
+ register int e = ((i >> 23) & 0x000000ff) - (127 - 15);
+ register int m = i & 0x007fffff;
+
+ if (e <= 0)
+ {
+ if (e < -10)
+ {
+ return 0;
+ }
+ m = (m | 0x00800000) >> (1 - e);
+
+ return s | (m >> 13);
+ }
+ else if (e == 0xff - (127 - 15))
+ {
+ if (m == 0) // Inf
+ {
+ return s | 0x7c00;
+ }
+ else // NAN
+ {
+ m >>= 13;
+ return s | 0x7c00 | m | (m == 0);
+ }
+ }
+ else
+ {
+ if (e > 30) // Overflow
+ {
+ return s | 0x7c00;
+ }
+
+ return s | (e << 10) | (m >> 13);
+ }
+ }
+
+ /**
+ * Convert a float16 (NV_half_float) to a float32
+ * Courtesy of OpenEXR
+ */
+ static inline float halfToFloat(uint16 y)
+ {
+ union { float f; uint32 i; } v;
+ v.i = halfToFloatI(y);
+ return v.f;
+ }
+ /** Converts a half in uint16 format to a float
+ in uint32 format
+ */
+ static inline uint32 halfToFloatI(uint16 y)
+ {
+ register int s = (y >> 15) & 0x00000001;
+ register int e = (y >> 10) & 0x0000001f;
+ register int m = y & 0x000003ff;
+
+ if (e == 0)
+ {
+ if (m == 0) // Plus or minus zero
+ {
+ return s << 31;
+ }
+ else // Denormalized number -- renormalize it
+ {
+ while (!(m & 0x00000400))
+ {
+ m <<= 1;
+ e -= 1;
+ }
+
+ e += 1;
+ m &= ~0x00000400;
+ }
+ }
+ else if (e == 31)
+ {
+ if (m == 0) // Inf
+ {
+ return (s << 31) | 0x7f800000;
+ }
+ else // NaN
+ {
+ return (s << 31) | 0x7f800000 | (m << 13);
+ }
+ }
+
+ e = e + (127 - 15);
+ m = m << 13;
+
+ return (s << 31) | (e << 23) | m;
+ }
+
+
+ };
+}
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreBitwise.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreColourValue.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreColourValue.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreColourValue.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,406 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreColourValue.h"
+#include "OgreMath.h"
+
+namespace Ogre {
+
+ const ColourValue ColourValue::ZERO = ColourValue(0.0,0.0,0.0,0.0);
+ const ColourValue ColourValue::Black = ColourValue(0.0,0.0,0.0);
+ const ColourValue ColourValue::White = ColourValue(1.0,1.0,1.0);
+ const ColourValue ColourValue::Red = ColourValue(1.0,0.0,0.0);
+ const ColourValue ColourValue::Green = ColourValue(0.0,1.0,0.0);
+ const ColourValue ColourValue::Blue = ColourValue(0.0,0.0,1.0);
+
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ ABGR ColourValue::getAsABGR(void) const
+#else
+ RGBA ColourValue::getAsRGBA(void) const
+#endif
+ {
+ uint8 val8;
+ uint32 val32 = 0;
+
+ // Convert to 32bit pattern
+ // (RGBA = 8888)
+
+ // Red
+ val8 = static_cast<uint8>(r * 255);
+ val32 = val8 << 24;
+
+ // Green
+ val8 = static_cast<uint8>(g * 255);
+ val32 += val8 << 16;
+
+ // Blue
+ val8 = static_cast<uint8>(b * 255);
+ val32 += val8 << 8;
+
+ // Alpha
+ val8 = static_cast<uint8>(a * 255);
+ val32 += val8;
+
+ return val32;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ BGRA ColourValue::getAsBGRA(void) const
+#else
+ ARGB ColourValue::getAsARGB(void) const
+#endif
+ {
+ uint8 val8;
+ uint32 val32 = 0;
+
+ // Convert to 32bit pattern
+ // (ARGB = 8888)
+
+ // Alpha
+ val8 = static_cast<uint8>(a * 255);
+ val32 = val8 << 24;
+
+ // Red
+ val8 = static_cast<uint8>(r * 255);
+ val32 += val8 << 16;
+
+ // Green
+ val8 = static_cast<uint8>(g * 255);
+ val32 += val8 << 8;
+
+ // Blue
+ val8 = static_cast<uint8>(b * 255);
+ val32 += val8;
+
+
+ return val32;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ ARGB ColourValue::getAsARGB(void) const
+#else
+ BGRA ColourValue::getAsBGRA(void) const
+#endif
+ {
+ uint8 val8;
+ uint32 val32 = 0;
+
+ // Convert to 32bit pattern
+ // (ARGB = 8888)
+
+ // Blue
+ val8 = static_cast<uint8>(b * 255);
+ val32 = val8 << 24;
+
+ // Green
+ val8 = static_cast<uint8>(g * 255);
+ val32 += val8 << 16;
+
+ // Red
+ val8 = static_cast<uint8>(r * 255);
+ val32 += val8 << 8;
+
+ // Alpha
+ val8 = static_cast<uint8>(a * 255);
+ val32 += val8;
+
+
+ return val32;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ RGBA ColourValue::getAsRGBA(void) const
+#else
+ ABGR ColourValue::getAsABGR(void) const
+#endif
+ {
+ uint8 val8;
+ uint32 val32 = 0;
+
+ // Convert to 32bit pattern
+ // (ABRG = 8888)
+
+ // Alpha
+ val8 = static_cast<uint8>(a * 255);
+ val32 = val8 << 24;
+
+ // Blue
+ val8 = static_cast<uint8>(b * 255);
+ val32 += val8 << 16;
+
+ // Green
+ val8 = static_cast<uint8>(g * 255);
+ val32 += val8 << 8;
+
+ // Red
+ val8 = static_cast<uint8>(r * 255);
+ val32 += val8;
+
+
+ return val32;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ void ColourValue::setAsABGR(const ABGR val)
+#else
+ void ColourValue::setAsRGBA(const RGBA val)
+#endif
+ {
+ uint32 val32 = val;
+
+ // Convert from 32bit pattern
+ // (RGBA = 8888)
+
+ // Red
+ r = ((val32 >> 24) & 0xFF) / 255.0f;
+
+ // Green
+ g = ((val32 >> 16) & 0xFF) / 255.0f;
+
+ // Blue
+ b = ((val32 >> 8) & 0xFF) / 255.0f;
+
+ // Alpha
+ a = (val32 & 0xFF) / 255.0f;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ void ColourValue::setAsBGRA(const BGRA val)
+#else
+ void ColourValue::setAsARGB(const ARGB val)
+#endif
+ {
+ uint32 val32 = val;
+
+ // Convert from 32bit pattern
+ // (ARGB = 8888)
+
+ // Alpha
+ a = ((val32 >> 24) & 0xFF) / 255.0f;
+
+ // Red
+ r = ((val32 >> 16) & 0xFF) / 255.0f;
+
+ // Green
+ g = ((val32 >> 8) & 0xFF) / 255.0f;
+
+ // Blue
+ b = (val32 & 0xFF) / 255.0f;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ void ColourValue::setAsARGB(const ARGB val)
+#else
+ void ColourValue::setAsBGRA(const BGRA val)
+#endif
+ {
+ uint32 val32 = val;
+
+ // Convert from 32bit pattern
+ // (ARGB = 8888)
+
+ // Blue
+ b = ((val32 >> 24) & 0xFF) / 255.0f;
+
+ // Green
+ g = ((val32 >> 16) & 0xFF) / 255.0f;
+
+ // Red
+ r = ((val32 >> 8) & 0xFF) / 255.0f;
+
+ // Alpha
+ a = (val32 & 0xFF) / 255.0f;
+ }
+ //---------------------------------------------------------------------
+#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
+ void ColourValue::setAsRGBA(const RGBA val)
+#else
+ void ColourValue::setAsABGR(const ABGR val)
+#endif
+ {
+ uint32 val32 = val;
+
+ // Convert from 32bit pattern
+ // (ABGR = 8888)
+
+ // Alpha
+ a = ((val32 >> 24) & 0xFF) / 255.0f;
+
+ // Blue
+ b = ((val32 >> 16) & 0xFF) / 255.0f;
+
+ // Green
+ g = ((val32 >> 8) & 0xFF) / 255.0f;
+
+ // Red
+ r = (val32 & 0xFF) / 255.0f;
+ }
+ //---------------------------------------------------------------------
+ bool ColourValue::operator==(const ColourValue& rhs) const
+ {
+ return (r == rhs.r &&
+ g == rhs.g &&
+ b == rhs.b &&
+ a == rhs.a);
+ }
+ //---------------------------------------------------------------------
+ bool ColourValue::operator!=(const ColourValue& rhs) const
+ {
+ return !(*this == rhs);
+ }
+ //---------------------------------------------------------------------
+ void ColourValue::setHSB(Real hue, Real saturation, Real brightness)
+ {
+ // wrap hue
+ if (hue > 1.0f)
+ {
+ hue -= (int)hue;
+ }
+ else if (hue < 0.0f)
+ {
+ hue += (int)hue + 1;
+ }
+ // clamp saturation / brightness
+ saturation = std::min(saturation, (Real)1.0);
+ saturation = std::max(saturation, (Real)0.0);
+ brightness = std::min(brightness, (Real)1.0);
+ brightness = std::max(brightness, (Real)0.0);
+
+ if (brightness == 0.0f)
+ {
+ // early exit, this has to be black
+ r = g = b = 0.0f;
+ return;
+ }
+
+ if (saturation == 0.0f)
+ {
+ // early exit, this has to be grey
+
+ r = g = b = brightness;
+ return;
+ }
+
+
+ Real hueDomain = hue * 6.0f;
+ if (hueDomain >= 6.0f)
+ {
+ // wrap around, and allow mathematical errors
+ hueDomain = 0.0f;
+ }
+ unsigned short domain = (unsigned short)hueDomain;
+ Real f1 = brightness * (1 - saturation);
+ Real f2 = brightness * (1 - saturation * (hueDomain - domain));
+ Real f3 = brightness * (1 - saturation * (1 - (hueDomain - domain)));
+
+ switch (domain)
+ {
+ case 0:
+ // red domain; green ascends
+ r = brightness;
+ g = f3;
+ b = f1;
+ break;
+ case 1:
+ // yellow domain; red descends
+ r = f2;
+ g = brightness;
+ b = f1;
+ break;
+ case 2:
+ // green domain; blue ascends
+ r = f1;
+ g = brightness;
+ b = f3;
+ break;
+ case 3:
+ // cyan domain; green descends
+ r = f1;
+ g = f2;
+ b = brightness;
+ break;
+ case 4:
+ // blue domain; red ascends
+ r = f3;
+ g = f1;
+ b = brightness;
+ break;
+ case 5:
+ // magenta domain; blue descends
+ r = brightness;
+ g = f1;
+ b = f2;
+ break;
+ }
+
+
+ }
+ //---------------------------------------------------------------------
+ void ColourValue::getHSB(Real* hue, Real* saturation, Real* brightness) const
+ {
+
+ Real vMin = std::min(r, std::min(g, b));
+ Real vMax = std::max(r, std::max(g, b));
+ Real delta = vMax - vMin;
+
+ *brightness = vMax;
+
+ if (Math::RealEqual(delta, 0.0f, 1e-6))
+ {
+ // grey
+ *hue = 0;
+ *saturation = 0;
+ }
+ else
+ {
+ // a colour
+ *saturation = delta / vMax;
+
+ Real deltaR = (((vMax - r) / 6.0f) + (delta / 2.0f)) / delta;
+ Real deltaG = (((vMax - g) / 6.0f) + (delta / 2.0f)) / delta;
+ Real deltaB = (((vMax - b) / 6.0f) + (delta / 2.0f)) / delta;
+
+ if (Math::RealEqual(r, vMax))
+ *hue = deltaB - deltaG;
+ else if (Math::RealEqual(g, vMax))
+ *hue = 0.3333333f + deltaR - deltaB;
+ else if (Math::RealEqual(b, vMax))
+ *hue = 0.6666667f + deltaG - deltaR;
+
+ if (*hue < 0.0f)
+ *hue += 1.0f;
+ if (*hue > 1.0f)
+ *hue -= 1.0f;
+ }
+
+
+ }
+
+}
+
Property changes on: sandbox_light/src/external/ogremath/OgreColourValue.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreColourValue.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreColourValue.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreColourValue.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,330 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef _COLOURVALUE_H__
+#define _COLOURVALUE_H__
+
+#include "OgrePrerequisites.h"
+
+#include <cassert>
+#include <ostream>
+
+namespace Ogre {
+
+ typedef uint32 RGBA;
+ typedef uint32 ARGB;
+ typedef uint32 ABGR;
+ typedef uint32 BGRA;
+
+ /** Class representing colour.
+ @remarks
+ Colour is represented as 4 components, each of which is a
+ floating-point value from 0.0 to 1.0.
+ @par
+ The 3 'normal' colour components are red, green and blue, a higher
+ number indicating greater amounts of that component in the colour.
+ The forth component is the 'alpha' value, which represents
+ transparency. In this case, 0.0 is completely transparent and 1.0 is
+ fully opaque.
+ */
+ class _OgreExport ColourValue
+ {
+ public:
+ static const ColourValue ZERO;
+ static const ColourValue Black;
+ static const ColourValue White;
+ static const ColourValue Red;
+ static const ColourValue Green;
+ static const ColourValue Blue;
+
+ explicit ColourValue( float red = 1.0f,
+ float green = 1.0f,
+ float blue = 1.0f,
+ float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
+ { }
+
+ bool operator==(const ColourValue& rhs) const;
+ bool operator!=(const ColourValue& rhs) const;
+
+ float r,g,b,a;
+
+ /** Retrieves colour as RGBA.
+ */
+ RGBA getAsRGBA(void) const;
+
+ /** Retrieves colour as ARGB.
+ */
+ ARGB getAsARGB(void) const;
+
+ /** Retrieves colour as BGRA.
+ */
+ BGRA getAsBGRA(void) const;
+
+ /** Retrieves colours as ABGR */
+ ABGR getAsABGR(void) const;
+
+ /** Sets colour as RGBA.
+ */
+ void setAsRGBA(const RGBA val);
+
+ /** Sets colour as ARGB.
+ */
+ void setAsARGB(const ARGB val);
+
+ /** Sets colour as BGRA.
+ */
+ void setAsBGRA(const BGRA val);
+
+ /** Sets colour as ABGR.
+ */
+ void setAsABGR(const ABGR val);
+
+ /** Clamps colour value to the range [0, 1].
+ */
+ void saturate(void)
+ {
+ if (r < 0)
+ r = 0;
+ else if (r > 1)
+ r = 1;
+
+ if (g < 0)
+ g = 0;
+ else if (g > 1)
+ g = 1;
+
+ if (b < 0)
+ b = 0;
+ else if (b > 1)
+ b = 1;
+
+ if (a < 0)
+ a = 0;
+ else if (a > 1)
+ a = 1;
+ }
+
+ /** As saturate, except that this colour value is unaffected and
+ the saturated colour value is returned as a copy. */
+ ColourValue saturateCopy(void) const
+ {
+ ColourValue ret = *this;
+ ret.saturate();
+ return ret;
+ }
+
+ /// Array accessor operator
+ inline float operator [] ( const size_t i ) const
+ {
+ assert( i < 4 );
+
+ return *(&r+i);
+ }
+
+ /// Array accessor operator
+ inline float& operator [] ( const size_t i )
+ {
+ assert( i < 4 );
+
+ return *(&r+i);
+ }
+
+ /// Pointer accessor for direct copying
+ inline float* ptr()
+ {
+ return &r;
+ }
+ /// Pointer accessor for direct copying
+ inline const float* ptr() const
+ {
+ return &r;
+ }
+
+
+ // arithmetic operations
+ inline ColourValue operator + ( const ColourValue& rkVector ) const
+ {
+ ColourValue kSum;
+
+ kSum.r = r + rkVector.r;
+ kSum.g = g + rkVector.g;
+ kSum.b = b + rkVector.b;
+ kSum.a = a + rkVector.a;
+
+ return kSum;
+ }
+
+ inline ColourValue operator - ( const ColourValue& rkVector ) const
+ {
+ ColourValue kDiff;
+
+ kDiff.r = r - rkVector.r;
+ kDiff.g = g - rkVector.g;
+ kDiff.b = b - rkVector.b;
+ kDiff.a = a - rkVector.a;
+
+ return kDiff;
+ }
+
+ inline ColourValue operator * (const float fScalar ) const
+ {
+ ColourValue kProd;
+
+ kProd.r = fScalar*r;
+ kProd.g = fScalar*g;
+ kProd.b = fScalar*b;
+ kProd.a = fScalar*a;
+
+ return kProd;
+ }
+
+ inline ColourValue operator * ( const ColourValue& rhs) const
+ {
+ ColourValue kProd;
+
+ kProd.r = rhs.r * r;
+ kProd.g = rhs.g * g;
+ kProd.b = rhs.b * b;
+ kProd.a = rhs.a * a;
+
+ return kProd;
+ }
+
+ inline ColourValue operator / ( const ColourValue& rhs) const
+ {
+ ColourValue kProd;
+
+ kProd.r = rhs.r / r;
+ kProd.g = rhs.g / g;
+ kProd.b = rhs.b / b;
+ kProd.a = rhs.a / a;
+
+ return kProd;
+ }
+
+ inline ColourValue operator / (const float fScalar ) const
+ {
+ assert( fScalar != 0.0 );
+
+ ColourValue kDiv;
+
+ float fInv = 1.0 / fScalar;
+ kDiv.r = r * fInv;
+ kDiv.g = g * fInv;
+ kDiv.b = b * fInv;
+ kDiv.a = a * fInv;
+
+ return kDiv;
+ }
+
+ inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
+ {
+ ColourValue kProd;
+
+ kProd.r = fScalar * rkVector.r;
+ kProd.g = fScalar * rkVector.g;
+ kProd.b = fScalar * rkVector.b;
+ kProd.a = fScalar * rkVector.a;
+
+ return kProd;
+ }
+
+ // arithmetic updates
+ inline ColourValue& operator += ( const ColourValue& rkVector )
+ {
+ r += rkVector.r;
+ g += rkVector.g;
+ b += rkVector.b;
+ a += rkVector.a;
+
+ return *this;
+ }
+
+ inline ColourValue& operator -= ( const ColourValue& rkVector )
+ {
+ r -= rkVector.r;
+ g -= rkVector.g;
+ b -= rkVector.b;
+ a -= rkVector.a;
+
+ return *this;
+ }
+
+ inline ColourValue& operator *= (const float fScalar )
+ {
+ r *= fScalar;
+ g *= fScalar;
+ b *= fScalar;
+ a *= fScalar;
+ return *this;
+ }
+
+ inline ColourValue& operator /= (const float fScalar )
+ {
+ assert( fScalar != 0.0 );
+
+ float fInv = 1.0 / fScalar;
+
+ r *= fInv;
+ g *= fInv;
+ b *= fInv;
+ a *= fInv;
+
+ return *this;
+ }
+
+ /** Set a colour value from Hue, Saturation and Brightness.
+ @param hue Hue value, scaled to the [0,1] range as opposed to the 0-360
+ @param saturation Saturation level, [0,1]
+ @param brightness Brightness level, [0,1]
+ */
+ void setHSB(Real hue, Real saturation, Real brightness);
+
+ /** Convert the current colour to Hue, Saturation and Brightness values.
+ @param hue Output hue value, scaled to the [0,1] range as opposed to the 0-360
+ @param saturation Output saturation level, [0,1]
+ @param brightness Output brightness level, [0,1]
+ */
+ void getHSB(Real* hue, Real* saturation, Real* brightness) const;
+
+
+
+ /** Function for writing to a stream.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const ColourValue& c )
+ {
+ o << "ColourValue(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
+ return o;
+ }
+
+ };
+
+} // namespace
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreColourValue.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreConfig.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreConfig.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreConfig.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,162 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+(Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Config_H_
+#define __Config_H_
+
+// Read configuration options; some systems use an auto-generated config.h,
+// other use a manually generated config.h; in any case just define
+// HAVE_CONFIG_H to include the custom config.h file.
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/** If set to 1, profiling code will be included in the application. When you
+ are deploying your application you will probably want to set this to 0 */
+#define OGRE_PROFILING 0
+
+/** There are three modes for handling asserts in OGRE:
+0 - STANDARD - Standard asserts in debug builds, nothing in release builds
+1 - RELEASE_EXCEPTIONS - Standard asserts in debug builds, exceptions in release builds
+2 - EXCEPTIONS - Exceptions in debug builds, exceptions in release builds
+*/
+#define OGRE_ASSERT_MODE 0
+
+/** If set to >0, OGRE will always 'think' that the graphics card only has the
+ number of texture units specified. Very useful for testing multipass fallback.
+*/
+#define OGRE_PRETEND_TEXTURE_UNITS 0
+
+/** If set to 1, Real is typedef'ed to double. Otherwise, Real is typedef'ed
+ to float. Setting this allows you to perform mathematical operations in the
+ CPU (Quaternion, Vector3 etc) with more precision, but bear in mind that the
+ GPU still operates in single-precision mode.
+*/
+#ifndef OGRE_DOUBLE_PRECISION
+#define OGRE_DOUBLE_PRECISION 0
+#endif
+
+/** Define number of texture coordinate sets allowed per vertex.
+*/
+#define OGRE_MAX_TEXTURE_COORD_SETS 6
+
+/** Define max number of texture layers allowed per pass on any card.
+*/
+#define OGRE_MAX_TEXTURE_LAYERS 16
+
+/** Define max number of lights allowed per pass.
+*/
+#define OGRE_MAX_SIMULTANEOUS_LIGHTS 8
+
+/** Define max number of blending weights allowed per vertex.
+*/
+#define OGRE_MAX_BLEND_WEIGHTS 4
+
+/** Define this if you want to link OGRE as a static lib (preferably as a project file)
+*/
+//#define OGRE_STATIC_LIB
+
+
+// define the memory allocator configuration to use
+#define OGRE_MEMORY_ALLOCATOR_STD 1
+#define OGRE_MEMORY_ALLOCATOR_NED 2 // you need to have nedmalloc on your path for this
+#define OGRE_MEMORY_ALLOCATOR_USER 3
+
+#ifndef OGRE_MEMORY_ALLOCATOR
+# define OGRE_MEMORY_ALLOCATOR OGRE_MEMORY_ALLOCATOR_NED
+#endif
+
+// enable or disable the memory tracker, recording the memory allocations & tracking leaks
+// default is to disable since it's expensive, but you can enable if needed per build target
+
+#ifndef OGRE_MEMORY_TRACKER_DEBUG_MODE
+# define OGRE_MEMORY_TRACKER_DEBUG_MODE 0
+#endif
+
+#ifndef OGRE_MEMORY_TRACKER_RELEASE_MODE
+# define OGRE_MEMORY_TRACKER_RELEASE_MODE 0
+#endif
+/** Define max number of multiple render targets (MRTs) to render to at once.
+*/
+#define OGRE_MAX_MULTIPLE_RENDER_TARGETS 8
+
+/** Support for multithreading, there are 3 options
+
+OGRE_THREAD_SUPPORT = 0
+ No support for threading.
+OGRE_THREAD_SUPPORT = 1
+ Thread support for background loading, by both loading and constructing resources
+ in a background thread. Resource management and SharedPtr handling becomes
+ thread-safe, and resources may be completely loaded in the background.
+ The places where threading is available are clearly
+ marked, you should assume state is NOT thread safe unless otherwise
+ stated in relation to this flag.
+OGRE_THREAD_SUPPORT = 2
+ Thread support for background resource preparation. This means that resource
+ data can streamed into memory in the background, but the final resource
+ construction (including RenderSystem dependencies) is still done in the primary
+ thread. Has a lower synchronisation primitive overhead than full threading
+ while still allowing the major blocking aspects of resource management (I/O)
+ to be done in the background.
+*/
+#ifndef OGRE_THREAD_SUPPORT
+#define OGRE_THREAD_SUPPORT 0
+#endif
+#if OGRE_THREAD_SUPPORT != 0 && OGRE_THREAD_SUPPORT != 1 && OGRE_THREAD_SUPPORT != 2
+#define OGRE_THREAD_SUPPORT 1
+#endif
+
+/** Disables use of the FreeImage image library for loading images.
+WARNING: Use only when you want to provide your own image loading code via codecs.
+*/
+#ifndef OGRE_NO_FREEIMAGE
+#define OGRE_NO_FREEIMAGE 0
+#endif
+
+/** Disables use of the DevIL image library for loading images.
+By default DevIL is disabled in Eihort in favour of FreeImage, but you may re-enable
+it if you choose
+*/
+#ifndef OGRE_NO_DEVIL
+#define OGRE_NO_DEVIL 1
+#endif
+
+/** Disables use of the internal image codec for loading DDS files.
+WARNING: Use only when you want to provide your own image loading code via codecs.
+*/
+#ifndef OGRE_NO_DDS_CODEC
+#define OGRE_NO_DDS_CODEC 0
+#endif
+
+/** Enables the use of the new script compilers when Ogre compiles resource scripts.
+*/
+#ifndef OGRE_USE_NEW_COMPILERS
+#define OGRE_USE_NEW_COMPILERS 1
+#endif
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreConfig.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMath.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreMath.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMath.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,449 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+#include "OgreMath.h"
+#include "asm_math.h"
+#include "OgreVector2.h"
+#include "OgreVector3.h"
+#include "OgreVector4.h"
+#include "OgreMatrix4.h"
+
+
+namespace Ogre
+{
+
+ const Real Math::POS_INFINITY = std::numeric_limits<Real>::infinity();
+ const Real Math::NEG_INFINITY = -std::numeric_limits<Real>::infinity();
+ const Real Math::PI = Real( 4.0 * atan( 1.0 ) );
+ const Real Math::TWO_PI = Real( 2.0 * PI );
+ const Real Math::HALF_PI = Real( 0.5 * PI );
+ const Real Math::fDeg2Rad = PI / Real(180.0);
+ const Real Math::fRad2Deg = Real(180.0) / PI;
+
+ int Math::mTrigTableSize;
+ Math::AngleUnit Math::msAngleUnit;
+
+ Real Math::mTrigTableFactor;
+ Real *Math::mSinTable = NULL;
+ Real *Math::mTanTable = NULL;
+
+ //-----------------------------------------------------------------------
+ Math::Math( unsigned int trigTableSize )
+ {
+ msAngleUnit = AU_DEGREE;
+
+ mTrigTableSize = trigTableSize;
+ mTrigTableFactor = mTrigTableSize / Math::TWO_PI;
+
+ mSinTable = static_cast<Real*>(malloc(mTrigTableSize * sizeof(Real)));
+ mTanTable = static_cast<Real*>(malloc(mTrigTableSize * sizeof(Real)));
+
+ buildTrigTables();
+ }
+
+ //-----------------------------------------------------------------------
+ Math::~Math()
+ {
+ free(mSinTable);
+ free(mTanTable);
+ }
+
+ //-----------------------------------------------------------------------
+ void Math::buildTrigTables(void)
+ {
+ // Build trig lookup tables
+ // Could get away with building only PI sized Sin table but simpler this
+ // way. Who cares, it'll ony use an extra 8k of memory anyway and I like
+ // simplicity.
+ Real angle;
+ for (int i = 0; i < mTrigTableSize; ++i)
+ {
+ angle = Math::TWO_PI * i / mTrigTableSize;
+ mSinTable[i] = sin(angle);
+ mTanTable[i] = tan(angle);
+ }
+ }
+ //-----------------------------------------------------------------------
+ Real Math::SinTable (Real fValue)
+ {
+ // Convert range to index values, wrap if required
+ int idx;
+ if (fValue >= 0)
+ {
+ idx = int(fValue * mTrigTableFactor) % mTrigTableSize;
+ }
+ else
+ {
+ idx = mTrigTableSize - (int(-fValue * mTrigTableFactor) % mTrigTableSize) - 1;
+ }
+
+ return mSinTable[idx];
+ }
+ //-----------------------------------------------------------------------
+ Real Math::TanTable (Real fValue)
+ {
+ // Convert range to index values, wrap if required
+ int idx = int(fValue *= mTrigTableFactor) % mTrigTableSize;
+ return mTanTable[idx];
+ }
+ //-----------------------------------------------------------------------
+ int Math::ISign (int iValue)
+ {
+ return ( iValue > 0 ? +1 : ( iValue < 0 ? -1 : 0 ) );
+ }
+ //-----------------------------------------------------------------------
+ Radian Math::ACos (Real fValue)
+ {
+ if ( -1.0 < fValue )
+ {
+ if ( fValue < 1.0 )
+ return Radian(acos(fValue));
+ else
+ return Radian(0.0);
+ }
+ else
+ {
+ return Radian(PI);
+ }
+ }
+ //-----------------------------------------------------------------------
+ Radian Math::ASin (Real fValue)
+ {
+ if ( -1.0 < fValue )
+ {
+ if ( fValue < 1.0 )
+ return Radian(asin(fValue));
+ else
+ return Radian(HALF_PI);
+ }
+ else
+ {
+ return Radian(-HALF_PI);
+ }
+ }
+ //-----------------------------------------------------------------------
+ Real Math::Sign (Real fValue)
+ {
+ if ( fValue > 0.0 )
+ return 1.0;
+
+ if ( fValue < 0.0 )
+ return -1.0;
+
+ return 0.0;
+ }
+ //-----------------------------------------------------------------------
+ Real Math::InvSqrt(Real fValue)
+ {
+ return Real(asm_rsq(fValue));
+ }
+ //-----------------------------------------------------------------------
+ Real Math::UnitRandom ()
+ {
+ return asm_rand() / asm_rand_max();
+ }
+
+ //-----------------------------------------------------------------------
+ Real Math::RangeRandom (Real fLow, Real fHigh)
+ {
+ return (fHigh-fLow)*UnitRandom() + fLow;
+ }
+
+ //-----------------------------------------------------------------------
+ Real Math::SymmetricRandom ()
+ {
+ return 2.0f * UnitRandom() - 1.0f;
+ }
+
+ //-----------------------------------------------------------------------
+ void Math::setAngleUnit(Math::AngleUnit unit)
+ {
+ msAngleUnit = unit;
+ }
+ //-----------------------------------------------------------------------
+ Math::AngleUnit Math::getAngleUnit(void)
+ {
+ return msAngleUnit;
+ }
+ //-----------------------------------------------------------------------
+ Real Math::AngleUnitsToRadians(Real angleunits)
+ {
+ if (msAngleUnit == AU_DEGREE)
+ return angleunits * fDeg2Rad;
+ else
+ return angleunits;
+ }
+
+ //-----------------------------------------------------------------------
+ Real Math::RadiansToAngleUnits(Real radians)
+ {
+ if (msAngleUnit == AU_DEGREE)
+ return radians * fRad2Deg;
+ else
+ return radians;
+ }
+
+ //-----------------------------------------------------------------------
+ Real Math::AngleUnitsToDegrees(Real angleunits)
+ {
+ if (msAngleUnit == AU_RADIAN)
+ return angleunits * fRad2Deg;
+ else
+ return angleunits;
+ }
+
+ //-----------------------------------------------------------------------
+ Real Math::DegreesToAngleUnits(Real degrees)
+ {
+ if (msAngleUnit == AU_RADIAN)
+ return degrees * fDeg2Rad;
+ else
+ return degrees;
+ }
+
+ //-----------------------------------------------------------------------
+ bool Math::pointInTri2D(const Vector2& p, const Vector2& a,
+ const Vector2& b, const Vector2& c)
+ {
+ // Winding must be consistent from all edges for point to be inside
+ Vector2 v1, v2;
+ Real dot[3];
+ bool zeroDot[3];
+
+ v1 = b - a;
+ v2 = p - a;
+
+ // Note we don't care about normalisation here since sign is all we need
+ // It means we don't have to worry about magnitude of cross products either
+ dot[0] = v1.crossProduct(v2);
+ zeroDot[0] = Math::RealEqual(dot[0], 0.0f, 1e-3);
+
+
+ v1 = c - b;
+ v2 = p - b;
+
+ dot[1] = v1.crossProduct(v2);
+ zeroDot[1] = Math::RealEqual(dot[1], 0.0f, 1e-3);
+
+ // Compare signs (ignore colinear / coincident points)
+ if(!zeroDot[0] && !zeroDot[1]
+ && Math::Sign(dot[0]) != Math::Sign(dot[1]))
+ {
+ return false;
+ }
+
+ v1 = a - c;
+ v2 = p - c;
+
+ dot[2] = v1.crossProduct(v2);
+ zeroDot[2] = Math::RealEqual(dot[2], 0.0f, 1e-3);
+ // Compare signs (ignore colinear / coincident points)
+ if((!zeroDot[0] && !zeroDot[2]
+ && Math::Sign(dot[0]) != Math::Sign(dot[2])) ||
+ (!zeroDot[1] && !zeroDot[2]
+ && Math::Sign(dot[1]) != Math::Sign(dot[2])))
+ {
+ return false;
+ }
+
+
+ return true;
+ }
+ //-----------------------------------------------------------------------
+ bool Math::pointInTri3D(const Vector3& p, const Vector3& a,
+ const Vector3& b, const Vector3& c, const Vector3& normal)
+ {
+ // Winding must be consistent from all edges for point to be inside
+ Vector3 v1, v2;
+ Real dot[3];
+ bool zeroDot[3];
+
+ v1 = b - a;
+ v2 = p - a;
+
+ // Note we don't care about normalisation here since sign is all we need
+ // It means we don't have to worry about magnitude of cross products either
+ dot[0] = v1.crossProduct(v2).dotProduct(normal);
+ zeroDot[0] = Math::RealEqual(dot[0], 0.0f, 1e-3);
+
+
+ v1 = c - b;
+ v2 = p - b;
+
+ dot[1] = v1.crossProduct(v2).dotProduct(normal);
+ zeroDot[1] = Math::RealEqual(dot[1], 0.0f, 1e-3);
+
+ // Compare signs (ignore colinear / coincident points)
+ if(!zeroDot[0] && !zeroDot[1]
+ && Math::Sign(dot[0]) != Math::Sign(dot[1]))
+ {
+ return false;
+ }
+
+ v1 = a - c;
+ v2 = p - c;
+
+ dot[2] = v1.crossProduct(v2).dotProduct(normal);
+ zeroDot[2] = Math::RealEqual(dot[2], 0.0f, 1e-3);
+ // Compare signs (ignore colinear / coincident points)
+ if((!zeroDot[0] && !zeroDot[2]
+ && Math::Sign(dot[0]) != Math::Sign(dot[2])) ||
+ (!zeroDot[1] && !zeroDot[2]
+ && Math::Sign(dot[1]) != Math::Sign(dot[2])))
+ {
+ return false;
+ }
+
+
+ return true;
+ }
+ //-----------------------------------------------------------------------
+ bool Math::RealEqual( Real a, Real b, Real tolerance )
+ {
+ if (fabs(b-a) <= tolerance)
+ return true;
+ else
+ return false;
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Math::calculateTangentSpaceVector(
+ const Vector3& position1, const Vector3& position2, const Vector3& position3,
+ Real u1, Real v1, Real u2, Real v2, Real u3, Real v3)
+ {
+ //side0 is the vector along one side of the triangle of vertices passed in,
+ //and side1 is the vector along another side. Taking the cross product of these returns the normal.
+ Vector3 side0 = position1 - position2;
+ Vector3 side1 = position3 - position1;
+ //Calculate face normal
+ Vector3 normal = side1.crossProduct(side0);
+ normal.normalise();
+ //Now we use a formula to calculate the tangent.
+ Real deltaV0 = v1 - v2;
+ Real deltaV1 = v3 - v1;
+ Vector3 tangent = deltaV1 * side0 - deltaV0 * side1;
+ tangent.normalise();
+ //Calculate binormal
+ Real deltaU0 = u1 - u2;
+ Real deltaU1 = u3 - u1;
+ Vector3 binormal = deltaU1 * side0 - deltaU0 * side1;
+ binormal.normalise();
+ //Now, we take the cross product of the tangents to get a vector which
+ //should point in the same direction as our normal calculated above.
+ //If it points in the opposite direction (the dot product between the normals is less than zero),
+ //then we need to reverse the s and t tangents.
+ //This is because the triangle has been mirrored when going from tangent space to object space.
+ //reverse tangents if necessary
+ Vector3 tangentCross = tangent.crossProduct(binormal);
+ if (tangentCross.dotProduct(normal) < 0.0f)
+ {
+ tangent = -tangent;
+ binormal = -binormal;
+ }
+
+ return tangent;
+
+ }
+ //-----------------------------------------------------------------------
+ Vector4 Math::calculateFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3)
+ {
+ Vector3 normal = calculateBasicFaceNormal(v1, v2, v3);
+ // Now set up the w (distance of tri from origin
+ return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Math::calculateBasicFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3)
+ {
+ Vector3 normal = (v2 - v1).crossProduct(v3 - v1);
+ normal.normalise();
+ return normal;
+ }
+ //-----------------------------------------------------------------------
+ Vector4 Math::calculateFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3)
+ {
+ Vector3 normal = calculateBasicFaceNormalWithoutNormalize(v1, v2, v3);
+ // Now set up the w (distance of tri from origin)
+ return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Math::calculateBasicFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3)
+ {
+ Vector3 normal = (v2 - v1).crossProduct(v3 - v1);
+ return normal;
+ }
+ //-----------------------------------------------------------------------
+ Real Math::gaussianDistribution(Real x, Real offset, Real scale)
+ {
+ Real nom = Math::Exp(
+ -Math::Sqr(x - offset) / (2 * Math::Sqr(scale)));
+ Real denom = scale * Math::Sqrt(2 * Math::PI);
+
+ return nom / denom;
+
+ }
+ //---------------------------------------------------------------------
+ Matrix4 Math::makeViewMatrix(const Vector3& position, const Quaternion& orientation,
+ const Matrix4* reflectMatrix)
+ {
+ Matrix4 viewMatrix;
+
+ // View matrix is:
+ //
+ // [ Lx Uy Dz Tx ]
+ // [ Lx Uy Dz Ty ]
+ // [ Lx Uy Dz Tz ]
+ // [ 0 0 0 1 ]
+ //
+ // Where T = -(Transposed(Rot) * Pos)
+
+ // This is most efficiently done using 3x3 Matrices
+ Matrix3 rot;
+ orientation.ToRotationMatrix(rot);
+
+ // Make the translation relative to new axes
+ Matrix3 rotT = rot.Transpose();
+ Vector3 trans = -rotT * position;
+
+ // Make final matrix
+ viewMatrix = Matrix4::IDENTITY;
+ viewMatrix = rotT; // fills upper 3x3
+ viewMatrix[0][3] = trans.x;
+ viewMatrix[1][3] = trans.y;
+ viewMatrix[2][3] = trans.z;
+
+ // Deal with reflections
+ if (reflectMatrix)
+ {
+ viewMatrix = viewMatrix * (*reflectMatrix);
+ }
+
+ return viewMatrix;
+
+ }
+
+}
Property changes on: sandbox_light/src/external/ogremath/OgreMath.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMath.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreMath.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMath.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,510 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Math_H__
+#define __Math_H__
+
+#include "OgrePrerequisites.h"
+
+#include <cassert>
+#include <cmath>
+#include <vector>
+#include <utility>
+#include <list>
+#include <limits>
+
+namespace Ogre
+{
+ /** Wrapper class which indicates a given angle value is in Radians.
+ @remarks
+ Radian values are interchangeable with Degree values, and conversions
+ will be done automatically between them.
+ */
+ class Radian
+ {
+ Real mRad;
+
+ public:
+ explicit Radian ( Real r=0 ) : mRad(r) {}
+ Radian ( const Degree& d );
+ Radian& operator = ( const Real& f ) { mRad = f; return *this; }
+ Radian& operator = ( const Radian& r ) { mRad = r.mRad; return *this; }
+ Radian& operator = ( const Degree& d );
+
+ Real valueDegrees() const; // see bottom of this file
+ Real valueRadians() const { return mRad; }
+ Real valueAngleUnits() const;
+
+ const Radian& operator + () const { return *this; }
+ Radian operator + ( const Radian& r ) const { return Radian ( mRad + r.mRad ); }
+ Radian operator + ( const Degree& d ) const;
+ Radian& operator += ( const Radian& r ) { mRad += r.mRad; return *this; }
+ Radian& operator += ( const Degree& d );
+ Radian operator - () const { return Radian(-mRad); }
+ Radian operator - ( const Radian& r ) const { return Radian ( mRad - r.mRad ); }
+ Radian operator - ( const Degree& d ) const;
+ Radian& operator -= ( const Radian& r ) { mRad -= r.mRad; return *this; }
+ Radian& operator -= ( const Degree& d );
+ Radian operator * ( Real f ) const { return Radian ( mRad * f ); }
+ Radian operator * ( const Radian& f ) const { return Radian ( mRad * f.mRad ); }
+ Radian& operator *= ( Real f ) { mRad *= f; return *this; }
+ Radian operator / ( Real f ) const { return Radian ( mRad / f ); }
+ Radian& operator /= ( Real f ) { mRad /= f; return *this; }
+
+ bool operator < ( const Radian& r ) const { return mRad < r.mRad; }
+ bool operator <= ( const Radian& r ) const { return mRad <= r.mRad; }
+ bool operator == ( const Radian& r ) const { return mRad == r.mRad; }
+ bool operator != ( const Radian& r ) const { return mRad != r.mRad; }
+ bool operator >= ( const Radian& r ) const { return mRad >= r.mRad; }
+ bool operator > ( const Radian& r ) const { return mRad > r.mRad; }
+ };
+
+ /** Wrapper class which indicates a given angle value is in Degrees.
+ @remarks
+ Degree values are interchangeable with Radian values, and conversions
+ will be done automatically between them.
+ */
+ class Degree
+ {
+ Real mDeg; // if you get an error here - make sure to define/typedef 'Real' first
+
+ public:
+ explicit Degree ( Real d=0 ) : mDeg(d) {}
+ Degree ( const Radian& r ) : mDeg(r.valueDegrees()) {}
+ Degree& operator = ( const Real& f ) { mDeg = f; return *this; }
+ Degree& operator = ( const Degree& d ) { mDeg = d.mDeg; return *this; }
+ Degree& operator = ( const Radian& r ) { mDeg = r.valueDegrees(); return *this; }
+
+ Real valueDegrees() const { return mDeg; }
+ Real valueRadians() const; // see bottom of this file
+ Real valueAngleUnits() const;
+
+ const Degree& operator + () const { return *this; }
+ Degree operator + ( const Degree& d ) const { return Degree ( mDeg + d.mDeg ); }
+ Degree operator + ( const Radian& r ) const { return Degree ( mDeg + r.valueDegrees() ); }
+ Degree& operator += ( const Degree& d ) { mDeg += d.mDeg; return *this; }
+ Degree& operator += ( const Radian& r ) { mDeg += r.valueDegrees(); return *this; }
+ Degree operator - () const { return Degree(-mDeg); }
+ Degree operator - ( const Degree& d ) const { return Degree ( mDeg - d.mDeg ); }
+ Degree operator - ( const Radian& r ) const { return Degree ( mDeg - r.valueDegrees() ); }
+ Degree& operator -= ( const Degree& d ) { mDeg -= d.mDeg; return *this; }
+ Degree& operator -= ( const Radian& r ) { mDeg -= r.valueDegrees(); return *this; }
+ Degree operator * ( Real f ) const { return Degree ( mDeg * f ); }
+ Degree operator * ( const Degree& f ) const { return Degree ( mDeg * f.mDeg ); }
+ Degree& operator *= ( Real f ) { mDeg *= f; return *this; }
+ Degree operator / ( Real f ) const { return Degree ( mDeg / f ); }
+ Degree& operator /= ( Real f ) { mDeg /= f; return *this; }
+
+ bool operator < ( const Degree& d ) const { return mDeg < d.mDeg; }
+ bool operator <= ( const Degree& d ) const { return mDeg <= d.mDeg; }
+ bool operator == ( const Degree& d ) const { return mDeg == d.mDeg; }
+ bool operator != ( const Degree& d ) const { return mDeg != d.mDeg; }
+ bool operator >= ( const Degree& d ) const { return mDeg >= d.mDeg; }
+ bool operator > ( const Degree& d ) const { return mDeg > d.mDeg; }
+ };
+
+ /** Wrapper class which identifies a value as the currently default angle
+ type, as defined by Math::setAngleUnit.
+ @remarks
+ Angle values will be automatically converted between radians and degrees,
+ as appropriate.
+ */
+ class Angle
+ {
+ Real mAngle;
+ public:
+ explicit Angle ( Real angle ) : mAngle(angle) {}
+ operator Radian() const;
+ operator Degree() const;
+ };
+
+ // these functions could not be defined within the class definition of class
+ // Radian because they required class Degree to be defined
+ inline Radian::Radian ( const Degree& d ) : mRad(d.valueRadians()) {
+ }
+ inline Radian& Radian::operator = ( const Degree& d ) {
+ mRad = d.valueRadians(); return *this;
+ }
+ inline Radian Radian::operator + ( const Degree& d ) const {
+ return Radian ( mRad + d.valueRadians() );
+ }
+ inline Radian& Radian::operator += ( const Degree& d ) {
+ mRad += d.valueRadians();
+ return *this;
+ }
+ inline Radian Radian::operator - ( const Degree& d ) const {
+ return Radian ( mRad - d.valueRadians() );
+ }
+ inline Radian& Radian::operator -= ( const Degree& d ) {
+ mRad -= d.valueRadians();
+ return *this;
+ }
+
+ /** Class to provide access to common mathematical functions.
+ @remarks
+ Most of the maths functions are aliased versions of the C runtime
+ library functions. They are aliased here to provide future
+ optimisation opportunities, either from faster RTLs or custom
+ math approximations.
+ @note
+ <br>This is based on MgcMath.h from
+ <a href="http://www.geometrictools.com/">Wild Magic</a>.
+ */
+ class _OgreExport Math
+ {
+ public:
+ /** The angular units used by the API. This functionality is now deprecated in favor
+ of discreet angular unit types ( see Degree and Radian above ). The only place
+ this functionality is actually still used is when parsing files. Search for
+ usage of the Angle class for those instances
+ */
+ enum AngleUnit
+ {
+ AU_DEGREE,
+ AU_RADIAN
+ };
+
+ protected:
+ // angle units used by the api
+ static AngleUnit msAngleUnit;
+
+ /// Size of the trig tables as determined by constructor.
+ static int mTrigTableSize;
+
+ /// Radian -> index factor value ( mTrigTableSize / 2 * PI )
+ static Real mTrigTableFactor;
+ static Real* mSinTable;
+ static Real* mTanTable;
+
+ /** Private function to build trig tables.
+ */
+ void buildTrigTables();
+
+ static Real SinTable (Real fValue);
+ static Real TanTable (Real fValue);
+ public:
+ /** Default constructor.
+ @param
+ trigTableSize Optional parameter to set the size of the
+ tables used to implement Sin, Cos, Tan
+ */
+ Math(unsigned int trigTableSize = 4096);
+
+ /** Default destructor.
+ */
+ ~Math();
+
+ static inline int IAbs (int iValue) { return ( iValue >= 0 ? iValue : -iValue ); }
+ static inline int ICeil (float fValue) { return int(ceil(fValue)); }
+ static inline int IFloor (float fValue) { return int(floor(fValue)); }
+ static int ISign (int iValue);
+
+ static inline Real Abs (Real fValue) { return Real(fabs(fValue)); }
+ static inline Degree Abs (const Degree& dValue) { return Degree(fabs(dValue.valueDegrees())); }
+ static inline Radian Abs (const Radian& rValue) { return Radian(fabs(rValue.valueRadians())); }
+ static Radian ACos (Real fValue);
+ static Radian ASin (Real fValue);
+ static inline Radian ATan (Real fValue) { return Radian(atan(fValue)); }
+ static inline Radian ATan2 (Real fY, Real fX) { return Radian(atan2(fY,fX)); }
+ static inline Real Ceil (Real fValue) { return Real(ceil(fValue)); }
+
+ /** Cosine function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Cos (const Radian& fValue, bool useTables = false) {
+ return (!useTables) ? Real(cos(fValue.valueRadians())) : SinTable(fValue.valueRadians() + HALF_PI);
+ }
+ /** Cosine function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Cos (Real fValue, bool useTables = false) {
+ return (!useTables) ? Real(cos(fValue)) : SinTable(fValue + HALF_PI);
+ }
+
+ static inline Real Exp (Real fValue) { return Real(exp(fValue)); }
+
+ static inline Real Floor (Real fValue) { return Real(floor(fValue)); }
+
+ static inline Real Log (Real fValue) { return Real(log(fValue)); }
+
+ static inline Real Pow (Real fBase, Real fExponent) { return Real(pow(fBase,fExponent)); }
+
+ static Real Sign (Real fValue);
+ static inline Radian Sign ( const Radian& rValue )
+ {
+ return Radian(Sign(rValue.valueRadians()));
+ }
+ static inline Degree Sign ( const Degree& dValue )
+ {
+ return Degree(Sign(dValue.valueDegrees()));
+ }
+
+ /** Sine function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Sin (const Radian& fValue, bool useTables = false) {
+ return (!useTables) ? Real(sin(fValue.valueRadians())) : SinTable(fValue.valueRadians());
+ }
+ /** Sine function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Sin (Real fValue, bool useTables = false) {
+ return (!useTables) ? Real(sin(fValue)) : SinTable(fValue);
+ }
+
+ static inline Real Sqr (Real fValue) { return fValue*fValue; }
+
+ static inline Real Sqrt (Real fValue) { return Real(sqrt(fValue)); }
+
+ static inline Radian Sqrt (const Radian& fValue) { return Radian(sqrt(fValue.valueRadians())); }
+
+ static inline Degree Sqrt (const Degree& fValue) { return Degree(sqrt(fValue.valueDegrees())); }
+
+ /** Inverse square root i.e. 1 / Sqrt(x), good for vector
+ normalisation.
+ */
+ static Real InvSqrt(Real fValue);
+
+ static Real UnitRandom (); // in [0,1]
+
+ static Real RangeRandom (Real fLow, Real fHigh); // in [fLow,fHigh]
+
+ static Real SymmetricRandom (); // in [-1,1]
+
+ /** Tangent function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Tan (const Radian& fValue, bool useTables = false) {
+ return (!useTables) ? Real(tan(fValue.valueRadians())) : TanTable(fValue.valueRadians());
+ }
+ /** Tangent function.
+ @param
+ fValue Angle in radians
+ @param
+ useTables If true, uses lookup tables rather than
+ calculation - faster but less accurate.
+ */
+ static inline Real Tan (Real fValue, bool useTables = false) {
+ return (!useTables) ? Real(tan(fValue)) : TanTable(fValue);
+ }
+
+ static inline Real DegreesToRadians(Real degrees) { return degrees * fDeg2Rad; }
+ static inline Real RadiansToDegrees(Real radians) { return radians * fRad2Deg; }
+
+ /** These functions used to set the assumed angle units (radians or degrees)
+ expected when using the Angle type.
+ @par
+ You can set this directly after creating a new Root, and also before/after resource creation,
+ depending on whether you want the change to affect resource files.
+ */
+ static void setAngleUnit(AngleUnit unit);
+ /** Get the unit being used for angles. */
+ static AngleUnit getAngleUnit(void);
+
+ /** Convert from the current AngleUnit to radians. */
+ static Real AngleUnitsToRadians(Real units);
+ /** Convert from radians to the current AngleUnit . */
+ static Real RadiansToAngleUnits(Real radians);
+ /** Convert from the current AngleUnit to degrees. */
+ static Real AngleUnitsToDegrees(Real units);
+ /** Convert from degrees to the current AngleUnit. */
+ static Real DegreesToAngleUnits(Real degrees);
+
+ /** Checks whether a given point is inside a triangle, in a
+ 2-dimensional (Cartesian) space.
+ @remarks
+ The vertices of the triangle must be given in either
+ trigonometrical (anticlockwise) or inverse trigonometrical
+ (clockwise) order.
+ @param
+ p The point.
+ @param
+ a The triangle's first vertex.
+ @param
+ b The triangle's second vertex.
+ @param
+ c The triangle's third vertex.
+ @returns
+ If the point resides in the triangle, <b>true</b> is
+ returned.
+ @par
+ If the point is outside the triangle, <b>false</b> is
+ returned.
+ */
+ static bool pointInTri2D(const Vector2& p, const Vector2& a,
+ const Vector2& b, const Vector2& c);
+
+ /** Checks whether a given 3D point is inside a triangle.
+ @remarks
+ The vertices of the triangle must be given in either
+ trigonometrical (anticlockwise) or inverse trigonometrical
+ (clockwise) order, and the point must be guaranteed to be in the
+ same plane as the triangle
+ @param
+ p The point.
+ @param
+ a The triangle's first vertex.
+ @param
+ b The triangle's second vertex.
+ @param
+ c The triangle's third vertex.
+ @param
+ normal The triangle plane's normal (passed in rather than calculated
+ on demand since the caller may already have it)
+ @returns
+ If the point resides in the triangle, <b>true</b> is
+ returned.
+ @par
+ If the point is outside the triangle, <b>false</b> is
+ returned.
+ */
+ static bool pointInTri3D(const Vector3& p, const Vector3& a,
+ const Vector3& b, const Vector3& c, const Vector3& normal);
+
+ /** Compare 2 reals, using tolerance for inaccuracies.
+ */
+ static bool RealEqual(Real a, Real b,
+ Real tolerance = std::numeric_limits<Real>::epsilon());
+
+ /** Calculates the tangent space vector for a given set of positions / texture coords. */
+ static Vector3 calculateTangentSpaceVector(
+ const Vector3& position1, const Vector3& position2, const Vector3& position3,
+ Real u1, Real v1, Real u2, Real v2, Real u3, Real v3);
+
+ /** Calculate a face normal, including the w component which is the offset from the origin. */
+ static Vector4 calculateFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3);
+ /** Calculate a face normal, no w-information. */
+ static Vector3 calculateBasicFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3);
+ /** Calculate a face normal without normalize, including the w component which is the offset from the origin. */
+ static Vector4 calculateFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3);
+ /** Calculate a face normal without normalize, no w-information. */
+ static Vector3 calculateBasicFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3);
+
+ /** Generates a value based on the Gaussian (normal) distribution function
+ with the given offset and scale parameters.
+ */
+ static Real gaussianDistribution(Real x, Real offset = 0.0f, Real scale = 1.0f);
+
+ /** Clamp a value within an inclusive range. */
+ template <typename T>
+ static T Clamp(T val, T minval, T maxval)
+ {
+ assert (minval < maxval && "Invalid clamp range");
+ return std::max(std::min(val, maxval), minval);
+ }
+
+ static Matrix4 makeViewMatrix(const Vector3& position, const Quaternion& orientation,
+ const Matrix4* reflectMatrix = 0);
+
+
+
+ static const Real POS_INFINITY;
+ static const Real NEG_INFINITY;
+ static const Real PI;
+ static const Real TWO_PI;
+ static const Real HALF_PI;
+ static const Real fDeg2Rad;
+ static const Real fRad2Deg;
+
+ };
+
+ // these functions must be defined down here, because they rely on the
+ // angle unit conversion functions in class Math:
+
+ inline Real Radian::valueDegrees() const
+ {
+ return Math::RadiansToDegrees ( mRad );
+ }
+
+ inline Real Radian::valueAngleUnits() const
+ {
+ return Math::RadiansToAngleUnits ( mRad );
+ }
+
+ inline Real Degree::valueRadians() const
+ {
+ return Math::DegreesToRadians ( mDeg );
+ }
+
+ inline Real Degree::valueAngleUnits() const
+ {
+ return Math::DegreesToAngleUnits ( mDeg );
+ }
+
+ inline Angle::operator Radian() const
+ {
+ return Radian(Math::AngleUnitsToRadians(mAngle));
+ }
+
+ inline Angle::operator Degree() const
+ {
+ return Degree(Math::AngleUnitsToDegrees(mAngle));
+ }
+
+ inline Radian operator * ( Real a, const Radian& b )
+ {
+ return Radian ( a * b.valueRadians() );
+ }
+
+ inline Radian operator / ( Real a, const Radian& b )
+ {
+ return Radian ( a / b.valueRadians() );
+ }
+
+ inline Degree operator * ( Real a, const Degree& b )
+ {
+ return Degree ( a * b.valueDegrees() );
+ }
+
+ inline Degree operator / ( Real a, const Degree& b )
+ {
+ return Degree ( a / b.valueDegrees() );
+ }
+
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreMath.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMatrix3.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreMatrix3.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMatrix3.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,1511 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreMatrix3.h"
+
+#include "OgreMath.h"
+
+// Adapted from Matrix math by Wild Magic http://www.geometrictools.com/
+
+namespace Ogre
+{
+ const Real Matrix3::EPSILON = 1e-06;
+ const Matrix3 Matrix3::ZERO(0,0,0,0,0,0,0,0,0);
+ const Matrix3 Matrix3::IDENTITY(1,0,0,0,1,0,0,0,1);
+ const Real Matrix3::ms_fSvdEpsilon = 1e-04;
+ const unsigned int Matrix3::ms_iSvdMaxIterations = 32;
+
+ //-----------------------------------------------------------------------
+ Vector3 Matrix3::GetColumn (size_t iCol) const
+ {
+ assert( 0 <= iCol && iCol < 3 );
+ return Vector3(m[0][iCol],m[1][iCol],
+ m[2][iCol]);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::SetColumn(size_t iCol, const Vector3& vec)
+ {
+ assert( 0 <= iCol && iCol < 3 );
+ m[0][iCol] = vec.x;
+ m[1][iCol] = vec.y;
+ m[2][iCol] = vec.z;
+
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis)
+ {
+ SetColumn(0,xAxis);
+ SetColumn(1,yAxis);
+ SetColumn(2,zAxis);
+
+ }
+
+ //-----------------------------------------------------------------------
+ bool Matrix3::operator== (const Matrix3& rkMatrix) const
+ {
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ if ( m[iRow][iCol] != rkMatrix.m[iRow][iCol] )
+ return false;
+ }
+ }
+
+ return true;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::operator+ (const Matrix3& rkMatrix) const
+ {
+ Matrix3 kSum;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ kSum.m[iRow][iCol] = m[iRow][iCol] +
+ rkMatrix.m[iRow][iCol];
+ }
+ }
+ return kSum;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::operator- (const Matrix3& rkMatrix) const
+ {
+ Matrix3 kDiff;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ kDiff.m[iRow][iCol] = m[iRow][iCol] -
+ rkMatrix.m[iRow][iCol];
+ }
+ }
+ return kDiff;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::operator* (const Matrix3& rkMatrix) const
+ {
+ Matrix3 kProd;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ kProd.m[iRow][iCol] =
+ m[iRow][0]*rkMatrix.m[0][iCol] +
+ m[iRow][1]*rkMatrix.m[1][iCol] +
+ m[iRow][2]*rkMatrix.m[2][iCol];
+ }
+ }
+ return kProd;
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Matrix3::operator* (const Vector3& rkPoint) const
+ {
+ Vector3 kProd;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ kProd[iRow] =
+ m[iRow][0]*rkPoint[0] +
+ m[iRow][1]*rkPoint[1] +
+ m[iRow][2]*rkPoint[2];
+ }
+ return kProd;
+ }
+ //-----------------------------------------------------------------------
+ Vector3 operator* (const Vector3& rkPoint, const Matrix3& rkMatrix)
+ {
+ Vector3 kProd;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ kProd[iRow] =
+ rkPoint[0]*rkMatrix.m[0][iRow] +
+ rkPoint[1]*rkMatrix.m[1][iRow] +
+ rkPoint[2]*rkMatrix.m[2][iRow];
+ }
+ return kProd;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::operator- () const
+ {
+ Matrix3 kNeg;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ kNeg[iRow][iCol] = -m[iRow][iCol];
+ }
+ return kNeg;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::operator* (Real fScalar) const
+ {
+ Matrix3 kProd;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ kProd[iRow][iCol] = fScalar*m[iRow][iCol];
+ }
+ return kProd;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 operator* (Real fScalar, const Matrix3& rkMatrix)
+ {
+ Matrix3 kProd;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ kProd[iRow][iCol] = fScalar*rkMatrix.m[iRow][iCol];
+ }
+ return kProd;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::Transpose () const
+ {
+ Matrix3 kTranspose;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ kTranspose[iRow][iCol] = m[iCol][iRow];
+ }
+ return kTranspose;
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::Inverse (Matrix3& rkInverse, Real fTolerance) const
+ {
+ // Invert a 3x3 using cofactors. This is about 8 times faster than
+ // the Numerical Recipes code which uses Gaussian elimination.
+
+ rkInverse[0][0] = m[1][1]*m[2][2] -
+ m[1][2]*m[2][1];
+ rkInverse[0][1] = m[0][2]*m[2][1] -
+ m[0][1]*m[2][2];
+ rkInverse[0][2] = m[0][1]*m[1][2] -
+ m[0][2]*m[1][1];
+ rkInverse[1][0] = m[1][2]*m[2][0] -
+ m[1][0]*m[2][2];
+ rkInverse[1][1] = m[0][0]*m[2][2] -
+ m[0][2]*m[2][0];
+ rkInverse[1][2] = m[0][2]*m[1][0] -
+ m[0][0]*m[1][2];
+ rkInverse[2][0] = m[1][0]*m[2][1] -
+ m[1][1]*m[2][0];
+ rkInverse[2][1] = m[0][1]*m[2][0] -
+ m[0][0]*m[2][1];
+ rkInverse[2][2] = m[0][0]*m[1][1] -
+ m[0][1]*m[1][0];
+
+ Real fDet =
+ m[0][0]*rkInverse[0][0] +
+ m[0][1]*rkInverse[1][0]+
+ m[0][2]*rkInverse[2][0];
+
+ if ( Math::Abs(fDet) <= fTolerance )
+ return false;
+
+ Real fInvDet = 1.0/fDet;
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ rkInverse[iRow][iCol] *= fInvDet;
+ }
+
+ return true;
+ }
+ //-----------------------------------------------------------------------
+ Matrix3 Matrix3::Inverse (Real fTolerance) const
+ {
+ Matrix3 kInverse = Matrix3::ZERO;
+ Inverse(kInverse,fTolerance);
+ return kInverse;
+ }
+ //-----------------------------------------------------------------------
+ Real Matrix3::Determinant () const
+ {
+ Real fCofactor00 = m[1][1]*m[2][2] -
+ m[1][2]*m[2][1];
+ Real fCofactor10 = m[1][2]*m[2][0] -
+ m[1][0]*m[2][2];
+ Real fCofactor20 = m[1][0]*m[2][1] -
+ m[1][1]*m[2][0];
+
+ Real fDet =
+ m[0][0]*fCofactor00 +
+ m[0][1]*fCofactor10 +
+ m[0][2]*fCofactor20;
+
+ return fDet;
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::Bidiagonalize (Matrix3& kA, Matrix3& kL,
+ Matrix3& kR)
+ {
+ Real afV[3], afW[3];
+ Real fLength, fSign, fT1, fInvT1, fT2;
+ bool bIdentity;
+
+ // map first column to (*,0,0)
+ fLength = Math::Sqrt(kA[0][0]*kA[0][0] + kA[1][0]*kA[1][0] +
+ kA[2][0]*kA[2][0]);
+ if ( fLength > 0.0 )
+ {
+ fSign = (kA[0][0] > 0.0 ? 1.0 : -1.0);
+ fT1 = kA[0][0] + fSign*fLength;
+ fInvT1 = 1.0/fT1;
+ afV[1] = kA[1][0]*fInvT1;
+ afV[2] = kA[2][0]*fInvT1;
+
+ fT2 = -2.0/(1.0+afV[1]*afV[1]+afV[2]*afV[2]);
+ afW[0] = fT2*(kA[0][0]+kA[1][0]*afV[1]+kA[2][0]*afV[2]);
+ afW[1] = fT2*(kA[0][1]+kA[1][1]*afV[1]+kA[2][1]*afV[2]);
+ afW[2] = fT2*(kA[0][2]+kA[1][2]*afV[1]+kA[2][2]*afV[2]);
+ kA[0][0] += afW[0];
+ kA[0][1] += afW[1];
+ kA[0][2] += afW[2];
+ kA[1][1] += afV[1]*afW[1];
+ kA[1][2] += afV[1]*afW[2];
+ kA[2][1] += afV[2]*afW[1];
+ kA[2][2] += afV[2]*afW[2];
+
+ kL[0][0] = 1.0+fT2;
+ kL[0][1] = kL[1][0] = fT2*afV[1];
+ kL[0][2] = kL[2][0] = fT2*afV[2];
+ kL[1][1] = 1.0+fT2*afV[1]*afV[1];
+ kL[1][2] = kL[2][1] = fT2*afV[1]*afV[2];
+ kL[2][2] = 1.0+fT2*afV[2]*afV[2];
+ bIdentity = false;
+ }
+ else
+ {
+ kL = Matrix3::IDENTITY;
+ bIdentity = true;
+ }
+
+ // map first row to (*,*,0)
+ fLength = Math::Sqrt(kA[0][1]*kA[0][1]+kA[0][2]*kA[0][2]);
+ if ( fLength > 0.0 )
+ {
+ fSign = (kA[0][1] > 0.0 ? 1.0 : -1.0);
+ fT1 = kA[0][1] + fSign*fLength;
+ afV[2] = kA[0][2]/fT1;
+
+ fT2 = -2.0/(1.0+afV[2]*afV[2]);
+ afW[0] = fT2*(kA[0][1]+kA[0][2]*afV[2]);
+ afW[1] = fT2*(kA[1][1]+kA[1][2]*afV[2]);
+ afW[2] = fT2*(kA[2][1]+kA[2][2]*afV[2]);
+ kA[0][1] += afW[0];
+ kA[1][1] += afW[1];
+ kA[1][2] += afW[1]*afV[2];
+ kA[2][1] += afW[2];
+ kA[2][2] += afW[2]*afV[2];
+
+ kR[0][0] = 1.0;
+ kR[0][1] = kR[1][0] = 0.0;
+ kR[0][2] = kR[2][0] = 0.0;
+ kR[1][1] = 1.0+fT2;
+ kR[1][2] = kR[2][1] = fT2*afV[2];
+ kR[2][2] = 1.0+fT2*afV[2]*afV[2];
+ }
+ else
+ {
+ kR = Matrix3::IDENTITY;
+ }
+
+ // map second column to (*,*,0)
+ fLength = Math::Sqrt(kA[1][1]*kA[1][1]+kA[2][1]*kA[2][1]);
+ if ( fLength > 0.0 )
+ {
+ fSign = (kA[1][1] > 0.0 ? 1.0 : -1.0);
+ fT1 = kA[1][1] + fSign*fLength;
+ afV[2] = kA[2][1]/fT1;
+
+ fT2 = -2.0/(1.0+afV[2]*afV[2]);
+ afW[1] = fT2*(kA[1][1]+kA[2][1]*afV[2]);
+ afW[2] = fT2*(kA[1][2]+kA[2][2]*afV[2]);
+ kA[1][1] += afW[1];
+ kA[1][2] += afW[2];
+ kA[2][2] += afV[2]*afW[2];
+
+ Real fA = 1.0+fT2;
+ Real fB = fT2*afV[2];
+ Real fC = 1.0+fB*afV[2];
+
+ if ( bIdentity )
+ {
+ kL[0][0] = 1.0;
+ kL[0][1] = kL[1][0] = 0.0;
+ kL[0][2] = kL[2][0] = 0.0;
+ kL[1][1] = fA;
+ kL[1][2] = kL[2][1] = fB;
+ kL[2][2] = fC;
+ }
+ else
+ {
+ for (int iRow = 0; iRow < 3; iRow++)
+ {
+ Real fTmp0 = kL[iRow][1];
+ Real fTmp1 = kL[iRow][2];
+ kL[iRow][1] = fA*fTmp0+fB*fTmp1;
+ kL[iRow][2] = fB*fTmp0+fC*fTmp1;
+ }
+ }
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::GolubKahanStep (Matrix3& kA, Matrix3& kL,
+ Matrix3& kR)
+ {
+ Real fT11 = kA[0][1]*kA[0][1]+kA[1][1]*kA[1][1];
+ Real fT22 = kA[1][2]*kA[1][2]+kA[2][2]*kA[2][2];
+ Real fT12 = kA[1][1]*kA[1][2];
+ Real fTrace = fT11+fT22;
+ Real fDiff = fT11-fT22;
+ Real fDiscr = Math::Sqrt(fDiff*fDiff+4.0*fT12*fT12);
+ Real fRoot1 = 0.5*(fTrace+fDiscr);
+ Real fRoot2 = 0.5*(fTrace-fDiscr);
+
+ // adjust right
+ Real fY = kA[0][0] - (Math::Abs(fRoot1-fT22) <=
+ Math::Abs(fRoot2-fT22) ? fRoot1 : fRoot2);
+ Real fZ = kA[0][1];
+ Real fInvLength = Math::InvSqrt(fY*fY+fZ*fZ);
+ Real fSin = fZ*fInvLength;
+ Real fCos = -fY*fInvLength;
+
+ Real fTmp0 = kA[0][0];
+ Real fTmp1 = kA[0][1];
+ kA[0][0] = fCos*fTmp0-fSin*fTmp1;
+ kA[0][1] = fSin*fTmp0+fCos*fTmp1;
+ kA[1][0] = -fSin*kA[1][1];
+ kA[1][1] *= fCos;
+
+ size_t iRow;
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ fTmp0 = kR[0][iRow];
+ fTmp1 = kR[1][iRow];
+ kR[0][iRow] = fCos*fTmp0-fSin*fTmp1;
+ kR[1][iRow] = fSin*fTmp0+fCos*fTmp1;
+ }
+
+ // adjust left
+ fY = kA[0][0];
+ fZ = kA[1][0];
+ fInvLength = Math::InvSqrt(fY*fY+fZ*fZ);
+ fSin = fZ*fInvLength;
+ fCos = -fY*fInvLength;
+
+ kA[0][0] = fCos*kA[0][0]-fSin*kA[1][0];
+ fTmp0 = kA[0][1];
+ fTmp1 = kA[1][1];
+ kA[0][1] = fCos*fTmp0-fSin*fTmp1;
+ kA[1][1] = fSin*fTmp0+fCos*fTmp1;
+ kA[0][2] = -fSin*kA[1][2];
+ kA[1][2] *= fCos;
+
+ size_t iCol;
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ fTmp0 = kL[iCol][0];
+ fTmp1 = kL[iCol][1];
+ kL[iCol][0] = fCos*fTmp0-fSin*fTmp1;
+ kL[iCol][1] = fSin*fTmp0+fCos*fTmp1;
+ }
+
+ // adjust right
+ fY = kA[0][1];
+ fZ = kA[0][2];
+ fInvLength = Math::InvSqrt(fY*fY+fZ*fZ);
+ fSin = fZ*fInvLength;
+ fCos = -fY*fInvLength;
+
+ kA[0][1] = fCos*kA[0][1]-fSin*kA[0][2];
+ fTmp0 = kA[1][1];
+ fTmp1 = kA[1][2];
+ kA[1][1] = fCos*fTmp0-fSin*fTmp1;
+ kA[1][2] = fSin*fTmp0+fCos*fTmp1;
+ kA[2][1] = -fSin*kA[2][2];
+ kA[2][2] *= fCos;
+
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ fTmp0 = kR[1][iRow];
+ fTmp1 = kR[2][iRow];
+ kR[1][iRow] = fCos*fTmp0-fSin*fTmp1;
+ kR[2][iRow] = fSin*fTmp0+fCos*fTmp1;
+ }
+
+ // adjust left
+ fY = kA[1][1];
+ fZ = kA[2][1];
+ fInvLength = Math::InvSqrt(fY*fY+fZ*fZ);
+ fSin = fZ*fInvLength;
+ fCos = -fY*fInvLength;
+
+ kA[1][1] = fCos*kA[1][1]-fSin*kA[2][1];
+ fTmp0 = kA[1][2];
+ fTmp1 = kA[2][2];
+ kA[1][2] = fCos*fTmp0-fSin*fTmp1;
+ kA[2][2] = fSin*fTmp0+fCos*fTmp1;
+
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ fTmp0 = kL[iCol][1];
+ fTmp1 = kL[iCol][2];
+ kL[iCol][1] = fCos*fTmp0-fSin*fTmp1;
+ kL[iCol][2] = fSin*fTmp0+fCos*fTmp1;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::SingularValueDecomposition (Matrix3& kL, Vector3& kS,
+ Matrix3& kR) const
+ {
+ // temas: currently unused
+ //const int iMax = 16;
+ size_t iRow, iCol;
+
+ Matrix3 kA = *this;
+ Bidiagonalize(kA,kL,kR);
+
+ for (unsigned int i = 0; i < ms_iSvdMaxIterations; i++)
+ {
+ Real fTmp, fTmp0, fTmp1;
+ Real fSin0, fCos0, fTan0;
+ Real fSin1, fCos1, fTan1;
+
+ bool bTest1 = (Math::Abs(kA[0][1]) <=
+ ms_fSvdEpsilon*(Math::Abs(kA[0][0])+Math::Abs(kA[1][1])));
+ bool bTest2 = (Math::Abs(kA[1][2]) <=
+ ms_fSvdEpsilon*(Math::Abs(kA[1][1])+Math::Abs(kA[2][2])));
+ if ( bTest1 )
+ {
+ if ( bTest2 )
+ {
+ kS[0] = kA[0][0];
+ kS[1] = kA[1][1];
+ kS[2] = kA[2][2];
+ break;
+ }
+ else
+ {
+ // 2x2 closed form factorization
+ fTmp = (kA[1][1]*kA[1][1] - kA[2][2]*kA[2][2] +
+ kA[1][2]*kA[1][2])/(kA[1][2]*kA[2][2]);
+ fTan0 = 0.5*(fTmp+Math::Sqrt(fTmp*fTmp + 4.0));
+ fCos0 = Math::InvSqrt(1.0+fTan0*fTan0);
+ fSin0 = fTan0*fCos0;
+
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ fTmp0 = kL[iCol][1];
+ fTmp1 = kL[iCol][2];
+ kL[iCol][1] = fCos0*fTmp0-fSin0*fTmp1;
+ kL[iCol][2] = fSin0*fTmp0+fCos0*fTmp1;
+ }
+
+ fTan1 = (kA[1][2]-kA[2][2]*fTan0)/kA[1][1];
+ fCos1 = Math::InvSqrt(1.0+fTan1*fTan1);
+ fSin1 = -fTan1*fCos1;
+
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ fTmp0 = kR[1][iRow];
+ fTmp1 = kR[2][iRow];
+ kR[1][iRow] = fCos1*fTmp0-fSin1*fTmp1;
+ kR[2][iRow] = fSin1*fTmp0+fCos1*fTmp1;
+ }
+
+ kS[0] = kA[0][0];
+ kS[1] = fCos0*fCos1*kA[1][1] -
+ fSin1*(fCos0*kA[1][2]-fSin0*kA[2][2]);
+ kS[2] = fSin0*fSin1*kA[1][1] +
+ fCos1*(fSin0*kA[1][2]+fCos0*kA[2][2]);
+ break;
+ }
+ }
+ else
+ {
+ if ( bTest2 )
+ {
+ // 2x2 closed form factorization
+ fTmp = (kA[0][0]*kA[0][0] + kA[1][1]*kA[1][1] -
+ kA[0][1]*kA[0][1])/(kA[0][1]*kA[1][1]);
+ fTan0 = 0.5*(-fTmp+Math::Sqrt(fTmp*fTmp + 4.0));
+ fCos0 = Math::InvSqrt(1.0+fTan0*fTan0);
+ fSin0 = fTan0*fCos0;
+
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ fTmp0 = kL[iCol][0];
+ fTmp1 = kL[iCol][1];
+ kL[iCol][0] = fCos0*fTmp0-fSin0*fTmp1;
+ kL[iCol][1] = fSin0*fTmp0+fCos0*fTmp1;
+ }
+
+ fTan1 = (kA[0][1]-kA[1][1]*fTan0)/kA[0][0];
+ fCos1 = Math::InvSqrt(1.0+fTan1*fTan1);
+ fSin1 = -fTan1*fCos1;
+
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ fTmp0 = kR[0][iRow];
+ fTmp1 = kR[1][iRow];
+ kR[0][iRow] = fCos1*fTmp0-fSin1*fTmp1;
+ kR[1][iRow] = fSin1*fTmp0+fCos1*fTmp1;
+ }
+
+ kS[0] = fCos0*fCos1*kA[0][0] -
+ fSin1*(fCos0*kA[0][1]-fSin0*kA[1][1]);
+ kS[1] = fSin0*fSin1*kA[0][0] +
+ fCos1*(fSin0*kA[0][1]+fCos0*kA[1][1]);
+ kS[2] = kA[2][2];
+ break;
+ }
+ else
+ {
+ GolubKahanStep(kA,kL,kR);
+ }
+ }
+ }
+
+ // positize diagonal
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ if ( kS[iRow] < 0.0 )
+ {
+ kS[iRow] = -kS[iRow];
+ for (iCol = 0; iCol < 3; iCol++)
+ kR[iRow][iCol] = -kR[iRow][iCol];
+ }
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::SingularValueComposition (const Matrix3& kL,
+ const Vector3& kS, const Matrix3& kR)
+ {
+ size_t iRow, iCol;
+ Matrix3 kTmp;
+
+ // product S*R
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ for (iCol = 0; iCol < 3; iCol++)
+ kTmp[iRow][iCol] = kS[iRow]*kR[iRow][iCol];
+ }
+
+ // product L*S*R
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ m[iRow][iCol] = 0.0;
+ for (int iMid = 0; iMid < 3; iMid++)
+ m[iRow][iCol] += kL[iRow][iMid]*kTmp[iMid][iCol];
+ }
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::Orthonormalize ()
+ {
+ // Algorithm uses Gram-Schmidt orthogonalization. If 'this' matrix is
+ // M = [m0|m1|m2], then orthonormal output matrix is Q = [q0|q1|q2],
+ //
+ // q0 = m0/|m0|
+ // q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0|
+ // q2 = (m2-(q0*m2)q0-(q1*m2)q1)/|m2-(q0*m2)q0-(q1*m2)q1|
+ //
+ // where |V| indicates length of vector V and A*B indicates dot
+ // product of vectors A and B.
+
+ // compute q0
+ Real fInvLength = Math::InvSqrt(m[0][0]*m[0][0]
+ + m[1][0]*m[1][0] +
+ m[2][0]*m[2][0]);
+
+ m[0][0] *= fInvLength;
+ m[1][0] *= fInvLength;
+ m[2][0] *= fInvLength;
+
+ // compute q1
+ Real fDot0 =
+ m[0][0]*m[0][1] +
+ m[1][0]*m[1][1] +
+ m[2][0]*m[2][1];
+
+ m[0][1] -= fDot0*m[0][0];
+ m[1][1] -= fDot0*m[1][0];
+ m[2][1] -= fDot0*m[2][0];
+
+ fInvLength = Math::InvSqrt(m[0][1]*m[0][1] +
+ m[1][1]*m[1][1] +
+ m[2][1]*m[2][1]);
+
+ m[0][1] *= fInvLength;
+ m[1][1] *= fInvLength;
+ m[2][1] *= fInvLength;
+
+ // compute q2
+ Real fDot1 =
+ m[0][1]*m[0][2] +
+ m[1][1]*m[1][2] +
+ m[2][1]*m[2][2];
+
+ fDot0 =
+ m[0][0]*m[0][2] +
+ m[1][0]*m[1][2] +
+ m[2][0]*m[2][2];
+
+ m[0][2] -= fDot0*m[0][0] + fDot1*m[0][1];
+ m[1][2] -= fDot0*m[1][0] + fDot1*m[1][1];
+ m[2][2] -= fDot0*m[2][0] + fDot1*m[2][1];
+
+ fInvLength = Math::InvSqrt(m[0][2]*m[0][2] +
+ m[1][2]*m[1][2] +
+ m[2][2]*m[2][2]);
+
+ m[0][2] *= fInvLength;
+ m[1][2] *= fInvLength;
+ m[2][2] *= fInvLength;
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::QDUDecomposition (Matrix3& kQ,
+ Vector3& kD, Vector3& kU) const
+ {
+ // Factor M = QR = QDU where Q is orthogonal, D is diagonal,
+ // and U is upper triangular with ones on its diagonal. Algorithm uses
+ // Gram-Schmidt orthogonalization (the QR algorithm).
+ //
+ // If M = [ m0 | m1 | m2 ] and Q = [ q0 | q1 | q2 ], then
+ //
+ // q0 = m0/|m0|
+ // q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0|
+ // q2 = (m2-(q0*m2)q0-(q1*m2)q1)/|m2-(q0*m2)q0-(q1*m2)q1|
+ //
+ // where |V| indicates length of vector V and A*B indicates dot
+ // product of vectors A and B. The matrix R has entries
+ //
+ // r00 = q0*m0 r01 = q0*m1 r02 = q0*m2
+ // r10 = 0 r11 = q1*m1 r12 = q1*m2
+ // r20 = 0 r21 = 0 r22 = q2*m2
+ //
+ // so D = diag(r00,r11,r22) and U has entries u01 = r01/r00,
+ // u02 = r02/r00, and u12 = r12/r11.
+
+ // Q = rotation
+ // D = scaling
+ // U = shear
+
+ // D stores the three diagonal entries r00, r11, r22
+ // U stores the entries U[0] = u01, U[1] = u02, U[2] = u12
+
+ // build orthogonal matrix Q
+ Real fInvLength = Math::InvSqrt(m[0][0]*m[0][0]
+ + m[1][0]*m[1][0] +
+ m[2][0]*m[2][0]);
+ kQ[0][0] = m[0][0]*fInvLength;
+ kQ[1][0] = m[1][0]*fInvLength;
+ kQ[2][0] = m[2][0]*fInvLength;
+
+ Real fDot = kQ[0][0]*m[0][1] + kQ[1][0]*m[1][1] +
+ kQ[2][0]*m[2][1];
+ kQ[0][1] = m[0][1]-fDot*kQ[0][0];
+ kQ[1][1] = m[1][1]-fDot*kQ[1][0];
+ kQ[2][1] = m[2][1]-fDot*kQ[2][0];
+ fInvLength = Math::InvSqrt(kQ[0][1]*kQ[0][1] + kQ[1][1]*kQ[1][1] +
+ kQ[2][1]*kQ[2][1]);
+ kQ[0][1] *= fInvLength;
+ kQ[1][1] *= fInvLength;
+ kQ[2][1] *= fInvLength;
+
+ fDot = kQ[0][0]*m[0][2] + kQ[1][0]*m[1][2] +
+ kQ[2][0]*m[2][2];
+ kQ[0][2] = m[0][2]-fDot*kQ[0][0];
+ kQ[1][2] = m[1][2]-fDot*kQ[1][0];
+ kQ[2][2] = m[2][2]-fDot*kQ[2][0];
+ fDot = kQ[0][1]*m[0][2] + kQ[1][1]*m[1][2] +
+ kQ[2][1]*m[2][2];
+ kQ[0][2] -= fDot*kQ[0][1];
+ kQ[1][2] -= fDot*kQ[1][1];
+ kQ[2][2] -= fDot*kQ[2][1];
+ fInvLength = Math::InvSqrt(kQ[0][2]*kQ[0][2] + kQ[1][2]*kQ[1][2] +
+ kQ[2][2]*kQ[2][2]);
+ kQ[0][2] *= fInvLength;
+ kQ[1][2] *= fInvLength;
+ kQ[2][2] *= fInvLength;
+
+ // guarantee that orthogonal matrix has determinant 1 (no reflections)
+ Real fDet = kQ[0][0]*kQ[1][1]*kQ[2][2] + kQ[0][1]*kQ[1][2]*kQ[2][0] +
+ kQ[0][2]*kQ[1][0]*kQ[2][1] - kQ[0][2]*kQ[1][1]*kQ[2][0] -
+ kQ[0][1]*kQ[1][0]*kQ[2][2] - kQ[0][0]*kQ[1][2]*kQ[2][1];
+
+ if ( fDet < 0.0 )
+ {
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ kQ[iRow][iCol] = -kQ[iRow][iCol];
+ }
+
+ // build "right" matrix R
+ Matrix3 kR;
+ kR[0][0] = kQ[0][0]*m[0][0] + kQ[1][0]*m[1][0] +
+ kQ[2][0]*m[2][0];
+ kR[0][1] = kQ[0][0]*m[0][1] + kQ[1][0]*m[1][1] +
+ kQ[2][0]*m[2][1];
+ kR[1][1] = kQ[0][1]*m[0][1] + kQ[1][1]*m[1][1] +
+ kQ[2][1]*m[2][1];
+ kR[0][2] = kQ[0][0]*m[0][2] + kQ[1][0]*m[1][2] +
+ kQ[2][0]*m[2][2];
+ kR[1][2] = kQ[0][1]*m[0][2] + kQ[1][1]*m[1][2] +
+ kQ[2][1]*m[2][2];
+ kR[2][2] = kQ[0][2]*m[0][2] + kQ[1][2]*m[1][2] +
+ kQ[2][2]*m[2][2];
+
+ // the scaling component
+ kD[0] = kR[0][0];
+ kD[1] = kR[1][1];
+ kD[2] = kR[2][2];
+
+ // the shear component
+ Real fInvD0 = 1.0/kD[0];
+ kU[0] = kR[0][1]*fInvD0;
+ kU[1] = kR[0][2]*fInvD0;
+ kU[2] = kR[1][2]/kD[1];
+ }
+ //-----------------------------------------------------------------------
+ Real Matrix3::MaxCubicRoot (Real afCoeff[3])
+ {
+ // Spectral norm is for A^T*A, so characteristic polynomial
+ // P(x) = c[0]+c[1]*x+c[2]*x^2+x^3 has three positive real roots.
+ // This yields the assertions c[0] < 0 and c[2]*c[2] >= 3*c[1].
+
+ // quick out for uniform scale (triple root)
+ const Real fOneThird = 1.0/3.0;
+ const Real fEpsilon = 1e-06;
+ Real fDiscr = afCoeff[2]*afCoeff[2] - 3.0*afCoeff[1];
+ if ( fDiscr <= fEpsilon )
+ return -fOneThird*afCoeff[2];
+
+ // Compute an upper bound on roots of P(x). This assumes that A^T*A
+ // has been scaled by its largest entry.
+ Real fX = 1.0;
+ Real fPoly = afCoeff[0]+fX*(afCoeff[1]+fX*(afCoeff[2]+fX));
+ if ( fPoly < 0.0 )
+ {
+ // uses a matrix norm to find an upper bound on maximum root
+ fX = Math::Abs(afCoeff[0]);
+ Real fTmp = 1.0+Math::Abs(afCoeff[1]);
+ if ( fTmp > fX )
+ fX = fTmp;
+ fTmp = 1.0+Math::Abs(afCoeff[2]);
+ if ( fTmp > fX )
+ fX = fTmp;
+ }
+
+ // Newton's method to find root
+ Real fTwoC2 = 2.0*afCoeff[2];
+ for (int i = 0; i < 16; i++)
+ {
+ fPoly = afCoeff[0]+fX*(afCoeff[1]+fX*(afCoeff[2]+fX));
+ if ( Math::Abs(fPoly) <= fEpsilon )
+ return fX;
+
+ Real fDeriv = afCoeff[1]+fX*(fTwoC2+3.0*fX);
+ fX -= fPoly/fDeriv;
+ }
+
+ return fX;
+ }
+ //-----------------------------------------------------------------------
+ Real Matrix3::SpectralNorm () const
+ {
+ Matrix3 kP;
+ size_t iRow, iCol;
+ Real fPmax = 0.0;
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ for (iCol = 0; iCol < 3; iCol++)
+ {
+ kP[iRow][iCol] = 0.0;
+ for (int iMid = 0; iMid < 3; iMid++)
+ {
+ kP[iRow][iCol] +=
+ m[iMid][iRow]*m[iMid][iCol];
+ }
+ if ( kP[iRow][iCol] > fPmax )
+ fPmax = kP[iRow][iCol];
+ }
+ }
+
+ Real fInvPmax = 1.0/fPmax;
+ for (iRow = 0; iRow < 3; iRow++)
+ {
+ for (iCol = 0; iCol < 3; iCol++)
+ kP[iRow][iCol] *= fInvPmax;
+ }
+
+ Real afCoeff[3];
+ afCoeff[0] = -(kP[0][0]*(kP[1][1]*kP[2][2]-kP[1][2]*kP[2][1]) +
+ kP[0][1]*(kP[2][0]*kP[1][2]-kP[1][0]*kP[2][2]) +
+ kP[0][2]*(kP[1][0]*kP[2][1]-kP[2][0]*kP[1][1]));
+ afCoeff[1] = kP[0][0]*kP[1][1]-kP[0][1]*kP[1][0] +
+ kP[0][0]*kP[2][2]-kP[0][2]*kP[2][0] +
+ kP[1][1]*kP[2][2]-kP[1][2]*kP[2][1];
+ afCoeff[2] = -(kP[0][0]+kP[1][1]+kP[2][2]);
+
+ Real fRoot = MaxCubicRoot(afCoeff);
+ Real fNorm = Math::Sqrt(fPmax*fRoot);
+ return fNorm;
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::ToAxisAngle (Vector3& rkAxis, Radian& rfRadians) const
+ {
+ // Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
+ // The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where
+ // I is the identity and
+ //
+ // +- -+
+ // P = | 0 -z +y |
+ // | +z 0 -x |
+ // | -y +x 0 |
+ // +- -+
+ //
+ // If A > 0, R represents a counterclockwise rotation about the axis in
+ // the sense of looking from the tip of the axis vector towards the
+ // origin. Some algebra will show that
+ //
+ // cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P
+ //
+ // In the event that A = pi, R-R^t = 0 which prevents us from extracting
+ // the axis through P. Instead note that R = I+2*P^2 when A = pi, so
+ // P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
+ // z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
+ // it does not matter which sign you choose on the square roots.
+
+ Real fTrace = m[0][0] + m[1][1] + m[2][2];
+ Real fCos = 0.5*(fTrace-1.0);
+ rfRadians = Math::ACos(fCos); // in [0,PI]
+
+ if ( rfRadians > Radian(0.0) )
+ {
+ if ( rfRadians < Radian(Math::PI) )
+ {
+ rkAxis.x = m[2][1]-m[1][2];
+ rkAxis.y = m[0][2]-m[2][0];
+ rkAxis.z = m[1][0]-m[0][1];
+ rkAxis.normalise();
+ }
+ else
+ {
+ // angle is PI
+ float fHalfInverse;
+ if ( m[0][0] >= m[1][1] )
+ {
+ // r00 >= r11
+ if ( m[0][0] >= m[2][2] )
+ {
+ // r00 is maximum diagonal term
+ rkAxis.x = 0.5*Math::Sqrt(m[0][0] -
+ m[1][1] - m[2][2] + 1.0);
+ fHalfInverse = 0.5/rkAxis.x;
+ rkAxis.y = fHalfInverse*m[0][1];
+ rkAxis.z = fHalfInverse*m[0][2];
+ }
+ else
+ {
+ // r22 is maximum diagonal term
+ rkAxis.z = 0.5*Math::Sqrt(m[2][2] -
+ m[0][0] - m[1][1] + 1.0);
+ fHalfInverse = 0.5/rkAxis.z;
+ rkAxis.x = fHalfInverse*m[0][2];
+ rkAxis.y = fHalfInverse*m[1][2];
+ }
+ }
+ else
+ {
+ // r11 > r00
+ if ( m[1][1] >= m[2][2] )
+ {
+ // r11 is maximum diagonal term
+ rkAxis.y = 0.5*Math::Sqrt(m[1][1] -
+ m[0][0] - m[2][2] + 1.0);
+ fHalfInverse = 0.5/rkAxis.y;
+ rkAxis.x = fHalfInverse*m[0][1];
+ rkAxis.z = fHalfInverse*m[1][2];
+ }
+ else
+ {
+ // r22 is maximum diagonal term
+ rkAxis.z = 0.5*Math::Sqrt(m[2][2] -
+ m[0][0] - m[1][1] + 1.0);
+ fHalfInverse = 0.5/rkAxis.z;
+ rkAxis.x = fHalfInverse*m[0][2];
+ rkAxis.y = fHalfInverse*m[1][2];
+ }
+ }
+ }
+ }
+ else
+ {
+ // The angle is 0 and the matrix is the identity. Any axis will
+ // work, so just use the x-axis.
+ rkAxis.x = 1.0;
+ rkAxis.y = 0.0;
+ rkAxis.z = 0.0;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromAxisAngle (const Vector3& rkAxis, const Radian& fRadians)
+ {
+ Real fCos = Math::Cos(fRadians);
+ Real fSin = Math::Sin(fRadians);
+ Real fOneMinusCos = 1.0-fCos;
+ Real fX2 = rkAxis.x*rkAxis.x;
+ Real fY2 = rkAxis.y*rkAxis.y;
+ Real fZ2 = rkAxis.z*rkAxis.z;
+ Real fXYM = rkAxis.x*rkAxis.y*fOneMinusCos;
+ Real fXZM = rkAxis.x*rkAxis.z*fOneMinusCos;
+ Real fYZM = rkAxis.y*rkAxis.z*fOneMinusCos;
+ Real fXSin = rkAxis.x*fSin;
+ Real fYSin = rkAxis.y*fSin;
+ Real fZSin = rkAxis.z*fSin;
+
+ m[0][0] = fX2*fOneMinusCos+fCos;
+ m[0][1] = fXYM-fZSin;
+ m[0][2] = fXZM+fYSin;
+ m[1][0] = fXYM+fZSin;
+ m[1][1] = fY2*fOneMinusCos+fCos;
+ m[1][2] = fYZM-fXSin;
+ m[2][0] = fXZM-fYSin;
+ m[2][1] = fYZM+fXSin;
+ m[2][2] = fZ2*fOneMinusCos+fCos;
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesXYZ (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz -cy*sz sy
+ // cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx
+ // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
+
+ rfPAngle = Radian(Math::ASin(m[0][2]));
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(-m[1][2],m[2][2]);
+ rfRAngle = Math::ATan2(-m[0][1],m[0][0]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(m[1][0],m[1][1]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(m[1][0],m[1][1]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesXZY (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz -sz cz*sy
+ // sx*sy+cx*cy*sz cx*cz -cy*sx+cx*sy*sz
+ // -cx*sy+cy*sx*sz cz*sx cx*cy+sx*sy*sz
+
+ rfPAngle = Math::ASin(-m[0][1]);
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(m[2][1],m[1][1]);
+ rfRAngle = Math::ATan2(m[0][2],m[0][0]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(-m[2][0],m[2][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(-m[2][0],m[2][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesYXZ (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz+sx*sy*sz cz*sx*sy-cy*sz cx*sy
+ // cx*sz cx*cz -sx
+ // -cz*sy+cy*sx*sz cy*cz*sx+sy*sz cx*cy
+
+ rfPAngle = Math::ASin(-m[1][2]);
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(m[0][2],m[2][2]);
+ rfRAngle = Math::ATan2(m[1][0],m[1][1]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(-m[0][1],m[0][0]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(-m[0][1],m[0][0]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesYZX (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz sx*sy-cx*cy*sz cx*sy+cy*sx*sz
+ // sz cx*cz -cz*sx
+ // -cz*sy cy*sx+cx*sy*sz cx*cy-sx*sy*sz
+
+ rfPAngle = Math::ASin(m[1][0]);
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(-m[2][0],m[0][0]);
+ rfRAngle = Math::ATan2(-m[1][2],m[1][1]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(m[2][1],m[2][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(m[2][1],m[2][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesZXY (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz-sx*sy*sz -cx*sz cz*sy+cy*sx*sz
+ // cz*sx*sy+cy*sz cx*cz -cy*cz*sx+sy*sz
+ // -cx*sy sx cx*cy
+
+ rfPAngle = Math::ASin(m[2][1]);
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(-m[0][1],m[1][1]);
+ rfRAngle = Math::ATan2(-m[2][0],m[2][2]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(m[0][2],m[0][0]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(m[0][2],m[0][0]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::ToEulerAnglesZYX (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const
+ {
+ // rot = cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz
+ // cy*sz cx*cz+sx*sy*sz -cz*sx+cx*sy*sz
+ // -sy cy*sx cx*cy
+
+ rfPAngle = Math::ASin(-m[2][0]);
+ if ( rfPAngle < Radian(Math::HALF_PI) )
+ {
+ if ( rfPAngle > Radian(-Math::HALF_PI) )
+ {
+ rfYAngle = Math::ATan2(m[1][0],m[0][0]);
+ rfRAngle = Math::ATan2(m[2][1],m[2][2]);
+ return true;
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRmY = Math::ATan2(-m[0][1],m[0][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = rfRAngle - fRmY;
+ return false;
+ }
+ }
+ else
+ {
+ // WARNING. Not a unique solution.
+ Radian fRpY = Math::ATan2(-m[0][1],m[0][2]);
+ rfRAngle = Radian(0.0); // any angle works
+ rfYAngle = fRpY - rfRAngle;
+ return false;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesXYZ (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ *this = kXMat*(kYMat*kZMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesXZY (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ *this = kXMat*(kZMat*kYMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesYXZ (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ *this = kYMat*(kXMat*kZMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesYZX (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ *this = kYMat*(kZMat*kXMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesZXY (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ *this = kZMat*(kXMat*kYMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::FromEulerAnglesZYX (const Radian& fYAngle, const Radian& fPAngle,
+ const Radian& fRAngle)
+ {
+ Real fCos, fSin;
+
+ fCos = Math::Cos(fYAngle);
+ fSin = Math::Sin(fYAngle);
+ Matrix3 kZMat(fCos,-fSin,0.0,fSin,fCos,0.0,0.0,0.0,1.0);
+
+ fCos = Math::Cos(fPAngle);
+ fSin = Math::Sin(fPAngle);
+ Matrix3 kYMat(fCos,0.0,fSin,0.0,1.0,0.0,-fSin,0.0,fCos);
+
+ fCos = Math::Cos(fRAngle);
+ fSin = Math::Sin(fRAngle);
+ Matrix3 kXMat(1.0,0.0,0.0,0.0,fCos,-fSin,0.0,fSin,fCos);
+
+ *this = kZMat*(kYMat*kXMat);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::Tridiagonal (Real afDiag[3], Real afSubDiag[3])
+ {
+ // Householder reduction T = Q^t M Q
+ // Input:
+ // mat, symmetric 3x3 matrix M
+ // Output:
+ // mat, orthogonal matrix Q
+ // diag, diagonal entries of T
+ // subd, subdiagonal entries of T (T is symmetric)
+
+ Real fA = m[0][0];
+ Real fB = m[0][1];
+ Real fC = m[0][2];
+ Real fD = m[1][1];
+ Real fE = m[1][2];
+ Real fF = m[2][2];
+
+ afDiag[0] = fA;
+ afSubDiag[2] = 0.0;
+ if ( Math::Abs(fC) >= EPSILON )
+ {
+ Real fLength = Math::Sqrt(fB*fB+fC*fC);
+ Real fInvLength = 1.0/fLength;
+ fB *= fInvLength;
+ fC *= fInvLength;
+ Real fQ = 2.0*fB*fE+fC*(fF-fD);
+ afDiag[1] = fD+fC*fQ;
+ afDiag[2] = fF-fC*fQ;
+ afSubDiag[0] = fLength;
+ afSubDiag[1] = fE-fB*fQ;
+ m[0][0] = 1.0;
+ m[0][1] = 0.0;
+ m[0][2] = 0.0;
+ m[1][0] = 0.0;
+ m[1][1] = fB;
+ m[1][2] = fC;
+ m[2][0] = 0.0;
+ m[2][1] = fC;
+ m[2][2] = -fB;
+ }
+ else
+ {
+ afDiag[1] = fD;
+ afDiag[2] = fF;
+ afSubDiag[0] = fB;
+ afSubDiag[1] = fE;
+ m[0][0] = 1.0;
+ m[0][1] = 0.0;
+ m[0][2] = 0.0;
+ m[1][0] = 0.0;
+ m[1][1] = 1.0;
+ m[1][2] = 0.0;
+ m[2][0] = 0.0;
+ m[2][1] = 0.0;
+ m[2][2] = 1.0;
+ }
+ }
+ //-----------------------------------------------------------------------
+ bool Matrix3::QLAlgorithm (Real afDiag[3], Real afSubDiag[3])
+ {
+ // QL iteration with implicit shifting to reduce matrix from tridiagonal
+ // to diagonal
+
+ for (int i0 = 0; i0 < 3; i0++)
+ {
+ const unsigned int iMaxIter = 32;
+ unsigned int iIter;
+ for (iIter = 0; iIter < iMaxIter; iIter++)
+ {
+ int i1;
+ for (i1 = i0; i1 <= 1; i1++)
+ {
+ Real fSum = Math::Abs(afDiag[i1]) +
+ Math::Abs(afDiag[i1+1]);
+ if ( Math::Abs(afSubDiag[i1]) + fSum == fSum )
+ break;
+ }
+ if ( i1 == i0 )
+ break;
+
+ Real fTmp0 = (afDiag[i0+1]-afDiag[i0])/(2.0*afSubDiag[i0]);
+ Real fTmp1 = Math::Sqrt(fTmp0*fTmp0+1.0);
+ if ( fTmp0 < 0.0 )
+ fTmp0 = afDiag[i1]-afDiag[i0]+afSubDiag[i0]/(fTmp0-fTmp1);
+ else
+ fTmp0 = afDiag[i1]-afDiag[i0]+afSubDiag[i0]/(fTmp0+fTmp1);
+ Real fSin = 1.0;
+ Real fCos = 1.0;
+ Real fTmp2 = 0.0;
+ for (int i2 = i1-1; i2 >= i0; i2--)
+ {
+ Real fTmp3 = fSin*afSubDiag[i2];
+ Real fTmp4 = fCos*afSubDiag[i2];
+ if ( Math::Abs(fTmp3) >= Math::Abs(fTmp0) )
+ {
+ fCos = fTmp0/fTmp3;
+ fTmp1 = Math::Sqrt(fCos*fCos+1.0);
+ afSubDiag[i2+1] = fTmp3*fTmp1;
+ fSin = 1.0/fTmp1;
+ fCos *= fSin;
+ }
+ else
+ {
+ fSin = fTmp3/fTmp0;
+ fTmp1 = Math::Sqrt(fSin*fSin+1.0);
+ afSubDiag[i2+1] = fTmp0*fTmp1;
+ fCos = 1.0/fTmp1;
+ fSin *= fCos;
+ }
+ fTmp0 = afDiag[i2+1]-fTmp2;
+ fTmp1 = (afDiag[i2]-fTmp0)*fSin+2.0*fTmp4*fCos;
+ fTmp2 = fSin*fTmp1;
+ afDiag[i2+1] = fTmp0+fTmp2;
+ fTmp0 = fCos*fTmp1-fTmp4;
+
+ for (int iRow = 0; iRow < 3; iRow++)
+ {
+ fTmp3 = m[iRow][i2+1];
+ m[iRow][i2+1] = fSin*m[iRow][i2] +
+ fCos*fTmp3;
+ m[iRow][i2] = fCos*m[iRow][i2] -
+ fSin*fTmp3;
+ }
+ }
+ afDiag[i0] -= fTmp2;
+ afSubDiag[i0] = fTmp0;
+ afSubDiag[i1] = 0.0;
+ }
+
+ if ( iIter == iMaxIter )
+ {
+ // should not get here under normal circumstances
+ return false;
+ }
+ }
+
+ return true;
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::EigenSolveSymmetric (Real afEigenvalue[3],
+ Vector3 akEigenvector[3]) const
+ {
+ Matrix3 kMatrix = *this;
+ Real afSubDiag[3];
+ kMatrix.Tridiagonal(afEigenvalue,afSubDiag);
+ kMatrix.QLAlgorithm(afEigenvalue,afSubDiag);
+
+ for (size_t i = 0; i < 3; i++)
+ {
+ akEigenvector[i][0] = kMatrix[0][i];
+ akEigenvector[i][1] = kMatrix[1][i];
+ akEigenvector[i][2] = kMatrix[2][i];
+ }
+
+ // make eigenvectors form a right--handed system
+ Vector3 kCross = akEigenvector[1].crossProduct(akEigenvector[2]);
+ Real fDet = akEigenvector[0].dotProduct(kCross);
+ if ( fDet < 0.0 )
+ {
+ akEigenvector[2][0] = - akEigenvector[2][0];
+ akEigenvector[2][1] = - akEigenvector[2][1];
+ akEigenvector[2][2] = - akEigenvector[2][2];
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Matrix3::TensorProduct (const Vector3& rkU, const Vector3& rkV,
+ Matrix3& rkProduct)
+ {
+ for (size_t iRow = 0; iRow < 3; iRow++)
+ {
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ rkProduct[iRow][iCol] = rkU[iRow]*rkV[iCol];
+ }
+ }
+ //-----------------------------------------------------------------------
+}
Property changes on: sandbox_light/src/external/ogremath/OgreMatrix3.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMatrix3.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreMatrix3.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMatrix3.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,241 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Matrix3_H__
+#define __Matrix3_H__
+
+#include "OgrePrerequisites.h"
+
+#include "OgreVector3.h"
+#include <ostream>
+
+// NB All code adapted from Wild Magic 0.2 Matrix math (free source code)
+// http://www.geometrictools.com/
+
+// NOTE. The (x,y,z) coordinate system is assumed to be right-handed.
+// Coordinate axis rotation matrices are of the form
+// RX = 1 0 0
+// 0 cos(t) -sin(t)
+// 0 sin(t) cos(t)
+// where t > 0 indicates a counterclockwise rotation in the yz-plane
+// RY = cos(t) 0 sin(t)
+// 0 1 0
+// -sin(t) 0 cos(t)
+// where t > 0 indicates a counterclockwise rotation in the zx-plane
+// RZ = cos(t) -sin(t) 0
+// sin(t) cos(t) 0
+// 0 0 1
+// where t > 0 indicates a counterclockwise rotation in the xy-plane.
+
+namespace Ogre
+{
+ /** A 3x3 matrix which can represent rotations around axes.
+ @note
+ <b>All the code is adapted from the Wild Magic 0.2 Matrix
+ library (http://www.geometrictools.com/).</b>
+ @par
+ The coordinate system is assumed to be <b>right-handed</b>.
+ */
+ class _OgreExport Matrix3
+ {
+ public:
+ /** Default constructor.
+ @note
+ It does <b>NOT</b> initialize the matrix for efficiency.
+ */
+ inline Matrix3 () {};
+ inline explicit Matrix3 (const Real arr[3][3])
+ {
+ memcpy(m,arr,9*sizeof(Real));
+ }
+ inline Matrix3 (const Matrix3& rkMatrix)
+ {
+ memcpy(m,rkMatrix.m,9*sizeof(Real));
+ }
+ Matrix3 (Real fEntry00, Real fEntry01, Real fEntry02,
+ Real fEntry10, Real fEntry11, Real fEntry12,
+ Real fEntry20, Real fEntry21, Real fEntry22)
+ {
+ m[0][0] = fEntry00;
+ m[0][1] = fEntry01;
+ m[0][2] = fEntry02;
+ m[1][0] = fEntry10;
+ m[1][1] = fEntry11;
+ m[1][2] = fEntry12;
+ m[2][0] = fEntry20;
+ m[2][1] = fEntry21;
+ m[2][2] = fEntry22;
+ }
+
+ // member access, allows use of construct mat[r][c]
+ inline Real* operator[] (size_t iRow) const
+ {
+ return (Real*)m[iRow];
+ }
+ /*inline operator Real* ()
+ {
+ return (Real*)m[0];
+ }*/
+ Vector3 GetColumn (size_t iCol) const;
+ void SetColumn(size_t iCol, const Vector3& vec);
+ void FromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
+
+ // assignment and comparison
+ inline Matrix3& operator= (const Matrix3& rkMatrix)
+ {
+ memcpy(m,rkMatrix.m,9*sizeof(Real));
+ return *this;
+ }
+ bool operator== (const Matrix3& rkMatrix) const;
+ inline bool operator!= (const Matrix3& rkMatrix) const
+ {
+ return !operator==(rkMatrix);
+ }
+
+ // arithmetic operations
+ Matrix3 operator+ (const Matrix3& rkMatrix) const;
+ Matrix3 operator- (const Matrix3& rkMatrix) const;
+ Matrix3 operator* (const Matrix3& rkMatrix) const;
+ Matrix3 operator- () const;
+
+ // matrix * vector [3x3 * 3x1 = 3x1]
+ Vector3 operator* (const Vector3& rkVector) const;
+
+ // vector * matrix [1x3 * 3x3 = 1x3]
+ _OgreExport friend Vector3 operator* (const Vector3& rkVector,
+ const Matrix3& rkMatrix);
+
+ // matrix * scalar
+ Matrix3 operator* (Real fScalar) const;
+
+ // scalar * matrix
+ _OgreExport friend Matrix3 operator* (Real fScalar, const Matrix3& rkMatrix);
+
+ // utilities
+ Matrix3 Transpose () const;
+ bool Inverse (Matrix3& rkInverse, Real fTolerance = 1e-06) const;
+ Matrix3 Inverse (Real fTolerance = 1e-06) const;
+ Real Determinant () const;
+
+ // singular value decomposition
+ void SingularValueDecomposition (Matrix3& rkL, Vector3& rkS,
+ Matrix3& rkR) const;
+ void SingularValueComposition (const Matrix3& rkL,
+ const Vector3& rkS, const Matrix3& rkR);
+
+ // Gram-Schmidt orthonormalization (applied to columns of rotation matrix)
+ void Orthonormalize ();
+
+ // orthogonal Q, diagonal D, upper triangular U stored as (u01,u02,u12)
+ void QDUDecomposition (Matrix3& rkQ, Vector3& rkD,
+ Vector3& rkU) const;
+
+ Real SpectralNorm () const;
+
+ // matrix must be orthonormal
+ void ToAxisAngle (Vector3& rkAxis, Radian& rfAngle) const;
+ inline void ToAxisAngle (Vector3& rkAxis, Degree& rfAngle) const {
+ Radian r;
+ ToAxisAngle ( rkAxis, r );
+ rfAngle = r;
+ }
+ void FromAxisAngle (const Vector3& rkAxis, const Radian& fRadians);
+
+ // The matrix must be orthonormal. The decomposition is yaw*pitch*roll
+ // where yaw is rotation about the Up vector, pitch is rotation about the
+ // Right axis, and roll is rotation about the Direction axis.
+ bool ToEulerAnglesXYZ (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ bool ToEulerAnglesXZY (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ bool ToEulerAnglesYXZ (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ bool ToEulerAnglesYZX (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ bool ToEulerAnglesZXY (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ bool ToEulerAnglesZYX (Radian& rfYAngle, Radian& rfPAngle,
+ Radian& rfRAngle) const;
+ void FromEulerAnglesXYZ (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ void FromEulerAnglesXZY (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ void FromEulerAnglesYXZ (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ void FromEulerAnglesYZX (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ void FromEulerAnglesZXY (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ void FromEulerAnglesZYX (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
+ // eigensolver, matrix must be symmetric
+ void EigenSolveSymmetric (Real afEigenvalue[3],
+ Vector3 akEigenvector[3]) const;
+
+ static void TensorProduct (const Vector3& rkU, const Vector3& rkV,
+ Matrix3& rkProduct);
+
+ /** Determines if this matrix involves a scaling. */
+ inline bool hasScale() const
+ {
+ // check magnitude of column vectors (==local axes)
+ Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+ t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+ t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+
+ return false;
+ }
+
+
+ static const Real EPSILON;
+ static const Matrix3 ZERO;
+ static const Matrix3 IDENTITY;
+
+ protected:
+ // support for eigensolver
+ void Tridiagonal (Real afDiag[3], Real afSubDiag[3]);
+ bool QLAlgorithm (Real afDiag[3], Real afSubDiag[3]);
+
+ // support for singular value decomposition
+ static const Real ms_fSvdEpsilon;
+ static const unsigned int ms_iSvdMaxIterations;
+ static void Bidiagonalize (Matrix3& kA, Matrix3& kL,
+ Matrix3& kR);
+ static void GolubKahanStep (Matrix3& kA, Matrix3& kL,
+ Matrix3& kR);
+
+ // support for spectral norm
+ static Real MaxCubicRoot (Real afCoeff[3]);
+
+ Real m[3][3];
+
+ // for faster access
+ friend class Matrix4;
+ };
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreMatrix3.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMatrix4.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreMatrix4.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMatrix4.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,252 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+(Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreMatrix4.h"
+
+#include "OgreVector3.h"
+#include "OgreMatrix3.h"
+
+namespace Ogre
+{
+
+ const Matrix4 Matrix4::ZERO(
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0 );
+
+ const Matrix4 Matrix4::IDENTITY(
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1 );
+
+ const Matrix4 Matrix4::CLIPSPACE2DTOIMAGESPACE(
+ 0.5, 0, 0, 0.5,
+ 0, -0.5, 0, 0.5,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+
+ //-----------------------------------------------------------------------
+ inline static Real
+ MINOR(const Matrix4& m, const size_t r0, const size_t r1, const size_t r2,
+ const size_t c0, const size_t c1, const size_t c2)
+ {
+ return m[r0][c0] * (m[r1][c1] * m[r2][c2] - m[r2][c1] * m[r1][c2]) -
+ m[r0][c1] * (m[r1][c0] * m[r2][c2] - m[r2][c0] * m[r1][c2]) +
+ m[r0][c2] * (m[r1][c0] * m[r2][c1] - m[r2][c0] * m[r1][c1]);
+ }
+ //-----------------------------------------------------------------------
+ Matrix4 Matrix4::adjoint() const
+ {
+ return Matrix4( MINOR(*this, 1, 2, 3, 1, 2, 3),
+ -MINOR(*this, 0, 2, 3, 1, 2, 3),
+ MINOR(*this, 0, 1, 3, 1, 2, 3),
+ -MINOR(*this, 0, 1, 2, 1, 2, 3),
+
+ -MINOR(*this, 1, 2, 3, 0, 2, 3),
+ MINOR(*this, 0, 2, 3, 0, 2, 3),
+ -MINOR(*this, 0, 1, 3, 0, 2, 3),
+ MINOR(*this, 0, 1, 2, 0, 2, 3),
+
+ MINOR(*this, 1, 2, 3, 0, 1, 3),
+ -MINOR(*this, 0, 2, 3, 0, 1, 3),
+ MINOR(*this, 0, 1, 3, 0, 1, 3),
+ -MINOR(*this, 0, 1, 2, 0, 1, 3),
+
+ -MINOR(*this, 1, 2, 3, 0, 1, 2),
+ MINOR(*this, 0, 2, 3, 0, 1, 2),
+ -MINOR(*this, 0, 1, 3, 0, 1, 2),
+ MINOR(*this, 0, 1, 2, 0, 1, 2));
+ }
+ //-----------------------------------------------------------------------
+ Real Matrix4::determinant() const
+ {
+ return m[0][0] * MINOR(*this, 1, 2, 3, 1, 2, 3) -
+ m[0][1] * MINOR(*this, 1, 2, 3, 0, 2, 3) +
+ m[0][2] * MINOR(*this, 1, 2, 3, 0, 1, 3) -
+ m[0][3] * MINOR(*this, 1, 2, 3, 0, 1, 2);
+ }
+ //-----------------------------------------------------------------------
+ Matrix4 Matrix4::inverse() const
+ {
+ Real m00 = m[0][0], m01 = m[0][1], m02 = m[0][2], m03 = m[0][3];
+ Real m10 = m[1][0], m11 = m[1][1], m12 = m[1][2], m13 = m[1][3];
+ Real m20 = m[2][0], m21 = m[2][1], m22 = m[2][2], m23 = m[2][3];
+ Real m30 = m[3][0], m31 = m[3][1], m32 = m[3][2], m33 = m[3][3];
+
+ Real v0 = m20 * m31 - m21 * m30;
+ Real v1 = m20 * m32 - m22 * m30;
+ Real v2 = m20 * m33 - m23 * m30;
+ Real v3 = m21 * m32 - m22 * m31;
+ Real v4 = m21 * m33 - m23 * m31;
+ Real v5 = m22 * m33 - m23 * m32;
+
+ Real t00 = + (v5 * m11 - v4 * m12 + v3 * m13);
+ Real t10 = - (v5 * m10 - v2 * m12 + v1 * m13);
+ Real t20 = + (v4 * m10 - v2 * m11 + v0 * m13);
+ Real t30 = - (v3 * m10 - v1 * m11 + v0 * m12);
+
+ Real invDet = 1 / (t00 * m00 + t10 * m01 + t20 * m02 + t30 * m03);
+
+ Real d00 = t00 * invDet;
+ Real d10 = t10 * invDet;
+ Real d20 = t20 * invDet;
+ Real d30 = t30 * invDet;
+
+ Real d01 = - (v5 * m01 - v4 * m02 + v3 * m03) * invDet;
+ Real d11 = + (v5 * m00 - v2 * m02 + v1 * m03) * invDet;
+ Real d21 = - (v4 * m00 - v2 * m01 + v0 * m03) * invDet;
+ Real d31 = + (v3 * m00 - v1 * m01 + v0 * m02) * invDet;
+
+ v0 = m10 * m31 - m11 * m30;
+ v1 = m10 * m32 - m12 * m30;
+ v2 = m10 * m33 - m13 * m30;
+ v3 = m11 * m32 - m12 * m31;
+ v4 = m11 * m33 - m13 * m31;
+ v5 = m12 * m33 - m13 * m32;
+
+ Real d02 = + (v5 * m01 - v4 * m02 + v3 * m03) * invDet;
+ Real d12 = - (v5 * m00 - v2 * m02 + v1 * m03) * invDet;
+ Real d22 = + (v4 * m00 - v2 * m01 + v0 * m03) * invDet;
+ Real d32 = - (v3 * m00 - v1 * m01 + v0 * m02) * invDet;
+
+ v0 = m21 * m10 - m20 * m11;
+ v1 = m22 * m10 - m20 * m12;
+ v2 = m23 * m10 - m20 * m13;
+ v3 = m22 * m11 - m21 * m12;
+ v4 = m23 * m11 - m21 * m13;
+ v5 = m23 * m12 - m22 * m13;
+
+ Real d03 = - (v5 * m01 - v4 * m02 + v3 * m03) * invDet;
+ Real d13 = + (v5 * m00 - v2 * m02 + v1 * m03) * invDet;
+ Real d23 = - (v4 * m00 - v2 * m01 + v0 * m03) * invDet;
+ Real d33 = + (v3 * m00 - v1 * m01 + v0 * m02) * invDet;
+
+ return Matrix4(
+ d00, d01, d02, d03,
+ d10, d11, d12, d13,
+ d20, d21, d22, d23,
+ d30, d31, d32, d33);
+ }
+ //-----------------------------------------------------------------------
+ Matrix4 Matrix4::inverseAffine(void) const
+ {
+ assert(isAffine());
+
+ Real m10 = m[1][0], m11 = m[1][1], m12 = m[1][2];
+ Real m20 = m[2][0], m21 = m[2][1], m22 = m[2][2];
+
+ Real t00 = m22 * m11 - m21 * m12;
+ Real t10 = m20 * m12 - m22 * m10;
+ Real t20 = m21 * m10 - m20 * m11;
+
+ Real m00 = m[0][0], m01 = m[0][1], m02 = m[0][2];
+
+ Real invDet = 1 / (m00 * t00 + m01 * t10 + m02 * t20);
+
+ t00 *= invDet; t10 *= invDet; t20 *= invDet;
+
+ m00 *= invDet; m01 *= invDet; m02 *= invDet;
+
+ Real r00 = t00;
+ Real r01 = m02 * m21 - m01 * m22;
+ Real r02 = m01 * m12 - m02 * m11;
+
+ Real r10 = t10;
+ Real r11 = m00 * m22 - m02 * m20;
+ Real r12 = m02 * m10 - m00 * m12;
+
+ Real r20 = t20;
+ Real r21 = m01 * m20 - m00 * m21;
+ Real r22 = m00 * m11 - m01 * m10;
+
+ Real m03 = m[0][3], m13 = m[1][3], m23 = m[2][3];
+
+ Real r03 = - (r00 * m03 + r01 * m13 + r02 * m23);
+ Real r13 = - (r10 * m03 + r11 * m13 + r12 * m23);
+ Real r23 = - (r20 * m03 + r21 * m13 + r22 * m23);
+
+ return Matrix4(
+ r00, r01, r02, r03,
+ r10, r11, r12, r13,
+ r20, r21, r22, r23,
+ 0, 0, 0, 1);
+ }
+ //-----------------------------------------------------------------------
+ void Matrix4::makeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation)
+ {
+ // Ordering:
+ // 1. Scale
+ // 2. Rotate
+ // 3. Translate
+
+ Matrix3 rot3x3, scale3x3;
+ orientation.ToRotationMatrix(rot3x3);
+ scale3x3 = Matrix3::ZERO;
+ scale3x3[0][0] = scale.x;
+ scale3x3[1][1] = scale.y;
+ scale3x3[2][2] = scale.z;
+
+ // Set up final matrix with scale, rotation and translation
+ *this = rot3x3 * scale3x3;
+ this->setTrans(position);
+
+ // No projection term
+ m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
+ }
+ //-----------------------------------------------------------------------
+ void Matrix4::makeInverseTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation)
+ {
+ // Invert the parameters
+ Vector3 invTranslate = -position;
+ Vector3 invScale(1 / scale.x, 1 / scale.y, 1 / scale.z);
+ Quaternion invRot = orientation.Inverse();
+
+ // Because we're inverting, order is translation, rotation, scale
+ // So make translation relative to scale & rotation
+ invTranslate *= invScale; // scale
+ invTranslate = invRot * invTranslate; // rotate
+
+ // Next, make a 3x3 rotation matrix and apply inverse scale
+ Matrix3 rot3x3, scale3x3;
+ invRot.ToRotationMatrix(rot3x3);
+ scale3x3 = Matrix3::ZERO;
+ scale3x3[0][0] = invScale.x;
+ scale3x3[1][1] = invScale.y;
+ scale3x3[2][2] = invScale.z;
+
+ // Set up final matrix with scale, rotation and translation
+ *this = scale3x3 * rot3x3;
+ this->setTrans(invTranslate);
+
+ // No projection term
+ m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
+ }
+
+}
Property changes on: sandbox_light/src/external/ogremath/OgreMatrix4.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreMatrix4.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreMatrix4.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreMatrix4.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,614 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Matrix4__
+#define __Matrix4__
+
+// Precompiler options
+#include "OgrePrerequisites.h"
+
+#include "OgreVector3.h"
+#include "OgreMatrix3.h"
+#include "OgreVector4.h"
+#include <ostream>
+
+namespace Ogre
+{
+ /** Class encapsulating a standard 4x4 homogeneous matrix.
+ @remarks
+ OGRE uses column vectors when applying matrix multiplications,
+ This means a vector is represented as a single column, 4-row
+ matrix. This has the effect that the transformations implemented
+ by the matrices happens right-to-left e.g. if vector V is to be
+ transformed by M1 then M2 then M3, the calculation would be
+ M3 * M2 * M1 * V. The order that matrices are concatenated is
+ vital since matrix multiplication is not cummatative, i.e. you
+ can get a different result if you concatenate in the wrong order.
+ @par
+ The use of column vectors and right-to-left ordering is the
+ standard in most mathematical texts, and id the same as used in
+ OpenGL. It is, however, the opposite of Direct3D, which has
+ inexplicably chosen to differ from the accepted standard and uses
+ row vectors and left-to-right matrix multiplication.
+ @par
+ OGRE deals with the differences between D3D and OpenGL etc.
+ internally when operating through different render systems. OGRE
+ users only need to conform to standard maths conventions, i.e.
+ right-to-left matrix multiplication, (OGRE transposes matrices it
+ passes to D3D to compensate).
+ @par
+ The generic form M * V which shows the layout of the matrix
+ entries is shown below:
+ <pre>
+ [ m[0][0] m[0][1] m[0][2] m[0][3] ] {x}
+ | m[1][0] m[1][1] m[1][2] m[1][3] | * {y}
+ | m[2][0] m[2][1] m[2][2] m[2][3] | {z}
+ [ m[3][0] m[3][1] m[3][2] m[3][3] ] {1}
+ </pre>
+ */
+ class _OgreExport Matrix4
+ {
+ protected:
+ /// The matrix entries, indexed by [row][col].
+ union {
+ Real m[4][4];
+ Real _m[16];
+ };
+ public:
+ /** Default constructor.
+ @note
+ It does <b>NOT</b> initialize the matrix for efficiency.
+ */
+ inline Matrix4()
+ {
+ }
+
+ inline Matrix4(
+ Real m00, Real m01, Real m02, Real m03,
+ Real m10, Real m11, Real m12, Real m13,
+ Real m20, Real m21, Real m22, Real m23,
+ Real m30, Real m31, Real m32, Real m33 )
+ {
+ m[0][0] = m00;
+ m[0][1] = m01;
+ m[0][2] = m02;
+ m[0][3] = m03;
+ m[1][0] = m10;
+ m[1][1] = m11;
+ m[1][2] = m12;
+ m[1][3] = m13;
+ m[2][0] = m20;
+ m[2][1] = m21;
+ m[2][2] = m22;
+ m[2][3] = m23;
+ m[3][0] = m30;
+ m[3][1] = m31;
+ m[3][2] = m32;
+ m[3][3] = m33;
+ }
+
+ /** Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3 matrix.
+ */
+
+ inline Matrix4(const Matrix3& m3x3)
+ {
+ operator=(IDENTITY);
+ operator=(m3x3);
+ }
+
+ /** Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling Quaternion.
+ */
+
+ inline Matrix4(const Quaternion& rot)
+ {
+ Matrix3 m3x3;
+ rot.ToRotationMatrix(m3x3);
+ operator=(IDENTITY);
+ operator=(m3x3);
+ }
+
+
+ inline Real* operator [] ( size_t iRow )
+ {
+ assert( iRow < 4 );
+ return m[iRow];
+ }
+
+ inline const Real *const operator [] ( size_t iRow ) const
+ {
+ assert( iRow < 4 );
+ return m[iRow];
+ }
+
+ inline Matrix4 concatenate(const Matrix4 &m2) const
+ {
+ Matrix4 r;
+ r.m[0][0] = m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0] + m[0][3] * m2.m[3][0];
+ r.m[0][1] = m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1] + m[0][3] * m2.m[3][1];
+ r.m[0][2] = m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2] + m[0][3] * m2.m[3][2];
+ r.m[0][3] = m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3] * m2.m[3][3];
+
+ r.m[1][0] = m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0] + m[1][3] * m2.m[3][0];
+ r.m[1][1] = m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1] + m[1][3] * m2.m[3][1];
+ r.m[1][2] = m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2] + m[1][3] * m2.m[3][2];
+ r.m[1][3] = m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3] * m2.m[3][3];
+
+ r.m[2][0] = m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0] + m[2][3] * m2.m[3][0];
+ r.m[2][1] = m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1] + m[2][3] * m2.m[3][1];
+ r.m[2][2] = m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2] + m[2][3] * m2.m[3][2];
+ r.m[2][3] = m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3] * m2.m[3][3];
+
+ r.m[3][0] = m[3][0] * m2.m[0][0] + m[3][1] * m2.m[1][0] + m[3][2] * m2.m[2][0] + m[3][3] * m2.m[3][0];
+ r.m[3][1] = m[3][0] * m2.m[0][1] + m[3][1] * m2.m[1][1] + m[3][2] * m2.m[2][1] + m[3][3] * m2.m[3][1];
+ r.m[3][2] = m[3][0] * m2.m[0][2] + m[3][1] * m2.m[1][2] + m[3][2] * m2.m[2][2] + m[3][3] * m2.m[3][2];
+ r.m[3][3] = m[3][0] * m2.m[0][3] + m[3][1] * m2.m[1][3] + m[3][2] * m2.m[2][3] + m[3][3] * m2.m[3][3];
+
+ return r;
+ }
+
+ /** Matrix concatenation using '*'.
+ */
+ inline Matrix4 operator * ( const Matrix4 &m2 ) const
+ {
+ return concatenate( m2 );
+ }
+
+ /** Vector transformation using '*'.
+ @remarks
+ Transforms the given 3-D vector by the matrix, projecting the
+ result back into <i>w</i> = 1.
+ @note
+ This means that the initial <i>w</i> is considered to be 1.0,
+ and then all the tree elements of the resulting 3-D vector are
+ divided by the resulting <i>w</i>.
+ */
+ inline Vector3 operator * ( const Vector3 &v ) const
+ {
+ Vector3 r;
+
+ Real fInvW = 1.0 / ( m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] );
+
+ r.x = ( m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] ) * fInvW;
+ r.y = ( m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] ) * fInvW;
+ r.z = ( m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] ) * fInvW;
+
+ return r;
+ }
+ inline Vector4 operator * (const Vector4& v) const
+ {
+ return Vector4(
+ m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
+ m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
+ m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
+ m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w
+ );
+ }
+
+
+ /** Matrix addition.
+ */
+ inline Matrix4 operator + ( const Matrix4 &m2 ) const
+ {
+ Matrix4 r;
+
+ r.m[0][0] = m[0][0] + m2.m[0][0];
+ r.m[0][1] = m[0][1] + m2.m[0][1];
+ r.m[0][2] = m[0][2] + m2.m[0][2];
+ r.m[0][3] = m[0][3] + m2.m[0][3];
+
+ r.m[1][0] = m[1][0] + m2.m[1][0];
+ r.m[1][1] = m[1][1] + m2.m[1][1];
+ r.m[1][2] = m[1][2] + m2.m[1][2];
+ r.m[1][3] = m[1][3] + m2.m[1][3];
+
+ r.m[2][0] = m[2][0] + m2.m[2][0];
+ r.m[2][1] = m[2][1] + m2.m[2][1];
+ r.m[2][2] = m[2][2] + m2.m[2][2];
+ r.m[2][3] = m[2][3] + m2.m[2][3];
+
+ r.m[3][0] = m[3][0] + m2.m[3][0];
+ r.m[3][1] = m[3][1] + m2.m[3][1];
+ r.m[3][2] = m[3][2] + m2.m[3][2];
+ r.m[3][3] = m[3][3] + m2.m[3][3];
+
+ return r;
+ }
+
+ /** Matrix subtraction.
+ */
+ inline Matrix4 operator - ( const Matrix4 &m2 ) const
+ {
+ Matrix4 r;
+ r.m[0][0] = m[0][0] - m2.m[0][0];
+ r.m[0][1] = m[0][1] - m2.m[0][1];
+ r.m[0][2] = m[0][2] - m2.m[0][2];
+ r.m[0][3] = m[0][3] - m2.m[0][3];
+
+ r.m[1][0] = m[1][0] - m2.m[1][0];
+ r.m[1][1] = m[1][1] - m2.m[1][1];
+ r.m[1][2] = m[1][2] - m2.m[1][2];
+ r.m[1][3] = m[1][3] - m2.m[1][3];
+
+ r.m[2][0] = m[2][0] - m2.m[2][0];
+ r.m[2][1] = m[2][1] - m2.m[2][1];
+ r.m[2][2] = m[2][2] - m2.m[2][2];
+ r.m[2][3] = m[2][3] - m2.m[2][3];
+
+ r.m[3][0] = m[3][0] - m2.m[3][0];
+ r.m[3][1] = m[3][1] - m2.m[3][1];
+ r.m[3][2] = m[3][2] - m2.m[3][2];
+ r.m[3][3] = m[3][3] - m2.m[3][3];
+
+ return r;
+ }
+
+ /** Tests 2 matrices for equality.
+ */
+ inline bool operator == ( const Matrix4& m2 ) const
+ {
+ if(
+ m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
+ m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
+ m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
+ m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
+ return false;
+ return true;
+ }
+
+ /** Tests 2 matrices for inequality.
+ */
+ inline bool operator != ( const Matrix4& m2 ) const
+ {
+ if(
+ m[0][0] != m2.m[0][0] || m[0][1] != m2.m[0][1] || m[0][2] != m2.m[0][2] || m[0][3] != m2.m[0][3] ||
+ m[1][0] != m2.m[1][0] || m[1][1] != m2.m[1][1] || m[1][2] != m2.m[1][2] || m[1][3] != m2.m[1][3] ||
+ m[2][0] != m2.m[2][0] || m[2][1] != m2.m[2][1] || m[2][2] != m2.m[2][2] || m[2][3] != m2.m[2][3] ||
+ m[3][0] != m2.m[3][0] || m[3][1] != m2.m[3][1] || m[3][2] != m2.m[3][2] || m[3][3] != m2.m[3][3] )
+ return true;
+ return false;
+ }
+
+ /** Assignment from 3x3 matrix.
+ */
+ inline void operator = ( const Matrix3& mat3 )
+ {
+ m[0][0] = mat3.m[0][0]; m[0][1] = mat3.m[0][1]; m[0][2] = mat3.m[0][2];
+ m[1][0] = mat3.m[1][0]; m[1][1] = mat3.m[1][1]; m[1][2] = mat3.m[1][2];
+ m[2][0] = mat3.m[2][0]; m[2][1] = mat3.m[2][1]; m[2][2] = mat3.m[2][2];
+ }
+
+ inline Matrix4 transpose(void) const
+ {
+ return Matrix4(m[0][0], m[1][0], m[2][0], m[3][0],
+ m[0][1], m[1][1], m[2][1], m[3][1],
+ m[0][2], m[1][2], m[2][2], m[3][2],
+ m[0][3], m[1][3], m[2][3], m[3][3]);
+ }
+
+ /*
+ -----------------------------------------------------------------------
+ Translation Transformation
+ -----------------------------------------------------------------------
+ */
+ /** Sets the translation transformation part of the matrix.
+ */
+ inline void setTrans( const Vector3& v )
+ {
+ m[0][3] = v.x;
+ m[1][3] = v.y;
+ m[2][3] = v.z;
+ }
+
+ /** Extracts the translation transformation part of the matrix.
+ */
+ inline Vector3 getTrans() const
+ {
+ return Vector3(m[0][3], m[1][3], m[2][3]);
+ }
+
+
+ /** Builds a translation matrix
+ */
+ inline void makeTrans( const Vector3& v )
+ {
+ m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = v.x;
+ m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = v.y;
+ m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = v.z;
+ m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
+ }
+
+ inline void makeTrans( Real tx, Real ty, Real tz )
+ {
+ m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; m[0][3] = tx;
+ m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; m[1][3] = ty;
+ m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; m[2][3] = tz;
+ m[3][0] = 0.0; m[3][1] = 0.0; m[3][2] = 0.0; m[3][3] = 1.0;
+ }
+
+ /** Gets a translation matrix.
+ */
+ inline static Matrix4 getTrans( const Vector3& v )
+ {
+ Matrix4 r;
+
+ r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = v.x;
+ r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = v.y;
+ r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = v.z;
+ r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
+
+ return r;
+ }
+
+ /** Gets a translation matrix - variation for not using a vector.
+ */
+ inline static Matrix4 getTrans( Real t_x, Real t_y, Real t_z )
+ {
+ Matrix4 r;
+
+ r.m[0][0] = 1.0; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = t_x;
+ r.m[1][0] = 0.0; r.m[1][1] = 1.0; r.m[1][2] = 0.0; r.m[1][3] = t_y;
+ r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = 1.0; r.m[2][3] = t_z;
+ r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
+
+ return r;
+ }
+
+ /*
+ -----------------------------------------------------------------------
+ Scale Transformation
+ -----------------------------------------------------------------------
+ */
+ /** Sets the scale part of the matrix.
+ */
+ inline void setScale( const Vector3& v )
+ {
+ m[0][0] = v.x;
+ m[1][1] = v.y;
+ m[2][2] = v.z;
+ }
+
+ /** Gets a scale matrix.
+ */
+ inline static Matrix4 getScale( const Vector3& v )
+ {
+ Matrix4 r;
+ r.m[0][0] = v.x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
+ r.m[1][0] = 0.0; r.m[1][1] = v.y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
+ r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = v.z; r.m[2][3] = 0.0;
+ r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
+
+ return r;
+ }
+
+ /** Gets a scale matrix - variation for not using a vector.
+ */
+ inline static Matrix4 getScale( Real s_x, Real s_y, Real s_z )
+ {
+ Matrix4 r;
+ r.m[0][0] = s_x; r.m[0][1] = 0.0; r.m[0][2] = 0.0; r.m[0][3] = 0.0;
+ r.m[1][0] = 0.0; r.m[1][1] = s_y; r.m[1][2] = 0.0; r.m[1][3] = 0.0;
+ r.m[2][0] = 0.0; r.m[2][1] = 0.0; r.m[2][2] = s_z; r.m[2][3] = 0.0;
+ r.m[3][0] = 0.0; r.m[3][1] = 0.0; r.m[3][2] = 0.0; r.m[3][3] = 1.0;
+
+ return r;
+ }
+
+ /** Extracts the rotation / scaling part of the Matrix as a 3x3 matrix.
+ @param m3x3 Destination Matrix3
+ */
+ inline void extract3x3Matrix(Matrix3& m3x3) const
+ {
+ m3x3.m[0][0] = m[0][0];
+ m3x3.m[0][1] = m[0][1];
+ m3x3.m[0][2] = m[0][2];
+ m3x3.m[1][0] = m[1][0];
+ m3x3.m[1][1] = m[1][1];
+ m3x3.m[1][2] = m[1][2];
+ m3x3.m[2][0] = m[2][0];
+ m3x3.m[2][1] = m[2][1];
+ m3x3.m[2][2] = m[2][2];
+
+ }
+
+ /** Determines if this matrix involves a scaling. */
+ inline bool hasScale() const
+ {
+ // check magnitude of column vectors (==local axes)
+ Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+ t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+ t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
+ if (!Math::RealEqual(t, 1.0, 1e-04))
+ return true;
+
+ return false;
+ }
+
+ /** Determines if this matrix involves a negative scaling. */
+ inline bool hasNegativeScale() const
+ {
+ return determinant() < 0;
+ }
+
+ /** Extracts the rotation / scaling part as a quaternion from the Matrix.
+ */
+ inline Quaternion extractQuaternion() const
+ {
+ Matrix3 m3x3;
+ extract3x3Matrix(m3x3);
+ return Quaternion(m3x3);
+ }
+
+ static const Matrix4 ZERO;
+ static const Matrix4 IDENTITY;
+ /** Useful little matrix which takes 2D clipspace {-1, 1} to {0,1}
+ and inverts the Y. */
+ static const Matrix4 CLIPSPACE2DTOIMAGESPACE;
+
+ inline Matrix4 operator*(Real scalar) const
+ {
+ return Matrix4(
+ scalar*m[0][0], scalar*m[0][1], scalar*m[0][2], scalar*m[0][3],
+ scalar*m[1][0], scalar*m[1][1], scalar*m[1][2], scalar*m[1][3],
+ scalar*m[2][0], scalar*m[2][1], scalar*m[2][2], scalar*m[2][3],
+ scalar*m[3][0], scalar*m[3][1], scalar*m[3][2], scalar*m[3][3]);
+ }
+
+ /** Function for writing to a stream.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const Matrix4& m )
+ {
+ o << "Matrix4(";
+ for (size_t i = 0; i < 4; ++i)
+ {
+ o << " row" << (unsigned)i << "{";
+ for(size_t j = 0; j < 4; ++j)
+ {
+ o << m[i][j] << " ";
+ }
+ o << "}";
+ }
+ o << ")";
+ return o;
+ }
+
+ Matrix4 adjoint() const;
+ Real determinant() const;
+ Matrix4 inverse() const;
+
+ /** Building a Matrix4 from orientation / scale / position.
+ @remarks
+ Transform is performed in the order scale, rotate, translation, i.e. translation is independent
+ of orientation axes, scale does not affect size of translation, rotation and scaling are always
+ centered on the origin.
+ */
+ void makeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
+
+ /** Building an inverse Matrix4 from orientation / scale / position.
+ @remarks
+ As makeTransform except it build the inverse given the same data as makeTransform, so
+ performing -translation, -rotate, 1/scale in that order.
+ */
+ void makeInverseTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation);
+
+ /** Check whether or not the matrix is affine matrix.
+ @remarks
+ An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1),
+ e.g. no projective coefficients.
+ */
+ inline bool isAffine(void) const
+ {
+ return m[3][0] == 0 && m[3][1] == 0 && m[3][2] == 0 && m[3][3] == 1;
+ }
+
+ /** Returns the inverse of the affine matrix.
+ @note
+ The matrix must be an affine matrix. @see Matrix4::isAffine.
+ */
+ Matrix4 inverseAffine(void) const;
+
+ /** Concatenate two affine matrix.
+ @note
+ The matrices must be affine matrix. @see Matrix4::isAffine.
+ */
+ inline Matrix4 concatenateAffine(const Matrix4 &m2) const
+ {
+ assert(isAffine() && m2.isAffine());
+
+ return Matrix4(
+ m[0][0] * m2.m[0][0] + m[0][1] * m2.m[1][0] + m[0][2] * m2.m[2][0],
+ m[0][0] * m2.m[0][1] + m[0][1] * m2.m[1][1] + m[0][2] * m2.m[2][1],
+ m[0][0] * m2.m[0][2] + m[0][1] * m2.m[1][2] + m[0][2] * m2.m[2][2],
+ m[0][0] * m2.m[0][3] + m[0][1] * m2.m[1][3] + m[0][2] * m2.m[2][3] + m[0][3],
+
+ m[1][0] * m2.m[0][0] + m[1][1] * m2.m[1][0] + m[1][2] * m2.m[2][0],
+ m[1][0] * m2.m[0][1] + m[1][1] * m2.m[1][1] + m[1][2] * m2.m[2][1],
+ m[1][0] * m2.m[0][2] + m[1][1] * m2.m[1][2] + m[1][2] * m2.m[2][2],
+ m[1][0] * m2.m[0][3] + m[1][1] * m2.m[1][3] + m[1][2] * m2.m[2][3] + m[1][3],
+
+ m[2][0] * m2.m[0][0] + m[2][1] * m2.m[1][0] + m[2][2] * m2.m[2][0],
+ m[2][0] * m2.m[0][1] + m[2][1] * m2.m[1][1] + m[2][2] * m2.m[2][1],
+ m[2][0] * m2.m[0][2] + m[2][1] * m2.m[1][2] + m[2][2] * m2.m[2][2],
+ m[2][0] * m2.m[0][3] + m[2][1] * m2.m[1][3] + m[2][2] * m2.m[2][3] + m[2][3],
+
+ 0, 0, 0, 1);
+ }
+
+ /** 3-D Vector transformation specially for affine matrix.
+ @remarks
+ Transforms the given 3-D vector by the matrix, projecting the
+ result back into <i>w</i> = 1.
+ @note
+ The matrix must be an affine matrix. @see Matrix4::isAffine.
+ */
+ inline Vector3 transformAffine(const Vector3& v) const
+ {
+ assert(isAffine());
+
+ return Vector3(
+ m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3],
+ m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3],
+ m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3]);
+ }
+
+ /** 4-D Vector transformation specially for affine matrix.
+ @note
+ The matrix must be an affine matrix. @see Matrix4::isAffine.
+ */
+ inline Vector4 transformAffine(const Vector4& v) const
+ {
+ assert(isAffine());
+
+ return Vector4(
+ m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w,
+ m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w,
+ m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w,
+ v.w);
+ }
+ };
+
+ /* Removed from Vector4 and made a non-member here because otherwise
+ OgreMatrix4.h and OgreVector4.h have to try to include and inline each
+ other, which frankly doesn't work ;)
+ */
+ inline Vector4 operator * (const Vector4& v, const Matrix4& mat)
+ {
+ return Vector4(
+ v.x*mat[0][0] + v.y*mat[1][0] + v.z*mat[2][0] + v.w*mat[3][0],
+ v.x*mat[0][1] + v.y*mat[1][1] + v.z*mat[2][1] + v.w*mat[3][1],
+ v.x*mat[0][2] + v.y*mat[1][2] + v.z*mat[2][2] + v.w*mat[3][2],
+ v.x*mat[0][3] + v.y*mat[1][3] + v.z*mat[2][3] + v.w*mat[3][3]
+ );
+ }
+
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreMatrix4.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgrePlatform.h
===================================================================
--- sandbox_light/src/external/ogremath/OgrePlatform.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgrePlatform.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,226 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Platform_H_
+#define __Platform_H_
+
+#include "OgreConfig.h"
+
+namespace Ogre {
+/* Initial platform/compiler-related stuff to set.
+*/
+#define OGRE_PLATFORM_WIN32 1
+#define OGRE_PLATFORM_LINUX 2
+#define OGRE_PLATFORM_APPLE 3
+
+#define OGRE_COMPILER_MSVC 1
+#define OGRE_COMPILER_GNUC 2
+#define OGRE_COMPILER_BORL 3
+
+#define OGRE_ENDIAN_LITTLE 1
+#define OGRE_ENDIAN_BIG 2
+
+#define OGRE_ARCHITECTURE_32 1
+#define OGRE_ARCHITECTURE_64 2
+
+/* Finds the compiler type and version.
+*/
+#if defined( _MSC_VER )
+# define OGRE_COMPILER OGRE_COMPILER_MSVC
+# define OGRE_COMP_VER _MSC_VER
+
+#elif defined( __GNUC__ )
+# define OGRE_COMPILER OGRE_COMPILER_GNUC
+# define OGRE_COMP_VER (((__GNUC__)*100) + \
+ (__GNUC_MINOR__*10) + \
+ __GNUC_PATCHLEVEL__)
+
+#elif defined( __BORLANDC__ )
+# define OGRE_COMPILER OGRE_COMPILER_BORL
+# define OGRE_COMP_VER __BCPLUSPLUS__
+# define __FUNCTION__ __FUNC__
+#else
+# pragma error "No known compiler. Abort! Abort!"
+
+#endif
+
+/* See if we can use __forceinline or if we need to use __inline instead */
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC
+# if OGRE_COMP_VER >= 1200
+# define FORCEINLINE __forceinline
+# endif
+#elif defined(__MINGW32__)
+# if !defined(FORCEINLINE)
+# define FORCEINLINE __inline
+# endif
+#else
+# define FORCEINLINE __inline
+#endif
+
+/* Finds the current platform */
+
+#if defined( __WIN32__ ) || defined( _WIN32 )
+# define OGRE_PLATFORM OGRE_PLATFORM_WIN32
+
+#elif defined( __APPLE_CC__)
+# define OGRE_PLATFORM OGRE_PLATFORM_APPLE
+
+#else
+# define OGRE_PLATFORM OGRE_PLATFORM_LINUX
+#endif
+
+ /* Find the arch type */
+#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__)
+# define OGRE_ARCH_TYPE OGRE_ARCHITECTURE_64
+#else
+# define OGRE_ARCH_TYPE OGRE_ARCHITECTURE_32
+#endif
+
+// For generating compiler warnings - should work on any compiler
+// As a side note, if you start your message with 'Warning: ', the MSVC
+// IDE actually does catch a warning :)
+#define OGRE_QUOTE_INPLACE(x) # x
+#define OGRE_QUOTE(x) OGRE_QUOTE_INPLACE(x)
+#define OGRE_WARN( x ) message( __FILE__ "(" QUOTE( __LINE__ ) ") : " x "\n" )
+
+//----------------------------------------------------------------------------
+// Windows Settings
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+
+// If we're not including this from a client build, specify that the stuff
+// should get exported. Otherwise, import it.
+# if defined( OGRE_STATIC_LIB )
+ // Linux compilers don't have symbol import/export directives.
+# define _OgreExport
+# define _OgrePrivate
+# else
+# if defined( OGRE_NONCLIENT_BUILD )
+# define _OgreExport __declspec( dllexport )
+# else
+# if defined( __MINGW32__ )
+# define _OgreExport
+# else
+# define _OgreExport __declspec( dllimport )
+# endif
+# endif
+# define _OgrePrivate
+# endif
+// Win32 compilers use _DEBUG for specifying debug builds.
+# ifdef _DEBUG
+# define OGRE_DEBUG_MODE 1
+# else
+# define OGRE_DEBUG_MODE 0
+# endif
+
+// Disable unicode support on MingW at the moment, poorly supported in stdlibc++
+// STLPORT fixes this though so allow if found
+// MinGW C++ Toolkit supports unicode and sets the define __MINGW32_TOOLKIT_UNICODE__ in _mingw.h
+#if defined( __MINGW32__ ) && !defined(_STLPORT_VERSION)
+# include<_mingw.h>
+# if defined(__MINGW32_TOOLBOX_UNICODE__)
+# define OGRE_UNICODE_SUPPORT 1
+# else
+# define OGRE_UNICODE_SUPPORT 0
+# endif
+#else
+# define OGRE_UNICODE_SUPPORT 1
+#endif
+
+#endif
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+// Linux/Apple Settings
+#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+
+// Enable GCC symbol visibility
+# if defined( OGRE_GCC_VISIBILITY )
+# define _OgreExport __attribute__ ((visibility("default")))
+# define _OgrePrivate __attribute__ ((visibility("hidden")))
+# else
+# define _OgreExport
+# define _OgrePrivate
+# endif
+
+// A quick define to overcome different names for the same function
+# define stricmp strcasecmp
+
+// Unlike the Win32 compilers, Linux compilers seem to use DEBUG for when
+// specifying a debug build.
+// (??? this is wrong, on Linux debug builds aren't marked in any way unless
+// you mark it yourself any way you like it -- zap ???)
+# ifdef DEBUG
+# define OGRE_DEBUG_MODE 1
+# else
+# define OGRE_DEBUG_MODE 0
+# endif
+
+#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+ #define OGRE_PLATFORM_LIB "OgrePlatform.bundle"
+#else
+ //OGRE_PLATFORM_LINUX
+ #define OGRE_PLATFORM_LIB "libOgrePlatform.so"
+#endif
+
+// Always enable unicode support for the moment
+// Perhaps disable in old versions of gcc if necessary
+#define OGRE_UNICODE_SUPPORT 1
+
+#endif
+
+//For apple, we always have a custom config.h file
+#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+# include "config.h"
+#endif
+
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+// Endian Settings
+// check for BIG_ENDIAN config flag, set OGRE_ENDIAN correctly
+#ifdef OGRE_CONFIG_BIG_ENDIAN
+# define OGRE_ENDIAN OGRE_ENDIAN_BIG
+#else
+# define OGRE_ENDIAN OGRE_ENDIAN_LITTLE
+#endif
+
+// Integer formats of fixed bit width
+typedef unsigned int uint32;
+typedef unsigned short uint16;
+typedef unsigned char uint8;
+// define uint64 type
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC
+ typedef unsigned __int64 uint64;
+#else
+ typedef unsigned long long uint64;
+#endif
+
+
+}
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgrePlatform.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgrePrerequisites.h
===================================================================
--- sandbox_light/src/external/ogremath/OgrePrerequisites.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgrePrerequisites.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,407 @@
+/*-------------------------------------------------------------------------
+This source file is a part of OGRE
+(Object-oriented Graphics Rendering Engine)
+
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This library is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License (LGPL) as
+published by the Free Software Foundation; either version 2.1 of the
+License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library; if not, write to the Free Software Foundation,
+Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or go to
+http://www.gnu.org/copyleft/lesser.txt
+-------------------------------------------------------------------------*/
+#ifndef __OgrePrerequisites_H__
+#define __OgrePrerequisites_H__
+
+// Platform-specific stuff
+#include "OgrePlatform.h"
+
+// Needed for OGRE_WCHAR_T_STRINGS below
+#include <string>
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC
+// Turn off warnings generated by long std templates
+// This warns about truncation to 255 characters in debug/browse info
+# pragma warning (disable : 4786)
+
+// Turn off warnings generated by long std templates
+// This warns about truncation to 255 characters in debug/browse info
+# pragma warning (disable : 4503)
+
+// disable: "conversion from 'double' to 'float', possible loss of data
+# pragma warning (disable : 4244)
+
+// disable: "truncation from 'double' to 'float'
+# pragma warning (disable : 4305)
+
+// disable: "<type> needs to have dll-interface to be used by clients'
+// Happens on STL member variables which are not public therefore is ok
+# pragma warning (disable : 4251)
+
+// disable: "non dll-interface class used as base for dll-interface class"
+// Happens when deriving from Singleton because bug in compiler ignores
+// template export
+# pragma warning (disable : 4275)
+
+// disable: "C++ Exception Specification ignored"
+// This is because MSVC 6 did not implement all the C++ exception
+// specifications in the ANSI C++ draft.
+# pragma warning( disable : 4290 )
+
+// disable: "no suitable definition provided for explicit template
+// instantiation request" Occurs in VC7 for no justifiable reason on all
+// #includes of Singleton
+# pragma warning( disable: 4661)
+
+// disable: deprecation warnings when using CRT calls in VC8
+// These show up on all C runtime lib code in VC8, disable since they clutter
+// the warnings with things we may not be able to do anything about (e.g.
+// generated code from nvparse etc). I doubt very much that these calls
+// will ever be actually removed from VC anyway, it would break too much code.
+# pragma warning( disable: 4996)
+
+// disable: "conditional expression constant", always occurs on
+// OGRE_MUTEX_CONDITIONAL when no threading enabled
+# pragma warning (disable : 201)
+
+#endif
+
+// configure memory tracking
+#if OGRE_DEBUG_MODE
+# if OGRE_MEMORY_TRACKER_DEBUG_MODE
+# define OGRE_MEMORY_TRACKER 1
+# else
+# define OGRE_MEMORY_TRACKER 0
+# endif
+#else
+# if OGRE_MEMORY_TRACKER_RELEASE_MODE
+# define OGRE_MEMORY_TRACKER 1
+# else
+# define OGRE_MEMORY_TRACKER 0
+# endif
+#endif
+
+
+
+
+namespace Ogre {
+ // Define ogre version
+ #define OGRE_VERSION_MAJOR 1
+ #define OGRE_VERSION_MINOR 6
+ #define OGRE_VERSION_PATCH 1
+ #define OGRE_VERSION_SUFFIX ""
+ #define OGRE_VERSION_NAME "Shoggoth"
+
+ #define OGRE_VERSION ((OGRE_VERSION_MAJOR << 16) | (OGRE_VERSION_MINOR << 8) | OGRE_VERSION_PATCH)
+
+ // define the real number values to be used
+ // default to use 'float' unless precompiler option set
+ #if OGRE_DOUBLE_PRECISION == 1
+ /** Software floating point type.
+ @note Not valid as a pointer to GPU buffers / parameters
+ */
+ typedef double Real;
+ #else
+ /** Software floating point type.
+ @note Not valid as a pointer to GPU buffers / parameters
+ */
+ typedef float Real;
+ #endif
+
+ #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
+ # if OGRE_COMP_VER >= 430
+ # define HashMap ::std::tr1::unordered_map
+ # define HashSet ::std::tr1::unordered_set
+ # else
+ # define HashMap ::__gnu_cxx::hash_map
+ # define HashSet ::__gnu_cxx::hash_set
+ # endif
+ #else
+ # if OGRE_COMPILER == OGRE_COMPILER_MSVC
+ # if OGRE_COMP_VER > 1300 && !defined(_STLP_MSVC)
+ # define HashMap ::stdext::hash_map
+ # define HashSet ::stdext::hash_set
+ # else
+ # define HashMap ::std::hash_map
+ # define HashSet ::std::hash_set
+ # endif
+ # else
+ # define HashMap ::std::hash_map
+ # define HashSet ::std::hash_set
+ # endif
+ #endif
+
+ /** In order to avoid finger-aches :)
+ */
+ typedef unsigned char uchar;
+ typedef unsigned short ushort;
+ typedef unsigned int uint;
+ typedef unsigned long ulong;
+
+ #if OGRE_WCHAR_T_STRINGS
+ typedef std::wstring _StringBase;
+ #else
+ typedef std::string _StringBase;
+ #endif
+
+ typedef _StringBase String;
+
+ // Useful threading defines
+ #define OGRE_AUTO_MUTEX_NAME mutex
+ #if OGRE_THREAD_SUPPORT
+ #define OGRE_AUTO_MUTEX mutable boost::recursive_mutex OGRE_AUTO_MUTEX_NAME;
+ #define OGRE_LOCK_AUTO_MUTEX boost::recursive_mutex::scoped_lock ogreAutoMutexLock(OGRE_AUTO_MUTEX_NAME);
+ #define OGRE_MUTEX(name) mutable boost::recursive_mutex name;
+ #define OGRE_STATIC_MUTEX(name) static boost::recursive_mutex name;
+ #define OGRE_STATIC_MUTEX_INSTANCE(name) boost::recursive_mutex name;
+ #define OGRE_LOCK_MUTEX(name) boost::recursive_mutex::scoped_lock ogrenameLock(name);
+ #define OGRE_LOCK_MUTEX_NAMED(mutexName, lockName) boost::recursive_mutex::scoped_lock lockName(mutexName);
+ // like OGRE_AUTO_MUTEX but mutex held by pointer
+ #define OGRE_AUTO_SHARED_MUTEX mutable boost::recursive_mutex *OGRE_AUTO_MUTEX_NAME;
+ #define OGRE_LOCK_AUTO_SHARED_MUTEX assert(OGRE_AUTO_MUTEX_NAME); boost::recursive_mutex::scoped_lock ogreAutoMutexLock(*OGRE_AUTO_MUTEX_NAME);
+ #define OGRE_NEW_AUTO_SHARED_MUTEX assert(!OGRE_AUTO_MUTEX_NAME); OGRE_AUTO_MUTEX_NAME = new boost::recursive_mutex();
+ #define OGRE_DELETE_AUTO_SHARED_MUTEX assert(OGRE_AUTO_MUTEX_NAME); delete OGRE_AUTO_MUTEX_NAME;
+ #define OGRE_COPY_AUTO_SHARED_MUTEX(from) assert(!OGRE_AUTO_MUTEX_NAME); OGRE_AUTO_MUTEX_NAME = from;
+ #define OGRE_SET_AUTO_SHARED_MUTEX_NULL OGRE_AUTO_MUTEX_NAME = 0;
+ #define OGRE_MUTEX_CONDITIONAL(mutex) if (mutex)
+ #define OGRE_THREAD_SYNCHRONISER(sync) boost::condition sync;
+ #define OGRE_THREAD_WAIT(sync, lock) sync.wait(lock);
+ #define OGRE_THREAD_NOTIFY_ONE(sync) sync.notify_one();
+ #define OGRE_THREAD_NOTIFY_ALL(sync) sync.notify_all();
+ // Thread-local pointer
+ #define OGRE_THREAD_POINTER(T, var) boost::thread_specific_ptr<T> var
+ #define OGRE_THREAD_POINTER_SET(var, expr) var.reset(expr)
+ #define OGRE_THREAD_POINTER_DELETE(var) var.reset(0)
+ #define OGRE_THREAD_POINTER_GET(var) var.get()
+ #else
+ #define OGRE_AUTO_MUTEX
+ #define OGRE_LOCK_AUTO_MUTEX
+ #define OGRE_MUTEX(name)
+ #define OGRE_STATIC_MUTEX(name)
+ #define OGRE_STATIC_MUTEX_INSTANCE(name)
+ #define OGRE_LOCK_MUTEX(name)
+ #define OGRE_LOCK_MUTEX_NAMED(mutexName, lockName)
+ #define OGRE_AUTO_SHARED_MUTEX
+ #define OGRE_LOCK_AUTO_SHARED_MUTEX
+ #define OGRE_NEW_AUTO_SHARED_MUTEX
+ #define OGRE_DELETE_AUTO_SHARED_MUTEX
+ #define OGRE_COPY_AUTO_SHARED_MUTEX(from)
+ #define OGRE_SET_AUTO_SHARED_MUTEX_NULL
+ #define OGRE_MUTEX_CONDITIONAL(name) if(true)
+ #define OGRE_THREAD_SYNCHRONISER(sync)
+ #define OGRE_THREAD_WAIT(sync, lock)
+ #define OGRE_THREAD_NOTIFY_ONE(sync)
+ #define OGRE_THREAD_NOTIFY_ALL(sync)
+ #define OGRE_THREAD_POINTER(T, var) T* var
+ #define OGRE_THREAD_POINTER_SET(var, expr) var = expr
+ #define OGRE_THREAD_POINTER_DELETE(var) OGRE_DELETE var; var = 0
+ #define OGRE_THREAD_POINTER_GET(var) var
+ #endif
+
+
+// Pre-declare classes
+// Allows use of pointers in header files without including individual .h
+// so decreases dependencies between files
+ class Angle;
+ class Animation;
+ class AnimationState;
+ class AnimationStateSet;
+ class AnimationTrack;
+ class Archive;
+ class ArchiveFactory;
+ class ArchiveManager;
+ class AutoParamDataSource;
+ class AxisAlignedBox;
+ class AxisAlignedBoxSceneQuery;
+ class Billboard;
+ class BillboardChain;
+ class BillboardSet;
+ class Bone;
+ class Camera;
+ class Codec;
+ class ColourValue;
+ class ConfigDialog;
+ template <typename T> class Controller;
+ template <typename T> class ControllerFunction;
+ class ControllerManager;
+ template <typename T> class ControllerValue;
+ class Degree;
+ class DynLib;
+ class DynLibManager;
+ class EdgeData;
+ class EdgeListBuilder;
+ class Entity;
+ class ErrorDialog;
+ class ExternalTextureSourceManager;
+ class Factory;
+ class Font;
+ class FontPtr;
+ class FontManager;
+ struct FrameEvent;
+ class FrameListener;
+ class Frustum;
+ class GpuProgram;
+ class GpuProgramPtr;
+ class GpuProgramManager;
+ class GpuProgramUsage;
+ class HardwareIndexBuffer;
+ class HardwareOcclusionQuery;
+ class HardwareVertexBuffer;
+ class HardwarePixelBuffer;
+ class HardwarePixelBufferSharedPtr;
+ class HighLevelGpuProgram;
+ class HighLevelGpuProgramPtr;
+ class HighLevelGpuProgramManager;
+ class HighLevelGpuProgramFactory;
+ class IndexData;
+ class IntersectionSceneQuery;
+ class IntersectionSceneQueryListener;
+ class Image;
+ class KeyFrame;
+ class Light;
+ class Log;
+ class LogManager;
+ class ManualResourceLoader;
+ class ManualObject;
+ class Material;
+ class MaterialPtr;
+ class MaterialManager;
+ class Math;
+ class Matrix3;
+ class Matrix4;
+ class MemoryManager;
+ class Mesh;
+ class MeshPtr;
+ class MeshSerializer;
+ class MeshSerializerImpl;
+ class MeshManager;
+ class MovableObject;
+ class MovablePlane;
+ class Node;
+ class NodeAnimationTrack;
+ class NodeKeyFrame;
+ class NumericAnimationTrack;
+ class NumericKeyFrame;
+ class Overlay;
+ class OverlayContainer;
+ class OverlayElement;
+ class OverlayElementFactory;
+ class OverlayManager;
+ class Particle;
+ class ParticleAffector;
+ class ParticleAffectorFactory;
+ class ParticleEmitter;
+ class ParticleEmitterFactory;
+ class ParticleSystem;
+ class ParticleSystemManager;
+ class ParticleSystemRenderer;
+ class ParticleSystemRendererFactory;
+ class ParticleVisualData;
+ class Pass;
+ class PatchMesh;
+ class PixelBox;
+ class Plane;
+ class PlaneBoundedVolume;
+ class Plugin;
+ class Pose;
+ class ProgressiveMesh;
+ class Profile;
+ class Profiler;
+ class Quaternion;
+ class Radian;
+ class Ray;
+ class RaySceneQuery;
+ class RaySceneQueryListener;
+ class Renderable;
+ class RenderPriorityGroup;
+ class RenderQueue;
+ class RenderQueueGroup;
+ class RenderQueueInvocation;
+ class RenderQueueInvocationSequence;
+ class RenderQueueListener;
+ class RenderSystem;
+ class RenderSystemCapabilities;
+ class RenderSystemCapabilitiesManager;
+ class RenderSystemCapabilitiesSerializer;
+ class RenderTarget;
+ class RenderTargetListener;
+ class RenderTexture;
+ class MultiRenderTarget;
+ class RenderWindow;
+ class RenderOperation;
+ class Resource;
+ class ResourceBackgroundQueue;
+ class ResourceGroupManager;
+ class ResourceManager;
+ class RibbonTrail;
+ class Root;
+ class SceneManager;
+ class SceneManagerEnumerator;
+ class SceneNode;
+ class SceneQuery;
+ class SceneQueryListener;
+ class ScriptCompiler;
+ class ScriptCompilerManager;
+ class ScriptLoader;
+ class Serializer;
+ class ShadowCaster;
+ class ShadowRenderable;
+ class ShadowTextureManager;
+ class SimpleRenderable;
+ class SimpleSpline;
+ class Skeleton;
+ class SkeletonPtr;
+ class SkeletonInstance;
+ class SkeletonManager;
+ class Sphere;
+ class SphereSceneQuery;
+ class StaticGeometry;
+ class StringConverter;
+ class StringInterface;
+ class SubEntity;
+ class SubMesh;
+ class TagPoint;
+ class Technique;
+ class TempBlendedBufferInfo;
+ class ExternalTextureSource;
+ class TextureUnitState;
+ class Texture;
+ class TexturePtr;
+ class TextureManager;
+ class TransformKeyFrame;
+ class Timer;
+ class UserDefinedObject;
+ class Vector2;
+ class Vector3;
+ class Vector4;
+ class Viewport;
+ class VertexAnimationTrack;
+ class VertexBufferBinding;
+ class VertexData;
+ class VertexDeclaration;
+ class VertexMorphKeyFrame;
+ class WireBoundingBox;
+ class Compositor;
+ class CompositorManager;
+ class CompositorChain;
+ class CompositorInstance;
+ class CompositionTechnique;
+ class CompositionPass;
+ class CompositionTargetPass;
+}
+
+#endif // __OgrePrerequisites_H__
+
+
Property changes on: sandbox_light/src/external/ogremath/OgrePrerequisites.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreQuaternion.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreQuaternion.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreQuaternion.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,615 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+// NOTE THAT THIS FILE IS BASED ON MATERIAL FROM:
+
+// Magic Software, Inc.
+// http://www.geometrictools.com
+// Copyright (c) 2000, All Rights Reserved
+//
+// Source code from Magic Software is supplied under the terms of a license
+// agreement and may not be copied or disclosed except in accordance with the
+// terms of that agreement. The various license agreements may be found at
+// the Magic Software web site. This file is subject to the license
+//
+// FREE SOURCE CODE
+// http://www.geometrictools.com/License/WildMagic3License.pdf
+
+#include "OgreQuaternion.h"
+
+#include "OgreMath.h"
+#include "OgreMatrix3.h"
+#include "OgreVector3.h"
+
+namespace Ogre {
+
+ const Real Quaternion::ms_fEpsilon = 1e-03;
+ const Quaternion Quaternion::ZERO(0.0,0.0,0.0,0.0);
+ const Quaternion Quaternion::IDENTITY(1.0,0.0,0.0,0.0);
+
+ //-----------------------------------------------------------------------
+ void Quaternion::FromRotationMatrix (const Matrix3& kRot)
+ {
+ // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
+ // article "Quaternion Calculus and Fast Animation".
+
+ Real fTrace = kRot[0][0]+kRot[1][1]+kRot[2][2];
+ Real fRoot;
+
+ if ( fTrace > 0.0 )
+ {
+ // |w| > 1/2, may as well choose w > 1/2
+ fRoot = Math::Sqrt(fTrace + 1.0); // 2w
+ w = 0.5*fRoot;
+ fRoot = 0.5/fRoot; // 1/(4w)
+ x = (kRot[2][1]-kRot[1][2])*fRoot;
+ y = (kRot[0][2]-kRot[2][0])*fRoot;
+ z = (kRot[1][0]-kRot[0][1])*fRoot;
+ }
+ else
+ {
+ // |w| <= 1/2
+ static size_t s_iNext[3] = { 1, 2, 0 };
+ size_t i = 0;
+ if ( kRot[1][1] > kRot[0][0] )
+ i = 1;
+ if ( kRot[2][2] > kRot[i][i] )
+ i = 2;
+ size_t j = s_iNext[i];
+ size_t k = s_iNext[j];
+
+ fRoot = Math::Sqrt(kRot[i][i]-kRot[j][j]-kRot[k][k] + 1.0);
+ Real* apkQuat[3] = { &x, &y, &z };
+ *apkQuat[i] = 0.5*fRoot;
+ fRoot = 0.5/fRoot;
+ w = (kRot[k][j]-kRot[j][k])*fRoot;
+ *apkQuat[j] = (kRot[j][i]+kRot[i][j])*fRoot;
+ *apkQuat[k] = (kRot[k][i]+kRot[i][k])*fRoot;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::ToRotationMatrix (Matrix3& kRot) const
+ {
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwx = fTx*w;
+ Real fTwy = fTy*w;
+ Real fTwz = fTz*w;
+ Real fTxx = fTx*x;
+ Real fTxy = fTy*x;
+ Real fTxz = fTz*x;
+ Real fTyy = fTy*y;
+ Real fTyz = fTz*y;
+ Real fTzz = fTz*z;
+
+ kRot[0][0] = 1.0-(fTyy+fTzz);
+ kRot[0][1] = fTxy-fTwz;
+ kRot[0][2] = fTxz+fTwy;
+ kRot[1][0] = fTxy+fTwz;
+ kRot[1][1] = 1.0-(fTxx+fTzz);
+ kRot[1][2] = fTyz-fTwx;
+ kRot[2][0] = fTxz-fTwy;
+ kRot[2][1] = fTyz+fTwx;
+ kRot[2][2] = 1.0-(fTxx+fTyy);
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::FromAngleAxis (const Radian& rfAngle,
+ const Vector3& rkAxis)
+ {
+ // assert: axis[] is unit length
+ //
+ // The quaternion representing the rotation is
+ // q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)
+
+ Radian fHalfAngle ( 0.5*rfAngle );
+ Real fSin = Math::Sin(fHalfAngle);
+ w = Math::Cos(fHalfAngle);
+ x = fSin*rkAxis.x;
+ y = fSin*rkAxis.y;
+ z = fSin*rkAxis.z;
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::ToAngleAxis (Radian& rfAngle, Vector3& rkAxis) const
+ {
+ // The quaternion representing the rotation is
+ // q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)
+
+ Real fSqrLength = x*x+y*y+z*z;
+ if ( fSqrLength > 0.0 )
+ {
+ rfAngle = 2.0*Math::ACos(w);
+ Real fInvLength = Math::InvSqrt(fSqrLength);
+ rkAxis.x = x*fInvLength;
+ rkAxis.y = y*fInvLength;
+ rkAxis.z = z*fInvLength;
+ }
+ else
+ {
+ // angle is 0 (mod 2*pi), so any axis will do
+ rfAngle = Radian(0.0);
+ rkAxis.x = 1.0;
+ rkAxis.y = 0.0;
+ rkAxis.z = 0.0;
+ }
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::FromAxes (const Vector3* akAxis)
+ {
+ Matrix3 kRot;
+
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ kRot[0][iCol] = akAxis[iCol].x;
+ kRot[1][iCol] = akAxis[iCol].y;
+ kRot[2][iCol] = akAxis[iCol].z;
+ }
+
+ FromRotationMatrix(kRot);
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::FromAxes (const Vector3& xaxis, const Vector3& yaxis, const Vector3& zaxis)
+ {
+ Matrix3 kRot;
+
+ kRot[0][0] = xaxis.x;
+ kRot[1][0] = xaxis.y;
+ kRot[2][0] = xaxis.z;
+
+ kRot[0][1] = yaxis.x;
+ kRot[1][1] = yaxis.y;
+ kRot[2][1] = yaxis.z;
+
+ kRot[0][2] = zaxis.x;
+ kRot[1][2] = zaxis.y;
+ kRot[2][2] = zaxis.z;
+
+ FromRotationMatrix(kRot);
+
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::ToAxes (Vector3* akAxis) const
+ {
+ Matrix3 kRot;
+
+ ToRotationMatrix(kRot);
+
+ for (size_t iCol = 0; iCol < 3; iCol++)
+ {
+ akAxis[iCol].x = kRot[0][iCol];
+ akAxis[iCol].y = kRot[1][iCol];
+ akAxis[iCol].z = kRot[2][iCol];
+ }
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Quaternion::xAxis(void) const
+ {
+ //Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwy = fTy*w;
+ Real fTwz = fTz*w;
+ Real fTxy = fTy*x;
+ Real fTxz = fTz*x;
+ Real fTyy = fTy*y;
+ Real fTzz = fTz*z;
+
+ return Vector3(1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy);
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Quaternion::yAxis(void) const
+ {
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwx = fTx*w;
+ Real fTwz = fTz*w;
+ Real fTxx = fTx*x;
+ Real fTxy = fTy*x;
+ Real fTyz = fTz*y;
+ Real fTzz = fTz*z;
+
+ return Vector3(fTxy-fTwz, 1.0-(fTxx+fTzz), fTyz+fTwx);
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Quaternion::zAxis(void) const
+ {
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwx = fTx*w;
+ Real fTwy = fTy*w;
+ Real fTxx = fTx*x;
+ Real fTxz = fTz*x;
+ Real fTyy = fTy*y;
+ Real fTyz = fTz*y;
+
+ return Vector3(fTxz+fTwy, fTyz-fTwx, 1.0-(fTxx+fTyy));
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::ToAxes (Vector3& xaxis, Vector3& yaxis, Vector3& zaxis) const
+ {
+ Matrix3 kRot;
+
+ ToRotationMatrix(kRot);
+
+ xaxis.x = kRot[0][0];
+ xaxis.y = kRot[1][0];
+ xaxis.z = kRot[2][0];
+
+ yaxis.x = kRot[0][1];
+ yaxis.y = kRot[1][1];
+ yaxis.z = kRot[2][1];
+
+ zaxis.x = kRot[0][2];
+ zaxis.y = kRot[1][2];
+ zaxis.z = kRot[2][2];
+ }
+
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::operator+ (const Quaternion& rkQ) const
+ {
+ return Quaternion(w+rkQ.w,x+rkQ.x,y+rkQ.y,z+rkQ.z);
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::operator- (const Quaternion& rkQ) const
+ {
+ return Quaternion(w-rkQ.w,x-rkQ.x,y-rkQ.y,z-rkQ.z);
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::operator* (const Quaternion& rkQ) const
+ {
+ // NOTE: Multiplication is not generally commutative, so in most
+ // cases p*q != q*p.
+
+ return Quaternion
+ (
+ w * rkQ.w - x * rkQ.x - y * rkQ.y - z * rkQ.z,
+ w * rkQ.x + x * rkQ.w + y * rkQ.z - z * rkQ.y,
+ w * rkQ.y + y * rkQ.w + z * rkQ.x - x * rkQ.z,
+ w * rkQ.z + z * rkQ.w + x * rkQ.y - y * rkQ.x
+ );
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::operator* (Real fScalar) const
+ {
+ return Quaternion(fScalar*w,fScalar*x,fScalar*y,fScalar*z);
+ }
+ //-----------------------------------------------------------------------
+ Quaternion operator* (Real fScalar, const Quaternion& rkQ)
+ {
+ return Quaternion(fScalar*rkQ.w,fScalar*rkQ.x,fScalar*rkQ.y,
+ fScalar*rkQ.z);
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::operator- () const
+ {
+ return Quaternion(-w,-x,-y,-z);
+ }
+ //-----------------------------------------------------------------------
+ Real Quaternion::Dot (const Quaternion& rkQ) const
+ {
+ return w*rkQ.w+x*rkQ.x+y*rkQ.y+z*rkQ.z;
+ }
+ //-----------------------------------------------------------------------
+ Real Quaternion::Norm () const
+ {
+ return w*w+x*x+y*y+z*z;
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::Inverse () const
+ {
+ Real fNorm = w*w+x*x+y*y+z*z;
+ if ( fNorm > 0.0 )
+ {
+ Real fInvNorm = 1.0/fNorm;
+ return Quaternion(w*fInvNorm,-x*fInvNorm,-y*fInvNorm,-z*fInvNorm);
+ }
+ else
+ {
+ // return an invalid result to flag the error
+ return ZERO;
+ }
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::UnitInverse () const
+ {
+ // assert: 'this' is unit length
+ return Quaternion(w,-x,-y,-z);
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::Exp () const
+ {
+ // If q = A*(x*i+y*j+z*k) where (x,y,z) is unit length, then
+ // exp(q) = cos(A)+sin(A)*(x*i+y*j+z*k). If sin(A) is near zero,
+ // use exp(q) = cos(A)+A*(x*i+y*j+z*k) since A/sin(A) has limit 1.
+
+ Radian fAngle ( Math::Sqrt(x*x+y*y+z*z) );
+ Real fSin = Math::Sin(fAngle);
+
+ Quaternion kResult;
+ kResult.w = Math::Cos(fAngle);
+
+ if ( Math::Abs(fSin) >= ms_fEpsilon )
+ {
+ Real fCoeff = fSin/(fAngle.valueRadians());
+ kResult.x = fCoeff*x;
+ kResult.y = fCoeff*y;
+ kResult.z = fCoeff*z;
+ }
+ else
+ {
+ kResult.x = x;
+ kResult.y = y;
+ kResult.z = z;
+ }
+
+ return kResult;
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::Log () const
+ {
+ // If q = cos(A)+sin(A)*(x*i+y*j+z*k) where (x,y,z) is unit length, then
+ // log(q) = A*(x*i+y*j+z*k). If sin(A) is near zero, use log(q) =
+ // sin(A)*(x*i+y*j+z*k) since sin(A)/A has limit 1.
+
+ Quaternion kResult;
+ kResult.w = 0.0;
+
+ if ( Math::Abs(w) < 1.0 )
+ {
+ Radian fAngle ( Math::ACos(w) );
+ Real fSin = Math::Sin(fAngle);
+ if ( Math::Abs(fSin) >= ms_fEpsilon )
+ {
+ Real fCoeff = fAngle.valueRadians()/fSin;
+ kResult.x = fCoeff*x;
+ kResult.y = fCoeff*y;
+ kResult.z = fCoeff*z;
+ return kResult;
+ }
+ }
+
+ kResult.x = x;
+ kResult.y = y;
+ kResult.z = z;
+
+ return kResult;
+ }
+ //-----------------------------------------------------------------------
+ Vector3 Quaternion::operator* (const Vector3& v) const
+ {
+ // nVidia SDK implementation
+ Vector3 uv, uuv;
+ Vector3 qvec(x, y, z);
+ uv = qvec.crossProduct(v);
+ uuv = qvec.crossProduct(uv);
+ uv *= (2.0f * w);
+ uuv *= 2.0f;
+
+ return v + uv + uuv;
+
+ }
+ //-----------------------------------------------------------------------
+ bool Quaternion::equals(const Quaternion& rhs, const Radian& tolerance) const
+ {
+ Real fCos = Dot(rhs);
+ Radian angle = Math::ACos(fCos);
+
+ return (Math::Abs(angle.valueRadians()) <= tolerance.valueRadians())
+ || Math::RealEqual(angle.valueRadians(), Math::PI, tolerance.valueRadians());
+
+
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::Slerp (Real fT, const Quaternion& rkP,
+ const Quaternion& rkQ, bool shortestPath)
+ {
+ Real fCos = rkP.Dot(rkQ);
+ Quaternion rkT;
+
+ // Do we need to invert rotation?
+ if (fCos < 0.0f && shortestPath)
+ {
+ fCos = -fCos;
+ rkT = -rkQ;
+ }
+ else
+ {
+ rkT = rkQ;
+ }
+
+ if (Math::Abs(fCos) < 1 - ms_fEpsilon)
+ {
+ // Standard case (slerp)
+ Real fSin = Math::Sqrt(1 - Math::Sqr(fCos));
+ Radian fAngle = Math::ATan2(fSin, fCos);
+ Real fInvSin = 1.0f / fSin;
+ Real fCoeff0 = Math::Sin((1.0f - fT) * fAngle) * fInvSin;
+ Real fCoeff1 = Math::Sin(fT * fAngle) * fInvSin;
+ return fCoeff0 * rkP + fCoeff1 * rkT;
+ }
+ else
+ {
+ // There are two situations:
+ // 1. "rkP" and "rkQ" are very close (fCos ~= +1), so we can do a linear
+ // interpolation safely.
+ // 2. "rkP" and "rkQ" are almost inverse of each other (fCos ~= -1), there
+ // are an infinite number of possibilities interpolation. but we haven't
+ // have method to fix this case, so just use linear interpolation here.
+ Quaternion t = (1.0f - fT) * rkP + fT * rkT;
+ // taking the complement requires renormalisation
+ t.normalise();
+ return t;
+ }
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::SlerpExtraSpins (Real fT,
+ const Quaternion& rkP, const Quaternion& rkQ, int iExtraSpins)
+ {
+ Real fCos = rkP.Dot(rkQ);
+ Radian fAngle ( Math::ACos(fCos) );
+
+ if ( Math::Abs(fAngle.valueRadians()) < ms_fEpsilon )
+ return rkP;
+
+ Real fSin = Math::Sin(fAngle);
+ Radian fPhase ( Math::PI*iExtraSpins*fT );
+ Real fInvSin = 1.0/fSin;
+ Real fCoeff0 = Math::Sin((1.0-fT)*fAngle - fPhase)*fInvSin;
+ Real fCoeff1 = Math::Sin(fT*fAngle + fPhase)*fInvSin;
+ return fCoeff0*rkP + fCoeff1*rkQ;
+ }
+ //-----------------------------------------------------------------------
+ void Quaternion::Intermediate (const Quaternion& rkQ0,
+ const Quaternion& rkQ1, const Quaternion& rkQ2,
+ Quaternion& rkA, Quaternion& rkB)
+ {
+ // assert: q0, q1, q2 are unit quaternions
+
+ Quaternion kQ0inv = rkQ0.UnitInverse();
+ Quaternion kQ1inv = rkQ1.UnitInverse();
+ Quaternion rkP0 = kQ0inv*rkQ1;
+ Quaternion rkP1 = kQ1inv*rkQ2;
+ Quaternion kArg = 0.25*(rkP0.Log()-rkP1.Log());
+ Quaternion kMinusArg = -kArg;
+
+ rkA = rkQ1*kArg.Exp();
+ rkB = rkQ1*kMinusArg.Exp();
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::Squad (Real fT,
+ const Quaternion& rkP, const Quaternion& rkA,
+ const Quaternion& rkB, const Quaternion& rkQ, bool shortestPath)
+ {
+ Real fSlerpT = 2.0*fT*(1.0-fT);
+ Quaternion kSlerpP = Slerp(fT, rkP, rkQ, shortestPath);
+ Quaternion kSlerpQ = Slerp(fT, rkA, rkB);
+ return Slerp(fSlerpT, kSlerpP ,kSlerpQ);
+ }
+ //-----------------------------------------------------------------------
+ Real Quaternion::normalise(void)
+ {
+ Real len = Norm();
+ Real factor = 1.0f / Math::Sqrt(len);
+ *this = *this * factor;
+ return len;
+ }
+ //-----------------------------------------------------------------------
+ Radian Quaternion::getRoll(bool reprojectAxis) const
+ {
+ if (reprojectAxis)
+ {
+ // roll = atan2(localx.y, localx.x)
+ // pick parts of xAxis() implementation that we need
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwz = fTz*w;
+ Real fTxy = fTy*x;
+ Real fTyy = fTy*y;
+ Real fTzz = fTz*z;
+
+ // Vector3(1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy);
+
+ return Radian(Math::ATan2(fTxy+fTwz, 1.0-(fTyy+fTzz)));
+
+ }
+ else
+ {
+ return Radian(Math::ATan2(2*(x*y + w*z), w*w + x*x - y*y - z*z));
+ }
+ }
+ //-----------------------------------------------------------------------
+ Radian Quaternion::getPitch(bool reprojectAxis) const
+ {
+ if (reprojectAxis)
+ {
+ // pitch = atan2(localy.z, localy.y)
+ // pick parts of yAxis() implementation that we need
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwx = fTx*w;
+ Real fTxx = fTx*x;
+ Real fTyz = fTz*y;
+ Real fTzz = fTz*z;
+
+ // Vector3(fTxy-fTwz, 1.0-(fTxx+fTzz), fTyz+fTwx);
+ return Radian(Math::ATan2(fTyz+fTwx, 1.0-(fTxx+fTzz)));
+ }
+ else
+ {
+ // internal version
+ return Radian(Math::ATan2(2*(y*z + w*x), w*w - x*x - y*y + z*z));
+ }
+ }
+ //-----------------------------------------------------------------------
+ Radian Quaternion::getYaw(bool reprojectAxis) const
+ {
+ if (reprojectAxis)
+ {
+ // yaw = atan2(localz.x, localz.z)
+ // pick parts of zAxis() implementation that we need
+ Real fTx = 2.0*x;
+ Real fTy = 2.0*y;
+ Real fTz = 2.0*z;
+ Real fTwy = fTy*w;
+ Real fTxx = fTx*x;
+ Real fTxz = fTz*x;
+ Real fTyy = fTy*y;
+
+ // Vector3(fTxz+fTwy, fTyz-fTwx, 1.0-(fTxx+fTyy));
+
+ return Radian(Math::ATan2(fTxz+fTwy, 1.0-(fTxx+fTyy)));
+
+ }
+ else
+ {
+ // internal version
+ return Radian(Math::ASin(-2*(x*z - w*y)));
+ }
+ }
+ //-----------------------------------------------------------------------
+ Quaternion Quaternion::nlerp(Real fT, const Quaternion& rkP,
+ const Quaternion& rkQ, bool shortestPath)
+ {
+ Quaternion result;
+ Real fCos = rkP.Dot(rkQ);
+ if (fCos < 0.0f && shortestPath)
+ {
+ result = rkP + fT * ((-rkQ) - rkP);
+ }
+ else
+ {
+ result = rkP + fT * (rkQ - rkP);
+ }
+ result.normalise();
+ return result;
+ }
+}
Property changes on: sandbox_light/src/external/ogremath/OgreQuaternion.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreQuaternion.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreQuaternion.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreQuaternion.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,257 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+// NOTE THAT THIS FILE IS BASED ON MATERIAL FROM:
+
+// Magic Software, Inc.
+// http://www.geometrictools.com/
+// Copyright (c) 2000, All Rights Reserved
+//
+// Source code from Magic Software is supplied under the terms of a license
+// agreement and may not be copied or disclosed except in accordance with the
+// terms of that agreement. The various license agreements may be found at
+// the Magic Software web site. This file is subject to the license
+//
+// FREE SOURCE CODE
+// http://www.geometrictools.com/License/WildMagic3License.pdf
+
+#ifndef __Quaternion_H__
+#define __Quaternion_H__
+
+#include "OgrePrerequisites.h"
+
+#include <cassert>
+#include "OgreMath.h"
+#include <ostream>
+
+namespace Ogre {
+
+ /** Implementation of a Quaternion, i.e. a rotation around an axis.
+ */
+ class _OgreExport Quaternion
+ {
+ public:
+ inline Quaternion (
+ Real fW = 1.0,
+ Real fX = 0.0, Real fY = 0.0, Real fZ = 0.0)
+ {
+ w = fW;
+ x = fX;
+ y = fY;
+ z = fZ;
+ }
+ /// Construct a quaternion from a rotation matrix
+ inline Quaternion(const Matrix3& rot)
+ {
+ this->FromRotationMatrix(rot);
+ }
+ /// Construct a quaternion from an angle/axis
+ inline Quaternion(const Radian& rfAngle, const Vector3& rkAxis)
+ {
+ this->FromAngleAxis(rfAngle, rkAxis);
+ }
+ /// Construct a quaternion from 3 orthonormal local axes
+ inline Quaternion(const Vector3& xaxis, const Vector3& yaxis, const Vector3& zaxis)
+ {
+ this->FromAxes(xaxis, yaxis, zaxis);
+ }
+ /// Construct a quaternion from 3 orthonormal local axes
+ inline Quaternion(const Vector3* akAxis)
+ {
+ this->FromAxes(akAxis);
+ }
+ /// Construct a quaternion from 4 manual w/x/y/z values
+ inline Quaternion(Real* valptr)
+ {
+ memcpy(&w, valptr, sizeof(Real)*4);
+ }
+
+ /// Array accessor operator
+ inline Real operator [] ( const size_t i ) const
+ {
+ assert( i < 4 );
+
+ return *(&w+i);
+ }
+
+ /// Array accessor operator
+ inline Real& operator [] ( const size_t i )
+ {
+ assert( i < 4 );
+
+ return *(&w+i);
+ }
+
+ /// Pointer accessor for direct copying
+ inline Real* ptr()
+ {
+ return &w;
+ }
+
+ /// Pointer accessor for direct copying
+ inline const Real* ptr() const
+ {
+ return &w;
+ }
+
+ void FromRotationMatrix (const Matrix3& kRot);
+ void ToRotationMatrix (Matrix3& kRot) const;
+ void FromAngleAxis (const Radian& rfAngle, const Vector3& rkAxis);
+ void ToAngleAxis (Radian& rfAngle, Vector3& rkAxis) const;
+ inline void ToAngleAxis (Degree& dAngle, Vector3& rkAxis) const {
+ Radian rAngle;
+ ToAngleAxis ( rAngle, rkAxis );
+ dAngle = rAngle;
+ }
+ void FromAxes (const Vector3* akAxis);
+ void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
+ void ToAxes (Vector3* akAxis) const;
+ void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis) const;
+ /// Get the local x-axis
+ Vector3 xAxis(void) const;
+ /// Get the local y-axis
+ Vector3 yAxis(void) const;
+ /// Get the local z-axis
+ Vector3 zAxis(void) const;
+
+ inline Quaternion& operator= (const Quaternion& rkQ)
+ {
+ w = rkQ.w;
+ x = rkQ.x;
+ y = rkQ.y;
+ z = rkQ.z;
+ return *this;
+ }
+ Quaternion operator+ (const Quaternion& rkQ) const;
+ Quaternion operator- (const Quaternion& rkQ) const;
+ Quaternion operator* (const Quaternion& rkQ) const;
+ Quaternion operator* (Real fScalar) const;
+ _OgreExport friend Quaternion operator* (Real fScalar,
+ const Quaternion& rkQ);
+ Quaternion operator- () const;
+ inline bool operator== (const Quaternion& rhs) const
+ {
+ return (rhs.x == x) && (rhs.y == y) &&
+ (rhs.z == z) && (rhs.w == w);
+ }
+ inline bool operator!= (const Quaternion& rhs) const
+ {
+ return !operator==(rhs);
+ }
+ // functions of a quaternion
+ Real Dot (const Quaternion& rkQ) const; // dot product
+ Real Norm () const; // squared-length
+ /// Normalises this quaternion, and returns the previous length
+ Real normalise(void);
+ Quaternion Inverse () const; // apply to non-zero quaternion
+ Quaternion UnitInverse () const; // apply to unit-length quaternion
+ Quaternion Exp () const;
+ Quaternion Log () const;
+
+ // rotation of a vector by a quaternion
+ Vector3 operator* (const Vector3& rkVector) const;
+
+ /** Calculate the local roll element of this quaternion.
+ @param reprojectAxis By default the method returns the 'intuitive' result
+ that is, if you projected the local Y of the quaternion onto the X and
+ Y axes, the angle between them is returned. If set to false though, the
+ result is the actual yaw that will be used to implement the quaternion,
+ which is the shortest possible path to get to the same orientation and
+ may involve less axial rotation.
+ */
+ Radian getRoll(bool reprojectAxis = true) const;
+ /** Calculate the local pitch element of this quaternion
+ @param reprojectAxis By default the method returns the 'intuitive' result
+ that is, if you projected the local Z of the quaternion onto the X and
+ Y axes, the angle between them is returned. If set to true though, the
+ result is the actual yaw that will be used to implement the quaternion,
+ which is the shortest possible path to get to the same orientation and
+ may involve less axial rotation.
+ */
+ Radian getPitch(bool reprojectAxis = true) const;
+ /** Calculate the local yaw element of this quaternion
+ @param reprojectAxis By default the method returns the 'intuitive' result
+ that is, if you projected the local Z of the quaternion onto the X and
+ Z axes, the angle between them is returned. If set to true though, the
+ result is the actual yaw that will be used to implement the quaternion,
+ which is the shortest possible path to get to the same orientation and
+ may involve less axial rotation.
+ */
+ Radian getYaw(bool reprojectAxis = true) const;
+ /// Equality with tolerance (tolerance is max angle difference)
+ bool equals(const Quaternion& rhs, const Radian& tolerance) const;
+
+ // spherical linear interpolation
+ static Quaternion Slerp (Real fT, const Quaternion& rkP,
+ const Quaternion& rkQ, bool shortestPath = false);
+
+ static Quaternion SlerpExtraSpins (Real fT,
+ const Quaternion& rkP, const Quaternion& rkQ,
+ int iExtraSpins);
+
+ // setup for spherical quadratic interpolation
+ static void Intermediate (const Quaternion& rkQ0,
+ const Quaternion& rkQ1, const Quaternion& rkQ2,
+ Quaternion& rka, Quaternion& rkB);
+
+ // spherical quadratic interpolation
+ static Quaternion Squad (Real fT, const Quaternion& rkP,
+ const Quaternion& rkA, const Quaternion& rkB,
+ const Quaternion& rkQ, bool shortestPath = false);
+
+ // normalised linear interpolation - faster but less accurate (non-constant rotation velocity)
+ static Quaternion nlerp(Real fT, const Quaternion& rkP,
+ const Quaternion& rkQ, bool shortestPath = false);
+
+ // cutoff for sine near zero
+ static const Real ms_fEpsilon;
+
+ // special values
+ static const Quaternion ZERO;
+ static const Quaternion IDENTITY;
+
+ Real w, x, y, z;
+
+ /** Function for writing to a stream. Outputs "Quaternion(w, x, y, z)" with w,x,y,z
+ being the member values of the quaternion.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const Quaternion& q )
+ {
+ o << "Quaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ")";
+ return o;
+ }
+
+ };
+
+}
+
+
+
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreQuaternion.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreTimer.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreTimer.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreTimer.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,44 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __OgreCommonTimer_H__
+#define __OgreCommonTimer_H__
+
+#include "OgrePrerequisites.h"
+#include "OgrePlatform.h"
+
+//Bring in the specific platform's header file
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+# include "WIN32/OgreTimerImp.h"
+#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
+# include "GLX/OgreTimerImp.h"
+#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+# include "OSX/OgreTimerImp.h"
+#endif
+
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreTimer.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector2.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector2.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector2.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,43 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+#include "OgreVector2.h"
+#include "OgreMath.h"
+
+namespace Ogre
+{
+ const Vector2 Vector2::ZERO( 0, 0);
+
+ const Vector2 Vector2::UNIT_X( 1, 0);
+ const Vector2 Vector2::UNIT_Y( 0, 1);
+ const Vector2 Vector2::NEGATIVE_UNIT_X( -1, 0);
+ const Vector2 Vector2::NEGATIVE_UNIT_Y( 0, -1);
+ const Vector2 Vector2::UNIT_SCALE(1, 1);
+
+}
Property changes on: sandbox_light/src/external/ogremath/OgreVector2.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector2.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector2.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector2.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,528 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Vector2_H__
+#define __Vector2_H__
+
+
+#include "OgrePrerequisites.h"
+#include "OgreMath.h"
+#include <ostream>
+
+namespace Ogre
+{
+
+ /** Standard 2-dimensional vector.
+ @remarks
+ A direction in 2D space represented as distances along the 2
+ orthogonal axes (x, y). Note that positions, directions and
+ scaling factors can be represented by a vector, depending on how
+ you interpret the values.
+ */
+ class _OgreExport Vector2
+ {
+ public:
+ Real x, y;
+
+ public:
+ inline Vector2()
+ {
+ }
+
+ inline Vector2(const Real fX, const Real fY )
+ : x( fX ), y( fY )
+ {
+ }
+
+ inline explicit Vector2( const Real scaler )
+ : x( scaler), y( scaler )
+ {
+ }
+
+ inline explicit Vector2( const Real afCoordinate[2] )
+ : x( afCoordinate[0] ),
+ y( afCoordinate[1] )
+ {
+ }
+
+ inline explicit Vector2( const int afCoordinate[2] )
+ {
+ x = (Real)afCoordinate[0];
+ y = (Real)afCoordinate[1];
+ }
+
+ inline explicit Vector2( Real* const r )
+ : x( r[0] ), y( r[1] )
+ {
+ }
+
+ inline Real operator [] ( const size_t i ) const
+ {
+ assert( i < 2 );
+
+ return *(&x+i);
+ }
+
+ inline Real& operator [] ( const size_t i )
+ {
+ assert( i < 2 );
+
+ return *(&x+i);
+ }
+
+ /// Pointer accessor for direct copying
+ inline Real* ptr()
+ {
+ return &x;
+ }
+ /// Pointer accessor for direct copying
+ inline const Real* ptr() const
+ {
+ return &x;
+ }
+
+ /** Assigns the value of the other vector.
+ @param
+ rkVector The other vector
+ */
+ inline Vector2& operator = ( const Vector2& rkVector )
+ {
+ x = rkVector.x;
+ y = rkVector.y;
+
+ return *this;
+ }
+
+ inline Vector2& operator = ( const Real fScalar)
+ {
+ x = fScalar;
+ y = fScalar;
+
+ return *this;
+ }
+
+ inline bool operator == ( const Vector2& rkVector ) const
+ {
+ return ( x == rkVector.x && y == rkVector.y );
+ }
+
+ inline bool operator != ( const Vector2& rkVector ) const
+ {
+ return ( x != rkVector.x || y != rkVector.y );
+ }
+
+ // arithmetic operations
+ inline Vector2 operator + ( const Vector2& rkVector ) const
+ {
+ return Vector2(
+ x + rkVector.x,
+ y + rkVector.y);
+ }
+
+ inline Vector2 operator - ( const Vector2& rkVector ) const
+ {
+ return Vector2(
+ x - rkVector.x,
+ y - rkVector.y);
+ }
+
+ inline Vector2 operator * ( const Real fScalar ) const
+ {
+ return Vector2(
+ x * fScalar,
+ y * fScalar);
+ }
+
+ inline Vector2 operator * ( const Vector2& rhs) const
+ {
+ return Vector2(
+ x * rhs.x,
+ y * rhs.y);
+ }
+
+ inline Vector2 operator / ( const Real fScalar ) const
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ return Vector2(
+ x * fInv,
+ y * fInv);
+ }
+
+ inline Vector2 operator / ( const Vector2& rhs) const
+ {
+ return Vector2(
+ x / rhs.x,
+ y / rhs.y);
+ }
+
+ inline const Vector2& operator + () const
+ {
+ return *this;
+ }
+
+ inline Vector2 operator - () const
+ {
+ return Vector2(-x, -y);
+ }
+
+ // overloaded operators to help Vector2
+ inline friend Vector2 operator * ( const Real fScalar, const Vector2& rkVector )
+ {
+ return Vector2(
+ fScalar * rkVector.x,
+ fScalar * rkVector.y);
+ }
+
+ inline friend Vector2 operator / ( const Real fScalar, const Vector2& rkVector )
+ {
+ return Vector2(
+ fScalar / rkVector.x,
+ fScalar / rkVector.y);
+ }
+
+ inline friend Vector2 operator + (const Vector2& lhs, const Real rhs)
+ {
+ return Vector2(
+ lhs.x + rhs,
+ lhs.y + rhs);
+ }
+
+ inline friend Vector2 operator + (const Real lhs, const Vector2& rhs)
+ {
+ return Vector2(
+ lhs + rhs.x,
+ lhs + rhs.y);
+ }
+
+ inline friend Vector2 operator - (const Vector2& lhs, const Real rhs)
+ {
+ return Vector2(
+ lhs.x - rhs,
+ lhs.y - rhs);
+ }
+
+ inline friend Vector2 operator - (const Real lhs, const Vector2& rhs)
+ {
+ return Vector2(
+ lhs - rhs.x,
+ lhs - rhs.y);
+ }
+ // arithmetic updates
+ inline Vector2& operator += ( const Vector2& rkVector )
+ {
+ x += rkVector.x;
+ y += rkVector.y;
+
+ return *this;
+ }
+
+ inline Vector2& operator += ( const Real fScaler )
+ {
+ x += fScaler;
+ y += fScaler;
+
+ return *this;
+ }
+
+ inline Vector2& operator -= ( const Vector2& rkVector )
+ {
+ x -= rkVector.x;
+ y -= rkVector.y;
+
+ return *this;
+ }
+
+ inline Vector2& operator -= ( const Real fScaler )
+ {
+ x -= fScaler;
+ y -= fScaler;
+
+ return *this;
+ }
+
+ inline Vector2& operator *= ( const Real fScalar )
+ {
+ x *= fScalar;
+ y *= fScalar;
+
+ return *this;
+ }
+
+ inline Vector2& operator *= ( const Vector2& rkVector )
+ {
+ x *= rkVector.x;
+ y *= rkVector.y;
+
+ return *this;
+ }
+
+ inline Vector2& operator /= ( const Real fScalar )
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ x *= fInv;
+ y *= fInv;
+
+ return *this;
+ }
+
+ inline Vector2& operator /= ( const Vector2& rkVector )
+ {
+ x /= rkVector.x;
+ y /= rkVector.y;
+
+ return *this;
+ }
+
+ /** Returns the length (magnitude) of the vector.
+ @warning
+ This operation requires a square root and is expensive in
+ terms of CPU operations. If you don't need to know the exact
+ length (e.g. for just comparing lengths) use squaredLength()
+ instead.
+ */
+ inline Real length () const
+ {
+ return Math::Sqrt( x * x + y * y );
+ }
+
+ /** Returns the square of the length(magnitude) of the vector.
+ @remarks
+ This method is for efficiency - calculating the actual
+ length of a vector requires a square root, which is expensive
+ in terms of the operations required. This method returns the
+ square of the length of the vector, i.e. the same as the
+ length but before the square root is taken. Use this if you
+ want to find the longest / shortest vector without incurring
+ the square root.
+ */
+ inline Real squaredLength () const
+ {
+ return x * x + y * y;
+ }
+
+ /** Calculates the dot (scalar) product of this vector with another.
+ @remarks
+ The dot product can be used to calculate the angle between 2
+ vectors. If both are unit vectors, the dot product is the
+ cosine of the angle; otherwise the dot product must be
+ divided by the product of the lengths of both vectors to get
+ the cosine of the angle. This result can further be used to
+ calculate the distance of a point from a plane.
+ @param
+ vec Vector with which to calculate the dot product (together
+ with this one).
+ @returns
+ A float representing the dot product value.
+ */
+ inline Real dotProduct(const Vector2& vec) const
+ {
+ return x * vec.x + y * vec.y;
+ }
+
+ /** Normalises the vector.
+ @remarks
+ This method normalises the vector such that it's
+ length / magnitude is 1. The result is called a unit vector.
+ @note
+ This function will not crash for zero-sized vectors, but there
+ will be no changes made to their components.
+ @returns The previous length of the vector.
+ */
+ inline Real normalise()
+ {
+ Real fLength = Math::Sqrt( x * x + y * y);
+
+ // Will also work for zero-sized vectors, but will change nothing
+ if ( fLength > 1e-08 )
+ {
+ Real fInvLength = 1.0 / fLength;
+ x *= fInvLength;
+ y *= fInvLength;
+ }
+
+ return fLength;
+ }
+
+
+
+ /** Returns a vector at a point half way between this and the passed
+ in vector.
+ */
+ inline Vector2 midPoint( const Vector2& vec ) const
+ {
+ return Vector2(
+ ( x + vec.x ) * 0.5,
+ ( y + vec.y ) * 0.5 );
+ }
+
+ /** Returns true if the vector's scalar components are all greater
+ that the ones of the vector it is compared against.
+ */
+ inline bool operator < ( const Vector2& rhs ) const
+ {
+ if( x < rhs.x && y < rhs.y )
+ return true;
+ return false;
+ }
+
+ /** Returns true if the vector's scalar components are all smaller
+ that the ones of the vector it is compared against.
+ */
+ inline bool operator > ( const Vector2& rhs ) const
+ {
+ if( x > rhs.x && y > rhs.y )
+ return true;
+ return false;
+ }
+
+ /** Sets this vector's components to the minimum of its own and the
+ ones of the passed in vector.
+ @remarks
+ 'Minimum' in this case means the combination of the lowest
+ value of x, y and z from both vectors. Lowest is taken just
+ numerically, not magnitude, so -1 < 0.
+ */
+ inline void makeFloor( const Vector2& cmp )
+ {
+ if( cmp.x < x ) x = cmp.x;
+ if( cmp.y < y ) y = cmp.y;
+ }
+
+ /** Sets this vector's components to the maximum of its own and the
+ ones of the passed in vector.
+ @remarks
+ 'Maximum' in this case means the combination of the highest
+ value of x, y and z from both vectors. Highest is taken just
+ numerically, not magnitude, so 1 > -3.
+ */
+ inline void makeCeil( const Vector2& cmp )
+ {
+ if( cmp.x > x ) x = cmp.x;
+ if( cmp.y > y ) y = cmp.y;
+ }
+
+ /** Generates a vector perpendicular to this vector (eg an 'up' vector).
+ @remarks
+ This method will return a vector which is perpendicular to this
+ vector. There are an infinite number of possibilities but this
+ method will guarantee to generate one of them. If you need more
+ control you should use the Quaternion class.
+ */
+ inline Vector2 perpendicular(void) const
+ {
+ return Vector2 (-y, x);
+ }
+ /** Calculates the 2 dimensional cross-product of 2 vectors, which results
+ in a single floating point value which is 2 times the area of the triangle.
+ */
+ inline Real crossProduct( const Vector2& rkVector ) const
+ {
+ return x * rkVector.y - y * rkVector.x;
+ }
+ /** Generates a new random vector which deviates from this vector by a
+ given angle in a random direction.
+ @remarks
+ This method assumes that the random number generator has already
+ been seeded appropriately.
+ @param
+ angle The angle at which to deviate in radians
+ @param
+ up Any vector perpendicular to this one (which could generated
+ by cross-product of this vector and any other non-colinear
+ vector). If you choose not to provide this the function will
+ derive one on it's own, however if you provide one yourself the
+ function will be faster (this allows you to reuse up vectors if
+ you call this method more than once)
+ @returns
+ A random vector which deviates from this vector by angle. This
+ vector will not be normalised, normalise it if you wish
+ afterwards.
+ */
+ inline Vector2 randomDeviant(
+ Real angle) const
+ {
+
+ angle *= Math::UnitRandom() * Math::TWO_PI;
+ Real cosa = cos(angle);
+ Real sina = sin(angle);
+ return Vector2(cosa * x - sina * y,
+ sina * x + cosa * y);
+ }
+
+ /** Returns true if this vector is zero length. */
+ inline bool isZeroLength(void) const
+ {
+ Real sqlen = (x * x) + (y * y);
+ return (sqlen < (1e-06 * 1e-06));
+
+ }
+
+ /** As normalise, except that this vector is unaffected and the
+ normalised vector is returned as a copy. */
+ inline Vector2 normalisedCopy(void) const
+ {
+ Vector2 ret = *this;
+ ret.normalise();
+ return ret;
+ }
+
+ /** Calculates a reflection vector to the plane with the given normal .
+ @remarks NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
+ */
+ inline Vector2 reflect(const Vector2& normal) const
+ {
+ return Vector2( *this - ( 2 * this->dotProduct(normal) * normal ) );
+ }
+
+ // special points
+ static const Vector2 ZERO;
+ static const Vector2 UNIT_X;
+ static const Vector2 UNIT_Y;
+ static const Vector2 NEGATIVE_UNIT_X;
+ static const Vector2 NEGATIVE_UNIT_Y;
+ static const Vector2 UNIT_SCALE;
+
+ /** Function for writing to a stream.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const Vector2& v )
+ {
+ o << "Vector2(" << v.x << ", " << v.y << ")";
+ return o;
+ }
+
+ };
+
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreVector2.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector3.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector3.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector3.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,43 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreVector3.h"
+#include "OgreMath.h"
+
+namespace Ogre
+{
+ const Vector3 Vector3::ZERO( 0, 0, 0 );
+
+ const Vector3 Vector3::UNIT_X( 1, 0, 0 );
+ const Vector3 Vector3::UNIT_Y( 0, 1, 0 );
+ const Vector3 Vector3::UNIT_Z( 0, 0, 1 );
+ const Vector3 Vector3::NEGATIVE_UNIT_X( -1, 0, 0 );
+ const Vector3 Vector3::NEGATIVE_UNIT_Y( 0, -1, 0 );
+ const Vector3 Vector3::NEGATIVE_UNIT_Z( 0, 0, -1 );
+ const Vector3 Vector3::UNIT_SCALE(1, 1, 1);
+}
Property changes on: sandbox_light/src/external/ogremath/OgreVector3.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector3.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector3.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector3.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,775 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Vector3_H__
+#define __Vector3_H__
+
+#include "OgrePrerequisites.h"
+#include "OgreMath.h"
+#include "OgreQuaternion.h"
+#include <ostream>
+
+namespace Ogre
+{
+
+ /** Standard 3-dimensional vector.
+ @remarks
+ A direction in 3D space represented as distances along the 3
+ orthogonal axes (x, y, z). Note that positions, directions and
+ scaling factors can be represented by a vector, depending on how
+ you interpret the values.
+ */
+ class _OgreExport Vector3
+ {
+ public:
+ Real x, y, z;
+
+ public:
+ inline Vector3()
+ {
+ }
+
+ inline Vector3( const Real fX, const Real fY, const Real fZ )
+ : x( fX ), y( fY ), z( fZ )
+ {
+ }
+
+ inline explicit Vector3( const Real afCoordinate[3] )
+ : x( afCoordinate[0] ),
+ y( afCoordinate[1] ),
+ z( afCoordinate[2] )
+ {
+ }
+
+ inline explicit Vector3( const int afCoordinate[3] )
+ {
+ x = (Real)afCoordinate[0];
+ y = (Real)afCoordinate[1];
+ z = (Real)afCoordinate[2];
+ }
+
+ inline explicit Vector3( Real* const r )
+ : x( r[0] ), y( r[1] ), z( r[2] )
+ {
+ }
+
+ inline explicit Vector3( const Real scaler )
+ : x( scaler )
+ , y( scaler )
+ , z( scaler )
+ {
+ }
+
+
+ inline Real operator [] ( const size_t i ) const
+ {
+ assert( i < 3 );
+
+ return *(&x+i);
+ }
+
+ inline Real& operator [] ( const size_t i )
+ {
+ assert( i < 3 );
+
+ return *(&x+i);
+ }
+ /// Pointer accessor for direct copying
+ inline Real* ptr()
+ {
+ return &x;
+ }
+ /// Pointer accessor for direct copying
+ inline const Real* ptr() const
+ {
+ return &x;
+ }
+
+ /** Assigns the value of the other vector.
+ @param
+ rkVector The other vector
+ */
+ inline Vector3& operator = ( const Vector3& rkVector )
+ {
+ x = rkVector.x;
+ y = rkVector.y;
+ z = rkVector.z;
+
+ return *this;
+ }
+
+ inline Vector3& operator = ( const Real fScaler )
+ {
+ x = fScaler;
+ y = fScaler;
+ z = fScaler;
+
+ return *this;
+ }
+
+ inline bool operator == ( const Vector3& rkVector ) const
+ {
+ return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
+ }
+
+ inline bool operator != ( const Vector3& rkVector ) const
+ {
+ return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
+ }
+
+ // arithmetic operations
+ inline Vector3 operator + ( const Vector3& rkVector ) const
+ {
+ return Vector3(
+ x + rkVector.x,
+ y + rkVector.y,
+ z + rkVector.z);
+ }
+
+ inline Vector3 operator - ( const Vector3& rkVector ) const
+ {
+ return Vector3(
+ x - rkVector.x,
+ y - rkVector.y,
+ z - rkVector.z);
+ }
+
+ inline Vector3 operator * ( const Real fScalar ) const
+ {
+ return Vector3(
+ x * fScalar,
+ y * fScalar,
+ z * fScalar);
+ }
+
+ inline Vector3 operator * ( const Vector3& rhs) const
+ {
+ return Vector3(
+ x * rhs.x,
+ y * rhs.y,
+ z * rhs.z);
+ }
+
+ inline Vector3 operator / ( const Real fScalar ) const
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ return Vector3(
+ x * fInv,
+ y * fInv,
+ z * fInv);
+ }
+
+ inline Vector3 operator / ( const Vector3& rhs) const
+ {
+ return Vector3(
+ x / rhs.x,
+ y / rhs.y,
+ z / rhs.z);
+ }
+
+ inline const Vector3& operator + () const
+ {
+ return *this;
+ }
+
+ inline Vector3 operator - () const
+ {
+ return Vector3(-x, -y, -z);
+ }
+
+ // overloaded operators to help Vector3
+ inline friend Vector3 operator * ( const Real fScalar, const Vector3& rkVector )
+ {
+ return Vector3(
+ fScalar * rkVector.x,
+ fScalar * rkVector.y,
+ fScalar * rkVector.z);
+ }
+
+ inline friend Vector3 operator / ( const Real fScalar, const Vector3& rkVector )
+ {
+ return Vector3(
+ fScalar / rkVector.x,
+ fScalar / rkVector.y,
+ fScalar / rkVector.z);
+ }
+
+ inline friend Vector3 operator + (const Vector3& lhs, const Real rhs)
+ {
+ return Vector3(
+ lhs.x + rhs,
+ lhs.y + rhs,
+ lhs.z + rhs);
+ }
+
+ inline friend Vector3 operator + (const Real lhs, const Vector3& rhs)
+ {
+ return Vector3(
+ lhs + rhs.x,
+ lhs + rhs.y,
+ lhs + rhs.z);
+ }
+
+ inline friend Vector3 operator - (const Vector3& lhs, const Real rhs)
+ {
+ return Vector3(
+ lhs.x - rhs,
+ lhs.y - rhs,
+ lhs.z - rhs);
+ }
+
+ inline friend Vector3 operator - (const Real lhs, const Vector3& rhs)
+ {
+ return Vector3(
+ lhs - rhs.x,
+ lhs - rhs.y,
+ lhs - rhs.z);
+ }
+
+ // arithmetic updates
+ inline Vector3& operator += ( const Vector3& rkVector )
+ {
+ x += rkVector.x;
+ y += rkVector.y;
+ z += rkVector.z;
+
+ return *this;
+ }
+
+ inline Vector3& operator += ( const Real fScalar )
+ {
+ x += fScalar;
+ y += fScalar;
+ z += fScalar;
+ return *this;
+ }
+
+ inline Vector3& operator -= ( const Vector3& rkVector )
+ {
+ x -= rkVector.x;
+ y -= rkVector.y;
+ z -= rkVector.z;
+
+ return *this;
+ }
+
+ inline Vector3& operator -= ( const Real fScalar )
+ {
+ x -= fScalar;
+ y -= fScalar;
+ z -= fScalar;
+ return *this;
+ }
+
+ inline Vector3& operator *= ( const Real fScalar )
+ {
+ x *= fScalar;
+ y *= fScalar;
+ z *= fScalar;
+ return *this;
+ }
+
+ inline Vector3& operator *= ( const Vector3& rkVector )
+ {
+ x *= rkVector.x;
+ y *= rkVector.y;
+ z *= rkVector.z;
+
+ return *this;
+ }
+
+ inline Vector3& operator /= ( const Real fScalar )
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ x *= fInv;
+ y *= fInv;
+ z *= fInv;
+
+ return *this;
+ }
+
+ inline Vector3& operator /= ( const Vector3& rkVector )
+ {
+ x /= rkVector.x;
+ y /= rkVector.y;
+ z /= rkVector.z;
+
+ return *this;
+ }
+
+
+ /** Returns the length (magnitude) of the vector.
+ @warning
+ This operation requires a square root and is expensive in
+ terms of CPU operations. If you don't need to know the exact
+ length (e.g. for just comparing lengths) use squaredLength()
+ instead.
+ */
+ inline Real length () const
+ {
+ return Math::Sqrt( x * x + y * y + z * z );
+ }
+
+ /** Returns the square of the length(magnitude) of the vector.
+ @remarks
+ This method is for efficiency - calculating the actual
+ length of a vector requires a square root, which is expensive
+ in terms of the operations required. This method returns the
+ square of the length of the vector, i.e. the same as the
+ length but before the square root is taken. Use this if you
+ want to find the longest / shortest vector without incurring
+ the square root.
+ */
+ inline Real squaredLength () const
+ {
+ return x * x + y * y + z * z;
+ }
+
+ /** Returns the distance to another vector.
+ @warning
+ This operation requires a square root and is expensive in
+ terms of CPU operations. If you don't need to know the exact
+ distance (e.g. for just comparing distances) use squaredDistance()
+ instead.
+ */
+ inline Real distance(const Vector3& rhs) const
+ {
+ return (*this - rhs).length();
+ }
+
+ /** Returns the square of the distance to another vector.
+ @remarks
+ This method is for efficiency - calculating the actual
+ distance to another vector requires a square root, which is
+ expensive in terms of the operations required. This method
+ returns the square of the distance to another vector, i.e.
+ the same as the distance but before the square root is taken.
+ Use this if you want to find the longest / shortest distance
+ without incurring the square root.
+ */
+ inline Real squaredDistance(const Vector3& rhs) const
+ {
+ return (*this - rhs).squaredLength();
+ }
+
+ /** Calculates the dot (scalar) product of this vector with another.
+ @remarks
+ The dot product can be used to calculate the angle between 2
+ vectors. If both are unit vectors, the dot product is the
+ cosine of the angle; otherwise the dot product must be
+ divided by the product of the lengths of both vectors to get
+ the cosine of the angle. This result can further be used to
+ calculate the distance of a point from a plane.
+ @param
+ vec Vector with which to calculate the dot product (together
+ with this one).
+ @returns
+ A float representing the dot product value.
+ */
+ inline Real dotProduct(const Vector3& vec) const
+ {
+ return x * vec.x + y * vec.y + z * vec.z;
+ }
+
+ /** Calculates the absolute dot (scalar) product of this vector with another.
+ @remarks
+ This function work similar dotProduct, except it use absolute value
+ of each component of the vector to computing.
+ @param
+ vec Vector with which to calculate the absolute dot product (together
+ with this one).
+ @returns
+ A Real representing the absolute dot product value.
+ */
+ inline Real absDotProduct(const Vector3& vec) const
+ {
+ return Math::Abs(x * vec.x) + Math::Abs(y * vec.y) + Math::Abs(z * vec.z);
+ }
+
+ /** Normalises the vector.
+ @remarks
+ This method normalises the vector such that it's
+ length / magnitude is 1. The result is called a unit vector.
+ @note
+ This function will not crash for zero-sized vectors, but there
+ will be no changes made to their components.
+ @returns The previous length of the vector.
+ */
+ inline Real normalise()
+ {
+ Real fLength = Math::Sqrt( x * x + y * y + z * z );
+
+ // Will also work for zero-sized vectors, but will change nothing
+ if ( fLength > 1e-08 )
+ {
+ Real fInvLength = 1.0 / fLength;
+ x *= fInvLength;
+ y *= fInvLength;
+ z *= fInvLength;
+ }
+
+ return fLength;
+ }
+
+ /** Calculates the cross-product of 2 vectors, i.e. the vector that
+ lies perpendicular to them both.
+ @remarks
+ The cross-product is normally used to calculate the normal
+ vector of a plane, by calculating the cross-product of 2
+ non-equivalent vectors which lie on the plane (e.g. 2 edges
+ of a triangle).
+ @param
+ vec Vector which, together with this one, will be used to
+ calculate the cross-product.
+ @returns
+ A vector which is the result of the cross-product. This
+ vector will <b>NOT</b> be normalised, to maximise efficiency
+ - call Vector3::normalise on the result if you wish this to
+ be done. As for which side the resultant vector will be on, the
+ returned vector will be on the side from which the arc from 'this'
+ to rkVector is anticlockwise, e.g. UNIT_Y.crossProduct(UNIT_Z)
+ = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X.
+ This is because OGRE uses a right-handed coordinate system.
+ @par
+ For a clearer explanation, look a the left and the bottom edges
+ of your monitor's screen. Assume that the first vector is the
+ left edge and the second vector is the bottom edge, both of
+ them starting from the lower-left corner of the screen. The
+ resulting vector is going to be perpendicular to both of them
+ and will go <i>inside</i> the screen, towards the cathode tube
+ (assuming you're using a CRT monitor, of course).
+ */
+ inline Vector3 crossProduct( const Vector3& rkVector ) const
+ {
+ return Vector3(
+ y * rkVector.z - z * rkVector.y,
+ z * rkVector.x - x * rkVector.z,
+ x * rkVector.y - y * rkVector.x);
+ }
+
+ /** Returns a vector at a point half way between this and the passed
+ in vector.
+ */
+ inline Vector3 midPoint( const Vector3& vec ) const
+ {
+ return Vector3(
+ ( x + vec.x ) * 0.5,
+ ( y + vec.y ) * 0.5,
+ ( z + vec.z ) * 0.5 );
+ }
+
+ /** Returns true if the vector's scalar components are all greater
+ that the ones of the vector it is compared against.
+ */
+ inline bool operator < ( const Vector3& rhs ) const
+ {
+ if( x < rhs.x && y < rhs.y && z < rhs.z )
+ return true;
+ return false;
+ }
+
+ /** Returns true if the vector's scalar components are all smaller
+ that the ones of the vector it is compared against.
+ */
+ inline bool operator > ( const Vector3& rhs ) const
+ {
+ if( x > rhs.x && y > rhs.y && z > rhs.z )
+ return true;
+ return false;
+ }
+
+ /** Sets this vector's components to the minimum of its own and the
+ ones of the passed in vector.
+ @remarks
+ 'Minimum' in this case means the combination of the lowest
+ value of x, y and z from both vectors. Lowest is taken just
+ numerically, not magnitude, so -1 < 0.
+ */
+ inline void makeFloor( const Vector3& cmp )
+ {
+ if( cmp.x < x ) x = cmp.x;
+ if( cmp.y < y ) y = cmp.y;
+ if( cmp.z < z ) z = cmp.z;
+ }
+
+ /** Sets this vector's components to the maximum of its own and the
+ ones of the passed in vector.
+ @remarks
+ 'Maximum' in this case means the combination of the highest
+ value of x, y and z from both vectors. Highest is taken just
+ numerically, not magnitude, so 1 > -3.
+ */
+ inline void makeCeil( const Vector3& cmp )
+ {
+ if( cmp.x > x ) x = cmp.x;
+ if( cmp.y > y ) y = cmp.y;
+ if( cmp.z > z ) z = cmp.z;
+ }
+
+ /** Generates a vector perpendicular to this vector (eg an 'up' vector).
+ @remarks
+ This method will return a vector which is perpendicular to this
+ vector. There are an infinite number of possibilities but this
+ method will guarantee to generate one of them. If you need more
+ control you should use the Quaternion class.
+ */
+ inline Vector3 perpendicular(void) const
+ {
+ static const Real fSquareZero = 1e-06 * 1e-06;
+
+ Vector3 perp = this->crossProduct( Vector3::UNIT_X );
+
+ // Check length
+ if( perp.squaredLength() < fSquareZero )
+ {
+ /* This vector is the Y axis multiplied by a scalar, so we have
+ to use another axis.
+ */
+ perp = this->crossProduct( Vector3::UNIT_Y );
+ }
+ perp.normalise();
+
+ return perp;
+ }
+ /** Generates a new random vector which deviates from this vector by a
+ given angle in a random direction.
+ @remarks
+ This method assumes that the random number generator has already
+ been seeded appropriately.
+ @param
+ angle The angle at which to deviate
+ @param
+ up Any vector perpendicular to this one (which could generated
+ by cross-product of this vector and any other non-colinear
+ vector). If you choose not to provide this the function will
+ derive one on it's own, however if you provide one yourself the
+ function will be faster (this allows you to reuse up vectors if
+ you call this method more than once)
+ @returns
+ A random vector which deviates from this vector by angle. This
+ vector will not be normalised, normalise it if you wish
+ afterwards.
+ */
+ inline Vector3 randomDeviant(
+ const Radian& angle,
+ const Vector3& up = Vector3::ZERO ) const
+ {
+ Vector3 newUp;
+
+ if (up == Vector3::ZERO)
+ {
+ // Generate an up vector
+ newUp = this->perpendicular();
+ }
+ else
+ {
+ newUp = up;
+ }
+
+ // Rotate up vector by random amount around this
+ Quaternion q;
+ q.FromAngleAxis( Radian(Math::UnitRandom() * Math::TWO_PI), *this );
+ newUp = q * newUp;
+
+ // Finally rotate this by given angle around randomised up
+ q.FromAngleAxis( angle, newUp );
+ return q * (*this);
+ }
+
+ /** Gets the angle between 2 vectors.
+ @remarks
+ Vectors do not have to be unit-length but must represent directions.
+ */
+ inline Radian angleBetween(const Vector3& dest)
+ {
+ Real lenProduct = length() * dest.length();
+
+ // Divide by zero check
+ if(lenProduct < 1e-6f)
+ lenProduct = 1e-6f;
+
+ Real f = dotProduct(dest) / lenProduct;
+
+ f = Math::Clamp(f, (Real)-1.0, (Real)1.0);
+ return Math::ACos(f);
+
+ }
+ /** Gets the shortest arc quaternion to rotate this vector to the destination
+ vector.
+ @remarks
+ If you call this with a dest vector that is close to the inverse
+ of this vector, we will rotate 180 degrees around the 'fallbackAxis'
+ (if specified, or a generated axis if not) since in this case
+ ANY axis of rotation is valid.
+ */
+ Quaternion getRotationTo(const Vector3& dest,
+ const Vector3& fallbackAxis = Vector3::ZERO) const
+ {
+ // Based on Stan Melax's article in Game Programming Gems
+ Quaternion q;
+ // Copy, since cannot modify local
+ Vector3 v0 = *this;
+ Vector3 v1 = dest;
+ v0.normalise();
+ v1.normalise();
+
+ Real d = v0.dotProduct(v1);
+ // If dot == 1, vectors are the same
+ if (d >= 1.0f)
+ {
+ return Quaternion::IDENTITY;
+ }
+ if (d < (1e-6f - 1.0f))
+ {
+ if (fallbackAxis != Vector3::ZERO)
+ {
+ // rotate 180 degrees about the fallback axis
+ q.FromAngleAxis(Radian(Math::PI), fallbackAxis);
+ }
+ else
+ {
+ // Generate an axis
+ Vector3 axis = Vector3::UNIT_X.crossProduct(*this);
+ if (axis.isZeroLength()) // pick another if colinear
+ axis = Vector3::UNIT_Y.crossProduct(*this);
+ axis.normalise();
+ q.FromAngleAxis(Radian(Math::PI), axis);
+ }
+ }
+ else
+ {
+ Real s = Math::Sqrt( (1+d)*2 );
+ Real invs = 1 / s;
+
+ Vector3 c = v0.crossProduct(v1);
+
+ q.x = c.x * invs;
+ q.y = c.y * invs;
+ q.z = c.z * invs;
+ q.w = s * 0.5;
+ q.normalise();
+ }
+ return q;
+ }
+
+ /** Returns true if this vector is zero length. */
+ inline bool isZeroLength(void) const
+ {
+ Real sqlen = (x * x) + (y * y) + (z * z);
+ return (sqlen < (1e-06 * 1e-06));
+
+ }
+
+ /** As normalise, except that this vector is unaffected and the
+ normalised vector is returned as a copy. */
+ inline Vector3 normalisedCopy(void) const
+ {
+ Vector3 ret = *this;
+ ret.normalise();
+ return ret;
+ }
+
+ /** Calculates a reflection vector to the plane with the given normal .
+ @remarks NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.
+ */
+ inline Vector3 reflect(const Vector3& normal) const
+ {
+ return Vector3( *this - ( 2 * this->dotProduct(normal) * normal ) );
+ }
+
+ /** Returns whether this vector is within a positional tolerance
+ of another vector.
+ @param rhs The vector to compare with
+ @param tolerance The amount that each element of the vector may vary by
+ and still be considered equal
+ */
+ inline bool positionEquals(const Vector3& rhs, Real tolerance = 1e-03) const
+ {
+ return Math::RealEqual(x, rhs.x, tolerance) &&
+ Math::RealEqual(y, rhs.y, tolerance) &&
+ Math::RealEqual(z, rhs.z, tolerance);
+
+ }
+
+ /** Returns whether this vector is within a positional tolerance
+ of another vector, also take scale of the vectors into account.
+ @param rhs The vector to compare with
+ @param tolerance The amount (related to the scale of vectors) that distance
+ of the vector may vary by and still be considered close
+ */
+ inline bool positionCloses(const Vector3& rhs, Real tolerance = 1e-03f) const
+ {
+ return squaredDistance(rhs) <=
+ (squaredLength() + rhs.squaredLength()) * tolerance;
+ }
+
+ /** Returns whether this vector is within a directional tolerance
+ of another vector.
+ @param rhs The vector to compare with
+ @param tolerance The maximum angle by which the vectors may vary and
+ still be considered equal
+ @note Both vectors should be normalised.
+ */
+ inline bool directionEquals(const Vector3& rhs,
+ const Radian& tolerance) const
+ {
+ Real dot = dotProduct(rhs);
+ Radian angle = Math::ACos(dot);
+
+ return Math::Abs(angle.valueRadians()) <= tolerance.valueRadians();
+
+ }
+
+ // special points
+ static const Vector3 ZERO;
+ static const Vector3 UNIT_X;
+ static const Vector3 UNIT_Y;
+ static const Vector3 UNIT_Z;
+ static const Vector3 NEGATIVE_UNIT_X;
+ static const Vector3 NEGATIVE_UNIT_Y;
+ static const Vector3 NEGATIVE_UNIT_Z;
+ static const Vector3 UNIT_SCALE;
+
+ /** Function for writing to a stream.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const Vector3& v )
+ {
+ o << "Vector3(" << v.x << ", " << v.y << ", " << v.z << ")";
+ return o;
+ }
+ };
+
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreVector3.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector4.cpp
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector4.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector4.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,35 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "OgreVector4.h"
+#include "OgreMath.h"
+
+namespace Ogre
+{
+ const Vector4 Vector4::ZERO( 0, 0, 0, 0 );
+}
Property changes on: sandbox_light/src/external/ogremath/OgreVector4.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/OgreVector4.h
===================================================================
--- sandbox_light/src/external/ogremath/OgreVector4.h (rev 0)
+++ sandbox_light/src/external/ogremath/OgreVector4.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,392 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Vector4_H__
+#define __Vector4_H__
+
+#include "OgrePrerequisites.h"
+#include "OgreVector3.h"
+#include <ostream>
+
+namespace Ogre
+{
+
+ /** 4-dimensional homogeneous vector.
+ */
+ class _OgreExport Vector4
+ {
+ public:
+ Real x, y, z, w;
+
+ public:
+ inline Vector4()
+ {
+ }
+
+ inline Vector4( const Real fX, const Real fY, const Real fZ, const Real fW )
+ : x( fX ), y( fY ), z( fZ ), w( fW)
+ {
+ }
+
+ inline explicit Vector4( const Real afCoordinate[4] )
+ : x( afCoordinate[0] ),
+ y( afCoordinate[1] ),
+ z( afCoordinate[2] ),
+ w( afCoordinate[3] )
+ {
+ }
+
+ inline explicit Vector4( const int afCoordinate[4] )
+ {
+ x = (Real)afCoordinate[0];
+ y = (Real)afCoordinate[1];
+ z = (Real)afCoordinate[2];
+ w = (Real)afCoordinate[3];
+ }
+
+ inline explicit Vector4( Real* const r )
+ : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] )
+ {
+ }
+
+ inline explicit Vector4( const Real scaler )
+ : x( scaler )
+ , y( scaler )
+ , z( scaler )
+ , w( scaler )
+ {
+ }
+
+ inline explicit Vector4(const Vector3& rhs)
+ : x(rhs.x), y(rhs.y), z(rhs.z), w(1.0f)
+ {
+ }
+
+ inline Real operator [] ( const size_t i ) const
+ {
+ assert( i < 4 );
+
+ return *(&x+i);
+ }
+
+ inline Real& operator [] ( const size_t i )
+ {
+ assert( i < 4 );
+
+ return *(&x+i);
+ }
+
+ /// Pointer accessor for direct copying
+ inline Real* ptr()
+ {
+ return &x;
+ }
+ /// Pointer accessor for direct copying
+ inline const Real* ptr() const
+ {
+ return &x;
+ }
+
+ /** Assigns the value of the other vector.
+ @param
+ rkVector The other vector
+ */
+ inline Vector4& operator = ( const Vector4& rkVector )
+ {
+ x = rkVector.x;
+ y = rkVector.y;
+ z = rkVector.z;
+ w = rkVector.w;
+
+ return *this;
+ }
+
+ inline Vector4& operator = ( const Real fScalar)
+ {
+ x = fScalar;
+ y = fScalar;
+ z = fScalar;
+ w = fScalar;
+ return *this;
+ }
+
+ inline bool operator == ( const Vector4& rkVector ) const
+ {
+ return ( x == rkVector.x &&
+ y == rkVector.y &&
+ z == rkVector.z &&
+ w == rkVector.w );
+ }
+
+ inline bool operator != ( const Vector4& rkVector ) const
+ {
+ return ( x != rkVector.x ||
+ y != rkVector.y ||
+ z != rkVector.z ||
+ w != rkVector.w );
+ }
+
+ inline Vector4& operator = (const Vector3& rhs)
+ {
+ x = rhs.x;
+ y = rhs.y;
+ z = rhs.z;
+ w = 1.0f;
+ return *this;
+ }
+
+ // arithmetic operations
+ inline Vector4 operator + ( const Vector4& rkVector ) const
+ {
+ return Vector4(
+ x + rkVector.x,
+ y + rkVector.y,
+ z + rkVector.z,
+ w + rkVector.w);
+ }
+
+ inline Vector4 operator - ( const Vector4& rkVector ) const
+ {
+ return Vector4(
+ x - rkVector.x,
+ y - rkVector.y,
+ z - rkVector.z,
+ w - rkVector.w);
+ }
+
+ inline Vector4 operator * ( const Real fScalar ) const
+ {
+ return Vector4(
+ x * fScalar,
+ y * fScalar,
+ z * fScalar,
+ w * fScalar);
+ }
+
+ inline Vector4 operator * ( const Vector4& rhs) const
+ {
+ return Vector4(
+ rhs.x * x,
+ rhs.y * y,
+ rhs.z * z,
+ rhs.w * w);
+ }
+
+ inline Vector4 operator / ( const Real fScalar ) const
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ return Vector4(
+ x * fInv,
+ y * fInv,
+ z * fInv,
+ w * fInv);
+ }
+
+ inline Vector4 operator / ( const Vector4& rhs) const
+ {
+ return Vector4(
+ x / rhs.x,
+ y / rhs.y,
+ z / rhs.z,
+ w / rhs.w);
+ }
+
+ inline const Vector4& operator + () const
+ {
+ return *this;
+ }
+
+ inline Vector4 operator - () const
+ {
+ return Vector4(-x, -y, -z, -w);
+ }
+
+ inline friend Vector4 operator * ( const Real fScalar, const Vector4& rkVector )
+ {
+ return Vector4(
+ fScalar * rkVector.x,
+ fScalar * rkVector.y,
+ fScalar * rkVector.z,
+ fScalar * rkVector.w);
+ }
+
+ inline friend Vector4 operator / ( const Real fScalar, const Vector4& rkVector )
+ {
+ return Vector4(
+ fScalar / rkVector.x,
+ fScalar / rkVector.y,
+ fScalar / rkVector.z,
+ fScalar / rkVector.w);
+ }
+
+ inline friend Vector4 operator + (const Vector4& lhs, const Real rhs)
+ {
+ return Vector4(
+ lhs.x + rhs,
+ lhs.y + rhs,
+ lhs.z + rhs,
+ lhs.w + rhs);
+ }
+
+ inline friend Vector4 operator + (const Real lhs, const Vector4& rhs)
+ {
+ return Vector4(
+ lhs + rhs.x,
+ lhs + rhs.y,
+ lhs + rhs.z,
+ lhs + rhs.w);
+ }
+
+ inline friend Vector4 operator - (const Vector4& lhs, Real rhs)
+ {
+ return Vector4(
+ lhs.x - rhs,
+ lhs.y - rhs,
+ lhs.z - rhs,
+ lhs.w - rhs);
+ }
+
+ inline friend Vector4 operator - (const Real lhs, const Vector4& rhs)
+ {
+ return Vector4(
+ lhs - rhs.x,
+ lhs - rhs.y,
+ lhs - rhs.z,
+ lhs - rhs.w);
+ }
+
+ // arithmetic updates
+ inline Vector4& operator += ( const Vector4& rkVector )
+ {
+ x += rkVector.x;
+ y += rkVector.y;
+ z += rkVector.z;
+ w += rkVector.w;
+
+ return *this;
+ }
+
+ inline Vector4& operator -= ( const Vector4& rkVector )
+ {
+ x -= rkVector.x;
+ y -= rkVector.y;
+ z -= rkVector.z;
+ w -= rkVector.w;
+
+ return *this;
+ }
+
+ inline Vector4& operator *= ( const Real fScalar )
+ {
+ x *= fScalar;
+ y *= fScalar;
+ z *= fScalar;
+ w *= fScalar;
+ return *this;
+ }
+
+ inline Vector4& operator += ( const Real fScalar )
+ {
+ x += fScalar;
+ y += fScalar;
+ z += fScalar;
+ w += fScalar;
+ return *this;
+ }
+
+ inline Vector4& operator -= ( const Real fScalar )
+ {
+ x -= fScalar;
+ y -= fScalar;
+ z -= fScalar;
+ w -= fScalar;
+ return *this;
+ }
+
+ inline Vector4& operator *= ( const Vector4& rkVector )
+ {
+ x *= rkVector.x;
+ y *= rkVector.y;
+ z *= rkVector.z;
+ w *= rkVector.w;
+
+ return *this;
+ }
+
+ inline Vector4& operator /= ( const Real fScalar )
+ {
+ assert( fScalar != 0.0 );
+
+ Real fInv = 1.0 / fScalar;
+
+ x *= fInv;
+ y *= fInv;
+ z *= fInv;
+ w *= fInv;
+
+ return *this;
+ }
+
+ inline Vector4& operator /= ( const Vector4& rkVector )
+ {
+ x /= rkVector.x;
+ y /= rkVector.y;
+ z /= rkVector.z;
+ w /= rkVector.w;
+
+ return *this;
+ }
+
+ /** Calculates the dot (scalar) product of this vector with another.
+ @param
+ vec Vector with which to calculate the dot product (together
+ with this one).
+ @returns
+ A float representing the dot product value.
+ */
+ inline Real dotProduct(const Vector4& vec) const
+ {
+ return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
+ }
+ /** Function for writing to a stream.
+ */
+ inline _OgreExport friend std::ostream& operator <<
+ ( std::ostream& o, const Vector4& v )
+ {
+ o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
+ return o;
+ }
+ // special
+ static const Vector4 ZERO;
+ };
+
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/OgreVector4.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/WIN32/OgreTimer.cpp
===================================================================
--- sandbox_light/src/external/ogremath/WIN32/OgreTimer.cpp (rev 0)
+++ sandbox_light/src/external/ogremath/WIN32/OgreTimer.cpp 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,220 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#include "ogremath/OgreTimer.h"
+
+#include "ogremath/OgreBitwise.h"
+
+using namespace Ogre;
+
+//-------------------------------------------------------------------------
+Timer::Timer()
+ : mTimerMask( 0 )
+{
+ reset();
+}
+
+//-------------------------------------------------------------------------
+Timer::~Timer()
+{
+}
+
+//-------------------------------------------------------------------------
+bool Timer::setOption( const String & key, const void * val )
+{
+ if ( key == "QueryAffinityMask" )
+ {
+ // Telling timer what core to use for a timer read
+ DWORD newTimerMask = * static_cast < const DWORD * > ( val );
+
+ // Get the current process core mask
+ DWORD procMask;
+ DWORD sysMask;
+#if _MSC_VER >= 1400 && defined (_M_X64)
+ GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
+#else
+ GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
+#endif
+
+ // If new mask is 0, then set to default behavior, otherwise check
+ // to make sure new timer core mask overlaps with process core mask
+ // and that new timer core mask is a power of 2 (i.e. a single core)
+ if( ( newTimerMask == 0 ) ||
+ ( ( ( newTimerMask & procMask ) != 0 ) && Bitwise::isPO2( newTimerMask ) ) )
+ {
+ mTimerMask = newTimerMask;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+//-------------------------------------------------------------------------
+void Timer::reset()
+{
+ // Get the current process core mask
+ DWORD procMask;
+ DWORD sysMask;
+#if _MSC_VER >= 1400 && defined (_M_X64)
+ GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
+#else
+ GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
+#endif
+
+ // If procMask is 0, consider there is only one core available
+ // (using 0 as procMask will cause an infinite loop below)
+ if (procMask == 0)
+ procMask = 1;
+
+ // Find the lowest core that this process uses
+ if( mTimerMask == 0 )
+ {
+ mTimerMask = 1;
+ while( ( mTimerMask & procMask ) == 0 )
+ {
+ mTimerMask <<= 1;
+ }
+ }
+
+ HANDLE thread = GetCurrentThread();
+
+ // Set affinity to the first core
+ DWORD oldMask = SetThreadAffinityMask(thread, mTimerMask);
+
+ // Get the constant frequency
+ QueryPerformanceFrequency(&mFrequency);
+
+ // Query the timer
+ QueryPerformanceCounter(&mStartTime);
+ mStartTick = GetTickCount();
+
+ // Reset affinity
+ SetThreadAffinityMask(thread, oldMask);
+
+ mLastTime = 0;
+ mZeroClock = clock();
+}
+
+//-------------------------------------------------------------------------
+unsigned long Timer::getMilliseconds()
+{
+ LARGE_INTEGER curTime;
+
+ HANDLE thread = GetCurrentThread();
+
+ // Set affinity to the first core
+ DWORD oldMask = SetThreadAffinityMask(thread, mTimerMask);
+
+ // Query the timer
+ QueryPerformanceCounter(&curTime);
+
+ // Reset affinity
+ SetThreadAffinityMask(thread, oldMask);
+
+ LONGLONG newTime = curTime.QuadPart - mStartTime.QuadPart;
+
+ // scale by 1000 for milliseconds
+ unsigned long newTicks = (unsigned long) (1000 * newTime / mFrequency.QuadPart);
+
+ // detect and compensate for performance counter leaps
+ // (surprisingly common, see Microsoft KB: Q274323)
+ unsigned long check = GetTickCount() - mStartTick;
+ signed long msecOff = (signed long)(newTicks - check);
+ if (msecOff < -100 || msecOff > 100)
+ {
+ // We must keep the timer running forward :)
+ LONGLONG adjust = (std::min)(msecOff * mFrequency.QuadPart / 1000, newTime - mLastTime);
+ mStartTime.QuadPart += adjust;
+ newTime -= adjust;
+
+ // Re-calculate milliseconds
+ newTicks = (unsigned long) (1000 * newTime / mFrequency.QuadPart);
+ }
+
+ // Record last time for adjust
+ mLastTime = newTime;
+
+ return newTicks;
+}
+
+//-------------------------------------------------------------------------
+unsigned long Timer::getMicroseconds()
+{
+ LARGE_INTEGER curTime;
+
+ HANDLE thread = GetCurrentThread();
+
+ // Set affinity to the first core
+ DWORD oldMask = SetThreadAffinityMask(thread, mTimerMask);
+
+ // Query the timer
+ QueryPerformanceCounter(&curTime);
+
+ // Reset affinity
+ SetThreadAffinityMask(thread, oldMask);
+
+ LONGLONG newTime = curTime.QuadPart - mStartTime.QuadPart;
+
+ // get milliseconds to check against GetTickCount
+ unsigned long newTicks = (unsigned long) (1000 * newTime / mFrequency.QuadPart);
+
+ // detect and compensate for performance counter leaps
+ // (surprisingly common, see Microsoft KB: Q274323)
+ unsigned long check = GetTickCount() - mStartTick;
+ signed long msecOff = (signed long)(newTicks - check);
+ if (msecOff < -100 || msecOff > 100)
+ {
+ // We must keep the timer running forward :)
+ LONGLONG adjust = (std::min)(msecOff * mFrequency.QuadPart / 1000, newTime - mLastTime);
+ mStartTime.QuadPart += adjust;
+ newTime -= adjust;
+ }
+
+ // Record last time for adjust
+ mLastTime = newTime;
+
+ // scale by 1000000 for microseconds
+ unsigned long newMicro = (unsigned long) (1000000 * newTime / mFrequency.QuadPart);
+
+ return newMicro;
+}
+
+//-------------------------------------------------------------------------
+unsigned long Timer::getMillisecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)( (float)( newClock - mZeroClock ) / ( (float)CLOCKS_PER_SEC / 1000.0 ) ) ;
+}
+
+//-------------------------------------------------------------------------
+unsigned long Timer::getMicrosecondsCPU()
+{
+ clock_t newClock = clock();
+ return (unsigned long)( (float)( newClock - mZeroClock ) / ( (float)CLOCKS_PER_SEC / 1000000.0 ) ) ;
+}
Property changes on: sandbox_light/src/external/ogremath/WIN32/OgreTimer.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/WIN32/OgreTimerImp.h
===================================================================
--- sandbox_light/src/external/ogremath/WIN32/OgreTimerImp.h (rev 0)
+++ sandbox_light/src/external/ogremath/WIN32/OgreTimerImp.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,103 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+ (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+#ifndef __Win32Timer_H__
+#define __Win32Timer_H__
+
+#include <ctime>
+
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+#include "windows.h"
+
+//Get around Windows hackery
+#ifdef max
+# undef max
+#endif
+#ifdef min
+# undef min
+#endif
+
+namespace Ogre
+{
+ class _OgreExport Timer
+ {
+ private:
+ clock_t mZeroClock;
+
+ DWORD mStartTick;
+ LONGLONG mLastTime;
+ LARGE_INTEGER mStartTime;
+ LARGE_INTEGER mFrequency;
+
+ DWORD mTimerMask;
+ public:
+ /** Timer constructor. MUST be called on same thread that calls getMilliseconds() */
+ Timer();
+ ~Timer();
+
+ /** Method for setting a specific option of the Timer. These options are usually
+ specific for a certain implementation of the Timer class, and may (and probably
+ will) not exist across different implementations. reset() must be called after
+ all setOption() calls.
+ @par
+ Current options supported are:
+ <ul><li>"QueryAffinityMask" (DWORD): Set the thread affinity mask to be used
+ to check the timer. If 'reset' has been called already this mask should
+ overlap with the process mask that was in force at that point, and should
+ be a power of two (a single core).</li></ul>
+ @param
+ strKey The name of the option to set
+ @param
+ pValue A pointer to the value - the size should be calculated by the timer
+ based on the key
+ @return
+ On success, true is returned.
+ @par
+ On failure, false is returned.
+ */
+ bool setOption( const String& strKey, const void* pValue );
+
+ /** Resets timer */
+ void reset();
+
+ /** Returns milliseconds since initialisation or last reset */
+ unsigned long getMilliseconds();
+
+ /** Returns microseconds since initialisation or last reset */
+ unsigned long getMicroseconds();
+
+ /** Returns milliseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMillisecondsCPU();
+
+ /** Returns microseconds since initialisation or last reset, only CPU time measured */
+ unsigned long getMicrosecondsCPU();
+ };
+}
+#endif
Property changes on: sandbox_light/src/external/ogremath/WIN32/OgreTimerImp.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: sandbox_light/src/external/ogremath/asm_math.h
===================================================================
--- sandbox_light/src/external/ogremath/asm_math.h (rev 0)
+++ sandbox_light/src/external/ogremath/asm_math.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -0,0 +1,367 @@
+#ifndef __asm_math_H__
+#define __asm_math_H__
+
+#include "OgrePrerequisites.h"
+
+namespace Ogre
+{
+
+/*=============================================================================
+ ASM math routines posted by davepermen et al on flipcode forums
+=============================================================================*/
+const float pi = 4.0 * atan( 1.0 );
+const float half_pi = 0.5 * pi;
+
+/*=============================================================================
+ NO EXPLICIT RETURN REQUIRED FROM THESE METHODS!!
+=============================================================================*/
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+# pragma warning( push )
+# pragma warning( disable: 4035 )
+#endif
+
+float asm_arccos( float r ) {
+ // return half_pi + arctan( r / -sqr( 1.f - r * r ) );
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ float asm_one = 1.f;
+ float asm_half_pi = half_pi;
+ __asm {
+ fld r // r0 = r
+ fld r // r1 = r0, r0 = r
+ fmul r // r0 = r0 * r
+ fsubr asm_one // r0 = r0 - 1.f
+ fsqrt // r0 = sqrtf( r0 )
+ fchs // r0 = - r0
+ fdiv // r0 = r1 / r0
+ fld1 // {{ r0 = atan( r0 )
+ fpatan // }}
+ fadd asm_half_pi // r0 = r0 + pi / 2
+ } // returns r0
+
+#else
+
+ return float( acos( r ) );
+
+#endif
+}
+
+float asm_arcsin( float r ) {
+ // return arctan( r / sqr( 1.f - r * r ) );
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ const float asm_one = 1.f;
+ __asm {
+ fld r // r0 = r
+ fld r // r1 = r0, r0 = r
+ fmul r // r0 = r0 * r
+ fsubr asm_one // r0 = r0 - 1.f
+ fsqrt // r0 = sqrtf( r0 )
+ fdiv // r0 = r1 / r0
+ fld1 // {{ r0 = atan( r0 )
+ fpatan // }}
+ } // returns r0
+
+#else
+
+ return float( asin( r ) );
+
+#endif
+
+}
+
+float asm_arctan( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ __asm {
+ fld r // r0 = r
+ fld1 // {{ r0 = atan( r0 )
+ fpatan // }}
+ } // returns r0
+
+#else
+
+ return float( atan( r ) );
+
+#endif
+
+}
+
+float asm_sin( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ __asm {
+ fld r // r0 = r
+ fsin // r0 = sinf( r0 )
+ } // returns r0
+
+#else
+
+ return sin( r );
+
+#endif
+
+}
+
+float asm_cos( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ __asm {
+ fld r // r0 = r
+ fcos // r0 = cosf( r0 )
+ } // returns r0
+
+#else
+
+ return cos( r );
+
+#endif
+}
+
+float asm_tan( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ // return sin( r ) / cos( r );
+ __asm {
+ fld r // r0 = r
+ fsin // r0 = sinf( r0 )
+ fld r // r1 = r0, r0 = r
+ fcos // r0 = cosf( r0 )
+ fdiv // r0 = r1 / r0
+ } // returns r0
+
+#else
+
+ return tan( r );
+
+#endif
+}
+
+// returns a for a * a = r
+float asm_sqrt( float r )
+{
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ __asm {
+ fld r // r0 = r
+ fsqrt // r0 = sqrtf( r0 )
+ } // returns r0
+
+#else
+
+ return sqrt( r );
+
+#endif
+}
+
+// returns 1 / a for a * a = r
+// -- Use this for Vector normalisation!!!
+float asm_rsq( float r )
+{
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ __asm {
+ fld1 // r0 = 1.f
+ fld r // r1 = r0, r0 = r
+ fsqrt // r0 = sqrtf( r0 )
+ fdiv // r0 = r1 / r0
+ } // returns r0
+
+#else
+
+ return 1. / sqrt( r );
+
+#endif
+}
+
+// returns 1 / a for a * a = r
+// Another version
+float apx_rsq( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ const float asm_dot5 = 0.5f;
+ const float asm_1dot5 = 1.5f;
+
+ __asm {
+ fld r // r0 = r
+ fmul asm_dot5 // r0 = r0 * .5f
+ mov eax, r // eax = r
+ shr eax, 0x1 // eax = eax >> 1
+ neg eax // eax = -eax
+ add eax, 0x5F400000 // eax = eax & MAGICAL NUMBER
+ mov r, eax // r = eax
+ fmul r // r0 = r0 * r
+ fmul r // r0 = r0 * r
+ fsubr asm_1dot5 // r0 = 1.5f - r0
+ fmul r // r0 = r0 * r
+ } // returns r0
+
+#else
+
+ return 1. / sqrt( r );
+
+#endif
+}
+
+/* very MS-specific, commented out for now
+ Finally the best InvSqrt implementation?
+ Use for vector normalisation instead of 1/length() * x,y,z
+*/
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+__declspec(naked) float __fastcall InvSqrt(float fValue)
+{
+ __asm
+ {
+ mov eax, 0be6eb508h
+ mov dword ptr[esp-12],03fc00000h
+ sub eax, dword ptr[esp + 4]
+ sub dword ptr[esp+4], 800000h
+ shr eax, 1
+ mov dword ptr[esp - 8], eax
+
+ fld dword ptr[esp - 8]
+ fmul st, st
+ fld dword ptr[esp - 8]
+ fxch st(1)
+ fmul dword ptr[esp + 4]
+ fld dword ptr[esp - 12]
+ fld st(0)
+ fsub st,st(2)
+
+ fld st(1)
+ fxch st(1)
+ fmul st(3),st
+ fmul st(3),st
+ fmulp st(4),st
+ fsub st,st(2)
+
+ fmul st(2),st
+ fmul st(3),st
+ fmulp st(2),st
+ fxch st(1)
+ fsubp st(1),st
+
+ fmulp st(1), st
+ ret 4
+ }
+}
+
+#endif
+
+// returns a random number
+FORCEINLINE float asm_rand()
+{
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+ #if 0
+ #if OGRE_COMP_VER >= 1300
+
+ static unsigned __int64 q = time( NULL );
+
+ _asm {
+ movq mm0, q
+
+ // do the magic MMX thing
+ pshufw mm1, mm0, 0x1E
+ paddd mm0, mm1
+
+ // move to integer memory location and free MMX
+ movq q, mm0
+ emms
+ }
+
+ return float( q );
+ #endif
+ #else
+ // VC6 does not support pshufw
+ return float( rand() );
+ #endif
+#else
+ // GCC etc
+
+ return float( rand() );
+
+#endif
+}
+
+// returns the maximum random number
+FORCEINLINE float asm_rand_max()
+{
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+ #if 0
+ #if OGRE_COMP_VER >= 1300
+
+ return (std::numeric_limits< unsigned __int64 >::max)();
+ return 9223372036854775807.0f;
+ #endif
+ #else
+ // VC6 does not support unsigned __int64
+ return float( RAND_MAX );
+ #endif
+
+#else
+ // GCC etc
+ return float( RAND_MAX );
+
+#endif
+}
+
+// returns log2( r ) / log2( e )
+float asm_ln( float r ) {
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+
+ const float asm_e = 2.71828182846f;
+ const float asm_1_div_log2_e = .693147180559f;
+ const float asm_neg1_div_3 = -.33333333333333333333333333333f;
+ const float asm_neg2_div_3 = -.66666666666666666666666666667f;
+ const float asm_2 = 2.f;
+
+ int log_2 = 0;
+
+ __asm {
+ // log_2 = ( ( r >> 0x17 ) & 0xFF ) - 0x80;
+ mov eax, r
+ sar eax, 0x17
+ and eax, 0xFF
+ sub eax, 0x80
+ mov log_2, eax
+
+ // r = ( r & 0x807fffff ) + 0x3f800000;
+ mov ebx, r
+ and ebx, 0x807FFFFF
+ add ebx, 0x3F800000
+ mov r, ebx
+
+ // r = ( asm_neg1_div_3 * r + asm_2 ) * r + asm_neg2_div_3; // (1)
+ fld r
+ fmul asm_neg1_div_3
+ fadd asm_2
+ fmul r
+ fadd asm_neg2_div_3
+ fild log_2
+ fadd
+ fmul asm_1_div_log2_e
+ }
+
+#else
+
+ return log( r );
+
+#endif
+}
+
+#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32
+# pragma warning( pop )
+#endif
+} // namespace
+#endif
Property changes on: sandbox_light/src/external/ogremath/asm_math.h
___________________________________________________________________
Added: svn:eol-style
+ native
Deleted: sandbox_light/src/libraries/core/BaseObject.cc
===================================================================
--- sandbox_light/src/libraries/core/BaseObject.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/BaseObject.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,60 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the BaseObject class.
-*/
-
-#include "BaseObject.h"
-#include "CoreIncludes.h"
-
-namespace orxonox
-{
- CreateFactory(BaseObject);
-
- /**
- @brief Constructor: Registers the object in the BaseObject-list.
- */
- BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false)
- {
- RegisterRootObject(BaseObject);
-
- this->bInitialized_ = true;
- }
-
- /**
- @brief Destructor
- */
- BaseObject::~BaseObject()
- {
- if (this->isInitialized())
- {
- }
- }
-}
Deleted: sandbox_light/src/libraries/core/BaseObject.h
===================================================================
--- sandbox_light/src/libraries/core/BaseObject.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/BaseObject.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,63 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the BaseObject class.
-
- The BaseObject is the parent of all classes representing an instance in the game.
-*/
-
-#ifndef _BaseObject_H__
-#define _BaseObject_H__
-
-#include "CorePrereqs.h"
-#include "OrxonoxClass.h"
-
-namespace orxonox
-{
- //! The BaseObject is the parent of all classes representing an instance in the game.
- class _CoreExport BaseObject : virtual public OrxonoxClass
- {
- public:
- BaseObject(BaseObject* creator);
- virtual ~BaseObject();
-
- /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */
- inline bool isInitialized() const { return this->bInitialized_; }
-
- inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
- inline BaseObject* getCreator() const { return this->creator_; }
-
- private:
- bool bInitialized_; //!< True if the object was initialized (passed the object registration)
- BaseObject* creator_;
- };
-}
-
-#endif /* _BaseObject_H__ */
Modified: sandbox_light/src/libraries/core/CMakeLists.txt
===================================================================
--- sandbox_light/src/libraries/core/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -19,33 +19,9 @@
SET_SOURCE_FILES(CORE_SRC_FILES
Clock.cc
- ConfigFileManager.cc
- ConfigValueContainer.cc
+ CommandLine.cc
Core.cc
- DynLib.cc
- DynLibManager.cc
- Game.cc
- GameState.cc
- Language.cc
LuaState.cc
- ObjectListBase.cc
- OrxonoxClass.cc
-
- # command
- CommandLine.cc
- Executor.cc
-
- # hierarchy
- Factory.cc
- Identifier.cc
- MetaObjectList.cc
-
- # level
- BaseObject.cc
-
- # multithreading
- Thread.cc
- ThreadPool.cc
)
ORXONOX_ADD_LIBRARY(core
@@ -54,15 +30,11 @@
LuaState.h
DEFINE_SYMBOL
"CORE_SHARED_BUILD"
- PCH_FILE
- CorePrecompiledHeaders.h
LINK_LIBRARIES
- ${OGRE_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY} # Filesystem dependency
- ${Boost_THREAD_LIBRARY}
- ${Boost_DATE_TIME_LIBRARY} # Thread dependency
${LUA_LIBRARIES}
+ ogremath_orxonox
tolua++_orxonox
util
SOURCE_FILES
Deleted: sandbox_light/src/libraries/core/ClassFactory.h
===================================================================
--- sandbox_light/src/libraries/core/ClassFactory.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ClassFactory.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,105 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition and implementation of the ClassFactory class
-
- The ClassFactory is able to create new objects of a specific class.
-*/
-
-#ifndef _ClassFactory_H__
-#define _ClassFactory_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-
-#include "util/Debug.h"
-#include "Factory.h"
-#include "Identifier.h"
-
-namespace orxonox
-{
- // ###############################
- // ### ClassFactory ###
- // ###############################
- //! The ClassFactory is able to create new objects of a specific class.
- template <class T>
- class ClassFactory : public BaseFactory
- {
- public:
- static bool create(const std::string& name);
- BaseObject* fabricate(BaseObject* creator);
-
- private:
- ClassFactory() {} // Don't create
- ClassFactory(const ClassFactory& factory) {} // Don't copy
- virtual ~ClassFactory() {} // Don't delete
-
- static T* createNewObject(BaseObject* creator);
- };
-
- /**
- @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
- @param name The name of the class
- @param bLoadable True if the class can be loaded through XML
- @return Always true (this is needed because the compiler only allows assignments before main())
- */
- template <class T>
- bool ClassFactory<T>::create(const std::string& name)
- {
- COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
- ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
- Factory::add(name, ClassIdentifier<T>::getIdentifier());
-
- return true;
- }
-
- /**
- @brief Creates and returns a new object of class T.
- @return The new object
- */
- template <class T>
- inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
- {
- return ClassFactory<T>::createNewObject(creator);
- }
-
- /**
- @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
- @return The new object
- */
- template <class T>
- inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
- {
- return new T(creator);
- }
-}
-
-#endif /* _ClassFactory_H__ */
Modified: sandbox_light/src/libraries/core/Clock.cc
===================================================================
--- sandbox_light/src/libraries/core/Clock.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Clock.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -32,7 +32,7 @@
*/
#include "Clock.h"
-#include <OgreTimer.h>
+#include <ogremath/OgreTimer.h>
namespace orxonox
{
Modified: sandbox_light/src/libraries/core/CommandLine.cc
===================================================================
--- sandbox_light/src/libraries/core/CommandLine.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/CommandLine.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -30,7 +30,6 @@
#include <algorithm>
#include <sstream>
-#include <boost/filesystem.hpp>
#include "util/Convert.h"
#include "util/Debug.h"
@@ -347,12 +346,11 @@
void CommandLine::_parseFile()
{
std::string filename = CommandLine::getValue("optionsFile").getString();
- boost::filesystem::path filepath(Core::getConfigPath() / filename);
// look for additional arguments in given file or start.ini as default
// They will not overwrite the arguments given directly
std::ifstream file;
- file.open(filepath.string().c_str());
+ file.open((Core::getConfigPathString() + filename).c_str());
std::vector<std::string> args;
if (file)
{
Deleted: sandbox_light/src/libraries/core/ConfigFileManager.cc
===================================================================
--- sandbox_light/src/libraries/core/ConfigFileManager.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ConfigFileManager.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,566 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#include "ConfigFileManager.h"
-
-#include <boost/filesystem.hpp>
-
-#include "util/Convert.h"
-#include "util/Math.h"
-#include "util/StringUtils.h"
-#include "ConfigValueContainer.h"
-#include "Core.h"
-
-namespace orxonox
-{
- bool config(const std::string& classname, const std::string& varname, const std::string& value)
- {
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
- if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
- return (*variable).second->set(value);
- }
- return false;
- }
-
- bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
- {
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
- if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
- return (*variable).second->tset(value);
- }
- return false;
- }
-
- void reloadConfig()
- {
- ConfigFileManager::getInstance().load();
- }
-
- void cleanConfig()
- {
- ConfigFileManager::getInstance().clean(false);
- }
-
- void loadSettings(const std::string& filename)
- {
- ConfigFileManager::getInstance().setFilename(ConfigFileType::Settings, filename);
- }
-
- //////////////////////////
- // ConfigFileEntryValue //
- //////////////////////////
-
- void ConfigFileEntryValue::setValue(const std::string& value)
- {
- if (!this->bString_)
- this->value_ = value;
- else
- this->value_ = "\"" + addSlashes(stripEnclosingQuotes(value)) + "\"";
- }
-
- std::string ConfigFileEntryValue::getValue() const
- {
- if (!this->bString_)
- return this->value_;
- else
- return removeSlashes(stripEnclosingQuotes(this->value_));
- }
-
- std::string ConfigFileEntryValue::getFileEntry() const
- {
- if (this->additionalComment_ == "" || this->additionalComment_.size() == 0)
- return (this->name_ + "=" + this->value_);
- else
- return (this->name_ + "=" + this->value_ + " " + this->additionalComment_);
- }
-
-
- ////////////////////////////////
- // ConfigFileEntryVectorValue //
- ////////////////////////////////
- std::string ConfigFileEntryVectorValue::getFileEntry() const
- {
- if (this->additionalComment_ == "" || this->additionalComment_.size() == 0)
- return (this->name_ + "[" + multi_cast<std::string>(this->index_) + "]" + "=" + this->value_);
- else
- return (this->name_ + "[" + multi_cast<std::string>(this->index_) + "]=" + this->value_ + " " + this->additionalComment_);
- }
-
-
- ///////////////////////
- // ConfigFileSection //
- ///////////////////////
- ConfigFileSection::~ConfigFileSection()
- {
- for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); )
- delete (*(it++));
- }
-
- void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex)
- {
- for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); )
- {
- if (((*it)->getName() == name) && ((*it)->getIndex() >= startindex))
- {
- delete (*it);
- this->entries_.erase(it++);
- }
- else
- {
- ++it;
- }
- }
- }
-
- unsigned int ConfigFileSection::getVectorSize(const std::string& name)
- {
- unsigned int size = 0;
- for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
- if ((*it)->getName() == name)
- if ((*it)->getIndex() > size)
- size = (*it)->getIndex();
- if (size == 0)
- return 0;
- else
- return (size + 1);
- }
-
- std::string ConfigFileSection::getFileEntry() const
- {
- if (this->additionalComment_ == "" || this->additionalComment_.size() == 0)
- return ("[" + this->name_ + "]");
- else
- return ("[" + this->name_ + "] " + this->additionalComment_);
- }
-
- std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback, bool bString)
- {
- for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
- {
- if ((*it)->getName() == name)
- {
- (*it)->setString(bString);
- return it;
- }
- }
-
- this->bUpdated_ = true;
-
- return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryValue(name, fallback, bString)));
- }
-
- std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- {
- for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
- {
- if (((*it)->getName() == name) && ((*it)->getIndex() == index))
- {
- (*it)->setString(bString);
- return it;
- }
- }
-
- this->bUpdated_ = true;
-
- if (index == 0)
- return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
- else
- return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
- }
-
-
- ////////////////
- // ConfigFile //
- ////////////////
- ConfigFile::~ConfigFile()
- {
- this->clear();
- }
-
- void ConfigFile::load(bool bCreateIfNotExisting)
- {
- // Be sure we start from new in the memory
- this->clear();
-
- // Get default file if necessary and available
- boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
- if (!boost::filesystem::exists(filepath))
- {
- // Try to get default one from the data folder
- boost::filesystem::path defaultFilepath(Core::getDataPath() / "defaultConfig" / this->filename_);
- if (boost::filesystem::exists(defaultFilepath))
- {
- COUT(3) << "Copied " << this->filename_ << " from the defaultConfig folder." << std::endl;
- boost::filesystem::copy_file(defaultFilepath, filepath);
- }
- }
-
- // Open the file
- std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
- if (file.is_open())
- {
- ConfigFileSection* newsection = 0;
-
- while (file.good() && !file.eof())
- {
- std::string line;
- std::getline(file, line);
-
- std::string temp = getStripped(line);
- if (!isEmpty(temp) && !isComment(temp))
- {
- size_t pos1 = temp.find('[');
- if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos;
- size_t pos2 = line.find(']');
-
- if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1)
- {
- // New section
- std::string comment = line.substr(pos2 + 1);
- if (isComment(comment))
- newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment);
- else
- newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1));
- this->sections_.insert(this->sections_.end(), newsection);
- continue;
- }
- }
-
- if (newsection != 0)
- {
- if (isComment(line))
- {
- // New comment
- newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line)));
- continue;
- }
- else
- {
- size_t pos1 = line.find('=');
-
- if (pos1 != std::string::npos && pos1 > 0)
- {
- // New entry
- size_t pos2 = line.find('[');
- size_t pos3 = line.find(']');
- size_t commentposition = getNextCommentPosition(line, pos1 + 1);
- while (isBetweenQuotes(line, commentposition))
- {
- commentposition = getNextCommentPosition(line, commentposition + 1);
- }
- std::string value = "", comment = "";
- if (commentposition == std::string::npos)
- {
- value = removeTrailingWhitespaces(line.substr(pos1 + 1));
- }
- else
- {
- value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1));
- comment = removeTrailingWhitespaces(line.substr(commentposition));
- }
-
- if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1)
- {
- // There might be an array index
- unsigned int index = 0;
- if (convertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1)))
- {
- // New array
- std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
- (*it)->setValue(value);
- (*it)->setComment(comment);
- continue;
- }
- }
-
- // New value
- newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment));
- continue;
- }
- }
- }
- }
-
- file.close();
-
- COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
-
- // Save the file in case something changed (like stripped whitespaces)
- this->save();
-
- // Update all ConfigValueContainers
- this->updateConfigValues();
- } // end file.is_open()
- }
-
- void ConfigFile::save() const
- {
- std::ofstream file;
- file.open((Core::getConfigPathString() + filename_).c_str(), std::fstream::out);
- file.setf(std::ios::fixed, std::ios::floatfield);
- file.precision(6);
-
- if (!file.is_open())
- {
- COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl;
- COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl;
- return;
- }
-
- for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
- {
- file << (*it)->getFileEntry() << std::endl;
-
- for (std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries)
- {
- file << (*it_entries)->getFileEntry() << std::endl;
- }
-
- file << std::endl;
- }
-
- file.close();
-
- COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl;
- }
-
- void ConfigFile::saveAs(const std::string& filename)
- {
- std::string temp = this->filename_;
- this->filename_ = filename;
- this->save();
- this->filename_ = temp;
- }
-
- void ConfigFile::clean(bool bCleanComments)
- {
- for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
- {
- std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName());
- if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues())
- {
- // The section exists, delete comment
- if (bCleanComments)
- (*it1)->setComment("");
- for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); )
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it4 = (*it2).second->getConfigValueMap().find((*it3)->getName());
- if (it4 != (*it2).second->getConfigValueMapEnd())
- {
- // The config-value exists, delete comment
- if (bCleanComments)
- (*it3)->setComment("");
- ++it3;
- }
- else
- {
- // The config-value doesn't exist
- delete (*it3);
- (*it1)->entries_.erase(it3++);
- }
- }
- ++it1;
- }
- else
- {
- // The section doesn't exist
- delete (*it1);
- this->sections_.erase(it1++);
- }
- }
-
- // Save the file
- this->save();
- }
-
- void ConfigFile::clear()
- {
- for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); )
- delete (*(it++));
- this->sections_.clear();
- }
-
- ConfigFileSection* ConfigFile::getSection(const std::string& section)
- {
- for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
- if ((*it)->getName() == section)
- return (*it);
-
- this->bUpdated_ = true;
-
- return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section)));
- }
-
- void ConfigFile::saveIfUpdated()
- {
- bool sectionsUpdated = false;
-
- for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
- {
- if ((*it)->bUpdated_)
- {
- sectionsUpdated = true;
- (*it)->bUpdated_ = false;
- }
- }
-
- if (this->bUpdated_ || sectionsUpdated)
- {
- this->bUpdated_ = false;
- this->save();
- }
- }
-
- void ConfigFile::updateConfigValues()
- {
- if (this->type_ == ConfigFileType::Settings)
- {
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
- {
- if (it->second->hasConfigValues())
- {
- for (std::map<std::string, ConfigValueContainer*>::const_iterator it2 = (*it).second->getConfigValueMapBegin(); it2 != (*it).second->getConfigValueMapEnd(); ++it2)
- it2->second->update();
-
- it->second->updateConfigValues();
- }
- }
- }
- }
-
-
- ///////////////////////
- // ConfigFileManager //
- ///////////////////////
-
- ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
-
- std::string ConfigFileManager::DEFAULT_CONFIG_FILE = "default.ini";
-
- ConfigFileManager::ConfigFileManager()
- : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)
- {
- }
-
- ConfigFileManager::~ConfigFileManager()
- {
- for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); )
- delete (it++)->second;
- }
-
- void ConfigFileManager::setFilename(ConfigFileType type, const std::string& filename)
- {
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- {
- assert(it->second);
- delete it->second;
- }
- this->configFiles_[type] = new ConfigFile(filename, type);
- this->load(type);
- }
-
- void ConfigFileManager::load()
- {
- for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->load();
- }
-
- void ConfigFileManager::save()
- {
- for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->save();
- }
-
- void ConfigFileManager::clean(bool bCleanComments)
- {
- for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- this->clean(it->first, bCleanComments);
- }
-
- void ConfigFileManager::load(ConfigFileType type)
- {
- this->getFile(type)->load();
- }
-
- void ConfigFileManager::save(ConfigFileType type)
- {
- this->getFile(type)->save();
- }
-
- void ConfigFileManager::saveAs(ConfigFileType type, const std::string& saveFilename)
- {
- this->getFile(type)->saveAs(saveFilename);
- }
-
- void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments)
- {
- this->getFile(type)->clean(bCleanComments);
- }
-
- void ConfigFileManager::updateConfigValues()
- {
- for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->updateConfigValues();
- }
-
- void ConfigFileManager::updateConfigValues(ConfigFileType type)
- {
- this->getFile(type)->updateConfigValues();
- }
-
- const std::string& ConfigFileManager::getFilename(ConfigFileType type)
- {
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- return it->second->getFilename();
- else
- return BLANKSTRING;
- }
-
- ConfigFile* ConfigFileManager::getFile(ConfigFileType type)
- {
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- return it->second;
- else
- {
- COUT(1) << "ConfigFileManager: Can't find a config file for type with ID " << static_cast<int>(type) << std::endl;
- COUT(1) << "Using " << DEFAULT_CONFIG_FILE << " file." << std::endl;
- this->setFilename(type, DEFAULT_CONFIG_FILE);
- return getFile(type);
- }
- }
-}
Deleted: sandbox_light/src/libraries/core/ConfigFileManager.h
===================================================================
--- sandbox_light/src/libraries/core/ConfigFileManager.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ConfigFileManager.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,323 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _ConfigFileManager_H__
-#define _ConfigFileManager_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include <string>
-#include <list>
-#include <map>
-
-#include "util/OrxEnum.h"
-#include "util/Singleton.h"
-
-namespace orxonox
-{
- // Use int as config file type to have an arbitrary number of files
- struct ConfigFileType : OrxEnum<ConfigFileType>
- {
- OrxEnumConstructors(ConfigFileType);
-
- static const int NoType = 0;
- static const int Settings = 1;
- static const int JoyStickCalibration = 2;
-
- static const int numberOfReservedTypes = 1024;
- };
-
- bool config(const std::string& classname, const std::string& varname, const std::string& value);
- bool tconfig(const std::string& classname, const std::string& varname, const std::string& value);
- void reloadConfig();
- void saveConfig();
- void cleanConfig();
- void loadSettings(const std::string& filename);
-
-
- /////////////////////
- // ConfigFileEntry //
- /////////////////////
- class _CoreExport ConfigFileEntry
- {
- public:
- virtual ~ConfigFileEntry() {};
- virtual void setValue(const std::string& value) = 0;
- virtual std::string getValue() const = 0;
- virtual const std::string& getName() const = 0;
- virtual void setComment(const std::string& comment) = 0;
- virtual unsigned int getIndex() const { return 0; }
- virtual void setString(bool bString) = 0;
- virtual std::string getFileEntry() const = 0;
- };
-
-
- //////////////////////////
- // ConfigFileEntryValue //
- //////////////////////////
- class _CoreExport ConfigFileEntryValue : public ConfigFileEntry
- {
- public:
- inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : name_(name), value_(value), bString_(bString), additionalComment_(additionalComment) {}
- inline virtual ~ConfigFileEntryValue() {}
-
- inline virtual const std::string& getName() const
- { return this->name_; }
-
- inline virtual void setComment(const std::string& comment)
- { this->additionalComment_ = comment; }
-
- virtual void setValue(const std::string& value);
- virtual std::string getValue() const;
-
- inline bool isString() const
- { return this->bString_; }
- inline void setString(bool bString)
- { this->bString_ = bString; }
-
- virtual std::string getFileEntry() const;
-
- protected:
- std::string name_;
- std::string value_;
- bool bString_;
- std::string additionalComment_;
- };
-
-
- ///////////////////////////////
- // ConfigFileEntryVectorValue //
- ///////////////////////////////
- class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue
- {
- public:
- inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, bString, additionalComment), index_(index) {}
- inline virtual ~ConfigFileEntryVectorValue() {}
-
- inline virtual unsigned int getIndex() const
- { return this->index_; }
-
- virtual std::string getFileEntry() const;
-
- private:
- unsigned int index_;
- };
-
-
- ////////////////////////////
- // ConfigFileEntryComment //
- ////////////////////////////
- class _CoreExport ConfigFileEntryComment : public ConfigFileEntry
- {
- public:
- inline ConfigFileEntryComment(const std::string& comment) : comment_(comment) {}
- inline virtual ~ConfigFileEntryComment() {}
-
- inline virtual const std::string& getName() const
- { return this->comment_; }
-
- inline virtual void setComment(const std::string& comment)
- { this->comment_ = comment; }
-
- inline virtual void setValue(const std::string& value)
- {}
- inline virtual std::string getValue() const
- { return this->comment_; }
-
- inline void setString(bool bString) {}
-
- inline virtual std::string getFileEntry() const
- { return this->comment_; }
-
- private:
- std::string comment_;
- };
-
-
- ///////////////////////
- // ConfigFileSection //
- ///////////////////////
- class _CoreExport ConfigFileSection
- {
- friend class ConfigFile;
-
- public:
- inline ConfigFileSection(const std::string& name, const std::string& additionalComment = "") : name_(name), additionalComment_(additionalComment), bUpdated_(false) {}
- ~ConfigFileSection();
-
- inline const std::string& getName() const
- { return this->name_; }
-
- inline void setComment(const std::string& comment)
- { this->additionalComment_ = comment; }
-
- inline void setValue(const std::string& name, const std::string& value, bool bString)
- { this->getEntry(name, value, bString)->setValue(value); }
- inline std::string getValue(const std::string& name, const std::string& fallback, bool bString)
- { return this->getEntry(name, fallback, bString)->getValue(); }
-
- inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getEntry(name, index, value, bString)->setValue(value); }
- inline std::string getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return this->getEntry(name, index, fallback, bString)->getValue(); }
-
- void deleteVectorEntries(const std::string& name, unsigned int startindex = 0);
- unsigned int getVectorSize(const std::string& name);
-
- std::string getFileEntry() const;
-
- private:
- std::list<ConfigFileEntry*>& getEntries()
- { return this->entries_; }
- std::list<ConfigFileEntry*>::const_iterator getEntriesBegin() const
- { return this->entries_.begin(); }
- std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const
- { return this->entries_.end(); }
-
- std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback, bool bString);
- std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString);
-
- inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback, bool bString)
- { return (*this->getEntryIterator(name, fallback, bString)); }
- inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return (*this->getEntryIterator(name, index, fallback, bString)); }
-
- std::string name_;
- std::string additionalComment_;
- std::list<ConfigFileEntry*> entries_;
- bool bUpdated_;
- };
-
-
- ////////////////
- // ConfigFile //
- ////////////////
- class _CoreExport ConfigFile
- {
- public:
- inline ConfigFile(const std::string& filename, ConfigFileType type)
- : filename_(filename)
- , type_(type)
- , bUpdated_(false)
- { }
- ~ConfigFile();
-
- void load(bool bCreateIfNotExisting = true);
- void save() const;
- void saveAs(const std::string& filename);
- void clean(bool bCleanComments = false);
- void clear();
-
- const std::string& getFilename() { return this->filename_; }
-
- inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString)
- { this->getSection(section)->setValue(name, value, bString); this->save(); }
- inline std::string getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
- { std::string output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; }
-
- inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getSection(section)->setValue(name, index, value, bString); this->save(); }
- inline std::string getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { std::string output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; }
-
- inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0)
- { this->getSection(section)->deleteVectorEntries(name, startindex); }
- inline unsigned int getVectorSize(const std::string& section, const std::string& name)
- { return this->getSection(section)->getVectorSize(name); }
-
- void updateConfigValues();
-
- private:
- ConfigFileSection* getSection(const std::string& section);
- void saveIfUpdated();
-
- std::string filename_;
- ConfigFileType type_;
- std::list<ConfigFileSection*> sections_;
- bool bUpdated_;
- };
-
-
- ///////////////////////
- // ConfigFileManager //
- ///////////////////////
- class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager>
- {
- friend class Singleton<ConfigFileManager>;
- public:
- ConfigFileManager();
- ~ConfigFileManager();
-
- void load();
- void save();
- void clean(bool bCleanComments = false);
-
- void setFilename(ConfigFileType type, const std::string& filename);
- const std::string& getFilename(ConfigFileType type);
-
- ConfigFileType getNewConfigFileType() { return mininmalFreeType_++; }
-
- void load(ConfigFileType type);
- void save(ConfigFileType type);
- void saveAs(ConfigFileType type, const std::string& saveFilename);
- void clean(ConfigFileType type, bool bCleanComments = false);
-
- inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString)
- { this->getFile(type)->setValue(section, name, value, bString); }
- inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)
- { return this->getFile(type)->getValue(section, name, fallback, bString); }
-
- inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getFile(type)->setValue(section, name, index, value, bString); }
- inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return this->getFile(type)->getValue(section, name, index, fallback, bString); }
-
- inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0)
- { this->getFile(type)->deleteVectorEntries(section, name, startindex); }
- inline unsigned int getVectorSize(ConfigFileType type, const std::string& section, const std::string& name)
- { return this->getFile(type)->getVectorSize(section, name); }
-
- void updateConfigValues();
- void updateConfigValues(ConfigFileType type);
-
- static std::string DEFAULT_CONFIG_FILE;
-
- private:
- ConfigFileManager(const ConfigFileManager&);
-
- ConfigFile* getFile(ConfigFileType type);
-
- std::map<ConfigFileType, ConfigFile*> configFiles_;
- unsigned int mininmalFreeType_;
-
- static ConfigFileManager* singletonPtr_s;
- };
-}
-
-#endif /* _ConfigFileManager_H__ */
Deleted: sandbox_light/src/libraries/core/ConfigValueContainer.cc
===================================================================
--- sandbox_light/src/libraries/core/ConfigValueContainer.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ConfigValueContainer.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,344 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the ConfigValueContainer class.
-*/
-
-#include "ConfigValueContainer.h"
-
-#include "util/Convert.h"
-#include "util/SubString.h"
-#include "Language.h"
-
-namespace orxonox
-{
- const unsigned int MAX_VECTOR_INDEX = 255; // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument
-
- /**
- @brief Initializes the ConfigValueContainer with defaultvalues.
- */
- void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
- {
- this->type_ = type;
- this->identifier_ = identifier;
- this->sectionname_ = sectionname;
- this->varname_ = varname;
- this->callback_ = 0;
- this->bContainerIsNew_ = true;
- this->bDoInitialCallback_ = false;
- this->bAddedDescription_ = false;
- }
-
- /**
- @brief Does some special initialization for single config-values.
- */
- void ConfigValueContainer::initValue(const MultiType& defvalue)
- {
- this->value_ = defvalue;
- this->bIsVector_ = false;
-
- this->defvalueString_ = this->value_.getString();
- this->update();
- }
-
- /**
- @brief Does some special initialization for vector config-values.
- */
- void ConfigValueContainer::initVector()
- {
- this->bIsVector_ = true;
-
- for (unsigned int i = 0; i < this->valueVector_.size(); i++)
- {
- ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
- this->defvalueStringVector_.push_back(this->valueVector_[i]);
- }
-
- this->update();
- }
-
- /**
- @brief Destructor: Deletes the callback object if necessary.
- */
- ConfigValueContainer::~ConfigValueContainer()
- {
- if (this->callback_)
- delete this->callback_;
- }
-
- /**
- @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
- @param input The new value
- @return True if the new value was successfully assigned
- */
- bool ConfigValueContainer::set(const MultiType& input)
- {
- if (this->bIsVector_)
- {
- return this->callFunctionWithIndex(&ConfigValueContainer::set, input);
- }
- else
- {
- if (this->tset(input))
- {
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));
- return true;
- }
- }
- return false;
- }
-
- /**
- @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
- @param index The index in the vector
- @param input The new value
- @return True if the new value was successfully assigned
- */
- bool ConfigValueContainer::set(unsigned int index, const MultiType& input)
- {
- if (this->bIsVector_)
- {
- if (this->tset(index, input))
- {
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));
- return true;
- }
- }
- else
- {
- COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
- }
- return false;
- }
-
- /**
- @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
- @param input The new value. If bIsVector_ then write "index value"
- @return True if the new value was successfully assigned
- */
- bool ConfigValueContainer::tset(const MultiType& input)
- {
- if (this->bIsVector_)
- {
- return this->callFunctionWithIndex(&ConfigValueContainer::tset, input);
- return false;
- }
- else
- {
- this->value_ = input;
-
- if (this->identifier_)
- this->identifier_->updateConfigValues();
-
- return true;
- }
- }
-
- /**
- @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
- @param index The index in the vector
- @param input The new value
- @return True if the new value was successfully assigned
- */
- bool ConfigValueContainer::tset(unsigned int index, const MultiType& input)
- {
- if (this->bIsVector_)
- {
- if (index > MAX_VECTOR_INDEX)
- {
- COUT(1) << "Error: Index " << index << " is too large." << std::endl;
- return false;
- }
-
- if (index >= this->valueVector_.size())
- {
- for (unsigned int i = this->valueVector_.size(); i <= index; i++)
- {
- this->valueVector_.push_back(MultiType());
- }
- }
-
- this->valueVector_[index] = input;
-
- if (this->identifier_)
- this->identifier_->updateConfigValues();
-
- return true;
- }
- else
- {
- COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
- return false;
- }
- }
-
- /**
- @brief Adds a new entry to the end of the vector.
- @param input The new entry
- @return True if the new entry was successfully added
- */
- bool ConfigValueContainer::add(const MultiType& input)
- {
- if (this->bIsVector_)
- return this->set(this->valueVector_.size(), input);
-
- COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
- return false;
- }
-
- /**
- @brief Removes an existing entry from the vector.
- @param index The index of the entry
- @return True if the entry was removed
- */
- bool ConfigValueContainer::remove(unsigned int index)
- {
- if (this->bIsVector_)
- {
- if (index < this->valueVector_.size())
- {
- // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file
- this->valueVector_.erase(this->valueVector_.begin() + index);
- for (unsigned int i = index; i < this->valueVector_.size(); i++)
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
- ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
-
- return true;
- }
- COUT(1) << "Error: Invalid vector-index." << std::endl;
- }
-
- COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
- return false;
- }
-
- /**
- @brief Sets the value of the variable back to the default value and resets the config-file entry.
- */
- bool ConfigValueContainer::reset()
- {
- if (!this->bIsVector_)
- return this->set(this->defvalueString_);
- else
- {
- bool success = true;
- for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++)
- if (!this->set(i, this->defvalueStringVector_[i]))
- success = false;
- ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
- return success;
- }
- }
-
- /**
- @brief Retrieves the configured value from the currently loaded config-file.
- */
- void ConfigValueContainer::update()
- {
- if (!this->bIsVector_)
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));
- else
- {
- this->valueVector_.clear();
- unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_);
- for (unsigned int i = 0; i < vectorSize; i++)
- {
- if (i < this->defvalueStringVector_.size())
- {
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));
- }
- else
- {
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));
- }
-
- this->valueVector_.push_back(this->value_);
- }
- }
- }
-
- /**
- @brief Calls the given function with parsed index and the parsed argument from the input string.
- @param function The function to call
- @param input The input string
- @return The returnvalue of the functioncall
- */
- bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input)
- {
- SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0');
- int index = -1;
- bool success = false;
-
- if (token.size() > 0)
- success = convertValue(&index, token[0]);
-
- if (!success || index < 0 || index > (signed int)MAX_VECTOR_INDEX)
- {
- if (!success)
- {
- COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;
- }
- else
- {
- COUT(1) << "Error: Invalid vector-index." << std::endl;
- }
- return false;
- }
-
- if (token.size() >= 2)
- return (this->*function)(index, token.subSet(1).join());
- else
- return (this->*function)(index, "");
- }
-
- /**
- @brief Adds a description to the config-value.
- @param description The description
- */
- ConfigValueContainer& ConfigValueContainer::description(const std::string& description)
- {
- if (!this->bAddedDescription_)
- {
- this->description_ = std::string("ConfigValueDescription::" + this->sectionname_ + "::" + this->varname_);
- AddLanguageEntry(this->description_, description);
- this->bAddedDescription_ = true;
- }
- return (*this);
- }
-
- /**
- @brief Returns the description of the config-value.
- @return The description
- */
- const std::string& ConfigValueContainer::getDescription() const
- {
- return GetLocalisation(this->description_);
- }
-}
Deleted: sandbox_light/src/libraries/core/ConfigValueContainer.h
===================================================================
--- sandbox_light/src/libraries/core/ConfigValueContainer.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ConfigValueContainer.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,301 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the ConfigValueContainer class.
-
- The ConfigValueContainer class contains all needed information about a configurable variable:
- - the name of the variable
- - the name of the class the variable belongs to
- - the default value
- - the user-specified value
- - a pointer to the entry in the config-file
-
- This is needed to assign the configured values to all newly created objects.
-*/
-
-#ifndef _ConfigValueContainer_H__
-#define _ConfigValueContainer_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-#include <vector>
-
-#include "util/MultiType.h"
-#include "ConfigFileManager.h"
-#include "Identifier.h"
-
-namespace orxonox
-{
- class ConfigValueCallbackBase
- {
- public:
- virtual void call(void* object) = 0;
- inline virtual ~ConfigValueCallbackBase() {}
- };
-
- template <class T>
- class ConfigValueCallback: public ConfigValueCallbackBase
- {
- public:
- inline ConfigValueCallback(void (T::*function) (void)) : function_(function) {}
- inline virtual ~ConfigValueCallback() {}
- inline virtual void call(void* object)
- {
- if (!Identifier::isCreatingHierarchy())
- (static_cast<T*>(object)->*this->function_)();
- }
-
- private:
- void (T::*function_) (void);
- };
-
-
- //! The ConfigValuecontainer contains all needed information about a configurable variable.
- /**
- The ConfigValueContainer class contains all needed information about a configurable variable:
- - the name of the variable
- - the name of the class the variable belongs to
- - the default value
- - the user-specified value
- - a pointer to the entry in the config-file
-
- This is needed to assign the configured values to all newly created objects.
-
- The container searches for the entry in the config file.
- If there is an entry, it parses the specified value and assigns it to the variable of the right type.
- If there is no entry, it adds the entry with the default-value to the section of the variables class.
- If there is no section, the section and the entry are added to the end of the config-file.
- */
- class _CoreExport ConfigValueContainer
- {
- public:
- /**
- @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
- @param type The type of the corresponding config-file
- @param identifier The identifier of the class the variable belongs to
- @param sectionname Name of the section the configValue should be put in.
- @param varname The name of the variable
- @param defvalue The default-value
- @param value Only needed do determine the right type.
- */
- template <class D, class V>
- ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value)
- {
- this->init(type, identifier, sectionname, varname);
- this->initValue(static_cast<V>(defvalue));
- }
-
- /**
- @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
- @param type The type of the corresponding config-file
- @param identifier The identifier of the class the variable belongs to
- @param varname The name of the variable
- @param defvalue The default-value
- */
- template <class V>
- ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<V>& defvalue)
- {
- this->init(type, identifier, sectionname, varname);
-
- this->value_ = V();
- for (unsigned int i = 0; i < defvalue.size(); i++)
- this->valueVector_.push_back(MultiType(defvalue[i]));
-
- this->initVector();
- }
-
- ~ConfigValueContainer();
-
- /**
- @brief Returns the configured value.
- @param value A pointer to the variable to store the value.
- @param object The object calling this function
- @return The ConfigValueContainer
- */
- template <typename T, class C>
- ConfigValueContainer& getValue(T* value, C* object)
- {
- if ((this->callback_ && object) || this->bContainerIsNew_)
- {
- if (this->bContainerIsNew_)
- this->bContainerIsNew_ = false;
-
- T temp = *value;
- this->value_.getValue(value);
- if ((*value) != temp)
- {
- if (this->callback_ && object)
- this->callback_->call(object);
- else
- this->bDoInitialCallback_ = true;
- }
- }
- else
- {
- this->value_.getValue(value);
- }
- return *this;
- }
-
- /**
- @brief Returns the configured vector.
- @param value A pointer to the vector to store the values.
- @param object The object calling this function
- @return The ConfigValueContainer
- */
- template <typename T, class C>
- ConfigValueContainer& getValue(std::vector<T>* value, C* object)
- {
- if ((this->callback_ && object) || this->bContainerIsNew_)
- {
- if (this->bContainerIsNew_)
- this->bContainerIsNew_ = false;
-
- std::vector<T> temp = *value;
- value->clear();
- for (unsigned int i = 0; i < this->valueVector_.size(); ++i)
- value->push_back(this->valueVector_[i]);
-
- if (value->size() != temp.size())
- {
- if (this->callback_ && object)
- this->callback_->call(object);
- else
- this->bDoInitialCallback_ = true;
- }
- else
- {
- for (unsigned int i = 0; i < value->size(); ++i)
- {
- if ((*value)[i] != temp[i])
- {
- if (this->callback_ && object)
- this->callback_->call(object);
- else
- this->bDoInitialCallback_ = true;
- break;
- }
- }
- }
- }
- else
- {
- value->clear();
- for (unsigned int i = 0; i < this->valueVector_.size(); ++i)
- value->push_back(this->valueVector_[i]);
- }
- return *this;
- }
-
- /** @brief Returns the name of this container. */
- inline const std::string& getName() const
- { return this->varname_; }
- /** @brief Retuns the name of the section this config value is in. */
- inline const std::string& getSectionName() const
- { return this->sectionname_; }
- /** @brief Returns true if this config-value is a vector */
- inline bool isVector() const
- { return this->bIsVector_; }
- /** @brief Returns the vectors size (or zero if it's not a vector). */
- inline unsigned int getVectorSize() const
- { return this->valueVector_.size(); }
-
- ConfigValueContainer& description(const std::string& description);
- const std::string& getDescription() const;
-
- /**
- @brief Adds a callback function, that gets called after getValue() if the newly assigned value differs from the old value of the variable.
- @param object The object to call the function
- @param function The callback function
- */
- template <class T>
- inline ConfigValueContainer& callback(T* object, void (T::*function) (void))
- {
- if (!this->callback_)
- {
- this->callback_ = new ConfigValueCallback<T>(function);
-
- if (this->bDoInitialCallback_)
- {
- this->bDoInitialCallback_ = false;
- this->callback_->call(object);
- }
- }
-
- return (*this);
- }
-
- bool set(const MultiType& input);
- bool tset(const MultiType& input);
-
- bool set(unsigned int index, const MultiType& input);
- bool tset(unsigned int index, const MultiType& input);
- bool add(const MultiType& input);
- bool remove(unsigned int index);
-
- bool reset();
- void update();
-
- /** @brief Converts the config-value to a string. @return The string */
- inline std::string toString() const
- { return this->value_; }
- /** @brief Returns the typename of the assigned config-value. @return The typename */
- inline std::string getTypename() const
- { return this->value_.getTypename(); }
-
- private:
- void init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname);
- void initValue(const MultiType& defvalue);
- void initVector();
- bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input);
-
- bool bIsVector_; //!< True if the container contains a std::vector
-
- ConfigFileType type_; //!< The type of the corresponding config-file
- Identifier* identifier_; //!< The identifier of the class
- std::string sectionname_; //!< The name of the class the variable belongs to
- std::string varname_; //!< The name of the variable
- std::string defvalueString_; //!< The string of the default-value
- std::vector<std::string> defvalueStringVector_; //!< A vector, containg the strings of the default-values in case we're storing a vector
-
- MultiType value_; //!< The value
- std::vector<MultiType> valueVector_; //!< A vector, containg the values in case we're storing a vector
-
- bool bAddedDescription_; //!< True if a description was added
- LanguageEntryLabel description_; //!< The description
- ConfigValueCallbackBase* callback_; //!< A callback function to call after getValue if the value changed
-
- bool bContainerIsNew_; //!< True if it's the first time getValue() gets called
- bool bDoInitialCallback_; //!< True if the callback should be called as soon as it gets created
- };
-}
-
-#endif /* _ConfigValueContainer_H__ */
Deleted: sandbox_light/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- sandbox_light/src/libraries/core/ConfigValueIncludes.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ConfigValueIncludes.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,114 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of macros for config-values.
-*/
-
-#ifndef _ConfigValueIncludes_H__
-#define _ConfigValueIncludes_H__
-
-#include "CorePrereqs.h"
-
-#include "Identifier.h"
-#include "ConfigValueContainer.h"
-#include "ConfigFileManager.h"
-
-
-/**
- @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
- @param varname The name of the variable
- @param defvalue The default-value of the variable
-*/
-#define SetConfigValueGeneric(type, varname, defvalue) \
- static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
- orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
- if (!container##varname) \
- { \
- container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \
- identifier##varname->addConfigValueContainer(#varname, container##varname); \
- } \
- container##varname->getValue(&varname, this)
-
-#define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, defvalue)
-
-
-/**
- @brief Assigns the vector-values, defined in the config-file, to the vector (or the default-value, if there are no entries in the file).
- @param varname The name of the std::vector
- @param defvalue The default-value
-*/
-#define SetConfigValueVectorGeneric(type, varname, defvalue) \
- static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
- orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
- if (!container##varname) \
- { \
- container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue); \
- identifier##varname->addConfigValueContainer(#varname, container##varname); \
- } \
- container##varname->getValue(&varname, this)
-
-#define SetConfigValueVector(varname, defvalue) SetConfigValueVectorGeneric(ConfigFileType::Settings, varname, defvalue)
-
-
-/**
- @brief Sets the variable and the config-file entry back to the previously defined default-value.
- @param varname The name of the variable
-*/
-#define ResetConfigValue(varname) \
- orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
- if (container##varname##reset) \
- { \
- container##varname##reset->reset(); \
- container##varname##reset->getValue(&varname, this); \
- } \
- else \
- { \
- COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
- }
-
-
-/**
- @brief Modifies a config-value by using a modifier and some arguments.
- @param varname The name of the config-value
- @param modifier The name of the modifier: set, tset, add, remove, reset, update
-*/
-#define ModifyConfigValue(varname, modifier, ...) \
- orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
- if (container##varname##modify##modifier) \
- { \
- container##varname##modify##modifier->modifier(__VA_ARGS__); \
- container##varname##modify##modifier->getValue(&varname, this); \
- } \
- else \
- { \
- COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
- }
-
-#endif /* _ConfigValueIncludes_H__ */
Modified: sandbox_light/src/libraries/core/Core.cc
===================================================================
--- sandbox_light/src/libraries/core/Core.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Core.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -63,13 +63,6 @@
#include "util/SignalHandler.h"
#include "Clock.h"
#include "CommandLine.h"
-#include "ConfigFileManager.h"
-#include "ConfigValueIncludes.h"
-#include "CoreIncludes.h"
-#include "DynLibManager.h"
-#include "Factory.h"
-#include "Identifier.h"
-#include "Language.h"
#include "LuaState.h"
// Boost 1.36 has some issues with deprecated functions that have been omitted
@@ -84,7 +77,6 @@
//! Static pointer to the singleton
Core* Core::singletonPtr_s = 0;
- SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
#ifdef ORXONOX_PLATFORM_WINDOWS
@@ -97,7 +89,7 @@
Core from OrxonoxClass because we need to handle the Identifier
destruction in the Core destructor.
*/
- class CoreConfiguration : public OrxonoxClass
+ class CoreConfiguration
{
public:
CoreConfiguration()
@@ -106,15 +98,6 @@
void initialise()
{
- RegisterRootObject(CoreConfiguration);
- this->setConfigValues();
- }
-
- /**
- @brief Function to collect the SetConfigValue-macro calls.
- */
- void setConfigValues()
- {
#ifdef NDEBUG
const unsigned int defaultLevelConsole = 1;
const unsigned int defaultLevelLogfile = 3;
@@ -124,22 +107,13 @@
const unsigned int defaultLevelLogfile = 4;
const unsigned int defaultLevelShell = 3;
#endif
- SetConfigValue(softDebugLevelConsole_, defaultLevelConsole)
- .description("The maximal level of debug output shown in the console")
- .callback(this, &CoreConfiguration::debugLevelChanged);
- SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile)
- .description("The maximal level of debug output shown in the logfile")
- .callback(this, &CoreConfiguration::debugLevelChanged);
- SetConfigValue(softDebugLevelShell_, defaultLevelShell)
- .description("The maximal level of debug output shown in the ingame shell")
- .callback(this, &CoreConfiguration::debugLevelChanged);
+ softDebugLevelConsole_ = defaultLevelConsole;
+ softDebugLevelLogfile_ = defaultLevelLogfile;
+ softDebugLevelShell_ = defaultLevelShell;
+ this->debugLevelChanged();
- SetConfigValue(language_, Language::getInstance().defaultLanguage_)
- .description("The language of the ingame text")
- .callback(this, &CoreConfiguration::languageChanged);
- SetConfigValue(bInitializeRandomNumberGenerator_, true)
- .description("If true, all random actions are different each time you start the game")
- .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
+ bInitializeRandomNumberGenerator_ = true;
+ this->initializeRandomNumberGenerator();
}
/**
@@ -160,23 +134,6 @@
OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_);
}
- /**
- @brief Callback function if the language has changed.
- */
- void languageChanged()
- {
- // Read the translation file after the language was configured
- Language::getInstance().readTranslatedLanguageFile();
- }
-
- /**
- @brief Sets the language in the config-file back to the default.
- */
- void resetLanguage()
- {
- ResetConfigValue(language_);
- }
-
void initializeRandomNumberGenerator()
{
static bool bInitialized = false;
@@ -192,13 +149,11 @@
int softDebugLevelConsole_; //!< The debug level for the console
int softDebugLevelLogfile_; //!< The debug level for the logfile
int softDebugLevelShell_; //!< The debug level for the ingame shell
- std::string language_; //!< The language
bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called
//! Path to the parent directory of the ones above if program was installed with relativ pahts
boost::filesystem::path rootPath_;
boost::filesystem::path executablePath_; //!< Path to the executable
- boost::filesystem::path modulePath_; //!< Path to the modules
boost::filesystem::path dataPath_; //!< Path to the data file folder
boost::filesystem::path configPath_; //!< Path to the config file folder
boost::filesystem::path logPath_; //!< Path to the log file folder
@@ -207,66 +162,12 @@
Core::Core(const std::string& cmdLine)
// Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
- : identifierDestroyer_(Identifier::destroyAllIdentifiers)
- , configuration_(new CoreConfiguration()) // Don't yet create config values!
+ : configuration_(new CoreConfiguration()) // Don't yet create config values!
, bDevRun_(false)
{
// Set the hard coded fixed paths
this->setFixedPaths();
- // Create a new dynamic library manager
- this->dynLibManager_.reset(new DynLibManager());
-
- // Load modules
- try
- {
- // We search for helper files with the following extension
- std::string moduleextension = specialConfig::moduleExtension;
- size_t moduleextensionlength = moduleextension.size();
-
- // Search in the directory of our executable
- boost::filesystem::path searchpath = this->configuration_->modulePath_;
-
- // Add that path to the PATH variable in case a module depends on another one
- std::string pathVariable = getenv("PATH");
- putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
-
- boost::filesystem::directory_iterator file(searchpath);
- boost::filesystem::directory_iterator end;
-
- // Iterate through all files
- while (file != end)
- {
- std::string filename = file->BOOST_LEAF_FUNCTION();
-
- // Check if the file ends with the exension in question
- if (filename.size() > moduleextensionlength)
- {
- if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
- {
- // We've found a helper file - now load the library with the same name
- std::string library = filename.substr(0, filename.size() - moduleextensionlength);
- boost::filesystem::path librarypath = searchpath / library;
-
- try
- {
- DynLibManager::getInstance().load(librarypath.string());
- }
- catch (...)
- {
- COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl;
- }
- }
- }
-
- ++file;
- }
- }
- catch (...)
- {
- COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;
- }
-
// Parse command line arguments AFTER the modules have been loaded (static code!)
CommandLine::parseCommandLine(cmdLine);
@@ -293,17 +194,6 @@
setThreadAffinity(static_cast<unsigned int>(limitToCPU));
#endif
- // Manage ini files and set the default settings file (usually orxonox.ini)
- this->configFileManager_.reset(new ConfigFileManager());
- this->configFileManager_->setFilename(ConfigFileType::Settings,
- CommandLine::getValue("settingsFile").getString());
-
- // Required as well for the config values
- this->languageInstance_.reset(new Language());
-
- // creates the class hierarchy for all classes with factories
- Factory::createClassHierarchy();
-
// Do this soon after the ConfigFileManager has been created to open up the
// possibility to configure everything below here
this->configuration_->initialise();
@@ -359,22 +249,6 @@
OutputHandler::setSoftDebugLevel(device, level);
}
- /**
- @brief Returns the configured language.
- */
- /*static*/ const std::string& Core::getLanguage()
- {
- return Core::getInstance().configuration_->language_;
- }
-
- /**
- @brief Sets the language in the config-file back to the default.
- */
- /*static*/ void Core::resetLanguage()
- {
- Core::getInstance().configuration_->resetLanguage();
- }
-
/*static*/ const boost::filesystem::path& Core::getDataPath()
{
return getInstance().configuration_->dataPath_;
@@ -523,7 +397,6 @@
{
COUT(1) << "Running from the build tree." << std::endl;
Core::bDevRun_ = true;
- configuration_->modulePath_ = specialConfig::moduleDevDirectory;
}
else
{
@@ -539,15 +412,6 @@
if (configuration_->rootPath_.empty())
ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
- // Module path is fixed as well
- configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
-
-#else
-
- // There is no root path, so don't set it at all
- // Module path is fixed as well
- configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
-
#endif
}
}
@@ -625,12 +489,4 @@
}
}
}
-
- void Core::preUpdate(const Clock& time)
- {
- }
-
- void Core::postUpdate(const Clock& time)
- {
- }
}
Modified: sandbox_light/src/libraries/core/Core.h
===================================================================
--- sandbox_light/src/libraries/core/Core.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Core.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -64,7 +64,6 @@
{
typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
friend class Singleton<Core>;
- friend class Game;
public:
/**
@@ -81,8 +80,6 @@
static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
- static const std::string& getLanguage();
- static void resetLanguage();
//! Returns the path to the data files as boost::filesystem::path
static const boost::filesystem::path& getDataPath();
@@ -106,19 +103,12 @@
private:
Core(const Core&); //!< Don't use (undefined symbol)
- void preUpdate(const Clock& time);
- void postUpdate(const Clock& time);
-
void setFixedPaths();
void setConfigurablePaths();
void setThreadAffinity(int limitToCPU);
// Mind the order for the destruction!
- scoped_ptr<DynLibManager> dynLibManager_;
scoped_ptr<SignalHandler> signalHandler_;
- SimpleScopeGuard identifierDestroyer_;
- scoped_ptr<ConfigFileManager> configFileManager_;
- scoped_ptr<Language> languageInstance_;
scoped_ptr<CoreConfiguration> configuration_;
bool bDevRun_; //!< True for runs in the build directory (not installed)
Deleted: sandbox_light/src/libraries/core/CoreIncludes.h
===================================================================
--- sandbox_light/src/libraries/core/CoreIncludes.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/CoreIncludes.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,113 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of macros for Identifier and Factory.
-
- Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
- or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
-
- To allow the object being created through the factory, use the CreateFactory(class) macro outside
- the of the class implementation, so it gets executed before main().
-*/
-
-#ifndef _CoreIncludes_H__
-#define _CoreIncludes_H__
-
-#include "CorePrereqs.h"
-
-#include "util/Debug.h"
-#include "Identifier.h"
-#include "Factory.h"
-#include "ClassFactory.h"
-#include "ObjectList.h"
-
-
-/**
- @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
- @param ClassName The name of the class
- @param bRootClass True if the class is directly derived from OrxonoxClass
-*/
-#define InternRegisterObject(ClassName, bRootClass) \
- if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
- return; \
- else \
- ((void)0)
-
-/**
- @brief RegisterObject - with and without debug output.
- @param ClassName The name of the class
-*/
-#define RegisterObject(ClassName) \
- InternRegisterObject(ClassName, false)
-
-/**
- @brief RegisterRootObject - with and without debug output.
- @param ClassName The name of the class
-*/
-#define RegisterRootObject(ClassName) \
- InternRegisterObject(ClassName, true)
-
-/**
- @brief Creates the entry in the Factory.
- @param ClassName The name of the class
-*/
-#define CreateFactory(ClassName) \
- bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
-
-/**
- @brief Returns the Identifier of the given class.
- @param ClassName The name of the class
-*/
-#define Class(ClassName) \
- orxonox::ClassIdentifier<ClassName>::getIdentifier()
-
-
-namespace orxonox
-{
- /**
- @brief Returns the Identifier with a given name through the factory.
- @param String The name of the class
- */
- inline Identifier* ClassByString(const std::string& name)
- {
- return Factory::getIdentifier(name);
- }
-
- /**
- @brief Returns the Identifier with a given network ID through the factory.
- @param networkID The network ID of the class
- */
- inline Identifier* ClassByID(uint32_t id)
- {
- return Factory::getIdentifier(id);
- }
-}
-
-#endif /* _CoreIncludes_H__ */
Deleted: sandbox_light/src/libraries/core/CorePrecompiledHeaders.h
===================================================================
--- sandbox_light/src/libraries/core/CorePrecompiledHeaders.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/CorePrecompiledHeaders.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,82 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Compilation of the most often used header files in the core library
- at details
- Updated: 13. September 2009
- Total Files: 56
-*/
-
-#include "OrxonoxConfig.h"
-
-///////////////////////////////////////////
-///// Stable Headers /////
-///////////////////////////////////////////
-
-#include <string> // 54
-#include <vector> // 54
-#include <cassert> // 53
-#include <fstream> // 53
-#include <iostream> // 53
-#include <map> // 53
-#include <sstream> // 53
-#include <set> // 50
-
-#include "util/Debug.h" // 48
-
-#include <deque> // 43
-#include <list> // 44
-#include <cmath> // 42
-
-#include "util/ScopeGuard.h" // 38
-
-#include <OgreMath.h> // 36
-#include <OgreVector2.h> // 36
-#include <OgreVector3.h> // 36
-#include <OgreVector4.h> // 36
-#include <OgreQuaternion.h> // 36
-#include <OgreColourValue.h> // 36
-#include <boost/preprocessor/cat.hpp> // 27
-#include <boost/shared_ptr.hpp> // 21
-
-#ifdef ORXONOX_COMPILER_MSVC
-
-#include "util/SubString.h" // 14
-
-#include <boost/scoped_ptr.hpp> // 13
-#include <stack> // 12
-
-#endif /*ORXONOX_COMPILER_MSVC */
-
-
-// Just in case some header included windows.h
-#undef min
-#undef max
Deleted: sandbox_light/src/libraries/core/DynLib.cc
===================================================================
--- sandbox_light/src/libraries/core/DynLib.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/DynLib.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,138 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#include "DynLib.h"
-
-#include "util/Exception.h"
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
-# define WIN32_LEAN_AND_MEAN
-# ifndef NOMINMAX
-# define NOMINMAX // required to stop windows.h messing up std::min
-# endif
-# include <windows.h>
-#endif
-
-#ifdef ORXONOX_PLATFORM_LINUX
-# include <dlfcn.h>
-#endif
-
-#ifdef ORXONOX_PLATFORM_APPLE
-# include <macPlugins.h>
-#endif
-
-namespace orxonox
-{
- //-----------------------------------------------------------------------
- DynLib::DynLib( const std::string& name )
- {
- mName = name;
- m_hInst = NULL;
- }
-
- //-----------------------------------------------------------------------
- DynLib::~DynLib()
- {
- }
-
- //-----------------------------------------------------------------------
- void DynLib::load()
- {
- // Log library load
- COUT(2) << "Loading module " << mName << std::endl;
-
- std::string name = mName;
-#ifdef ORXONOX_PLATFORM_LINUX
- // dlopen() does not add .so to the filename, like windows does for .dll
- if (name.substr(name.length() - 3, 3) != ".so")
- name += ".so";
-#endif
-
- m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
-
- if( !m_hInst )
- ThrowException(
- General,
- "Could not load dynamic library " + mName +
- ". System Error: " + dynlibError());
- }
-
- //-----------------------------------------------------------------------
- void DynLib::unload()
- {
- // Log library unload
- COUT(4) << "Unloading module " << mName << std::endl;
-
- if( DYNLIB_UNLOAD( m_hInst ) )
- {
- ThrowException(
- General,
- "Could not unload dynamic library " + mName +
- ". System Error: " + dynlibError());
- }
-
- }
-
- //-----------------------------------------------------------------------
- void* DynLib::getSymbol( const std::string& strName ) const throw()
- {
- return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() );
- }
- //-----------------------------------------------------------------------
- std::string DynLib::dynlibError( void )
- {
-#if defined(ORXONOX_PLATFORM_WINDOWS)
- LPVOID lpMsgBuf;
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
- std::string ret = (char*)lpMsgBuf;
- // Free the buffer.
- LocalFree( lpMsgBuf );
- return ret;
-#elif defined(ORXONOX_PLATFORM_LINUX)
- return std::string(dlerror());
-#elif defined(ORXONOX_PLATFORM_APPLE)
- return std::string(mac_errorBundle());
-#else
- return std::string("");
-#endif
- }
-
-}
Deleted: sandbox_light/src/libraries/core/DynLib.h
===================================================================
--- sandbox_light/src/libraries/core/DynLib.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/DynLib.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,121 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#ifndef _Core_DynLib_H__
-#define _Core_DynLib_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-
-#if defined(ORXONOX_PLATFORM_WINDOWS)
-# define DYNLIB_HANDLE hInstance
-# define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
-# define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
-# define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
-
-struct HINSTANCE__;
-typedef struct HINSTANCE__* hInstance;
-
-#elif defined(ORXONOX_PLATFORM_LINUX)
-# define DYNLIB_HANDLE void*
-# define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
-# define DYNLIB_GETSYM( a, b ) dlsym( a, b )
-# define DYNLIB_UNLOAD( a ) dlclose( a )
-
-#elif defined(ORXONOX_PLATFORM_APPLE)
-# define DYNLIB_HANDLE CFBundleRef
-# define DYNLIB_LOAD( a ) mac_loadExeBundle( a )
-# define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
-# define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
-#endif
-
-namespace orxonox
-{
- /** Resource holding data about a dynamic library.
- @remarks
- This class holds the data required to get symbols from
- libraries loaded at run-time (i.e. from DLL's for so's)
- @author
- Adrian Cearnãu (cearny at cearny.ro)
- @since
- 27 January 2002
- @see
- Resource
- */
- class _CoreExport DynLib
- {
- protected:
- std::string mName;
- /// Gets the last loading error
- std::string dynlibError(void);
- public:
- /** Default constructor - used by DynLibManager.
- @warning
- Do not call directly
- */
- DynLib( const std::string& name );
-
- /** Default destructor.
- */
- ~DynLib();
-
- /** Load the library
- */
- void load();
- /** Unload the library
- */
- void unload();
- /// Get the name of the library
- const std::string& getName(void) const { return mName; }
-
- /**
- Returns the address of the given symbol from the loaded library.
- @param
- strName The name of the symbol to search for
- @returns
- If the function succeeds, the returned value is a handle to
- the symbol.
- @par
- If the function fails, the returned value is <b>NULL</b>.
-
- */
- void* getSymbol( const std::string& strName ) const throw();
-
- protected:
-
- /// Handle to the loaded library.
- DYNLIB_HANDLE m_hInst;
- };
-
-}
-
-#endif /* _Core_DynLib_H__ */
Deleted: sandbox_light/src/libraries/core/DynLibManager.cc
===================================================================
--- sandbox_light/src/libraries/core/DynLibManager.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/DynLibManager.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,86 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#include "DynLibManager.h"
-
-#include "DynLib.h"
-
-namespace orxonox
-{
- //-----------------------------------------------------------------------
- //! Static pointer to the singleton
- DynLibManager* DynLibManager::singletonPtr_s = 0;
-
- //-----------------------------------------------------------------------
- DynLibManager::DynLibManager()
- {
- }
- //-----------------------------------------------------------------------
- DynLib* DynLibManager::load( const std::string& filename)
- {
- DynLibList::iterator i = mLibList.find(filename);
- if (i != mLibList.end())
- {
- return i->second;
- }
- else
- {
- DynLib* pLib = new DynLib(filename);
- pLib->load();
- mLibList[filename] = pLib;
- return pLib;
- }
- }
- //-----------------------------------------------------------------------
- void DynLibManager::unload(DynLib* lib)
- {
- DynLibList::iterator i = mLibList.find(lib->getName());
- if (i != mLibList.end())
- {
- mLibList.erase(i);
- }
- lib->unload();
- delete lib;
- }
- //-----------------------------------------------------------------------
- DynLibManager::~DynLibManager()
- {
- // Unload & delete resources in turn
- for( DynLibList::iterator it = mLibList.begin(); it != mLibList.end(); ++it )
- {
- it->second->unload();
- delete it->second;
- }
-
- // Empty the list
- mLibList.clear();
- }
-}
Deleted: sandbox_light/src/libraries/core/DynLibManager.h
===================================================================
--- sandbox_light/src/libraries/core/DynLibManager.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/DynLibManager.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,90 +0,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2006 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place - Suite 330, Boston, MA 02111-1307, USA, or go to
-http://www.gnu.org/copyleft/lesser.txt.
-
-You may alternatively use this source under the terms of a specific version of
-the OGRE Unrestricted License provided you have obtained such a license from
-Torus Knot Software Ltd.
------------------------------------------------------------------------------
-*/
-
-// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
-
-#ifndef _Core_DynLibManager_H__
-#define _Core_DynLibManager_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-#include "util/Singleton.h"
-
-namespace orxonox
-{
- /** Manager for Dynamic-loading Libraries.
- @remarks
- This manager keeps a track of all the open dynamic-loading
- libraries, opens them and returns references to already-open
- libraries.
- */
- class _CoreExport DynLibManager: public Singleton<DynLibManager>
- {
- friend class Singleton<DynLibManager>;
-
- protected:
- typedef std::map<std::string, DynLib*> DynLibList;
- DynLibList mLibList;
-
- public:
- /** Default constructor.
- @note
- <br>Should never be called as the singleton is automatically
- created during the creation of the Root object.
- @see
- Root::Root
- */
- DynLibManager();
-
- /** Default destructor.
- @see
- Root::~Root
- */
- virtual ~DynLibManager();
-
- /** Loads the passed library.
- @param
- filename The name of the library. The extension can be omitted
- */
- DynLib* load(const std::string& filename);
-
- /** Unloads the passed library.
- @param
- filename The name of the library. The extension can be omitted
- */
- void unload(DynLib* lib);
-
- private:
- static DynLibManager* singletonPtr_s;
- };
-}
-
-#endif /* _Core_DynLibManager_H__ */
Deleted: sandbox_light/src/libraries/core/Executor.cc
===================================================================
--- sandbox_light/src/libraries/core/Executor.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Executor.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,252 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- * Inspiration: Executor by Benjamin Grauer
- */
-
-#include "Executor.h"
-
-#include "util/Convert.h"
-#include "Language.h"
-
-namespace orxonox
-{
- Executor::Executor(Functor* functor, const std::string& name)
- {
- this->functor_ = functor;
- this->name_ = name;
-
- this->bAddedDescription_ = false;
- this->bAddedDescriptionReturnvalue_ = false;
-
- this->bAddedDescriptionParam_[0] = false;
- this->bAddedDescriptionParam_[1] = false;
- this->bAddedDescriptionParam_[2] = false;
- this->bAddedDescriptionParam_[3] = false;
- this->bAddedDescriptionParam_[4] = false;
-
- this->bAddedDefaultValue_[0] = false;
- this->bAddedDefaultValue_[1] = false;
- this->bAddedDefaultValue_[2] = false;
- this->bAddedDefaultValue_[3] = false;
- this->bAddedDefaultValue_[4] = false;
- }
-
- Executor::~Executor()
- {
- delete this->functor_;
- }
-
- bool Executor::parse(const std::string& params, const std::string& delimiter) const
- {
- EXECUTOR_PARSE(normal);
- }
-
- bool Executor::evaluate(const std::string& params, MultiType param[5], const std::string& delimiter) const
- {
- unsigned int paramCount = this->functor_->getParamCount();
-
- if (paramCount == 1)
- {
- // only one param: check if there are params given, otherwise try to use default values
- std::string temp = getStripped(params);
- if ((temp != "") && (temp.size() != 0))
- {
- param[0] = params;
- this->functor_->evaluateParam(0, param[0]);
- return true;
- }
- else if (this->bAddedDefaultValue_[0])
- {
- param[0] = this->defaultValue_[0];
- this->functor_->evaluateParam(0, param[0]);
- return true;
- }
- return false;
- }
- else
- {
- // more than one param
- SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
-
- // if there are not enough params given, check if there are default values
- for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
- if (!this->bAddedDefaultValue_[i])
- return false;
-
- // assign all given arguments to the multitypes
- for (unsigned int i = 0; i < std::min(tokens.size(), MAX_FUNCTOR_ARGUMENTS); i++)
- param[i] = tokens[i];
-
- // fill the remaining multitypes with default values
- for (unsigned int i = tokens.size(); i < std::min(paramCount, MAX_FUNCTOR_ARGUMENTS); i++)
- param[i] = this->defaultValue_[i];
-
- // evaluate the param types through the functor
- for (unsigned int i = 0; i < std::min(paramCount, MAX_FUNCTOR_ARGUMENTS); i++)
- this->functor_->evaluateParam(i, param[i]);
-
- return true;
- }
- }
-
- Executor& Executor::setDescription(const std::string& description)
- {
- if (!this->bAddedDescription_)
- {
- this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function");
- AddLanguageEntry(this->description_, description);
- this->bAddedDescription_ = true;
- }
- return (*this);
- }
-
- const std::string& Executor::getDescription() const
- {
- return GetLocalisation(this->description_);
- }
-
- Executor& Executor::setDescriptionParam(unsigned int param, const std::string& description)
- {
- if (param < MAX_FUNCTOR_ARGUMENTS)
- {
- if (!this->bAddedDescriptionParam_[param])
- {
- std::string paramnumber;
- if (!convertValue(¶mnumber, param))
- return (*this);
-
- this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
- AddLanguageEntry(this->descriptionParam_[param], description);
- this->bAddedDescriptionParam_[param] = true;
- }
- }
- return (*this);
- }
-
- const std::string& Executor::getDescriptionParam(unsigned int param) const
- {
- if (param < MAX_FUNCTOR_ARGUMENTS)
- return GetLocalisation(this->descriptionParam_[param]);
-
- return this->descriptionParam_[0];
- }
-
- Executor& Executor::setDescriptionReturnvalue(const std::string& description)
- {
- if (!this->bAddedDescriptionReturnvalue_)
- {
- this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue");
- AddLanguageEntry(this->descriptionReturnvalue_, description);
- this->bAddedDescriptionReturnvalue_ = true;
- }
- return (*this);
- }
-
- const std::string& Executor::getDescriptionReturnvalue(int param) const
- {
- return GetLocalisation(this->descriptionReturnvalue_);
- }
-
- Executor& Executor::setDefaultValues(const MultiType& param1)
- {
- this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
-
- return (*this);
- }
-
- Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2)
- {
- this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
- this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
-
- return (*this);
- }
-
- Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
- {
- this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
- this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
- this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
-
- return (*this);
- }
-
- Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
- {
- this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
- this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
- this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
- this->defaultValue_[3] = param4;
- this->bAddedDefaultValue_[3] = true;
-
- return (*this);
- }
-
- Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
- {
- this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
- this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
- this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
- this->defaultValue_[3] = param4;
- this->bAddedDefaultValue_[3] = true;
- this->defaultValue_[4] = param5;
- this->bAddedDefaultValue_[4] = true;
-
- return (*this);
- }
-
- Executor& Executor::setDefaultValue(unsigned int index, const MultiType& param)
- {
- if (index < MAX_FUNCTOR_ARGUMENTS)
- {
- this->defaultValue_[index] = param;
- this->bAddedDefaultValue_[index] = true;
- }
- return (*this);
- }
-
- bool Executor::allDefaultValuesSet() const
- {
- for (unsigned int i = 0; i < this->functor_->getParamCount(); i++)
- if (!this->bAddedDefaultValue_[i])
- return false;
-
- return true;
- }
-}
Deleted: sandbox_light/src/libraries/core/Executor.h
===================================================================
--- sandbox_light/src/libraries/core/Executor.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Executor.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,312 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- * Inspiration: Executor by Benjamin Grauer
- */
-
-#ifndef _Executor_H__
-#define _Executor_H__
-
-#include "CorePrereqs.h"
-
-#include <algorithm>
-#include <string>
-
-#include "util/Debug.h"
-#include "util/Math.h"
-#include "util/StringUtils.h"
-#include "util/SubString.h"
-#include "Functor.h"
-
-
-#define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode
-#define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_)
-#define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_))
-
-#define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma
-#define EXECUTOR_PARSE_OBJECTnormal0
-#define EXECUTOR_PARSE_OBJECTnormal1
-#define EXECUTOR_PARSE_OBJECTobject0 object
-#define EXECUTOR_PARSE_OBJECTobject1 object,
-
-#define EXECUTOR_PARSE(mode) \
- unsigned int paramCount = this->functor_->getParamCount(); \
- \
- if (paramCount == 0) \
- { \
- COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \
- } \
- else if (paramCount == 1) \
- { \
- std::string temp = getStripped(params); \
- if ((temp != "") && (temp.size() != 0)) \
- { \
- COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiType(params)); \
- } \
- else if (this->bAddedDefaultValue_[0]) \
- { \
- COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \
- } \
- else \
- { \
- COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \
- return false; \
- } \
- } \
- else \
- { \
- SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \
- \
- for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \
- { \
- if (!this->bAddedDefaultValue_[i]) \
- { \
- COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \
- return false; \
- } \
- } \
- \
- MultiType param[MAX_FUNCTOR_ARGUMENTS]; \
- COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \
- for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \
- { \
- param[i] = tokens[i]; \
- if (i != 0) \
- { \
- COUT(5) << ", "; \
- } \
- COUT(5) << tokens[i]; \
- } \
- COUT(5) << ") and " << std::max(static_cast<int>(paramCount) - static_cast<int>(tokens.size()), 0) << " default values ("; \
- for (unsigned int i = tokens.size(); i < paramCount; i++) \
- { \
- param[i] = this->defaultValue_[i]; \
- if (i != 0) \
- { \
- COUT(5) << ", "; \
- } \
- COUT(5) << this->defaultValue_[i]; \
- } \
- COUT(5) << ")." << std::endl; \
- \
- if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \
- param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \
- \
- switch(paramCount) \
- { \
- case 2: \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \
- break; \
- case 3: \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \
- break; \
- case 4: \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \
- break; \
- case 5: \
- EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \
- break; \
- } \
- } \
- \
- return true
-
-namespace orxonox
-{
- class _CoreExport Executor
- {
- public:
- Executor(Functor* functor, const std::string& name = "");
- virtual ~Executor();
-
- inline void operator()() const
- { (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const MultiType& param1) const
- { (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const MultiType& param1, const MultiType& param2) const
- { (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3) const
- { (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
- { (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); }
- inline void operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
- { (*this->functor_)(param1, param2, param3, param4, param5); }
-
- bool parse(const std::string& params, const std::string& delimiter = " ") const;
-
- bool evaluate(const std::string& params, MultiType param[5], const std::string& delimiter = " ") const;
-
- Executor& setDescription(const std::string& description);
- const std::string& getDescription() const;
-
- Executor& setDescriptionParam(unsigned int param, const std::string& description);
- const std::string& getDescriptionParam(unsigned int param) const;
-
- Executor& setDescriptionReturnvalue(const std::string& description);
- const std::string& getDescriptionReturnvalue(int param) const;
-
- inline Functor* getFunctor() const
- { return this->functor_; }
- inline unsigned int getParamCount() const
- { return this->functor_->getParamCount(); }
- inline bool hasReturnvalue() const
- { return this->functor_->hasReturnvalue(); }
- inline FunctionType::Value getType() const
- { return this->functor_->getType(); }
- inline const MultiType& getReturnvalue() const
- { return this->functor_->getReturnvalue(); }
- inline const std::string& getTypenameParam(unsigned int param) const
- { return this->functor_->getTypenameParam(param); }
- inline const std::string& getTypenameReturnvalue() const
- { return this->functor_->getTypenameReturnvalue(); }
-
- inline void setName(const std::string name)
- { this->name_ = name; }
- inline const std::string& getName() const
- { return this->name_; }
-
- Executor& setDefaultValues(const MultiType& param1);
- Executor& setDefaultValues(const MultiType& param1, const MultiType& param2);
- Executor& setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3);
- Executor& setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4);
- Executor& setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5);
- Executor& setDefaultValue(unsigned int index, const MultiType& param);
-
- inline MultiType getDefaultValue(unsigned int index) const
- {
- if (index < MAX_FUNCTOR_ARGUMENTS)
- return this->defaultValue_[index];
-
- return MT_Type::Null;
- }
-
- bool allDefaultValuesSet() const;
- inline bool defaultValueSet(unsigned int index) const
- {
- if (index < MAX_FUNCTOR_ARGUMENTS)
- return this->bAddedDefaultValue_[index];
-
- return false;
- }
-
- protected:
- Functor* functor_;
- std::string name_;
- MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS];
- bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
-
- private:
- LanguageEntryLabel description_;
- LanguageEntryLabel descriptionReturnvalue_;
- LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
-
- bool bAddedDescription_;
- bool bAddedDescriptionReturnvalue_;
- bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
- };
-
- class _CoreExport ExecutorStatic : public Executor
- {
- public:
- ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
- virtual ~ExecutorStatic() {}
- };
-
- template <class T>
- class ExecutorMember : public Executor
- {
- public:
- ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
- virtual ~ExecutorMember() {}
-
- using Executor::operator();
-
- inline void operator()(T* object) const
- { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(T* object, const MultiType& param1) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(T* object, const MultiType& param1, const MultiType& param2) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
- inline void operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
-
-
- inline void operator()(const T* object) const
- { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const T* object, const MultiType& param1) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const T* object, const MultiType& param1, const MultiType& param2) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
- inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
- inline void operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const
- { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
-
- inline void setObject(T* object) const
- { ((FunctorMember<T>*)this->functor_)->setObject(object); }
- inline void setObject(const T* object) const
- { ((FunctorMember<T>*)this->functor_)->setObject(object); }
-
- using Executor::parse;
-
- bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
- {
- EXECUTOR_PARSE(object);
- }
-
- bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const
- {
- EXECUTOR_PARSE(object);
- }
- };
-
- inline Executor* createExecutor(Functor* functor, const std::string& name = "")
- {
- return new Executor(functor, name);
- }
-
- template <class T>
- inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "")
- {
- return new ExecutorMember<T>(functor, name);
- }
-
- inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "")
- {
- return new ExecutorStatic(functor, name);
- }
-}
-
-#endif /* _Executor_H__ */
Deleted: sandbox_light/src/libraries/core/Factory.cc
===================================================================
--- sandbox_light/src/libraries/core/Factory.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Factory.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,94 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the Factory class.
-*/
-
-#include "Factory.h"
-
-#include "util/Debug.h"
-#include "Identifier.h"
-#include "BaseObject.h"
-
-namespace orxonox
-{
- /**
- @brief Returns the Identifier with a given name.
- @param name The name of the wanted Identifier
- @return The Identifier
- */
- Identifier* Factory::getIdentifier(const std::string& name)
- {
- std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name);
- if (it != getFactoryPointer()->identifierStringMap_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Adds a new Identifier to both maps.
- @param name The name of the identifier
- @param identifier The identifier to add
- */
- void Factory::add(const std::string& name, Identifier* identifier)
- {
- getFactoryPointer()->identifierStringMap_[name] = identifier;
- }
-
- /**
- @brief Creates the class-hierarchy by creating and destroying one object of each type.
- */
- void Factory::createClassHierarchy()
- {
- COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
- std::map<std::string, Identifier*>::iterator it;
- it = getFactoryPointer()->identifierStringMap_.begin();
- (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
- for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
- {
- // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
- BaseObject* temp = (*it).second->fabricate(0);
- delete temp;
- }
- (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
- COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
- }
-
- /**
- @brief Ensures the Factory gets created in the right moment.
- @return The Factory.
- */
- Factory* Factory::getFactoryPointer()
- {
- static Factory theOneAndOnlyFactoryInstance = Factory();
- return &theOneAndOnlyFactoryInstance;
- }
-}
Deleted: sandbox_light/src/libraries/core/Factory.h
===================================================================
--- sandbox_light/src/libraries/core/Factory.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Factory.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,98 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the Factory and the BaseFactory class.
-
- The Factory is a singleton, containing two maps to map either the name or the network ID
- of a class with the corresponding Identifier.
-
- Usage:
- ID(classname) or ID(networkID) returns the corresponding Identifier.
-
-
- BaseObject is the parent of ClassFactory which is defined in ClassFactory.h.
- It can't be defined in ClassFactory.h, because of circular dependencies.
-*/
-
-#ifndef _Factory_H__
-#define _Factory_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-
-namespace orxonox
-{
- // ###############################
- // ### Factory ###
- // ###############################
- //! The Factory is used to map the name or the network ID of a class with its Identifier.
- class _CoreExport Factory
- {
- public:
- static Identifier* getIdentifier(const std::string& name);
- static Identifier* getIdentifier(const uint32_t id);
- static void add(const std::string& name, Identifier* identifier);
- static void createClassHierarchy();
-
- static Factory* getFactoryPointer(); // avoid overriding order problem in the static intialisation process
-
- /** @brief Returns the factory-map. */
- static const std::map<std::string, Identifier*>& getFacbtoryMap()
- { return Factory::getFactoryPointer()->identifierStringMap_; }
- /** @brief Returns the begin-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
- { return Factory::getFactoryPointer()->identifierStringMap_.begin(); }
- /** @brief Returns the end-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapEnd()
- { return Factory::getFactoryPointer()->identifierStringMap_.end(); }
-
- private:
- Factory() {} // don't create
- Factory(const Factory& factory); // don't copy
- ~Factory() {} // don't delete
-
- std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier
- };
-
- // ###############################
- // ### BaseFactory ###
- // ###############################
- //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies.
- class _CoreExport BaseFactory
- {
- public:
- virtual BaseObject* fabricate(BaseObject* creator) = 0;
- virtual ~BaseFactory() {};
- };
-}
-
-#endif /* _Factory_H__ */
Deleted: sandbox_light/src/libraries/core/Functor.h
===================================================================
--- sandbox_light/src/libraries/core/Functor.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Functor.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,483 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- * Inspiration: Functor by Benjamin Grauer
- */
-
-#ifndef _Functor_H__
-#define _Functor_H__
-
-#include "CorePrereqs.h"
-
-#include "util/Debug.h"
-#include "util/MultiType.h"
-#include "util/StringUtils.h"
-
-namespace orxonox
-{
- const unsigned int MAX_FUNCTOR_ARGUMENTS = 5;
-
- namespace FunctionType
- {
- enum Value
- {
- Member,
- ConstMember,
- Static
- };
- }
-
-
- template <class T>
- inline std::string typeToString() { return "unknown"; }
-
-#define CreateTypeToStringTemplate(type) \
- template <> \
- inline std::string typeToString<type>() { return #type; } \
- template <> \
- inline std::string typeToString<type&>() { return #type; } \
- template <> \
- inline std::string typeToString<const type>() { return #type; } \
- template <> \
- inline std::string typeToString<const type&>() { return #type; }
-
- CreateTypeToStringTemplate(int);
- CreateTypeToStringTemplate(unsigned int);
- CreateTypeToStringTemplate(char);
- CreateTypeToStringTemplate(unsigned char);
- CreateTypeToStringTemplate(short);
- CreateTypeToStringTemplate(unsigned short);
- CreateTypeToStringTemplate(long);
- CreateTypeToStringTemplate(unsigned long);
- CreateTypeToStringTemplate(long long);
- CreateTypeToStringTemplate(unsigned long long);
- CreateTypeToStringTemplate(float);
- CreateTypeToStringTemplate(double);
- CreateTypeToStringTemplate(long double);
- CreateTypeToStringTemplate(bool);
- CreateTypeToStringTemplate(Vector2);
- CreateTypeToStringTemplate(Vector3);
- CreateTypeToStringTemplate(Quaternion);
- CreateTypeToStringTemplate(ColourValue);
- CreateTypeToStringTemplate(Radian);
- CreateTypeToStringTemplate(Degree);
-
- template <>
- inline std::string typeToString<std::string>() { return "string"; }
- template <>
- inline std::string typeToString<std::string&>() { return "string"; }
- template <>
- inline std::string typeToString<const std::string>() { return "string"; }
- template <>
- inline std::string typeToString<const std::string&>() { return "string"; }
-
- class _CoreExport Functor
- {
- public:
- Functor() {}
- virtual ~Functor() {}
-
- virtual void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
-
- inline unsigned int getParamCount() const { return this->numParams_; }
- inline bool hasReturnvalue() const { return this->hasReturnValue_; }
- inline FunctionType::Value getType() const { return this->type_; }
- inline const MultiType& getReturnvalue() const { return this->returnedValue_; }
-
- const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : BLANKSTRING; }
- const std::string& getTypenameReturnvalue() const { return this->typeReturnvalue_; }
-
- virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
-
- protected:
- unsigned int numParams_;
- bool hasReturnValue_;
- FunctionType::Value type_;
- MultiType returnedValue_;
-
- std::string typeReturnvalue_;
- std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
- };
-
- class _CoreExport FunctorStatic : public Functor
- {
- public:
- virtual ~FunctorStatic() {}
- virtual void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
- };
-
- template <class T>
- class FunctorMember : public Functor
- {
- public:
- FunctorMember()
- {
- constObject_ = 0;
- object_ = 0;
- bConstObject_ = false;
- }
- virtual ~FunctorMember() {}
-
- virtual void operator()(T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
- virtual void operator()(const T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
-
- virtual void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null)
- {
- if (this->bConstObject_)
- {
- if (this->constObject_)
- (*this)(this->constObject_, param1, param2, param3, param4, param5);
- else
- {
- COUT(1) << "An error occurred in Functor.h:" << std::endl;
- COUT(1) << "Error: No const object set." << std::endl;
- }
- }
- else
- {
- if (this->object_)
- (*this)(this->object_, param1, param2, param3, param4, param5);
- else
- {
- COUT(1) << "An error occurred in Functor.h:" << std::endl;
- COUT(1) << "Error: No object set." << std::endl;
- }
- }
- }
-
- FunctorMember<T>* setObject(T* object)
- {
- this->bConstObject_ = false;
- this->object_ = object;
- return this;
- }
-
- FunctorMember<T>* setObject(const T* object)
- {
- this->bConstObject_ = true;
- this->constObject_ = object;
- return this;
- }
-
- private:
- const T* constObject_;
- T* object_;
- bool bConstObject_;
- };
-
-
-
-#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams
-#define FUNCTOR_TEMPLATE000
-#define FUNCTOR_TEMPLATE001 template <class P1>
-#define FUNCTOR_TEMPLATE002 template <class P1, class P2>
-#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE010 template <class R>
-#define FUNCTOR_TEMPLATE011 template <class R, class P1>
-#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>
-#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE100 template <class T>
-#define FUNCTOR_TEMPLATE101 template <class T, class P1>
-#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>
-#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>
-#define FUNCTOR_TEMPLATE110 template <class T, class R>
-#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>
-#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>
-#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>
-#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>
-#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
-
-
-
-#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams
-#define FUNCTOR_TEMPLATE_CLASSES000
-#define FUNCTOR_TEMPLATE_CLASSES001 <P1>
-#define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2>
-#define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3>
-#define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4>
-#define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5>
-#define FUNCTOR_TEMPLATE_CLASSES010 <R>
-#define FUNCTOR_TEMPLATE_CLASSES011 <R, P1>
-#define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2>
-#define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3>
-#define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4>
-#define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5>
-#define FUNCTOR_TEMPLATE_CLASSES100 <T>
-#define FUNCTOR_TEMPLATE_CLASSES101 <T, P1>
-#define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2>
-#define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3>
-#define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4>
-#define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5>
-#define FUNCTOR_TEMPLATE_CLASSES110 <T, R>
-#define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1>
-#define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2>
-#define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3>
-#define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4>
-#define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5>
-
-
-
-#define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams
-#define FUNCTOR_TYPENAME_PARAMS0
-#define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();
-#define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();
-#define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();
-#define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();
-#define FUNCTOR_TYPENAME_PARAMS5 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); this->typeParam_[4] = typeToString<P5>();
-
-#define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue
-#define FUNCTOR_TYPENAME_RETURN0
-#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();
-
-
-
-#define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams
-#define FUNCTOR_FUNCTION_PARAMS0
-#define FUNCTOR_FUNCTION_PARAMS1 P1 param1
-#define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2
-#define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3
-#define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4
-#define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5
-
-#define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue
-#define FUNCTOR_FUNCTION_RETURNVALUE0 void
-#define FUNCTOR_FUNCTION_RETURNVALUE1 R
-
-
-
-#define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams
-#define FUNCTOR_FUNCTION_CALL0
-#define FUNCTOR_FUNCTION_CALL1 param1
-#define FUNCTOR_FUNCTION_CALL2 param1, param2
-#define FUNCTOR_FUNCTION_CALL3 param1, param2, param3
-#define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4
-#define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5
-
-#define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)
-#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall
-#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall
-
-
-
-#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
-#define FUNCTOR_EVALUATE_PARAM0
-#define FUNCTOR_EVALUATE_PARAM1 \
- if (index == 0) { param.convert<P1>(); }
-#define FUNCTOR_EVALUATE_PARAM2 \
- if (index == 0) { param.convert<P1>(); } \
- else if (index == 1) { param.convert<P2>(); }
-#define FUNCTOR_EVALUATE_PARAM3 \
- if (index == 0) { param.convert<P1>(); } \
- else if (index == 1) { param.convert<P2>(); } \
- else if (index == 2) { param.convert<P3>(); }
-#define FUNCTOR_EVALUATE_PARAM4 \
- if (index == 0) { param.convert<P1>(); } \
- else if (index == 1) { param.convert<P2>(); } \
- else if (index == 2) { param.convert<P3>(); } \
- else if (index == 3) { param.convert<P4>(); }
-#define FUNCTOR_EVALUATE_PARAM5 \
- if (index == 0) { param.convert<P1>(); } \
- else if (index == 1) { param.convert<P2>(); } \
- else if (index == 2) { param.convert<P3>(); } \
- else if (index == 3) { param.convert<P4>(); } \
- else if (index == 4) { param.convert<P5>(); }
-
-
-
-
-
-#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
- FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
- class FunctorStatic##returnvalue##numparams : public FunctorStatic \
- { \
- public: \
- FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
- { \
- this->numParams_ = numparams; \
- this->hasReturnValue_ = returnvalue; \
- this->type_ = FunctionType::Static; \
- this->functionPointer_ = functionPointer; \
- \
- FUNCTOR_TYPENAME_PARAMS(numparams); \
- FUNCTOR_TYPENAME_RETURN(returnvalue); \
- } \
- \
- void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
- { \
- FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
- } \
- \
- virtual void evaluateParam(unsigned int index, MultiType& param) const \
- { \
- FUNCTOR_EVALUATE_PARAM(numparams); \
- } \
- \
- private: \
- FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
- }; \
- \
- \
- FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
- inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
- { \
- return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
- }
-
-
-
-
-
-#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
- class FunctorMember##returnvalue##numparams : public FunctorMember<T> \
- { \
- public: \
- FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
- { \
- this->numParams_ = numparams; \
- this->hasReturnValue_ = returnvalue; \
- this->type_ = FunctionType::Member; \
- this->functionPointer_ = functionPointer; \
- } \
- \
- void operator()(T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
- { \
- FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
- } \
- \
- void operator()(const T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
- { \
- COUT(1) << "An error occurred in Functor.h:" << std::endl; \
- COUT(1) << "Error: Function is not const." << std::endl; \
- } \
- \
- virtual void evaluateParam(unsigned int index, MultiType& param) const \
- { \
- FUNCTOR_EVALUATE_PARAM(numparams); \
- } \
- \
- private: \
- FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
- }; \
- \
- \
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
- class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \
- { \
- public: \
- FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
- { \
- this->numParams_ = numparams; \
- this->hasReturnValue_ = returnvalue; \
- this->type_ = FunctionType::ConstMember; \
- this->functionPointer_ = functionPointer; \
- } \
- \
- void operator()(T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
- { \
- FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
- } \
- \
- void operator()(const T* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
- { \
- FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
- } \
- \
- virtual void evaluateParam(unsigned int index, MultiType& param) const \
- { \
- FUNCTOR_EVALUATE_PARAM(numparams); \
- } \
- \
- private: \
- FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \
- }; \
- \
- \
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
- inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
- { \
- return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
- } \
- \
- \
- FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
- inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
- { \
- return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
- }
-
-
-// disable annoying warning about forcing value to boolean
-#ifdef ORXONOX_COMPILER_MSVC
-#pragma warning(push)
-#pragma warning(disable:4100 4800)
-#endif
-
-#define CREATE_ALL_STATIC_FUNCTORS() \
- CREATE_STATIC_FUNCTOR(0, 0); \
- CREATE_STATIC_FUNCTOR(0, 1); \
- CREATE_STATIC_FUNCTOR(0, 2); \
- CREATE_STATIC_FUNCTOR(0, 3); \
- CREATE_STATIC_FUNCTOR(0, 4); \
- CREATE_STATIC_FUNCTOR(0, 5); \
- CREATE_STATIC_FUNCTOR(1, 0); \
- CREATE_STATIC_FUNCTOR(1, 1); \
- CREATE_STATIC_FUNCTOR(1, 2); \
- CREATE_STATIC_FUNCTOR(1, 3); \
- CREATE_STATIC_FUNCTOR(1, 4); \
- CREATE_STATIC_FUNCTOR(1, 5)
-
-
-#define CREATE_ALL_MEMBER_FUNCTORS() \
- CREATE_MEMBER_FUNCTOR(0, 0); \
- CREATE_MEMBER_FUNCTOR(0, 1); \
- CREATE_MEMBER_FUNCTOR(0, 2); \
- CREATE_MEMBER_FUNCTOR(0, 3); \
- CREATE_MEMBER_FUNCTOR(0, 4); \
- CREATE_MEMBER_FUNCTOR(0, 5); \
- CREATE_MEMBER_FUNCTOR(1, 0); \
- CREATE_MEMBER_FUNCTOR(1, 1); \
- CREATE_MEMBER_FUNCTOR(1, 2); \
- CREATE_MEMBER_FUNCTOR(1, 3); \
- CREATE_MEMBER_FUNCTOR(1, 4); \
- CREATE_MEMBER_FUNCTOR(1, 5)
-
-
- CREATE_ALL_STATIC_FUNCTORS();
- CREATE_ALL_MEMBER_FUNCTORS();
-}
-
-#ifdef ORXONOX_COMPILER_MSVC
-#pragma warning(pop)
-#endif
-
-#endif /* _Functor_H__ */
Deleted: sandbox_light/src/libraries/core/Game.cc
===================================================================
--- sandbox_light/src/libraries/core/Game.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Game.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,576 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Implementation of the Game class.
-*/
-
-#include "Game.h"
-
-#include <exception>
-#include <boost/weak_ptr.hpp>
-
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/ScopeGuard.h"
-#include "util/Sleep.h"
-#include "util/SubString.h"
-#include "Clock.h"
-#include "CommandLine.h"
-#include "Core.h"
-#include "CoreIncludes.h"
-#include "ConfigValueIncludes.h"
-#include "GameState.h"
-
-namespace orxonox
-{
- std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
- Game* Game::singletonPtr_s = 0;
-
-
- /**
- @brief
- Represents one node of the game state tree.
- */
- struct GameStateTreeNode
- {
- std::string name_;
- weak_ptr<GameStateTreeNode> parent_;
- std::vector<shared_ptr<GameStateTreeNode> > children_;
- };
-
-
- /**
- @brief
- Another helper class for the Game singleton: we cannot derive
- Game from OrxonoxClass because we need to handle the Identifier
- destruction in the Core destructor.
- */
- class GameConfiguration : public OrxonoxClass
- {
- public:
- GameConfiguration()
- {
- RegisterRootObject(GameConfiguration);
- this->setConfigValues();
- }
-
- void setConfigValues()
- {
- SetConfigValue(statisticsRefreshCycle_, 250000)
- .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
- SetConfigValue(statisticsAvgLength_, 1000000)
- .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
- SetConfigValue(fpsLimit_, 50)
- .description("Sets the desired framerate (0 for no limit).");
- }
-
- unsigned int statisticsRefreshCycle_;
- unsigned int statisticsAvgLength_;
- unsigned int fpsLimit_;
- };
-
-
- /**
- @brief
- Non-initialising constructor.
- */
- Game::Game(const std::string& cmdLine)
- // Destroy factories before the Core!
- : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
- {
- this->bAbort_ = false;
- bChangingState_ = false;
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
- minimumSleepTime_ = 1000/*us*/;
-#else
- minimumSleepTime_ = 0/*us*/;
-#endif
-
- // Create an empty root state
- this->declareGameState<GameState>("GameState", "emptyRootGameState", true, false);
-
- // Set up a basic clock to keep time
- this->gameClock_.reset(new Clock());
-
- // Create the Core
- this->core_.reset(new Core(cmdLine));
-
- // After the core has been created, we can safely instantiate the GameStates that don't require graphics
- for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
- it != gameStateDeclarations_s.end(); ++it)
- {
- if (!it->second.bGraphicsMode)
- constructedStates_[it->second.stateName] = GameStateFactory::fabricate(it->second);
- }
-
- // The empty root state is ALWAYS loaded!
- this->rootStateNode_ = shared_ptr<GameStateTreeNode>(new GameStateTreeNode());
- this->rootStateNode_->name_ = "emptyRootGameState";
- this->loadedTopStateNode_ = this->rootStateNode_;
- this->loadedStates_.push_back(this->getState(rootStateNode_->name_));
-
- // Do this after the Core creation!
- this->configuration_.reset(new GameConfiguration());
- }
-
- /**
- @brief
- All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
- */
- Game::~Game()
- {
- }
-
- /**
- @brief
- Main loop of the orxonox game.
- @note
- We use the Ogre::Timer to measure time since it uses the most precise
- method an any platform (however the windows timer lacks time when under
- heavy kernel load!).
- */
- void Game::run()
- {
- if (this->requestedStateNodes_.empty())
- COUT(0) << "Warning: Starting game without requesting GameState. This automatically terminates the program." << std::endl;
-
- // reset statistics
- this->statisticsStartTime_ = 0;
- this->statisticsTickTimes_.clear();
- this->periodTickTime_ = 0;
- this->periodTime_ = 0;
- this->avgFPS_ = 0.0f;
- this->avgTickTime_ = 0.0f;
- this->excessSleepTime_ = 0;
-
- // START GAME
- // first delta time should be about 0 seconds
- this->gameClock_->capture();
- // A first item is required for the fps limiter
- StatisticsTickInfo tickInfo = {0, 0};
- statisticsTickTimes_.push_back(tickInfo);
- while (!this->bAbort_ && (!this->loadedStates_.empty() || this->requestedStateNodes_.size() > 0))
- {
- // Generate the dt
- this->gameClock_->capture();
-
- // Statistics init
- StatisticsTickInfo tickInfo = {gameClock_->getMicroseconds(), 0};
- statisticsTickTimes_.push_back(tickInfo);
- this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds();
-
- // Update the GameState stack if required
- this->updateGameStateStack();
-
- // Core preUpdate (doesn't throw)
- try
- { this->core_->preUpdate(*this->gameClock_); }
- catch (...)
- {
- COUT(0) << "An exception occurred in the Core preUpdate: " << Exception::handleMessage() << std::endl;
- COUT(0) << "This should really never happen! Closing the program." << std::endl;
- this->stop();
- break;
- }
-
- // Update the GameStates bottom up in the stack
- this->updateGameStates();
-
- // Core postUpdate (doesn't throw)
- try
- { this->core_->postUpdate(*this->gameClock_); }
- catch (...)
- {
- COUT(0) << "An exception occurred in the Core postUpdate: " << Exception::handleMessage() << std::endl;
- COUT(0) << "This should really never happen! Closing the program." << std::endl;
- this->stop();
- break;
- }
-
- // Evaluate statistics
- this->updateStatistics();
-
- // Limit framerate
- this->updateFPSLimiter();
- }
-
- // UNLOAD all remaining states
- while (this->loadedStates_.size() > 1)
- this->unloadState(this->loadedStates_.back()->getName());
- this->loadedTopStateNode_ = this->rootStateNode_;
- this->requestedStateNodes_.clear();
- }
-
- void Game::updateGameStateStack()
- {
- while (this->requestedStateNodes_.size() > 0)
- {
- shared_ptr<GameStateTreeNode> requestedStateNode = this->requestedStateNodes_.front();
- assert(this->loadedTopStateNode_);
- if (!this->loadedTopStateNode_->parent_.expired() && requestedStateNode == this->loadedTopStateNode_->parent_.lock())
- this->unloadState(loadedTopStateNode_->name_);
- else // has to be child
- {
- try
- {
- this->loadState(requestedStateNode->name_);
- }
- catch (...)
- {
- COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Exception::handleMessage() << std::endl;
- // All scheduled operations have now been rendered inert --> flush them and issue a warning
- if (this->requestedStateNodes_.size() > 1)
- COUT(4) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
- this->requestedStateNodes_.clear();
- break;
- }
- }
- this->loadedTopStateNode_ = requestedStateNode;
- this->requestedStateNodes_.erase(this->requestedStateNodes_.begin());
- }
- }
-
- void Game::updateGameStates()
- {
- // Note: The first element is the empty root state, which doesn't need ticking
- for (GameStateVector::const_iterator it = this->loadedStates_.begin() + 1;
- it != this->loadedStates_.end(); ++it)
- {
- try
- {
- // Add tick time for most of the states
- uint64_t timeBeforeTick = 0;
- if ((*it)->getInfo().bIgnoreTickTime)
- timeBeforeTick = this->gameClock_->getRealMicroseconds();
- (*it)->update(*this->gameClock_);
- if ((*it)->getInfo().bIgnoreTickTime)
- this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
- }
- catch (...)
- {
- COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Exception::handleMessage() << std::endl;
- COUT(1) << "This should really never happen!" << std::endl;
- COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
- shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;
- while (current->name_ != (*it)->getName() && current)
- current = current->parent_.lock();
- if (current && current->parent_.lock())
- this->requestState(current->parent_.lock()->name_);
- else
- this->stop();
- break;
- }
- }
- }
-
- void Game::updateStatistics()
- {
- // Add the tick time of this frame (rendering time has already been subtracted)
- uint64_t currentTime = gameClock_->getMicroseconds();
- uint64_t currentRealTime = gameClock_->getRealMicroseconds();
- this->statisticsTickTimes_.back().tickLength += currentRealTime - currentTime;
- this->periodTickTime_ += currentRealTime - currentTime;
- if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_)
- {
- std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
- assert(it != this->statisticsTickTimes_.end());
- int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_;
- if (static_cast<int64_t>(it->tickTime) < lastTime)
- {
- do
- {
- assert(this->periodTickTime_ >= it->tickLength);
- this->periodTickTime_ -= it->tickLength;
- ++it;
- assert(it != this->statisticsTickTimes_.end());
- } while (static_cast<int64_t>(it->tickTime) < lastTime);
- this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
- }
-
- uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
- this->avgFPS_ = static_cast<float>(framesPerPeriod) / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0f;
- this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
-
- this->periodTime_ -= this->configuration_->statisticsRefreshCycle_;
- }
- }
-
- void Game::updateFPSLimiter()
- {
- // Why configuration_->fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high
- uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / (configuration_->fpsLimit_ - 1));
- uint64_t currentRealTime = gameClock_->getRealMicroseconds();
- while (currentRealTime < nextTime - minimumSleepTime_)
- {
- usleep(nextTime - currentRealTime);
- currentRealTime = gameClock_->getRealMicroseconds();
- }
- // Integrate excess to avoid steady state error
- excessSleepTime_ = currentRealTime - nextTime;
- // Anti windup
- if (excessSleepTime_ > 50000) // 20ms is about the maximum time Windows would sleep for too long
- excessSleepTime_ = 50000;
- }
-
- void Game::stop()
- {
- this->bAbort_ = true;
- }
-
- void Game::subtractTickTime(int32_t length)
- {
- assert(!this->statisticsTickTimes_.empty());
- this->statisticsTickTimes_.back().tickLength -= length;
- this->periodTickTime_ -= length;
- }
-
-
- /***** GameState related *****/
-
- void Game::requestState(const std::string& name)
- {
- if (!this->checkState(name))
- {
- COUT(2) << "Warning: GameState named '" << name << "' doesn't exist!" << std::endl;
- return;
- }
-
- if (this->bChangingState_)
- {
- COUT(2) << "Warning: Requesting GameStates while loading/unloading a GameState is illegal! Ignoring." << std::endl;
- return;
- }
-
- shared_ptr<GameStateTreeNode> lastRequestedNode;
- if (this->requestedStateNodes_.empty())
- lastRequestedNode = this->loadedTopStateNode_;
- else
- lastRequestedNode = this->requestedStateNodes_.back();
- if (name == lastRequestedNode->name_)
- {
- COUT(2) << "Warning: Requesting the currently active state! Ignoring." << std::endl;
- return;
- }
-
- // Check children first
- std::vector<shared_ptr<GameStateTreeNode> > requestedNodes;
- for (unsigned int i = 0; i < lastRequestedNode->children_.size(); ++i)
- {
- if (lastRequestedNode->children_[i]->name_ == name)
- {
- requestedNodes.push_back(lastRequestedNode->children_[i]);
- break;
- }
- }
-
- if (requestedNodes.empty())
- {
- // Check parent and all its grand parents
- shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;
- while (currentNode != NULL)
- {
- if (currentNode->name_ == name)
- break;
- currentNode = currentNode->parent_.lock();
- requestedNodes.push_back(currentNode);
- }
- }
-
- if (requestedNodes.empty())
- COUT(1) << "Error: Requested GameState transition is not allowed. Ignoring." << std::endl;
- else
- this->requestedStateNodes_.insert(requestedStateNodes_.end(), requestedNodes.begin(), requestedNodes.end());
- }
-
- void Game::requestStates(const std::string& names)
- {
- SubString tokens(names, ",;", " ");
- for (unsigned int i = 0; i < tokens.size(); ++i)
- this->requestState(tokens[i]);
- }
-
- void Game::popState()
- {
- shared_ptr<GameStateTreeNode> lastRequestedNode;
- if (this->requestedStateNodes_.empty())
- lastRequestedNode = this->loadedTopStateNode_;
- else
- lastRequestedNode = this->requestedStateNodes_.back();
- if (lastRequestedNode != this->rootStateNode_)
- this->requestState(lastRequestedNode->parent_.lock()->name_);
- else
- COUT(2) << "Warning: Can't pop the internal dummy root GameState" << std::endl;
- }
-
- shared_ptr<GameState> Game::getState(const std::string& name)
- {
- GameStateMap::const_iterator it = constructedStates_.find(name);
- if (it != constructedStates_.end())
- return it->second;
- else
- {
- std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.find(name);
- if (it != gameStateDeclarations_s.end())
- COUT(1) << "Error: GameState '" << name << "' has not yet been loaded." << std::endl;
- else
- COUT(1) << "Error: Could not find GameState '" << name << "'." << std::endl;
- return shared_ptr<GameState>();
- }
- }
-
- void Game::setStateHierarchy(const std::string& str)
- {
- // Split string into pieces of the form whitespacesText
- std::vector<std::pair<std::string, unsigned> > stateStrings;
- size_t pos = 0;
- size_t startPos = 0;
- while (pos < str.size())
- {
- unsigned indentation = 0;
- while(pos < str.size() && str[pos] == ' ')
- ++indentation, ++pos;
- startPos = pos;
- while(pos < str.size() && str[pos] != ' ')
- ++pos;
- stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation));
- }
- unsigned int currentLevel = 0;
- shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_;
- for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
- {
- std::string newStateName = it->first;
- unsigned newLevel = it->second + 1; // empty root is 0
- if (!this->checkState(newStateName))
- ThrowException(GameState, "GameState with name '" << newStateName << "' not found!");
- if (newStateName == this->rootStateNode_->name_)
- ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
- shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
- newNode->name_ = newStateName;
-
- if (newLevel <= currentLevel)
- {
- do
- currentNode = currentNode->parent_.lock();
- while (newLevel <= --currentLevel);
- }
- if (newLevel == currentLevel + 1)
- {
- // Add the child
- newNode->parent_ = currentNode;
- currentNode->children_.push_back(newNode);
- }
- else
- ThrowException(GameState, "Indentation error while parsing the hierarchy.");
- currentNode = newNode;
- currentLevel = newLevel;
- }
- }
-
- /*** Internal ***/
-
- void Game::loadGraphics()
- {
- }
-
- void Game::unloadGraphics()
- {
- }
-
- bool Game::checkState(const std::string& name) const
- {
- std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.find(name);
- if (it == gameStateDeclarations_s.end())
- return false;
- else
- return true;
- }
-
- void Game::loadState(const std::string& name)
- {
- this->bChangingState_ = true;
- LOKI_ON_BLOCK_EXIT_OBJ(*this, &Game::resetChangingState);
-
- // If state requires graphics, load it
- Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
- if (gameStateDeclarations_s[name].bGraphicsMode)
- this->loadGraphics();
- else
- graphicsUnloader.Dismiss();
-
- shared_ptr<GameState> state = this->getState(name);
- state->activate();
- if (!this->loadedStates_.empty())
- this->loadedStates_.back()->activity_.topState = false;
- this->loadedStates_.push_back(state);
- state->activity_.topState = true;
-
- graphicsUnloader.Dismiss();
- }
-
- void Game::unloadState(const std::string& name)
- {
- this->bChangingState_ = true;
- try
- {
- shared_ptr<GameState> state = this->getState(name);
- state->activity_.topState = false;
- this->loadedStates_.pop_back();
- if (!this->loadedStates_.empty())
- this->loadedStates_.back()->activity_.topState = true;
- state->deactivate();
- }
- catch (...)
- {
- COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Exception::handleMessage() << std::endl;
- COUT(2) << " There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
- }
- // Check if graphics is still required
- if (!bAbort_)
- {
- bool graphicsRequired = false;
- for (unsigned i = 0; i < loadedStates_.size(); ++i)
- graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
- if (!graphicsRequired)
- this->unloadGraphics();
- }
- this->bChangingState_ = false;
- }
-
- std::map<std::string, shared_ptr<Game::GameStateFactory> > Game::GameStateFactory::factories_s;
-
- /*static*/ shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)
- {
- std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = factories_s.find(info.className);
- assert(it != factories_s.end());
- return it->second->fabricateInternal(info);
- }
-}
Deleted: sandbox_light/src/libraries/core/Game.h
===================================================================
--- sandbox_light/src/libraries/core/Game.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Game.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,212 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Declaration of Game Singleton.
- */
-
-#ifndef _Game_H__
-#define _Game_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include <list>
-#include <map>
-#include <string>
-#include <vector>
-#include <boost/shared_ptr.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/preprocessor/cat.hpp>
-
-#include "util/Debug.h"
-#include "util/ScopeGuard.h"
-#include "util/Singleton.h"
-
-/**
- at def
- Adds a new GameState to the Game. The second parameter is the name as string
- and every following paramter is a constructor argument (which is usually non existent)
-*/
-#define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \
- static bool BOOST_PP_CAT(bGameStateDummy_##className, __LINE__) = orxonox::Game::declareGameState<className>(#className, stateName, bIgnoreTickTime, bGraphicsMode)
-
-namespace orxonox
-{
- class GameConfiguration;
-
- //! Helper object required before GameStates are being constructed
- struct GameStateInfo
- {
- std::string stateName;
- std::string className;
- bool bIgnoreTickTime;
- bool bGraphicsMode;
- };
-
- /**
- @brief
- Main class responsible for running the game.
- @remark
- You should only create this singleton once because it owns the Core class! (see remark there)
- */
- class _CoreExport Game : public Singleton<Game>
- {
- friend class Singleton<Game>;
- typedef std::vector<shared_ptr<GameState> > GameStateVector;
- typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
- typedef shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
-
- public:
- Game(const std::string& cmdLine);
- ~Game();
-
- void setStateHierarchy(const std::string& str);
- shared_ptr<GameState> getState(const std::string& name);
-
- void run();
- void stop();
-
- void requestState(const std::string& name);
- void requestStates(const std::string& names);
- void popState();
-
- const Clock& getGameClock() { return *this->gameClock_; }
-
- float getAvgTickTime() { return this->avgTickTime_; }
- float getAvgFPS() { return this->avgFPS_; }
-
- void subtractTickTime(int32_t length);
-
- template <class T>
- static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode);
-
- private:
- class _CoreExport GameStateFactory
- {
- public:
- virtual ~GameStateFactory() { }
- static shared_ptr<GameState> fabricate(const GameStateInfo& info);
- template <class T>
- static void createFactory(const std::string& className)
- { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
-
- virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
- static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
- };
- template <class T>
- class TemplateGameStateFactory : public GameStateFactory
- {
- public:
- shared_ptr<GameState> fabricateInternal(const GameStateInfo& info)
- { return shared_ptr<GameState>(new T(info)); }
- };
- // For the factory destruction
- typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard;
-
- struct StatisticsTickInfo
- {
- uint64_t tickTime;
- uint32_t tickLength;
- };
-
- Game(Game&); // don't mess with singletons
-
- void loadGraphics();
- void unloadGraphics();
-
- bool checkState(const std::string& name) const;
- void loadState(const std::string& name);
- void unloadState(const std::string& name);
-
- // Main loop structuring
- void updateGameStateStack();
- void updateGameStates();
- void updateStatistics();
- void updateFPSLimiter();
-
- // ScopeGuard helper function
- void resetChangingState() { this->bChangingState_ = false; }
-
- scoped_ptr<Clock> gameClock_;
- scoped_ptr<Core> core_;
- ObjScopeGuard gsFactoryDestroyer_;
- scoped_ptr<GameConfiguration> configuration_;
-
- GameStateMap constructedStates_;
- GameStateVector loadedStates_;
- GameStateTreeNodePtr rootStateNode_;
- GameStateTreeNodePtr loadedTopStateNode_;
- std::vector<GameStateTreeNodePtr> requestedStateNodes_;
-
- bool bChangingState_;
- bool bAbort_;
-
- // variables for time statistics
- uint64_t statisticsStartTime_;
- std::list<StatisticsTickInfo> statisticsTickTimes_;
- uint32_t periodTime_;
- uint32_t periodTickTime_;
- float avgFPS_;
- float avgTickTime_;
- int excessSleepTime_;
- unsigned int minimumSleepTime_;
-
- static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
- static Game* singletonPtr_s; //!< Pointer to the Singleton
- };
-
- template <class T>
- /*static*/ bool Game::declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bGraphicsMode)
- {
- std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.find(stateName);
- if (it == gameStateDeclarations_s.end())
- {
- GameStateInfo& info = gameStateDeclarations_s[stateName];
- info.stateName = stateName;
- info.className = className;
- info.bIgnoreTickTime = bIgnoreTickTime;
- info.bGraphicsMode = bGraphicsMode;
- }
- else
- {
- COUT(0) << "Error: Cannot declare two GameStates with the same name." << std::endl;
- COUT(0) << " Ignoring second one ('" << stateName << "')." << std::endl;
- }
-
- // Create a factory to delay GameState creation
- GameStateFactory::createFactory<T>(className);
-
- // just a required dummy return value
- return true;
- }
-}
-
-#endif /* _Game_H__ */
Deleted: sandbox_light/src/libraries/core/GameState.cc
===================================================================
--- sandbox_light/src/libraries/core/GameState.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/GameState.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,97 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Implementation of GameState class.
-*/
-
-#include "GameState.h"
-
-#include "util/Debug.h"
-#include "util/Exception.h"
-#include "util/OrxAssert.h"
-#include "Game.h"
-
-namespace orxonox
-{
- /**
- @brief
- Constructor only initialises variables and sets the name permanently.
- */
- GameState::GameState(const GameStateInfo& info)
- : info_(info)
- {
- this->activity_.activating = false;
- this->activity_.active = false;
- this->activity_.deactivating = false;
- this->activity_.suspended = false;
- this->activity_.topState = false;
- this->activity_.updating = false;
- }
-
- /**
- @brief
- Destructor only checks that we don't delete an active state.
- */
- GameState::~GameState()
- {
- OrxAssert(this->activity_.active == false, "Deleting an active GameState is a very bad idea..");
- }
-
- const std::string& GameState::getName() const
- {
- return info_.stateName;
- }
-
- void GameState::activateInternal()
- {
- this->activity_.activating = true;
- this->activate();
- this->activity_.activating = false;
- this->activity_.active = true;
- }
-
- void GameState::deactivateInternal()
- {
- this->activity_.active = false;
- this->activity_.deactivating = true;
- this->activate();
- this->activity_.deactivating = false;
- this->activity_.suspended = false;
- this->activity_.updating = false;
- }
-
- void GameState::updateInternal(const Clock& time)
- {
- this->activity_.updating = true;
- this->update(time);
- this->activity_.updating = false;
- }
-}
Deleted: sandbox_light/src/libraries/core/GameState.h
===================================================================
--- sandbox_light/src/libraries/core/GameState.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/GameState.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,102 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Definition of GameState class.
-*/
-
-#ifndef _GameState_H__
-#define _GameState_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-
-namespace orxonox
-{
- /**
- @brief
- An implementation of a tree to manage game states.
- This leads to a certain hierarchy that is created at runtime.
- To actually use the structure, you will have to derive from it and
- implement 'enter', 'leave' and 'tick'. The latter corresponds to an
- update function.
-
- Internally the tree is managed by two maps per node: One stores all its
- children, grandchildren, etc. by name of the state. The other maps these
- children states to the actual child of the node.
- An example: Foo is a grandchildren of Bar and Foofoo is the Foo's parent.
- Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
- */
- class _CoreExport GameState
- {
- friend class Game;
-
- public:
- /**
- @brief
- Gives information about what the GameState is currently doing
- */
- struct State
- {
- unsigned active : 1;
- unsigned activating : 1;
- unsigned deactivating : 1;
- unsigned updating : 1;
- unsigned suspended : 1;
- unsigned topState : 1;
- };
-
- public:
- GameState(const GameStateInfo& info);
- virtual ~GameState();
-
- const std::string& getName() const;
- State getActivity() const { return activity_; }
- const GameStateInfo& getInfo() const { return info_; }
-
- protected:
- virtual void activate() { }
- virtual void deactivate() { }
- virtual void update(const Clock& time) { }
-
- private:
- void setActivity(State activity);
- void activateInternal();
- void deactivateInternal();
- void updateInternal(const Clock& time);
-
- const GameStateInfo& info_;
- State activity_;
- };
-}
-
-#endif /* _GameState_H__ */
Deleted: sandbox_light/src/libraries/core/Identifier.cc
===================================================================
--- sandbox_light/src/libraries/core/Identifier.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Identifier.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,359 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the Identifier class.
-*/
-
-#include "Identifier.h"
-
-#include <ostream>
-
-#include "util/StringUtils.h"
-#include "ConfigValueContainer.h"
-#include "Factory.h"
-
-namespace orxonox
-{
- // ###############################
- // ### Identifier ###
- // ###############################
- int Identifier::hierarchyCreatingCounter_s = 0;
- unsigned int Identifier::classIDCounter_s = 0;
-
- /**
- @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
- */
- Identifier::Identifier()
- : classID_(classIDCounter_s++)
- {
- this->objects_ = new ObjectListBase(this);
-
- this->bCreatedOneObject_ = false;
- this->bSetName_ = false;
- this->factory_ = 0;
-
- this->bHasConfigValues_ = false;
-
- this->children_ = new std::set<const Identifier*>();
- this->directChildren_ = new std::set<const Identifier*>();
- }
-
- /**
- @brief Destructor: Deletes the list containing the children.
- */
- Identifier::~Identifier()
- {
- delete this->children_;
- delete this->directChildren_;
- delete this->objects_;
-
- if (this->factory_)
- delete this->factory_;
-
- for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
- delete (it->second);
- }
-
- /**
- @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
- */
- std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
- {
- static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers.
- return identifiers;
- }
-
- /**
- @brief Returns an identifier by name and adds it if not available
- @param name The name of the identifier as typeid().name() suggests
- @param proposal A pointer to a newly created identifier for the case of non existance in the map
- @return The identifier (unique instance)
- */
- Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
- {
- std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
-
- if (it != getTypeIDIdentifierMap().end())
- {
- // There is already an entry: return it and delete the proposal
- delete proposal;
- return (*it).second;
- }
- else
- {
- // There is no entry: put the proposal into the map and return it
- getTypeIDIdentifierMap()[name] = proposal;
- return proposal;
- }
- }
-
- /**
- @brief Registers a class, which means that the name and the parents get stored.
- @param parents A list, containing the Identifiers of all parents of the class
- @param bRootClass True if the class is either an Interface or the BaseObject itself
- */
- void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
- {
- // Check if at least one object of the given type was created
- if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
- {
- // If no: We have to store the information and initialize the Identifier
- COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
- if (bRootClass)
- this->initialize(0); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
- else
- this->initialize(parents);
- }
- }
-
- /**
- @brief Initializes the Identifier with a list containing all parents of the class the Identifier belongs to.
- @param parents A list containing all parents
- */
- void Identifier::initialize(std::set<const Identifier*>* parents)
- {
- COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl;
- this->bCreatedOneObject_ = true;
-
- if (parents)
- {
- this->parents_ = (*parents);
- this->directParents_ = (*parents);
-
- // Iterate through all parents
- for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
- {
- // Tell the parent we're one of it's children
- (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
-
- // Erase all parents of our parent from our direct-parent-list
- for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
- {
- // Search for the parent's parent in our direct-parent-list
- for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
- {
- if ((*it1) == (*it2))
- {
- // We've found a non-direct parent in our list: Erase it
- this->directParents_.erase(it2);
- break;
- }
- }
- }
- }
-
- // Now iterate through all direct parents
- for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
- {
- // Tell the parent we're one of it's direct children
- (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
- }
- }
- }
-
- /**
- @brief Destroys all Identifiers. Called when exiting the program.
- */
- void Identifier::destroyAllIdentifiers()
- {
- for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
- delete (it->second);
- }
-
- /**
- @brief Sets the name of the class.
- @param name The name
- */
- void Identifier::setName(const std::string& name)
- {
- if (!this->bSetName_)
- {
- this->name_ = name;
- this->bSetName_ = true;
- Identifier::getIdentifierMapIntern()[name] = this;
- Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
- }
- }
-
- /**
- @brief Creates an object of the type the Identifier belongs to.
- @return The new object
- */
- BaseObject* Identifier::fabricate(BaseObject* creator)
- {
- if (this->factory_)
- {
- return this->factory_->fabricate(creator); // We have to return a BaseObject, because we don't know the exact type.
- }
- else
- {
- COUT(1) << "An error occurred in Identifier.cc:" << std::endl;
- COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
- COUT(1) << "Aborting..." << std::endl;
- abort();
- return NULL;
- }
- }
-
- /**
- @brief Returns true, if the Identifier is at least of the given type.
- @param identifier The identifier to compare with
- */
- bool Identifier::isA(const Identifier* identifier) const
- {
- return (identifier == this || (this->parents_.find(identifier) != this->parents_.end()));
- }
-
- /**
- @brief Returns true, if the Identifier is exactly of the given type.
- @param identifier The identifier to compare with
- */
- bool Identifier::isExactlyA(const Identifier* identifier) const
- {
- return (identifier == this);
- }
-
- /**
- @brief Returns true, if the assigned identifier is a child of the given identifier.
- @param identifier The identifier to compare with
- */
- bool Identifier::isChildOf(const Identifier* identifier) const
- {
- return (this->parents_.find(identifier) != this->parents_.end());
- }
-
- /**
- @brief Returns true, if the assigned identifier is a direct child of the given identifier.
- @param identifier The identifier to compare with
- */
- bool Identifier::isDirectChildOf(const Identifier* identifier) const
- {
- return (this->directParents_.find(identifier) != this->directParents_.end());
- }
-
- /**
- @brief Returns true, if the assigned identifier is a parent of the given identifier.
- @param identifier The identifier to compare with
- */
- bool Identifier::isParentOf(const Identifier* identifier) const
- {
- return (this->children_->find(identifier) != this->children_->end());
- }
-
- /**
- @brief Returns true, if the assigned identifier is a direct parent of the given identifier.
- @param identifier The identifier to compare with
- */
- bool Identifier::isDirectParentOf(const Identifier* identifier) const
- {
- return (this->directChildren_->find(identifier) != this->directChildren_->end());
- }
-
- /**
- @brief Returns the map that stores all Identifiers.
- @return The map
- */
- std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
- {
- static std::map<std::string, Identifier*> identifierMap;
- return identifierMap;
- }
-
- /**
- @brief Returns the map that stores all Identifiers.
- @return The map
- */
- std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
- {
- static std::map<std::string, Identifier*> lowercaseIdentifierMap;
- return lowercaseIdentifierMap;
- }
-
- /**
- @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
- @param varname The name of the variablee
- @param container The container
- */
- void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname);
- if (it != this->configValues_.end())
- {
- COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl;
- delete (it->second);
- }
-
- this->bHasConfigValues_ = true;
- this->configValues_[varname] = container;
- this->configValues_LC_[getLowercase(varname)] = container;
- }
-
- /**
- @brief Returns the ConfigValueContainer of a variable, given by the string of its name.
- @param varname The name of the variable
- @return The ConfigValueContainer
- */
- ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname)
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
- if (it != configValues_.end())
- return ((*it).second);
- else
- return 0;
- }
-
- /**
- @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.
- @param varname The name of the variable in lowercase
- @return The ConfigValueContainer
- */
- ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
- if (it != configValues_LC_.end())
- return ((*it).second);
- else
- return 0;
- }
-
- /**
- @brief Lists the names of all Identifiers in a std::set<const Identifier*>.
- @param out The outstream
- @param list The list (or set) of Identifiers
- @return The outstream
- */
- std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
- {
- for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
- out << (*it)->getName() << " ";
-
- return out;
- }
-}
Deleted: sandbox_light/src/libraries/core/Identifier.h
===================================================================
--- sandbox_light/src/libraries/core/Identifier.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Identifier.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,559 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
-
- The Identifier contains all needed information about the class it belongs to:
- - the name
- - a list with all objects
- - parents and children
- - the factory (if available)
- - the networkID that can be synchronised with the server
- - all configurable variables (if available)
-
- Every object has a pointer to the Identifier of its class. This allows the use isA(...),
- isExactlyA(...), isChildOf(...) and isParentOf(...).
-
- To create the class-hierarchy, the Identifier has some intern functions and variables.
-
- Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier.
-
- SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
- You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
-*/
-
-#ifndef _Identifier_H__
-#define _Identifier_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include <map>
-#include <set>
-#include <string>
-#include <typeinfo>
-
-#include "util/Debug.h"
-#include "util/TypeTraits.h"
-#include "MetaObjectList.h"
-#include "ObjectList.h"
-#include "ObjectListBase.h"
-
-namespace orxonox
-{
- // ###############################
- // ### Identifier ###
- // ###############################
- //! The Identifier is used to identify the class of an object and to store information about the class.
- /**
- The Identifier contains all needed information about the class it belongs to:
- - the name
- - a list with all objects
- - parents and children
- - the factory (if available)
- - the networkID that can be synchronised with the server
- - all configurable variables (if available)
-
- Every object has a pointer to the Identifier of its class. This allows the use isA(...),
- isExactlyA(...), isChildOf(...) and isParentOf(...).
-
- You can't directly create an Identifier, it's just the base-class for ClassIdentifier.
- */
- class _CoreExport Identifier
- {
- template <class T>
- friend class SubclassIdentifier;
-
- friend class Factory;
-
- public:
- /** @brief Sets the Factory. @param factory The factory to assign */
- inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
-
- BaseObject* fabricate(BaseObject* creator);
- bool isA(const Identifier* identifier) const;
- bool isExactlyA(const Identifier* identifier) const;
- bool isChildOf(const Identifier* identifier) const;
- bool isDirectChildOf(const Identifier* identifier) const;
- bool isParentOf(const Identifier* identifier) const;
- bool isDirectParentOf(const Identifier* identifier) const;
-
- /** @brief Returns the list of all existing objects of this class. @return The list */
- inline ObjectListBase* getObjects() const
- { return this->objects_; }
-
- /** @brief Returns the name of the class the Identifier belongs to. @return The name */
- inline const std::string& getName() const { return this->name_; }
- void setName(const std::string& name);
-
- virtual void updateConfigValues(bool updateChildren = true) const = 0;
-
- /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
- inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
- /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
- /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
-
- /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
- inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }
- /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
- /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
-
- /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
- inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
- /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
- /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
-
- /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
- inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
- /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
- /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
- inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
-
-
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
- /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
-
- /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
- /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
-
-
- /** @brief Returns the map that stores all config values. @return The const_iterator */
- inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); }
-
- /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
-
-
- /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
- inline bool hasConfigValues() const { return this->bHasConfigValues_; }
-
- /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
- inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
-
- /** @brief Returns the unique ID of the class */
- FORCEINLINE unsigned int getClassID() const { return this->classID_; }
-
- void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
- ConfigValueContainer* getConfigValueContainer(const std::string& varname);
- ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
-
- void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
-
- static void destroyAllIdentifiers();
-
- protected:
- Identifier();
- Identifier(const Identifier& identifier); // don't copy
- virtual ~Identifier();
-
- static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
-
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static std::map<std::string, Identifier*>& getIdentifierMapIntern();
- /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
-
- /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
- inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
- /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
- inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
-
- ObjectListBase* objects_; //!< The list of all objects of this class
-
- private:
- /**
- @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
- */
- inline static void startCreatingHierarchy()
- {
- hierarchyCreatingCounter_s++;
- COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
- }
-
- /**
- @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
- */
- inline static void stopCreatingHierarchy()
- {
- hierarchyCreatingCounter_s--;
- COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
- }
-
- static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
-
- void initialize(std::set<const Identifier*>* parents);
-
- std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to
- std::set<const Identifier*>* children_; //!< The children of the class the Identifier belongs to
-
- std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to
- std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to
-
- bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
- bool bSetName_; //!< True if the name is set
- std::string name_; //!< The name of the class the Identifier belongs to
- BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available)
- static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
- const unsigned int classID_; //!< Uniquely identifies a class (might not be the same as the networkID_)
- static unsigned int classIDCounter_s; //!< Static counter for the unique classIDs
-
- bool bHasConfigValues_; //!< True if this class has at least one assigned config value
- std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
- std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer
- };
-
- _CoreExport std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list);
-
-
- // ###############################
- // ### ClassIdentifier ###
- // ###############################
- //! The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have.
- /**
- ClassIdentifier is a Singleton, which means that only one object of a given type T exists.
- This makes it possible to store information about a class, sharing them with all
- objects of that class without defining static variables in every class.
-
- To be really sure that not more than exactly one object exists (even with libraries),
- ClassIdentifiers are stored in the Identifier Singleton.
- */
- template <class T>
- class ClassIdentifier : public Identifier
- {
- public:
- static ClassIdentifier<T> *getIdentifier();
- static ClassIdentifier<T> *getIdentifier(const std::string& name);
-
- bool initialiseObject(T* object, const std::string& className, bool bRootClass);
-
- void updateConfigValues(bool updateChildren = true) const;
-
- private:
- static void initialiseIdentifier();
- ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy
- ClassIdentifier()
- {
- }
- ~ClassIdentifier()
- {
- }
-
- static ClassIdentifier<T>* classIdentifier_s;
- };
-
- template <class T>
- ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
-
- /**
- @brief Returns the only instance of this class.
- @return The unique Identifier
- */
- template <class T>
- inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
- {
- // check if the static field has already been filled
- if (ClassIdentifier<T>::classIdentifier_s == 0)
- ClassIdentifier<T>::initialiseIdentifier();
-
- return ClassIdentifier<T>::classIdentifier_s;
- }
-
- /**
- @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
- @param name The name of this Identifier
- @return The Identifier
- */
- template <class T>
- inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
- {
- ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
- identifier->setName(name);
- return identifier;
- }
-
- /**
- @brief Assigns the static field for the identifier singleton.
- */
- template <class T>
- void ClassIdentifier<T>::initialiseIdentifier()
- {
- // Get the name of the class
- std::string name = typeid(T).name();
-
- // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
- ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
-
- // Get the entry from the map
- ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
-
- if (ClassIdentifier<T>::classIdentifier_s == proposal)
- {
- COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
- }
- else
- {
- COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
- }
- }
-
- /**
- @brief Adds an object of the given type to the ObjectList.
- @param object The object to add
- */
- template <class T>
- bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
- {
- if (bRootClass)
- COUT(5) << "*** Register Root-Object: " << className << std::endl;
- else
- COUT(5) << "*** Register Object: " << className << std::endl;
-
- object->identifier_ = this;
- if (Identifier::isCreatingHierarchy())
- {
- if (bRootClass && !object->parents_)
- object->parents_ = new std::set<const Identifier*>();
-
- if (object->parents_)
- {
- this->initializeClassHierarchy(object->parents_, bRootClass);
- object->parents_->insert(object->parents_->end(), this);
- }
-
- object->setConfigValues();
- return true;
- }
- else
- {
- COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
- object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
-
- // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
- object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
- return false;
- }
- }
-
- /**
- @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
- */
- template <class T>
- void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
- {
- if (!this->hasConfigValues())
- return;
-
- for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
- it->setConfigValues();
-
- if (updateChildren)
- for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it)
- (*it)->updateConfigValues(false);
- }
-
-
- // ###############################
- // ### orxonox_cast ###
- // ###############################
- /**
- @brief
- Casts on object of type OrxonoxClass to any derived type that is
- registered in the class hierarchy.
- @return
- Returns NULL if the cast is not possible
- @note
- In case of NULL return (and using MSVC), a dynamic_cast might still be possible if
- a class forgot to register its objects.
- Also note that the function is implemented differently for GCC/MSVC.
- */
- template <class T, class U>
- FORCEINLINE T orxonox_cast(U source)
- {
-#ifdef ORXONOX_COMPILER_MSVC
- typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
- if (source != NULL)
- return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
- else
- return NULL;
-#else
- return dynamic_cast<T>(source);
-#endif
- }
-
-
- // ###############################
- // ### SubclassIdentifier ###
- // ###############################
- //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
- /**
- You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
- If you assign something else, the program aborts.
- Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
- */
- template <class T>
- class SubclassIdentifier
- {
- public:
- /**
- @brief Constructor: Automaticaly assigns the Identifier of the given class.
- */
- SubclassIdentifier()
- {
- this->identifier_ = ClassIdentifier<T>::getIdentifier();
- }
-
- /**
- @brief Copyconstructor: Assigns the given Identifier.
- @param identifier The Identifier
- */
- SubclassIdentifier(Identifier* identifier)
- {
- this->operator=(identifier);
- }
-
- /**
- @brief Overloading of the = operator: assigns the identifier and checks its type.
- @param identifier The Identifier to assign
- @return The SubclassIdentifier itself
- */
- SubclassIdentifier<T>& operator=(Identifier* identifier)
- {
- if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- if (identifier)
- {
- COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
- }
- else
- {
- COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
- }
- }
- else
- {
- this->identifier_ = identifier;
- }
- return *this;
- }
-
- /**
- @brief Overloading of the * operator: returns the assigned identifier.
- */
- inline Identifier* operator*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Overloading of the -> operator: returns the assigned identifier.
- */
- inline Identifier* operator->() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
- */
- inline operator Identifier*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
- @return The new object
- */
- T* fabricate(BaseObject* creator) const
- {
- BaseObject* newObject = this->identifier_->fabricate(creator);
-
- // Check if the creation was successful
- if (newObject)
- {
- return orxonox_cast<T*>(newObject);
- }
- else
- {
- // Something went terribly wrong
- if (this->identifier_)
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
- COUT(1) << "Aborting..." << std::endl;
- }
- else
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
- COUT(1) << "Aborting..." << std::endl;
- }
-
- assert(false);
- return 0;
- }
- }
-
- /** @brief Returns the assigned identifier. @return The identifier */
- inline Identifier* getIdentifier() const
- { return this->identifier_; }
-
- private:
- Identifier* identifier_; //!< The assigned identifier
- };
-}
-
-#endif /* _Identifier_H__ */
Deleted: sandbox_light/src/libraries/core/Iterator.h
===================================================================
--- sandbox_light/src/libraries/core/Iterator.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Iterator.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,306 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition and implementation of the Iterator class.
-
- The Iterator of a given class allows to iterate through an ObjectList. Objects in
- this list are casted to the template argument of the Iterator.
-
- Usage:
- for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it)
- {
- it->someFunction(...);
- myClass* myObject = *it;
- }
-*/
-
-#ifndef _Iterator_H__
-#define _Iterator_H__
-
-#include "CorePrereqs.h"
-
-#include "Identifier.h"
-#include "ObjectListBase.h"
-
-namespace orxonox
-{
- //! The Iterator allows to iterate through a given ObjectList
- template <class T = OrxonoxClass>
- class Iterator
- {
- public:
- /**
- @brief Constructor: Sets the element, whereon the iterator points, to zero.
- */
- inline Iterator()
- {
- this->element_ = 0;
- this->list_ = 0;
- }
-
- /**
- @brief Constructor: Sets this element to the exported element.
- @param exp The exported element
- */
- inline Iterator(const ObjectListBase::Export& exp)
- {
- this->element_ = exp.element_;
- this->list_ = exp.list_;
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to the element of another Iterator.
- @param other The other Iterator
- */
- inline Iterator(const Iterator<T>& other)
- {
- this->element_ = other.element_;
- this->list_ = other.list_;
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to a given element
- @param element The element
- */
- template <class O>
- inline Iterator(ObjectListElement<O>* element)
- {
- this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to the element an ObjectListIterator.
- @param other The ObjectListIterator
- */
- template <class O>
- inline Iterator(const ObjectListIterator<O>& other)
- {
- this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
- }
-
- /**
- @brief Unregisters the Iterator from the ObjectList.
- */
- inline ~Iterator()
- {
- this->list_->unregisterIterator(this);
- }
-
- /**
- @brief Assigns an exported element.
- @param exp The exported element
- */
- inline const Iterator<T>& operator=(const ObjectListBase::Export& exp)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = exp.element_;
- this->list_ = exp.list_;
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Assigns the element of another Iterator.
- @param other The other Iterator
- */
- inline const Iterator<T>& operator=(const Iterator<T>& other)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = other.element_;
- this->list_ = other.list_;
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Assigns a given element.
- @param element The element
- */
- template <class O>
- inline const Iterator<T>& operator=(ObjectListElement<O>* element)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
-
- return (*this);
- return *this;
- }
-
- /**
- @brief Assigns the element of an ObjectListIterator.
- @param other The ObjectListIterator
- */
- template <class O>
- inline const Iterator<T>& operator=(const ObjectListIterator<O>& other)
- {
- if (this->list_)
- this->list_->unregisterIterator(this);
-
- this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
- this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
- this->list_->registerIterator(this);
-
- return (*this);
- }
-
- /**
- @brief Overloading of the ++it operator: Iterator points to the next object in the list.
- @return The Iterator itself
- */
- inline const Iterator<T>& operator++()
- {
- if (this->element_)
- this->element_ = this->element_->next_;
- return *this;
- }
-
- /**
- @brief Overloading of the it++ operator: Iterator points to the next object in the list.
- @return The Iterator itself
- */
- inline Iterator<T> operator++(int i)
- {
- Iterator<T> copy = *this;
- if (this->element_)
- this->element_ = this->element_->next_;
- return copy;
- }
-
- /**
- @brief Overloading of the --it operator: Iterator points to the previous object in the list.
- @return The Iterator itself
- */
- inline const Iterator<T>& operator--()
- {
- if (this->element_)
- this->element_ = this->element_->prev_;
- return *this;
- }
-
- /**
- @brief Overloading of the it-- operator: Iterator points to the previous object in the list.
- @return The Iterator itself
- */
- inline Iterator<T> operator--(int i)
- {
- Iterator<T> copy = *this;
- if (this->element_)
- this->element_ = this->element_->prev_;
- return copy;
- }
-
- /**
- @brief Overloading of the *it operator: returns the pointer to the object.
- @return The object the Iterator points at
- */
- inline T* operator*() const
- {
- if (this->element_)
- return orxonox_cast<T*>(this->element_->objectBase_);
- else
- return 0;
- }
-
- /**
- @brief Overloading of the it-> operator: returns the pointer to the object.
- @return The object the Iterator points at
- */
- inline T* operator->() const
- {
- if (this->element_)
- return orxonox_cast<T*>(this->element_->objectBase_);
- else
- return 0;
- }
-
- /**
- @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
- @return True if the Iterator points to an existing object.
- */
- inline operator bool() const
- {
- return (this->element_ != 0);
- }
-
- /**
- @brief Overloading of the == operator to compare with another Iterator.
- @param compare The other Iterator
- @return True if the iterators point to the same element
- */
- inline bool operator==(const Iterator<T>& compare) const
- {
- return (this->element_ == compare.element_);
- }
-
- /**
- @brief Overloading of the != operator to compare with another Iterator.
- @param compare The other Iterator
- @return True if the iterators point to different elements
- */
- inline bool operator!=(const Iterator<T>& compare) const
- {
- return (this->element_ != compare.element_);
- }
-
- /**
- @brief Increments the Iterator if it points at the given object.
- @param object The object to compare with
- */
- inline void incrementIfEqual(OrxonoxClass* object)
- {
- if (this->element_ && this->element_->objectBase_ == object)
- this->operator++();
- }
-
- protected:
- ObjectListBaseElement* element_; //!< The element the Iterator points at
- ObjectListBase* list_; //!< The list wherein the element is
- };
-
- typedef Iterator<OrxonoxClass> BaseIterator;
-}
-
-#endif /* _Iterator_H__ */
Deleted: sandbox_light/src/libraries/core/Language.cc
===================================================================
--- sandbox_light/src/libraries/core/Language.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Language.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,326 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the Language and the LanguageEntry classes.
-*/
-
-#include "Language.h"
-
-#include <fstream>
-#include <boost/filesystem.hpp>
-
-#include "util/Debug.h"
-#include "Core.h"
-
-namespace orxonox
-{
- // ###############################
- // ### LanguageEntry ###
- // ###############################
- /**
- @brief Constructor: Sets the default entry.
- @param fallbackEntry The default entry
- */
- LanguageEntry::LanguageEntry(const std::string& fallbackEntry)
- {
- this->fallbackEntry_ = fallbackEntry;
- this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned
- this->bLocalisationSet_ = false;
- }
-
- /**
- @brief Sets the localisation of the entry.
- @param localisation The localisation
- */
- void LanguageEntry::setLocalisation(const std::string& localisation)
- {
- // Check if the translation is more than just an empty string
- if ((localisation != "") && (localisation.size() > 0))
- {
- this->localisedEntry_ = localisation;
- this->bLocalisationSet_ = true;
- }
- else
- this->localisedEntry_ = this->fallbackEntry_;
- }
-
- /**
- @brief Sets the default entry.
- @param fallbackEntry The default entry
- */
- void LanguageEntry::setDefault(const std::string& fallbackEntry)
- {
- // If the default entry changes and the translation wasn't set yet, use the new default entry as translation
- if (!this->bLocalisationSet_)
- this->localisedEntry_ = fallbackEntry;
-
- this->fallbackEntry_ = fallbackEntry;
- }
-
- // ###############################
- // ### Language ###
- // ###############################
-
- Language* Language::singletonPtr_s = 0;
-
- /**
- @brief Constructor: Reads the default language file and sets some values.
- */
- Language::Language()
- {
- this->defaultLanguage_ = "default";
- this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
-
- // Read the default language file to create all known LanguageEntry objects
- this->readDefaultLanguageFile();
- }
-
- /**
- @brief Destructor: Deletes all language entries.
- */
- Language::~Language()
- {
- for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
- delete (it->second);
- }
-
- /**
- @brief Creates a new LanguageEntry with a given label and a given default entry.
- @param label The label of the entry
- @param entry The default entry
- @return The created LanguageEntry object
- */
- LanguageEntry* Language::createEntry(const LanguageEntryLabel& label, const std::string& entry)
- {
- std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label);
-
- // Make sure we don't create a duplicate entry
- if (it == this->languageEntries_.end())
- {
- LanguageEntry* newEntry = new LanguageEntry(entry);
- newEntry->setLabel(label);
- this->languageEntries_[label] = newEntry;
- return newEntry;
- }
-
- COUT(2) << "Warning: Language entry " << label << " is duplicate in " << getFilename(this->defaultLanguage_) << "!" << std::endl;
- return it->second;
- }
-
- /**
- @brief Adds a new LanguageEntry, if it's not already existing.
- @param label The label of the entry
- @param entry The default entry
- */
- void Language::addEntry(const LanguageEntryLabel& label, const std::string& entry)
- {
- COUT(5) << "Language: Called addEntry with\n label: " << label << "\n entry: " << entry << std::endl;
- std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label);
- if (it == this->languageEntries_.end())
- {
- // The entry isn't available yet, meaning it's new, so create it
- this->createEntry(label, entry);
- }
- else if (it->second->getDefault().compare(entry) == 0)
- {
- // The entry is available and the default string is the same, so return because everything is fine
- return;
- }
- else
- {
- // The defined default entry is not the same as in the default language file - change it to the new entry
- it->second->setDefault(entry);
- }
-
- // Write the default language file because either a new entry was created or an existing entry has changed
- this->writeDefaultLanguageFile();
-
- }
-
- /**
- @brief Returns the localisation of a given entry.
- @param label The label of the entry
- @return The localisation
- */
- const std::string& Language::getLocalisation(const LanguageEntryLabel& label) const
- {
- std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label);
- if (it != this->languageEntries_.end())
- return it->second->getLocalisation();
- else
- {
- // Uh, oh, an undefined entry was requested: return the default string
- COUT(2) << "Warning: Language entry \"" << label << "\" not found!" << std::endl;
- return this->defaultLocalisation_;
- }
- }
-
- /**
- @brief Creates the name of the language file out of the languages name.
- @param language The name of the language
- @return The filename
- */
- std::string Language::getFilename(const std::string& language)
- {
- return std::string("translation_" + language + ".lang");
- }
-
- /**
- @brief Reads the default language file and creates a LanguageEntry objects for every entry.
- */
- void Language::readDefaultLanguageFile()
- {
- COUT(4) << "Read default language file." << std::endl;
-
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
-
- // This creates the file if it's not existing
- std::ofstream createFile;
- createFile.open(filepath.string().c_str(), std::fstream::app);
- createFile.close();
-
- // Open the file
- std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
-
- if (!file.is_open())
- {
- COUT(1) << "An error occurred in Language.cc:" << std::endl;
- COUT(1) << "Error: Couldn't open file " << getFilename(this->defaultLanguage_) << " to read the default language entries!" << std::endl;
- return;
- }
-
- // Iterate through the file and create the LanguageEntries
- while (file.good() && !file.eof())
- {
- std::string lineString;
- std::getline(file, lineString);
-
- // Check if the line is empty
- if ((lineString != "") && (lineString.size() > 0))
- {
- size_t pos = lineString.find('=');
-
- // Check if the length is at least 3 and if there's an entry before and behind the =
- if (pos > 0 && pos < (lineString.size() - 1) && lineString.size() >= 3)
- this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1));
- else
- {
- COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(this->defaultLanguage_) << std::endl;
- }
- }
- }
-
- file.close();
- }
-
- /**
- @brief Reads the language file of the configured language and assigns the localisation to the corresponding LanguageEntry object.
- */
- void Language::readTranslatedLanguageFile()
- {
- COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
-
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
-
- // Open the file
- std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
-
- if (!file.is_open())
- {
- COUT(1) << "An error occurred in Language.cc:" << std::endl;
- COUT(1) << "Error: Couldn't open file " << getFilename(Core::getLanguage()) << " to read the translated language entries!" << std::endl;
- Core::resetLanguage();
- COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl;
- return;
- }
-
- // Iterate through the file and create the LanguageEntries
- while (file.good() && !file.eof())
- {
- std::string lineString;
- std::getline(file, lineString);
-
- // Check if the line is empty
- if ((lineString != "") && (lineString.size() > 0))
- {
- size_t pos = lineString.find('=');
-
- // Check if the length is at least 3 and if there's an entry before and behind the =
- if (pos > 0 && pos < (lineString.size() - 1) && lineString.size() >= 3)
- {
- std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(lineString.substr(0, pos));
-
- // Check if the entry exists
- if (it != this->languageEntries_.end())
- it->second->setLocalisation(lineString.substr(pos + 1));
- else
- this->createEntry(lineString.substr(0, pos), this->defaultLocalisation_)->setLocalisation(lineString.substr(pos + 1));
- }
- else
- {
- COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getLanguage()) << std::endl;
- }
- }
- }
-
- file.close();
- }
-
- /**
- @brief Writes all default entries to the default language file.
- */
- void Language::writeDefaultLanguageFile() const
- {
- COUT(4) << "Language: Write default language file." << std::endl;
-
- boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
-
- // Open the file
- std::ofstream file;
- file.open(filepath.string().c_str(), std::fstream::out);
-
- if (!file.is_open())
- {
- COUT(1) << "An error occurred in Language.cc:" << std::endl;
- COUT(1) << "Error: Couldn't open file " << getFilename(this->defaultLanguage_) << " to write the default language entries!" << std::endl;
- return;
- }
-
- // Iterate through the list an write the lines into the file
- for (std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
- {
- file << (*it).second->getLabel() << "=" << (*it).second->getDefault() << std::endl;
- }
-
- file.close();
- }
-}
Deleted: sandbox_light/src/libraries/core/Language.h
===================================================================
--- sandbox_light/src/libraries/core/Language.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Language.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,144 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the Language and the LanguageEntry class.
-
- The Language class is used, to get a localisation of a string in the configured language.
- The string is identified by another string, the label of the entry.
- If the translation in the configured language isn't available, the default entry, defined in the code, is used.
-
- Usage:
- - Set the entry with the default string:
- Language::getInstance()->addEntry("label of the entry", "the string to translate");
-
- - Get the localisation of the entry in the configured language:
- std::cout << Language::getInstance()->getLocalisation("name of the entry") << std::endl;
-*/
-
-#ifndef _Language_H__
-#define _Language_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-#include <cassert>
-#include "util/Singleton.h"
-
-#define AddLanguageEntry(label, fallbackstring) \
- orxonox::Language::getInstance().addEntry(label, fallbackstring)
-
-#define GetLocalisation(label) \
- orxonox::Language::getInstance().getLocalisation(label)
-
-
-namespace orxonox
-{
- // ###############################
- // ### LanguageEntry ###
- // ###############################
- //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file.
- class _CoreExport LanguageEntry
- {
- public:
- explicit LanguageEntry(const std::string& fallbackEntry);
- void setLocalisation(const std::string& localisation);
- void setDefault(const std::string& fallbackEntry);
-
- /**
- @brief Returns the localised entry in the configured language.
- @return The translated entry
- */
- inline const std::string& getLocalisation()
- { return this->localisedEntry_; }
-
- /**
- @brief Returns the default entry.
- @return The default entry
- */
- inline const std::string& getDefault()
- { return this->fallbackEntry_; }
-
- /**
- @brief Sets the label of this entry.
- @param label The label
- */
- inline void setLabel(const LanguageEntryLabel& label)
- { this->label_ = label; }
-
- /**
- @brief Returns the label of this entry.
- @return The label
- */
- inline const LanguageEntryLabel& getLabel() const
- { return this->label_; }
-
- private:
- LanguageEntryLabel label_; //!< The label of the entry
- std::string fallbackEntry_; //!< The default entry: Used, if no translation is available or no language configured
- std::string localisedEntry_; //!< The localised entry in the configured language
- bool bLocalisationSet_; //!< True if the translation was set
- };
-
-
- // ###############################
- // ### Language ###
- // ###############################
- //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map.
- class _CoreExport Language : public Singleton<Language>
- {
- friend class Singleton<Language>;
- friend class CoreConfiguration;
-
- public:
- Language();
- ~Language();
-
- void addEntry(const LanguageEntryLabel& label, const std::string& entry);
- const std::string& getLocalisation(const LanguageEntryLabel& label) const;
-
- private:
- Language(const Language&);
-
- void readDefaultLanguageFile();
- void readTranslatedLanguageFile();
- void writeDefaultLanguageFile() const;
- static std::string getFilename(const std::string& language);
- LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry);
-
- std::string defaultLanguage_; //!< The default language
- std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested
- std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
-
- static Language* singletonPtr_s;
- };
-}
-
-#endif /* _Language_H__ */
Deleted: sandbox_light/src/libraries/core/MetaObjectList.cc
===================================================================
--- sandbox_light/src/libraries/core/MetaObjectList.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/MetaObjectList.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,103 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the MetaObjectList class.
-*/
-
-#include "MetaObjectList.h"
-
-#include "util/Debug.h"
-#include "Identifier.h"
-#include "ObjectListBase.h"
-
-namespace orxonox
-{
- // ###############################
- // ### MetaObjectListElement ###
- // ###############################
- /**
- @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
- */
- MetaObjectListElement::~MetaObjectListElement()
- {
- COUT(5) << "*** MetaObjectList: Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << std::endl;
- this->list_->notifyIterators(this->element_->objectBase_);
-
- if (this->element_->next_)
- this->element_->next_->prev_ = this->element_->prev_;
- else
- this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
-
- if (this->element_->prev_)
- this->element_->prev_->next_ = this->element_->next_;
- else
- this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
-
- delete this->element_;
- }
-
-
- // ###############################
- // ### MetaObjectList ###
- // ###############################
- /**
- @brief Constructor: Sets first_ to zero.
- */
- MetaObjectList::MetaObjectList()
- {
- this->first_ = 0;
- }
-
- /**
- @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList.
- */
- MetaObjectList::~MetaObjectList()
- {
- MetaObjectListElement* temp;
- while (this->first_)
- {
- temp = this->first_->next_;
- delete this->first_;
- this->first_ = temp;
- }
- }
-
- /**
- @brief Adds an ObjectList and an element of that list to the MetaObjectList.
- @param list The ObjectList wherein the element is
- @param element The element wherein the object is
- */
- void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
- {
- MetaObjectListElement* temp = this->first_;
- this->first_ = new MetaObjectListElement(list, element);
- this->first_->next_ = temp;
- }
-}
Deleted: sandbox_light/src/libraries/core/MetaObjectList.h
===================================================================
--- sandbox_light/src/libraries/core/MetaObjectList.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/MetaObjectList.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,84 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the MetaObjectList class.
-
- The MetaObjectList is a single-linked list, containing all list-elements and their
- lists wherein the object, owning the MetaObjectList, is registered.
- This allows much faster deletion of objects because no iteration is needed.
-*/
-
-#ifndef _MetaObjectList_H__
-#define _MetaObjectList_H__
-
-#include "CorePrereqs.h"
-
-namespace orxonox
-{
- // ###############################
- // ### MetaObjectListElement ###
- // ###############################
- //! The list-element of the MetaObjectList
- class _CoreExport MetaObjectListElement
- {
- public:
- /**
- @brief Constructor: Creates the list-element with given list and element.
- */
- MetaObjectListElement(ObjectListBase* list, ObjectListBaseElement* element) : next_(0), element_(element), list_(list) {}
- ~MetaObjectListElement();
-
- MetaObjectListElement* next_; //!< The next Element in the list
- ObjectListBaseElement* element_; //!< The list element, containing the object
- ObjectListBase* list_; //!< The list, containing the element
- };
-
-
- // ###############################
- // ### MetaObjectList ###
- // ###############################
- //! The MetaObjectList contains ObjectListBaseElements and their ObjectListBases.
- /**
- The MetaObjectList is a single-linked list, containing all list-elements and their
- lists wherein the object that owns the MetaObjectList is registered.
- This allows much faster deletion of objects because no iteration is needed.
- */
- class _CoreExport MetaObjectList
- {
- public:
- MetaObjectList();
- ~MetaObjectList();
- void add(ObjectListBase* list, ObjectListBaseElement* element);
-
- MetaObjectListElement* first_; //!< The first element in the list
- };
-}
-
-#endif /* _MetaObjectList_H__ */
Deleted: sandbox_light/src/libraries/core/ObjectList.h
===================================================================
--- sandbox_light/src/libraries/core/ObjectList.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ObjectList.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,79 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition and implementation of the ObjectList class.
-
- The ObjectList is a wrapper of an ObjectListBase of a given class.
- Use Iterator<class> to iterate through all objects of the class.
-*/
-
-#ifndef _ObjectList_H__
-#define _ObjectList_H__
-
-#include "CorePrereqs.h"
-
-#include "Identifier.h"
-#include "ObjectListIterator.h"
-
-namespace orxonox
-{
- // ###############################
- // ### ObjectList ###
- // ###############################
- //! The ObjectList contains all objects of the given class.
- /**
- Wraps the ObjectListBase of the corresponding Identifier.
- Use ObjectListIterator<class> to iterate through all objects in the list.
- */
- template <class T>
- class ObjectList
- {
- public:
- typedef ObjectListIterator<T> iterator;
-
- /** @brief Returns an Iterator to the first element in the list. @return The Iterator */
- inline static ObjectListElement<T>* begin()
- { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->begin().element_); }
-
- /** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */
- inline static ObjectListElement<T>* end()
- { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->end().element_); }
-
- /** @brief Returns an Iterator to the last element in the list. @return The Iterator */
- inline static ObjectListElement<T>* rbegin()
- { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rbegin().element_); }
-
- /** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */
- inline static ObjectListElement<T>* rend()
- { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rend().element_); }
- };
-}
-
-#endif /* _ObjectList_H__ */
Deleted: sandbox_light/src/libraries/core/ObjectListBase.cc
===================================================================
--- sandbox_light/src/libraries/core/ObjectListBase.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ObjectListBase.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,106 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the ObjectListBase class.
-
- The ObjectListBase is a double-linked list, used by Identifiers to store all objects of a given class.
- Newly created objects are added through the RegisterObject-macro in its constructor.
-*/
-
-#include "ObjectListBase.h"
-
-#include <set>
-#include "Identifier.h"
-#include "Iterator.h"
-#include "ObjectListIterator.h"
-
-namespace orxonox
-{
- /**
- @brief Constructor: Sets default values.
- */
- ObjectListBase::ObjectListBase(Identifier* identifier)
- {
- this->identifier_ = identifier;
- this->first_ = 0;
- this->last_ = 0;
- }
-
- /**
- @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
- */
- ObjectListBase::~ObjectListBase()
- {
- ObjectListBaseElement* temp;
- while (this->first_)
- {
- temp = this->first_->next_;
- delete this->first_;
- this->first_ = temp;
- }
- }
-
- /**
- @brief Increases all Iterators that currently point on the given element (because it gets removed).
- @param element The element that gets removed
- */
- void ObjectListBase::notifyIterators(OrxonoxClass* object) const
- {
- for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
- ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
- for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
- ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
- }
-
- /**
- @brief Adds a new object to the end of the list.
- @param object The object to add
- @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
- */
- ObjectListBaseElement* ObjectListBase::add(ObjectListBaseElement* element)
- {
- if (!this->last_)
- {
- // If the list is empty
- this->last_ = element;
- this->first_ = this->last_; // There's only one object in the list now
- }
- else
- {
- // If the list isn't empty
- ObjectListBaseElement* temp = this->last_;
- this->last_ = element;
- this->last_->prev_ = temp;
- temp->next_ = this->last_;
- }
-
- return this->last_;
- }
-}
Deleted: sandbox_light/src/libraries/core/ObjectListBase.h
===================================================================
--- sandbox_light/src/libraries/core/ObjectListBase.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ObjectListBase.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,150 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the ObjectListBase class.
-
- The ObjectListBase is a double-linked list, used by Identifiers to store all objects of a given class.
- Newly created objects are added through the RegisterObject-macro in its constructor.
-*/
-
-#ifndef _ObjectListBase_H__
-#define _ObjectListBase_H__
-
-#include "CorePrereqs.h"
-
-#include <vector>
-#include "OrxonoxClass.h"
-
-namespace orxonox
-{
- // ###############################
- // ### ObjectListBaseElement ###
- // ###############################
- //! The list-element of the ObjectListBase
- class _CoreExport ObjectListBaseElement
- {
- public:
- /**
- @brief Constructor: Creates the list-element with an object.
- @param object The object to store
- */
- ObjectListBaseElement(OrxonoxClass* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
-
- ObjectListBaseElement* next_; //!< The next element in the list
- ObjectListBaseElement* prev_; //!< The previous element in the list
- OrxonoxClass* objectBase_;
- };
-
-
- // ###############################
- // ### ObjectListElement ###
- // ###############################
- //! The list-element that actually contains the object
- template <class T>
- class ObjectListElement : public ObjectListBaseElement
- {
- public:
- ObjectListElement(T* object) : ObjectListBaseElement(static_cast<OrxonoxClass*>(object)), object_(object) {}
- T* object_; //!< The object
- };
-
-
- // ###############################
- // ### ObjectListBase ###
- // ###############################
- //! The ObjectListBase contains all objects of a given class.
- /**
- The ObjectListBase is used by Identifiers to store all objects of their given class.
- Use ObjectList<T> to get the list of all T's and Iterator<T> to iterate through them.
- */
- class _CoreExport ObjectListBase
- {
- friend class MetaObjectListElement;
-
- public:
- ObjectListBase(Identifier* identifier);
- ~ObjectListBase();
-
- ObjectListBaseElement* add(ObjectListBaseElement* element);
-
- struct Export
- {
- Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {}
- ObjectListBase* list_;
- ObjectListBaseElement* element_;
- };
-
- /** @brief Returns a pointer to the first element in the list. @return The element */
- inline Export begin() { return ObjectListBase::Export(this, this->first_); }
- /** @brief Returns a pointer to the element after the last element in the list. @return The element */
- inline Export end() { return ObjectListBase::Export(this, 0); }
- /** @brief Returns a pointer to the last element in the list. @return The element */
- inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }
- /** @brief Returns a pointer to the element in front of the first element in the list. @return The element */
- inline Export rend() { return ObjectListBase::Export(this, 0); }
-
- inline void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
- inline void unregisterIterator(void* iterator)
- {
- for (unsigned int i = 0; i < this->iterators_.size(); ++i)
- {
- if (iterators_[i] == iterator)
- {
- iterators_.erase(iterators_.begin() + i);
- break;
- }
- }
- }
- inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }
- inline void unregisterObjectListIterator(void* iterator)
- {
- for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)
- {
- if (objectListIterators_[i] == iterator)
- {
- objectListIterators_.erase(objectListIterators_.begin() + i);
- break;
- }
- }
- }
- void notifyIterators(OrxonoxClass* object) const;
-
- inline Identifier* getIdentifier() const { return this->identifier_; }
-
- private:
- Identifier* identifier_; //!< The Iterator owning this list
- ObjectListBaseElement* first_; //!< The first element in the list
- ObjectListBaseElement* last_; //!< The last element in the list
- std::vector<void*> iterators_; //!< A list of Iterators pointing on an element in this list
- std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
- };
-}
-
-#endif /* _ObjectListBase_H__ */
Deleted: sandbox_light/src/libraries/core/ObjectListIterator.h
===================================================================
--- sandbox_light/src/libraries/core/ObjectListIterator.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ObjectListIterator.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,233 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition and implementation of the Iterator class.
-
- The ObjectListIterator of a given class allows to iterate through the
- ObjectList of this class, containing all objects of that type.
- This is the only way to access the objects stored in an ObjectList.
-
- Usage:
- for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
- {
- it->someFunction(...);
- myClass* myObject = *it;
- }
-*/
-
-#ifndef _ObjectListIterator_H__
-#define _ObjectListIterator_H__
-
-#include "CorePrereqs.h"
-#include "Identifier.h"
-#include "ObjectList.h"
-
-namespace orxonox
-{
- //! The Iterator allows to iterate through the ObjectList of a given class.
- template <class T>
- class ObjectListIterator
- {
- template <class I>
- friend class Iterator;
-
- public:
- /**
- @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
- */
- inline ObjectListIterator()
- {
- this->element_ = 0;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to a given element.
- @param element The element to start with
- */
- inline ObjectListIterator(ObjectListElement<T>* element)
- {
- this->element_ = element;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Constructor: Sets this element to the element of another ObjectListIterator.
- @param other The other ObjectListIterator
- */
- inline ObjectListIterator(const ObjectListIterator<T>& other)
- {
- this->element_ = other.element_;
- ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
- }
-
- /**
- @brief Unregisters the ObjectListIterator from the ObjectList.
- */
- inline ~ObjectListIterator()
- {
- ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this);
- }
-
- /**
- @brief Assigns an ObjectListElement.
- @param element The ObjectListElement
- */
- inline const ObjectListIterator<T>& operator=(ObjectListElement<T>* element)
- {
- this->element_ = element;
- return (*this);
- }
-
- /**
- @brief Assigns the element of another ObjectListIterator.
- @param element The other ObjectListIterator
- */
- inline const ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other)
- {
- this->element_ = other.element_;
- return (*this);
- }
-
- /**
- @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list.
- @return The ObjectListIterator itself
- */
- inline const ObjectListIterator<T>& operator++()
- {
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
- return *this;
- }
-
- /**
- @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list.
- @return The ObjectListIterator itself
- */
- inline ObjectListIterator<T> operator++(int i)
- {
- ObjectListIterator<T> copy = *this;
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
- return copy;
- }
-
- /**
- @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list.
- @return The ObjectListIterator itself
- */
- inline const ObjectListIterator<T>& operator--()
- {
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
- return *this;
- }
-
- /**
- @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list.
- @return The ObjectListIterator itself
- */
- inline ObjectListIterator<T> operator--(int i)
- {
- ObjectListIterator<T> copy = *this;
- if (this->element_)
- this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
- return copy;
- }
-
- /**
- @brief Overloading of the *it operator: returns the pointer to the object.
- @return The object the ObjectListIterator points at
- */
- inline T* operator*() const
- {
- if (this->element_)
- return this->element_->object_;
- else
- return 0;
- }
-
- /**
- @brief Overloading of the it-> operator: returns the pointer to the object.
- @return The object the ObjectListIterator points at
- */
- inline T* operator->() const
- {
- if (this->element_)
- return this->element_->object_;
- else
- return 0;
- }
-
- /**
- @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.
- @return True if the ObjectListIterator points to an existing object.
- */
- inline operator bool() const
- {
- return (this->element_ != 0);
- }
-
- /**
- @brief Overloading of the == operator to compare with another ObjectListIterator.
- @param compare The other ObjectListIterator
- @return True if the ObjectListIterator point to the same element
- */
- inline bool operator==(const ObjectListIterator<T>& compare) const
- {
- return (this->element_ == compare.element_);
- }
-
- /**
- @brief Overloading of the != operator to compare with another ObjectListIterator.
- @param compare The other ObjectListIterator
- @return True if the ObjectListIterator point to different elements
- */
- inline bool operator!=(const ObjectListIterator<T>& compare) const
- {
- return (this->element_ != compare.element_);
- }
-
- /**
- @brief Increments the ObjectListIterator if it points at the given object.
- @param object The object to compare with
- */
- inline void incrementIfEqual(OrxonoxClass* object)
- {
- if (this->element_ && this->element_->objectBase_ == object)
- this->operator++();
- }
-
- private:
- ObjectListElement<T>* element_; //!< The element the Iterator points at
- };
-}
-
-#endif /* _ObjectListIterator_H__ */
Deleted: sandbox_light/src/libraries/core/OrxonoxClass.cc
===================================================================
--- sandbox_light/src/libraries/core/OrxonoxClass.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/OrxonoxClass.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,137 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the OrxonoxClass Class.
-*/
-
-#include "OrxonoxClass.h"
-
-#include "MetaObjectList.h"
-#include "Identifier.h"
-
-namespace orxonox
-{
- /** @brief Constructor: Sets the default values. */
- OrxonoxClass::OrxonoxClass()
- {
- this->identifier_ = 0;
- this->parents_ = 0;
- this->metaList_ = new MetaObjectList();
- }
-
- /** @brief Destructor: Deletes, if existing, the list of the parents. */
- OrxonoxClass::~OrxonoxClass()
- {
- delete this->metaList_;
-
- // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
- if (this->parents_)
- delete this->parents_;
- }
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
- bool OrxonoxClass::isA(const Identifier* identifier)
- { return this->getIdentifier()->isA(identifier); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- bool OrxonoxClass::isExactlyA(const Identifier* identifier)
- { return this->getIdentifier()->isExactlyA(identifier); }
- /** @brief Returns true if the objects class is a child of the given type. */
- bool OrxonoxClass::isChildOf(const Identifier* identifier)
- { return this->getIdentifier()->isChildOf(identifier); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
- { return this->getIdentifier()->isDirectChildOf(identifier); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- bool OrxonoxClass::isParentOf(const Identifier* identifier)
- { return this->getIdentifier()->isParentOf(identifier); }
- /** @brief Returns true if the objects class is a direct parent of the given type. */
- bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
- { return this->getIdentifier()->isDirectParentOf(identifier); }
-
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
- template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isA(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a child of the given type. */
- template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct parent of the given type. */
- template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B>* identifier)
- { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
-
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
- template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isA(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a child of the given type. */
- template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
- /** @brief Returns true if the objects class is a direct parent of the given type. */
- template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B> identifier)
- { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
-
-
- /** @brief Returns true if the objects class is of the given type or a derivative. */
- bool OrxonoxClass::isA(const OrxonoxClass* object)
- { return this->getIdentifier()->isA(object->getIdentifier()); }
- /** @brief Returns true if the objects class is exactly of the given type. */
- bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
- { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
- /** @brief Returns true if the objects class is a child of the given type. */
- bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
- { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
- { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
- /** @brief Returns true if the objects class is a parent of the given type. */
- bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
- { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
- /** @brief Returns true if the objects class is a direct child of the given type. */
- bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
- { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
-}
Deleted: sandbox_light/src/libraries/core/OrxonoxClass.h
===================================================================
--- sandbox_light/src/libraries/core/OrxonoxClass.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/OrxonoxClass.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,128 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Declaration of the OrxonoxClass Class.
-
- All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
- It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
-*/
-
-#ifndef _OrxonoxClass_H__
-#define _OrxonoxClass_H__
-
-#include "CorePrereqs.h"
-
-#include <set>
-#include <vector>
-
-namespace orxonox
-{
- //! The class all objects and interfaces of the game-logic (not the engine) are derived from.
- /**
- The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
- OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
- */
- class _CoreExport OrxonoxClass
- {
- template <class T>
- friend class ClassIdentifier;
-
- public:
- OrxonoxClass();
- virtual ~OrxonoxClass();
-
- /** @brief Function to collect the SetConfigValue-macro calls. */
- void setConfigValues() {};
-
- /** @brief Returns the Identifier of the object. @return The Identifier */
- inline Identifier* getIdentifier() const { return this->identifier_; }
-
- bool isA(const Identifier* identifier);
- bool isExactlyA(const Identifier* identifier);
- bool isChildOf(const Identifier* identifier);
- bool isDirectChildOf(const Identifier* identifier);
- bool isParentOf(const Identifier* identifier);
- bool isDirectParentOf(const Identifier* identifier);
-
- template <class B> bool isA(const SubclassIdentifier<B>* identifier);
- template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier);
- template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier);
- template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier);
-
- template <class B> bool isA(const SubclassIdentifier<B> identifier);
- template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier);
- template <class B> bool isChildOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isParentOf(const SubclassIdentifier<B> identifier);
- template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier);
-
- bool isA(const OrxonoxClass* object);
- bool isExactlyA(const OrxonoxClass* object);
- bool isChildOf(const OrxonoxClass* object);
- bool isDirectChildOf(const OrxonoxClass* object);
- bool isParentOf(const OrxonoxClass* object);
- bool isDirectParentOf(const OrxonoxClass* object);
-
- /**
- @brief
- Returns a valid pointer of any derived type that is
- registered in the class hierarchy.
- @return
- Returns NULL if the no pointer was found.
- */
- template <class T>
- FORCEINLINE T* getDerivedPointer(unsigned int classID)
- {
- for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
- {
- if (this->objectPointers_[i].first == classID)
- return static_cast<T*>(this->objectPointers_[i].second);
- }
- return NULL;
- }
- //! Const version of getDerivedPointer
- template <class T>
- FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
- {
- return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);
- }
-
- private:
- Identifier* identifier_; //!< The Identifier of the object
- std::set<const Identifier*>* parents_; //!< List of all parents of the object
- MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
- //! 'Fast map' that holds this-pointers of all derived types
- std::vector<std::pair<unsigned int, void*> > objectPointers_;
- };
-}
-
-#endif /* _OrxonoxClass_H__ */
Deleted: sandbox_light/src/libraries/core/Thread.cc
===================================================================
--- sandbox_light/src/libraries/core/Thread.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Thread.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,129 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * ...
- *
- */
-
-#include "Thread.h"
-
-#include <cassert>
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread_time.hpp>
-
-#include "util/Sleep.h"
-#include "Executor.h"
-
-namespace orxonox
-{
- boost::posix_time::millisec THREAD_WAIT_BEFORE_DETACH(1000);
-
-
- Thread::Thread():
- executor_(0),
- isWorking_(false),
- stopThread_(false)
- {
- this->executorMutex_ = new boost::mutex;
- this->isWorkingMutex_ = new boost::mutex;
- this->stopThreadMutex_ = new boost::mutex;
- this->workerThread_ = new boost::thread( boost::bind(&Thread::threadLoop, this) );
- }
-
- Thread::~Thread()
- {
- this->stopThreadMutex_->lock();
- this->stopThread_ = true;
- this->stopThreadMutex_->unlock();
- if( !this->workerThread_->timed_join( THREAD_WAIT_BEFORE_DETACH ) )
- assert(0); // this should not happen
- delete this->workerThread_;
- delete this->executorMutex_;
- delete this->stopThreadMutex_;
- delete this->isWorkingMutex_;
- }
-
- bool Thread::isWorking()
- {
- this->isWorkingMutex_->lock();
- bool isWorking = this->isWorking_;
- this->isWorkingMutex_->unlock();
- return isWorking;
- }
-
- bool Thread::evaluateExecutor( Executor* executor )
- {
- this->isWorkingMutex_->lock();
- this->isWorking_=true;
- this->isWorkingMutex_->unlock();
- this->executorMutex_->lock();
- this->executor_ = executor;
- this->executorMutex_->unlock();
- return true;
- }
-
- void Thread::threadLoop()
- {
- bool stopThread = false;
- while( !stopThread )
- {
- //this->executorMutex_->lock();
- Executor* executor = this->executor_;
- //this->executorMutex_->unlock();
- if( executor )
- {
- (*executor)();
- this->executorMutex_->lock();
- delete this->executor_;
- this->executor_ = 0;
- this->executorMutex_->unlock();
- this->isWorkingMutex_->lock();
- this->isWorking_=false;
- this->isWorkingMutex_->unlock();
- }
- else
- {
- this->workerThread_->yield();
- }
- //this->stopThreadMutex_->lock();
- stopThread = this->stopThread_;
- //this->stopThreadMutex_->unlock();
- }
- }
-
- void Thread::waitUntilFinished()
- {
- bool stillWorking = true;
- while( stillWorking )
- {
- this->isWorkingMutex_->lock();
- stillWorking = this->isWorking_;
- this->isWorkingMutex_->unlock();
- if( stillWorking )
- msleep( 1 );
- }
- }
-}
Deleted: sandbox_light/src/libraries/core/Thread.h
===================================================================
--- sandbox_light/src/libraries/core/Thread.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/Thread.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,64 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _Thread_H__
-#define _Thread_H__
-
-#include "CorePrereqs.h"
-
-namespace boost{
- class recursive_mutex;
-}
-
- namespace orxonox
-{
- class _CoreExport Thread
- {
- public:
- Thread();
- virtual ~Thread();
-
- bool isWorking();
- void waitUntilFinished();
- bool evaluateExecutor( Executor* executor );
-
- private:
- void threadLoop();
-
- Executor* executor_;
- bool isWorking_;
- bool stopThread_;
- boost::thread* workerThread_;
- boost::mutex* executorMutex_;
- boost::mutex* isWorkingMutex_;
- boost::mutex* stopThreadMutex_;
- };
-
- }
-
-#endif /* _Thread_H__ */
Deleted: sandbox_light/src/libraries/core/ThreadPool.cc
===================================================================
--- sandbox_light/src/libraries/core/ThreadPool.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ThreadPool.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,115 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * ...
- *
- */
-
-#include "ThreadPool.h"
-#include "Thread.h"
-#include <cassert>
-
-namespace orxonox
-{
-
- ThreadPool::ThreadPool()
- {
- }
-
- ThreadPool::~ThreadPool()
- {
- unsigned int a = this->setNrOfThreads(0);
- assert(a == 0);
- }
-
- void ThreadPool::addThreads( unsigned int nr )
- {
- for( unsigned int i=0; i<nr; i++ )
- this->threadPool_.push_back(new Thread());
- }
- unsigned int ThreadPool::removeThreads( unsigned int nr )
- {
- unsigned int i=0;
- std::vector<Thread*>::iterator it;
- for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; )
- {
- if( ! (*it)->isWorking() )
- {
- Thread* temp = *it;
- it=this->threadPool_.erase( it );
- delete temp;
- ++i;
- }
- else
- ++it;
- }
- return i;
- }
- unsigned int ThreadPool::setNrOfThreads( unsigned int nr )
- {
- unsigned int currentsize = this->threadPool_.size();
- if ( nr < currentsize )
- return currentsize - removeThreads( currentsize - nr );
- else if ( nr == currentsize )
- return currentsize;
- else
- {
- addThreads( nr - currentsize );
- return nr;
- }
- }
-
- bool ThreadPool::passFunction( Executor* executor, bool addThread )
- {
- std::vector<Thread*>::iterator it;
- for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
- {
- if ( ! (*it)->isWorking() )
- {
- bool b = (*it)->evaluateExecutor( executor );
- assert(b); // if b is false then there is some code error
- return true;
- }
- }
- if ( addThread )
- {
- addThreads( 1 );
- bool b = this->threadPool_.back()->evaluateExecutor( executor ); // access the last element
- assert(b);
- return true;
- }
- else
- return false;
- }
-
- void ThreadPool::synchronise()
- {
- std::vector<Thread*>::iterator it;
- for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
- {
- (*it)->waitUntilFinished();
- }
- }
-
-}
Deleted: sandbox_light/src/libraries/core/ThreadPool.h
===================================================================
--- sandbox_light/src/libraries/core/ThreadPool.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/core/ThreadPool.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,57 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _ThreadPool_H__
-#define _ThreadPool_H__
-
-#include "CorePrereqs.h"
-
-#include <vector>
-
- namespace orxonox
-{
- class _CoreExport ThreadPool
- {
- public:
- ThreadPool();
- virtual ~ThreadPool();
-
- void addThreads( unsigned int nr );
- unsigned int removeThreads( unsigned int nr );
- unsigned int setNrOfThreads( unsigned int nr );
-
- bool passFunction( Executor* executor, bool addThread=false );
- void synchronise();
-
- private:
- std::vector<Thread*> threadPool_;
-
- };
-}
-
-#endif /* _ThreadPool_H__ */
Modified: sandbox_light/src/libraries/util/CMakeLists.txt
===================================================================
--- sandbox_light/src/libraries/util/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -18,14 +18,11 @@
#
SET_SOURCE_FILES(UTIL_SRC_FILES
- CRC32.cc
Exception.cc
- ExprParser.cc
Math.cc
MultiType.cc
OutputBuffer.cc
OutputHandler.cc
- Scope.cc
SignalHandler.cc
Sleep.cc
StringUtils.cc
@@ -42,8 +39,7 @@
DEFINE_SYMBOL
"UTIL_SHARED_BUILD"
LINK_LIBRARIES
- ${CEGUI_LIBRARY}
- ${OGRE_LIBRARY}
+ ogremath_orxonox
SOURCE_FILES
${UTIL_SRC_FILES}
)
Deleted: sandbox_light/src/libraries/util/CRC32.cc
===================================================================
--- sandbox_light/src/libraries/util/CRC32.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/CRC32.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,59 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * ...
- * Co-authors:
- * ...
- *
- */
-
-#include "CRC32.h"
-
-namespace orxonox
-{
- void calcCRCBit(uint32_t &crc32, int bit)
- {
- int hbit = (crc32 & 0x80000000) ? 1 : 0;
- if (hbit != bit)
- crc32 = (crc32 << 1) ^ UTIL_CRC32POLY;
- else
- crc32 = crc32 << 1;
- }
-
- uint32_t calcCRC(unsigned char *data, unsigned int dataLength)
- {
- uint32_t crc32 = 0;
- for(unsigned int i = 0; i < dataLength; i++)
- {
- calcCRCBit(crc32, (data[i] & 0x1) >> 0); // 1st bit
- calcCRCBit(crc32, (data[i] & 0x2) >> 1); // 2nd bit
- calcCRCBit(crc32, (data[i] & 0x3) >> 2); // 3rd bit
- calcCRCBit(crc32, (data[i] & 0x4) >> 3); // 4th bit
- calcCRCBit(crc32, (data[i] & 0x5) >> 4); // 5th bit
- calcCRCBit(crc32, (data[i] & 0x6) >> 5); // 6th bit
- calcCRCBit(crc32, (data[i] & 0x7) >> 6); // 7th bit
- calcCRCBit(crc32, (data[i] & 0x8) >> 7); // 8th bit
- }
- return crc32;
- }
-}
-
Deleted: sandbox_light/src/libraries/util/CRC32.h
===================================================================
--- sandbox_light/src/libraries/util/CRC32.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/CRC32.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,43 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * ...
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _Util_CRC_H__
-#define _Util_CRC_H__
-
-#include "UtilPrereqs.h"
-
-namespace orxonox
-{
- const unsigned int UTIL_CRC32POLY = 0x04C11DB7; /* CRC-32 Polynom */
-
- _UtilExport void calcCRCBit(uint32_t &crc32, int bit);
-
- _UtilExport uint32_t calcCRC(unsigned char *data, unsigned int dataLength);
-}
-
-#endif /* _Util_CRC_H__ */
Deleted: sandbox_light/src/libraries/util/ExprParser.cc
===================================================================
--- sandbox_light/src/libraries/util/ExprParser.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/ExprParser.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,453 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Declaration of FloatParser
-*/
-
-#include "ExprParser.h"
-#include <cmath>
-#include <cstring>
-#include <cstdlib>
-
-// macros for easier if, else statements
-#define CASE_1(var) if (!strcmp(SWITCH,var))
-#define CASE(var) else if (!strcmp(SWITCH,var))
-#define CASE_ELSE else
-
-//! skip white spaces
-#define PARSE_BLANKS while (*reading_stream == ' ') ++reading_stream
-
-namespace orxonox
-{
- ExprParser::ExprParser(const std::string& str)
- {
- this->failed_ = false;
- this->reading_stream = str.c_str();
- if (str.size() == 0 || *reading_stream == '\0')
- {
- this->failed_ = true;
- this->result_ = 0.0;
- }
- else
- {
- this->result_ = parse_expr_8();
- this->remains_ = reading_stream;
- }
- }
-
- //Private functions:
- /******************/
- double ExprParser::parse_argument()
- {
- double value = parse_expr_8();
- if (*reading_stream == ',')
- {
- ++reading_stream;
- return value;
- }
- else
- {
- this->failed_ = true;
- return 0;
- }
- }
-
- double ExprParser::parse_last_argument()
- {
- double value = parse_expr_8();
- if (*reading_stream == ')')
- {
- ++reading_stream;
- return value;
- }
- else
- {
- this->failed_ = true;
- return 0;
- }
- }
-
- double ExprParser::parse_expr_8()
- {
- double value = parse_expr_7();
- for(;;)
- {
- switch (op)
- {
- case oder:
- value = parse_expr_7() || value;
- break;
- default: return value;
- }
- };
- }
-
-
- double ExprParser::parse_expr_7()
- {
- double value = parse_expr_6();
- for(;;)
- {
- switch (op)
- {
- case und:
- value = value && parse_expr_6();
- break;
- default: return value;
- }
- };
- }
-
- double ExprParser::parse_expr_6()
- {
- double value = parse_expr_5();
- for(;;)
- {
- switch (op)
- {
- case gleich:
- value = (value == parse_expr_5());
- break;
- case ungleich:
- value = (value != parse_expr_5());
- break;
- default:
- return value;
- }
- };
- }
-
- double ExprParser::parse_expr_5()
- {
- double value = parse_expr_4();
- for(;;)
- {
- switch (op)
- {
- case kleiner:
- value = (value < parse_expr_4());
- break;
- case kleinergleich:
- value = (value <= parse_expr_4());
- break;
- case groesser:
- value = (value > parse_expr_4());
- break;
- case groessergleich:
- value = (value >= parse_expr_4());
- break;
- default:
- return value;
- }
- };
- }
-
- double ExprParser::parse_expr_4()
- {
- double value = parse_expr_3();
- for(;;)
- {
- switch (op)
- {
- case b_plus:
- value += parse_expr_3();
- break;
- case b_minus:
- value -= parse_expr_3();
- break;
- default:
- return value;
- }
- };
- }
-
- double ExprParser::parse_expr_3()
- {
- double value = parse_expr_2();
- for(;;)
- {
- switch (op)
- {
- case mal:
- value *= parse_expr_2();
- break;
- case durch:
- value /= parse_expr_2();
- break;
- case modulo:
- {
- double temp = parse_expr_2();
- value = value - floor(value/temp)*temp;
- break;
- }
- default:
- return value;
- }
- };
- }
-
- double ExprParser::parse_expr_2()
- {
- double value = parse_expr_1();
- while (*reading_stream != '\0')
- {
- op = parse_binary_operator();
- switch (op)
- {
- case hoch:
- value = pow(value,parse_expr_1());
- break;
- default:
- return value;
- }
- };
- op = undef;
- return value;
- }
-
- double ExprParser::parse_expr_1()
- {
- PARSE_BLANKS;
- double value;
-
- unary_operator op = parse_unary_operator();
- PARSE_BLANKS;
-
- if (*reading_stream == '\0')
- {
- // end of string
- this->failed_ = true;
- return 0;
- }
- else if ((*reading_stream > 47 && *reading_stream < 59) || *reading_stream == 46)
- { // number
- value = strtod(reading_stream, const_cast<char**>(&reading_stream));
- }
- else if ((*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46)
- { // variable or function
- char* word = new char[256];
- parse_word(word);
- PARSE_BLANKS;
- if (*reading_stream == '(')
- {
- ++reading_stream;
-#define SWITCH word
- CASE_1("sin")
- value = sin(parse_last_argument());
- CASE("asin")
- value = asin(parse_last_argument());
- CASE("sinh")
- value = sinh(parse_last_argument());
- CASE("asinh")
- {
- value = parse_last_argument();
- value = log(sqrt(pow(value, 2) + 1) + value);
- }
- CASE("cos")
- value = cos(parse_last_argument());
- CASE("acos")
- value = acos(parse_last_argument());
- CASE("cosh")
- value = cosh(parse_last_argument());
- CASE("acosh")
- {
- value = parse_last_argument();
- value = log(sqrt(pow(value, 2) - 1) + value);
- }
- CASE("tan")
- value = tan(parse_last_argument());
- CASE("atan")
- value = atan(parse_last_argument());
- CASE("atan2")
- value = atan2(parse_argument(),parse_last_argument());
- CASE("tanh")
- value = tanh(parse_last_argument());
- CASE("atanh")
- {
- value = parse_last_argument();
- value = 0.5*log((value + 1)/(value - 1));
- }
- CASE("int")
- value = floor(parse_last_argument());
- CASE("floor")
- value = floor(parse_last_argument());
- CASE("ceil")
- value = ceil(parse_last_argument());
- CASE("abs")
- value = fabs(parse_last_argument());
- CASE("exp")
- value = exp(parse_last_argument());
- CASE("log")
- value = log10(parse_last_argument());
- CASE("ln")
- value = log(parse_last_argument());
- CASE("sign")
- {
- value = parse_last_argument();
- value = (value>0 ? 1 : (value<0 ? -1 : 0));
- }
- CASE("sqrt")
- value = sqrt(parse_last_argument());
- CASE("degrees")
- value = parse_last_argument()*180/3.1415926535897932;
- CASE("radians")
- value = parse_last_argument()*3.1415926535897932/180;
- CASE("mod")
- {
- value = parse_argument();
- double value2 = parse_last_argument();
- value = value - floor(value/value2)*value2;
- }
- CASE("pow")
- value = pow(parse_argument(),parse_last_argument());
- CASE("div")
- value = floor(parse_argument()/parse_last_argument());
- CASE("max")
- value = std::max(parse_argument(),parse_last_argument());
- CASE("min")
- value = std::min(parse_argument(),parse_last_argument());
- CASE_ELSE
- {
- this->failed_ = true;
- delete[] word;
- return 0;
- }
- }
- else
- {
-#define SWITCH word
- CASE_1("pi")
- value = 3.1415926535897932;
- CASE("e")
- value = 2.7182818284590452;
- CASE_ELSE
- {
- this->failed_ = true;
- delete[] word;
- return 0;
- }
- }
- delete[] word;
- }
- else if (*reading_stream == 40)
- { // expresion in paranthesis
- ++reading_stream;
- value = parse_last_argument();
- }
- else
- {
- this->failed_ = true;
- return 0;
- }
-
- PARSE_BLANKS;
- switch (op)
- {
- case u_nicht: return !value;
- case u_plus: return value;
- case u_minus: return -value;
- default:
- this->failed_ = true;
- return 0;
- }
- }
-
- char* ExprParser::parse_word(char* str)
- {
- char* word = str;
- int counter = 0;
- while ((*reading_stream > 47 && *reading_stream < 58) || (*reading_stream > 64 && *reading_stream < 91) || (*reading_stream > 96 && *reading_stream < 123) || *reading_stream == 46)
- {
- *word++ = *reading_stream++;
- counter++;
- if (counter > 255)
- {
- this->failed_ = true;
- return '\0';
- }
- };
- *word = '\0';
- return str;
- }
-
- ExprParser::binary_operator ExprParser::parse_binary_operator()
- {
- binary_operator op;
- switch (*reading_stream)
- {
- case '+': op = b_plus; break;
- case '-': op = b_minus; break;
- case '*': op = mal; break;
- case '/': op = durch; break;
- case '^': op = hoch; break;
- case '%': op = modulo; break;
- case '&': op = und; break;
- case '|': op = oder; break;
- case '=': op = gleich; break;
- case '!': op = b_nicht; break;
- case '<': op = kleiner; break;
- case '>': op = groesser; break;
- default: return undef;
- }
- if (*++reading_stream == '=')
- {
- if (op > 9)
- {
- ++reading_stream;
- return (binary_operator)(op + 3);
- }
- else
- {
- --reading_stream;
- return undef;
- }
- }
- else
- return op;
- }
-
- ExprParser::unary_operator ExprParser::parse_unary_operator()
- {
- switch (*reading_stream)
- {
- case '!':
- ++reading_stream;
- return u_nicht;
- case '+':
- ++reading_stream;
- return u_plus;
- case '-':
- ++reading_stream;
- return u_minus;
- default :
- return u_plus;
- }
- }
-}
Deleted: sandbox_light/src/libraries/util/ExprParser.h
===================================================================
--- sandbox_light/src/libraries/util/ExprParser.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/ExprParser.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,110 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Declaration of FloatParser
-*/
-
-#ifndef _FloatParser_H__
-#define _FloatParser_H__
-
-#include "UtilPrereqs.h"
-#include <string>
-
-namespace orxonox
-{
- class _UtilExport ExprParser
- {
- public:
- enum binary_operator
- {
- b_plus,
- b_minus,
- mal,
- durch,
- modulo,
- hoch,
- undef,
- oder,
- und,
- gleich,
- b_nicht,
- kleiner,
- groesser,
- ungleich,
- kleinergleich,
- groessergleich
- };
-
- enum unary_operator
- {
- u_plus,
- u_minus,
- u_nicht
- };
-
-
- ExprParser(const std::string& str);
- const std::string& getRemains() { return this->remains_; }
- double getResult() { return this->result_; }
- bool getSuccess() { return !this->failed_; }
-
- private:
- double parse_expr_1();
- double parse_expr_2();
- double parse_expr_3();
- double parse_expr_4();
- double parse_expr_5();
- double parse_expr_6();
- double parse_expr_7();
- double parse_expr_8();
- char* parse_word(char* str);
- binary_operator parse_binary_operator();
- unary_operator parse_unary_operator();
-
- double parse_argument();
- double parse_last_argument();
-
- binary_operator op;
- const char* reading_stream;
- bool failed_;
- double result_;
- std::string remains_;
-
- };
-
- //Endzeichen für float expression: ')', '}', ']', ',', ';'
- _UtilExport bool parse_float(char* const, char**, double*);
- //Endzeichen angegeben
- _UtilExport bool parse_float(char* const, char**, char, double*);
- //Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen)
- _UtilExport bool parse_vector_float(char* const, char**, bool, double*);
-}
-
-#endif /* _FloatParser_H__ */
Modified: sandbox_light/src/libraries/util/Math.cc
===================================================================
--- sandbox_light/src/libraries/util/Math.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/Math.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -33,12 +33,8 @@
#include "Math.h"
-#include <OgrePlane.h>
-
#include "MathConvert.h"
#include "SubString.h"
-// Do not remove this include, it avoids linker errors.
-#include "mbool.h"
namespace orxonox
{
@@ -82,141 +78,6 @@
return in;
}
-
- /**
- @brief Gets the angle between my viewing direction and the direction to the position of the other object.
- @param myposition My position
- @param mydirection My viewing direction
- @param otherposition The position of the other object
- @return The angle
-
- @example
- If the other object is exactly in front of me, the function returns 0.
- If the other object is exactly behind me, the function returns pi.
- If the other object is exactly right/left to me (or above/below), the function returns pi/2.
- */
- float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition)
- {
- orxonox::Vector3 distance = otherposition - myposition;
- float distancelength = distance.length();
- if (distancelength == 0)
- return 0;
- else
- return acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1));
- }
-
- /**
- @brief Gets the 2D viewing direction (up/down, left/right) to the position of the other object.
- @param myposition My position
- @param mydirection My viewing direction
- @param myorthonormal My orthonormalvector (pointing upwards through my head)
- @param otherposition The position of the other object
- @return The viewing direction
-
- @example
- If the other object is exactly in front of me, the function returns Vector2(0, 0).
- If the other object is exactly at my left, the function returns Vector2(-1, 0).
- If the other object is exactly at my right, the function returns Vector2(1, 0).
- If the other object is only a bit at my right, the function still returns Vector2(1, 0).
- If the other object is exactly above me, the function returns Vector2(0, 1).
- */
- orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
- {
- orxonox::Vector3 distance = otherposition - myposition;
-
- // project difference vector on our plane
- orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
-
- float projectionlength = projection.length();
- if (projectionlength == 0)
- {
- if (myposition.dotProduct(otherposition) >= 0)
- return orxonox::Vector2(0, 0);
- else
- return orxonox::Vector2(0, 1);
- }
-
- float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
- float sin_value = sqrt( 1 - cos_value*cos_value );
-
- if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
- return orxonox::Vector2( sin_value, cos_value );
- else
- return orxonox::Vector2( -sin_value, cos_value );
- }
-
- /**
- @brief Gets the 2D viewing direction (up/down, left/right) to the position of the other object, multiplied with the viewing distance to the object (0° = 0, 180° = 1).
- @param myposition My position
- @param mydirection My viewing direction
- @param myorthonormal My orthonormalvector (pointing upwards through my head)
- @param otherposition The position of the other object
- @return The viewing direction
-
- @example
- If the other object is exactly in front of me, the function returns Vector2(0, 0).
- If the other object is exactly at my left, the function returns Vector2(-0.5, 0).
- If the other object is exactly at my right, the function returns Vector2(0.5, 0).
- If the other object is only a bit at my right, the function still returns Vector2(0.01, 0).
- If the other object is exactly above me, the function returns Vector2(0, 0.5).
- */
- orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
- {
- orxonox::Vector3 distance = otherposition - myposition;
-
- // project difference vector on our plane
- orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
-
- float projectionlength = projection.length();
- if (projectionlength == 0)
- {
- if (myposition.dotProduct(otherposition) >= 0)
- return orxonox::Vector2(0, 0);
- else
- return orxonox::Vector2(0, 1);
- }
- //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
-
- float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
- float sin_value = sqrt( 1 - cos_value*cos_value );
-
- float distancelength = distance.length();
- if (distancelength == 0) return orxonox::Vector2(0, 0);
- float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
-
- if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
- return orxonox::Vector2( sin_value * radius, cos_value * radius);
- else
- return orxonox::Vector2( -sin_value * radius, cos_value * radius);
- }
-
- /**
- @brief Returns the predicted position I have to aim at, if I want to hit a moving target with a moving projectile.
- @param myposition My position
- @param projectilespeed The speed of my projectile
- @param targetposition The position of my target
- @param targetvelocity The velocity of my target
- @return The predicted position
-
- The function predicts the position based on a linear velocity of the target. If the target changes speed or direction, the projectile will miss.
- */
- orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity)
- {
- float squaredProjectilespeed = projectilespeed * projectilespeed;
- orxonox::Vector3 distance = targetposition - myposition;
- float a = distance.squaredLength();
- float b = 2 * (distance.x + distance.y + distance.z) * (targetvelocity.x + targetvelocity.y + targetvelocity.z);
- float c = targetvelocity.squaredLength();
-
- float temp = 4*squaredProjectilespeed*c + a*a - 4*b*c;
- if (temp < 0)
- return orxonox::Vector3::ZERO;
-
- temp = sqrt(temp);
- float time = (temp + a) / (2 * (squaredProjectilespeed - b));
- return (targetposition + targetvelocity * time);
- }
-
unsigned long getUniqueNumber()
{
static unsigned long aNumber = 135;
Modified: sandbox_light/src/libraries/util/Math.h
===================================================================
--- sandbox_light/src/libraries/util/Math.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/Math.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -39,12 +39,12 @@
#include <string>
#include <cmath>
-#include <OgreMath.h>
-#include <OgreVector2.h>
-#include <OgreVector3.h>
-#include <OgreVector4.h>
-#include <OgreQuaternion.h>
-#include <OgreColourValue.h>
+#include <ogremath/OgreMath.h>
+#include <ogremath/OgreVector2.h>
+#include <ogremath/OgreVector3.h>
+#include <ogremath/OgreVector4.h>
+#include <ogremath/OgreQuaternion.h>
+#include <ogremath/OgreColourValue.h>
// Certain headers might define unwanted macros...
#undef max
@@ -63,11 +63,6 @@
_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
_UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree);
- _UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition);
- _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
- _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
- _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity);
-
/**
@brief Returns the sign of the given value.
@param x The value
Modified: sandbox_light/src/libraries/util/MultiType.h
===================================================================
--- sandbox_light/src/libraries/util/MultiType.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/MultiType.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -70,11 +70,11 @@
#include <cassert>
#include <string>
-#include <OgreVector2.h>
-#include <OgreVector3.h>
-#include <OgreVector4.h>
-#include <OgreQuaternion.h>
-#include <OgreColourValue.h>
+#include <ogremath/OgreVector2.h>
+#include <ogremath/OgreVector3.h>
+#include <ogremath/OgreVector4.h>
+#include <ogremath/OgreQuaternion.h>
+#include <ogremath/OgreColourValue.h>
#include "TypeTraits.h"
Deleted: sandbox_light/src/libraries/util/OrxEnum.h
===================================================================
--- sandbox_light/src/libraries/util/OrxEnum.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/OrxEnum.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,67 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- at file
- at brief
- Declaration of the OrxEnum class.
-*/
-
-#ifndef _OrxEnum_H__
-#define _OrxEnum_H__
-
-#include "UtilPrereqs.h"
-
-namespace orxonox
-{
- template <class T>
- struct OrxEnum
- {
- public:
- OrxEnum() { }
- OrxEnum(int type) { type_ = type; }
- OrxEnum(const T& instance) { type_ = instance.type_; }
-
- operator int() { return type_; }
- T& operator =(int type) { type_ = type; return *this; }
- bool operator <(const T& right) const { return (type_ < right.type_); }
- bool operator >(const T& right) const { return (type_ > right.type_); }
-
- private:
- OrxEnum(const OrxEnum& instance);
- int type_;
- };
-}
-
-#define OrxEnumConstructors(enumName) \
-enumName() { } \
-enumName(int type) : OrxEnum<enumName>(type) { } \
-enumName(const enumName& inst) : OrxEnum<enumName>(inst) { } \
-void dummyFunction()
-
-#endif /* _OrxEnum_H__ */
Deleted: sandbox_light/src/libraries/util/Scope.cc
===================================================================
--- sandbox_light/src/libraries/util/Scope.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/Scope.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,35 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#include "Scope.h"
-
-namespace orxonox
-{
- std::map<ScopeID::Value, int> ScopeManager::instanceCounts_s;
- std::map<ScopeID::Value, std::set<ScopeListener*> > ScopeManager::listeners_s;
-}
Deleted: sandbox_light/src/libraries/util/Scope.h
===================================================================
--- sandbox_light/src/libraries/util/Scope.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/Scope.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,141 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef __Util_Scope_H__
-#define __Util_Scope_H__
-
-#include "UtilPrereqs.h"
-#include <cassert>
-#include <set>
-#include <map>
-#include "Debug.h"
-
-namespace orxonox
-{
- namespace ScopeID
- {
- /**
- @brief A list of available scopes for the Scope template.
- */
- enum Value
- {
- GSRoot,
- GSGraphics,
- GSLevel
- };
- }
-
- class ScopeListener; // Forward declaration
-
- /**
- @brief The ScopeManager stores the variables of the scope templates in a statically linked context.
- */
- class _UtilExport ScopeManager
- {
- template <ScopeID::Value scope>
- friend class Scope;
- friend class ScopeListener;
-
- private:
- static std::map<ScopeID::Value, int> instanceCounts_s; //!< Counts the number of active instances (>0 means active) for a scope
- static std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_s; //!< Stores all listeners for a scope
- };
-
- /**
- @brief ScopeListeners register themselves in the corresponding scope and wait for notifications.
- */
- class _UtilExport ScopeListener
- {
- template <ScopeID::Value scope>
- friend class Scope;
-
- protected:
- //! Constructor: Registers the instance.
- ScopeListener(ScopeID::Value scope) : scope_(scope)
- { ScopeManager::listeners_s[this->scope_].insert(this); }
- //! Destructor: Unregisters the instance.
- virtual ~ScopeListener()
- { ScopeManager::listeners_s[this->scope_].erase(this); }
-
- //! Gets called if the scope is activated
- virtual void activated() = 0;
- //! Gets called if the scope is deactivated
- virtual void deactivated() = 0;
-
- private:
- ScopeID::Value scope_; //!< Store the scope to unregister on destruction
- };
-
- /**
- @brief A scope for a given template argument is either active or not.
-
- Objects inheriting from a ScopeListener are registered in a list (different for each scope).
- If the scope gets activated or deactivated, all objects in this list are notified.
- */
- template <ScopeID::Value scope>
- class Scope
- {
- public:
- //! Constructor: Increases the instance counter and activates the scope if the count went from 0 to 1. Counts >1 don't change anything.
- Scope()
- {
- ScopeManager::instanceCounts_s[scope]++;
- assert(ScopeManager::instanceCounts_s[scope] > 0);
- if (ScopeManager::instanceCounts_s[scope] == 1)
- {
- for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
- (*(it++))->activated();
- }
- }
-
- //! Destructor: Decreases the instance counter and deactivates the scope if the count went from 1 to 0. Counts >0 don't change anything.
- ~Scope()
- {
- ScopeManager::instanceCounts_s[scope]--;
-
- // This shouldn't happen but just to be sure: check if the count is positive
- assert(ScopeManager::instanceCounts_s[scope] >= 0);
- if (ScopeManager::instanceCounts_s[scope] < 0)
- ScopeManager::instanceCounts_s[scope] = 0;
-
- if (ScopeManager::instanceCounts_s[scope] == 0)
- {
- for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
- (*(it++))->deactivated();
- }
- }
-
- //! Returns true if the scope is active.
- static bool isActive()
- {
- return (ScopeManager::instanceCounts_s[scope] > 0);
- }
- };
-}
-
-#endif /* __Util_Scope_H__ */
Deleted: sandbox_light/src/libraries/util/ScopedSingleton.h
===================================================================
--- sandbox_light/src/libraries/util/ScopedSingleton.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/ScopedSingleton.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,102 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef __Util_ScopedSingleton_H__
-#define __Util_ScopedSingleton_H__
-
-#include "UtilPrereqs.h"
-#include <cassert>
-
-#include "Scope.h"
-
-namespace orxonox
-{
- /**
- @brief
- Base for scoped singleton classes.
- A Scoped singleton creates itself if the scope is active and getInstance() is called.
- Destroys itself if the scope is deactivated.
-
- Usage:
- Inherit publicly from ScopedSingleton<MyClass, scope> and provide access to
- MyClass::singletonPtr_s.
- This can easily be done with a friend declaration.
-
- See @ref UtilPrereqs.h for a list of scopes (ScopeID::Value).
- */
- template <class T, ScopeID::Value scope>
- class ScopedSingleton : public ScopeListener
- {
- public:
- //! Returns a reference to the singleton instance
- static T& getInstance()
- {
- assert(Scope<scope>::isActive());
-
- if (!T::singletonPtr_s && Scope<scope>::isActive())
- T::singletonPtr_s = new T();
-
- return *T::singletonPtr_s;
- }
-
- protected:
- //! Constructor sets the singleton instance pointer
- ScopedSingleton() : ScopeListener(scope)
- {
- assert(T::singletonPtr_s == 0);
- T::singletonPtr_s = static_cast<T*>(this);
- }
-
- //! Constructor resets the singleton instance pointer
- ~ScopedSingleton()
- {
- assert(T::singletonPtr_s != 0);
- T::singletonPtr_s = 0;
- }
-
- private:
- //! Called if the Scope of this Singleton gets active (no instance should be active then)
- void activated()
- {
- // The ScopedSingleton shouldn't be active bevor the scope is activated -> always assertion failed
- assert(T::singletonPtr_s == 0 && false);
- }
-
- //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
- void deactivated()
- {
- if (T::singletonPtr_s)
- {
- delete T::singletonPtr_s;
- T::singletonPtr_s = 0;
- }
- }
- };
-}
-
-#endif /* __Util_ScopedSingleton_H__ */
Deleted: sandbox_light/src/libraries/util/mbool.h
===================================================================
--- sandbox_light/src/libraries/util/mbool.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/libraries/util/mbool.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,81 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _mbool_H__
-#define _mbool_H__
-
-#include "UtilPrereqs.h"
-
-namespace orxonox
-{
- struct _UtilExport mbool
- {
- public:
- inline mbool(bool value = false)
- { this->value_.memory_ = 0; this->value_.bool_ = value; }
- inline mbool(const mbool& value)
- { this->value_.memory_ = value.value_.memory_; }
-
- inline const mbool& operator=(bool value)
- { if (value != this->value_.bool_) { ++this->value_.memory_; } return (*this); }
- inline const mbool& operator=(const mbool& value)
- { this->value_.memory_ = value.value_.memory_; return (*this); }
-
- inline mbool& operator++()
- { ++this->value_.memory_; return (*this); }
- inline mbool operator++(int i)
- { mbool temp = (*this); ++this->value_.memory_; return temp; }
-
- inline operator bool() const
- { return this->value_.bool_; }
-
- inline bool operator==(bool other) const
- { return this->value_.bool_ == other; }
- inline bool operator!=(bool other) const
- { return this->value_.bool_ != other; }
-
- inline bool operator==(const mbool& other) const
- { return this->value_.memory_ == other.value_.memory_; }
- inline bool operator!=(const mbool& other) const
- { return this->value_.memory_ != other.value_.memory_; }
-
- inline bool operator!() const
- { return (!this->value_.bool_); }
-
- inline unsigned char& getMemory(){ return value_.memory_; }
-
- private:
- union
- {
- bool bool_ : 1;
- unsigned char memory_;
- } value_;
- };
-}
-
-#endif /* _mbool_H__ */
Modified: sandbox_light/src/orxonox/CMakeLists.txt
===================================================================
--- sandbox_light/src/orxonox/CMakeLists.txt 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/orxonox/CMakeLists.txt 2009-09-25 22:44:49 UTC (rev 5789)
@@ -25,11 +25,12 @@
SET_SOURCE_FILES(ORXONOX_SRC_FILES
Main.cc
- GSRoot.cc
)
ORXONOX_ADD_LIBRARY(orxonox
FIND_HEADER_FILES
+ TOLUA_FILES
+ Main.h
DEFINE_SYMBOL
"ORXONOX_SHARED_BUILD"
LINK_LIBRARIES
Deleted: sandbox_light/src/orxonox/GSRoot.cc
===================================================================
--- sandbox_light/src/orxonox/GSRoot.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/orxonox/GSRoot.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,58 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#include "GSRoot.h"
-
-#include "core/Clock.h"
-#include "core/Game.h"
-
-namespace orxonox
-{
- DeclareGameState(GSRoot, "root", false, false);
-
- GSRoot::GSRoot(const GameStateInfo& info)
- : GameState(info)
- {
- }
-
- GSRoot::~GSRoot()
- {
- }
-
- void GSRoot::activate()
- {
- }
-
- void GSRoot::deactivate()
- {
- }
-
- void GSRoot::update(const Clock& time)
- {
- }
-}
Deleted: sandbox_light/src/orxonox/GSRoot.h
===================================================================
--- sandbox_light/src/orxonox/GSRoot.h 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/orxonox/GSRoot.h 2009-09-25 22:44:49 UTC (rev 5789)
@@ -1,51 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _GSRoot_H__
-#define _GSRoot_H__
-
-#include "OrxonoxPrereqs.h"
-#include "core/GameState.h"
-
-namespace orxonox
-{
- class _OrxonoxExport GSRoot : public GameState
- {
- public:
- GSRoot(const GameStateInfo& info);
- ~GSRoot();
-
- void activate();
- void deactivate();
- void update(const Clock& time);
-
- private:
- };
-}
-
-#endif /* _GSRoot_H__ */
Modified: sandbox_light/src/orxonox/Main.cc
===================================================================
--- sandbox_light/src/orxonox/Main.cc 2009-09-25 22:42:29 UTC (rev 5788)
+++ sandbox_light/src/orxonox/Main.cc 2009-09-25 22:44:49 UTC (rev 5789)
@@ -34,33 +34,37 @@
*/
#include "OrxonoxPrereqs.h"
-#include "SpecialConfig.h"
-#include "util/Exception.h"
#include "core/CommandLine.h"
-#include "core/Game.h"
+#include "core/Core.h"
+#include "core/Clock.h"
#include "core/LuaState.h"
+#include "ToluaBindOrxonox.h"
#include "Main.h"
+DeclareToluaInterface(Orxonox);
+
namespace orxonox
{
+ void sandbox()
+ {
+ }
+
/**
@brief
Main method. Game starts here (except for static initialisations).
*/
int main(const std::string& strCmdLine)
{
- Game* game = new Game(strCmdLine);
+ // Create the Core
+ Core* core = new Core(strCmdLine);
+ // Set up a basic clock to keep time
+ Clock* clock = new Clock();
- game->setStateHierarchy(
- "root"
- );
+ sandbox();
- game->requestState("root");
-
- game->run();
- delete game;
-
+ delete clock;
+ delete core;
return 0;
}
}
More information about the Orxonox-commit
mailing list