~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/ogreopcode/include/Opcode/OPC_PlanesCollider.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
2
/*
 
3
 *      OPCODE - Optimized Collision Detection
 
4
 *      Copyright (C) 2001 Pierre Terdiman
 
5
 *      Homepage: http://www.codercorner.com/Opcode.htm
 
6
 *
 
7
 *  OPCODE modifications for scaled model support (and other things)
 
8
 *  Copyright (C) 2004 Gilvan Maia (gilvan 'at' vdl.ufc.br)
 
9
 *      Check http://www.vdl.ufc.br/gilvan/coll/opcode/index.htm for updates.
 
10
 *
 
11
 */
 
12
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
13
 
 
14
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
15
/**
 
16
 *      Contains code for a planes collider.
 
17
 *      \file           OPC_PlanesCollider.h
 
18
 *      \author         Pierre Terdiman
 
19
 *      \date           January, 1st, 2002
 
20
 */
 
21
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
22
 
 
23
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
24
// Include Guard
 
25
#ifndef __OPC_PLANESCOLLIDER_H__
 
26
#define __OPC_PLANESCOLLIDER_H__
 
27
 
 
28
        struct PlanesCache : VolumeCache
 
29
        {
 
30
                                        PlanesCache()
 
31
                                        {
 
32
                                        }
 
33
        };
 
34
 
 
35
        class PlanesCollider : public VolumeCollider
 
36
        {
 
37
                public:
 
38
                // Constructor / Destructor
 
39
                                                                                        PlanesCollider();
 
40
                virtual                                                         ~PlanesCollider();
 
41
 
 
42
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
43
                /**
 
44
                 *      Generic collision query for generic OPCODE models. After the call, access the results:
 
45
                 *      - with GetContactStatus()
 
46
                 *      - with GetNbTouchedPrimitives()
 
47
                 *      - with GetTouchedPrimitives()
 
48
                 *
 
49
                 *      \param          cache                   [in/out] a planes cache
 
50
                 *      \param          planes                  [in] list of planes in world space
 
51
                 *      \param          nb_planes               [in] number of planes
 
52
                 *      \param          model                   [in] Opcode model to collide with
 
53
                 *      \param          worldm                  [in] model's world matrix, or null
 
54
                 *      \return         true if success
 
55
                 */
 
56
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
57
                                                        bool                    Collide(PlanesCache& cache, const IceMaths::Plane* planes, udword nb_planes, const Model& model, const IceMaths::Matrix4x4* worldm=null);
 
58
 
 
59
                // Mutant box-with-planes collision queries
 
60
                inline_                         bool                    Collide(PlanesCache& cache, const IceMaths::OBB& box, const Model& model, const IceMaths::Matrix4x4* worldb=null, const IceMaths::Matrix4x4* worldm=null)
 
61
                                                                                        {
 
62
                                                                                                IceMaths::Plane PL[6];
 
63
 
 
64
                                                                                                if(worldb)
 
65
                                                                                                {
 
66
                                                                                                        // Create a new OBB in world space
 
67
                                                                                                        IceMaths::OBB WorldBox;
 
68
                                                                                                        box.Rotate(*worldb, WorldBox);
 
69
                                                                                                        // Compute planes from the sides of the box
 
70
                                                                                                        WorldBox.ComputePlanes(PL);
 
71
                                                                                                }
 
72
                                                                                                else
 
73
                                                                                                {
 
74
                                                                                                        // Compute planes from the sides of the box
 
75
                                                                                                        box.ComputePlanes(PL);
 
76
                                                                                                }
 
77
 
 
78
                                                                                                // Collide with box planes
 
79
                                                                                                return Collide(cache, PL, 6, model, worldm);
 
80
                                                                                        }
 
81
                // Settings
 
82
 
 
83
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
84
                /**
 
85
                 *      Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider.
 
86
                 *      \return         null if everything is ok, else a string describing the problem
 
87
                 */
 
88
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
89
                override(Collider)      const char*             ValidateSettings();
 
90
 
 
91
                protected:
 
92
                // Planes in model space
 
93
                                                        udword                  mNbPlanes;
 
94
                                                        IceMaths::Plane*                        mPlanes;
 
95
                // Leaf description
 
96
                                                        VertexPointers  mVP;
 
97
                // Internal methods
 
98
                                                        void                    _Collide(const AABBCollisionNode* node, udword clip_mask);
 
99
                                                        void                    _Collide(const AABBNoLeafNode* node, udword clip_mask);
 
100
                                                        void                    _Collide(const AABBQuantizedNode* node, udword clip_mask);
 
101
                                                        void                    _Collide(const AABBQuantizedNoLeafNode* node, udword clip_mask);
 
102
                                                        void                    _CollideNoPrimitiveTest(const AABBCollisionNode* node, udword clip_mask);
 
103
                                                        void                    _CollideNoPrimitiveTest(const AABBNoLeafNode* node, udword clip_mask);
 
104
                                                        void                    _CollideNoPrimitiveTest(const AABBQuantizedNode* node, udword clip_mask);
 
105
                                                        void                    _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node, udword clip_mask);
 
106
                        // Overlap tests
 
107
                inline_                         BOOL                    PlanesAABBOverlap(const IceMaths::Point& center, const IceMaths::Point& extents, udword& out_clip_mask, udword in_clip_mask);
 
108
                inline_                         BOOL                    PlanesTriOverlap(udword in_clip_mask);
 
109
                        // Init methods
 
110
                                                        BOOL                    InitQuery(PlanesCache& cache, const IceMaths::Plane* planes, udword nb_planes, const IceMaths::Matrix4x4* worldm=null);
 
111
        };
 
112
 
 
113
        class HybridPlanesCollider : public PlanesCollider
 
114
        {
 
115
                public:
 
116
                // Constructor / Destructor
 
117
                                                                                        HybridPlanesCollider();
 
118
                virtual                                                         ~HybridPlanesCollider();
 
119
 
 
120
                                                        bool                    Collide(PlanesCache& cache, const IceMaths::Plane* planes, udword nb_planes, const HybridModel& model, const IceMaths::Matrix4x4* worldm=null);
 
121
                protected:
 
122
                                                        IceCore::Container              mTouchedBoxes;
 
123
        };
 
124
 
 
125
#endif // __OPC_PLANESCOLLIDER_H__