Jump to content
  • Advertisement
Sign in to follow this  
ManTis

Rotation errors

This topic is 4405 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

Hi people. I'm creating this camera class which i want to combine usability of world system coordinates and local rotations. I've encountered very strange results and can't quite pinpoint the source of the problem.
class CCam
{
    public:
	// constructors, destructors
	CCam() {}
	CCam(float px, float py, float pz, float ax, float ay, float az, float ux, float uy, float uz)
	{
	    pos.x = px;
	    pos.y = py;
	    pos.z = pz;

	    at.x = ax;
	    at.y = ay;
	    at.z = az;

	    up.x = ux;
	    up.y = uy;
	    up.z = uz;

        at = at-pos;
	    at.Normalize();
	    at = pos+at;
	    up.Normalize();
	    up=pos+up;
	    side = (up - pos)^(at-pos);	    
	    side.Normalize();
	    side = side + pos;
	    up = (at - pos)^(side - pos);
	    up.Normalize();
	    up = up + pos;
	    


	}
	~CCam() {}
	
	void Pitch(float angle) // dunno if this is correct english name - it is supposed to be rotation of 'at' vector about 'up' vector ;)
	{

        at = at - pos;
        up = up - pos;
	    at = at.Rotate(angle, up);

	    at.Normalize();
	    at = pos + at;
	    up = up + pos;
	    side = (up - pos)^(at-pos);	    
	    side.Normalize();
	    side = side + pos;	    
	}

Oh yeah, my vector cross product, magnitude and normalize methods look like this (maybe the error's here?):
        CVector operator^(const CVector &v) const   { return CVector(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);}
	float Magnitude() const			    { return sqrt(x*x + y*y + z*z);}
	void Normalize()			    { if(Magnitude() != 0)*this /= Magnitude();}

Any help would be welcome :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!