Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Polygon triangulation  (Read 4251 times)
0 Members and 1 Guest are viewing this topic.
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Posted 2009-09-28 14:54:12 »

Hi there,

for some reason, I want to do a "realtime" SVG renderer. For now, I manage to :
- load the file (even the arcs, what a noughty thing  Angry)
- construct polygons for filling and stroking
- a basic polygon triangulation

It work pretty well (and quicker than expected for an none optimized test). But my polygon are not "simple" ones and some rendering are wrong. I use the "Ears" algorithm right now (and this problem is quite difficult).

There's a quick&dirty test. It compares my triangulation with the Java2D shape drawing.

Any idea about the problem.

ps1 : I just gone an idea while writing this post  Tongue
ps2 : I hear about an GLU Tesselator in LWJGL 2.2

Offline kevglass

JGO Kernel


Medals: 188
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2009-09-28 14:58:54 »

There's a series of different triangulators in Slick you could rip off. They all comply to the Triangulator interface so it should be easy to compare them. AFAIK none copy with holes tho.

Kev

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #2 - Posted 2009-09-30 08:55:58 »

I take a look to them and they all use more or less the same algorithm : "Ears algorithm"  Wink

I manage to get better result  Tongue. The trick is to transform polygon in several polygons that triangulator can deal with  Grin
It need lots of tests and calculations  Undecided and it's not perfect.

I will have to do lot's of optimization but it seems to be fast enough for now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline broumbroum

Junior Duke





« Reply #3 - Posted 2009-10-08 12:11:05 »

It may be properly known as "Polygon Tesselation". Java 2D Shapes have PathIterator's that handles "Winding Rules" which is part of this chapter of OpenGL : http://glprogramming.com/red/chapter11.html

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #4 - Posted 2009-10-09 07:32:43 »

It may be properly known as "Polygon Tesselation". Java 2D Shapes have PathIterator's that handles "Winding Rules" which is part of this chapter of OpenGL : http://glprogramming.com/red/chapter11.html


Thanks, but I allready know it  Grin

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
 public void create(Shape shape)
  {
    double doubles[] = new double[6];
    Point2D.Double pt = null;
    Point2D.Double lastPoint = null;
    Point2D.Double lastMove = null;
    clear();

    PathIterator it = shape.getPathIterator(null, 0.25);
    //PathIterator it = shape.getPathIterator(null);

    while(!it.isDone())
    {
      int type = it.currentSegment(doubles);

      switch(type)
      {
        case PathIterator.SEG_LINETO :
          pt = new Point2D.Double(doubles[0],doubles[1]);

          if (pt.distance(lastPoint)>0.0001)
          {
            addPoint( pt );
            lastPoint = pt;
          }
        break;
        case PathIterator.SEG_MOVETO :
          pt = new Point2D.Double(doubles[0],doubles[1]);

          if (lastMove != null)
          {
            if (current.get(current.size()-1).distance(lastMove)<0.0001)
            {
              current.remove(current.size()-1);
            }
          }

          newPolygone();

          addPoint( pt );
          lastPoint = pt;
          lastMove = pt;
        break;
        case PathIterator.SEG_CLOSE :

        break;
        default :
      }

      it.next();
    }

    if (lastMove != null)
    {
      if (current.get(current.size()-1).distance(lastMove)<0.0001)
      {
        current.remove(current.size()-1);
      }
    }
  }


But there is something even greater in Java 2D, it can generate a shape form an outline style and a filling shape :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
createPath(p);

    if (style.fill != null)
    {
      GL11.glColor3f((float)style.fill.getRed()/255.0f,
                     (float)style.fill.getGreen()/255.0f,
                     (float)style.fill.getBlue()/255.0f);
     
      drawGlShape(path);
    }

    if(style.stroke != null)
    {
      GL11.glColor3f((float)style.stroke.getRed()/255.0f,
                     (float)style.stroke.getGreen()/255.0f,
                     (float)style.stroke.getBlue()/255.0f);
     
      Shape outLinePath = style.getBasicStroke().createStrokedShape(path);
      drawGlShape(outLinePath);
    }
Offline CommanderKeith
« Reply #5 - Posted 2009-11-19 13:19:40 »

Hi Bonbon-Chan,

Did you ever give LWJGL's new GLUTesselator a go? I'm wondering whether it's faster than tesselating in software. I suppose for your very complex polygons the openGL card's algorithm  might not be stable enough and you want control over how it is tesselated.

Offline kevglass

JGO Kernel


Medals: 188
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2009-11-19 13:41:13 »

GLUTesselator is software.

Kev

Offline CommanderKeith
« Reply #7 - Posted 2009-11-19 13:48:18 »

I didn't know that, thanks Smiley

And cheers for letting us use your slick tessellation code. It's great how many polygon tesselation routines are in there. Also the GeomUtils class is pretty cool with its constructive area geometry.


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (20 views)
2014-10-25 15:46:29

Longarmx (53 views)
2014-10-17 03:59:02

Norakomi (47 views)
2014-10-16 15:22:06

Norakomi (35 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (69 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (46 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!