It is currently Wed Nov 22, 2017 9:08 pm

All times are UTC - 5 hours




 Page 1 of 1 [ 7 posts ] 
Author Message
 Post subject: Ghost VMK 41 - Switching Weapons
PostPosted: Mon Dec 21, 2009 6:37 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
VMK 41A: The Interpolate3 class is created in this VMK and used to allow the player to switch between the Mace and the Crossbow weapon. You will be able to switch weapons using the keyboard or using the scroll wheel on the mouse.

VMK 41B: Weapon Class. The WeaponCrossbow and WeaponMace classes are simplified by inheriting from a general Weapon class created in this VMK.


Offline
 Profile  
 
 Post subject: About Template Classes For Interpolations
PostPosted: Sat Feb 27, 2010 12:53 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
Ok I tried to take your advice on cleaning up some code with the Interpolate1 and Interpolate 3 classes, by bringing both classes into one class using templates. Templates are one area in c++ that I find interesting and powerful if knowing how to use them correctly. I completely understand what templates are and some of their many uses, though I struggle with there complicated syntax and have trouble with them. If I am just trying to template a function that does the same operation with different in and out params, that isn't too hard, but when I try to make an entire class as a template, then it starts to get tough.

I got each file in my source code to compile individually, but I can not get the program to build as a whole. This is what I have done with the Interpolate class.

================ InterpolateT.h ====================
#ifndef INTERPOLATET_H
#define INTERPOLATET_H

// =========================================== //
// FileName: InterpolateT.h
// Version: 1.0
// Copyright (c) 2010 by Marek A. Krzeminski
// www.marek-knows.com
// =========================================== //

// Includes
#include "stdafx.h"
#include "GameOGL.h"

template<typename T>
class InterpolateT
{
public:
   // Constructor And Destructor
   
   InterpolateT( T Start, T Stop, float fDuration, bool bSmooth = true );
   ~InterpolateT();

   // Public Member Functions
   void   Reset( T Start, T Stop, float fDuration = -1.0f, bool bSmooth = true );
   void   Reverse( float fDuration = -1.0f );

   T   GetValue();
   T   GetValue( const float fBlendFactor );

   inline bool IsDone();
   inline void Evaluate();

protected:

private:
   // Private Member Variables
   T      m_Start;
   T      m_Stop;
   float   m_fTime;
   float   m_fDurationInv;
   bool   m_bSmooth;

   T       m_Value;
   T      m_ValuePrev;

};

// ------------------------------------------------------------------------------ //
// Name: IsDone()
// Desc: Returns True If Reached Stop
// ------------------------------------------------------------------------------ //
template<class T>
inline bool InterpolateT<T>::IsDone()
{
   return ( m_fTime >= 1.0f );

} // IsDone

// ------------------------------------------------------------------------------ //
// Name: Evaluate()
// Desc: Time Value Will Range From 0 To 1, Evaluated At Physics Refresh Rate
// ------------------------------------------------------------------------------ //
template<class T>
inline void InterpolateT<T>::Evaluate()
{
   // Store Previous Value
   m_ValuePrev = m_Value;

   if ( IsDone() )
   {
      m_Value = m_Stop;
   }
   else
   {
      m_fTime += GameOGL::GetPhysicsTimeStep() * m_fDurationInv;

      if ( m_fTime >= 1.0f )
      {
         // Reached The End, Set Stop Value To Final Value So That We Don't
         // Have To Calculate It Every Time Evaluate Is Called Again
         m_Stop += m_Start;
         m_Value = m_Stop;
      }
      else
      {
         if ( m_bSmooth )
         {
            // Smooth Interpolation
            m_Value = ( m_Start + (m_Stop * m_fTime * m_fTime * (3.0f - 2.0f * m_fTime)));
         }
         else
         {
            // Linear Interpolation
            m_Value = ( m_Start + m_Stop * m_fTime );
         }
      }
   }
} // Evaluate

#endif // INTERPOLATET_H


================= InterpolateT.cpp ==================
// =========================================== // 
// FileName: InterpolateT.cpp
// Version: 1.0
// Copyright (c) 2010 by Marek A. Krzeminski
// www.marek-knows.com
// =========================================== //
// Includes
#include "InterpolateT.h"

