Jump to content
  • Advertisement
Sign in to follow this  
HelderBorges

Collision problem

This topic is 2692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I´m facing a problem wen i try to know wen a bullet and a hero collide. can someone help plz?
the code is this :






bool bala=false;
float xptocontador=0;
float destino[3];
float origem[3];
float posbullet[3];




void drawBala(){
bala = true;
float d1 =calculardistancia(posb,post); // calc position between hero and tower
float d2 =calculardistancia(posb,posbullet); // calc position between hero and bullet
printf("###########-pos boneco %f %f %f-########\n",posb[0],posb[1],posb[2]); // test purpose
printf("**********dist bala %f -**********\n",d2);// test purpose
if((int ) xptocontador==5||calculardistancia(posb,posbullet)==0){ // if bullet reach the end of range or the hero sop the draw
bala= false;
xptocontador=0;
}
else{
glPushMatrix();
glTranslatef(0,1,0);
glRotatef(atan2(post[0]-destino[0],post[2]-destino[2])*(180/3.14)-0.8*(180/3.14),0,1,0); // rotate bullet to hero
glTranslatef(post[0]-destino[0]-((post[0]-destino[0])+xptocontador),0,post[2]-destino[2]-((post[2]-destino[2])+xptocontador)); // move bullet to heroe
glColor3f(0.8f, 0.5f, 2.0f);
glutSolidSphere(0.6,30,30);
printf("ttttttttttt-xpto %f-tttttttttttttttttttt\n",xptocontador);
glPopMatrix();
xptocontador+=0.01;
posbullet[0]=post[0]-destino[0]-((post[0]-destino[0])+xptocontador); // save position of bullet
posbullet[1]=post[1];// save position of bullet
posbullet[2]=post[2]-destino[2]-((post[2]-destino[2])+xptocontador);// save position of bullet
printf("###########-pos bullet %f %f %f-########\n",posbullet[0],posbullet[1],posbullet[2]);
}


}



void drawTorre(float m,float rtorre,float n){


glColor3f(1.0f, 2.0f, 0.0f);

glPushMatrix();


glTranslatef(0, coiso*distancia*escala,-10);
post[0]=0;
post[1]= 0;
post[2]=-10;
float d =calculardistancia(post,posb);
if(d<=5)// test if hero is in the range
{
if(bala == false){ // if there is no bullet start a new one with the actual position of the hero
glPushMatrix();
destino[0]=posb[0];
destino[1]=posb[1];
destino[2]=posb[2];
drawBala();
glPopMatrix();
}
}
if(bala == true){ // if bullet is already drow, continue till bala = false
drawBala();
printf("#########-Bullet on-###########\n");}
printf("vvvvvvvv-%f-vvvvvvv\n",d);
glRotatef(atan2(post[0]-posb[0],post[2]-posb[2])*(180/3.14),0,1,0);
for(int i=0;i<ndonuts;i++){
glPushMatrix();
glRotatef(90,1*escala,0,0);
glutWireTorus(raiointrior,raioexterior,numlados,aneis);
glPopMatrix();
glTranslatef(0, coiso*distancia*escala, 0);
}

//Bule de chá
glTranslatef(0, coiso*distancia*escala-0.2, 0);
glRotatef(90,0,1,0);
glRotatef(-45,0,0,1*escala);//Incliar bool
glColor3f(0.0f, 1.0f, 0.0f);
glutSolidTeapot(tamanhobule); //Cria bule
glPopMatrix();



}







The bullet moves to the hero and stop wen reaches the range. Some tip? :S i´m using c++ in visual studio with opengl

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!