Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rotate z-axis using sf::Drawable inherit  (Read 1834 times)

0 Members and 1 Guest are viewing this topic.

large

  • Newbie
  • *
  • Posts: 1
    • View Profile
Rotate z-axis using sf::Drawable inherit
« on: July 08, 2011, 12:59:14 am »
Hi

Using the latest built with SFML 2.0 from the git-hub! :)

I'm currently working on a project that needs to rotate an object through the z-axis.

Currently this little class is used to set a transform matrix:
Code: [Select]

class CMyDrawable : public sf::Drawable
{
public:
sf::Clock m_clock;

virtual void Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
sf::Matrix3 m3;
m3 = target.GetDefaultView().GetMatrix();

float fAngle = m_clock.GetElapsedTime() * 0.0000001f;
  sf::Matrix3 m3Translate(1.f, 0.f, 0.f,
0, cos(fAngle), -sin(fAngle),
  0, sin(fAngle), cos(fAngle));

  renderer.SetProjection(m3*m3Translate);
}
};


The projection almost work, rightside rotate, but the left side sticks to the x=0 coordinate.

The matrix is based on this little intro: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

It has been quite a while since I've messed with matrix's, but a rotation matrix seems right. I want the "Star Wars" effect, somehow limited. But since SFML draws 2D in 3D space, it should work?

Are there better ways to set a own matrix with SFML?
Can this be done much simpler? :)

Cheers, and thanks alot for a great framework!