Starchasers / OCGlasses

mod for minecraft and addon for Open Computers
zlib License
30 stars 17 forks source link

Triangle drawing problem (addCustom2D()) #84

Closed SAlexW closed 3 years ago

SAlexW commented 4 years ago

Found problem with glasses.addCustom2D(). I made a simple script that should move the vertices of the triangle. Each time, all widgets are destroyed and repainted. For convenience, I have marked which vertex is drawn first (red square), which is the second (green square) and which is the third (blue square). So. While the vertex moved along the edge of the square, inside which the triangle was drawn, all is well, but it was worth trying to "flip" the triangle along the long side, as a problem was found: after the vertex crossed the long side, the triangle was no longer there. The marks-squares continued to move. Code:

comp = require("component")
g = comp.glasses

g.startLinking()
for i=1, 51 do
g.removeAll()
wt = g.addCustom2D()
wb1 = g.addBox2D()
wb2 = g.addBox2D()
wb3 = g.addBox2D()
wb1.addColor(1, 0, 0, 1)
wb2.addColor(0, 1, 0, 1)
wb3.addColor(0, 0, 1, 1)
wb1.setSize(10, 10)
wb2.setSize(10, 10)
wb3.setSize(10, 10)
wb1.addTranslation(95, 145, -1)
wb2.addTranslation(145, 95, -1)
wb3.addTranslation(100+i-6, 100+i-6, -1) 
wt.addVertex(100, 150, 0)
wt.addVertex(150, 100, 0)
wt.addVertex(100+i-1, 100+i-1, 0)
wt.addColor(0.7, 0, 1, 0.5)
wt.setGLMODE("TRIANGLE_STRIP")
wt.setShading("FLAT")
os.sleep(0.2)
end
ben-mkiv commented 4 years ago

Thats due to the nature that Minecraft enables face culling, which doesnt draw the backside of a Face (whats front and what's back is determined by the order of how you define the vertices)

However, i've added a new method to disable face culling in 2.2-50 which is on curseForge now, so your code should be like this

comp = require("component")
g = comp.glasses

g.startLinking()
for i=1, 51 do
g.removeAll()
wt = g.addCustom2D()
wt.setCulling(false)
wb1 = g.addBox2D()
wb2 = g.addBox2D()
wb3 = g.addBox2D()
wb1.addColor(1, 0, 0, 1)
wb2.addColor(0, 1, 0, 1)
wb3.addColor(0, 0, 1, 1)
wb1.setSize(10, 10)
wb2.setSize(10, 10)
wb3.setSize(10, 10)
wb1.addTranslation(95, 145, -1)
wb2.addTranslation(145, 95, -1)
wb3.addTranslation(100+i-6, 100+i-6, -1) 
wt.addVertex(100, 150, 0)
wt.addVertex(150, 100, 0)
wt.addVertex(100+i-1, 100+i-1, 0)
wt.addColor(0.7, 0, 1, 0.5)
wt.setGLMODE("TRIANGLE_STRIP")
wt.setShading("FLAT")
os.sleep(0.2)
end