Panda3D

physxControllerReport.cxx

00001 // Filename: physxControllerReport.cxx
00002 // Created by:  enn0x (24Sep09)
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 "physxControllerReport.h"
00016 
00017 PStatCollector PhysxControllerReport::_pcollector("App:PhysX:Controller Reporting");
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: PhysxControllerReport::enable
00021 //       Access: Public
00022 //  Description:
00023 ////////////////////////////////////////////////////////////////////
00024 void PhysxControllerReport::
00025 enable() {
00026 
00027   _enabled = true;
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PhysxControllerReport::disable
00032 //       Access: Public
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 void PhysxControllerReport::
00036 disable() {
00037 
00038   _enabled = false;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: PhysxControllerReport::is_enabled
00043 //       Access: Public
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 bool PhysxControllerReport::
00047 is_enabled() const {
00048 
00049   return _enabled;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: PhysxControllerReport::onShapeHit
00054 //       Access: Public
00055 //  Description: 
00056 ////////////////////////////////////////////////////////////////////
00057 NxControllerAction PhysxControllerReport::
00058 onShapeHit( const NxControllerShapeHit& hit ) {
00059 
00060   if (!_enabled) {
00061     return NX_ACTION_NONE;
00062   }
00063 
00064   _pcollector.start();
00065 
00066   if (1 && hit.shape) {
00067     NxActor& actor = hit.shape->getActor();
00068     if (actor.isDynamic() && !actor.readBodyFlag(NX_BF_KINEMATIC)) {
00069       if (hit.dir.z == 0.0f) {
00070         NxF32 controllerMass = hit.controller->getActor()->getMass();
00071         NxF32 coeff = actor.getMass() * hit.length * controllerMass;
00072         actor.addForceAtLocalPos(hit.dir*coeff, NxVec3(0,0,0), NX_IMPULSE);
00073       }
00074     }
00075   }
00076 
00077   _pcollector.stop();
00078 
00079   return NX_ACTION_NONE;
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: PhysxControllerReport::onControllerHit
00084 //       Access: Public
00085 //  Description:
00086 ////////////////////////////////////////////////////////////////////
00087 NxControllerAction PhysxControllerReport::
00088 onControllerHit(const NxControllersHit& hit) {
00089 
00090   if (!_enabled) {
00091     return NX_ACTION_NONE;
00092   }
00093 
00094   _pcollector.start();
00095 
00096   if (1 && hit.other) {
00097     // For now other controllers are unpushable. --TODO--
00098     //return NX_ACTION_PUSH; is not implemented!
00099   }
00100 
00101   _pcollector.stop();
00102 
00103   return NX_ACTION_NONE;
00104 }
00105 
 All Classes Functions Variables Enumerations