It is currently Mon Dec 18, 2017 7:49 am

All times are UTC - 5 hours




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: Physics VMK 10 - Tuning Space Ship
PostPosted: Thu Oct 02, 2008 7:38 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Three things are modified in this video to make the space ship fly better.
* Angle of space ship is limited to be between +/- 360 degrees
* Space ship is constrained to always be in the confinds of the window
* Limit the maximum speed of the ship

Note: When I was describing the damping that you can apply to the ship's motion when it hits a wall, I incorrectly showed how to implement this. When a collision occures you should change both the x and y component by your damping factor. In other words when there is a collision, take the new calculated velocity and multiply it by your damping factor, rather than multiplying just the one component of the velocity.


Offline
 Profile  
 
 Post subject:
PostPosted: Thu Feb 11, 2010 5:24 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
If you have not purchased the OpenGL Game Engine Development DVDor the VC++ 2005 Game Engine Source Code from the store then you will be missing a few functions in the Vector2 and Vector3 classes when you get to this point. I've included these functions below.


Put this inside your Vector3.h
 
//------------------------------------------------------------------------
// Name: operator*=(:)
// Desc: multiply this vector by a scalar value: ie  Vector3*fValue
//
inline Vector3& Vector3::operator*=(const float &fValue) {
   m_fX *= fValue;
   m_fY *= fValue;
   m_fZ *= fValue;

   return *this;
} //operator*=

//------------------------------------------------------------------------
// Name: operator/=(:)
// Desc: divide this vector by a scalar value: ie  Vector3/fValue
//
inline Vector3& Vector3::operator/=(const float &fValue) {
   if (Math::isZero(fValue)) {
      m_fX = 0;   
      m_fY = 0;
      m_fZ = 0;
   }
   else {
      float fValue_Inv = 1/fValue;
      m_fX *= fValue_Inv;
      m_fY *= fValue_Inv;
      m_fZ *= fValue_Inv;
   }

   return *this;
} //operator/=

//------------------------------------------------------------------------
// Name: Zero(:)
// Desc: Set value to (0,0,0)
//
inline void Vector3::Zero() {
   m_fX = 0;
   m_fY = 0;
   m_fZ = 0;
} //Zero

//------------------------------------------------------------------------
// Name: Length2(:)
// Desc: Return the length squared of this vector
//
inline float Vector3::Length2() const {
   return (m_fX * m_fX +
         m_fY * m_fY +
         m_fZ * m_fZ);
} //Length2


Put this inside your Vector2.h
 
//------------------------------------------------------------------------
// Name: operator*=(:)
// Desc: multiply this vector by a scalar value: ie  Vector2*fValue
//
inline Vector2& Vector2::operator*=(const float &fValue) {
   m_fX *= fValue;
   m_fY *= fValue;

   return *this;
} //operator*=


//------------------------------------------------------------------------
// Name: operator/=(:)
// Desc: divide this vector by a scalar value: ie  Vector2/fValue
//
inline Vector2& Vector2::operator/=(const float &fValue) {
   if (Math::isZero(fValue)) {
      m_fX = 0;   
      m_fY = 0;
   }
   else {
      float fValue_Inv = 1/fValue;
      m_fX *= fValue_Inv;
      m_fY *= fValue_Inv;
   }

   return *this;
} //operator/=

//------------------------------------------------------------------------
// Name: Zero(:)
// Desc: Set value to (0,0)
//
inline void Vector2::Zero() {
   m_fX = 0;
   m_fY = 0;
} //Zero

//------------------------------------------------------------------------
// Name: Length2(:)
// Desc: Return the length squared of this vector
//
inline float Vector2::Length2() const {
   return (m_fX * m_fX +
         m_fY * m_fY);
} //Length2


Offline
 Profile  
 
 Post subject: Thank You!
PostPosted: Thu Feb 11, 2010 6:22 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
Yeah, Thank You for the code, and every thing works well so far, if I am missing anything else Ill either post it here or send you an email.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron