Is sprintf'ing a D3DXVECTOR3 possible?
Hello,
I'm trying to output/convert a D3DXVECTOR3 to something I can render in a font, and I think I'm trying to do something like:
sprintf( m_cameraPos, "%d, %d, %d, Campos", m_camera->GetTranslation );
But I'm a little lost and I can't exactly figure it out. Is there a way to extract the individual components of a D3DXVECTOR3, or do I have to like, cast it to something more native to a sprintf function?
In the past, I've just kept extra x, y and z floats embedded in the objects but if there's an easier or more simple way, I'd really appreciate the advice.
Thanks a bunch!
If you look at the definition of D3DXVECTOR3, you can see that you can just use x, y, and z fields from the vector.
So,
So,
D3DXVECTOR3 const &t = m_camera->GetTranslation;sprintf( m_cameraPos, "%.2f, %.2f, %.2f, Campos", t.x, t.y, t.z );
should just work.
sprintf cannot be extended to support more types, which is one of the reasons why C++ streams are a superior solution.
In your particular case, it would be as simple as:
Or perhaps:
As long as you've defined operator<< for the vector:
In your particular case, it would be as simple as:
return boost::lexical_cast<std::string>(m_camera->GetTranslation)
Or perhaps:
std::strintstream stream;stream << m_camera->GetTranslation;return stream.str();
As long as you've defined operator<< for the vector:
std::ostream& operator<<(std::ostream& out, const D3DXVECTOR3 & v) { return out << v.x << " " << v.y << " " << v.z; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement