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.

AppGameKit Classic Chat / Help getting terrain height

Author
Message
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 18th Apr 2018 11:08
Calling all maths wiz kids.

I need to figure out how to get the terrain height of any point between any four vertices on a terrain. I have a bit of code (Will share later) that almost works.....but it messes up corners.

I cannot use AppGameKit terrain height commands (there's no height map)
I cannot use recasting or collision checking as for some reason AppGameKit won't detect a collision

Has anyone done this before?
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Apr 2018 11:18
Hi Santman

You CAN raycast into your terrain object and get a height from that fairly easily....just cast a ray directly down into the terrain and read back the collision point on the Y axis

Alternatively, if you have a memblock you can take any position and interpolate between the vertices for a height


Ive used both and they both work so it depends what your trying to do?? I can post up the functions that i used if wanted.

Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Apr 2018 11:19 Edited at: 18th Apr 2018 11:19
Ohh wait....i bet you havent called SetObjectCollisionMode(heightmapobj,1) on your height map have you??....then you can raycast with it....

That gave me 30 mins of headscratching when I was trying to get it working
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 18th Apr 2018 16:21
Sorry at work so can't answer quickly.

Bengisimo.....I know I SHOULD be able to do what you said, hence this post.

Ok, so what I did was create a blank, jet black image. I then used AppGameKit to create a terrain from this.....blam, instant mesh. This I then created a memblock from, and I adjust vertex heights and positions within the mesh, then copy back to an object from the memblock.

I set the object up for collision, then taken the camera position and a position far below the camera......then raycast between the two. No matter what I do, AppGameKit declares no collision occurs.

That's said, interpollating the height from the vertices is probably going to be quicker so if you would share that example I would be grateful.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Apr 2018 17:15 Edited at: 18th Apr 2018 20:08
Your doing something wrong somewhere then

[img][/img]

This above is a heightmap loaded in then turned into a memblock...3 vertices edited then set back to the object and the heightmap raychecking still works fine for me at least. If you post some code then I can check it.

The raycasting is fast...will certainly be faster then interpreted basic code looking up 4 vertex points and interpolating between.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 18th Apr 2018 20:25
Hahahaha....are you ready for this Bengisimo - you're gonna love it, honestly.

My code was working fine.....but I was ADDING to the Y coord....as in screen coord style, where as obviously in 3D it's reversed. SO I was raycasting thusly:



Where as I obviously needed to do:


I literally refuse to admit how long I spent trying to sort this......
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Apr 2018 22:13 Edited at: 18th Apr 2018 22:15
Ahhh...Great Glad to see you got it sorted.

Ive made much more obvious and worse misjudgements/mistakes and spent frustrating hours looking for them... All part of programming.

And....Most friday and saturday evenings i end up not knowing which way is up
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 19th Apr 2018 01:33
Hahahaha....love it.

Thanks for the help though - the interpolation that you posted was almost identical to one I modified from a C tutorial and it almost worked - it was just the corners that it clipped through the landscape. Anyway....one problem down, onto the next.....

Login to post a reply

Server time is: 2024-11-23 21:23:19
Your offset time is: 2024-11-23 21:23:19