Hello guys,
I am programming a free direction tunnel oldschool effect with my “own” engine using a raytracing algorythm.
I followed this famous tutorial herehttp://www.programmersheaven.com/d/click.aspx?ID=F6526:
Renditions is perfect, but i am encountering a weird issue when i move the camera.
To rotate around axis X for example i use the following procedure:
[quote]private void rotateZ(Vector vector,double angle) {
//normalize(vector); // No need to normalize, vector is already ok...
vector.x = (float)(vector.x * Math.cos(angle) - vector.y * Math.sin(angle));
vector.y = (float)(vector.x * Math.sin(angle) + vector.y * Math.cos(angle)) ;
}
[/quote]
The issue is that rotate one time by PI/3 isn’t then same as rotate 10 times by PI/30 !! Result are totally different:
Rotate by PI/3
Vector before:
x=-0.5773502691896258
y=-0.5773502691896258
z=-0.5773502691896258
Vector after:
x=0.21132486540518702
y=-0.10566243270259373
z=-0.5773502691896258
Rotate 10 times by PI/30
Vector before:
x=-0.5773502691896258
y=-0.5773502691896258
z=-0.5773502691896258
Vector after:
x=0.17820429666750315
y=-0.7207237170724873
z=-0.5773502691896258
As a result after a “small” rotation, rendition is ok, but if I try to rotate by PI/2, vectors become total non-sense and the picture is totally distorded !!!
I am missing something huge, but i cannot find what…
Anybody ever ran into this issue ?
PS: I tried to use double instead of float to represent a vector with no success…