// ----------------------------------------------------------------------------- //
// Name: InterpolateT()
// Desc: Default Constructor
// ----------------------------------------------------------------------------- //
template<class T>
InterpolateT<T>::InterpolateT( T Start, T Stop, float fDuration, bool bSmooth )
{
   m_fDurationInv = 1.0f;
   Reset( Start, Stop, fDuration, bSmooth );

} // InterpolateT

// ----------------------------------------------------------------------------- //
// Name: ~InterpolateT
// Desc: Default Destructor
// ----------------------------------------------------------------------------- //
template<class T>
InterpolateT<T>::~InterpolateT()
{
} // ~InterpolateT

// ----------------------------------------------------------------------------- //
// Name: Reset()
// Desc: Set And Reset All Values
// ----------------------------------------------------------------------------- //
template<class T>
void InterpolateT<T>::Reset( T Start, T Stop, float fDuration, bool bSmooth )
{
   m_Start      = Start;
   m_Stop      = Stop - Start;
   m_bSmooth   = bSmooth;
   m_fTime      = 0.0f;

   if ( fDuration > 0 )
   {
      // Change Duration Value
      m_fDurationInv = 1.0f / fDuration;
   }

   m_ValuePrev = Start;
   m_Value    = Start;

} // Reset

// ------------------------------------------------------------------------------ //
// Name: Reverse()
// Desc: Cause Interpolation To Go From Stop To Start
// ------------------------------------------------------------------------------ //
template<class T>
void InterpolateT<T>::Reverse( float fDuration )
{
   // Switch Direction
   if ( IsDone() )
   {
      Reset( m_Stop, m_Start, fDuration, m_bSmooth );
   }
   else
   {
      Reset( m_Stop + m_Start, m_Start, fDuration, m_bSmooth );
   }

} // Reverse

// ------------------------------------------------------------------------------ //
// Name: GetValue()
// Desc: Returns The Current Value. No Blending Used
// ------------------------------------------------------------------------------ // 
template<class T>
T InterpolateT<T>::GetValue()
{
   return m_Value;

} // GetValue

// ------------------------------------------------------------------------------ //
// Name: GetValue()
// Desc: Returns A Value Based On Blending Factor
// ------------------------------------------------------------------------------ //
template<class T>
T InterpolateT<T>::GetValue( const float fBlendFactor )
{
   // Linear Interpolation
   return ( (m_Value-m_ValuePrev)*fBlendFactor + m_ValuePrev );

} // GetValue


Here I use T at the end for two reasons one for knowing that this class is of a template type, and two that it doesn't interfer with the functions that are named Interpolate() with in other classes such as the ghost and scene class. This is the situation I am having now.

When I try to build this program this is what I am receiving from the Output window...


===================================== Errors ======================================
4>ObjectLib_Debug.lib(Ghost.obj) : error LNK2019: unresolved external symbol "public: __thiscall InterpolateT<float>::~InterpolateT<float>(void)" (??1?$InterpolateT@M@@QAE@XZ) referenced in function __unwindfunclet$??0Ghost@@QAE@PAVNodeTransform@@@Z$0
4>ObjectLib_Debug.lib(Ghost.obj) : error LNK2019: unresolved external symbol "public: __thiscall InterpolateT<float>::InterpolateT<float>(float,float,float,bool)" (??0?$InterpolateT@M@@QAE@MMM_N@Z) referenced in function "public: __thiscall Ghost::Ghost(class NodeTransform *)" (??0Ghost@@QAE@PAVNodeTransform@@@Z)
4>ObjectLib_Debug.lib(Ghost.obj) : error LNK2019: unresolved external symbol "public: float __thiscall InterpolateT<float>::GetValue(void)" (?GetValue@?$InterpolateT@M@@QAEMXZ) referenced in function "public: void __thiscall Ghost::Interpolate(float)" (?Interpolate@Ghost@@QAEXM@Z)
4>ObjectLib_Debug.lib(Ghost.obj) : error LNK2019: unresolved external symbol "public: void __thiscall InterpolateT<float>::Reverse(float)" (?Reverse@?$InterpolateT@M@@QAEXM@Z) referenced in function "public: void __thiscall Ghost::Interpolate(float)" (?Interpolate@Ghost@@QAEXM@Z)
4>ObjectLib_Debug.lib(Ghost.obj) : error LNK2019: unresolved external symbol "public: float __thiscall InterpolateT<float>::GetValue(float)" (?GetValue@?$InterpolateT@M@@QAEMM@Z) referenced in function "public: void __thiscall Ghost::Interpolate(float)" (?Interpolate@Ghost@@QAEXM@Z)
4>./_Build/Ghost_Debug.exe : fatal error LNK1120: 5 unresolved externals
4>Build log was saved at "file://c:\Users\skilz80\Documents\Visual Studio 2008\Projects\Ghost Toast\_Debug\BuildLog.htm"
4>GameEngine - 6 error(s), 0 warning(s)

