aspose file tools*
The moose likes Java in General and the fly likes [Unsolved] Heightmap + glScalef not accurate with a larger HeightMap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "[Unsolved] Heightmap + glScalef not accurate with a larger HeightMap?" Watch "[Unsolved] Heightmap + glScalef not accurate with a larger HeightMap?" New topic
Forums: Java in General Game Development
Author

[Unsolved] Heightmap + glScalef not accurate with a larger HeightMap?

Joe Thatcher
Greenhorn

Joined: Jun 24, 2014
Posts: 15
Hi! I have another problem which I cannot seem to solve. While related to my ship rotation issue, it technically has nothing to do with it, which is why I am posting here.
I did also ask on Stack Overflow (http://stackoverflow.com/questions/24431328/heightmap-glscalef-not-accurate-with-a-larger-heightmap), however that question has got few (6) views and I doubt it will be answered any time soon (Will edit this question if issue is solved elsewhere).

So, to quote the Stack Overflow page:
I have got two HeightMaps. One is of size 250, the other is of size 2000.

The HeightMap with the size 2000 is stored into memory and used to detect if the player is in collision (i.e. if (player.y() < heightmap.y()) do collision stuff).

The HeightMap with the size of 250 is stored into a DisplayList and is rendered.

Before rendering (glCallList()) the 250 Heightmap, I glScalef(8, 1, 8).

It is fairly accurate. However, there seems to be a slight offset. If I move to one side of the map, I seem to collide slightly before I actually hit the land.
If I travel to the other side of the map, I seem to collide slightly after I actually hit the land.

This is a pretty big problem, because players are colliding and taking damage when graphically there is nothing to hit, and then at other times they are sinking into the map where they should be taking damage.

What is wrong? Is there anything wrong with glScalef() that I do not understand?


If I have an island, a player (the ship) coming at it from 1 angle will collide with it before graphically colliding with it. The person on the other side will actually go slightly into the island before any collision is detected.

Is there something to do with glScalef() that I do not understand?

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Please explain more about what height map is; I am not familiar with it, and maybe other poeple won't be familiar with it.
In the scale method, I can see that 250→2000 is 8, but why are you using 8 1 8?
Joe Thatcher
Greenhorn

Joined: Jun 24, 2014
Posts: 15
Campbell Ritchie wrote:Please explain more about what height map is; I am not familiar with it, and maybe other poeple won't be familiar with it.
In the scale method, I can see that 250→2000 is 8, but why are you using 8 1 8?

While my code is not directly from there, there is a good tutorial about heightmaps at https://www.youtube.com/watch?v=nFrBwkaReJE. Pretty much explains what a HeightMap is in the first minute.

Or, if you're not willing to watch Youtube, it is an image which sets the height of a coordinate of a certain location, meaning that it is a simple and easy way to store a map file. The drawbacks are that I cannot have tunnels, overhangs, etc.

glScalef(8, 1, 8) - glScalef(x, y, z). Both heightmaps have got the exact same height (y). The smaller one just has the X and Z at 8 times less than what they actually are, which is why I only scale those ones up.
If I scaled the Y, not only would it not be accurate with the collision heightmap, but also I would have massive cliffs/peaks instead of small/medium hills.
I am scaling it up because rendering that massive amount of vertices in a display list is impossible without dropping to <10 FPS. Eventually, I will have a chunk mechanism where it scales it less and less and gives a more and more accurate heightmap the closer you get to it, however that will be a while in coming and won't actually solve the 'now' problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
So the slopes appear 8× as steep on the smaller map? That part explains the 8 1 8. Don't know about the other things, I am afraid.
Shall try duplicating the question in the games forum.
Joe Thatcher
Greenhorn

Joined: Jun 24, 2014
Posts: 15
Campbell Ritchie wrote:So the slopes appear 8× as steep on the smaller map? That part explains the 8 1 8. Don't know about the other things, I am afraid.
Shall try duplicating the question in the games forum.

Each map if rendered is the exact same.

However, one of them is a full-scale map of 2000px x 2000px. The other one is a 250px x 250px - This one is timsed by 8 when rendering. Effectively, it gives the same image but less vertices.
Decreasing the detail of the map would not work because it is the amount of vertices rendered that is the issue here, not detail. I have as much detail as 250 x 8 will allow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Unsolved] Heightmap + glScalef not accurate with a larger HeightMap?