Esempio n. 1
0
void WaterPhysicsSystem::renderWireframe()
{
  for (unsigned int i = 0; i != edges.size(); i++)
    {
      Edge* edge = edges[i];
      glBegin(GL_LINES);
      {
	glColor3f(1,1,1);
	glVertex2f(edge->aPosition().x, edge->aPosition().y);
	glVertex2f(edge->bPosition().x, edge->bPosition().y);
      }
      glEnd();
      glBegin(GL_POINTS);
      {
	glColor3f(1,0,0);
	glVertex2f(edge->aPosition().x, edge->aPosition().y);
	glVertex2f(edge->bPosition().x, edge->bPosition().y);
      }
      glEnd();
    }
  glColor3f(0,0,1);
  for (unsigned int i = 0; i != volumes.size(); i++)
    {
      Volume* volume = volumes[i];
      Vec2f center;
      center = volume->getLeft()->aPosition();
      center += volume->getLeft()->bPosition();
      center += volume->getRight()->aPosition();
      center += volume->getRight()->bPosition();
      center /= 4.0f;
      glBegin(GL_LINES);
      {
	glVertex2f(volume->getLeft()->aPosition().x, volume->getLeft()->aPosition().y);
	glVertex2f(center.x, center.y);
	glVertex2f(volume->getRight()->aPosition().x, volume->getRight()->aPosition().y);
	glVertex2f(center.x, center.y);

	glVertex2f(volume->getRight()->bPosition().x, volume->getRight()->bPosition().y);
	glVertex2f(center.x, center.y);
	glVertex2f(volume->getLeft()->bPosition().x, volume->getLeft()->bPosition().y);
	glVertex2f(center.x, center.y);
      }
      glEnd();
    }
  glBegin(GL_LINES);
  glColor3f(1,1,0.5f);
  //  for (Boundary* boundary = boundaries.front(); boundary; boundary = boundary->getNextObject())
  for (unsigned int i = 0; i != boundaries.size(); i++)
    {
      Boundary* boundary = boundaries[i];
      if (boundary)
	{
	  Vec2f p = boundary->getLeftPosition();
	  glVertex2f(p.x, p.y);
	  p = boundary->getRightPosition();
	  glVertex2f(p.x, p.y);
	}
    }
  glEnd();
}
Esempio n. 2
0
void WaterPhysicsSystem::addFinalisedEdge(Edge* _edge)
{
  edges.push_back(_edge);
  Edge::EdgeType type = _edge->getEdgeType();
  bool leftEdge;
  if (type == Edge::eLeftFloor || type == Edge::eLeftRoof)
    {
      leftEdge = true;
    }
  else
    {
      leftEdge = false;
    }
  addFinalisedVertex(_edge->getA(), _edge, leftEdge);
  addFinalisedVertex(_edge->getB(), _edge, leftEdge);

  //  for (Boundary* boundary = boundaries.front(); boundary; boundary = boundary->getNextObject())
  for (unsigned int i = 0; i != boundaries.size(); i++)
    {
      Boundary* boundary = boundaries[i];
      if (boundary)
      try
	{
	  Vec2f position = intersectionPosition(_edge->aPosition(), _edge->bPosition(), boundary->getLeftPosition(), boundary->getRightPosition());
	  Vertex* vertex = new Vertex(position, nullptr, true);
	  if (leftEdge)
	    {
	      //assert(boundary->getLeft() == nullptr);
	      boundary->setLeft(vertex);
	    }
	  else
	    {
	      // assert(boundary->getRight() == nullptr);
	      boundary->setRight(vertex);
	    }
	}
      catch (int i)
	{}
    }
  /*
  edges.push_back(_edge);
  Vec2f a = _edge->aPosition();
  Vertex* vertex = _edge->getA();
  bool jump = true;
  goto ACTUAL_START;
 START:
  vertex = _edge->getB();
  jump = false;
 ACTUAL_START:
  Vec2f b;
  Edge::EdgeType type = _edge->getEdgeType();
  bool leftEdge;
  if (type == Edge::eLeftFloor | type == Edge::eLeftRoof)
    {
      b = a + Vec2f(500, 0);
      leftEdge = true;
    }
  else
    {
      b = a - Vec2f(500, 0);
      leftEdge = false;
    }
  Edge* opposingEdge = findIntersectingEdge(a, &b, _edge);
  if (opposingEdge)
    {
      Vec2f a2 = opposingEdge->aPosition();
      Vec2f b2 = a2 + Vec2f((leftEdge)?-500:500,0);
      Edge* opposingOpposingEdge = findIntersectingEdge(a2, &b2, opposingEdge);
      if (opposingOpposingEdge == _edge)
	{
	  Edge* selfSplit = _edge->split(b2, nullptr);
	  edges.push_back(selfSplit);
	}
      //      else
      {
	a2 = opposingEdge->bPosition();
	b2 = a2 + Vec2f((leftEdge)?-500:500,0);
	opposingOpposingEdge = findIntersectingEdge(a2, &b2, opposingEdge);
	if (opposingOpposingEdge == _edge)
	  {
	    Edge* selfSplit = _edge->split(b2, nullptr);
	    edges.push_back(selfSplit);
	  }
      }
      Edge* newEdge = opposingEdge->split(b, nullptr);
      edges.push_back(newEdge);
    }
  if (jump)
    {
      a = _edge->bPosition();
      goto START;
      }*/
}