Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 10:33 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Dec 31, 2011 10:25 pm 
Offline

Joined: Fri Dec 30, 2011 7:34 pm
Posts: 4
I'm working on a game that makes heavy use of arbitrary polygons. The majority get triangulated properly and look fine when drawn filled. However, some polygons fail dramatically, leaving giant gaping triangle-shaped holes in my image.

Here is an example I've found.

Code:
package com.pippop.models;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Transform;

/**
* User: Tommaso Sciortino
* Date: Dec 31, 2011
* Time: 2:04:38 PM
*/
public class TriangulatorTest extends BasicGame {

    float[] f = {188.61414f, 224.11491f, 201.38396f, 240.2874f, 214.34015f, 245.45316f, 226.51714f, 241.96631f,
            236.94958f, 232.18132f, 244.67203f, 218.45242f, 248.7191f, 203.13402f, 248.1253f, 188.5804f, 241.92523f,
            177.14589f, 229.15344f, 171.18483f, 208.84453f, 173.05153f, 211.86403f, 168.51219f, 211.88025f, 170.80391f,
            209.59912f, 178.16882f, 205.72678f, 188.84912f, 200.9692f, 201.08694f, 196.03241f, 213.12448f, 191.62248f,
            223.20387f, 188.44543f, 229.56732f, 187.20732f, 230.45694f};

    private Shape s = new Polygon(f);

    public TriangulatorTest() {
        super("Triangulator Test");
    }

    @Override
    public void init(GameContainer container) throws SlickException {
        Transform t = Transform.createScaleTransform(4, 4);
        t.concatenate(Transform.createTranslateTransform(-150,-150));
        s = s.transform(t);
    }

    @Override
    public void update(GameContainer container, int delta) throws SlickException {
    }

    @Override
    public void render(GameContainer container, Graphics g) throws SlickException {
        g.setColor(Color.green);
        g.fill(s);
        g.setColor(Color.red);
        g.draw(s);

        g.setColor(Color.white);
        float[] f = s.getPoints();
        for (int i = 0; i < f.length; i += 2) {
            g.drawString(i/2 + "", f[i] - 1, f[i + 1] - 1);
        }
    }

    public static void main(String[] args) {
        try {
            AppGameContainer app = new AppGameContainer(new TriangulatorTest());
            app.setDisplayMode(500, 500, false);
            app.start();
        } catch (SlickException e) {
            e.printStackTrace();
        }
    }
}


Any advice?


Top
 Profile  
 
PostPosted: Sun Jan 01, 2012 11:13 pm 
Offline

Joined: Fri Dec 30, 2011 7:34 pm
Posts: 4
I realize now the problem is that the polygon is self-intersecting. If you don't support that, it's understandable. That being said, you should at least document which use cases are not supported.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group