Results 1 to 6 of 6

Thread: For loop and boolean expression in it and other troubles..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    For loop and boolean expression in it and other troubles..

    Hi.
    I have "weird" problem. In my map editor i must draw selection boxes and i only have to draw in the current camera viewing range. Currently when i move camera somewhere, the selectionboxes are floating in air.

    Im rendering only small portion of the map (rectangle type).
    Now im trying to limit the rendering. Tried many things.. Dunno how to do it.
    The camera range is X,Y and is defined as 4 variables that hold current visible area:
    Code:
    X1 -- X2
    Y1 -- Y2
    X camera range starts from X1 and goes to X2, same with Y.
    Anyway here is piece of code im drawing the selectorblocks with:

    Code:
       
    
    // This currently limits the drawing of selectorblocks at the right "side" of the camera.
    // Works fine, what about the math?
    
    // XSelection contains how many blocks are selected in the X axis
    // StartPnt is just a record with X,Y integers, holding the selection start coordinates, after first mousedown!
    
    for SelCountX:= Iff(
        DragPnt.X > x2, x2 - startpnt.x, xselection
       ) downto 0
    
          do
          begin
         
            for SelCountY:=  0 to YSelection do
            begin
              for SelCountZ :=  0 to ZSelection do
              begin
                
                glPushMatrix();
    
    
                      glTranslatef(
    
    
                        SelCountX + selX  -0.5,
                        SelCountZ + selZ  -0.5,
                        SelCountY + selY  -0.5
    
    
                      );
    
    
    // Just draws cube, nothing special in there.
                    DrawCube(SelCountZ, SelCountX, SelCountY);
    
    
    
                glPopMatrix();
              end;
            end;
          end;
    "Iff" is from JclSysUtils.pas from JEDI.
    Code:
    // Replacement for the C ternary conditional operator ? :
    function Iff(const Condition: Boolean; const TruePart, FalsePart: string): string; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Char): Char; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Byte): Byte; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Integer): Integer; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Cardinal): Cardinal; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Float): Float; overload;
    function Iff(const Condition: Boolean; const TruePart, FalsePart: Boolean): Boolean; overload;
    My question is how to make that "for X:" loop neat enough so i can use the Iff twice there, so i can do like: Less than.. also in that loop.

    The right side "drawing limitation" for selectorblocks works, i would like to do the same for left side also. But it seems impossible within "for loop" without repeating code.


    Is it even possible in Pascal (Delphi) ?
    Code:
    Iff(
        DragPnt.X < x2, x2 - startpnt.x, xselection
       ) downto 0

    I cant say Delphi, if THIS is true then loop that way, but if THIS is NOT true, loop another way. Also i cant say him to use either DOWNTO or TO. But this would probably fix it.

    With separate loops and repeated code maybe yes, but without it?

    Impossible?

    EDIT: In C++ it seems possible:
    http://stackoverflow.com/questions/1...loop-statement
    Last edited by hwnd; 27-11-2013 at 02:52 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •