Reversing equation
BlitzMax Forums/BlitzMax Programming/Reversing equation
| ||
I have this:XPos+(30*CountX)-(CountY*30), YPos+(15*CountY)+(CountX*15) the first part works out the X and the second part works out the Y coordinate. But how would i reverse the equation to work out the CountX/Y values if i have an X and a Y cooridinate. I'm having trouble because in order to work out what the CountX value is i need to know the CountY and vice-versa. I have been working on this a week now and it is really starting to trouble me. Is this possible at all? Thanks Matt |
| ||
You can't. You are trying to get 3 values from 1?. it's not possible. TOTAL == Xpos + CountX + CountY |
| ||
I don't know what are you trying to do. CountX and CountY is like a tab? why don't store the values in a full string XD ''''Temporal Amount 3digs(val a) + 3digs(val b) ''''---------------------------030 090 TempAmountX = 30090 ' If I have TempAmountX I can generate TempAmountY and CountX and CountY Xpos=10 Ypos=45 'in=TempAmountX out=CountX and CountY CountX=Int(Left$(Right$("0"+TempAmountX,6),3))/30 CountY=Int(Right$(TempAmountX,3))/30 Print Print "TempAmountX = "+TempAmountX+" ===> CountX="+CountX+" CountY="+CountY Print Print "XPos+(30*CountX)-(CountY*30)" Print Xpos+" + (30*"+CountX+"="+30*CountX+") - ("+CountY+"*30="+CountY*30+") = "+(Xpos+30*CountX-CountY*30)+" <=== REAL TOTAL" Print Print "YPos+(15*CountY)+(CountX*15)" Print Ypos+" + (15*"+CountY+"="+15*CountY+") + ("+CountX+"*15="+CountX*15+") = "+(Ypos+15*CountY+CountX*15)+" <=== REAL TOTAL" Print 'TempAmountX = Int(String(30*CountX)+Right$("00"+String(CountY*30),3)) TempAmountY = Int(String(15*CountY)+Right$("00"+String(CountX*15),3)) Print "TempAmountY = "+TempAmountY+" ===> CountX="+CountX+" CountY="+CountY 'in=TempAmountY out=CountY and CountX CountY=Int(Left$(Right$("0"+TempAmountY,6),3))/15 CountX=Int(Right$(TempAmountY,3))/15 |
| ||
Ok sorry i didn't explain it that well. The first part calculates an X coordinate and the second calculates the Y: X Co-ord= XPos+(30*CountX)-(CountY*30) Y Co-ord= YPos+(15*CountY)+(CountX*15) CountX and CountY are numbers from 0 to n (whole numbers). I use these in a For loop to draw the images i am using. PosX and PosY are numbers i know. They are just in there so i can move the overall image around the screen. So if the user clicks on one of the images i need to (using MouseX and MouseY) work out what the CountX, CountY position of the image is. I hope this makes more sense. |
| ||
So.. x = (a*30) - (b*30) y = (a*15) + (b*15) simplified : x = (a - b) * 2 y = a + b The result is :- Coming up After I've had a sleep! Why can't you have a simple co-ordinate system? |
| ||
Its for isometric tiles so i have to move they down/side-to-side depending on which row theyre on etc. So it ends up needing both x and y. Thanks for the simplification. I was building it up bit by bit trying new things to get the right layout so i ended up with pieced together bits of code. |
| ||
Check out this article, towards the bottom is the equation you are looking for: http://www.bookofhook.com/Article/GameDevelopment/IsometricEngineDevelopmen.html |
| ||
Try it! a=22 b=166 x=(a-b)*2 y=a+b '------------------ aNew=((x/2)+y)/2 bNew=y-aNew |
| ||
Thanks for the link altitudems. That helped alot. Your version didn't seem to work for me though BlackSp1der. |