Extremely simple question!

Started by
2 comments, last by neurokaotix 21 years, 8 months ago
For the demo I''m programming I declare a vector called m_LookAt which stores the location of the players camera from the enemy mesh so that it can look at the player. I declare it like this: D3DXVECTOR3 m_LookAt;. The vector is declared in a function called CalculateRotation() which appears just before the Render() function. Another function called Update() calls CalculateRotation() in order to get the calculated rotation(simple). The update function appears after CalculateRotation() and before Render(). Near the end of the Render() function I call Update() in order to get the updated turn ratio. My problem is occurs when I try to rotate the mesh like this: XMesh[14]->RotateMesh(&m_LookAt);. It gives me an error stating "''m_LookAt'' : undeclared identifier". Is there a way in which I can declare m_LookAt so that any function can use it?
Advertisement
*bump*
Make it global or pass it as a parameter to the functions
What''s up, neuro--

The "m_" in such variable names usually stands for "member variable." Meaning that the variable is declared accessible to all functions in a single C++ class. So, in this code:


  class MyClass {protected:   D3DXVECTOR3 m_LookAt;public:     void Update();   void CalculateRotation();   void Render(); };void MyClass::Update() {...}void MyClass::CalculateRotation() {...}void MyClass::Render() {...}  


all three of the functions listed in the class can work with m_LookAt directly.

Or, as Anonymous Poster suggested, you can make m_LookAt a global variable, in which case you should name it "g_LookAt".

--Hoozit.
----------------------Check out my game demo and resume at www.fivestory.com/projects/game.

This topic is closed to new replies.

Advertisement