Author Topic: Is Interact2D.getPolygon(worldSpaceVectors) Trivial to Write?  (Read 1997 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Is Interact2D.getPolygon(worldSpaceVectors) Trivial to Write?
« on: January 20, 2011, 09:04:25 pm »
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...

Code: [Select]
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() {}
}


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Is Interact2D.getPolygon(worldSpaceVectors) Trivial to Write?
« Reply #1 on: January 20, 2011, 09:11:19 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Is Interact2D.getPolygon(worldSpaceVectors) Trivial to Write?
« Reply #2 on: January 20, 2011, 09:13:11 pm »
No, it's just for those ground planes, and it doesn't need to happen more than twice per second.