mirror of
https://github.com/minetest/minetest.git
synced 2024-11-10 09:43:45 +01:00
Improve raillike drawtype
This commit is contained in:
parent
d834d6e074
commit
f21291211c
@ -883,22 +883,69 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
bool is_rail_x [] = { false, false }; /* x-1, x+1 */
|
bool is_rail_x [] = { false, false }; /* x-1, x+1 */
|
||||||
bool is_rail_z [] = { false, false }; /* z-1, z+1 */
|
bool is_rail_z [] = { false, false }; /* z-1, z+1 */
|
||||||
|
|
||||||
|
bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
|
||||||
|
bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
|
||||||
|
bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
|
||||||
|
bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
|
||||||
|
|
||||||
MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
|
MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
|
||||||
MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
|
MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
|
||||||
MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
|
MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
|
||||||
MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
|
MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
|
||||||
|
MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
|
||||||
|
MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
|
||||||
|
MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
|
||||||
|
MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
|
||||||
|
MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
|
||||||
|
MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
|
||||||
|
MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
|
||||||
|
MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
|
||||||
|
|
||||||
content_t thiscontent = n.getContent();
|
content_t thiscontent = n.getContent();
|
||||||
if(n_minus_x.getContent() == thiscontent)
|
if(n_minus_x.getContent() == thiscontent)
|
||||||
is_rail_x[0] = true;
|
is_rail_x[0] = true;
|
||||||
|
if (n_minus_x_minus_y.getContent() == thiscontent)
|
||||||
|
is_rail_x_minus_y[0] = true;
|
||||||
|
if(n_minus_x_plus_y.getContent() == thiscontent)
|
||||||
|
is_rail_x_plus_y[0] = true;
|
||||||
|
|
||||||
if(n_plus_x.getContent() == thiscontent)
|
if(n_plus_x.getContent() == thiscontent)
|
||||||
is_rail_x[1] = true;
|
is_rail_x[1] = true;
|
||||||
|
if (n_plus_x_minus_y.getContent() == thiscontent)
|
||||||
|
is_rail_x_minus_y[1] = true;
|
||||||
|
if(n_plus_x_plus_y.getContent() == thiscontent)
|
||||||
|
is_rail_x_plus_y[1] = true;
|
||||||
|
|
||||||
if(n_minus_z.getContent() == thiscontent)
|
if(n_minus_z.getContent() == thiscontent)
|
||||||
is_rail_z[0] = true;
|
is_rail_z[0] = true;
|
||||||
|
if (n_minus_z_minus_y.getContent() == thiscontent)
|
||||||
|
is_rail_z_minus_y[0] = true;
|
||||||
|
if(n_minus_z_plus_y.getContent() == thiscontent)
|
||||||
|
is_rail_z_plus_y[0] = true;
|
||||||
|
|
||||||
if(n_plus_z.getContent() == thiscontent)
|
if(n_plus_z.getContent() == thiscontent)
|
||||||
is_rail_z[1] = true;
|
is_rail_z[1] = true;
|
||||||
|
if (n_plus_z_minus_y.getContent() == thiscontent)
|
||||||
|
is_rail_z_minus_y[1] = true;
|
||||||
|
if(n_plus_z_plus_y.getContent() == thiscontent)
|
||||||
|
is_rail_z_plus_y[1] = true;
|
||||||
|
|
||||||
int adjacencies = is_rail_x[0] + is_rail_x[1] + is_rail_z[0] + is_rail_z[1];
|
|
||||||
|
bool is_rail_x_all[] = {false, false};
|
||||||
|
bool is_rail_z_all[] = {false, false};
|
||||||
|
is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
|
||||||
|
is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
|
||||||
|
is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
|
||||||
|
is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
|
||||||
|
|
||||||
|
bool is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);//is really straight, rails on both sides
|
||||||
|
int adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
|
||||||
|
|
||||||
|
if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1]) //is straight because sloped
|
||||||
|
{
|
||||||
|
adjacencies = 5; //5 means sloped
|
||||||
|
is_straight = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Assign textures
|
// Assign textures
|
||||||
AtlasPointer ap = f.tiles[0].texture; // straight
|
AtlasPointer ap = f.tiles[0].texture; // straight
|
||||||
@ -906,7 +953,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
ap = f.tiles[0].texture; // straight
|
ap = f.tiles[0].texture; // straight
|
||||||
else if(adjacencies == 2)
|
else if(adjacencies == 2)
|
||||||
{
|
{
|
||||||
if((is_rail_x[0] && is_rail_x[1]) || (is_rail_z[0] && is_rail_z[1]))
|
if(is_straight)
|
||||||
ap = f.tiles[0].texture; // straight
|
ap = f.tiles[0].texture; // straight
|
||||||
else
|
else
|
||||||
ap = f.tiles[1].texture; // curved
|
ap = f.tiles[1].texture; // curved
|
||||||
@ -928,49 +975,71 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
|
u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
|
||||||
video::SColor c = MapBlock_LightColor(255, l);
|
video::SColor c = MapBlock_LightColor(255, l);
|
||||||
|
|
||||||
float d = (float)BS/16;
|
float d = (float)BS/64;
|
||||||
|
|
||||||
|
char g=-1;
|
||||||
|
if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
|
||||||
|
g=1; //Object is at a slope
|
||||||
|
|
||||||
video::S3DVertex vertices[4] =
|
video::S3DVertex vertices[4] =
|
||||||
{
|
{
|
||||||
video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
|
video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
|
||||||
ap.x0(), ap.y1()),
|
ap.x0(), ap.y1()),
|
||||||
video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
|
video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
|
||||||
ap.x1(), ap.y1()),
|
ap.x1(), ap.y1()),
|
||||||
video::S3DVertex(BS/2,-BS/2+d,BS/2, 0,0,0, c,
|
video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c,
|
||||||
ap.x1(), ap.y0()),
|
ap.x1(), ap.y0()),
|
||||||
video::S3DVertex(-BS/2,-BS/2+d,BS/2, 0,0,0, c,
|
video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c,
|
||||||
ap.x0(), ap.y0()),
|
ap.x0(), ap.y0()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Rotate textures
|
// Rotate textures
|
||||||
int angle = 0;
|
int angle = 0;
|
||||||
|
|
||||||
if(adjacencies == 1)
|
if(adjacencies == 1)
|
||||||
{
|
{
|
||||||
if(is_rail_x[0] || is_rail_x[1])
|
if(is_rail_x_all[0] or is_rail_x_all[1])
|
||||||
angle = 90;
|
angle = 90;
|
||||||
}
|
}
|
||||||
else if(adjacencies == 2)
|
if(adjacencies == 2)
|
||||||
|
{
|
||||||
|
if(is_rail_x_all[0] && is_rail_x_all[1])
|
||||||
{
|
{
|
||||||
if(is_rail_x[0] && is_rail_x[1])
|
|
||||||
angle = 90;
|
angle = 90;
|
||||||
else if(is_rail_x[0] && is_rail_z[0])
|
}
|
||||||
|
if(is_rail_z_all[0] && is_rail_z_all[1])
|
||||||
|
{
|
||||||
|
if (n_minus_z_plus_y.getContent() == thiscontent) angle = 180;
|
||||||
|
}
|
||||||
|
else if(is_rail_x_all[0] && is_rail_z_all[0])
|
||||||
angle = 270;
|
angle = 270;
|
||||||
else if(is_rail_x[0] && is_rail_z[1])
|
else if(is_rail_x_all[0] && is_rail_z_all[1])
|
||||||
angle = 180;
|
angle = 180;
|
||||||
else if(is_rail_x[1] && is_rail_z[1])
|
else if(is_rail_x_all[1] && is_rail_z_all[1])
|
||||||
angle = 90;
|
angle = 90;
|
||||||
}
|
}
|
||||||
else if(adjacencies == 3)
|
if(adjacencies == 3)
|
||||||
{
|
{
|
||||||
if(!is_rail_x[0])
|
if(!is_rail_x_all[0])
|
||||||
angle=0;
|
angle=0;
|
||||||
if(!is_rail_x[1])
|
if(!is_rail_x_all[1])
|
||||||
angle=180;
|
angle=180;
|
||||||
if(!is_rail_z[0])
|
if(!is_rail_z_all[0])
|
||||||
angle=90;
|
angle=90;
|
||||||
if(!is_rail_z[1])
|
if(!is_rail_z_all[1])
|
||||||
angle=270;
|
angle=270;
|
||||||
}
|
}
|
||||||
|
//adjacencies 4: Crossing
|
||||||
|
if(adjacencies == 5) //sloped
|
||||||
|
{
|
||||||
|
if(is_rail_z_plus_y[0])
|
||||||
|
angle = 180;
|
||||||
|
if(is_rail_x_plus_y[0])
|
||||||
|
angle = 90;
|
||||||
|
if(is_rail_x_plus_y[1])
|
||||||
|
angle = -90;
|
||||||
|
}
|
||||||
|
|
||||||
if(angle != 0) {
|
if(angle != 0) {
|
||||||
for(u16 i=0; i<4; i++)
|
for(u16 i=0; i<4; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user