Picking areas of a texture on a mesh

Blitz3D Forums/Blitz3D Programming/Picking areas of a texture on a mesh

Chaduke(Posted 2006) [#1]
Say I had a model of earth that could be rotated like a virtual globe, but when the user moves the mouse pointer over a specific state or country the border of it becomes highlighted.
Is there a way to figure out what pixel of the texture map the mouse pointer is over?
If that could be determined then I suppose you would need a formula to determine if it fell within the borders of a specific country, then drawing the outline of that country on top of the texture would be another challenge.
Anyone ever try something like this?

EDIT:
I just thought of an easier way, I suppose I could just record the x and y location of the mouse and what the rotation of the globe is and then just keep a table of what countries fall at what x,y coords for that rotation.
I would just have to limit the amount of different rotations the globe can be set at or it could get really time consuming.


stayne(Posted 2006) [#2]
Or you could split the model up by country borders in your modeling app, then load them all at once and treat them as separate entities.

Edit: never mind... would be too time consuming and high poly. forgot you're using a texture for the globe ;).


kevin8084(Posted 2006) [#3]
you could use pickedX(),pickedY(), and pickedZ() and translate to 2d screen coordinates, I believe.


Stevie G(Posted 2006) [#4]
I would do it like so ...

Create a new color map texture which has all countries displayed as a separate colour. Do not texture the planet with this.

Use the PickedU & V code in the archives which will give you the uv coords on your visible texture.

http://www.blitzbasic.com/codearcs/codearcs.php?code=515

Get the x, y position of the pixel on the colormap texture by multiplying the u coord by the texturewidth() and the v coord by the textureheight().

Read the color at this position and determine which country is picked.

Stevie


Chaduke(Posted 2006) [#5]
Wow, nice reply Stevie. I never would have thought to use different colors but that makes perfect sense. I'm going to give that a try.
Any suggestions on how to "highlight" the current country? Either by making the border light up or making it change to a brighter color on the texture map?


Stevie G(Posted 2006) [#6]
To highlight a country ... use another overlay texture, clear it to black and apply this over the existing planet texture using additive blend. This will be used to brighten an area of the texture.

When a country is detected ... read all the pixels from the colour texture of this country's colour and plot a pixel of colour 128,128,128 ( or suchlike ) onto the overlay texture. Remember and clear it when another country is selected.

It should be fast enough.

For highlighting .. do a similar exercise but only plot pixels which border this countries colour.

Make sense?

Stevie


Chaduke(Posted 2006) [#7]
Ok I got it working pretty good now, that picked uvw code works great. I have it picking the colors of the current texture map and I've tried a few different ones. For some reason its doing something weird on one of them. In the areas where its blue, in the ocean, its saying the rgb is 0,0,0 which is wrong. I think it has something to do with the image being indexed color instead of RGB. I took it into photoshop and converted it but its still not working correctly.
I tried a different texture though and it works great.

The highlighting technique by grabbing the colors sounds great, another thing I wouldn't have thought of, thanks again.


Chaduke(Posted 2006) [#8]
I found a really nice earth texture. In the area of the United States I added part of a map to test it out. It seems to work ok but check out what happens when you hover over Texas. It's detecting yellow as white.

http://www.doresoftware.com/misc/globe.zip

Extract to a folder, run globe.bb

Use WASD or arrow keys to turn the globe.


Stevie G(Posted 2006) [#9]
You got your blue pixel argb values wrong ...

This is what it should look like ..

argb = ReadPixel(x,y)
dotred# = (argb Shr 16 And %11111111)
dotgrn# = (argb Shr 8 And %11111111)
dotblu# = (argb And %11111111)


Works fine now ;)

Stevie


Chaduke(Posted 2006) [#10]
Hrm I never noticed that before. I copied that function from the example so its wrong in there as well.

Now I need to find a nice image that seperates the boundries of all the states and countries so I can start color coding.

Thanks once again.


Stevie G(Posted 2006) [#11]
No worries. Let us see what you come up with.


Chaduke(Posted 2006) [#12]
Will do. Basically I'm working on simple geography learning tool but I have all sorts of ideas to make it different and fun.