Anybody have an idea what this variable is used for?

Member
Posts: 321
Joined: 2004.10
Post: #1
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.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #2
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]
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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".
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #4
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
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #5
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...

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
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
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
what are you attempting to reverse engineer?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #8
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.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
did someone say fonts? Grin

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Use an integer value as part of a variable name PHANTOMIAS 5 3,832 Dec 8, 2009 09:24 AM
Last Post: PHANTOMIAS
  variable frame rate animation in Cocoa Damian 3 3,570 Jul 16, 2003 06:00 PM
Last Post: macboy