🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Coordinate system conversions

Started by
0 comments, last by Bleech_Studios 4 years, 2 months ago

Sorry if this is the wrong place to ask this, please do tell me where a question like this is better asked.

Im importing a model from another game into the video game minecraft, which uses a coordinate system where a coordinate maps to a block in the world. Ive scaled it correctly as good as I can but each block (or set of 8 vertices for each corner) are scaled wrong. This is hard to explain but here take this image:

https://imgur.com/a/tE00E9F (2nd image, scroll down)

The blocks which import to minecraft are scaled wrong, and the blocks vertices are where the fence poles are. So in the picture above, in minecraft the width is 5 blocks, but it should be 4 blocks because If you see the fence poles they show the outlines of the block which should be placed. Ideally I want to create the block at ONE of the corners of each fence pole (which represents a block), it doesnt matter the corner as the model would still import, just with a 1 offset depending on which vertex (bottom left,bottom right,top right or top left, + all the others for the z coordinate…) the block is placed at.

i.e, the left 8 blocks in the picture represent the 8 vertices of the single block in the right:

https://imgur.com/a/tE00E9F (top one, there are 8 blocks on the left, although it seems 4)

Since this does not need to be done fast, I just loop though each vertex of the blocks that should be placed and are in the model, but place a block at each vertex instead. Maybe I have to group these vertices up? If so, how would I do that with big models?

I read the vertices from a file here, this is the loop right now:

Code (Text):


for(int x = 1; x <= vertCount; x++) {
float f = buf.readFloat();
p.verts.add(f);
}

Yes, I see how you would be confused by this. Each vertex in the loop above gets grouped in threes. So when x = 1, thats the x coord of the first vertex, then y and z, then new loop etc..

(This gets handled somewhere else)

The problem is that im placing blocks in minecraft at the vertices of the block that should be placed.

(P.S, the vertices are in floats, but they are whole numbers it just some are smaller than a block and have decimal points but I handle that elsewhere)

This is where I group the vertices:

Code (Text):


int i=0;
short index1; //cache the x
short index2;//cache the y
for(short x : faces){
if(i==1) {//this loop gets the x
index1=x;
i++;
continue;
}else if(i==2) {//this lop gets the y
index2=x;
i++;
continue;
}else {//this loop gets the z, also place the block here too and start collecting x,y,z again
float pos1x = poly.verts.get(index1*3) /100;
float pos1y = poly.verts.get((index1*3)+1) /100;
float pos1z = poly.verts.get((index1*3)+2) /100;
float pos2x = poly.verts.get(index2*3) /100;
float pos2y = poly.verts.get((index2*3)+1) /100;
float pos2z = poly.verts.get((index2*3)+2) /100;
float pos3x = poly.verts.get(x*3) /100;
float pos3y = poly.verts.get((x*3)+1) /100;
float pos3z = poly.verts.get((x*3)+2) /100;
drawTriangle(pos1x,pos1y,pos1z,pos2x,pos2y,pos2z,pos3x,pos3y,pos3z);
i=1;
continue;
}
}

In the loop which this code lies in, It loops though each FACE (sets of three coordinates (like the vertices list)) I loop through a list of shorts which specify the index in vertices list which should connect to draw) the which each of the three sets of vertices connect up to.

drawTriangle takes three points and just places a block at each block inbetween the three corners of the face in the face, as the model im importing is just lots of triangles which make a mesh

EDIT: The dividing of 100 scales the model into blocks which are the same size as minecraft. Also, the model being imported is blocks, no circles, etc..

This topic is closed to new replies.

Advertisement