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 program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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