GL_TRIANGLE_FAN points get Messed Up

Started by Deus, February 28, 2016, 15:55:08

Previous topic - Next topic

Deus

Hi,
I'm experimenting with lwjgl. My goal is to generate a small landscape.
As a base structure I generate a voronoi diagramm (got it displayed and everthing is fine).
Than I have to restructure the way it is represented for the next stepp. To be sure nothing got
messed up, I want to display the new struckture.

public List<Object> createGraphic()
	{
		List<Object> ret = new ArrayList<Object>();
		for(Center center : centers)
		{
			Object qube = Shapes.createQube(0.05f, new Vector3f(0.96078f,0.67058f,0.20784f));
			qube.move(center.point);
			ret.add(qube);
			
			Corner first = center.corners.get(0);
			for(Corner corner : center.corners)
			{
				if(center.point.y>first.point.y)
					first = corner;
			}
			List<Corner> left = new ArrayList<Corner>();
			List<Corner> right = new ArrayList<Corner>();
			for(Corner corner : center.corners)
			{
				if(corner.equals(first))
					continue;
				if(first.point.x<corner.point.x)
				{
					for(int i=0;i<=right.size();i++)
					{
						
						if(i==right.size())
						{
							right.add(corner);
							break;
						}
						else if(right.get(i).point.y>corner.point.y)
						{
							right.add(i, corner);
							break;
						}
					}
				}
				else
				{
					for(int i=0;i<=left.size();i++)
					{
						if(i==left.size())
						{
							left.add(corner);
							break;
						}
						else if(left.get(i).point.y<corner.point.y)
						{
							left.add(i, corner);
							break;
						}
					}
				}
			}
			
			
			System.out.println("Links:");
			for(int i=0;i<left.size();i++)
				System.out.println(left.get(i).point.y);
			

			System.out.println("Rechts:");
			for(int i=0;i<right.size();i++)
				System.out.println(right.get(i).point.y);
			
			
			Object object = new Object(GL11.GL_TRIANGLE_FAN);
			
			object.add(center.point);
			object.add(first.point);
			for(int i=0;i<left.size();i++)
				object.add(left.get(i).point);
			for(int i=0;i<right.size();i++)
				object.add(right.get(i).point);
			object.add(first.point);
			object.setColor(DisplayExample.rColor());
			ret.add(object);
		}
		
		System.out.println("Ende Graphic");
		return ret;
	}

That code looks for the highest corner (giggest y). After this it sorts all corners left of the highest decent
and the one on the right ascent. Now it orders the Like:
Center point
First point
left list
right list
first point

With GL_TRIANGLE_FAN I should get a nice polygon, but some of them are quite messed up.
I put a picture in the attachment.
Someone got an idea what I have done wrong?

Deus

Deus

I have found the problem.
If ther is a point with a bigger Y than the lowest point to the right of the point with the highest Y
but on the left of the point with the lowest Y, it does not sort correctly.
Now is the question how do I fix this? Or is ther a efficent alternativ?

Deus

Deus

I found a way to hold the order I get from the framework.
So now the points are sorted either clockwise or counterclockwise.
To get the orientation I take the highest point und test:
-Is the following point to the left
or
-are both neighbours points to the right AND is the following beneath the previous one
95% are now correct.
My question is do I miss a case where my rules are not true or have I made a mistake while implementing?

Deus