logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

This lab introduces structs as a data structure to organize information.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 

Purpose: This lab introduces structs as a data structure to organize information.

Problem:

In this lab you are to implement a computer drafting program.  The program reads in a set of objects and implements the ability to translate, scale, and rotate individual objects. Objects are defined by a set of lines, each line defined by its endpoints. Software is provided which will create a visual of your objects by allowing you to draw the individual lines.

Support:

Graphics code is provided to you supporting the drawing of lines. Student code needs to use the struct Point3D found in Point3D.h when define a point in a Cartesian coordinate system. The graphics is initialized by a call to InitializeGraphics which is already called for you in the provided main function.

Lines are provided to the graphics display by individual calls to:

void DrawLine(Point3D pt1, Point3D pt2);

providing the two endpoints of the line as pt1 and pt2. Prior to drawing any lines for a new scene, the new scene should be cleared by a call to:

void RefreshGraphics();

Once all lines to be drawn are provided to the graphics by calling DrawLine for each line in a scene, the graphics can be updated to the new scene by a call to:

void UpdateGraphics();

All three of these functions are defined in OglWorker.h.

The idea is to define all lines in a scene by updating individual objects in the scene, and then the scene should be redrawn by providing all lines to the graphics, and then updating the graphics.

Approach:

Step 1: Define data structures.

Your program should work on a Scene which can have up to 10 objects. Each object is defined to have up to 20 lines to provide it a 3D shape. Each line has 2 endpoints, each a 3D point. A struct is provided for you to define a 3D point (found in Point3D.h).

You need to define a Scene, Object, and Line in Draw3D.h.

Step 2: Declare functions for the following operations in Draw3D.h and implement them in Draw3D.cpp.

InitScene – This function should initialize a scene by reading information about the scene from a file. A string should be provided to indicate the file to read. The format of the file is provided below.

DrawScene – This function draws the scene to the window. It should loop through all objects and for each object loop through all lines calling DrawLine (provided for you) for each line. The first line of the function should call RefreshGraphics() (provided for you) and the last line of the function should call UpdateGraphics() (provided for you).

Translate – This function should translate a single object by a given offset. The offset can be provided by a Point3D, where x, y, and z provide the x offset, y offset, and z offset. Then

 

for each point (pt) in the object (remember lines are defined by endpoints), the point pt should be modified by:

pt.x += offset.x pt.y += offset.y pt.z += offset.z

Scale – This function is provided an object, a base point, and a scale factor. It then scales the object’s size by scaling the distance of all points in the object relative to the base point. This can be accomplished by translating the object by the negative of the base point (this moves the point by which the object will be scaled to the origin), then multiplying all points in the object by the factor, and then translating the object back to its original position (translate by the base point). Alternatively, each point pt in the object can be updated by

pt.x = (pt.x – base.x)*factor + base.x pt.y = (pt.y – base.y)*factor + base.y pt.z = (pt.z – base.z)*factor + base.z

RotateX – This function rotates an object about the x axis by an angle provided in degrees. Each point in the object must be rotated to its new position by

new_pt.x = old_pt.x

new_pt.y = old_pt.y * cos(angle) – old_pt.z * sin(angle); new_pt.z = old_pt.y * sin(angle) + old_pt.z * cos(angle);

where old_pt is the original point and new_pt is the rotated point.

RotateY – This function rotates an object about the y axis by an angle provided in degrees. Each point in the object must be rotated to its new position by

new_pt.x = old_pt.z * sin(angle) + old_pt.x * cos(angle); new_pt.y = old_pt.y

new_pt.z = old_pt.z * cos(angle) – old_pt.x * sin(angle); where old_pt is the original point and new_pt is the rotated point.

RotateZ – This function rotates an object about the z axis by an angle provided in degrees. Each point in the object must be rotated to its new position by

new_pt.x = old_pt.x * cos(angle) – old_pt.y * sin(angle); new_pt.y = old_pt.x * sin(angle) + old_pt.y * cos(angle); new_pt.z = old_pt.z

where old_pt is the original point and new_pt is the rotated point.

 

Input File Format:

The initial scene is defined in a file. A sample file is provided in SceneFile.txt. The first line in the file defines how many objects are in the scene. Then each object is defined individually by providing the number of lines in the object on the first line in the file for that object, and then defining each line on successive file lines, each file line having x, y, and z values for the 1st endpoint of the line and again for the 2nd endpoint. The contents of SceneFile.txt for a single square pyramid is:

2

8

0.0 0.0 0.0 30.0 0.0 0.0

30.0 0.0 0.0 30.0 30.0 0.0

30.0 30.0 0.0 0.0 30.0 0.0

0.0 30.0 0.0 0.0 0.0 0.0

 

0.0 0.0 0.0 15.0 15.0 20.0

30.0 0.0 0.0 15.0 15.0 20.0

30.0 30.0 0.0 15.0 15.0 20.0

0.0 30.0 0.0 15.0 15.0 20.0

4

0.0 0.0 0.0 -10.0 0.0 0.0

-10.0 0.0 0.0 -10.0 -10.0 0.0

-10.0 -10.0 0.0 0.0 -10.0 0.0

0.0 -10.0 0.0 0.0 0.0 0.0

 

Tasks:

Design the algorithms for each function.

Implement the code in the provided project (provided project has graphics support).

Test your code using the provided SceneFile.txt and the operation sequence provided in the main function.

Add another object to the input file and test your ability to manipulate the objects individually. You should define a test sequence that you think tests all functionality. For instance, can you manipulate 1 object and not the other.

Deliverables:

Design: 5 pts.

o Define each function in your design.

Provide a behavioral description of the function – “What does it do”

Provide the algorithm for the function – “How does it do it”

Visual Studio project 10 pts.

o Make sure to properly document your code, especially your .h file as discussed in recitation.

New scene file 2 pts.

Demonstrate your program to the TA. 3 pts.

 

Extra Credit:

You can get 1 point of extra credit for each of the 5 functions (Translate, Scale, RotateX, RotateY, Rotatez) if you modify their behavior so that a single call to one does not just modify the object, but rather smoothly moves the object to its new location/position. To do so, it is suggested to modify each function so that rather than making one large move, you make 50000 small moves (change based on the speed of your computer, 50000 looks good on my computer), redrawing the scene each time you do so. This will change the behavior of each function, the algorithm, and possibly the interface (the function signatures), and thus main. Therefore, you should provide a new design and implementation.

While you can directly attempt to design and implement this, it is suggested to do the standard lab first and make sure you have the translate, scale and rotate operations working first.

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

648 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

902 Answers

Hire Me
expert
Husnain SaeedComputer science

615 Answers

Hire Me
expert
Atharva PatilComputer science

564 Answers

Hire Me
April
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30