PDA

View Full Version : Height of ground, how to get this?



Michael Hartlef
13-06-2007, 09:59
Hi Petr,

I'm in the need of retreaving the Y coordinate of a mesh at a given X and Z coordinate. Is there a command in TBGL that can let me do this?
I'm playing with some waves and a boat. Now I want to let the ship float on top of the water. As the waves go up and down, I have to detect the Y coordinate of the wave mesh at a certain coordinate.

Michael

Petr Schreiber
13-06-2007, 10:13
Hi Mike,

this sounds promising, can't wait to see it running ;)

I presume you use some algo to make the surface wave, based on X,Z of vertex.
Then use the same function to calculate position of ship at determined XZ ?!

Could you explain it more, I think I am understanding it wrong? Do you need to know it on per fragment level ?


Bye,
Petr

Michael Hartlef
13-06-2007, 10:25
Hi Mike,

this sounds promising, can't wait to see it running ;)

I presume you use some algo to make the surface wave, based on X,Z of vertex.
Then use the same function to calculate position of ship at determined XZ ?!

Could you explain it more, I think I am understanding it wrong? Do you need to know it on per fragment level ?


Bye,
Petr


Per fragment level???

You suggested to calculate this during with modification loop of the waves. Well, I could do that. Something like detecting the face surounding an X/Z coordinate and then try to calculate the height as a the average of a face vertices.

But I was more thinking about a variation of what you allready have. You have this 2Dto3D functions and opposite. But I think they are related to the mouse pointer.Anyway, I will try to come up with an algo regarding your suggested solution.

Also I should look at the sources of MiniB3D. Maybe they have something like this allready in it.

Petr Schreiber
13-06-2007, 10:34
Hi Mike,

I would do it this way probably, see attachement.
Pos3DtoPos2D is to convert 3D coordinate to screen pixel location, so probably not good for this case.

So what you need is to shoot ray against surface and find where it will collide? This is what I mean by "fragment".
I will think more about this problem...


Bye,
Petr

kryton9
13-06-2007, 10:43
That reminds me of a stingray in the ocean. Too tired to study the code, but will when I get up. Looks like the magic trick to get the height should be in there.

Michael Hartlef
13-06-2007, 14:19
Thanks Petr for the code sample. I will look at it tonight.

Michael Hartlef
13-06-2007, 17:48
Looks nice. I will see what my algo brain will come up with.

Michael Hartlef
13-06-2007, 22:57
Ok, here is a quick way, not sure how reliable it is:



function getHeight(xf as single, yf as single, zf as single)
local x,y,z as single
local px,py as integer
TBGL_Pos3DtoPos2D( xf, yf, zf, px, py )

tbgl_GetPixelInfo px,py, %TBGL_PINFO_xyz, x, y, z
function = y

end function


And attached is a little result, where you can see how it works inside a script.
Please don't mind the mess of the code. I was lazy ;)

Edit: You need a gamepad to steer the boat

kryton9
14-06-2007, 06:10
Mike, I'm getting a crash when it tries to launch. Sorry no other info to give as there is no other message other than the fault window for microsoft.

I will wait to see if anyone else has any problems or just me. Looks like it will be fun when it runs!

Michael Hartlef
14-06-2007, 06:29
Sorry Kent, please redownload. I forgot to rem out some lines to models that are not in use right now and were not in the download.

Petr Schreiber
14-06-2007, 08:45
Hi Mike,

this is fun !
I just had to use JoyY instead of JoyZ on my gamepad, bu then it worked super.

In version of TopDown 3d with sounds ( WIP ) I used manipulation of volume to improve sound.
So idea is to play both low rpm and hi rpm sounds and blend their volumes according to current motor rpm, results should be perfect.

Very clever idea of 3Dto2dto3D, I like it! Ship also looks very nice!


Thanks ;),
Petr

Michael Hartlef
14-06-2007, 10:31
Hi Mike,

this is fun !
I just had to use JoyY instead of JoyZ on my gamepad, bu then it worked super.

In version of TopDown 3d with sounds ( WIP ) I used manipulation of volume to improve sound.
So idea is to play both low rpm and hi rpm sounds and blend their volumes according to current motor rpm, results should be perfect.

Very clever idea of 3Dto2dto3D, I like it! Ship also looks very nice!


Thanks ;),
Petr


Thanks Petr, I had the idea of sound manipulation myself. The physics right now are far from being perfect, but are allready fun
to play with.
I decided to use HotRod sounds for the engine, as they sound deep but powerful enough for PowerBoats. I have a lot of ideas for this, but this is also just a little Petprojekt. So I don't know if I will finish it.
It will be a good base to see how I can implement path finding and
physics with thinBasic.

kryton9
14-06-2007, 12:53
Had to play with it before heading off to sleep, that is neat Mike. I live by the Gulf of Mexico here and have no boat, so now I do :) woohoo!!

Michael Clease
14-06-2007, 13:38
i like how the ship sinks if you take the pointer off the window. ;D

Michael Hartlef
14-06-2007, 16:33
i like how the ship sinks if you take the pointer off the window. ;D


;D Well, that's the problem with these boats. They just can float inside a window ;)

Michael Hartlef
09-07-2007, 18:42
Petr, any idea why my script doesn't work with 1.4.0.1 anymore? No graphics are showing up, only sound and text.

Petr Schreiber
09-07-2007, 18:47
:-[ No idea Mike,

But I can confirm the problem.
I am now seeking for the cause.
But I did not updated TBGL from last version, so this is kind of weird.


Petr

Michael Hartlef
09-07-2007, 18:52
Strange.

Petr Schreiber
09-07-2007, 18:58
Mike!

I found it!

On line 141 of your script you have typo, which was ignored by previous tb:


many 1 = -0.15


Change to:


many = -0.15


And it will work again, at least on my box :)

Bye,
Petr

EDIT: Corrected line number

Michael Hartlef
09-07-2007, 19:08
Here too, many thanks!

ErosOlmi
09-07-2007, 19:17
Thanks gui.
I've added more precise parsing in variable assignment. thinBasic will now intercept it and generate a runtime error.
Will be present in next preview.

Eros

Michael Hartlef
09-07-2007, 21:30
Damn, now I'm doomed to write type error free code. ;D

kryton9
10-07-2007, 01:20
I forgot all about this post and getting the height and fun game, after I clean installed my computer forgot to get this one. That get height routine is so valuable for what all we need. Thanks for figuring it out Mike!!