Added collinear vertex detection
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ target
|
|||||||
.settings
|
.settings
|
||||||
chunks
|
chunks
|
||||||
new_chunks
|
new_chunks
|
||||||
|
images
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,6 @@ import java.awt.Color;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.MouseInfo;
|
import java.awt.MouseInfo;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
@@ -26,13 +24,13 @@ import java.util.Random;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.Timer;
|
|
||||||
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.EdgeSet;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.EdgeSet;
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.HalfEdge;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.HalfEdge;
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.Mesh;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.Mesh;
|
||||||
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.Mesh.Chain;
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.Mesh.EdgePolygon;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.Mesh.EdgePolygon;
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.Point;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.Point;
|
||||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.Polygon;
|
import com.aaaaahhhhhhh.bananapuncher714.mesh.Polygon;
|
||||||
@@ -56,7 +54,7 @@ public class MeshingTest2 extends JPanel {
|
|||||||
// private int windowHeight = 1000;
|
// private int windowHeight = 1000;
|
||||||
|
|
||||||
private int windowWidth = 1200;
|
private int windowWidth = 1200;
|
||||||
private int windowHeight = 1400;
|
private int windowHeight = 800;
|
||||||
|
|
||||||
// private int centerX = 600;
|
// private int centerX = 600;
|
||||||
// private int centerY = 400;
|
// private int centerY = 400;
|
||||||
@@ -72,11 +70,14 @@ public class MeshingTest2 extends JPanel {
|
|||||||
private Collection< Vertex > data;
|
private Collection< Vertex > data;
|
||||||
private Collection< EdgePolygon > polygons;
|
private Collection< EdgePolygon > polygons;
|
||||||
|
|
||||||
|
// Temporary... Remove at some point
|
||||||
|
private static Collection< Chain > chains;
|
||||||
|
|
||||||
public static void main( String[] args ) {
|
public static void main( String[] args ) {
|
||||||
if ( CHUNK_DIR.exists() && CHUNK_DIR.isDirectory() ) {
|
if ( CHUNK_DIR.exists() && CHUNK_DIR.isDirectory() ) {
|
||||||
System.out.println( "Found " + CHUNK_DIR.list().length + " files" );
|
System.out.println( "Found " + CHUNK_DIR.list().length + " files" );
|
||||||
for ( File file : CHUNK_DIR.listFiles() ) {
|
for ( File file : CHUNK_DIR.listFiles() ) {
|
||||||
Collection< Plane > planes = mesh( file );
|
List< Plane > planes = mesh( file );
|
||||||
|
|
||||||
Plane draw = null;
|
Plane draw = null;
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ public class MeshingTest2 extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection< Plane > mesh( File file ) {
|
private static List< Plane > mesh( File file ) {
|
||||||
String name = file.getName();
|
String name = file.getName();
|
||||||
String[] split = name.split( "," );
|
String[] split = name.split( "," );
|
||||||
ChunkLocation location = new ChunkLocation( split[ 0 ], Integer.parseInt( split[ 1 ] ), Integer.parseInt( split[ 2 ] ) );
|
ChunkLocation location = new ChunkLocation( split[ 0 ], Integer.parseInt( split[ 1 ] ), Integer.parseInt( split[ 2 ] ) );
|
||||||
@@ -187,7 +188,7 @@ public class MeshingTest2 extends JPanel {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
mesh.simplify();
|
mesh.simplify();
|
||||||
mesh.generateRegions();
|
mesh.generateRegions();
|
||||||
final Collection< EdgePolygon > polys = mesh.mesh();
|
final Collection< EdgePolygon > polys = mesh.copyOf().mesh();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println( plane.polygons.size() + " to " + polys.size() + ":\t " + ( end - start ) + "ms" );
|
System.out.println( plane.polygons.size() + " to " + polys.size() + ":\t " + ( end - start ) + "ms" );
|
||||||
} catch ( IllegalStateException e ) {
|
} catch ( IllegalStateException e ) {
|
||||||
@@ -263,6 +264,7 @@ public class MeshingTest2 extends JPanel {
|
|||||||
mesh = mesh.copyOf();
|
mesh = mesh.copyOf();
|
||||||
|
|
||||||
final Collection< EdgePolygon > polys = mesh.mesh();
|
final Collection< EdgePolygon > polys = mesh.mesh();
|
||||||
|
chains = mesh.chains;
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println( "Took " + ( end - start ) + "ms" );
|
System.out.println( "Took " + ( end - start ) + "ms" );
|
||||||
|
|
||||||
@@ -431,9 +433,9 @@ public class MeshingTest2 extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved( MouseWheelEvent e ) {
|
public void mouseWheelMoved( MouseWheelEvent e ) {
|
||||||
if ( e.getWheelRotation() < 0 ) {
|
if ( e.getWheelRotation() < 0 ) {
|
||||||
scroll += 0.5;
|
scroll += e.isControlDown() ? 0.1 : 0.5;
|
||||||
} else {
|
} else {
|
||||||
scroll -= 0.5;
|
scroll -= e.isControlDown() ? 0.1 : 0.5;
|
||||||
}
|
}
|
||||||
scale = Math.exp( scroll );
|
scale = Math.exp( scroll );
|
||||||
|
|
||||||
@@ -554,11 +556,27 @@ public class MeshingTest2 extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( chains != null ) {
|
||||||
|
for ( Chain chain : chains ) {
|
||||||
|
Point p1 = chain.getOrigin().getPosition();
|
||||||
|
Point p2 = chain.getDest().getPosition();
|
||||||
|
g.setColor( Color.RED );
|
||||||
|
g.drawLine(
|
||||||
|
( int ) ( ( centerX + p1.getX() + 40 ) * scale ) + offsetX,
|
||||||
|
( int ) ( ( centerY - p1.getY() ) * scale ) + offsetY,
|
||||||
|
( int ) ( ( centerX + p2.getX() + 40 ) * scale ) + offsetX,
|
||||||
|
( int ) ( ( centerY - p2.getY() ) * scale ) + offsetY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
java.awt.Point p = MouseInfo.getPointerInfo().getLocation();
|
java.awt.Point p = MouseInfo.getPointerInfo().getLocation();
|
||||||
p = new java.awt.Point( p.x - getLocation().x, p.y - getLocation().y );
|
java.awt.Point componentLocation = getLocation();
|
||||||
|
SwingUtilities.convertPointToScreen( componentLocation, this );
|
||||||
|
p = new java.awt.Point( p.x - componentLocation.x, p.y - componentLocation.y );
|
||||||
g.setColor( Color.RED );
|
g.setColor( Color.RED );
|
||||||
g.setFont( new Font( Font.MONOSPACED, Font.BOLD, 30 ) );
|
g.setFont( new Font( Font.MONOSPACED, Font.BOLD, 30 ) );
|
||||||
g.drawString( "X: " + ( ( p.x - offsetX ) / scale - centerX ), 10, 30 );
|
g.drawString( "X: " + ( ( p.x - offsetX ) / scale - centerX ), 10, 30 );
|
||||||
g.drawString( "Y: " + ( ( p.y - offsetY ) / scale - centerY ), 10, 60 );
|
g.drawString( "Y: " + ( - ( ( p.y - offsetY ) / scale - centerY ) ), 10, 60 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user