コード例 #1
0
ファイル: triangle.c プロジェクト: trulspowers/Informatikk
// Draw triangle on screen
void DrawTriangle(SDL_Surface *screen, triangle_t *triangle)
{
    int isOK;

    // Scale.
    ScaleTriangle(triangle);

    // Translate.
    TranslateTriangle(triangle);

    // Determine bounding box
    CalculateTriangleBoundingBox(triangle);

    // Sanity check that triangle is within screen boundaries.
    isOK = SanityCheckTriangle(screen, triangle);
    if (isOK == 0) {
        PrintTriangle(triangle, "Triangle outside screen boundaries");
        return;
    }

    // TODO: Insert calls to DrawLine to draw the triangle.
    // Remember to use the on-screen coordinates (triangle->sx1, etc.)
    DrawLine(screen, triangle->sx1, triangle->sy1, triangle->sx2, triangle->sy2, TRIANGLE_PENCOLOR);
    DrawLine(screen, triangle->sx2, triangle->sy2, triangle->sx3, triangle->sy3, TRIANGLE_PENCOLOR);
    DrawLine(screen, triangle->sx1, triangle->sy1, triangle->sx3, triangle->sy3, TRIANGLE_PENCOLOR);

    // Fill triangle
    FillTriangle(screen, triangle);
    /*
        DrawLine(screen, triangle->bx, triangle->by, triangle->bx + triangle->bw, triangle->by, 0xffffffff);
        DrawLine(screen, triangle->bx, triangle->by, triangle->bx, triangle->by + triangle->bh, 0xffffffff);
        DrawLine(screen, triangle->bx + triangle->bw, triangle->by + triangle->bh, triangle->bx + triangle->bw, triangle->by, 0xffffffff);
        DrawLine(screen, triangle->bx, triangle->bh + triangle->by, triangle->bw + triangle->bx, triangle->by + triangle->bh, 0xffffffff);
    */
    // Force screen update.
    SDL_UpdateRect(screen, triangle->bx, triangle->by, triangle->bw, triangle->bh);


    // Force update of entire screen.  Comment/remove this call and uncomment the above call
    // when your CalculateTriangleBoundingBox function has been implemented.
    // SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);

}
コード例 #2
-1
ファイル: triangle.c プロジェクト: hzcodec/c_edu
/* *** MAIN *** */
int main(void) {

    triangle_t red_triangle;
    triangle_t green_triangle;

    // declare a pointer to triangle_t
    triangle_t *p_triangle;
    // assigned the pointer to the green_triangle
    p_triangle= &green_triangle;

    red_triangle.x1    = 10;
    red_triangle.y1    = 30;
    red_triangle.scale = 2;

    PrintTriangle(&red_triangle);
    PrintTriangle(&blue_triangle);

    ScaleTriangle(&red_triangle);
    ScaleTriangle(&blue_triangle);

    // use the pointer to the green_triangle
    p_triangle->x1 = 44;
    p_triangle->y1 = 22;
    PrintTriangle(p_triangle);

    return 0;
}