public Quaternion toQuaternion()
    	{
    		float trace = m[0][0] + m[1][1] + m[2][2];
    		
    		float w = 1;
    		float x = 0;
    		float y = 0;
    		float z = 0;
    		  if( trace > 0 ) 
    		  {// I changed M_EPSILON to 0
    		    float s = 0.5f / (float)Math.sqrt(trace+ 1.0f);
    		    w = 0.25f / s;
    		    x = ( m[1][2] - m[2][1] ) * s;
    		    y = ( m[2][0] - m[0][2] ) * s;
    		    z = ( m[0][1] - m[1][0] ) * s;
    		  } 
    		  else 
    		  {
    		    if ( m[0][0] > m[1][1] && m[0][0] > m[2][2] ) 
    		    {
    		      float s = 2.0f * (float)Math.sqrt( 1.0f + m[0][0] - m[1][1] - m[2][2]);
    		      w = (m[1][2] - m[2][1] ) / s;
    		      x = 0.25f * s;
    		      y = (m[1][0] + m[0][1] ) / s;
    		     z = (m[2][0] + m[0][2] ) / s;
    		    } 
    		    else if (m[1][1] > m[2][2]) 
    		    {
    		      float s = 2.0f * (float)Math.sqrt( 1.0f + m[1][1] - m[0][0] - m[2][2]);
    		      w = (m[2][0] - m[0][2] ) / s;
    		      x = (m[1][0] + m[0][1] ) / s;
    		      y = 0.25f * s;
    		      z = (m[2][1] + m[1][2] ) / s;
    		    } 
    		    else 
    		    {
    		      float s = 2.0f * (float)Math.sqrt( 1.0f + m[2][2] - m[0][0] - m[1][1] );
    		      w = (m[0][1] - m[1][0] ) / s;
    		      x = (m[2][0] + m[0][2] ) / s;
    		      y = (m[1][2] + m[2][1] ) / s;
    		      z = 0.25f * s;
    		    }
    		  }
    		  
    		  return new Quaternion(x,y,z,w);
    	}