Painting a Mouse Cursor-Selected Polygon

Started by AGP, February 07, 2017, 06:52:55 AM

Previous topic - Next topic

AGP

I'm trying to paint an area of my 3d plane as a cursor is moved (think area selection for building in a strategy game). The furthest (farthest?) I got was:

VisList visList = theWorld.getVisibilityList();
int polyID = Interact2D.getPolygonID(Interact2D.pickPolygon(visList, Interact2D.reproject2D3D(theCamera, buffer, x, y)));

I assume that camera-space is all I need here, since the docs suggest reproject2D3D and not reproject2D3DWS. Even if this is right, how can I now get something useful out of it (like, say, the vertices of the returned polygon)?

EgonOlsen

You can get the (transformed) vertices from the PolygonManager by the polygon's ID. Not sure if that really helps here though. If you need the actual raw data for manipulating the polygons in a VertexController or something like that, you have create a kind of mapping between them. However, once they are compiled, your options to fiddle around with the polygons/vertices are limited anyway.

AGP

I'm using the software renderer, so I can use the vertices. What about the surrounding triangles?

EgonOlsen

You could guess them by matching coordinates and such....not sure if that's a great approach though.

AGP


EgonOlsen

Not sure...what exactly do you want to achieve? Is that supposed to be a marker that moves or a permanent selection?


EgonOlsen

In that case, you might have a know order in which the terrain has been build. I would rather rely on that instead of extracting the lost information from the mesh again. If you have to do it that way, then you could find a polygon's adjacent polygons by comparing the vertices.

AGP

In this particular case, I created the plane with the Primitives class. Is that no good or is there some kind of loop I could undergo to map the triangles?

EgonOlsen

Yes, you could use a combination of a vertex controller and the PolygonManager to map your polygons. I can't find an example for this ATM, but I'm pretty sure that I did similar things in the past.

AGP

I wrote this:

import com.threed.jpct.Object3D;

public class Ground {
     protected IntelligentPlane[][] planes;

     public Ground(int sizeX, int sizeY) {
planes = new IntelligentPlane[sizeX][sizeY];
for (int y = 0; y < sizeY; y++)
     for (int x = 0; x < sizeX; x++)
planes[x][y] = new IntelligentPlane(x, y);
     }
     public void setName(String name) {
for (int y = 0; y < sizeY; y++)
     for (int x = 0; x < sizeX; x++)
planes[x][y].setName(name +" ("+x+", "+y +")");
     }
}
class IntelligentPlane extends Object3D {
     public int x, y;
     public IntelligentPlane(int x, int y) {
super(Primitives.getPlane(1, 1f));
this.x = x;
this.y = y;
plane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
     }
}


Now, how could I map chunks of the map into their appropriate triangles?

EgonOlsen

By getting all polygons (or to be more precise: their vertices) from the PolygonManager and grouping them based on shared vertices and/or position in 3d space.

AGP

Sorry, I meant, "how do I break up the texture map into tiny maps for each plane?"

AGP

This is what I have for Ground.setTexture(String):


     public void setTexture(String name) {

Texture tex = com.threed.jpct.TextureManager.getInstance().getTexture(name);
Texture[][] subTextures = new Texture[planes.length][planes[0].length];

int sizeX = planes.length, sizeY = planes[0].length;
int width = tex.getWidth()/sizeX, height = tex.getHeight()/sizeY;
for (int y = 0; y < sizeY; y++)
     for (int x = 0; x < sizeX; x++) {
subTextures[x][y] = new Texture(width, height);
//NOW HOW TO PAINT A TEXTURE CHUNK INTO THIS SUB TEXTURE?
     }
}
     }

AGP

I made an AWT hack (as seen in the bottom). But now the line that's keeping me is this (level being an instance of Ground):         SimpleVector pV = Interact2D.project3D2D(theCamera, buffer, level.getPolygonManager().getTransformedVertex(constructionPolyID, 0));
How do I do this with the Ground class?


     public void setTexture(Image tex) {
BufferedImage bImage = new BufferedImage(tex.getWidth(null), tex.getHeight(null));
bImage.getGraphics().drawImage(tex, 0, 0, null);
Texture[][] subTextures = new Texture[planes.length][planes[0].length];
int sizeX = planes.length, sizeY = planes[0].length;
int width = tex.getWidth()/sizeX, height = tex.getHeight()/sizeY;
for (int y = 0; y < sizeY; y++) {
     for (int x = 0; x < sizeX; x++) {
subTextures[x][y] = new Texture(bImage.getSubImage(sizeX*x, sizeY*y, width, height));
TextureManager.getInstance().addTexture("Ground "+"("+x+", "+y+")");
planes[x][y].setTexture("Ground "+"("+x+", "+y+")");
     }
}
     }