Advertisement
kanciastopantalones

GK

May 25th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. bool Cube::collision(Obj * obj)
  2. {
  3. if(obj==NULL) return false;
  4.  
  5. Cube * c=dynamic_cast<Cube*>(obj);
  6. Sphere * s=dynamic_cast<Sphere*>(obj);
  7.  
  8. double maxz, minz, maxy, miny, maxx, minx; //obj
  9. double mmaxz, mminz, mmaxy, mminy, mmaxx, mminx; //this
  10.  
  11. //**********************************************************************************//
  12. //**********************************************************************************//
  13. // LAB GK - COL
  14. //**********************************************************************************//
  15. // Collision S-AABB & AABB-AABB
  16.  
  17. mmaxz = posZ + sizez / 2.0;
  18. mminz = posZ - sizez / 2.0;
  19. mmaxy = posY + sizey / 2.0;
  20. mminy = posY - sizey / 2.0;
  21. mmaxx = posX + sizex / 2.0;
  22. mminx = posX - sizex / 2.0;
  23.  
  24. if(s != NULL)
  25. {
  26. maxz = s->getMaxz();
  27. minz = s->getMinz();
  28. maxy = s->getMaxy();
  29. miny = s->getMiny();
  30. maxx = s->getMaxx();
  31. minx = s->getMinx();
  32. }
  33. else
  34. {
  35. maxz = c->posZ + c->sizez / 2.0;
  36. minz = c->posZ - c->sizez / 2.0;
  37. maxy = c->posY + c->sizey / 2.0;
  38. miny = c->posY - c->sizey / 2.0;
  39. maxx = c->posX + c->sizex / 2.0;
  40. minx = c->posX - c->sizex / 2.0;
  41. }
  42.  
  43. if((maxz >= mminz && maxz <= mmaxz) || (minz >= mminz && minz <= mmaxz))
  44. {
  45. if((maxy >= mminy && maxy <= mmaxy) || (miny >= mminy && miny <= mmaxy))
  46. {
  47. if((maxx >= mminx && maxx <= mmaxx) || (minx >= mminx && minx <= mmaxx))
  48. {
  49. obj->set_color((GLfloat *) Colors[rand()%10]);
  50. set_color((GLfloat *) Colors[rand()%10]);
  51. }
  52. }
  53. }
  54. else if((mmaxz >= minz && mmaxz <= maxz) || (mminz >= minz && mminz <= maxz))
  55. {
  56. if((mmaxy >= miny && mmaxy <= maxy) || (mminy >= miny && mminy <= maxy))
  57. {
  58. if((mmaxx >= minx && mmaxx <= maxx) || (mminx >= minx && mminx <= maxx))
  59. {
  60. obj->set_color((GLfloat *) Colors[rand()%10]);
  61. set_color((GLfloat *) Colors[rand()%10]);
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. //**********************************************************************************//
  71. //**********************************************************************************//
  72.  
  73.  
  74.  
  75. return false;
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement