Problem with my rotation code?
ok, after going through and understanding more on rotational transforms, as well as going on a trip to california, i yesterday sat down and programmed up some rotation code, which probably isnt working due to how crappy my setup code is(in the program i tself), but I want to make sure the code itself is valid.
Code:
void Camera::RotateView(int degrees, float x, float y, float z)
{
Vector3d Axis = Vector3d(x,y,z);
float costheta = cos(degrees);
float sintheta = sin(degrees);
m_view = ((m_view - (Axis * Dot(Axis,m_view)))*costheta) + (Cross(Axis,m_view) *sintheta) + (Axis * Dot(Axis,m_view));
};
also, is there another way to change where the camera looks(more efficient) besides gluLookAt()?
EDIT: btw, the reason why I am not going through the vector compinents individually is I have overloaded operators in my vector class for both other vectors and also scalars.
Re: Problem with my rotation code?
Quote:
Originally posted by EvBladeRunnervE
also, is there another way to change where the camera looks(more efficient) besides gluLookAt()?
In the manual you can read all about how glulookat works. Then you'll see how keeping track of a world position and a view direction, and updating the rotation matrix using a fast lookup table for trigs, only costs you 21 multiplications when the view direction changes where glulookat costs you 24 multiplications 2 divisions and 2 sqrt's every time you call glulookat whether or not you changed view direction. But who cares because if glulookat is the bottleneck on your "engine" that would mean you must be developing for a stopwatch. So lets talk about a real bottleneck:
I wouldn't store velocity as a normalized vector and a magnitude in a game. What happens when you have to add a linear acceleration to the velocity: convert velocity unit vector into non unit vector (3 extra multiplies), add acceleration, convert velocity back to unit vector ( 1 division, a sqrt, and 3 multiplies ). That comes to a total of 6 muls and 1 div and a fancy sqrt too wasted on every velocity in the scene, and all so you can use a velocity for a rotation axis. That would only be useful if you had radially symmetric charged objects moving through a magnetic field perpendicular to the axis of symmetry of the object (warning:you are writing a boring game if you have this), where as adding a linear acceleration to the velocity has to be done constantly in any scene.