================================== End Errors ======================================

From the looks of it the compiler doesn't know what to do. Am I instantiating this class correctly ? I know I am close or on track. I would like to be able to encapsulate both Interpolate functions into the one template class / class template. I forget which one is which with the naming convention. lol This is how my code is setup in Ghost.h where we set member variables of this class as Interpolate objects and define them in the constructor using the colon operator.

================= Ghost.h =======================
#ifndef GHOST_H
#define GHOST_H

// =========================================== //
// FileName: Ghost.h
// Version: 1.0
// Copyright (c) 2010 by Marek A. Krzeminski
// www.marek-knows.com
// =========================================== //

// Includes
#include "Vector3.h"
#include "InterpolateT.h"

class NodeTransform;
class Light;

class Ghost
{
public:
   // Constructor And Destructor
   Ghost( NodeTransform *pNT_Root );
   ~Ghost();

   // Public Member Functions
   void      AttachLight( Light *pLight );

   bool      IsValid();
   bool      IsVisible();
   bool      IsAlive();
   int         Kill();
   int         ArrowHit( Vector3 &v3ArrowPosition, Vector3 &v3PlayerPosition );

   void      SetPosition( Vector3 v3Position );
   Vector3      GetPosition();
   void      Update( Vector3 v3PlayerPosition );
   void      Interpolate( const float fBlendFactor );

protected:

private:
   enum State
   {
      FLYING = 0,
      FOLLOWING,
      DYING,
      DEAD,
   };

   // Private Member Variables
   State m_state;

   NodeTransform *m_pNT_Root;
   NodeTransform *m_pNT_Jaw;
   
   Light *m_pLight;

   // Ghost's Position And Direction
   Vector3      m_v3Position;
   Vector3      m_v3FaceDirection;

   // Random Floating Motion
   InterpolateT<float>  m_floatX;
   InterpolateT<float>  m_floatY;
   InterpolateT<float>  m_floatZ;

   // Jaw Control
   InterpolateT<float>  m_jawPosition;
   float       m_fJawPause;

   float       m_fTime2Appear;

};

#endif // GHOST_H


=================== Ghost.cpp ====================

// =========================================== //
// FileName: Ghost.cpp
// Version: 1.0
// Copyright (c) 2010 by Marek A. Krzeminski
// www.marek-knows.com
// =========================================== //

// Includes
#include "stdafx.h"
#include "Ghost.h"
#include "NodeTransform.h"
#include "Light.h"

// ------------------------------------------------------------------------------ //
// Name: Ghost()
// Desc: Default Constructor
// ------------------------------------------------------------------------------ //
Ghost::Ghost( NodeTransform *pNT_Root ) :
m_floatX( -0.02f, 0.02f, 1.0f ),
m_floatY(  0.15f, 0.30f, 1.0f ),
m_floatZ( -0.02f, 0.02f, 1.0f ),
m_jawPosition( -0.03f, 0.02f, 0.2f )
{
   m_state = FLYING;

   m_pNT_Root = pNT_Root;

   if ( pNT_Root == NULL )
   {
      // Error
      return;
   }
   
   // Transforms
   m_pNT_Jaw = (NodeTransform*)pNT_Root->FindNode( "jawBone" );
   
   m_pLight  = NULL;

   // Initial Position
   m_v3Position      = m_pNT_Root->m_v3Translate;
   m_v3FaceDirection   = Vector3( 0.0f, 0.0f, 1.0f );
   
   m_fJawPause = 0;

   m_fTime2Appear = 0;

} // Ghost

