GSP221 GSP 221 GSP/221 - Week 2 - Lab 2 - iLab 2 - Grade A+ !
    GSP221 GSP 221 GSP/221 - Week 2 - Lab 2 - iLab 2 - Grade A+ !

GSP221 GSP 221 GSP/221 - Week 2 - Lab 2 - iLab 2 - Grade A+ !

$19.99

Using Vectors is essential to our games, as it can represent both the vertices of polygons and many physical aspects of our objects (e.g. velocity, acceleration etc…), in N number of dimensions.

In this Lab, we will be creating two C++ Vector class: Vector2D for vectors in 2D space and Vector3D for vectors in 3D space. These will provide all the vector operations required in this and subsequent courses. The classes exploit operator-overloading to all creation of vector expressions, such as v3 = v1 + v2.

Some vector operations that we should be able to do for a given vector include: Length, Normalization.

We will need to be able to do the following calculations between vectors, such as Vector Addition and Subtraction, the Dot Product, the Cross Product, and the calculation of the angle between two vectors via either the Cross or Dot Product.

It uses Visual Studio and any release of DirectX 9. You can find this software through the iLab Environment or feel free to use versions of this software on your computer.

Deliverables

  1. Download here the GSP221 Week 2 iLab  Zip files to complete the iLab assignment
  2. Write the necessary implementation files (.cpp files) to the corresponding header files (.h files), that implements the needed functionality.
  3. Package your .cpp files in a Zip File. Use the following naming convention for your Zip file:
    GSP221_LastnameFirstInitial_ Week2_Lab.zip
  4. Submit the Zip file to the Dropbox for the Week 2 Lab Activity.
  5. It uses Visual Studio and any release of DirectX 9. You can find this software through the iLab Environment or feel free to use versions of this software on your computer.

Submit your lab to the Dropbox located on the silver tab at the top of this page. For instructions on how to use theDropbox, read these Step-by-Step Instructions or watch this Dropbox Tutorial.

See Syllabus/"Due Dates for Assignments & Exams" for due dates.

 

i L A B  S T E P S

 

STEP 1: Make the Initial Parts of Vector2D.cpp

 

In Vector2D.cpp include Vector2d.h.

Here are the three possible constructors:

Vector2D:: Vector2D()
{
         for ( inti = 0 ; i< dimension ; i++ ) v[i] = 0.0f ;
}

Vector2D:: Vector2D( const Vector2D& other )
{
         *this = other ;
}

Vector2D:: Vector2D( double x, double y )
{
         v[X] = Scalar( x ) ;
         v[Y] = Scalar( y ) ;
}

element codes:
Vector2D:: Vector2D( Scalar element[2] )
{
         for (inti = 0 ; i< dimension ; i++ )
                  v[i] = element[i] ;
}

Scalar& Vector2D::operator []( int index )
{
         return v[index] ;
}

Scalar Vector2D::operator [](int index ) const
{
         return v[index] ;
}

 

STEP 2:Make the Length method

 

Scalar Vector2D::Length()
{
         Scalar lengthSquared = 0.0 ; <--initialization

write a for loop that computes length squared
         return Math:: <--then fill-in the blank here that returns the length using sqrt
}

 

STEP 3: Make the Normalize method

 

voidVector2D::Normalize()
{
         Scalar length = Length() ;
         if ( length > epsilon ) // do not divide is length is really small
                  make a for loop that normalizes v by dividing each component of v by the appropriate scalar.
}

 

STEP 4: Make Overloaded Operators

 

This multiplies each component by a negative 1:

void Vector2D::operator - ( void )
{
         for ( inti = 0 ; i< dimension ; i++ )
                  v[i] *= Scalar( -1.0 ) ;
}

This multiplies each component by scalar:
void Vector2D::operator *= ( Scalar scalar )
{
         for ( inti = 0 ; i< dimension ; i++ )
                  v[i] *= scalar ;
}

 

This divides each component by scalar:
void Vector2D::operator /= ( Scalar scalar )
{
         Write the proper for loop here.
}

For the case when the operand order is vector * scalar:
Vector2D Vector2D::operator * ( Scalar scalar ) const
{
         Vector2D result;

         Write the proper for loop here.

          return result ;
}

// friend
For the case when the input is in component form (scalar , vector)

Vector2D operator * ( Scalar scalar, Vector2D& vector )
{
         Vector2D result ;

         Write the proper for loop here.

         return result ;
}

Here is the addition += operator, v += other :
void Vector2D::operator += ( Vector2D& other )
{
         Write the for loop here.
}

Here is the subtraction -= operator:
void Vector2D::operator -= ( Vector2D& other )
{
         Write the for loop here.
}

 

Here is the addition + operator, v= v + other :
Vector2D Vector2D::operator + ( Vector2D& other ) const
{
         Vector2D result ;

         Write the for loop here using result=v + other
          return result ;

}

Here is the subtraction - operator, v= v - other :
Vector2D Vector2D::operator - ( Vector2D& other ) const
{
         Vector2D result ;

         Write the for loop here.

          return result ;
}

Here is the dot product operator, v * other :
Scalar Vector2D::operator * ( Vector2D& other ) const
{
         Scalar dot_product = 0.0 ;

         Write the for loop here.

         returndot_product ;
}

Here is the Boolean equality operator:
bool Vector2D:: operator == ( const Vector2D& other ) const
{
         bool result = true ;

         for ( inti = 0 ; i< dimension ; i++ )
         result &= v[i] == other.v[i] ;
         return result ;
}

Here is the negation operator:
bool Vector2D:: operator != ( constVector2D& other ) const
{
         return ! (*this == other) ;
}

          Construct a 2D vector that is orthogonal (perpendicular) to the given vector:
Vector2D Vector2D:: Orthogonal() const
{
         Vector2D result ;

         result.v[X] = write the proper code here ;
         result.v[Y] = write the proper code here ;

         return result ;
}

Use this to test whether or not a vector == zero vector.
It returns a reference to a constant static vector full of 0's.
const Vector2D& Vector2D:: Zero_Vector()
{
         static Vector2D zero_vector ;

         return zero_vector ;
}

 

STEP 5: Make Vector3D.cpp

 

Do a find/replace of “2D” with “3D” in. Change the class constant “dimension” from 2 to 3. Change any of the constructors that depend on the dimension to accommodate 3D. Replace Orthogonal() with Cross_Product( const Vector3D& )

For the cross product v X other:

Vector3D Vector3D::Cross_Product( const Vector3D& other ) const
{
Vector3D result ;

         result.v[X] = Write the proper code here.
         result.v[Y] = Write the proper code here.
         result.v[Z] = Write the proper code here.

         return result ;
}

For the rest of the methods, imitate the work done for Vector2D to do Vector3D.

 

 

Here is solution for GSP221 - Week 2

It is 100% correct.

Solution contain Visual Studio C++ project

If you have more questions, please contact me via email support@extutorials.com

I will help you any time

Thank you very much

Attached Files

Move over [ preview ] file name to preview content in it!

Write a review

Your Name:


Your Review: Note: HTML is not translated!

Rating: Bad           Good

Enter the code in the box below:



PURCHASE SAVE
2 Tutorials 10%
3 Tutorials 13%
4 Tutorials 16%
5 Tutorials 19%
6 Tutorials 22%
7 Tutorials 25%
8 Tutorials 28%
9 Tutorials 31%
10 Tutorials 34%
add url more

9MZQASHWN73B