/* Copyright (c) 2015 Alex Diener 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. Alex Diener alex@ludobloom.com */ #ifndef __IntersectionManager_H__ #define __IntersectionManager_H__ #ifdef __cplusplus extern "C" { #endif typedef struct IntersectionManager IntersectionManager; #define IntersectionManager_superclass StemObject #include "collision/CollisionObject.h" #include "collision/CollisionShared.h" #include "gamemath/FixedPoint.h" #include "gamemath/Vector3x.h" #include "stemobject/StemObject.h" #include // IntersectionHandler rules: // - Return true and write to outTime, outNormal, outObject1Vector, outObject2Vector, and outCollisionArea if an intersection is detected // - Return false and do not modify out parameters if no intersection is detected // - Any of outTime, outNormal, outObject1Vector, outObject2Vector, and outCollisionArea may be NULL; check before writing to them // - Values written to outTime MUST be in the range of [0x00000, 0x10000]; if computed time is outside this range, return false instead // - Values written to outNormal must be normalized, and should point away from object1's trajectory // - Values written to outNormal for 2D shapes must have the z component set to 0x00000 typedef bool (* IntersectionManager_collisionTestHandler)(CollisionObject * object1, CollisionObject * object2, fixed16_16 * outTime, Vector3x * outNormal, Vector3x * outObject1Vector, Vector3x * outObject2Vector, fixed16_16 * outContactArea); // Return true if the two objects are overlapping in some way typedef bool (* IntersectionManager_overlapTestHandler)(CollisionObject * object1, CollisionObject * object2); typedef fixed16_16 (* IntersectionManager_raycastTestHandler)(CollisionObject * object, Vector3x rayStart, Vector3x rayEnd); struct IntersectionPairHandlerEntry { CollisionObject_shapeType type1; CollisionObject_shapeType type2; IntersectionManager_collisionTestHandler collisionTestHandler; IntersectionManager_overlapTestHandler overlapTestHandler; }; struct IntersectionRaycastHandlerEntry { CollisionObject_shapeType type; IntersectionManager_raycastTestHandler handler; }; #define IntersectionManager_ivars \ StemObject_ivars \ \ size_t private_ivar(pairHandlerCount); \ struct IntersectionPairHandlerEntry * private_ivar(pairHandlers); \ size_t private_ivar(raycastHandlerCount); \ struct IntersectionRaycastHandlerEntry * private_ivar(raycastHandlers); \ IntersectionManager_collisionTestHandler defaultCollisionTestHandler; \ IntersectionManager_overlapTestHandler defaultOverlapTestHandler; \ IntersectionManager_raycastTestHandler defaultRaycastTestHandler; #define IntersectionManager_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(IntersectionManager) IntersectionManager * IntersectionManager_create(void); IntersectionManager * IntersectionManager_createWithStandardHandlers(void); bool IntersectionManager_init(IntersectionManager * self); bool IntersectionManager_initWithStandardHandlers(IntersectionManager * self); void IntersectionManager_dispose(IntersectionManager * self); void IntersectionManager_addStandardHandlers(IntersectionManager * self); void IntersectionManager_setHandlersForTypePair(IntersectionManager * self, CollisionObject_shapeType type1, CollisionObject_shapeType type2, IntersectionManager_collisionTestHandler collisionTestHandler, IntersectionManager_overlapTestHandler overlapTestHandler); void IntersectionManager_setRaycastHandlerForType(IntersectionManager * self, CollisionObject_shapeType type, IntersectionManager_raycastTestHandler handler); IntersectionManager_collisionTestHandler IntersectionManager_getCollisionTestHandler(IntersectionManager * self, CollisionObject_shapeType type1, CollisionObject_shapeType type2); IntersectionManager_overlapTestHandler IntersectionManager_getOverlapTestHandler(IntersectionManager * self, CollisionObject_shapeType type1, CollisionObject_shapeType type2); IntersectionManager_raycastTestHandler IntersectionManager_getRaycastTestHandler(IntersectionManager * self, CollisionObject_shapeType type); #ifdef __cplusplus } #endif #endif