// ----------------------------------------------------------------------------- //
// Name: ~Ghost()
// Desc: Default Destructor
// ----------------------------------------------------------------------------- //
Ghost::~Ghost()
{
} // ~Ghost

// ----------------------------------------------------------------------------- //
// Name: AttachLight()
// Desc: Light Source Used By This Ghost
// ----------------------------------------------------------------------------- //
void Ghost::AttachLight( Light *pLight )
{
   m_pLight = pLight;

} // AttachLight

// ------------------------------------------------------------------------------ //
// Name: IsValid()
// Desc: Returns True If This Object Has A Valid Node Transform
// ------------------------------------------------------------------------------ //
bool Ghost::IsValid()
{
   ErrorHandler *pErrorHandler = ErrorHandler::Get();

   if ( m_pNT_Root == NULL )
   {
      pErrorHandler->SetError( ErrorHandler::EC_GAME_ERROR, "Ghost: Could not find root transform node." );
      pErrorHandler->ShowErrorMessage();
      pErrorHandler->SetError( ErrorHandler::EC_NOERROR, "No Error." );
      return false;
   }

   if ( m_pNT_Jaw == NULL )
   {
      pErrorHandler->SetError( ErrorHandler::EC_GAME_ERROR, "Ghost: Could not find jawBone transform node." );
      pErrorHandler->ShowErrorMessage();
      pErrorHandler->SetError( ErrorHandler::EC_NOERROR, "No Error." );
      return false;
   }

   if ( m_pLight == NULL )
   {
      pErrorHandler->SetError( ErrorHandler::EC_GAME_ERROR, "Ghost: Invalid light source." );
      pErrorHandler->ShowErrorMessage();
      pErrorHandler->SetError( ErrorHandler::EC_NOERROR, "No Error." );
      return false;
   }

   return true;

} // IsValid()

// ----------------------------------------------------------------------------- //
// Name: IsVisible()
// Desc: Returns True If This Object Is Not Hidden
// ----------------------------------------------------------------------------- //
bool Ghost::IsVisible()
{
   return m_pNT_Root->m_bVisible;

} // IsVisible

// ----------------------------------------------------------------------------- //
// Name: SetPosition()
// Desc: Set The Position Of The Ghost
// ----------------------------------------------------------------------------- //
void Ghost::SetPosition( Vector3 v3Position )
{
   m_pNT_Root->m_v3Translate = v3Position;
   m_v3Position            = v3Position;

} // SetPosition

// ----------------------------------------------------------------------------- //
// Name: GetPosition()
// Desc: Return The Ghost's Position
// ----------------------------------------------------------------------------- //
Vector3 Ghost::GetPosition()
{
   return m_pNT_Root->m_v3Translate;

} // GetPosition

// ------------------------------------------------------------------------------ //
// Name: IsAlive()
// Desc: Return If Ghost Is In An Alive State
// ------------------------------------------------------------------------------ //
bool Ghost::IsAlive()
{
   return ( (m_state != DYING) && (m_state != DEAD) );

} // IsAlive

// ------------------------------------------------------------------------------ //
// Name: Kill();
// Desc: This Ghost Has Been Killed, Return # Points Awarded
// ------------------------------------------------------------------------------ //
int Ghost::Kill()
{
   m_state = DYING;

   m_pLight->SetOn( false );

   return 5;

} // Kill

