Perhaps what I will do is create a matrix called "lines". This will store a numbered list of points, and a list of other points they connect to with lines. So points[ i][ j] would refer to point number "i", as having a connection to whatever point number is being stored in [ j].
Take a square. That's 4 points connected with 4 lines.
The matrix would look like this:
{ 0 3 1 }
{ 1 0 2 }
{ 2 1 3 }
{ 3 2 0 }
To store the data about this square, I might use something like this:
-- store data about a square
-- point data
pointX[0] = 25
pointY[0] = 25
pointX[1] = 25
pointY[1] = -25
pointX[2] = -25
pointY[2] = -25
pointX[3] = -25
pointY[3] = 25
numberofpoints = 3
-- line data
lines[0][0] = 3
lines[0][1] = 1
lines[1][0] = 0
lines[1][1] = 2
lines[2][0] = 1
lines[2][1] = 3
lines[3][0] = 2
lines[3][1] = 0
Finally, to draw the object, I simply do one Draw command per declared line:
-- for each point, draw all its lines
for i = 0,numberofpoints do
-- we need to calculate how many lines this point is part of
linenumber = -1
for numberoflinescheck = 0,100 do
if lines[i][linenumber] ~= nil then
linenumber = linenumber + 1
else
break
end
end
-- we now know this point is connected to "linenumber" other points by lines
for j = 0,linenumber do
-- now we take each of the other points...
destinationpoint = lines[i][j]
-- and retrieve the coordinates of that point
destX = pointX[destinationpoint]
destY = pointY[destinationpoint]
-- then we draw the line from the current point to the stored point.
DrawLine(pointX[i], pointY[i], destX, destY, 1,1,1,1,1,1,1,1,10)
end
end
One major problem of this approach is that many lines will be drawn twice.
Consider 2 points connected by a line. Under this system, first it would draw a line from Point A to Point B. Then, it would draw a line from Point B to Point A. That's the same line!! This is wasteful. Wonder how I can optimise that..
By the way this doesn't count as programming anything yet. :P