Gsp221 Gsp 221 Gsp/221 - Week 3 - Lab 3 - iLab 3 - Grade A+ !!!
    Gsp221 Gsp 221 Gsp/221 - Week 3 - Lab 3 - iLab 3 - Grade A+ !!!

Gsp221 Gsp 221 Gsp/221 - Week 3 - Lab 3 - iLab 3 - Grade A+ !!!

$19.99

 

i L A B  O V E R V I E W

 

Scenario/Summary

The first Lab taught us how to construct, translate, and render an object as a set of points. In the second Lab, we were introduced to how vector math is done in C++, with just a general reference to game objects.

In this third Lab, we finally put both concepts together, where we represent our object’s vertices through vectors and then use the vector math we learned in Lab 2, control the position, velocity, and acceleration of our game objects. The concepts of position, velocity, and acceleration are studies under the branch of physics termed kinematics.

You will create a 2D triangle in which the vertices are represented by vectors that can be translated using vector addition. You will then simulate the triangle moving under the influence of acceleration and then stopping when it collides with a vertical wall. You can simulate gravity with a constant acceleration in the –y direction (of -9.8 m/s if you want to use meters as your units). To detect the moment of collision, you will implement a parametric ray that intersects with a line.

Using Visual Studio and your code from Week 2, do the following:

  • Place the attached Triangle2D.h file in the Geometry project (see below for the Handout link). This creates a Triangle2D class similar to Triangle3D, except one replaces Point3D with Vector2D for the representation of the vertices. This includes a constructor that takes three Vector2D to define a triangle. This also has a Translate( Vector2D T ) method, and implements it using vector addition (it does not access the individual coordinates).
  • Implement the .cpp file for Physics.h in the Handout and use it for this lab. The only method that does anything interesting is dX() method, which computes the next position of the triangle using the current acceleration and the effect of gravity.
  • Implement Linear.cpp for Linear.h. This provides a Ray2D class and a Line2D. Use these for collision detection between a Triangle2D and a vertical wall near the right hand board of the window. Use a ray to provide a geometric representation of the motion of the triangle. In particular, define the ray.origin as the physics.Position() and ray.direction as physics.Velocity(). Compute the intersection between this ray and the line representing the wall. RayIntersect.t should be the time it will take for the triangle to reach the wall if it were traveling in a straight line; that is, if there is no gravity. When this t is < threshold, where threshold is a constant you choose, stop translating the triangle.

The equation for a ray can be written as P = O+Dt, where O is the origin of the ray, D is the direction, t is a parameter that can take any value, and P is the resulting point for a given value of t.

Two components of the object named ray: origin and direction:

Suppose one is given any fixed point P0 on a line and a vector N perpendicular to the line. The equation of the line can be written as:

N dot ( P – P0 ) = 0
P is another point on the line.

Three components of the object named line: point, normal and direction:
Setting the P in each equation equal to each other and solving the simultaneous equations give the intersection point. With this notation, the intersection of the ray with the line is:

t = (n dot P0 - N dot O) / ( N dot D )

Use this t in the ray equation O+D*t to produce the actual intersection point, if needed. In this lab, only the t value is needed, since it represents the time until impact.

Deliverables

  1. See the Week 3 Lecture to understand the physics equations.
  2. You will need the Week 2 iLab file. See the Week 2 iLab page if you do not have it.
  3. Download the three header files from the Week 3 iLab Handout zip folder.
  4. Note: Physics.h, Physics.cpp, Linear.h, and Linear.cpp go in the Math project.
    Triangle2D.h goes in the Geometry project.
  5. Package your .cpp files in a zip file. Use the following naming convention for your zip file:
    GSP221_LastnameFirstInitial_ Week3_Lab.zip.
  6. Submit the zip file to the Dropbox for the Week 3 Lab Activity.

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: Do the Physics.cpp File

 

Write this code to begin making Physics.cpp:

#include "Physics.h"

const floatgravitational_accleration = -9.8f ;

Physics::Physics(void)
{
         gravity = Vector2D( 0.0f, gravitational_accleration ) ;
}

Physics::~Physics(void)
{
}

void Physics::Set_Position( Vector2D position )
{
         this->position = position ;
}

void Physics::Set_Velocity( Vector2D velocity )
{
         this->velocity = velocity ;
}

void Physics::Set_Acceleration( Vector2D acceleration )
{
         this->acceleration = acceleration ;
}

Vector2D Physics::Gravity()
{
         return gravity ;
}

Scalar Physics::Speed()
{
         returnvelocity.Length() ;
}

Vector2D Physics::Position()
{
         return position ;
}

Vector2D Physics::Velocity()
{
          return velocity ;
}

Vector2D Physics::Acceleration()
{
         return acceleration ;
}

 

The main part of the code is here:
Vector2D Physics::dX( doubledt )
{

Vector2D dX ;
Scalar delta_t = (Scalar) dt ;
Vector2D initial_velocity = velocity ;

Then
(i)
Update velocity
(ii)
Use the updated velocity and initial velocity to find dx
(ii)
Use dx to update position.

 

returndX ;
}

 

STEP 2: Do the Linear.cpp File

 

This step will essentially reduce the student to figuring out two lines of code, explained below. The rest will be copying and pasting. The two lines of code are based on the formula for t up above.

Write down this code:

#include"Linear.h"

void Ray2D::Init()
{
         tmin = 0.0 ;
         tmax = Scalar( Math::_HUGE ) ;
}

Ray2D::Ray2D()
{
         Init() ;
}

Ray2D:: Ray2D( Vector2D origin, Vector2D direction )
{
         Init() ;
         this->origin = origin ;
         this->direction = direction ;
}

/**** Line ****/

Line::Line( Vector2D point, Vector2D normal )
{
         this->point = point ;
         this->normal = normal ;
         this->normal.Normalize() ;
}

Scalar Line::Distance( Vector2D point )
{
         return normal * ( point - this->point ) ;
}

/**** Intersection ****/

RayIntersectLineRay_Intersect_Line( Ray2D ray, Line line )
{
         RayIntersectLine result ;
         double numerator, denominator ;

numerator = Write the line of code for the numerator. Remember, * means dot product
denominator = Write the line of code for the denominator

Hint: line.normal is the vector normal to line. Here are the type declarations for ray and line:
Ray2D ray;
Line line;
You do not have to type these declarations anywhere, but this is just to give you an idea of their types.
Consider: point, origin, normal and direction.
See the pictures above of ray and line for their various components.

 

Here is the rest of the code. This first tests whether the numerator or denominator is small. Then it returns the value of t, among other things.
if ( Within_Epsilon( denominator ) )
         {
                  if ( Within_Epsilon( numerator ) )\
                  {
                                    result.type = RayIntersectLine::Coincident ;
                                    result.t = 0.0 ;
                  }
                  else
                  {
                                    result.type = RayIntersectLine::Parallel ;
                                    result.t = Scalar( Math::_HUGE ) ;
                  }
         }
         else
         {
                              result.t = Scalar( numerator / denominator ) ;
                              result.normal = line.normal ;
                              result.type = RayIntersectLine::Intersect ;
         }

         return result ;
}

The final result will be the triangle and the sphere moving:

The triangle will stop upon hitting an imaginary vertical line on the right-hand side of the screen. The sphere will continue to move until it leaves the window screen:
Now that you have completed the above steps, please do not forget to add the appropriate code to GSP221.cpp to complete the lab. 

 

Here is solution for GSP221 - Week 3

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