 |
 |
Member Community Game Development, 3D Modeling, Art, Sound Effects and more
|
 |
 |
 |
 |
|
 |
 |
 |
 |
 |
Marek Site Admin

Joined: 11 Feb 2007 Posts: 515 Location: Ontario Canada  |
Posted: Thu Oct 02, 2008 7:38 am Post subject: Physics VMK 10 - Tuning Space Ship |
 |
|
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. |
|
| |
|
|
|
 |
 |
 |
 |
 |
Marek Site Admin

Joined: 11 Feb 2007 Posts: 515 Location: Ontario Canada  |
Posted: Thu Feb 11, 2010 5:24 pm Post subject: |
 |
|
If you have not purchased the OpenGL Game Engine Development DVD or 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
| Code: |
//------------------------------------------------------------------------
// 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
| Code: |
//------------------------------------------------------------------------
// 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
|
|
|
| |
|
|
|
 |
 |
 |
 |
 |
skilz80

Joined: 16 Aug 2008 Posts: 58
 |
Posted: Thu Feb 11, 2010 6:22 pm Post subject: Thank You! |
 |
|
| 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. |
|
| |
|
|
|
 |
 |
 |
 |
 |
|
 |
 |
 |
 |
|
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 You cannot vote in polls in this forum
|
|
|
 |