#### Archived

This topic is now archived and is closed to further replies.

# i need help with writing an equation

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok here''s what im doing, hopefully it doesnt through you off we have a height map. the heightmap is a data file consisting of an array of height values, each point within the array contains a height, ranging from 0 - 255... now, we have another data set, called the detail terrain map. this map also has values ranging from 0 - 255 at each point. The detail terrain map determines how much detail is used at a specific point. For instance, lets say that at point 0,0 in the height map, we have a height of 0. ok no problem lets also say that at point 1,0, we have a height of 1. now in our detail map, both of the points i just mentioned, have a value of 0. in a detail terrain map, 0 means lowest amount of detail possible, white means the highest amount of detail. i need to convert the data from the detail terrain map into usable data. My first idea was to convert the range of 0 - 255 by 1''s to 2 - MAX_STEP_SIZE by MIN_STEP. I believe this is called a ratio. Example range 0 - 255 going by 1''s value is 80 range 2 - 128 going by 4''s value would be ?? but, im not sure that this is the type of value i would want really, because i havent even implemented the technique yet, im just taking a concept and seeing if its useful or not, i concept i came up with (But i wouldnt doubt someone already came up with the idea).. ive been struggling with writing a formula/equation, how would you write this ?

##### Share on other sites
You lost me at "My first idea was..." Can you rephrase, elaborate and explain the rest? (Maybe someone else will know what you mean... but I don''t...)

##### Share on other sites
Same here... It isn''t too clear what you mean...

##### Share on other sites
First of all, what does "detail" mean? Is this the granularity of the texture at that point or the distance from where you can see the point or what? I''d be glad to help, but what are you trying to accomplish exactly?

Maybe you are trying to make certain verteces remain in view from farther away, and cut others at a certain distance.

Then you could calculate the distance between the camera and the current vertex. MAX_DISTANCE = the distance at which every vertex disappears, say at 1000 units.

Then, detailMap[x][y] / 255 would be a percent. This percent multiplied by MAX_DISTANCE would be the distance at which the vertex dissappears. If this value is greater than the distance to the camera, then the vertex is drawn. If it is less, then the vertex is too far away and is skipped.

With this system, a value of 255 in your detailMap would make the vertex disappear at 1000 units. 255/2 would make it disappear at 1000/2. You could then make models simplify in the distance by skipping vertexes that aren''t critical.

To find the distance to the camera, you should use vector math, but I admit I have forgotten the excact equation, and I am away from my materials, at a public computer... I think it used the cross product of the two vectors, or something...

##### Share on other sites
this is what i want to do

0 - 255 going by 1's (0,1,2,3,4,5,6,7,...,255)
and turn that number into a number on the following scale
MIN_STEP - MAX_STEP going by SMALL_STEP (1,4,8,12,16,...,128)

this is basicaly a method of describing the terrain, because flat area's need less detail, we'd put 0 for flat areas... then if ran through this equation, it would know that we could skip several pixels until we reached an interesting point, where height changes

[edited by - fireking on November 6, 2003 3:51:09 PM]

##### Share on other sites
It still isn''t very clear to me since your inital sequence is linear, and your final sequence is non-linear. Though you seem to imply the final sequence should be linear, it is not as you have it written.

##### Share on other sites
What do you mean by "and turn that number into a number on the following scale"? 2-128 isn''t "a number" ... nor is 1-255.

Do you want to find the nearest multiple of 4 for each number between 1 and 255? Nearest multiple without going over?

Are the 1-255 array indices? Do you want to average several values in the array?

##### Share on other sites
examples:
a range = 0 - 5 going by 1''s
b range = 0 - 10 going by 1''s

if a''s value is 4, b''s value is 8
if a''s value is 2, b''s value is 4
if a''s value is 1, b''s value is 2

a range = 0 - 20 going by 2''s
b range = 0 - 10 going by 1''s

if a''s value is 10, b''s value is 5
if a''s value is 2, b''s value is 1

do you see what im talking about?

##### Share on other sites
Fireking never replys to what I say but I''ll say something anyway:

It sounds like you''re trying to do one of two things.
The first is:

1) When you say "detail map" you''re talking about information for a dynamic level of detail piece in your renderer. So you could... skip polygons out there at further distances where detail is closer to 0

I don''t think this is what you mean, but it''s a possibility.

the second thing it sound like it might be is:

2) You''ve been working on texturing your landscape lately, and have been looking for ways to specify which areas of the landscape have each type of terrain texture (like dirt, rock, grass, snow, sand, etc.)
You might be talking about a map for alpha blending of textures over the landscape (the way you talk of "detail" it sounds like you''re wanting to do something like terrain splatting.)

If this (2) is the case, you''ll probably want the value to range from 0 to 1
if it''s ranging from 0 to 255 right now, just take the value and divide it by 255
---
value/=255.0f;
--
or precompute with 1/255 is (0.003921568627450980392156862745098)
and multiply the value by it (should be faster)
---
value *=0.003921568627f;
--

One more thing comes to mind. Perhaps you''re wanting to modulate or multiply (same thing in this case) the terrain texture with a detail texture of the same resolution (you probably have a fairly high res texture in this case, like 1024x1024). If you''re doing this, might I recommend the range of 0.5 to 1.5 (that way you can darken, and overbright the original texture.
to do this you''d just do the same as above
---
value/=255.0f;
--
except you''d add 0.5 to it
---
value/=255.0f + 0.5f;
--
or
---
value *=0.003921568627f + 0.5f;
---------------

If this isn''t what you''re trying to do (any of these things) I apologize, I''m just trying to help (if I''m not, just tell me to get lost,k?)

-Michael

##### Share on other sites
((a-min_a)/step_a)*step_b+min_b

Though that will not guarantee that the max values of those sequences will be what you expected.

See, in your first example of your last post, you have 10 members in the b sequence but only 5 members in the a sequence. So either step_b is not 1 in that case or you still are not clearly explaining yourself.

How are you getting the answers in your examples? If you know how you are getting those answers, assuming you are not just pulling them out of thin air, then it should be trivial to write the mapping function.

[edited by - Mastaba on November 6, 2003 6:01:16 PM]

1. 1
Rutin
70
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011825
• ### Who's Online (See full list)

There are no registered users currently online

×