JNR
laCollisionDomain.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_COLLISION_DOMAIN_H
30 #define M_COLLISION_DOMAIN_H
31 
33 
34 
45 
47 {
48 protected:
49  // Collision lines
50  //
51  laLine2 _arLines[M_MAX_COLLISION_DOMAIN_SZ];
52  laPoint2 _arNormals[M_MAX_COLLISION_DOMAIN_SZ];
53  rpgTrap* _arTrap[M_MAX_COLLISION_DOMAIN_SZ];
54 
55  unsigned _nLineCnt;
56 
57  // Offset of all the lines in the domain
58  laPoint3 _offset;
59 
60  // Pointer to the next domain or NULL
61  laCollisionDomain* _pNextDomain;
62 
63  // Bounding box of the collision domain
64  laRect2 _rectBounds;
65 
66 public:
67  // Constructor and destructor
68  //
69  laCollisionDomain(void);
70  //~laCollisionDomain(void);
71 
72  inline unsigned countLines() const{return _nLineCnt; }
73  inline void offset(const laPoint3 &offset) { _offset = offset; }
74  inline laPoint3 offset() { return _offset; }
75 
76  // Domain connectivity
77  //
78  inline laCollisionDomain* nextDomain() const { return _pNextDomain; }
79  inline void setNextDomain(laCollisionDomain* pNext) { _pNextDomain = pNext; }
80 
81  void optimize(); // remove empty domains in the chain
82 
83  // Bunding box
84  //
85  inline laRect2 boundingRect() { return _rectBounds; }
86  void updateBounds(); // NOTE: should be called after adding new lines
87 
88  // Extract line information
89  //
90  inline laLine2* line(unsigned index) { return _arLines+index; }
91  inline rpgTrap* trap(unsigned index) { return _arTrap[index]; }
92  inline laPoint2* normal(unsigned index) { return _arNormals+index; }
93 
94  // Add a new line
95  void addLine(laPoint3 a, laPoint3 b, laPoint3 normal, rpgTrap* pTrap);
96 
97  // Find the intersection of a triangle with the collision plane
98  // and add the resulting line to the list of collision lines
99  //
100  void addTriangle(const laPoint3 &a, const laPoint3 &b, const laPoint3 &c, rpgTrap* pTrap);
101 
102 
103  //Construct the normal vector of the plane specified with 3 points
104  static laPoint3 normal(laPoint3 a, laPoint3 b, laPoint3 c);
105 
106  //Debug method - draw the lines in the domain
107  void draw(laRenderer* r, laPoint3 ptBasePos);
108 };
110 #endif
2D Point
Definition: laPoint_novec.h:41
Trap Properties.
Definition: rpgTrap.h:42
2D line segment
Definition: laLine2.h:40
2D rectangle (used by the GUI and also as a simple tool for proximity testing)
Definition: laRect2.h:39
Collision Domain.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98