1 hour ago, the incredible smoker said:
What i wanto do now : learn about camera field of view, about matrices how it exactly make things faster ?, and i need to learn about aspect.
The thing with the camera plane makes it more complicated, once i have it no problem.
This stuff is a bit tedious. Although math is easy, i got confused often here and forgot anything.
I attach some code i still use in a software rasterizer for HSR. But i doupt it will help you much, and a raycaster should be much simpler anyways. (I never implemeted a raycaster or looked at any id source really close)
For polygons it definitively helps to have conversions between World, Eye and Screenspace. Then you need to calculate clipping planes from fov and all this kind of stuff. And very important is that you can interpolate 1/z linear in screenspace when drawing a scanline but not z directly.
I never used a projection matrix in a specific format like OpenGL or DX does, instead i handled perspective divide in Eye to Screen space convertions and stored fov and pov variables in camera struct along eye orientation matrix and position.
Basically you mostly need to know how eye space to screen space works, and how to clip against frustum.
If anything works, there comes the fun to port it robustly to fixed point, avoid to draw a pixel outside the screen etc...
Abrashs book covers it all for polygons IIRC.
fov = field of fiew; not sure if i use cos or sin of angle here
povx/y = point of view; usually in the center of the screen
inline void EyeToWorld (v3f &d, v3f &s)
{
d = pos + orn3x3.TinvVec (s);
}
inline void WorldToEye (v3f &e, v3f &w)
{
e = orn3x3.TrnsVec (w) - pos;
}
inline void EyeToScreen (v3f &d, const v3f &s)
{
d.z = fov / s.z;
d.x = s.x * d.z + povx;
d.y = s.y * d.z + povy;
}
float ZRange (float z)
{
z = (z-clipfarS) * rangeMult;
return z;
}
float ZScale (float z)
{
z = z * rangeMult;
return z;
}
inline void EyeToScreenZRange (v3f &d, const v3f &s)
{
EyeToScreen (d, s);
d.z = ZRange (d.z);
}
inline void ScreenToEye (v3f &d, const v3f &s)
{
float z = 1.0f / s.z;
d.x = (s.x - povx) * z;
d.y = (s.y - povy) * z;
d.z = fov * z;
}
inline float EyeZToScreenZRange (float ez)
{
return ZRange (fov / ez);
}
inline float EyeZToScreenZ (float ez)
{
return fov / ez;
}
inline float ScreenZToEyeZ (float sz)
{
return fov / sz;
}