perspective projection in vecmat3 and tX test program

This commit is contained in:
2023-04-08 17:31:06 +02:00
parent 2922330c80
commit c24efe43a1
8 changed files with 386 additions and 8 deletions

View File

@@ -842,12 +842,23 @@ T Mat3<T>::norm(const T scalar) const
return sqrt(sum);
}
//cf. https://en.wikipedia.org/wiki/3D_projection
template<typename T>
void perspective(T *proj_xy, const Vec3<T> &point, const Mat3<T> &camera_angle, const Vec3<T> &camera, const Vec3<T> &plane_to_camera)
{
Vec3<T> d=camera_angle*(point-camera);
T scale = plane_to_camera[2]/d[2];
for(int i=0; i<2; ++i) proj_xy[i]= scale*d[i] + plane_to_camera[i];
}
//force instantization
#define INSTANTIZE(T) \
template class Vec3<T>; \
template class Mat3<T>; \
template void euler2rotmat(const T *eul, Mat3<T> &a, const char *type, bool transpose=0, bool direction=0, bool reverse=0); \
template void rotmat2euler(T *eul, const Mat3<T> &a, const char *type, bool transpose=0, bool direction=0, bool reverse=0); \
template void perspective(T *proj_xy, const Vec3<T> &point, const Mat3<T> &camera_angle, const Vec3<T> &camera, const Vec3<T> &plane_to_camera); \
#ifndef AVOID_STDSTREAM