Archived

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

i need help with writing an equation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites
Hmm, I''m still confused... tell me if I understand correctly

you have a range from 0 to 255 right now
(0,1,2,3,...254,255) with a step of 1

and you want a new range say, something like 2 - 17 with a step of 3 you''d want the numbers within the set of
(2,5,8,11,14,17)

is this correct?

-Michael

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i think you need this: (k+1) / 2
where k = 255 makes 255 + 1 / 2 = 128.
however it doesnt get you the by 4 thing you want, it instead mapps out like:
1
1
2
2
3
3
...127
127
128
something like that.

Share this post


Link to post
Share on other sites
quote:
Original post by Thr33d
Hmm, I''m still confused... tell me if I understand correctly

you have a range from 0 to 255 right now
(0,1,2,3,...254,255) with a step of 1

and you want a new range say, something like 2 - 17 with a step of 3 you''d want the numbers within the set of
(2,5,8,11,14,17)

is this correct?

-Michael


yeah

i need to convert from one range to the other range, without decimal values, whole numbers

Share this post


Link to post
Share on other sites
Solution:
To convert from A to B by Cs (in your terminology)
to D to E by Fs you do for each x in the first sequence:
y=trunc((x-A)/(B-A)*(E-D)/F)*F+D
Note that this means some values of x can be mapped to the same y and visa versa.
Trunc removes the decimal part of the number in question (i forget the C syntax). You could re-cast to integer and the compiler would do this automatically.
Rounding may be better than truncating, you'll need to experiment (I cannot say as you have not said what you want this for...)

EDIT: NB: The reason why everyone was so confused over what you said is that your second post contained a mistake:
(1,4,8,12,...) is wrong as the first interval is 3 when you wanted each step to be SMALL_STEP=4.

[edited by - sadwanmage on November 7, 2003 11:24:10 AM]

Share this post


Link to post
Share on other sites
If you use integers for all your calculations, you don''t need to worry about decimal values. How about this:

newVal = ((oldVal - oldMin) * (newMax - newMin) / (oldMax - oldMin)) / newStep * newStep + newMin

Expanation: You take the oldVal (old values) numbers, and subtract the oldMin (old minimum) number, thus getting the values relative to the old minimum. Then you divide by (oldMax - oldMin) to normalize the range of values to 0..1. Then, you multiply by (newMax - newMin) to expand set of possible values to the size of the new range of numbers. Then swap the order of those so that you multiply first, thus getting relatively good approximations to the correct ratios without using decimal numbers in the middle. Next, divide by newStep and multiply by newStep, in that order (using integer arithmatic) so you only get values that are every newStep numbers. There may be some duplication in this step depending on the old and new steps, but that can''t really be avoided. Next, add newMin to shift all the results up so they actually fall into the range from newMin to newMax.

Share this post


Link to post
Share on other sites