Archived

This topic is now archived and is closed to further replies.

Extremely simple question!

This topic is 5622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make it global or pass it as a parameter to the functions

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites