Adjacent Triangles

Blitz3D Forums/Blitz3D Beginners Area/Adjacent Triangles

A (much) simpler program to reproduce the problem:

graphics3d 800, 600
camera = createcamera()
positionentity(camera, 0, 0, -3)

const BLOCK_SIZE#         = 1.0
const BLOCK_BEVEL_WIDTH#  = 0.2

; lookup coordinates (x and y are identical)
global x#[3]
global y#[3]
global z#[3]
x[0] = -BLOCK_SIZE / 2
x[1] = -BLOCK_SIZE / 2 + BLOCK_BEVEL_WIDTH
x[2] =  BLOCK_SIZE / 2 - BLOCK_BEVEL_WIDTH
x[3] =  BLOCK_SIZE / 2
y[0] = -BLOCK_SIZE / 2
y[1] = -BLOCK_SIZE / 2 + BLOCK_BEVEL_WIDTH
y[2] =  BLOCK_SIZE / 2 - BLOCK_BEVEL_WIDTH
y[3] =  BLOCK_SIZE / 2
z[0] =  BLOCK_SIZE / 2
z[1] =  BLOCK_SIZE / 2 - BLOCK_BEVEL_WIDTH
z[2] = -BLOCK_SIZE / 2 + BLOCK_BEVEL_WIDTH
z[3] = -BLOCK_SIZE / 2

; create block
block = createmesh()
surface_id = createsurface(block)

vertex_0 = addvertex(surface_id, x[1], y[0], z[3])
vertex_1 = addvertex(surface_id, x[1], y[3], z[3])
vertex_2 = addvertex(surface_id, x[2], y[3], z[3])
addtriangle(surface_id, vertex_0, vertex_1, vertex_2)
vertex_3 = addvertex(surface_id, x[2], y[0], z[3])
addtriangle(surface_id, vertex_0, vertex_2, vertex_3)

vertex_4 = addvertex(surface_id, x[2], y[2], z[3])
vertex_5 = addvertex(surface_id, x[3], y[2], z[3])
vertex_6 = addvertex(surface_id, x[3], y[1], z[3])
addtriangle(surface_id, vertex_4, vertex_5, vertex_6)
vertex_7 = addvertex(surface_id, x[2], y[1], z[3])
addtriangle(surface_id, vertex_4, vertex_6, vertex_7)

; translucency better shows the artifacts
entityalpha(block, .5)
ambientlight(255, 255, 255)

; move it around with the mouse to see artifacts
movemouse(400, 300)
while true
	if keyhit(1) then end
	rotateentity(block, -mousey()+300, mousex()-400, 0)
	renderworld
	flip
wend