C++ // See attach for more details
Starting with the code completed for Week 3, do the following:
 Implement Matrix2D.cpp corresponding to the Matrix2D.h given as a handout.
 Add to Triangle2D, two methods
 void operator *= ( const Matrix2D& matrix ) ;
 which transforms the vertices of the triangle using Matrix * Vector
 Vector2D Centroid() ;
 computes the point that is the centroid (center) of the object by adding the three vertices and multiplying by 1/3. In other words, the centroid of a triangle is the average of its three vertices: (v1+v2+v3)/3
 void operator *= ( const Matrix2D& matrix ) ;
 Animate a Triangle2D
In the constructor for MathGame (in GSP221.cpp): Create a scaling matrix with a uniform scale factor (e.g. of 1.01).
 Create a rotation matrix with an angle of rotation of, for example, 2 degrees.
 Compute the centroid of a triangle and save it
In Update_Model.  Use the centroid to translate the triangle to the origin.
 create a composite matrix from the scaling and rotation matrices and use it to transform the triangle.
 Translate the triangle by the centroid back to its original position.
 After some number of frames (e.g. 50), invert the scaling matrix.
Deliverables 
 You will need the Week 2 iLab file with its solution. See the Week 2 iLab page.
 Download the two header files and the .cpp file from the Week 5 iLab 4 Handout zip folder.
 Note: Martix2D.h and Matrix2D.cpp go in the Math project.
Triangle2D.h goes in the Geometry project.
i L A B S T E P S 
STEP 1: Add to Triangle2D.cpp two methods 
Add the following two methods at the end of Triangle2D.cpp:
Vector2D Triangle2D:: Centroid() } void Triangle2D:: operator *= ( const Matrix2D& matrix ) } 
STEP 2: Modify MathGame (in GSP221.cpp) 
In GSP221.cpp add the following code:
class MathGame : public GameFramework
{
private:Appearance solid_red ;

Triangle2D triangle ;

Matrix2D rotation, scaling ;
Vector2D centroid ;
Then add this code:
public:
MathGame()
{
triangle = Triangle2D( Vector2D( 200, 200 ), Vector2D( 300, 200 ),
Vector2D( 300, 300 ) ) ;
solid_red = Appearance( Color( 1, 0, 0 ), true ) ;

Write the one line of code here that turns matrix scaling into one that scales uniformly by a factor of 1.01.
Write the one line of code here that turns matrix rotation into one that rotates counterclockwise 2 degrees.
Write the one line of code here that computes the centroid of triangle and saves it into vector centroid.
}

void Update_Model()
{ Write the one line of code here that will translate triangle by –(centroid)
This will cause the triangle to have its centroid at the origin.Write the one line of code here that will scale uniformly and then rotate
triangle.
triangle *= ...Write the one line of code here that will translate triangle by centroid.
This will cause the triangle to have its centroid back where it was.if ( frames % 50 == 0 )
Write the one line of code that will invert (i.e. turns it into its inverse) the scaling matrix. For example, inverting a scaling matrix that scales uniformly by a factor of 2 will cause it to scale by a factor of 1/2. See Matrix2D.h information on the Invert() method. The net effect is that it will invert the scaling matrix every 50 frames.
Put the rest of this code into GSP221.cpp:
}
void Render_Model()
{
triangle.Render( &solid_red ) ;
}
} ;int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd )
{
Matrix2D matrix ;
matrix.Scaling( Vector2D( 2,3 ) ) ;
matrix.Rotate( 45 ) ;
Matrix2D inverse = matrix.Inverse() ;
Matrix2D identity = matrix * inverse ;MathGame game ;
game.Open_Window( hInstance, "GSP 221 Project", 0, 0, 500, 500, 255, 255, 255 ) ;
game.Run() ;
}
In Vector2D.cpp in the Math project. Replace the negative overloaded operator (right below the Normalize() method) :
void
Vector2D::operator  ( void ){
for
( int i = 0 ; i < dimension ; i++ )v[i] *= Scalar( 1.0 ) ;
}
by this:
Vector2D Vector2D::operator  ( void ) const
{
Vector2D result = *this ;
for
( int i = 0 ; i < dimension ; i++ )result.v[i] *= Scalar( 1.0 ) ;
return result ;
}
The output should look like this. It is a triangle that
rotates counterclockwise about its centroid and scales the triangle as
it does so. It will alternate between getting bigger and getting smaller
as it rotates. More specifically, every 50 frames it will get bigger,
then it will get smaller for 50 frames. Then it will get bigger for 50
frames, and so on.
See attach for more details