Sign in to follow this  
Pixar

Triangle filling

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this