import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Objects; // stores both objects and other object collections public class ObjectCollection { public ArrayList<PointComp> points = new ArrayList<PointComp>(); private Object3d collectionObject; public ArrayList<ObjectCollection> subCollections = new ArrayList<ObjectCollection>(); public ArrayList<Object3d> objects = new ArrayList<Object3d>(); public void invalidate(boolean invalidatePoints){ // the first level of object collections should contain all the points for the sub-levels. // this means that we only need to invalidate them at the top level if(invalidatePoints){for (PointComp point: points) { point.invalidate(); }} for(ObjectCollection subCollection: subCollections){ subCollection.invalidate(false); } for(Object3d object: objects){ object.invalidate(); } } public void draw(BufferedImage img, BufferedImage debugimg, Matrix camMatrix, double FPDis, int scrX, int scrY, Point3D playerPos){ // todo check for frustum culling for (Object3d object: objects) { object.draw(img, debugimg, camMatrix, FPDis, scrX, scrY, playerPos); } // todo check for frustum culling for(ObjectCollection collection: subCollections){ collection.draw(img, debugimg, camMatrix, FPDis, scrX, scrY, playerPos); } } public void addCollection(int[] pointList){ subCollections.add(new ObjectCollection()); } // making sure that all the point indices make sense might be a nightmare but ehh public void addObject(Object3d object){ PointComp[] newpoints = object.points; objects.add(object); // add the new object // merge lists for (PointComp newpoint : newpoints) { boolean found = false; // find out if any of the new points already exist in the list for (PointComp point : points) { if (newpoint == point) { found = true; break; } } if (!found) { points.add(newpoint); } } } // }