Thread: Question about math... rendering varying sized boxes

  1. #1
    Registered User
    Join Date
    Nov 2005

    Question about math... rendering varying sized boxes

    Ok I have done this before, but I can't remember exactly how.
    I want to be able to render a box of varying sizes(width,height) and also varying scale. Reason for both is to preserve resolution as much as possible.

    I have the following variables with are the sprites or images that I want to blit
    hgeSprite* TopLeft;
    hgeSprite* TopMiddle;
    hgeSprite* TopRight;
    hgeSprite* LeftCenter;
    hgeSprite* Center;
    hgeSprite* RightCenter;
    hgeSprite* BottomLeft;
    hgeSprite* BottomMiddle;
    hgeSprite* BottomRight;
    TopLeft-Rendered once per frame
    TopMiddle-Rendered as many times as the box is wide
    TopRight-Rendered once per frame

    LeftCenter-Rendered as many times as the box is high
    Center-Rendered before each sprite of the box ( the box's background )
    RightCenter-Render as many times as the box is high

    BottomLeft-Rendered once per frame
    BottomMiddle-Rendered as many times as the box is wide
    BottomRight-Rendered once per frame

    I thought that I should render the corners first and then fill in the rest in a loop. Unless I am blind mentally and I cant see a way to loop the entire render without a million if statements.

    NOTE: I think the main problem is that the windows can be scaled at creation, or runtime. so that also makes the code a little different.

    All sprites start at 32x32pixels
    This is what I have for rendering the corners-
    //Scaled position
            float tpos_x = pos_x*scale_x;
            float tpos_y = pos_y*scale_y;
            //scaled section size
            float section = (32.0f*scale_x);
            float linksize_h = ((32.0f*scale_x)*links_h);
            float linksize_v = ((32.0f*scale_y)*links_v);
            /* Render corners */
            //Top Left corner
            //Top Right corner
            //Bottom Left corner
            //Bottom Right corner
    so I wrote this so far, but I can seem to get the rest figured out. I was hoping someone could help me with this. I will be extremely grateful for any assistance. Thank you.
    Last edited by Raigne; 04-23-2008 at 02:32 AM.

  2. #2
    Registered User
    Join Date
    Nov 2005
    -Rewritten below-
    Last edited by Raigne; 04-23-2008 at 03:34 PM.

  3. #3
    Registered User
    Join Date
    Oct 2006
    instead of rendering pixel by pixel, you can render line by line which is a looot faster.

    What API are you using?

  4. #4
    Registered User
    Join Date
    Nov 2005
    I am rendering line by line or rather (sprite by sprite).

    Calling the render function does not actual render it. It adds it to a render tree, and then when the frame is over the tree is dumped and rendered.

    Do you think I should store the position of the window render in a vector then just rmake the vect if position of the window changes?

  5. #5
    Registered User
    Join Date
    Nov 2005
    Ok I rewrote the rendering loop. To fix a problem with positioning. Although I still get the spacing problem with I render with any scale other than 0.5f and 1.0f. I don't know why though.
    void UI_Window::Draw()
    	const float NO_ROTATION = 0.0f;
    	//each section of the window scaled
    	float Section = (32.0f*scale_x);
    	//Total width and height of window
    	float Width = (Section*(links_h+1));
    	float Height= (Section*(links_v+1));
    	//Render loop
    	for ( int x = (int)pos_x; x <= (int)(pos_x+(Width-Section)); x += (int)Section )
    		for ( int y = (int)pos_y; y <= (int)(pos_y+(Height-Section)); y += (int)Section )
    			//Render background
    		/* Links */
    			//Render Top middle
    			if ( ( x > pos_x && x < (pos_x+(Width-Section)) ) && y == pos_y )
    			//Render Left center
    			if ( x == pos_x && ( y > pos_y && y < (pos_y+(Height-Section)) ) )
    			//Render Bottom Middle
    			if ( ( x > pos_x && x < (pos_x+(Width-Section)) ) && y == (pos_y+(Height-Section)) )
    			//Render Right center
    			if ( x == (pos_x+(Width-Section)) && ( y > pos_y && y < (pos_y+(Height-Section)) ) )
    		/* Corners */
    			//Render the TopLeft corner
    			if ( x == pos_x && y == pos_y )
    			//Render the TopRight corner
    			if ( x == (pos_x+(Width-Section)) && y == pos_y )
    			//Render the BottomLeft corner
    			if ( x == pos_x && y == (pos_y+(Height-Section)) )
    			//Render the BottomRight corner
    			if ( x == (pos_x+(Width-Section)) && y == (pos_y+(Height-Section)) )
    That is for rendering the window.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Here are some screen of the windows. Cut out the rest for size reasons.

    This is the window at 1.5 scale. Clearly it isn't drawing like I want. Not that I will need a window this big.Attachment 8083

    This is the window at 0.5 scale. This looks good to me.
    Attachment 8084

    Edit: I know the window graphic doesn't look good now, but it works until I spend time to make a better one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math Question, hard
    By Yoshi in forum A Brief History of
    Replies: 34
    Last Post: 12-08-2001, 11:58 AM
  2. Math Question
    By DarkEldar77 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2001, 12:52 PM
  3. Edit Boxes Question
    By Ruben in forum Windows Programming
    Replies: 2
    Last Post: 09-14-2001, 12:06 AM
  4. Edit Boxes Question
    By RubenJ in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2001, 08:01 PM
  5. question about Message Boxes
    By ArseMan in forum C++ Programming
    Replies: 5
    Last Post: 09-12-2001, 12:41 PM