Not logged in, Join Here! or Log In Below:  
News Articles Search    

Submitted by Yordan Gyurchev, posted on August 10, 2001

Image Description, by Yordan Gyurchev

The CurvCloth demo is a simple cloth effect that uses lattice of springs and curved surfaces. (very simple, trivial, unstable, unoptimized implementation).

You can find more tech details in the text file included in the zip archive.


I'm trying to measure the quality of my coding style (readabilty, maintainability). If you are interested in helping me with that, please download the source and send some feed back on the following questions.
  • Do you think the code is readable?
  • What do you think I should change in my coding style?
  • Were you able to understand the code or you had to look through it several times?
  • How about the comments? Too many? Insufficient? Senseless?
  • What did you like/dislike about this source code?
  • Please send your comments, responses, suggestions to this thread or mail to:

    Yordan Gyurchev

    Image of the Day Gallery


    Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
    Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
    Rectilinear Cat

    August 10, 2001, 02:59 PM

    Cool! Have you tried animating this thing yet? Wind effects?


    August 10, 2001, 03:27 PM

    I know you wanted feedback about you're code, I'll d/l it at home then post feedbacks...

    Is that cloth effect real time?
    And what are the possibilities with your cloth effect?


    August 10, 2001, 03:31 PM

    Cool, I'm actually working on similar cloth effects right now...

    I'd like to see some marbles dropped on there- bouncing and rolling around. I know it's a little difficult, but it'd be cool.

    For some reason it reminded me of a demonstration I once saw of General Relativity and warped space time creating gravity (my mind work in mysterious ways I guess). If you don't know which one I'm talking about, just ignore the comment :)



    August 10, 2001, 03:36 PM

    i havent actually downloaded the demo but the stretching of the cloth texture is very realistic. nice work ;)


    August 10, 2001, 03:43 PM

    Looks good. Might be my eyes going buggy (it is friday afternoon afterall) but it looks a bit distorted after the buldge. Anyone else see it, or do I just need more sleep?

    Anyways, in terms of the code, what format / style you use is as much a potential holy war as any other topic (such as asm or not ! :) ). I did however find the code readible at a glance, so that bodes well. I never really dug deep into it though.

    On that topic, heres a few pet pieves of mine

    //This variable is for something or other
    varaibletype variablename;

    I hate that format, and would much rather see
    variabletype variablename; // does something or other

    Dont have to waste time describing what the comment is for, as it becomes more obvious. However, I run 1600x1200, so having wide code doesnt bother me at all.

    Spaces vs tabs
    I have a huge preference to hard spaces over a tab. Makes layout of code consistant across editors and platforms. This however, is largely an opinion thing. I normally set my tab up to be 2 hard spaces. I know of some collabrative projects where this is strictly enforced.

    //lattice height and width
    const int cLatticeWidth = 16;

    Comments like this are basically a waste of space. Variable is named well enough that the comment is redundant. I also personally hate prefixed naming conventions (although, I still seem to use em all the time). cLatticeWidth c? Is this a char, or is it a constant? Its fairly obvious here, as im sitting at the declaration, but, miles away, in another module, it becomes more confusing. (Yeah, I know char is a). Some people love hungrian, myself I HATE it. I follow the all global constants should be UPPER CASE school of thought. I guess more then anything, consistancy is the key.

    Sorry I didnt get in much deeper, at work and dont really have the time or attention span to really get into something.

    Looks good though.



    August 10, 2001, 03:56 PM

    If you are talking about a slight cc rotation at the top of the bludge, with what appears to be an incoherent strecthing of the texture then yes I see it, but I have not looked at the demo yet. That might be natural to the flow of the fabric. But like you said its Friday and I'm tired of coding new bugs.


    August 10, 2001, 05:40 PM

    There are people that love hungarian notation? Nice image btw.


    August 10, 2001, 06:38 PM

    Hey it's terminator 2!

    It looks good! 107fps, PIII 650, 128mb, Voodoo 3/2000



    August 10, 2001, 06:39 PM

    Agreed, like I said, just an opinion :) However, there are some people that like spam.... I still think it tastes like crap though.



    Craig Rennie

    August 10, 2001, 06:53 PM

    That's what I thought it was when I saw the thumbnail on the main page :)
    The curves going the wrong way though isn't it?


    Thomas S

    August 10, 2001, 08:13 PM

    Since this isn't, I think it should be okay to recomend a book from Microsoft Press, without starting a flamewar (or being attacked by 14-year old l33t script kiddies)...

    'Code Complete' by Steve McConnel (ISBN 1-55615-484-4) -- It covers things like, variable naming convetions, commenting techniques, self-documenting code... I love this book -- Good and fun reading.

    For more info, reviews, table of contents:


    August 10, 2001, 08:19 PM

    Out of the way, there's a bit rat underneath that carpet! SMACK, bwahaha, smashed it with my giant hammer. Sorry about the red color your cloth has now...

    Ok serious now. Your code is really nice to read, there's some minor stuff that that I would write differently, but I think my personal preference doesn't matter here. It's really very clear and easy to understand, so keep up the good work!


    August 10, 2001, 10:24 PM


    The code is laid out and formatted very well and very consistantly. The only thing I would suggest, is to make more use of spaces (display width permitting). So instead of writing:



    n1+=v*(factor.PatchTNFactor*factor.PatchSFactor); n2+=v*(factor.PatchSNFactor*factor.PatchTFactor);

    write it something like:
    for( yPoint = 0; yPoint < cLatticeHeight; yPoint++ )
      for( xPoint = 0; xPoint < cLatticeWidth; xPoint++ )
    n1 += v * (factor.PatchTNFactor * factor.PatchSFactor);
    n2 += v * (factor.PatchSNFactor * factor.PatchTFactor);
    Makes it easier to read when everythings not bunched together. :) DGuy

    Stefan Karlsson

    August 11, 2001, 12:32 AM

    Come on.. is this post serious? ;)

    Craig Rennie

    August 11, 2001, 01:31 AM

    It's a matter of personal taste man, I find it harder to read code when there are spaces next to brackets (on the inside), and when spaces are placed between a variable, the equals sign, and it's value.
    However, in a for loop, if there aren't spaces after the semicolons, then it just drives me beserk :)


    George Ziniewicz

    August 11, 2001, 01:43 AM

    Great effect, almost scary. I got about 70 fps in the window mode on a 1 gig atlon 2/ GeForce2

    No exe? I had to compile it.
    Near the end of the run, the cloth went wildly unstable. Not on other runs.
    A second run by clicking on the exe won't run, "invalid enumerant"
    No ESC or other key to exit, no window widgets worked (maximize/close).
    The bump goes off the top of the screen/window, so you don't see the rolloff.

    Code style (picky!):

    Looks ok. A couple of things I like to do:

    1. function separators, a must for me:


    void class::func(void) {


    2. A 1-command if() goes on one line. compare:

    if (wParam==VK_F1) {

    if (wParam==VK_F1) ToggleFullScreen();

    3. Unlike a previous poster, I like compressed code (few unnecessary blanks) like you appear to, although I do not like all the blank lines everywhere.

    4. Personally I start a brace set on the line with the function beginning, or if statement, or for loop:

    if (condition) {
    do something
    do something else

    5. I agree with a previous poster, a short comment goes on/appended to the line it comments.

    But these are sylistic, only needing conformity in a group setting.

    Now re the cloth. I did a cool cloth thing awhile back on my Mac (DaliZ), dropping a cloth onto a round surface.
    Porting it to pc, it ran way too fast.
    My code normally uses deltaTime to adjust all modifiers, but I never figured out where to apply that in a cloth simulation.
    Yours looks ok. Insight?



    August 11, 2001, 02:24 AM


    Code looks good, needs a bit of spacing but I believe the previous posts already covered that.

    Demo looks good, runs @ 75 fps on my T-Bird 900 /w a GF2/MX



    August 11, 2001, 05:13 AM

    Had a quick look at the source. Coding style is good in most areas, the only problem I have is with brace determination.

    Some of your code is written in modern style, e.g;

    if (this)
    do something here

    But some files use the evil 'One true brace' style, e.g;

    if (something){
    do something

    I would pick a style and stick to it. (Not one true brace though due to the nature of it's evil! :) )

    Also be warned, a change of bracing style likes this makes it look like you only wrote part of the code!

    See ya

    Stefan Karlsson

    August 11, 2001, 07:32 AM

    personally i allways switch between different styles depending on what mood iam on and what looks coolest in the code :)

    // code

    and sometimes i write

    just to point out whats important or like "the bigger block"

    Stefan Karlsson

    August 11, 2001, 10:32 PM

    i noticed some spaces dissaperd to.. maybee i shoulve used the cpp tags.. o well =)

    Peter Honeder

    August 12, 2001, 11:04 AM

    the invalid enumerant message comes because you started the exe from the wrong directory (release or debug for msvc++).


    This thread contains 21 messages.
    Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.