JNR
laPivot.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_PH_POINT_H
30 #define M_PH_POINT_H
31 
33 
34 
43 
44 class laPivot: public laPoint3
45 {
46 protected:
47 
48  //Forces acting on the object
49  //
50  //std::list<laPhForce*> lsForces;
51 
52  //Internal breakdown of the simulate() methods
53  //
54  inline laPoint3 _displacement_vector( const laTimer &t, const laPoint3 ve ) const{
55  return ve * (t.delta()*M_UNIT);
56  }
57  //void _sim_forces(laTimer &t, M_BOOL bAnimatePosition = M_TRUE); // NOTE: Not implemented
58 
59  void _sim_gravitation(laTimer &t);
60  laPoint3 _sim_collisions(laTimer &t);
61 
62  // Collsion algorithm and range
63  //
64  static class laCollider *_pCollider;
65  static class laCollisionDomain *_pFirstDomain;
66  static unsigned long _nDomains;
67 
68 public:
69 
70  // Rotation angles
71  //
72  double angleX;
73  double angleY;
74  double angleZ;
75 
76  // 3D geometry offset from the pivot
77  laPoint3 ptGeometryOffset;
78 
79  // Physical parameters
80  //
81  laPoint3 velocity;
82  laPoint3 size;
83  double mass;
84 
85  // Gravitation and collision-detection flags
86  //
87  M_BOOL bSimulateGravitation;
88  M_BOOL bSimulateCollision;
89 
90  // Flag indicating wether the object is currently resting on a surface,
91  // and the Y coordinate of that surface.
92  // This can be used for projecting a pseudo-shadow
93  //
94  M_BOOL bOnGround;
95  double dShadowY;
96 
97  //Pointer to a trap if the object is being affected by one; Otherwise NULL.
98  rpgTrap* pTrap;
99 
100  // Constructor
101  //
102  laPivot(void);
103 
104  // Simulate forces and collisons
105  //
106  inline void simulate(laTimer &t)
107  {
108  PROFILE_COL(laPivot_simulate);
109  laPoint3 dv;
110 
111  if(bSimulateCollision)
112  {
113  ASSERT(_pCollider, "Nil collider");
114  ASSERT(_pFirstDomain, "Nil first collision domain domain");
115 
116  if( bSimulateGravitation ) _sim_gravitation(t);
117 
118  dv = _sim_collisions(t);
119  }
120  else dv = _displacement_vector(t, velocity);
121 
122  x( x() + dv.x() );
123  y( y() + dv.y() );
124  }
125 
126  // Project false shadow under the object
127  //
128  void projectShadow();
129 
130  // Query the collider with a vector
131  // NOTE: Can be used for implementing AI "tentacles" i.e. sensing the surroundsings of a monster
132  //
133  laPoint3 projectVector( laPoint3 vector, M_BOOL *pTrapFlag = NULL, rpgTrap** ppTrap = NULL);
134 
135  // Setup collision detection range
136  //
137  static void colliderRange( class laCollisionDomain *pfirst, unsigned long n) {
138  _pFirstDomain = pfirst;
139  _nDomains = n;
140  }
141 
142  // Misc
143  //
144 
145  laPivot &operator =(const laPoint3 &pt) {
146  x( pt.x() ); y( pt.y() ); z( pt.z() );
147  return *this;
148  }
149 
150  // Acting forces
151  //
152  /*unsigned forceAdd(laPhForce* f);
153  unsigned forceAdd(laPhForce* f, double sec);
154  laPhForce* forceRemove(unsigned id);
155  laPhForce* forceGet(unsigned id);*/
156 };
158 #endif //#ifndef M_PH_POINT_H
#define M_UNIT
Unit of 1 meter.
Trap Properties.
Definition: rpgTrap.h:42
Collision Detection and Response.
Definition: laCollider.h:41
Collision Domain.
Dynamic Object Pivot.
Definition: laPivot.h:44