Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Cube::collision(Obj * obj)
- {
- if(obj==NULL) return false;
- Cube * c=dynamic_cast<Cube*>(obj);
- Sphere * s=dynamic_cast<Sphere*>(obj);
- double maxz, minz, maxy, miny, maxx, minx; //obj
- double mmaxz, mminz, mmaxy, mminy, mmaxx, mminx; //this
- //**********************************************************************************//
- //**********************************************************************************//
- // LAB GK - COL
- //**********************************************************************************//
- // Collision S-AABB & AABB-AABB
- mmaxz = posZ + sizez / 2.0;
- mminz = posZ - sizez / 2.0;
- mmaxy = posY + sizey / 2.0;
- mminy = posY - sizey / 2.0;
- mmaxx = posX + sizex / 2.0;
- mminx = posX - sizex / 2.0;
- if(s != NULL)
- {
- maxz = s->getMaxz();
- minz = s->getMinz();
- maxy = s->getMaxy();
- miny = s->getMiny();
- maxx = s->getMaxx();
- minx = s->getMinx();
- }
- else
- {
- maxz = c->posZ + c->sizez / 2.0;
- minz = c->posZ - c->sizez / 2.0;
- maxy = c->posY + c->sizey / 2.0;
- miny = c->posY - c->sizey / 2.0;
- maxx = c->posX + c->sizex / 2.0;
- minx = c->posX - c->sizex / 2.0;
- }
- if((maxz >= mminz && maxz <= mmaxz) || (minz >= mminz && minz <= mmaxz))
- {
- if((maxy >= mminy && maxy <= mmaxy) || (miny >= mminy && miny <= mmaxy))
- {
- if((maxx >= mminx && maxx <= mmaxx) || (minx >= mminx && minx <= mmaxx))
- {
- obj->set_color((GLfloat *) Colors[rand()%10]);
- set_color((GLfloat *) Colors[rand()%10]);
- }
- }
- }
- else if((mmaxz >= minz && mmaxz <= maxz) || (mminz >= minz && mminz <= maxz))
- {
- if((mmaxy >= miny && mmaxy <= maxy) || (mminy >= miny && mminy <= maxy))
- {
- if((mmaxx >= minx && mmaxx <= maxx) || (mminx >= minx && mminx <= maxx))
- {
- obj->set_color((GLfloat *) Colors[rand()%10]);
- set_color((GLfloat *) Colors[rand()%10]);
- }
- }
- }
- //**********************************************************************************//
- //**********************************************************************************//
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement