From 6ba4040f08dbd0edfa3f8e1cdc9ec21c0ae7c172 Mon Sep 17 00:00:00 2001 From: nkorslund Date: Mon, 3 Nov 2008 11:34:49 +0000 Subject: [PATCH] - Added some non-working code (for later use) - Removed CMakeLists for now. It's enough work to keep the existing build alternatives updated. We can add it back later when things stabilize. git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@56 ea6a568a-9f4f-0410-981a-c910a81bb256 --- CMakeLists.txt | 205 ------------------------------------------ bullet/bindings.d | 5 +- bullet/cpp_bullet.cpp | 86 +++--------------- bullet/cpp_player.cpp | 36 ++++++-- bullet/cpp_scale.cpp | 98 ++++++++++++++++++++ ogre/meshloader.d | 10 ++- 6 files changed, 150 insertions(+), 290 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 bullet/cpp_scale.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 8325e29ec..000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,205 +0,0 @@ -# CMake build file list for OpenMW - -cmake_minimum_required(VERSION 2.4) - -if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) -endif(COMMAND cmake_policy) - - -include(CheckLibraryExists) -include(CheckIncludeFile) -include(CheckIncludeFileCXX) -include(FindPkgConfig) -include(UsePkgConfig) - -project(OpenMW D C CXX) - -include_directories("${OpenMW_SOURCE_DIR}") - -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) - -pkg_check_modules(Ogre OGRE) -if(NOT Ogre_FOUND) - check_include_file_cxx(Ogre.h HAVE_OGRE_H) - if(NOT HAVE_OGRE_H) - message(FATAL_ERROR "Ogre.h not found!") - endif() - set(Ogre_LIBRARIES OgreMain) -else() - include_directories(${Ogre_INCLUDE_DIRS}) - link_directories(${Ogre_LIBRARY_DIRS}) -endif() - -pkg_check_modules(OIS OIS) -if(NOT OIS_FOUND) - check_include_file_cxx(OIS/OIS.h HAVE_OIS_OIS_H) - if(NOT HAVE_OIS_OIS_H) - message(FATAL_ERROR "OIS/OIS.h not found!") - endif() - set(OIS_LIBRARIES OIS) -else() - include_directories(${OIS_INCLUDE_DIRS}) - link_directories(${OIS_LIBRARY_DIRS}) -endif() - -pkg_check_modules(FFmpeg libavcodec libavformat) -if(NOT FFmpeg_FOUND) - check_include_file(ffmpeg/avcodec.h HAVE_FFMPEG_AVCODEC_H) - check_include_file(ffmpeg/avformat.h HAVE_FFMPEG_AVFORMAT_H) - if(NOT HAVE_FFMPEG_AVCODEC_H AND NOT HAVE_FFMPEG_AVFORMAT_H) - message(FATAL_ERROR "FFmpeg not found!") - endif() - set(FFmpeg_LIBRARIES avformat avcodec) -else() - include_directories(${FFmpeg_INCLUDE_DIRS}) - link_directories(${FFmpeg_LIBRARY_DIRS}) -endif() - -pkg_check_modules(OpenAL openal) -if(NOT OpenAL_FOUND) - if(WIN32) - set(OpenAL_LIBRARIES OpenAL32) - else() - set(OpenAL_LIBRARIES openal) - endif() -else() - include_directories(${OpenAL_INCLUDE_DIRS}) - link_directories(${OpenAL_LIBRARY_DIRS}) -endif() - - -SET(OMWBASE_CXX_OBJS ogre/cpp_ogre.cpp - sound/cpp_avcodec.cpp -) - -set(OMWBASE_OBJS - util/reglist.d - util/regions.d - util/uniquename.d - util/random.d - core/inifile.d - core/resource.d - core/config.d - core/filefinder.d - core/memory.d - sound/sfx.d - sound/audio.d - sound/music.d - scene/soundlist.d - scene/player.d - scene/celldata.d - ogre/ogre.d - ogre/bindings.d - ogre/meshloader.d - bsa/bsafile.d - input/events.d - input/ois.d - input/keys.d - esm/loadrace.d - esm/loadappa.d - esm/loadbsgn.d - esm/loaddoor.d - esm/loadnpcc.d - esm/loadlocks.d - esm/loadacti.d - esm/loadgmst.d - esm/records.d - esm/loadscpt.d - esm/loadinfo.d - esm/loadcrea.d - esm/loadbody.d - esm/filereader.d - esm/loadcont.d - esm/loadfact.d - esm/loadregn.d - esm/loadltex.d - esm/loadalch.d - esm/loadarmo.d - esm/loadstat.d - esm/loadsoun.d - esm/loadspel.d - esm/loadskil.d - esm/loadingr.d - esm/loadclas.d - esm/loadnpc.d - esm/esmmain.d - esm/loadclot.d - esm/loadsscr.d - esm/loadlevlist.d - esm/loadbook.d - esm/listkeeper.d - esm/defs.d - esm/loadglob.d - esm/loadsndg.d - esm/loadligh.d - esm/imports.d - esm/loaddial.d - esm/loadmisc.d - esm/loadweap.d - esm/loadmgef.d - esm/loadcell.d - esm/loadcrec.d - esm/loadench.d - nif/property.d - nif/data.d - nif/controller.d - nif/nif.d - nif/base.d - nif/record.d - nif/controlled.d - nif/misc.d - nif/effect.d - nif/node.d - nif/extra.d - nif/niffile.d - monster/util/freelist.d - monster/util/aa.d - monster/util/list.d - monster/util/growarray.d - monster/util/string.d -) - -ADD_LIBRARY(omwbase STATIC ${OMWBASE_CXX_OBJS} ${OMWBASE_OBJS}) - -ADD_EXECUTABLE(openmw openmw.d) -TARGET_LINK_LIBRARIES(openmw omwbase ${Ogre_LIBRARIES} ${OIS_LIBRARIES} ${OpenAL_LIBRARIES} ${FFmpeg_LIBRARIES}) - -ADD_EXECUTABLE(esmtool esmtool.d) -TARGET_LINK_LIBRARIES(esmtool omwbase ${Ogre_LIBRARIES} ${OIS_LIBRARIES} ${OpenAL_LIBRARIES} ${FFmpeg_LIBRARIES}) - - -set(NIFTOOL_OBJS - nif/property.d - nif/data.d - nif/controller.d - nif/nif.d - nif/base.d - nif/record.d - nif/controlled.d - nif/misc.d - nif/effect.d - nif/node.d - nif/extra.d - nif/niffile.d - util/reglist.d - util/regions.d - util/uniquename.d - util/random.d - core/memory.d - monster/util/freelist.d - monster/util/aa.d - monster/util/list.d - monster/util/growarray.d - monster/util/string.d -) - -ADD_LIBRARY(nifbase STATIC ${NIFTOOL_OBJS}) - -ADD_EXECUTABLE(niftool niftool.d) -TARGET_LINK_LIBRARIES(niftool nifbase) - -ADD_EXECUTABLE(bsatool bsa/bsafile.d bsatool.d) -TARGET_LINK_LIBRARIES(bsatool nifbase) - -ADD_EXECUTABLE(bored bored.d) diff --git a/bullet/bindings.d b/bullet/bindings.d index 65c014430..af0c59151 100644 --- a/bullet/bindings.d +++ b/bullet/bindings.d @@ -48,12 +48,11 @@ void bullet_setPlayerDir(float x, float y, float z); // been applied. void bullet_getPlayerPos(float *x, float *y, float *z); -// Create a box shape. -/* +// Create a box shape. Used for bounding boxes. The box is a trimesh +// and is hollow (you can walk inside it.) void bullet_createBoxShape(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, float *trans,float *matrix); -*/ // Create a triangle shape. This is cumulative, all meshes created // with this function are added to the same shape. Since the various diff --git a/bullet/cpp_bullet.cpp b/bullet/cpp_bullet.cpp index deda89f56..c544d7a9a 100644 --- a/bullet/cpp_bullet.cpp +++ b/bullet/cpp_bullet.cpp @@ -62,11 +62,6 @@ btVector3 g_walkDirection; // added into this, until bullet_getFinalShape() is called. btTriangleIndexVertexArray *g_currentMesh; -// Current compound shape being built. g_compoundShape and -// g_currentMesh are returned together (the mesh inserted into the -// compound) if both are present. -btCompoundShape *g_compoundShape; - // These variables and the class below are used in player collision // detection. The callback is injected into the broadphase and keeps a // continuously updated list of what objects are colliding with the @@ -89,7 +84,7 @@ int g_physMode; #include "cpp_player.cpp" // Include the uniform shape scaler -//#include "cpp_scale.cpp" +#include "cpp_scale.cpp" class CustomOverlappingPairCallback : public btOverlappingPairCallback { @@ -201,7 +196,6 @@ extern "C" int32_t bullet_init() // Make sure these is zero at startup g_currentMesh = NULL; - g_compoundShape = NULL; // Start out walking g_physMode = PHYS_WALK; @@ -254,42 +248,7 @@ extern "C" void bullet_getPlayerPos(float *x, float *y, float *z) *z = g_playerPosition.getZ(); } -// Create a box shape and add it to the cumulative shape of the -// current object -/* -extern "C" void bullet_createBoxShape(float minX, float minY, float minZ, - float maxX, float maxY, float maxZ, - float *trans,float *matrix) -{ - if(g_compoundShape == NULL) - g_compoundShape = new btCompoundShape; - - // Build a box from the given data. - int x = (maxX-minX)/2; - int y = (maxY-minY)/2; - int z = (maxZ-minZ)/2; - btBoxShape *box = new btBoxShape(btVector3(x,y,z)); - - // Next, create the transformations - btMatrix3x3 mat(matrix[0], matrix[1], matrix[2], - matrix[3], matrix[4], matrix[5], - matrix[6], matrix[7], matrix[8]); - - // In addition to the mesh's world translation, we have to add the - // local translation of the box origin to fit with the given min/max - // values. - x += minX + trans[0]; - y += minY + trans[1]; - z += minZ + trans[2]; - btVector3 trns(x,y,z); - - // Finally, add the shape to the compound - btTransform tr(mat, trns); - g_compoundShape->addChildShape(tr, box); -} -*/ - -void* copyBuffer(void *buf, int elemSize, int len) +void* copyBuffer(const void *buf, int elemSize, int len) { int size = elemSize * len; void *res = malloc(size); @@ -299,9 +258,9 @@ void* copyBuffer(void *buf, int elemSize, int len) } // Internal version that does not copy buffers -void createTriShape(int32_t numFaces, void *triArray, - int32_t numVerts, void *vertArray, - float *trans, float *matrix) +void createTriShape(int32_t numFaces, const void *triArray, + int32_t numVerts, const void *vertArray, + const float *trans, const float *matrix) { // This struct holds the index and vertex buffers of a single // trimesh. @@ -377,12 +336,11 @@ const int cube_num_verts = 8; const int cube_num_tris = 12; // Create a (trimesh) box with the given dimensions. Used for bounding -// boxes. TODO: I guess we have to use the NIF-specified bounding box +// boxes. TODO: I guess we should use the NIF-specified bounding box // for this, not our automatically calculated one. -/* -extern "C" void bullet_createBox(float xmin, float ymin, float zmin, - float xmax, float ymax, float zmax, - float *trans, float *matrix) +extern "C" void bullet_createBoxShape(float xmin, float ymin, float zmin, + float xmax, float ymax, float zmax, + float *trans, float *matrix) { // Make a copy of the vertex buffer, since we need to change it float *vbuffer = (float*)copyBuffer(cube_verts, 12, cube_num_verts); @@ -406,7 +364,6 @@ extern "C" void bullet_createBox(float xmin, float ymin, float zmin, cube_num_verts, vbuffer, trans, matrix); } -*/ // Create a triangle shape and insert it into the current index/vertex // array. If no array is active, create one. @@ -433,38 +390,21 @@ extern "C" btCollisionShape *bullet_getFinalShape() if(g_currentMesh != NULL) shape = new btBvhTriangleMeshShape(g_currentMesh, false); - // Is there a compound shape as well? (usually contains bounding - // boxes) - if(g_compoundShape != NULL) - { - // If both shape types are present, insert the mesh shape into - // the compound. - if(shape != NULL) - { - btTransform tr; - tr.setIdentity(); - g_compoundShape->addChildShape(tr, shape); - } - - // The compound is the final shape - shape = g_compoundShape; - } - // Clear these for the next NIF g_currentMesh = NULL; - g_compoundShape = NULL; return shape; } // Insert a static mesh -extern "C" void bullet_insertStatic(btCollisionShape *shape, +extern "C" void bullet_insertStatic(btConcaveShape *shape, float *pos, float *quat, float scale) { + // FIXME: Scaling does NOT work. + // Are we scaled? - if(scale != 1.0) - return; + if(scale != 1.0) {} // Wrap the shape in a class that scales it. TODO: Try this on // ALL shapes, just to test the slowdown. //shape = new ScaleShape(shape, scale); diff --git a/bullet/cpp_player.cpp b/bullet/cpp_player.cpp index bc45edf6d..14b04bf84 100644 --- a/bullet/cpp_player.cpp +++ b/bullet/cpp_player.cpp @@ -3,6 +3,7 @@ Copyright (C) 2008 Nicolay Korslund Email: < korslund@gmail.com > WWW: http://openmw.snaptoad.com/ + (see additional copyrights for this file below) This file (cpp_player.cpp) is part of the OpenMW package. @@ -19,15 +20,40 @@ version 3 along with this program. If not, see http://www.gnu.org/licenses/ . - */ + ---- + + Parts of this file is based on the kinematic character controller + demo included with the Bullet library. The copyright statement for + these parts follow: + + Bullet Continuous Collision Detection and Physics Library + Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. Permission is + granted to anyone to use this software for any purpose, including + commercial applications, and to alter it and redistribute it freely, + subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + 3. This notice may not be removed or altered from any source + distribution. +*/ + // This file handles player-specific physics and collision detection // TODO: Later we might handle various physics modes, eg. dynamic -// (full physics), player_walk, player_fall, player_swim, player_float, -// player_levitate, player_ghost. These would be applicable to any -// object (through Monster script), allowing player physics to be used -// on NPCs and creatures. +// (full physics), player_walk, player_fall, player_swim, +// player_float, player_levitate, player_ghost. These would be +// applicable to any object (through Monster script), allowing the +// physics code to be shared between NPCs, creatures and the player. // Variables used internally in this file. Once we make per-object // player collision, these will be member variables. diff --git a/bullet/cpp_scale.cpp b/bullet/cpp_scale.cpp new file mode 100644 index 000000000..3dfd34a30 --- /dev/null +++ b/bullet/cpp_scale.cpp @@ -0,0 +1,98 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.snaptoad.com/ + + This file (cpp_scale.cpp) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + +*/ + +// WARNING: This file does NOT work, and it is not used yet. + +class ScaleCallback : public btTriangleCallback +{ + btTriangleCallback *call; + float factor; + +public: + ScaleCallback(btTriangleCallback *c, float f) + { call = c; factor = f; } + + void processTriangle(btVector3 *tri, int partid, int triindex) + { + btVector3 vecs[3]; + vecs[0] = tri[0]*factor; + vecs[1] = tri[1]*factor; + vecs[2] = tri[2]*factor; + + call->processTriangle(vecs, partid, triindex); + } +}; + +// This class is used to uniformly scale a triangle mesh by a +// factor. It wraps around an existing shape and does not copy the +// data. +class ScaleShape : public btConcaveShape +{ + btConcaveShape* child; + float factor, fact3, facthalf; + +public: + + ScaleShape(btConcaveShape* ch, float ft) + { + child = ch; + factor = ft; + fact3 = factor*factor*factor; + facthalf = factor*0.5; + } + + void calculateLocalInertia(btScalar mass,btVector3& inertia) const + { + btVector3 tmpInertia; + child->calculateLocalInertia(mass,tmpInertia); + inertia = tmpInertia * fact3; + } + + const char* getName()const { return "ScaleShape"; } + + void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const + { + child->getAabb(t,aabbMin,aabbMax); + btVector3 aabbCenter = (aabbMax+aabbMin)*0.5; + btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*facthalf; + + aabbMin = aabbCenter - scaledAabbHalfExtends; + aabbMax = aabbCenter + scaledAabbHalfExtends; + } + + void processAllTriangles(btTriangleCallback *callback,const btVector3& aabbMin,const btVector3& aabbMax) const + { + ScaleCallback scb(callback, factor); + + child->processAllTriangles(&scb, aabbMin, aabbMax); + } + + void setLocalScaling(const btVector3& scaling) + { child->setLocalScaling(scaling); } + + const btVector3& getLocalScaling() const + { return child->getLocalScaling(); } + + int getShapeType() const + { return TRIANGLE_MESH_SHAPE_PROXYTYPE; } +}; diff --git a/ogre/meshloader.d b/ogre/meshloader.d index 8799de02e..2251162a1 100644 --- a/ogre/meshloader.d +++ b/ogre/meshloader.d @@ -172,7 +172,7 @@ struct MeshLoader // Things marked "NCO" should not collide with anything. if(flags & 0x800) - collide = false; + { collide = false; bbcollide=false; } // Skip the entire material phase for hidden nodes if(hidden) goto nomaterial; @@ -297,9 +297,11 @@ struct MeshLoader ogre_getWorldTransform(node, trans.ptr, matrix.ptr); // Next we must create the actual OGRE mesh and the collision - // objects, based on the flags we have been given. + // objects, based on the flags we have been given. TODO: I + // guess the NIF bounding box is better than the one we have + // calculated ourselves? This code definitely doesn't work, + // but I haven't look into why yet. assert(!bbcollide); - /* // Bounding box collision currently disabled if(bbcollide) // Insert the bounding box into the collision system bullet_createBoxShape(minX, minY, minZ, maxX, maxY, maxZ, @@ -308,7 +310,7 @@ struct MeshLoader // Create a bullet collision shape from the trimesh. Pass // along the world transformation as well, since we must // transform the trimesh data manually. - else*/if(collide) + else if(collide) { assert(facesPtr !is null, "cannot create collision shape without a mesh");