mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-02 16:32:26 +00:00
- License was intended to be GPLv3 per earlier commit of GPLv3 LICENSE FILE - This is confirmed by the inclusion of libraries that are incompatible with GPLv2 - This is also confirmed by KLS and the agreement of KLS's predecessors - Added GPLv3 license headers to the compilable source files - Removed Folly licensing in strings.h since the string functions do not match the Folly functions and are standard functions - this must have been left over from previous implementations - Removed individual contributor license headers since the project has been under the "developer" mantle for many years - Removed comments on files that were previously automatically generated since they've been manually modified multiple times and there are no automatic scripts referencing them (removed in 2023)
80 lines
3.5 KiB
C++
80 lines
3.5 KiB
C++
/* EQEmu: EQEmulator
|
|
|
|
Copyright (C) 2001-2026 EQEmu Development Team
|
|
|
|
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 3 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, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#pragma once
|
|
|
|
// This code snippet allows you to create an axis aligned bounding volume tree for a triangle mesh so that you can do
|
|
// high-speed raycasting.
|
|
//
|
|
// There are much better implementations of this available on the internet. In particular I recommend that you use
|
|
// OPCODE written by Pierre Terdiman.
|
|
// @see: http://www.codercorner.com/Opcode.htm
|
|
//
|
|
// OPCODE does a whole lot more than just raycasting, and is a rather significant amount of source code.
|
|
//
|
|
// I am providing this code snippet for the use case where you *only* want to do quick and dirty optimized raycasting.
|
|
// I have not done performance testing between this version and OPCODE; so I don't know how much slower it is. However,
|
|
// anytime you switch to using a spatial data structure for raycasting, you increase your performance by orders and orders
|
|
// of magnitude; so this implementation should work fine for simple tools and utilities.
|
|
//
|
|
// It also serves as a nice sample for people who are trying to learn the algorithm of how to implement AABB trees.
|
|
// AABB = Axis Aligned Bounding Volume trees.
|
|
//
|
|
// http://www.cgal.org/Manual/3.5/doc_html/cgal_manual/AABB_tree/Chapter_main.html
|
|
//
|
|
//
|
|
// This code snippet was written by John W. Ratcliff on August 18, 2011 and released under the MIT. license.
|
|
//
|
|
// mailto:jratcliffscarab@gmail.com
|
|
//
|
|
// The official source can be found at: http://code.google.com/p/raycastmesh/
|
|
//
|
|
//
|
|
|
|
typedef float RmReal;
|
|
typedef unsigned int RmUint32;
|
|
|
|
class RaycastMesh
|
|
{
|
|
public:
|
|
virtual bool raycast(const RmReal *from,const RmReal *to,RmReal *hitLocation,RmReal *hitNormal,RmReal *hitDistance) = 0;
|
|
virtual bool bruteForceRaycast(const RmReal *from,const RmReal *to,RmReal *hitLocation,RmReal *hitNormal,RmReal *hitDistance) = 0;
|
|
|
|
virtual const RmReal * getBoundMin(void) const = 0; // return the minimum bounding box
|
|
virtual const RmReal * getBoundMax(void) const = 0; // return the maximum bounding box.
|
|
virtual void release(void) = 0;
|
|
protected:
|
|
virtual ~RaycastMesh(void) { };
|
|
};
|
|
|
|
|
|
RaycastMesh * createRaycastMesh(RmUint32 vcount, // The number of vertices in the source triangle mesh
|
|
const RmReal *vertices, // The array of vertex positions in the format x1,y1,z1..x2,y2,z2.. etc.
|
|
RmUint32 tcount, // The number of triangles in the source triangle mesh
|
|
const RmUint32 *indices, // The triangle indices in the format of i1,i2,i3 ... i4,i5,i6, ...
|
|
RmUint32 maxDepth=15, // Maximum recursion depth for the triangle mesh.
|
|
RmUint32 minLeafSize=4, // minimum triangles to treat as a 'leaf' node.
|
|
RmReal minAxisSize=0.01f // once a particular axis is less than this size, stop sub-dividing.
|
|
);
|
|
|
|
#ifdef USE_MAP_MMFS
|
|
#include <vector>
|
|
|
|
RaycastMesh* loadRaycastMesh(std::vector<char>& rm_buffer, bool& load_success);
|
|
void serializeRaycastMesh(RaycastMesh* rm, std::vector<char>& rm_buffer);
|
|
#endif /*USE_MAP_MMFS*/
|