Implement c code for drawing filled triangles

Assignment Help C/C++ Programming
Reference no: EM13870997

Overview

In this assignment you will implement C code for drawing filled triangles in a window on the screen.

Description

Your task is to complete the functions listed below. Together these functions provide functionality to draw filled triangles on the screen. In addition, the functions enable you to scale the size of a triangle and move (translate) a triangle to a given position on the screen.

Each triangle is described by a triangle_t data structure. All the functions below accept a pointer to a triangle data structure as input. Each function needs to access and modify the fields of the data structure as appropriate.

• ScaleTriangle - Scale the size of the triangle. The scaling factor is specified in the scale field in the triangle data structure. The scaling factor is a floating point number. A factor less than 1.0 should decrease the size of the triangle, while a factor greater than 1.0 should increase the size.

• TranslateTriangle - Move the triangle to a specific position on the screen. The position is specified in the triangle data structure in the tx and ty fields.

• CalculateTriangleBoundingBox - Calculate the size of a rectangle that is just large enough to contain the triangle. The bx, by, bw, and bh fields of the triangle data structure should be initialized with the appropriate values.

• FillTriangle - Fill the triangle with a color. The fillcolor field in the triangle data structure specifies the fill color. There exists many different approaches for filling triangles and polygons in general. See the Resources section below for some inspiration.

• DrawTriangle - Draw a scaled, translated, and filled triangle on the screen.

In this assignment there should be no need to define functions beyond those already defined in the files we provide. We recommend starting with code to draw a wireframe version of the triangle on the screen (by use of the DrawLine function). Then, either proceed with the code to scale the triangle, or the code to move the triangle to a given position on the screen. Note that triangle scale is specified as a floating point number, while the triangle coordinates are integer variables. You will need to think about conversions between integer and floating point numbers to make the scaling function work properly. When scaling, translation, and drawing works, embark on the code for filling the triangles.

Once you have working code for drawing triangles, you can test it by drawing a colourful teapot on the screen, using a triangle-based model that we provide.

The teapot model is represented as an array of pre-initialized triangle data structures. The model is contained within a 1000x1000 box, with coordinates ranging from -500 to 500 on both the x and y axis.

To properly draw this model you must translate it to the middle of the screen. Note that in this assignment we set the resolution of the screen to 1024x768 pixels. If translated to the middle of the screen, the teapot model does not have y coordinates that exceed the resolution of the screen. Thus there is no need to scale the teapot before drawing it.

Code

Your starting point is the following set of files:

• drawline.h - Specifies the interface of the drawline function. Do not modify this file.

• drawline.c - Implements the DrawLine function.

• triangle.h - Specifies the triangle data structure and the interface to the DrawTriangle function. Do not modify this file.

• triangle.c - Empty stubs for DrawTriangle and other functions. You will be editing this file.

• teapot_data.h - Coordinates for the classic teapot model.

• main.c - Contains the main function, calls to initialize SDL, and calls to draw some example triangles.

• Makefile - A Makefile for compiling the code.

Attachment:- problem.zip

Reference no: EM13870997

Questions Cloud

What distinguishes a customs union from a free trade area : What distinguishes a customs union from a free trade area? What distinguishes a common market from a customs union? What is the difference between trade creation and trade diversion? Can you provide an example of each?
Sale securities to the trading category : On February 1, Year 2, the Razorback Corporation decides to transfer its available for sale securities to the trading category.
What government agencies could he possibly be referring to : Mr. Carty mentions involvement of the federal government in labor relations. What government agencies could he possibly be referring to
How did gold-exchange standard differ from the gold standard : How did the gold-exchange standard differ from the gold standard? How did the adjustable gold peg (Bretton Woods) system differ from the gold-exchange standard?
Implement c code for drawing filled triangles : Calculate the size of a rectangle that is just large enough to contain the triangle. The bx, by, bw, and bh fields of the triangle data structure should be initialized with the appropriate values.
What distinguishes upper credit tranches from first credit : In the IMF credit arrangements, what distinguishes the upper credit tranches from the first credit tranche? What is your reaction to the different visions of the Keynes Plan and the White Plan?
Explain how one of the theories describe motivation : First employee, select and explain how one of the theories/models applies to describe employee's motivation- Second employee, select and explain how one of the theories/models describe motivation (Different Model than used on first employee)
Would you be in favor of expanding the role of the sdr : Would you be in favor of expanding the role of the SDR to make it an international currency along the lines of Keynes' bancor?
Share of eagle''s net income and dividends : On January 1, Year 1, Tiger Company purchased 6,720 shares of Eagle Corporation's common stock when Eagle Corporation had 22,400 shares outstanding.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create author-filename

FILENAME: title of the source file,SPECIFICATION: description of the program

  Add a copy constructor

Take the code below and add a copy constructor, assignment operator definition and destructor to the class. These functions have already been started for you.

  Expressions until the user says

Expressions until the user says he or she wishes to end the program. For a more difficult assignment, enhance your program so that the expression need not be well formed; if it is not well formed, then the user is asked to reenter the expression.

  Which is not a valid name for a method or function

Which is not a valid name for a method or function? Which of the following is a valid overloaded version of this method

  Program which asks the user for due date of next assignment

Write a program which asks the user for due date of the next assignment (hours, minutes). Then print number of minutes between the current time and the due date in format.

  Write a program that create a

Write a program that allows a user to navigate a robot through a maze from the start position at the bottom left of the maze, to the centre of the maze.

  Write in c++ another overloaded operator

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..

  Explain strings are an important part of programming

Strings are an important part of programming. They are used to transfer all sorts of data between the user and program, as well as from program to program. Humans communicate with streams because they are flexible enough to encode words and vari..

  Show how your function works

Write a function named longestSortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted non-decreasing sequence of integers in the array. For case given the sequence:

  Design class for textbook-data field for grade level of book

Design a class named TextBook that is child class of Book. Include new data field for grade level of book. Create a displayTextBookInfo () method so that you can accommodate new grade-level field.

  Write the complete description of all functions

Use the following class declarations. Write the complete description of all functions so that the program creates the following I/O

  If ptr is a pointer to a character

If ptr is a pointer to a character and has been initialized to point to the first element of arr, write a statement using ptr that is equivalent to the statement array[4] = 12.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd