Free Electron
ClosestGroundContactSystem.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __tire_ClosestGroundContactSystem_h__
8 #define __tire_ClosestGroundContactSystem_h__
9 
10 #include "solve/solve.h"
11 
12 namespace fe
13 {
14 namespace ext
15 {
16 
17 /// @brief Toy/Test Ground Collision System -- M*N: Ground and Collision Points
19  virtual public Stepper,
20  public Initialize<ClosestGroundContactSystem>
21 {
22  public:
24  {
25  }
26  void initialize(void) {}
27 virtual void compile(const t_note_id &a_note_id)
28  {
29  rg_all = m_rg_dataset;
30  m_asGround.bind(rg_all->scope());
31  m_asPoint.bind(rg_all->scope());
32  m_asContact.bind(rg_all->scope());
33  m_asLocator.bind(rg_all->scope());
34  m_asGround.filter(m_grounds, rg_all);
35 
36  for(RecordGroup::iterator i_rg = rg_all->begin();
37  i_rg != rg_all->end(); i_rg++)
38  {
39  sp<RecordArray> spRA = *i_rg;
40 
41  if(!m_asContact.check(spRA)) { continue; }
42 
43  if(m_asLocator.check(spRA))
44  {
45  for(unsigned int i_r = 0; i_r < spRA->length(); i_r++)
46  {
47  m_xform_contacts.push_back(spRA->getRecord(i_r));
48  }
49  }
50  else if(m_asPoint.check(spRA))
51  {
52  for(unsigned int i_r = 0; i_r < spRA->length(); i_r++)
53  {
54  m_point_contacts.push_back(spRA->getRecord(i_r));
55  }
56  }
57  }
58  }
59  void step(t_moa_real a_dt)
60  {
61  if(!rg_all->scope().isValid()) { return; }
62 
63  for(unsigned int i_ground = 0;i_ground<m_grounds.size();i_ground++)
64  {
65  Record &r_ground = m_grounds[i_ground];
66 
67  for(unsigned int i_contact = 0;
68  i_contact < m_point_contacts.size(); i_contact++)
69  {
70  Record &r_contact = m_point_contacts[i_contact];
71 
72  // contact point directly above ground
73  m_asContact.contact(r_contact) =
74  m_asPoint.location(r_contact);
75  m_asContact.contact(r_contact)[2] =
76  m_asGround.height(r_ground);
77  m_asContact.normal(r_contact) = SpatialVector(0,0,1);
78  }
79 
80  for(unsigned int i_contact = 0;
81  i_contact < m_xform_contacts.size(); i_contact++)
82  {
83  Record &r_contact = m_xform_contacts[i_contact];
84 
85  // contact point directly above ground
86  m_asContact.contact(r_contact) =
87  m_asLocator.transform(r_contact).translation();
88  m_asContact.contact(r_contact)[2] =
89  m_asGround.height(r_ground);
90  m_asContact.normal(r_contact) = SpatialVector(0,0,1);
91  }
92  }
93  }
94  private:
95  sp<RecordGroup> rg_all;
96  AsGround m_asGround;
97  AsContactLive m_asContact;
98  AsLocator m_asLocator;
99  AsPoint m_asPoint;
100  std::vector<Record> m_grounds;
101  std::vector<Record> m_xform_contacts;
102  std::vector<Record> m_point_contacts;
103 };
104 
105 } /* namespace ext */
106 } /* namespace fe */
107 
108 #endif /* __tire_ClosestGroundContactSystem_h__ */
109 
void step(t_moa_real a_dt)
Move system forward in time by a timestep.
Definition: ClosestGroundContactSystem.h:59
virtual void compile(const t_note_id &a_note_id)
Compile internal structure for dataset.
Definition: ClosestGroundContactSystem.h:27
kernel
Definition: namespace.dox:3
Ground.
Definition: tireAS.h:147
Toy/Test Ground Collision System – M*N: Ground and Collision Points.
Definition: ClosestGroundContactSystem.h:18
Time Stepping System.
Definition: Stepper.h:15
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Something with a location in simulation.
Definition: moaAS.h:216
STL style iterator.
Definition: RecordGroup.h:124
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53