Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Go Back  Xtreme Visual Basic Talk > > > Mouse Position to for Isomertic Grid


Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2016, 09:00 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,795
Post Mouse Position to for Isomertic Grid


I'm trying to figure out the row and column I'm over in an isometric view using the mouse, I would of upload and Image.

but uploading attachments does not seem to work anymore

you can view the image from here

Isomertic Map


Code:
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  mBitmap = Bitmap.FromFile(Application.StartupPath & "\" & "Images\tiles.png")

  mTile = New Bitmap(90, 45)

  Using mGraphics = Graphics.FromImage(mTile)
   Dim mDest As Rectangle = New Rectangle(0, 0, mTile.Width, mTile.Height)
   mSrc = New Rectangle(0, 0, mTile.Width, mTile.Height)
   mGraphics.DrawImage(mBitmap, mDest, mSrc, GraphicsUnit.Pixel)
  End Using

  mTileWidth = mTile.Width
  mTileHeight = mTile.Height

  mTileWidthHalf = mTileWidth * 0.5F
  mTileHeightHalf = mTileHeight * 0.5F

 End Sub

 Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
  mMapStartX = (Me.Width * 0.5F) - mTileWidthHalf
  mMapStartY = 0

  Dim mDestRect As Rectangle
  Dim mX As Int32 = mMapStartX
  Dim mY As Int32 = mMapStartY

  Using mFont As New Font("Segoe UI", 10.0F, FontStyle.Bold, GraphicsUnit.Point)


   For row As Int32 = 0 To 20
    For column As Int32 = 0 To 20

     mX = mMapStartX + ((column - row) * mTileWidthHalf)
     mY = mMapStartY + ((column + row) * mTileHeightHalf)

     'mX = mStartX + (column * mTileWidthHalf) - (row * mTileWidthHalf)
     'mY = mStartY + (column * mTileHeightHalf) + (row * mTileHeightHalf)

     mDestRect = New Rectangle(mX, mY, mTile.Width, mTile.Height)

     e.Graphics.DrawImage(mTile, mDestRect, mSrc, GraphicsUnit.Pixel)

    TextRenderer.DrawText(e.Graphics, String.Format("{0},{1}", row, column), mFont, mDestRect, Color.White, TextFormatFlags.NoPadding Or TextFormatFlags.VerticalCenter Or TextFormatFlags.HorizontalCenter)


    Next column
   Next row
  End Using
 End Sub

 Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove

 'Dim mX As Int32 = Math.Abs(e.X - mMapStartX)
 'Dim mouse_grid_x As Int32 = Math.Floor((e.Y / mTileHeight) + (mX / mTileWidth))
 'Dim mouse_grid_y As Int32 = Math.Floor((-mX / mTileWidth) + (e.Y / mTileHeight))

 'LblRow.Text = "Row is:" & mouse_grid_x.ToString()
 'LblColumn.Text = "Column is:" & mouse_grid_y.ToString()

 'Dim mrow As Int32 = e.X / mTileWidth
 'Dim mcolumn As Int32 = e.Y / mTileHeight
 'Dim mX As Int32 = ((mrow - mcolumn) * mTileWidthHalf)
 'Dim mY As Int32 = ((mrow + mcolumn) * mTileWidthHalf)
 'LblRow.Text = "Row is:" & mX.ToString()
 'LblColumn.Text = "Column is:" & mY.ToString()

 Dim mX As Int32 = ((e.X - mMapStartX) / mTileWidthHalf) - 1
 Dim mY As Int32 = ((e.Y - mMapStartY) / mTileHeightHalf) - 1
 LblRow.Text = "Row is:" & mX.ToString()
 LblColumn.Text = "Column is:" & mY.ToString()
 End Sub
I've made several stabs at it in the mouse move event but just cannot understand how to get it correct.

any help would be great.
Reply With Quote
  #2  
Old 10-17-2016, 02:16 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

I would think because the image is angled, you should also "angle" the mouse coordinants.
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #3  
Old 10-19-2016, 09:16 AM
passel's Avatar
passelMouse Position to for Isomertic Grid passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I can't look at your image from work (blocked), but perhaps these two old threads might help.
(The code is for VB6, but the calculations should be the same regardless).
Isometric Grid - Help with code

Isometric coordinate problem
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 10-20-2016, 04:54 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,795
Talking Here was the answer

Just in case anybody is interested, not that the site is used that much anymore

Code:
 Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove

  Dim mX As Int32 = ((e.X - mMapStartX) / mTileWidth + (e.Y - mMapStartY) / mTileHeight) - 1
  Dim mY As Int32 = (e.Y - mMapStartY) / mTileHeight - (e.X - mMapStartX) / mTileWidth

  If (mX >= 0 AndAlso mX <= 20) AndAlso (mY >= 0 AndAlso mY <= 20) Then
   Me.LblRow.Text = "Row is: " & mY.ToString()
   Me.LblColumn.Text = "Column is: " & mX.ToString()
  Else
   Me.LblRow.Text = "Row is: N/A"
   Me.LblColumn.Text = "Column is: N/A"
  End If



 End Sub
Reply With Quote
Reply

Tags
int32, dim, row, column, mtilewidthhalf, mtileheighthalf, mmapstartx, mtilewidth, mtileheight, mtile.width, mtile.height, mmapstarty, mdestrect, private, msrc, mouse, object, handles, 0.5f, lblrow.text, e.y, mcolumn, mrow, lblcolumn.text, rectangle0


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
 
Mouse Position to for Isomertic Grid
Mouse Position to for Isomertic Grid
 
-->