// ------------------------------------------------------------------------------ //
// Name: ArrowHit()
// Desc: If This Ghost Has Been Killed By An Arrow, Return # Points Awarded
// ------------------------------------------------------------------------------ //
int Ghost::ArrowHit( Vector3 &v3ArrowPosition, Vector3 &v3PlayerPosition )
{
   if ( !IsAlive() )
   {
      // Ghost Already Dead
      return 0;
   }

   // Test Collision Cylinder
   if ( v3ArrowPosition.m_fY > (m_pNT_Root->m_v3Translate.m_fY + 1.887f) )
   {
      // Arrow Is Above The Ghost
   }
   else if ( v3ArrowPosition.m_fY < (m_pNT_Root->m_v3Translate.m_fY + 0.829f) )
   {
      // Arrow Is Below The Ghost
   }
   else
   {
      // Get Center Location Of Cylinder
      Vector3 v3Center( 0.0f, 0.0f, -0.057f );
      float fAngleRad = Math::Degree2Radian( m_pNT_Root->m_fRotateAngle );
      v3Center = v3Center.RotateY( fAngleRad ) + m_pNT_Root->m_v3Translate;

      Vector3 v3Diff = v3Center - v3ArrowPosition;
      v3Diff.m_fY = 0;
      if ( v3Diff.Length2() > 0.08f ) // Radius = 0.272912 -> 0.07448
      {
         // Missed
         return 0;
      }

      // Possibly Hit, Check Each Sphere For Contact
      // Body Sphere r = 0.22
      v3Center = Vector3( 0.0f, 1.377f, 0.0f ) + m_pNT_Root->m_v3Translate;
      v3Diff   = v3Center - v3ArrowPosition;
      if ( v3Diff.Length2() <= 0.06f ) // 0.0484f
      {
         // Hit!
         Kill();

         // Distance From Ghost
         v3Diff = v3PlayerPosition - m_pNT_Root->m_v3Translate;
         v3Diff.m_fY = 0;

         // Points For Hitting Body
         return int (5 + v3Diff.Length() * 0.2); // 1/5
      }

      // Head Sphere r = 0.131
      v3Center = Vector3( 0.0f, 1.756f, 0.085f).RotateY( fAngleRad ) + m_pNT_Root->m_v3Translate;
      v3Diff   = v3Center - v3ArrowPosition;
      if ( v3Diff.Length2() <= 0.03f ) //0.0172f
      {
         // Hit!
         Kill();

         // Distance From Ghost
         v3Diff = v3PlayerPosition - m_pNT_Root->m_v3Translate;
         v3Diff.m_fY = 0;

         // Points For Hitting Body
         return int (5 + v3Diff.Length() * 0.6); // 3/5
      }

      // Pant Sphere r = 0.131
      v3Center = Vector3( 0.0f, 0.96f, -0.191f ).RotateY( fAngleRad ) + m_pNT_Root->m_v3Translate;
      v3Diff   = v3Center - v3ArrowPosition;
      if ( v3Diff.Length2() <= 0.03f ) // 0.0172f
      {
         // Hit!
         Kill();

         // Distance From Ghost
         v3Diff = v3PlayerPosition - m_pNT_Root->m_v3Translate;
         v3Diff.m_fY = 0;

         // Points For Hitting Body
         return int (5 + v3Diff.Length() * 0.4); // 2/5
      }
   }
   
   return 0;

} // ArrowHit


