AnimatLab  2
Test
VsIntersectionEvent.cpp
1 // VsIntersectionEvent.cpp: implementation of the VsIntersectionEvent class.
2 //
4 
5 #include "StdAfx.h"
6 #include "VsSimulator.h"
7 
8 namespace VortexAnimatSim
9 {
10  namespace Visualization
11  {
12 
14 // Construction/Destruction
16 
17 VsIntersectionEvent::VsIntersectionEvent() :
18  VxUniverse::IntersectSubscriber()
19 {
20  m_lpSim = NULL;
21 }
22 
23 VsIntersectionEvent::~VsIntersectionEvent()
24 {
25 
26 try
27 {
28 }
29 catch(...)
30 {Std_TraceMsg(0, "Caught Error in desctructor of VsIntersectionEvent\r\n", "", -1, false, true);}
31 }
32 
33 void VsIntersectionEvent::notifyIntersect(VxUniverse::eIntersectEventType type, VxIntersectResult* inResult, VxDynamicsResponseInput* inResp)
34 {
35  //Only respond to the iniital contact and removal of the contact.
36  if ( type == VxUniverse::kEventFirst )
37  {
38  VxEntity *e1, *e2;
39  inResult->getEntityPair(&e1, &e2);
40 
41  if(e1 && e2)
42  {
43  void *v1 = e1->getUserData();
44  void *v2 = e2->getUserData();
45 
46  if(v1 && v2)
47  {
48  RigidBody *lpBody1 = (RigidBody *) v1;
49  RigidBody *lpBody2 = (RigidBody *) v2;
50 
51  if( !((lpBody1->Parent() == lpBody2) || (lpBody2->Parent() == lpBody1)) )
52  {
53  lpBody1->AddSurfaceContact(lpBody2);
54  lpBody2->AddSurfaceContact(lpBody1);
55  }
56  }
57  }
58  }
59 }
60 
61 void VsIntersectionEvent::notifyDisjoint(VxUniverse::eIntersectEventType type, VxIntersectResult* inResult)
62 {
63  if ( type == VxUniverse::kEventDisjoint )
64  {
65  VxEntity *e1, *e2;
66  inResult->getEntityPair(&e1, &e2);
67 
68  if(e1 && e2)
69  {
70  void *v1 = e1->getUserData();
71  void *v2 = e2->getUserData();
72 
73  if(v1 && v2)
74  {
75  RigidBody *lpBody1 = (RigidBody *) v1;
76  RigidBody *lpBody2 = (RigidBody *) v2;
77 
78  if( !((lpBody1->Parent() == lpBody2) || (lpBody2->Parent() == lpBody1)) )
79  {
80  lpBody1->RemoveSurfaceContact(lpBody2);
81  lpBody2->RemoveSurfaceContact(lpBody1);
82  }
83  }
84  }
85  }
86 }
87 
88 
89  } // Visualization
90 } //VortexAnimatSim
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.