package blocks import ( "edgaru089.ml/go/gl01/internal/asset" "edgaru089.ml/go/gl01/internal/util/itype" "edgaru089.ml/go/gl01/internal/world" ) // texname is the full filename of the texture file (with .png) // faceOffset is added to each vertex func appendFace(face itype.Direction, pos itype.Vec3i, texname string, faceOffset itype.Vec3f, arr []world.Vertex) []world.Vertex { switch face { case itype.XPlus: // X+ arr = append(arr, // Vertex Position Normal Vector(normalized) Texture Coord Light world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 1}, 16}, ) case itype.XMinus: // X- arr = append(arr, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 0}, 16}, ) case itype.YPlus: // Y+ arr = append(arr, world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 0}, 16}, ) case itype.YMinus: // Y- arr = append(arr, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 1}, 16}, ) case itype.ZPlus: // Z+ arr = append(arr, world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 1}, 16}, world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 1}, 16}, ) case itype.ZMinus: // Z- arr = append(arr, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 0}, 16}, world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 1}, 16}, world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 0}, 16}, world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 1}, 16}, ) } texrect := asset.WorldTextureAtlas.RectNormalized(texname) for i := len(arr) - 6; i < len(arr); i++ { arr[i].Texture[0] = texrect.Left + arr[i].Texture[0]*texrect.Width arr[i].Texture[1] = texrect.Top + arr[i].Texture[1]*texrect.Height } return arr }