Author Topic: Painting a Mouse Cursor-Selected Polygon  (Read 1314 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Painting a Mouse Cursor-Selected Polygon
« on: February 07, 2017, 06:52:55 am »
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:
Code: [Select]
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)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #1 on: February 07, 2017, 08:35:59 am »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #2 on: February 07, 2017, 04:28:45 pm »
I'm using the software renderer, so I can use the vertices. What about the surrounding triangles?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #3 on: February 08, 2017, 08:25:10 am »
You could guess them by matching coordinates and such....not sure if that's a great approach though.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #4 on: February 08, 2017, 07:36:59 pm »
What would you suggest instead?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #5 on: February 08, 2017, 08:53:18 pm »
Not sure...what exactly do you want to achieve? Is that supposed to be a marker that moves or a permanent selection?

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #6 on: February 09, 2017, 02:45:46 am »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #7 on: February 09, 2017, 08:37:58 am »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #8 on: February 09, 2017, 05:08:12 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #9 on: February 09, 2017, 07:11:31 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #10 on: February 09, 2017, 08:22:01 pm »
I wrote this:
Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #11 on: February 10, 2017, 08:49:22 am »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #12 on: February 10, 2017, 03:02:42 pm »
Sorry, I meant, "how do I break up the texture map into tiny maps for each plane?"

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #13 on: February 10, 2017, 04:14:28 pm »
This is what I have for Ground.setTexture(String):

Code: [Select]
     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?
     }
}
     }

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Painting a Mouse Cursor-Selected Polygon
« Reply #14 on: February 10, 2017, 04:54:27 pm »
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?

Code: [Select]
     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+")");
     }
}
     }