Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Transforming image position to world coords

Author
Message
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 00:54 Edited at: 16th Jul 2018 14:14
Are the pixel colors in the image memblock not kept in top to bottom left to right format?

The edges of the image come back to what I expect. But the middle is not correct. For instance 512,512 on the image would center me on the map. The color is claiming green and bluish but the color is all red . I am not sure what I am doing wrong.. especially since its working on the edges.

edit: OK, so after taking a closer look the pixels values are correct, its my formula to convert to world space that is incorrect. I'm not sure why my formula to convert to world space is incorrect.

The author of this post has marked a post as an answer.

Go to answer

Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 02:39
I am thinking this may have to do with me using CreateObjectFromHeightMap. My GetObjectMaxSize's are not lining up with the input into the command CreateObjectFromHeightMap(). I am testing it on a plane I created instead.
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 16th Jul 2018 09:12 Edited at: 16th Jul 2018 09:13
ok...so theres quite a lot wrong with what your doing here

1) You are not actually covering all your pixels with those for loops
2) Your formula for getting the offset for a pixel is wrong
3) As your formula is wrong...all the pixel colour values are wrong
3) How image data is laid out in an image memblock has nothing to do with 3D heightmaps ?
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 14:05 Edited at: 16th Jul 2018 14:14
The formula does work on a plane, and does pull back the correct color.

I have attached a file with the X Y pixel, the R and G colors, along with the world position. These are "correct" on the plane. So, for some reason I need a different way to find the world position when using a heightmap. That is the part that has me befuddled.

Attachments

Login to view attachments
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 16th Jul 2018 14:16 Edited at: 16th Jul 2018 14:30
No its not correct... It should be

n = 12+(x*4)+((y*width)*4)

You got lucky and used a square image 1024x1024 so ...Height = Width and so you never saw your own error..try it with a non square image

Plus you are only printing out 1023 of the 1024 values too...

AND...
writeline( 1, str(line) + " " +str(x) +" " +str(y) + " R: " +str(r) + " G: " +str(g) + "X : " +str( x ) +" Z: " +str(y) )

Why would you print the x and y values twice?? Do you mean the second pair of values to be xw,zw??

Im really not sure why you would want a massive list of 1million pixel values anyway??

I posted various functions for heightmaps including one that got the height on the heightmap by working out where the position is on the imaged and interpolating the R value to get the height.
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 14:24 Edited at: 16th Jul 2018 14:28
Because I was trying to find out where I was going wrong lol

I had already corrected the xw zw mistake just a typo
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 14:32 Edited at: 16th Jul 2018 14:33
The biggest issue is the world coordinates on the heightmap object - it works fine on a plane, though. So I wanted to compare the two, and see if I could correct the formula.
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 16th Jul 2018 17:13 Edited at: 16th Jul 2018 19:12
This post has been marked by the post author as the answer.
I had to flip the z-coordinates on the x axis. Hopefully, that isn't a mistake that happens to be correct, too. haha. I believe a plane terrain would need to be adjusted since the center is 0,0.

zworldcoordinate = (y * (sizez#/height))-(((y * (sizez#/height))-sizez#/2)*2) This could probably be better written but I am not a math guy.



Thank you Bengismo. Man, I love having you around. Need to start paying you tutor fees.
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jul 2018 00:10
GetWorldXFromSprite()
GetWorldYFromSprite()
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Jul 2018 01:02 Edited at: 17th Jul 2018 01:06
Thats not really what he wanted blink

Hes talking about the fact that the x axis on the image becomes the x axis in 3d space but the y axis is inverted and becomes the -z axis in the heightmap object. This is so that as you look down the y axis from above the heightmap it matches the image that was used to create the heightmap.

Add that to the fact that the heighmap is centered about 0,0,0 and goes from -xwidth/2 to xwidth/2 and from -yheight/2 on the z axis to yheight/2 on z axis.

it does take some coordinate conversion but its all logical. Glad you got it sorted.
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jul 2018 02:24
Ah! Ok. My bad

Login to post a reply

Server time is: 2019-03-22 23:38:46
Your offset time is: 2019-03-22 23:38:46