jPCT - a 3d engine for Java > Support

Painting a Mouse Cursor-Selected Polygon

<< < (3/4) > >>

AGP:
I wrote this:

--- Code: ---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);
     }
}

--- End code ---

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):


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

--- End code ---

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?


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

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version