// ----------------------------------------------------------------------------- //
// Name: Udpate()
// Desc: Called At Physics Refresh Rate
// ----------------------------------------------------------------------------- //
void Ghost::Update( Vector3 v3PlayerPosition )
{
   // Floating Motion
   m_floatX.Evaluate();
   m_floatY.Evaluate();
   m_floatZ.Evaluate();

   // Jaw Motion
   m_jawPosition.Evaluate();

   switch ( m_state )
   {
   case FLYING:
      {
         // Make Ghost Face The Player -------
         // Line From Ghost To Player
         Vector3 v3Separation = v3PlayerPosition - m_v3Position;

         // Remove Y Component
         v3Separation.m_fY     = 0;
         v3PlayerPosition.m_fY = 0;

         // Player Is Within 3 Squares To The Ghost
         if ( v3Separation.Length2() < 225.0f ) // 225.0f = (3*m_fMapScale)^2
         {
            // Should Face The Player ?
            float fAngleDeg = v3Separation.GetAngle( m_v3FaceDirection, true, false );
            if ( fAngleDeg < 120.0f )
            {
               // Follow The Player
               m_state = FOLLOWING;
            }
         }

         break;
      }
   case FOLLOWING:
      {
         // Line From Ghost To Player
         Vector3 v3Separation = v3PlayerPosition - m_v3Position;

         // Remove Y Component
         v3Separation.m_fY = 0;
         v3PlayerPosition.m_fY = 0;

         // Player Is Further Than 5 Squares To The Ghost
         float fDist2 = v3Separation.Length2();
         if ( fDist2 > 625.0f ) // 625.0f = (5*m_fMapScale)^2
         {
            // Go Back To Flying State
            m_state = FLYING;
         }
         else
         {
            // Should Ghost Face The Player?
            float fAngleDeg = v3Separation.GetAngle( m_v3FaceDirection, true, false );
            if ( (fAngleDeg > 5.0f) && (fAngleDeg < 120.0f) )
            {
               // Adjust Ghost Look Direction To Face Player
               Vector3 v3Ref = m_v3FaceDirection.Cross( v3Separation );
               m_pNT_Root->m_fRotateAngle += Math::Sign( v3Ref.m_fY ) * 1.0f; // Speed Of Turn

               // Update Direction
               m_v3FaceDirection = Vector3( 0.0f, 0.0f, 1.0f ).RotateY( Math::Degree2Radian( m_pNT_Root->m_fRotateAngle ) );
            }
         }

         break;
      }
   case DYING:
      {
         // Shrink In Size
         m_pNT_Root->m_v3Scale -= Vector3( 0.01f, 0.01f, 0.01f );

         if ( m_pNT_Root->m_v3Scale.m_fX < 0 )
         {
            // Ghost Is Gone
            m_pNT_Root->m_bVisible = false;

            m_state = DEAD;
            
            // Time Delay Before Appearing Again
            m_fTime2Appear = GameOGL::GetGameTime() + 5.0f;
         }

         break;
      }
   case DEAD:
      {
         // Wait Until Ready To Appear
         if ( GameOGL::GetGameTime() > m_fTime2Appear )
         {
            float fX = Math::RandomRange( 18.8f, 35.8f );
            float fZ = Math::RandomRange( 29.0f, 41.3f );
            SetPosition( Vector3( fX, 0, fZ ) );
            
            m_pNT_Root->m_v3Scale  = Vector3( 1.0f, 1.0f, 1.0f );
            m_pNT_Root->m_bVisible = true;

            // Turn Light On
            m_pLight->SetOn( true );

            m_state   = FLYING;
         }

         break;
      }
   } // Switch

} // Update

// ------------------------------------------------------------------------------ //
// Name: Interpolate()
// Desc: Called Once Per Render Frame
// ------------------------------------------------------------------------------ //
void Ghost::Interpolate( const float fBlendFactor )
{
   if ( !IsVisible() )
   {
      // No Need To Update
      return;
   }

   float fValue;

   // Floating Motion-------------------------------
   fValue = m_floatX.GetValue( fBlendFactor );
   if ( m_floatX.IsDone() )
   {
      m_floatX.Reverse( Math::RandomRange( 0.5f, 1.0f ) );
   }
   m_pNT_Root->m_v3Translate.m_fX = m_v3Position.m_fX + fValue;

   fValue = m_floatY.GetValue( fBlendFactor );
   if ( m_floatY.IsDone() )
   {
      m_floatY.Reverse( Math::RandomRange( 0.5f, 1.0f ) );
   }
   m_pNT_Root->m_v3Translate.m_fY = m_v3Position.m_fY + fValue;

   fValue = m_floatZ.GetValue( fBlendFactor );
   if ( m_floatZ.IsDone() )
   {
      m_floatZ.Reverse( Math::RandomRange( 0.5f, 1.0f ) );
   }
   m_pNT_Root->m_v3Translate.m_fZ = m_v3Position.m_fZ + fValue;

   // Jaw Animation -------------------------------------
   fValue = m_jawPosition.GetValue();
   if ( m_jawPosition.IsDone() )
   {
      if ( fValue > 0 )
      {
         if ( GameOGL::GetGameTime() > m_fJawPause )
         {
            // Random Pause
            m_fJawPause = GameOGL::GetGameTime() + Math::RandomRange( 2.0f, 5.0f );

            // Open Mouth
            m_jawPosition.Reverse( Math::RandomRange( 0.25f, 0.4f ) );
         }
      }
      else
      {
         // Close Mouth
         m_jawPosition.Reverse( Math::RandomRange( 0.1f, 0.25f ) );
      }
   }
   m_pNT_Jaw->m_v3Translate.m_fY = fValue;

} // Interpolate


