Jump to content
  • Advertisement
Sign in to follow this  
Pixar

Triangle filling

This topic is 3050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I should start a new topic, because all the other topics did't let me post on them. So, I'm writing a software engine on C# with SlimDX (I use only surface from it) and, to be faithful, it is based on Andre LaMothe book :). Generally speaking, I'd like to create a topic about performance itself, but as I'm loosing the greater amount of frames in the filling triangle method, I want before to solve my problem with it. Here is the code (a part) of my method:
void Draw_Top_Tri(int x1, int y1, int x2, int y2, int x3, int y3, int color)
        {
            float dx_right, dx_left, xs, xe, height;

            int temp_x, temp_y, right, left;

            if (x2 < x1) { temp_x = x2; x2 = x1; x1 = temp_x; }

            height = y3 - y1;

            dx_left = (x3 - x1) / height;
            dx_right = (x3 - x2) / height

            xs = (float)x1;
            xe = (float)x2;

            if (y1 < min_clip_y)
            {
                xs += dx_left * (min_clip_y - y1);
                xe += dx_right * (min_clip_y - y1);
                y1 = min_clip_y;
            }
            if (y3 > max_clip_y)
                y3 = max_clip_y;

            if (x1 >= min_clip_x && x1 <= max_clip_x &&
                x2 >= min_clip_x && x2 <= max_clip_x &&
                x3 >= min_clip_x && x3 <= max_clip_x)
            {
                int i, ixs, ixe;

                for (temp_y = y1; temp_y <= y3; temp_y++)
                {
                    ixs = (int)(xs + 0.5f);
                    ixe = (int)(xe + 0.5f);
                    for (i = ixs; i <= ixe; i++)
                        Buffer[temp_y * Pitch_Div_4 + i] = color;

                    xs += dx_left; xe += dx_right;
                }
            }
}
I'm not writing comments, because it is intuitively understandable code, it's LaMothe's code, and they were in the other language :) So, I know that nested loop is very unprofitable, but I can't do anything with it, because in C# there is no function like memset and I have to make a loop to draw lines...so, I want to hear your advices...

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!