Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/collide/collisionHandlerPhysical.cxx

Go to the documentation of this file.
00001 // Filename: collisionHandlerPhysical.cxx
00002 // Created by:  drose (16Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "collisionHandlerPhysical.h"
00020 #include "config_collide.h"
00021 
00022 #include "transformState.h"
00023 
00024 TypeHandle CollisionHandlerPhysical::_type_handle;
00025 
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: CollisionHandlerPhysical::ColliderDef::get_mat
00029 //       Access: Public
00030 //  Description: Fills mat with the matrix representing the current
00031 //               position and orientation of this collider.
00032 ////////////////////////////////////////////////////////////////////
00033 void CollisionHandlerPhysical::ColliderDef::
00034 get_mat(LMatrix4f &mat) const {
00035   if (_node != (PandaNode *)NULL) {
00036     mat = _node->get_transform()->get_mat();
00037 
00038   } else if (_drive_interface != (DriveInterface *)NULL) {
00039     mat = _drive_interface->get_mat();
00040 
00041   } else {
00042     collide_cat.error()
00043       << "Invalid CollisionHandlerPhysical::ColliderDef\n";
00044   }
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: CollisionHandlerPhysical::ColliderDef::set_mat
00049 //       Access: Public
00050 //  Description: Moves this collider to the position and orientation
00051 //               indicated by the given transform.
00052 ////////////////////////////////////////////////////////////////////
00053 void CollisionHandlerPhysical::ColliderDef::
00054 set_mat(const LMatrix4f &mat) {
00055   if (_node != (PandaNode *)NULL) {
00056     _node->set_transform(TransformState::make_mat(mat));
00057 
00058   } else if (_drive_interface != (DriveInterface *)NULL) {
00059     _drive_interface->set_mat(mat);
00060     _drive_interface->force_dgraph();
00061 
00062   } else {
00063     collide_cat.error()
00064       << "Invalid CollisionHandlerPhysical::ColliderDef\n";
00065   }
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: CollisionHandlerPhysical::Constructor
00070 //       Access: Public
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 CollisionHandlerPhysical::
00074 CollisionHandlerPhysical() {
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: CollisionHandlerPhysical::Destructor
00079 //       Access: Public, Virtual
00080 //  Description:
00081 ////////////////////////////////////////////////////////////////////
00082 CollisionHandlerPhysical::
00083 ~CollisionHandlerPhysical() {
00084 }
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: CollisionHandlerPhysical::begin_group
00088 //       Access: Public, Virtual
00089 //  Description: Will be called by the CollisionTraverser before a new
00090 //               traversal is begun.  It instructs the handler to
00091 //               reset itself in preparation for a number of
00092 //               CollisionEntries to be sent.
00093 ////////////////////////////////////////////////////////////////////
00094 void CollisionHandlerPhysical::
00095 begin_group() {
00096   CollisionHandlerEvent::begin_group();
00097   _from_entries.clear();
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: CollisionHandlerPhysical::add_entry
00102 //       Access: Public, Virtual
00103 //  Description: Called between a begin_group() .. end_group()
00104 //               sequence for each collision that is detected.
00105 ////////////////////////////////////////////////////////////////////
00106 void CollisionHandlerPhysical::
00107 add_entry(CollisionEntry *entry) {
00108   nassertv(entry != (CollisionEntry *)NULL);
00109   CollisionHandlerEvent::add_entry(entry);
00110 
00111   if (entry->get_from()->is_tangible() &&
00112       (!entry->has_into() || entry->get_into()->is_tangible())) {
00113     _from_entries[entry->get_from_node()].push_back(entry);
00114   }
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: CollisionHandlerPhysical::end_group
00119 //       Access: Public, Virtual
00120 //  Description: Called by the CollisionTraverser at the completion of
00121 //               all collision detections for this traversal.  It
00122 //               should do whatever finalization is required for the
00123 //               handler.
00124 ////////////////////////////////////////////////////////////////////
00125 bool CollisionHandlerPhysical::
00126 end_group() {
00127   CollisionHandlerEvent::end_group();
00128 
00129   return handle_entries();
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: CollisionHandlerPhysical::add_collider_drive
00134 //       Access: Public
00135 //  Description: Adds a new collider to the list with a DriveInterface
00136 //               pointer that needs to be told about the collider's
00137 //               new position, or updates the existing collider with a
00138 //               new DriveInterface pointer.
00139 ////////////////////////////////////////////////////////////////////
00140 void CollisionHandlerPhysical::
00141 add_collider_drive(CollisionNode *node, DriveInterface *drive_interface) {
00142   _colliders[node].set_drive_interface(drive_interface);
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: CollisionHandlerPhysical::add_collider_node
00147 //       Access: Public
00148 //  Description: Adds a new collider to the list with a PandaNode
00149 //               pointer that will be updated with the collider's
00150 //               new position, or updates the existing collider with a
00151 //               new PandaNode pointer.
00152 ////////////////////////////////////////////////////////////////////
00153 void CollisionHandlerPhysical::
00154 add_collider_node(CollisionNode *node, PandaNode *target) {
00155   _colliders[node].set_node(target);
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: CollisionHandlerPhysical::remove_collider
00160 //       Access: Public
00161 //  Description: Removes the collider from the list of colliders that
00162 //               this handler knows about.
00163 ////////////////////////////////////////////////////////////////////
00164 bool CollisionHandlerPhysical::
00165 remove_collider(CollisionNode *node) {
00166   Colliders::iterator ci = _colliders.find(node);
00167   if (ci == _colliders.end()) {
00168     return false;
00169   }
00170   _colliders.erase(ci);
00171   return true;
00172 }
00173 
00174 ////////////////////////////////////////////////////////////////////
00175 //     Function: CollisionHandlerPhysical::has_collider
00176 //       Access: Public
00177 //  Description: Returns true if the handler knows about the indicated
00178 //               collider, false otherwise.
00179 ////////////////////////////////////////////////////////////////////
00180 bool CollisionHandlerPhysical::
00181 has_collider(CollisionNode *node) const {
00182   Colliders::const_iterator ci = _colliders.find(node);
00183   return (ci != _colliders.end());
00184 }
00185 
00186 ////////////////////////////////////////////////////////////////////
00187 //     Function: CollisionHandlerPhysical::clear_colliders
00188 //       Access: Public
00189 //  Description: Completely empties the list of colliders this handler
00190 //               knows about.
00191 ////////////////////////////////////////////////////////////////////
00192 void CollisionHandlerPhysical::
00193 clear_colliders() {
00194   _colliders.clear();
00195 }
00196 
00197 

Generated on Fri May 2 00:35:32 2003 for Panda by doxygen1.3