I would be very appreciated from any type of help on this matter. :?:


Offline
 Profile  
 
 Post subject: Just a follow up!
PostPosted: Sun Feb 28, 2010 1:50 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
For now I am using Interpolate1 and Interpolate3 classes and everything works fine.

Just as a note. I don't know if it makes a difference but at the end of this vmk you defined the values for the mouse wheel in the stdafx.h file.
I did not seem to have this problem. I am using Windows Vista Ultimate Edition, and I don't know if this makes a difference or not. I did add in the #define _WIN32_WINDOWS 0x0500 line inside of stdafx.h, but I just commented it out for now.


Offline
 Profile  
 
 Post subject: Re: Ghost VMK 41 - Switching Weapons
PostPosted: Fri Mar 16, 2012 5:09 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
I am toward the end of the VMK just before adding in the scroll wheel on the mouse. I check all my variables a dozen times, did a clean build. Everything compiles builds and runs great. The only bug I am getting is when I first start the game, the weapon is not initially rendering. :( at this point im kindof lost. When I referenced back to the source code in my VS2008 version I did not seem to find any errors in my new 2010 source. Only difference with my 2008 vs now is the 2008 source already has the base class for the weapons, where I am not at this point yet. When I tried to debug to find out why it isn't rendering. I went into the WeaponMace::render() function and I put a break point at this line...
_pNT_mace->v3Translate = _positionUpdate.getValue(); our Interpolate3 value is being initialized in the constructor correctly, how ever when I step through the code I am not getting any kindof of values that makes sense in our mace's transform's translate values. .......... This is where I got lost.
I do have our Player classe's member variable _state set to WS_MACE in both the Player's constructor and in Player::createWeapons() function. Any advise on where to look and what to look for would be great.


Offline
 Profile  
 
 Post subject: Re: Ghost VMK 41 - Switching Weapons
PostPosted: Sat Mar 24, 2012 8:13 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
@skilz80, did you figure out the problem? It sounds like you need to initialize the mace position to some sane values before you start rendering.


Offline
 Profile  
 
 Post subject: Re: Ghost VMK 41 - Switching Weapons
PostPosted: Mon Mar 26, 2012 1:28 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
I went back and rewatched the video and the code appears to be fine. If I switch weapons using either the number keys or the mousewheel, the next weapon does show and if I change back to the previous weapon it shows as well. The _v3PositionReady and _v3PositionHide variables are set in both weapon classes' constructors initializer lists, the values are the ones from the video, and they do render in the correct location and they hide properly too. I have the maces transform's translate value set to _v3PositionReady inside of its constructor and I have the crossbows transforms translate value set to _v3PositionHide inside of its constructor. I have the _state variable set to WS_MACE inside of Player's constructor and inside of Player::createWeapons(). For some reason, the mace is not rendering as we transition from the loading state into the play state. I'll keep searching, but any suggestions on where else to look for this little bug would be great. Thank You!


Offline
 Profile  
 
 Post subject: Re: Ghost VMK 41 - Switching Weapons
PostPosted: Wed Apr 11, 2012 11:38 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
Wow, it took me forever to find this one, it didn't appear to be a bug, but I made one simple change, did a clean build and ran the program and all is fine now. Im not 100% certain if this was the cause of it or not, but I had my interpolate variables declared in the weapons' header files before the vector3 ready and hide variables. I moved the interpolates below the vector3 vars in the header file and now there is no problem. It had nothing to do with initializing the positions. Now I can safely move on.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 7 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