From 75afee59c3a4525f70085e285b43a16b693d4ad9 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 28 Nov 2011 23:22:43 +0000 Subject: [PATCH] Get all the tests linking with shared-simgear, and duplicate the awkward core functions into a new file, pending a proper cleanup. --- simgear/CMakeLists.txt | 3 +- simgear/magvar/CMakeLists.txt | 8 +- simgear/math/CMakeLists.txt | 12 ++- simgear/misc/CMakeLists.txt | 13 ++- simgear/props/CMakeLists.txt | 12 ++- simgear/scene/util/SGCoreOSGDependant.cxx | 96 +++++++++++++++++++++++ 6 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 simgear/scene/util/SGCoreOSGDependant.cxx diff --git a/simgear/CMakeLists.txt b/simgear/CMakeLists.txt index cde6efa4..f85ccc3f 100644 --- a/simgear/CMakeLists.txt +++ b/simgear/CMakeLists.txt @@ -69,7 +69,8 @@ if(SIMGEAR_SHARED) ENDIF(APPLE) endif(LIBSVN_FOUND) - + list(APPEND sceneSources scene/util/SGCoreOSGDependant.cxx) + add_library(SimGearScene SHARED ${sceneSources}) # set_property(TARGET SimGearScene PROPERTY FRAMEWORK 1) # set_property(TARGET SimGearScene PROPERTY PUBLIC_HEADER "${publicHeaders}") diff --git a/simgear/magvar/CMakeLists.txt b/simgear/magvar/CMakeLists.txt index 08ce1e8a..2e6cd342 100644 --- a/simgear/magvar/CMakeLists.txt +++ b/simgear/magvar/CMakeLists.txt @@ -8,5 +8,11 @@ simgear_component(magvar magvar "${SOURCES}" "${HEADERS}") if(ENABLE_TESTS) add_executable(test_magvar testmagvar.cxx ) -target_link_libraries(test_magvar sgmagvar) + +if (SIMGEAR_SHARED) + target_link_libraries(test_magvar SimGearCore) +else() + target_link_libraries(test_magvar sgmagvar) +endif() + endif(ENABLE_TESTS) diff --git a/simgear/math/CMakeLists.txt b/simgear/math/CMakeLists.txt index 49e1b785..91f01dbe 100644 --- a/simgear/math/CMakeLists.txt +++ b/simgear/math/CMakeLists.txt @@ -46,11 +46,19 @@ set(SOURCES simgear_component(math math "${SOURCES}" "${HEADERS}") if(ENABLE_TESTS) + +if (SIMGEAR_SHARED) + set(TEST_LIBS SimGearCore) +else() + set(TEST_LIBS sgmath sgstructure sgdebug) +endif() + + add_executable(math_test SGMathTest.cxx) -target_link_libraries(math_test sgmath sgstructure sgdebug) +target_link_libraries(math_test ${TEST_LIBS}) add_test(math ${EXECUTABLE_OUTPUT_PATH}/math_test) add_executable(geometry_test SGGeometryTest.cxx) -target_link_libraries(geometry_test sgmath sgstructure sgdebug) +target_link_libraries(geometry_test ${TEST_LIBS}) add_test(geometry ${EXECUTABLE_OUTPUT_PATH}/geometry_test) endif(ENABLE_TESTS) diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index 597e80fa..582f29ec 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -33,15 +33,22 @@ set(SOURCES simgear_component(misc misc "${SOURCES}" "${HEADERS}") if(ENABLE_TESTS) + +if (SIMGEAR_SHARED) + set(TEST_LIBS SimGearCore) +else() + set(TEST_LIBS sgmisc sgdebug) +endif() + add_executable(test_tabbed_values tabbed_values_test.cxx) add_test(tabbed_values ${EXECUTABLE_OUTPUT_PATH}/test_tabbed_values) -target_link_libraries(test_tabbed_values sgmisc) +target_link_libraries(test_tabbed_values ${TEST_LIBS}) add_executable(test_strings strutils_test.cxx ) add_test(test_strings ${EXECUTABLE_OUTPUT_PATH}/test_strings) -target_link_libraries(test_strings sgmisc) +target_link_libraries(test_strings ${TEST_LIBS}) add_executable(test_path path_test.cxx ) add_test(test_path ${EXECUTABLE_OUTPUT_PATH}/test_path) -target_link_libraries(test_path sgmisc sgdebug) +target_link_libraries(test_path ${TEST_LIBS}) endif(ENABLE_TESTS) diff --git a/simgear/props/CMakeLists.txt b/simgear/props/CMakeLists.txt index dfd19160..f0dcbed8 100644 --- a/simgear/props/CMakeLists.txt +++ b/simgear/props/CMakeLists.txt @@ -23,11 +23,19 @@ set(SOURCES simgear_component(props props "${SOURCES}" "${HEADERS}") if(ENABLE_TESTS) + +if (SIMGEAR_SHARED) + set(TEST_LIBS SimGearCore) +else() + set(TEST_LIBS sgprops sgxml sgstructure sgmisc sgdebug) +endif() + + add_executable(test_props props_test.cxx) -target_link_libraries(test_props sgprops sgxml sgstructure sgmisc sgdebug) +target_link_libraries(test_props ${TEST_LIBS}) add_test(test_props ${EXECUTABLE_OUTPUT_PATH}/test_props) add_executable(test_propertyObject propertyObject_test.cxx) -target_link_libraries(test_propertyObject sgprops sgstructure sgdebug) +target_link_libraries(test_propertyObject ${TEST_LIBS}) add_test(test_propertyObject ${EXECUTABLE_OUTPUT_PATH}/test_propertyObject) endif(ENABLE_TESTS) diff --git a/simgear/scene/util/SGCoreOSGDependant.cxx b/simgear/scene/util/SGCoreOSGDependant.cxx new file mode 100644 index 00000000..15853700 --- /dev/null +++ b/simgear/scene/util/SGCoreOSGDependant.cxx @@ -0,0 +1,96 @@ + + +// Copyright (C) 2011 Curtis L Olson +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 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 +// Library 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. +// + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include + +#include +#include +#include + +namespace simgear +{ +GLint project(GLdouble objX, GLdouble objY, GLdouble objZ, + const GLdouble *model, const GLdouble *proj, const GLint *view, + GLdouble* winX, GLdouble* winY, GLdouble* winZ) +{ + using namespace osg; + Vec4d obj(objX, objY, objZ, 1.0); + Matrixd Mmodel(model), Mproj(proj); + Matrixd Mwin = (Matrixd::translate(1.0, 1.0, 1.0) + * Matrixd::scale(0.5 * view[2], 0.5 * view[3], 0.5) + * Matrixd::translate(view[0], view[1], 0.0)); + Vec4d result = obj * Mmodel * Mproj * Mwin; + if (equivalent(result.w(), 0.0)) + return GL_FALSE; + result = result / result.w(); + *winX = result.x(); *winY = result.y(); *winZ = result.z(); + return GL_TRUE; +} + +osgDB::ReaderWriter::Options* makeOptionsFromPath(const SGPath& path) +{ + using namespace osgDB; + ReaderWriter::Options *options + = new ReaderWriter::Options(*(Registry::instance()->getOptions())); + options->setDatabasePath(path.str()); + return options; +} + + +} + +osg::Matrix SGGeod::makeSimulationFrameRelative() const +{ + SGQuatd hlOr = SGQuatd::fromLonLat(*this); + return osg::Matrix(toOsg(hlOr)); +} + +osg::Matrix SGGeod::makeSimulationFrame() const +{ + osg::Matrix result(makeSimulationFrameRelative()); + SGVec3d coord; + SGGeodesy::SGGeodToCart(*this, coord); + result.setTrans(toOsg(coord)); + return result; +} + +osg::Matrix SGGeod::makeZUpFrameRelative() const +{ + osg::Matrix result(makeSimulationFrameRelative()); + // 180 degree rotation around Y axis + osg::Quat flip(0.0, 1.0, 0.0, 0.0); + result.preMult(osg::Matrix(flip)); + return result; +} + +osg::Matrix SGGeod::makeZUpFrame() const +{ + osg::Matrix result(makeZUpFrameRelative()); + SGVec3d coord; + SGGeodesy::SGGeodToCart(*this, coord); + result.setTrans(toOsg(coord)); + return result; +} + -- 2.39.5