Is Interact2D.getPolygon(worldSpaceVectors) Trivial to Write?

Started by AGP, January 20, 2011, 09:04:25 PM

Previous topic - Next topic

AGP

I'm thinking of something like the following. The idea would be to use the Java2D things like the contains methods when your world (like my QG game) is 2D...


Object3D something = ...;
VertexController somethingController = new VertexController(something);
SimpleVector[] worldSpaceVectors = somethingController.getWorldSpaceVertices();
Camera camera = world.getCamera();
java.awt.Polygon 2dPoly = Interact2D.getPolygon(worldSpaceVectors, camera);
class VertexController extends GenericVertexController {
    private Object3D theObject;
    public VertexController(Object3D theObject) {
super.init(theObject.getMesh(), true);
this.theObject = theObject;
    }

    public SimpleVector[] getWorldspaceVertices() {
SimpleVector[] vertices = getSourceMesh(), wsVertices = new SimpleVector[vertices.length];
for (int i = 0; i < vertices.length; i++) {
     wsVertices[i] = vertices[i];
     wsVertices[i].matMul(theObject.getWorldTransformation());//Object3D.getMesh() RETURNS THE MESH (OBJECTSPACE)
}
return wsVertices;
    }
    public void apply() {}
}


EgonOlsen

You can already obtain the transformed vertices of a polygon from the polygon manager. With those, you can go to Interact2D.project3D2D to get the coordinates in screen space. From those, you should be able to create your java.awt.Polygon. It won't be very fast if you do it each frame for a high polygon number though.

AGP

No, it's just for those ground planes, and it doesn't need to happen more than twice per second.