Panda3D

physxTriggerReport.cxx

00001 // Filename: physxTriggerReport.cxx
00002 // Created by:  enn0x (19Sep09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxTriggerReport.h"
00016 
00017 #include "event.h"
00018 #include "eventQueue.h"
00019 #include "eventParameter.h"
00020 
00021 PStatCollector PhysxTriggerReport::_pcollector("App:PhysX:Trigger Reporting");
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: PhysxTriggerReport::enable
00025 //       Access: Public
00026 //  Description:
00027 ////////////////////////////////////////////////////////////////////
00028 void PhysxTriggerReport::
00029 enable() {
00030 
00031   _enabled = true;
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: PhysxTriggerReport::disable
00036 //       Access: Public
00037 //  Description:
00038 ////////////////////////////////////////////////////////////////////
00039 void PhysxTriggerReport::
00040 disable() {
00041 
00042   _enabled = false;
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: PhysxTriggerReport::is_enabled
00047 //       Access: Public
00048 //  Description:
00049 ////////////////////////////////////////////////////////////////////
00050 bool PhysxTriggerReport::
00051 is_enabled() const {
00052 
00053   return _enabled;
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: PhysxTriggerReport::onTrigger
00058 //       Access: Public
00059 //  Description:
00060 ////////////////////////////////////////////////////////////////////
00061 void PhysxTriggerReport::
00062 onTrigger(NxShape &triggerShape, NxShape &otherShape, NxTriggerFlag status) {
00063 
00064   if (!_enabled) {
00065     return;
00066   }
00067 
00068   _pcollector.start();
00069 
00070   Event *event;
00071   if (status & NX_TRIGGER_ON_ENTER) {
00072     event = new Event("physx-trigger-enter");
00073   }
00074   else if (status & NX_TRIGGER_ON_LEAVE) {
00075     event = new Event("physx-trigger-leave");
00076   }
00077   else if (status & NX_TRIGGER_ON_STAY) {
00078     event = new Event("physx-trigger-stay");
00079   }
00080   else {
00081     return;
00082   }
00083 
00084   PT(PhysxShape) pTriggerShape = (PhysxShape *)triggerShape.userData;
00085   PT(PhysxShape) pOtherShape = (PhysxShape *)otherShape.userData;
00086   event->add_parameter(EventParameter(pTriggerShape));
00087   event->add_parameter(EventParameter(pOtherShape));
00088 
00089   EventQueue::get_global_event_queue()->queue_event(event);
00090 
00091   _pcollector.stop();
00092 }
00093 
 All Classes Functions Variables Enumerations