Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CollisionSphere.cpp

Go to the documentation of this file.
00001 
00006 #include "CollisionSphere.h"
00007 
00008 
00009 using namespace GraphicsLib;
00010 using namespace ParticleSystems; 
00011 
00012 CollisionSphere::CollisionSphere( Point3 *p1, Real r) : CollisionObject() {
00013                 position = p1;
00014                 radius = r;
00015 }
00016                         
00017 CollisionSphere::~CollisionSphere() {
00018         //free the position pointer
00019 }
00020 
00021 void CollisionSphere::collide(Particle *p) {
00022         // the relative position of the spheres
00023         Vector relPos;
00024         //min an max distances of the spheres
00025         GLfloat dist;
00026         float minDist;
00027         relPos = position-(p->position);
00028 
00029         // and the distance
00030         dist=relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z;
00031         minDist =radius+(p->size);
00032         // if it is a hit
00033         if(dist <=(minDist * minDist)) {
00034                 #ifdef __COLLISION_SPHERE__
00035             std::cout << "Collision"<< std::endl;
00036          #endif
00037                  //Change the velocity of the Particle 
00038                  (p->velocity).x-=((p->bounce)*(p->velocity).x);
00039                  (p->velocity).y-=((p->bounce)*(p->velocity).y);
00040                  (p->velocity).z-=((p->bounce)*(p->velocity).z);
00041         }else {
00042                 #ifdef __COLLISION_SPHERE_
00043             //std::cout << "New Velocity " << p->velocity<< std::endl;
00044          #endif
00045         }
00046 }
00047 
00048 void CollisionSphere::draw() {
00049         // preserve the tx matrix
00050         glPushMatrix();
00051                 // translate to the particle position
00052                 position.Translate();
00053                 //colour.Use();
00054                 glutSolidSphere(radius,10,10);
00055         glPopMatrix();
00056         
00057 }
00058 
00059 void CollisionSphere::translate() {
00060         std::cout << "Method not yet implemented" << std::endl;
00061 }
00062 void CollisionSphere::rotate() {
00063         std::cout << "Method not yet implemented" << std::endl;
00064 }
00065 void CollisionSphere::scale() {
00066         std::cout << "Method not yet implemented" << std::endl;
00067 }
00068 

Generated on Thu Mar 24 11:05:02 2005 for ParticleSystem by  doxygen 1.4.1