From 7dd2dc91816ab8b3bc3b99a1b1c99c7ea314d5a8 Mon Sep 17 00:00:00 2001 From: Xanadu Date: Sat, 17 Jul 2010 03:50:43 +0200 Subject: Correctly redo file moves/renames from rev. 8481. --HG-- branch : trunk rename : src/server/game/CollisionDetection/BoundingIntervalHierarchy.cpp => src/server/collision/BoundingIntervalHierarchy.cpp rename : src/server/game/CollisionDetection/BoundingIntervalHierarchy.h => src/server/collision/BoundingIntervalHierarchy.h rename : src/server/game/CollisionDetection/CMakeLists.txt => src/server/collision/CMakeLists.txt rename : src/server/game/CollisionDetection/IVMapManager.h => src/server/collision/Management/IVMapManager.h rename : src/server/game/CollisionDetection/VMapFactory.cpp => src/server/collision/Management/VMapFactory.cpp rename : src/server/game/CollisionDetection/VMapFactory.h => src/server/collision/Management/VMapFactory.h rename : src/server/game/CollisionDetection/VMapManager2.cpp => src/server/collision/Management/VMapManager2.cpp rename : src/server/game/CollisionDetection/VMapManager2.h => src/server/collision/Management/VMapManager2.h rename : src/server/game/CollisionDetection/MapTree.cpp => src/server/collision/Maps/MapTree.cpp rename : src/server/game/CollisionDetection/MapTree.h => src/server/collision/Maps/MapTree.h rename : src/server/game/CollisionDetection/TileAssembler.cpp => src/server/collision/Maps/TileAssembler.cpp rename : src/server/game/CollisionDetection/TileAssembler.h => src/server/collision/Maps/TileAssembler.h rename : src/server/game/CollisionDetection/ModelInstance.cpp => src/server/collision/Models/ModelInstance.cpp rename : src/server/game/CollisionDetection/ModelInstance.h => src/server/collision/Models/ModelInstance.h rename : src/server/game/CollisionDetection/WorldModel.cpp => src/server/collision/Models/WorldModel.cpp rename : src/server/game/CollisionDetection/WorldModel.h => src/server/collision/Models/WorldModel.h rename : src/server/game/CollisionDetection/VMapDefinitions.h => src/server/collision/VMapDefinitions.h rename : src/server/game/CollisionDetection/VMapTools.h => src/server/collision/VMapTools.h --- src/server/collision/VMapTools.h | 150 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/server/collision/VMapTools.h (limited to 'src/server/collision/VMapTools.h') diff --git a/src/server/collision/VMapTools.h b/src/server/collision/VMapTools.h new file mode 100644 index 00000000000..dbbd9af9271 --- /dev/null +++ b/src/server/collision/VMapTools.h @@ -0,0 +1,150 @@ +/* +* Copyright (C) 2005-2010 MaNGOS +* +* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _VMAPTOOLS_H +#define _VMAPTOOLS_H + +#include +#include + +#include "NodeValueAccess.h" + +/** +The Class is mainly taken from G3D/AABSPTree.h but modified to be able to use our internal data structure. +This is an iterator that helps us analysing the BSP-Trees. +The collision detection is modified to return true, if we are inside an object. +*/ + +namespace VMAP +{ + template + class IntersectionCallBack { + public: + TValue* closestEntity; + G3D::Vector3 hitLocation; + G3D::Vector3 hitNormal; + + void operator()(const G3D::Ray& ray, const TValue* entity, bool pStopAtFirstHit, float& distance) { + entity->intersect(ray, distance, pStopAtFirstHit, hitLocation, hitNormal); + } + }; + + //============================================================== + //============================================================== + //============================================================== + + class MyCollisionDetection + { + private: + public: + + static bool collisionLocationForMovingPointFixedAABox( + const G3D::Vector3& origin, + const G3D::Vector3& dir, + const G3D::AABox& box, + G3D::Vector3& location, + bool& Inside) + { + + // Integer representation of a floating-point value. +#define IR(x) (reinterpret_cast(x)) + + Inside = true; + const G3D::Vector3& MinB = box.low(); + const G3D::Vector3& MaxB = box.high(); + G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f); + + // Find candidate planes. + for (int i = 0; i < 3; ++i) + { + if (origin[i] < MinB[i]) + { + location[i] = MinB[i]; + Inside = false; + + // Calculate T distances to candidate planes + if (IR(dir[i])) + { + MaxT[i] = (MinB[i] - origin[i]) / dir[i]; + } + } + else if (origin[i] > MaxB[i]) + { + location[i] = MaxB[i]; + Inside = false; + + // Calculate T distances to candidate planes + if (IR(dir[i])) + { + MaxT[i] = (MaxB[i] - origin[i]) / dir[i]; + } + } + } + + if (Inside) + { + // definite hit + location = origin; + return true; + } + + // Get largest of the maxT's for final choice of intersection + int WhichPlane = 0; + if (MaxT[1] > MaxT[WhichPlane]) + { + WhichPlane = 1; + } + + if (MaxT[2] > MaxT[WhichPlane]) + { + WhichPlane = 2; + } + + // Check final candidate actually inside box + if (IR(MaxT[WhichPlane]) & 0x80000000) + { + // Miss the box + return false; + } + + for (int i = 0; i < 3; ++i) + { + if (i != WhichPlane) + { + location[i] = origin[i] + MaxT[WhichPlane] * dir[i]; + if ((location[i] < MinB[i]) || + (location[i] > MaxB[i])) + { + // On this plane we're outside the box extents, so + // we miss the box + return false; + } + } + } + /* + // Choose the normal to be the plane normal facing into the ray + normal = G3D::Vector3::zero(); + normal[WhichPlane] = (dir[WhichPlane] > 0) ? -1.0 : 1.0; + */ + return true; + +#undef IR + } + }; +} +#endif -- cgit v1.2.3