iDevGames Forums
Anybody have an idea what this variable is used for? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Anybody have an idea what this variable is used for? (/thread-3456.html)



Anybody have an idea what this variable is used for? - WhatMeWorry - Feb 28, 2007 07:44 PM

I'm trying to reverse engineer some code, and there is a variable called detailh. There is only one line where it is used. In all other instances, it is set to 1.0.

Code:
vector<Uint8> texture::make_normals(const vector<Uint8>& src, unsigned w, unsigned h, float detailh) const
{
    // src size must be w*h
    vector<Uint8> dst(3*w*h);
    float zh = 255.0f/detailh;

etc. etc. etc.

Anybody know what this does?
thanks.


Anybody have an idea what this variable is used for? - AnotherJake - Feb 28, 2007 08:22 PM

I don't know, but that is definitely some of the ugliest code I've ever seen!

I'll take a wild guess that h stands for height. zh might mean height expressed in terms of the z axis. detailh might mean detail scale corresponding to height. So height along the z axis is derived from a parameter passed in as detailh? Hey, my crystal ball is just as hazy as the next guy's...

[sarcasm] And I absolutely *love* comments! [/sarcasm] I don't understand why people are so crazy about them when they waste much more time and space than they save, 99% of the time. Somebody should start a non-comment revolution. It should go something like this: If you can't think of something helpful to say in a comment, then don't say it!

[edit] 'Nuther wild guess: Is this for some type of height-mapped terrain figgamajigger? [/edit]


Anybody have an idea what this variable is used for? - OneSadCookie - Feb 28, 2007 08:48 PM

Looks like it might be part of some code for turning an 8-bit image into a height map or normal map, but you haven't exactly given us enough information to say anything more than "255 is divided by it" Rasp

Jake: the anti-comment revolution is called "extreme programming".


Anybody have an idea what this variable is used for? - AnotherJake - Feb 28, 2007 09:39 PM

Extreme programming huh? Doesn't seem very `extreme' to me to write code that documents itself, but I guess I'll have to do a Google trip for that next time I get the chance. Smile


Anybody have an idea what this variable is used for? - reubert - Feb 28, 2007 10:15 PM

It would help if we knew what happened to zh after that.
A x / 255.0 would suggest converting an 8bit image value to a 0-1 float, which would be the normal way to do things like what OSC is suggesting.
But this is 255.0 / x which I can't see a simple use for.

I wrote a big stupid theory in here then deleted it because I think there are about 5000 possible explanations with the example given.

Kinda reminds me of a 'Add a quote to this image' type thing. 'What is this code trying to do?' <insert some funny response here>

Who knows? It could be a bug...


Anybody have an idea what this variable is used for? - akb825 - Feb 28, 2007 10:48 PM

AnotherJake Wrote:Extreme programming huh? Doesn't seem very `extreme' to me to write code that documents itself, but I guess I'll have to do a Google trip for that next time I get the chance. Smile
No need: Wikipedia knows all. Rasp


Anybody have an idea what this variable is used for? - unknown - Mar 1, 2007 05:14 AM

what are you attempting to reverse engineer?


Anybody have an idea what this variable is used for? - WhatMeWorry - Mar 1, 2007 08:33 AM

Well, it's submarine game code I found in - I believe at site's name was - sourceforge? Or something like that?

I thought this might be some typical technique, but obviously not.

Actually, I'm interested in the part of the code that implements a widgets interface. But to get here, i have to fudge with fonts. It's Linux/PC SDL/C++ code but it's turning into more trouble than it's worth.


Anybody have an idea what this variable is used for? - unknown - Mar 1, 2007 10:31 AM

did someone say fonts? Grin