I've been using this code for an isometric grid (I didn't write it)
This is the code:
Public Class IsometricBase 'written by Hammond Pearce
'this class creats a set of points to make an isometric grid like so: (ASCII ART FOLLOWS - MONOSPACE FONT REQUIRED)
' 3________C__________4
' / /
' / /
' B/ /D
' / /
' /__________________ /
' 1 A 2
Private sideApoints As Point() 'all the points along side A
Private sideBpoints As Point() 'all the points along side B
Private sideCpoints As Point() 'all the points along side C
Private sideDpoints As Point() 'all the points along side D
Private lastgridlines As Integer 'last gridlines used in calculatepoints, used in draw_all_points
Private Stored_Corners As Point() 'last corners used in calculatepoints, used in draw_all_points
Public ReadOnly Property SideA_Points() As Point()
Get
Return sideApoints
End Get
End Property
Public ReadOnly Property sideB_points() As Point()
Get
Return sideBpoints
End Get
End Property
Public ReadOnly Property sideC_points() As Point()
Get
Return sideCpoints
End Get
End Property
Public ReadOnly Property sideD_points() As Point()
Get
Return sideDpoints
End Get
End Property
Public Sub Calculatepoints(ByVal Corner1 As Point, ByVal Corner2 As Point, ByVal Corner3 As Point, ByVal Corner4 As Point, ByVal NumberOfGridlines As Integer)
'set up all variables
Stored_Corners = New Point(4) {New Point(0, 0), Corner1, Corner2, Corner3, Corner4} 'store the last points with an offset (the newpoint) so that its more userfriendly for me! :D
lastgridlines = NumberOfGridlines 'store the number of gridlines
Dim count As Integer 'used to put data in correct pocket in array
sideApoints = New Point(NumberOfGridlines) {} 'reset arrays ready to store
sideBpoints = New Point(NumberOfGridlines) {}
sideCpoints = New Point(NumberOfGridlines) {}
sideDpoints = New Point(NumberOfGridlines) {}
Dim temppoint As New Point 'used in do... loop as a temporary point to store values in
'side A
'reset common variables
count = 0
Do Until temppoint.X = Corner2.X And temppoint.Y = Corner2.Y 'do until the temppoint = the point we are working to
count += 1 'increment pocket
If count > NumberOfGridlines Then Exit Do
temppoint.X = Corner1.X - (Corner1.X - Corner2.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3
temppoint.Y = Corner1.Y - (Corner1.Y - Corner2.Y) / NumberOfGridlines * count
sideApoints(count) = temppoint 'store the temppoint as a real point
Loop
'side C
count = 0
Do Until temppoint.X = Corner4.X And temppoint.Y = Corner4.Y 'do until the temppoint = the point we are working to
count += 1 'increment pocket
If count > NumberOfGridlines Then Exit Do
temppoint.X = Corner3.X - (Corner3.X - Corner4.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3
temppoint.Y = Corner3.Y - (Corner3.Y - Corner4.Y) / NumberOfGridlines * count
sideCpoints(count) = temppoint 'store the temppoint as a real point
Loop
'sideB
count = 0
Do Until temppoint.X = Corner3.X And temppoint.Y = Corner3.Y 'do until the temppoint = the point we are working to
count += 1 'increment pocket
If count > NumberOfGridlines Then Exit Do
temppoint.X = Corner1.X + (Corner3.X - Corner1.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3
temppoint.Y = Corner1.Y + (Corner3.Y - Corner1.Y) / NumberOfGridlines * count
sideBpoints(count) = temppoint 'store the temppoint as a real point
Loop
'sideD
count = 0
Do Until temppoint.X = Corner4.X And temppoint.Y = Corner4.Y
count += 1
If count > NumberOfGridlines Then Exit Do
temppoint.X = Corner2.X + (Corner4.X - Corner2.X) / NumberOfGridlines * count
temppoint.Y = Corner2.Y + (Corner4.Y - Corner2.Y) / NumberOfGridlines * count
sideDpoints(count) = temppoint
Loop
End Sub
Public Sub Draw_All_Points(ByVal graphicsobject As Graphics, ByVal P As Pen)
'this subroutine draws the isometric grid according to the sidepoints and the stored corners, using the lastgridlines variable to control the arrays
With graphicsobject
.DrawLine(P, Stored_Corners(1), Stored_Corners(2)) 'draw the sides
.DrawLine(P, Stored_Corners(1), Stored_Corners(3))
.DrawLine(P, Stored_Corners(2), Stored_Corners(4))
.DrawLine(P, Stored_Corners(4), Stored_Corners(3))
End With
Dim i As Integer
For i = 0 To lastgridlines
graphicsobject.DrawLine(P, SideA_Points(i), sideC_points(i)) 'draw the gridlines
Next
For i = 0 To lastgridlines
graphicsobject.DrawLine(P, sideB_points(i), sideD_points(i))
Next
MainUI.readytoroll = True
End Sub
End Class
I'm trying to make it so whenever it finds the top left point (well, any of the 4 points on the block would work) that it adds the point to an array. But, I'm a bit confused on where/when in the code to actually put that. Any help?
Question
fhpuqrgrpgvirzhpujbj
I've been using this code for an isometric grid (I didn't write it)
This is the code:
Public Class IsometricBase 'written by Hammond Pearce 'this class creats a set of points to make an isometric grid like so: (ASCII ART FOLLOWS - MONOSPACE FONT REQUIRED) ' 3________C__________4 ' / / ' / / ' B/ /D ' / / ' /__________________ / ' 1 A 2 Private sideApoints As Point() 'all the points along side A Private sideBpoints As Point() 'all the points along side B Private sideCpoints As Point() 'all the points along side C Private sideDpoints As Point() 'all the points along side D Private lastgridlines As Integer 'last gridlines used in calculatepoints, used in draw_all_points Private Stored_Corners As Point() 'last corners used in calculatepoints, used in draw_all_points Public ReadOnly Property SideA_Points() As Point() Get Return sideApoints End Get End Property Public ReadOnly Property sideB_points() As Point() Get Return sideBpoints End Get End Property Public ReadOnly Property sideC_points() As Point() Get Return sideCpoints End Get End Property Public ReadOnly Property sideD_points() As Point() Get Return sideDpoints End Get End Property Public Sub Calculatepoints(ByVal Corner1 As Point, ByVal Corner2 As Point, ByVal Corner3 As Point, ByVal Corner4 As Point, ByVal NumberOfGridlines As Integer) 'set up all variables Stored_Corners = New Point(4) {New Point(0, 0), Corner1, Corner2, Corner3, Corner4} 'store the last points with an offset (the newpoint) so that its more userfriendly for me! :D lastgridlines = NumberOfGridlines 'store the number of gridlines Dim count As Integer 'used to put data in correct pocket in array sideApoints = New Point(NumberOfGridlines) {} 'reset arrays ready to store sideBpoints = New Point(NumberOfGridlines) {} sideCpoints = New Point(NumberOfGridlines) {} sideDpoints = New Point(NumberOfGridlines) {} Dim temppoint As New Point 'used in do... loop as a temporary point to store values in 'side A 'reset common variables count = 0 Do Until temppoint.X = Corner2.X And temppoint.Y = Corner2.Y 'do until the temppoint = the point we are working to count += 1 'increment pocket If count > NumberOfGridlines Then Exit Do temppoint.X = Corner1.X - (Corner1.X - Corner2.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3 temppoint.Y = Corner1.Y - (Corner1.Y - Corner2.Y) / NumberOfGridlines * count sideApoints(count) = temppoint 'store the temppoint as a real point Loop 'side C count = 0 Do Until temppoint.X = Corner4.X And temppoint.Y = Corner4.Y 'do until the temppoint = the point we are working to count += 1 'increment pocket If count > NumberOfGridlines Then Exit Do temppoint.X = Corner3.X - (Corner3.X - Corner4.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3 temppoint.Y = Corner3.Y - (Corner3.Y - Corner4.Y) / NumberOfGridlines * count sideCpoints(count) = temppoint 'store the temppoint as a real point Loop 'sideB count = 0 Do Until temppoint.X = Corner3.X And temppoint.Y = Corner3.Y 'do until the temppoint = the point we are working to count += 1 'increment pocket If count > NumberOfGridlines Then Exit Do temppoint.X = Corner1.X + (Corner3.X - Corner1.X) / NumberOfGridlines * count 'these two instructions calculate the points between corner1 and corner3 temppoint.Y = Corner1.Y + (Corner3.Y - Corner1.Y) / NumberOfGridlines * count sideBpoints(count) = temppoint 'store the temppoint as a real point Loop 'sideD count = 0 Do Until temppoint.X = Corner4.X And temppoint.Y = Corner4.Y count += 1 If count > NumberOfGridlines Then Exit Do temppoint.X = Corner2.X + (Corner4.X - Corner2.X) / NumberOfGridlines * count temppoint.Y = Corner2.Y + (Corner4.Y - Corner2.Y) / NumberOfGridlines * count sideDpoints(count) = temppoint Loop End Sub Public Sub Draw_All_Points(ByVal graphicsobject As Graphics, ByVal P As Pen) 'this subroutine draws the isometric grid according to the sidepoints and the stored corners, using the lastgridlines variable to control the arrays With graphicsobject .DrawLine(P, Stored_Corners(1), Stored_Corners(2)) 'draw the sides .DrawLine(P, Stored_Corners(1), Stored_Corners(3)) .DrawLine(P, Stored_Corners(2), Stored_Corners(4)) .DrawLine(P, Stored_Corners(4), Stored_Corners(3)) End With Dim i As Integer For i = 0 To lastgridlines graphicsobject.DrawLine(P, SideA_Points(i), sideC_points(i)) 'draw the gridlines Next For i = 0 To lastgridlines graphicsobject.DrawLine(P, sideB_points(i), sideD_points(i)) Next MainUI.readytoroll = True End Sub End ClassI'm trying to make it so whenever it finds the top left point (well, any of the 4 points on the block would work) that it adds the point to an array. But, I'm a bit confused on where/when in the code to actually put that. Any help?
Link to comment
Share on other sites
1 answer to this question
Recommended Posts