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
00019 }
00020
00021 void CollisionSphere::collide(Particle *p) {
00022
00023 Vector relPos;
00024
00025 GLfloat dist;
00026 float minDist;
00027 relPos = position-(p->position);
00028
00029
00030 dist=relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z;
00031 minDist =radius+(p->size);
00032
00033 if(dist <=(minDist * minDist)) {
00034 #ifdef __COLLISION_SPHERE__
00035 std::cout << "Collision"<< std::endl;
00036 #endif
00037
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
00044 #endif
00045 }
00046 }
00047
00048 void CollisionSphere::draw() {
00049
00050 glPushMatrix();
00051
00052 position.Translate();
00053
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