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

  Calculate and display the number of units of electricity

The manager of PG&E wants a program that calculates a customer's electric bill. He will enter the current and previous meter readings.

  Ansi-c program which allows the user to play a game

Your task is to write an ANSI-C program which allows the user to play a game. This will require I/O from both the user and from ?les.

  Function that evaluates a polynomial

1. Given the following function that evaluates a polynomial whose coefficients are stored in an array: double evaluate(double[] coefficients, int n, double x) double result = coefficients[0]; double power = 1; for (inti = 1; i

  Programming questions

Write a program (including timing measurements) for the following scenario. Generate 20 million random numbers, one at a time, and insert them into an array that doubles every time it runs out of space (starting size of 2), into an array that can..

  In the familiar base 10 system

In the familiar base 10 system, the smallest (rightmost) digit of a number is the ones place (100).  The next digit is in the tens place (101), and the next one is in the hundreds place (102) and so forth.  Thus the number 122 is really (1 * 102) + (..

  Program that opens a file representing an encoded maze

Write a C++ program that opens a file representing an encoded maze and reads it in properly so it can be analyzed.

  Test a function hydroxide that takes a chemical formula

Write and test a function hydroxide that takes a chemical formula as a parameter and returns True if the chemical is a hydroxide (i.e. ends in OH).

  Program that asks user to enter two sides of a rectangle

The program will then display the perimeter and area of the rectangle. Both output values will be labeled and formatted with two decimal places.

  Compute a program that calculates three resistance inputs

C language, compute a program that calculates three RESISTANCE inputs, and gives you the total resistance in OHMS. Like this, the total resistance is _____ ohms. These are three parallel circuits so the formula would be (1/R1 + 1/ R 2 +  1/ R 3 )  -1

  Write a cpp program for magic number

Ask the user to enter a "magic number," which is an integer between 0 and 9, inclusive. Then, ask a user to enter 10 integers between 0 and 9, inclusive. If a user enters an integer outside of that range, therefore invalid, notify the user of the ..

  Create a program for a company named retail-mart

Prompt the user to enter an item name (one word only), a quantity and a price. For this step, in addition to functionality, I'll be looking at: location of the variable declarations; appropriateness of data types selected; appropriateness of the va..

  Documenting the testing of c program

Writing a test plan and writing a C program with reasonable comments and sensible variable names - Test and documenting the testing of your c program

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