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.

DarkBASIC Professional Discussion / To find 3D coords of a texture pixel? :D

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 11:07 Edited at: 2nd Mar 2014 11:10
Hi again and again!
I am in full coding and I would to make a code to put object using a determinate color on a texture.

Example :
I have a terrain (a box) where I apply a ground texture (I take a top view photo of a farm terrain).

So I have my world with a decent texture.
Next step is to put a lot of trees and I make a piece of code for it where I can use a 3D cursor and when I press a key so I can put a tree there!
When I finish to put all my trees so I push another key that write a DAT file with all trees coords.
At this point I need just to load this DAT file and I find all my trees in the position in which I put.
Very nice but now I need a major code to make me add trees from outside of my exe.


I was thinking this way:
I open my terrain texture with some paint program, so I choose a very different color than my texture colors (for example violet)
and I put some simple violet dots, exactly where I would to find my 3D trees in my game.

Ok at this point, I should do a piece of code making the following:
1) start to analyze all single terrain texture pixels
2) when this code find a violet pixel so a 3D tree is putted exactly in the 3D coords of the violet pixel.....

..It's possible?
is there a command to know the 3D coords of a determinate pixel of a texture? or just do you have some good idea about?

I really need your help guys!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 11:50
Quote: "..It's possible?
is there a command to know the 3D coords of a determinate pixel of a texture? or just do you have some good idea about?"


Yes , look the POINT(X,Y) command

This piece of code shows you how we put 50 objects randomly on the floor, and then we make an image to save all the objects coordinates.





Imaging that you want to make manually all the points in any painting program. This code will make a box for every point in the image. Example attached.



In the same way, you can put differents colour points and decide that if a colur is white, then you add a tree, and if the colour is red, then you add soldat.

Cheers.

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 12:22
wow.. chafari I have no words! simply AMAZING!
Both your example are just great but I am pointing to the second one to make some experiments!

Now I try to modify the black background to transform it into a top view forest and I will try to use violet precise value to put the objects!

Please stay tuned.. I think I should to need your help again

For now, just a giant thank you!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 12:39
Quote: "wow.. chafari I have no words! simply AMAZING! "


Enjoy it !!

Cheers.

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 13:02
Hey chafari! Look this example! (mouse buttons to move camera)

Now I need to try with my game code.. biggest and UV modified texture... (and scaled too )
Maybe I will make many other experiments but you signed my way!!

Again thank you mate!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 13:27
What the command POINT(X,Y) gives to you, is the amount of a certain colour in the coordinates of the screen upper left. So when we put:

point (1,1) ...it looks in the first pixel upper left of the screen, even if we move the camera, it will give you the color it find in that moment.

Giving UV to any object is easy if you play with vertexdata.

I'm not a grumpy grandpa
Lukas W
22
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 2nd Mar 2014 13:35
You can lock pixels for faster load time


Although it's not a huge gain, but at bigger images it will be a bigger time improvement

IS that a game, a program, or 3 year old drawing.
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 14:03
Ahh Lukas W, very interesting! I need ALL for optimize my game! thank you!

@chafari:
Yeah my friend, I perfectly understand the logic!

Quote: "Giving UV to any object is easy if you play with vertexdata"

Ehmm.. Currently I can't play with vertexdata.. my knowledge is not at this level but please, don't be angry if I will soon ask you for help again

Experiment time now..
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 14:23 Edited at: 2nd Mar 2014 14:26
Hi Lukas W, lock pixels helps a bit, I use it specially when using Dot command.

@Alduce.
I can't understand why your code create 19 objects and it report only 10 . I made a test label to check this and give a correct data.



I'm not a grumpy grandpa
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Mar 2014 14:24
You could also use the pick screen commands and a terrain explorer program to place trees in 3D. The pick screen commands would tell you the exact 3D location that you click the mouse, then convert that to your image resolution and draw the dot, or just store the coordinates and save them that way.

Just depends on how you want to design your map - for me, I much prefer working with WYSIWYG, or at least have the option of running a quick test - it can make a big difference to be able to see exactly how it'll look in-game while you work.

I am the one who knocks...
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 17:07
Hi Van B!

If I understand what you mean, you prefer to have a editor directly on the game, you move the camera and you can put the trees where you want (and when you put a tree so your texture image directly changed with the added dot).

Really not bad to have both the possibilities to work directly on the texture image (with a paint program) and to modify your texture image (then add a new tree) from a 3D editor inside your game exe.

(if I understand what you mean eh )
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 17:53 Edited at: 2nd Mar 2014 17:55
EDIT:

Ok.. I modified the last code. Now there is my game terrain with my game texture.

The problem born when the size of the terrain does not coincide with the size of the image..

In the last code we had a box terrain 100x100 with a texture of 100x100 pixels.
Now we have a terrain of 50000x50000 with a texture of 1024x566 pixels....... and this is enough to kill me
Sure some math conversions needed but sincerely I getting just funny and weird results trying to make this code working good.....

You can also notice in the code there is a hidden piece of code regarding the scale and scroll of the texture....
For now this code is on rem status, my first objective is to have this code working without necessarily scaling and scrolling the texture.

But sure.. it would be great if someone of you can add these scale and scroll texture commands maintaining the coordination between the RED DOT (the color I am using in this code) and the texture...


Please download the code guys and try to make this working good!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 18:52 Edited at: 2nd Mar 2014 18:57
OK! HERE the new working version!


Now remain only ONE thing to do...

changing the code to use the scale and scroll texture commands too...


HELP!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 19:01 Edited at: 2nd Mar 2014 19:14
When we use an image as a reference of objects position, like above, we can not scale that image, as the image is really the 3D space of the virtual world. Any change to the image, won't fit with what you will see in 3D space. We can say, that this is a poor method of making an array to save position.


Edited: Take into account, that when we read pixel by pixels in an image of 100*100 or 128*128, we read for a pixel colour to place an object. If you make this image bigger, and the pixels let's say, in your image each point represent 6*6 pixels, when we use this methode of reading every pixel of the image, the program will create 6*6=36 objects per pixel found.....it is a mess...it will need too much memory. this method is good for small pictures where you want to save for example 100 or 200 trees in your terrain.

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 19:17 Edited at: 2nd Mar 2014 19:18
Mmm ok, so.. I really need the texture scaled and scrolled too...

So I got an idea..:

Can I load an image, using that image as texture, to apply the scale and the scroll of the texture and... SAVE THE RESULT AS A NEW IMAGE??

If I could to do that so I have no more problems!!

at that point I'd use the image obtained as my terrain image and I will not have the need to use scale and scroll texture!

In fact now I using scale and scroll texture just 'cause I want my terrain image slightly different than the original image.
ONLY FOR THIS MOTIVATION.


if I knew a program (for example like MS PAINT) that would allow me to scale and scroll my image like I making using DBPro so I will to use it instead to use scroll and scale texture commands...


I hope you can understand my english...
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 19:22
of course you can load an image of let say 1024*768, and reserv the first part of the image upper left of 100*100 pixels to add info about position, then you can add rest of your texture. When you apply the texture, you will have to scale a bit the texture and scroll in order to not see the black area.

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 19:38
chafari, a final big thankyou for your help!

I decided to stop to use these brutal methods in my game develop process (to choose an image that I do not consider perfect and to use scale and scroll texture to make it as I want)
Directly I will go to edit the image to make it fit perfectly with my game
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 19:57
Quote: "I decided to stop to use these brutal methods in my game develop process (to choose an image that I do not consider perfect and to use scale and scroll texture to make it as I want)"


You always could use several images. What is really your purpose of reading pixels?

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 21:04
Ahaha you are using a lot of sweetness to avoid to tell me "Aldo, your english sucks"

My purpose of reading pixels is exactly what autogen is in Flight Simulator!

When the code find green color so put the trees!
When the code find grey color so put the houses!
and when the code find brown so please put some bushes!

Just this! and thanks to you I can currently do this!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Mar 2014 21:37
Quote: "Ahaha you are using a lot of sweetness to avoid to tell me "Aldo, your english sucks""


That is not true, and you know it !!.Your English is pretty good. I mean you have enough vocabulary to make yourself understood, and that's what matters.My mother language in not english but today we can all communicate in this language.

I wish you all the best !!

I'm not a grumpy grandpa
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 2nd Mar 2014 21:46
Quote: "I wish you all the best !! "


I wish you all the best too my friend!
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 4th Mar 2014 09:51 Edited at: 4th Mar 2014 09:52
Van B
Quote: "
You could also use the pick screen commands and a terrain explorer program to place trees in 3D. The pick screen commands would tell you the exact 3D location that you click the mouse, then convert that to your image resolution and draw the dot, or just store the coordinates and save them that way.
"


Hi Van B, I was rereading your post and (just now) I understand what can be useful your idea!

1)Ok, I use an explorer code to fly in my game world.
2)using pick screen commands I can know the exact 3D location where I am
3)I convert that 3D location in the 2D pixel location of my texture image
4)I can draw a dot in my texture image using that 2D XY coords
5)I save in my HDD the modified texture image as a new BMP image

This will be damn useful for a lot of motivations!

But please, especially for steps number 4 and 5.
Can you (or anyone else) give me some trick or advice to make that?

Login to post a reply

Server time is: 2026-07-06 04:29:06
Your offset time is: 2026-07-06 04:29:06