Beispiel #1
0
//---------------------------------------------------------------------------
bool Circulo::Corte(Pelota* pelota, GLdouble &tIn, PV* &normal) {
  PV * pc =  new PV(*centro->operator -(*pelota->getCentro()));
  PV *pc_borrar = new PV(centro->getX() - pelota->getCentro()->getX(), centro->getY() - pelota->getCentro()->getY());
  PV *s = pelota->getDireccion();
  PV *sT = new PV(- s->getY(), s->getX());
  GLdouble a = pc->dot(s) / s->dot(s);
  GLdouble b = pc->dot(sT) / s->dot(s);
  GLdouble d0 = fabs(b) * sT->modulo();
  delete pc;
  delete sT;
  if (d0 < (pelota->getRadio() + radio)) {
    GLdouble d2 = sqrt(pow(pelota->getRadio() + radio, 2) - pow(d0, 2));
    GLdouble d1 = fabs(a) * s->modulo() - d2;
    tIn = d1 / s->modulo();
    PV *puntoContacto = new PV(pelota->getCentro()->getX() + tIn * pelota->getDireccion()->getX(),pelota->getCentro()->getY() + tIn * pelota->getDireccion()->getY());
    PV * unaNormalTemp = *puntoContacto-*centro;
    GLdouble mod = unaNormalTemp->modulo();
    if (unaNormal != NULL)
      delete unaNormal;
    unaNormal = new PV(unaNormalTemp->getX() / mod, unaNormalTemp->getY() / mod);
    normal = unaNormal;
    delete puntoContacto;
    return (a > 0) && (s->modulo() > d1);
  } else
    return false;
}
Beispiel #2
0
void Obstaculo::calculaNormales(){
  normales = new PV*[nVertices];
  for (int i = 0; i < nVertices; i++) {
    PV* unPunto = vertices[i];
    PV* otroPunto = vertices[(i+1)%nVertices];
    PV* normal = new PV(unPunto->getY() - otroPunto->getY(), otroPunto->getX() - unPunto->getX());
    normal->normaliza();
    normales[i] = normal;
  }
}
Beispiel #3
0
// Metodo que pinta las paredes
void Rectangulo::Pinta() {
        glColor3f(1.0, 1.0, 0.0);
        glBegin(GL_POLYGON);
                for (int i = 0; i<nVertices; i++){
                        glVertex2d(vertices[i]->getX(), vertices[i]->getY());
                }
        glEnd();

///////////////////////////////////
  PV** puntosMedios = new PV*[nVertices];
  for (int i = 0; i < nVertices; i++) {
    PV* unPunto = vertices[i];
    PV* otroPunto = vertices[(i+1)%nVertices];
    PV* puntoMedio = new PV((unPunto->getX() + otroPunto->getX())/2, (unPunto->getY() + otroPunto->getY())/2);
    puntosMedios[i] = puntoMedio;
  }
       glColor3f(1.0, 1.0, 1.0);
        glBegin(GL_LINES);
        for (int i = 0; i<nVertices; i++){
                glVertex2d(puntosMedios[i]->getX(), puntosMedios[i]->getY());
                glVertex2d(puntosMedios[i]->getX()+(normales[i]->getX()*20), puntosMedios[i]->getY()+(normales[i]->getY()*20));
                }
        glEnd();
}