Well, after a little bit of struggling yesterday I've come up with a buggy, but somewhat-working, implementation.

My basic steps are as follows:

**Get the vector of the line:**

lineDirection = (lineStart - lineEnd)

**Find our soon-to-be constructed quad's normal as:**

quadNormal = cameraPosition - lineMidpoint

Where lineMidpoint = ((lineStart + lineEnd) / 2). I reason this should be the quad's normal since the quad will always be facing the camera, like a billboard.**Get the direction along which we should extrude vertices from our line**, which is the cross product of lineDirection and quadNormal:

extrudeDirection = Vector3.Cross(lineDirection, quadNormal)

Normalize extrudeDirection.**Get the W of lineStart and lineEnd by transforming them by the viewMatrix * projectionMatrix.**

wStart = (Vector3.Transform(lineStart, viewMatrix * projectionMatrix)).W
wEnd = (Vector3.Transform(lineEnd, viewMatrix * projectionMatrix)).W

**Extrude vertices from the line along the extrudeDirection vector, in some multiple of the W.**

Vector3 startVert1 = lineStart + extrudeDirection * wStart * lineWeight
Vector3 startVert2 = lineStart - extrudeDirection * wStart * lineWeight
Vector3 endVert1 = lineEnd + extrudeDirection * wEnd * lineWeight
Vector3 endVert2 = lineEnd - extrudeDirection * wEnd * lineWeight

**Connect the vertices to form a quad.**

And therein lies the hitch, which took some unraveling for me.

If you are far from the line, both W's will be positive, which is fine, since presumably you connected your four vertices to form a quad with the diagonal of the triangles being shared between them. Un-projected, this quad looks like a trapezoid, with bases on either side, and one base larger than the other to cancel out the W-divide. Everything works well.

However, if you get close to the line and rotate the camera a bit to face one end, one vertex will go off-screen and behind the camera, and thus one of the W's will be negative. This mathematically legit, I've reasoned, but your vertices that you extrude will be created on opposite sides of the line. If you don't change the way your vertices are connected in this situation, your triangle's diagonals will cross, because on one side of the quad the vertices have been flipped over the line. The result is you get an extra "flap" of the triangle either below or above your line, which confused me to no end yesterday. In the below

~~(high-quality rendering)~~ diagram, the red section is what I'm talking about.

To get rid of the red section, I adjusted the vertices of the triangles to the

**point where the diagonals cross** **when one of the W's was negative.** That way, you'd get just the white part of the two triangles. (To get this point, I solve the equations of the two lines in 3D (since they're coplanar, they will intersect).)

That seemed to solve the problem in one little test I did, but when I scaled up and made a bunch of lines for my in-game grid, problems galore popped up, including some of the same problems the D3DXLine class seems to have (it appears to negate the transforms when you get close), which is not a good sign.

If anyone had the patience to read my essay on drawing lines with quads and has an idea on where in this process I went wrong, please do let me know--I'm very curious. I also don't want to abandon thick lines, but for now I'm just using a LINE_LIST to draw my grid.

I'll keep us updated if I come up with anything else, too.

Best,

-- Steve