[216] | 1 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | /* |
---|
| 3 | * OPCODE - Optimized Collision Detection |
---|
| 4 | * Copyright (C) 2001 Pierre Terdiman |
---|
| 5 | * Homepage: http://www.codercorner.com/Opcode.htm |
---|
| 6 | */ |
---|
| 7 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 8 | |
---|
| 9 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 10 | /** |
---|
| 11 | * Contains base volume collider class. |
---|
| 12 | * \file OPC_VolumeCollider.cpp |
---|
| 13 | * \author Pierre Terdiman |
---|
| 14 | * \date June, 2, 2001 |
---|
| 15 | */ |
---|
| 16 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 17 | |
---|
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 19 | /** |
---|
| 20 | * Contains the abstract class for volume colliders. |
---|
| 21 | * |
---|
| 22 | * \class VolumeCollider |
---|
| 23 | * \author Pierre Terdiman |
---|
| 24 | * \version 1.3 |
---|
| 25 | * \date June, 2, 2001 |
---|
| 26 | */ |
---|
| 27 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 28 | |
---|
| 29 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // Precompiled Header |
---|
| 31 | #include "Stdafx.h" |
---|
| 32 | |
---|
| 33 | using namespace Opcode; |
---|
| 34 | |
---|
| 35 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | /** |
---|
| 37 | * Constructor. |
---|
| 38 | */ |
---|
| 39 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | VolumeCollider::VolumeCollider() : |
---|
| 41 | mTouchedPrimitives (null), |
---|
| 42 | mNbVolumeBVTests (0), |
---|
| 43 | mNbVolumePrimTests (0) |
---|
| 44 | { |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 48 | /** |
---|
| 49 | * Destructor. |
---|
| 50 | */ |
---|
| 51 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 52 | VolumeCollider::~VolumeCollider() |
---|
| 53 | { |
---|
| 54 | mTouchedPrimitives = null; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 58 | /** |
---|
| 59 | * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider. |
---|
| 60 | * \return null if everything is ok, else a string describing the problem |
---|
| 61 | */ |
---|
| 62 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 63 | const char* VolumeCollider::ValidateSettings() |
---|
| 64 | { |
---|
| 65 | return null; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // Pretty dumb way to dump - to do better - one day... |
---|
| 69 | |
---|
| 70 | #define IMPLEMENT_NOLEAFDUMP(type) \ |
---|
| 71 | void VolumeCollider::_Dump(const type* node) \ |
---|
| 72 | { \ |
---|
| 73 | if(node->HasPosLeaf()) mTouchedPrimitives->Add(udword(node->GetPosPrimitive())); \ |
---|
| 74 | else _Dump(node->GetPos()); \ |
---|
| 75 | \ |
---|
| 76 | if(ContactFound()) return; \ |
---|
| 77 | \ |
---|
| 78 | if(node->HasNegLeaf()) mTouchedPrimitives->Add(udword(node->GetNegPrimitive())); \ |
---|
| 79 | else _Dump(node->GetNeg()); \ |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | #define IMPLEMENT_LEAFDUMP(type) \ |
---|
| 83 | void VolumeCollider::_Dump(const type* node) \ |
---|
| 84 | { \ |
---|
| 85 | if(node->IsLeaf()) \ |
---|
| 86 | { \ |
---|
| 87 | mTouchedPrimitives->Add(udword(node->GetPrimitive())); \ |
---|
| 88 | } \ |
---|
| 89 | else \ |
---|
| 90 | { \ |
---|
| 91 | _Dump(node->GetPos()); \ |
---|
| 92 | \ |
---|
| 93 | if(ContactFound()) return; \ |
---|
| 94 | \ |
---|
| 95 | _Dump(node->GetNeg()); \ |
---|
| 96 | } \ |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | IMPLEMENT_NOLEAFDUMP(AABBNoLeafNode) |
---|
| 100 | IMPLEMENT_NOLEAFDUMP(AABBQuantizedNoLeafNode) |
---|
| 101 | |
---|
| 102 | IMPLEMENT_LEAFDUMP(AABBCollisionNode) |
---|
| 103 | IMPLEMENT_LEAFDUMP(AABBQuantizedNode) |
---|