00001 /* 00002 svas_server -- virtual World Server of Svas 00003 Copyright (c) 2001, 2002 David Moreno Montero 00004 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00019 02111-1307, USA. 00020 00021 */ 00022 00023 #ifndef __COLLISION_H__ 00024 #define __COLLISION_H__ 00025 00026 /// Used for disttoplane contact limit, and for time subdivision limit 00027 #define COLLISION_SPACE_EPSILUM (1e-4) 00028 #define COLLISION_TIME_EPSILUM (1e-2) 00029 #define COLLISION_VELOCITY_EPSILUM (1e-5) 00030 #define COLLISION_ANGULARVELOCITY_EPSILUM (1e-5) 00031 00032 #include "cylinder.h" 00033 00034 typedef enum collisionType{ 00035 noCollision=0, 00036 contact=1, 00037 penetrating=2 00038 }; 00039 00040 class Collision{ 00041 protected: 00042 /// Cylinder that collides 00043 Cylinder *cyl1, *cyl2; 00044 /// Point over cylinder 00045 Point3d pt1, pt2; 00046 00047 /// Type of collision 00048 collisionType type; 00049 /// Collision normal, normalized 00050 Vector3d normal; 00051 00052 00053 /// Resolves the collision against ground plane 00054 void resolveGroundCollision(); 00055 /// Resolves the collision against another cylinder 00056 void resolveCylinderCollision(); 00057 00058 public: 00059 /// Default and unusefull default constructor 00060 Collision(); 00061 00062 /// Collision against other cylinder 00063 Collision(Cylinder *cyl1, const Point3d &pt1, Cylinder *cyl2, const Point3d &pt2, Vector3d &normal, collisionType type); 00064 00065 /// Collision between a plane and a cylinder. The plane is always 00066 /// the ground plane (n(0,0,1), p(0,1,0)). 00067 Collision(Cylinder *cyl, const Point3d &pt, collisionType type); 00068 /// Collision of one cylinder in two points over a plane 00069 Collision(Cylinder *cyl, const Point3d &pt1, const Point3d &pt2, collisionType type); 00070 00071 ~Collision(); 00072 00073 /// Resolves the collision appling a force on the cylinders 00074 void resolve(); 00075 /// Returns the type of collision 00076 inline collisionType getType(){ return type; }; 00077 }; 00078 00079 00080 #endif