C++代写:MTRN2500 Static Shapes and Vehicles



Learning Outcomes

This assignment specifically targets the following learning outcomes:

  1. Be well versed with structured and modular programming using C/C++ and to appreciate the use of software to communicate with external devices.
  2. Be able to develop prototype user interfaces to assist in the development of controlled Mechatronic systems.


During your laboratory class in week 9 you will be given a written quiz immediately before the in-class assessment. This will include content from lectures in weeks 1-7, with an emphasis on the items used in this assignment. The quiz will begin at 10 minutes after the beginning of the class and you’ll have 20 minutes to complete it. Normal exam conditions apply and you’ll only need your student card and a pen. Feedback on this will be provided within 2 weeks of the quiz. Following the quiz, the in-class assessment (coding) for that week will begin.

Assignment Specification

This assignment is split into four components. A style component and three in-class assessments. This document will explain what you are required to do, the dates for each part, and the contributions each part will make to your overall assignment mark. Total marks available for this assignment are 20. You will complete this assignment in pairs.

The associated quiz has 5 marks available and will be completed individually.
This assignment will require you to extend the provided 3D world modelling software to model the motion of two or more ground vehicles. You will then be required to read data streams or an input device in real-time, use the data to control the graphical ground vehicles and display them in their environments.

  • Style Component (5 marks)
  • This is due Sunday 16th September 2018 at 11:55pm by submission to Moodle (see below).
  • In-class Assessment Part 1 (5 marks): Static Shapes and Vehicles
  • See Section 4 below. This will be demonstrated to your tutor during your week 7 tutorial.
  • In-class Assessment Part 2 (5 marks): Moving Vehicles
  • See Section 5 below. This will be demonstrated to your tutor during your week 8 tutorial.
  • In-class Assessment Part 3 (5 marks): Final Demo
  • See Section 6 below. This will be demonstrated to your tutor during your week 9 tutorial, immediately following the quiz.

Style and version control component

For the style component you are required to submit all your .h and .cpp files together with the provided files. In addition, a PDF document showing evidence of the use of version control (e.g. exported commits from github) clearly identifying the authors must be included. All these files must be located in a folder named with your full zID (i.e. z1234567) then zipped and submitted to Moodle.

A submission box in Moodle will be open for you to submit the .zip file. Feedback on this will be provided within 2 weeks of submission.

Things we will be looking for include:

  • Consistent and neat structure
  • Choice of names for variables and #defines
  • Commenting and readability of the code
  • Modularity: is the program broken up into well defined files, classes, functions?
  • Evidence that version control (eg. git) has been used by both partners to contribute actively to the solution.

In-class Assessment Part 1: Static Shapes and Vehicles

Creating Basic 3D Shapes

Your first task is to extend the Shape class to implement a set of basic 3D shapes and eventually form a vehicle. When we say extend we mean the object oriented programming term - class derivation - rather than adding a large chunk of code to the Shape class itself. The Shape class contains position and orientation attributes, which are common to every 3D object. You need to implement classes at least for the following shapes outlined in this document. For simplicity, each object can be assigned one colour using three floats to specify the red, green and blue components of the colour. Look at the “Shape.hpp” file for more details on how to interface with and extend the Shape object.

Rectangular Prism

This shape should make use of three additional member attributes concerning the length of the shape in the three spatial dimensions (for example, x length, y length and z length). You should also devise how the volume of the prism is positioned relative to it’s internal x, y and z attributes and how the rotation variable rotates the object in the horizontal plane. One suggestion could be to define the (x, y, z) location as the center of the object and the object’s rotation is applied about the origin of the object.

Triangular Prism

This shape should make use of additional member attributes to specify the dimensions of the triangular prism, the choice of which is left up to you. The length of the prism is an obvious choice for one of these attributes, but you should determine a method for specifying the shape of the triangular dimensions of the object. For example, two different approaches, among others, are to store:

  • the three side lengths of the triangle, or
  • two side lengths and an angle.

You should also remember to intelligently decide on a center for your object and how this relates to object rotation.

Trapezoidal Prism

You should decide on additional member attributes to specify the shape of this object. In particular you need to decide on a way of specifying the dimensions of the trapezium at the end of the prism in an efficient way.


You can use additional member attributes such as length or height along with radius to specify the dimensions of a cylinder. You may make use of the inbuilt “gluCylinder” or “glutCylinder” functions. A cylinder for this project must be a solid cylinder. That is, it should consist of a curved surface together with two circles on each end of the cylinder. The center of a cylinder might be defined as the point half way along the central axis of the cylinder for rotation purposes.

Vehicle Modelling

Using at least one of each of the basic 3D shapes we have defined in the previous section, you should implement your own custom vehicle. When implementing a model of a vehicle you should extend from the base “Vehicle” class provided with the initial collection of files. When constructing the model from basic shapes you should position shapes in the vehicle’s local frame of reference. As a result, the “draw” function in your custom vehicle class should contain the following general structure:

void MyVehicle::draw() {
// move to the vehicle's local frame of reference

// all the local drawing code

// move back to global frame of reference

The base “Vehicle” class contains an “update” function which handles interpreting control input into vehicle motion using a basic mathematical model. Although it is not required, you may modify or improve this mathematical model in the “Vehicle” class. The “update” function, combined with the drawing structure above will position and orient the vehicle’s model correctly in 3D space. You need to make sure you position shapes so that the vehicle is facing the positive x-axis in it’s local frame of reference. For best results make your vehicles not longer than 4 units and not wider than 3 units.

Assessment for Part 1

Demonstrate your ability to draw these shapes before the end of your tutorial in week 7.

  1. Create a RectangularPrism class extended from the Shape class and use it to draw a rectangular prism.
  2. Create a TriangularPrism class extended from the Shape class and use it to draw a triangular prism.
  3. Create a TrapezoidalPrism class extended from the Shape class and use it to draw a trapezoidal prism.
  4. Create a Cylinder class extended from the Shape class and use it to draw a cylinder.
  5. Create a custom MyVehicle class extended from the Vehicle class and use it to draw a static vehicle of your choice, making use of one of each of the shapes defined above.

In-class Assessment Part 2: Moving Vehicles

Your second task is to make a moving vehicle which has wheels and animate both the rolling and steering motions of those wheels. The rolling motion of the wheels must coincide with the motion of the vehicle and the model’s motion should steer according to the wheels’ steering angle. The vehicle path can be pre-programmed.

In addition, this part deals with dynamically adding vehicles into your program using a server, and making these remote vehicles move. In order to do this you will need to interface with a data source over an Ethernet/Wi-fi connection. We have provided a class (called RemoteDataManager) and a set of functions (declared in Messages.hpp) that hides away most of the low-level implementation detail for you. The RemoteDataManager class will connect over the internet to the UNSW robotics server. Communication with the server is bidirectional, and is used to synchronise your environment with the server’s. To enable communication with the data server, uncomment the relevant line of code in the idle() function in the main.cpp file near this line:

Most of the messages received from the data server will be handled by the provided code, with the exception of the “M”-vehicle model message. The “M” message contains one or more VehicleModel objects represented according to the data structures given in Table 1, where each VehicleModel has a vector of shapes. You will need to process each model object to instantiate the remote vehicles correctly, and in each model object, you will need to process the shape information. The relevant section of code can be found in the main() function in the file main.cpp near this line:

You should replace “MyVehicle” with the name of your custom vehicle class and uncomment the line of code. This will enable remote vehicles to be added to the map of other vehicles to be drawn and updated.

As can be seen, the information here is not any different to the information you used to draw the local vehicle. Hence, you can use the parts of software you used to draw the local vehicle to draw these remote vehicles in an identical manner provided you match up the data received from the data server to your own vehicle data representation. As soon as you have drawn your remote vehicles, they will begin to move according to the state data streaming from the data server. The part that moves the remote vehicles has already been completed for you and you therefore do not have to do this part. However, on connection you will need to tell the remote server what your vehicle looks like. The functionality to package and send the data has been provided by the RemoteDataManager networking software. You need to provide the code to fill in the outgoing data structure, given in Table 1. If the data you provide is beyond nominal range, the server may respond with an error message and terminate your connection.

Assessment for Part 2

Demonstrate your ability to draw moving vehicles before the end of your tutorial in week 8.

  • Instantiate local/remote vehicles extended from Vehicle class.
  • Vehicles should have wheels that roll when driving forward/backward.
  • Vehicles should have front wheels that steer when steering.
  • Implement code in your graphical application to receive data server message “M” and display one or more vehicles accordingly with the correct shapes.
  • Implement code in your graphical application to report your local vehicle status to the server.

In-class Assessment Part 3: Final Demo

This part requires preparation before you come to the assessment. Learn to draw vehicles of arbitrary shape from a diagram. As good preparation, you could implement some prefabricated vehicle parts to make constructing vehicle models quicker. For example, a “Wheel” class could be created that contains a cylinder wheel with either cylindrical or prism based spokes for the wheels to tell they are turning when the vehicle is in motion.

6.1 Assessment for Part 3

During the week 9 tutorial, you will be asked to draw a vehicle of specified dimensions, given in the format as shown in Appendix A. You will be given 30 minutes to implement this vehicle using only the lab computers. You will have incorporated all other functionality required before arriving at the assessment. As such when you connect to the data server, we should see the remote vehicles on the screen and they should begin to move automatically. After such time your demonstrator will check the model you created to see if it appears to be correct to specification and any moving parts properly animate under vehicle motion. Your demonstrator will also check the reporting of your local vehicle status to the data server. You will then be asked to demonstrate your program by driving your vehicle around on the screen using an XBox controller.
Marking criteria

  • Making the program compile and be fully operational on the day of assessment.
  • Whether the model looks and animates correctly.
  • The vehicle motion is demonstrated using an XBox 360 game controller.
  • Whether the live feed of data from the data server is correctly read and used.
  • Whether the local vehicle’s status is correctly reported to the data server.
  • If you are up for a challenge, demonstrate to your tutor how you could give chase to vehicle with vehicle ID 1, when you press ‘L’. You will get an additional 1 course mark if successful.