When I was using VPython, I noticed that the level-of-detail for objects
sometimes appears incorrect (in my application, I move the camera around, so
this may exacerbate the problem). See
http://img512.imageshack.us/img512/1860/ringlod.png for an example of this
issue: the only difference between the two images is the direction that the
camera is facing (the ring is positioned to be exactly in front of the
camera).
I found out that the implementation of frame::world_frame_transform()
appears to be incorrect somehow, and so this is a patch which corrects it.
===================================================================
--- frame.cpp
+++ frame.cpp
@@ -174,44 +174,9 @@
tmatrix
frame::world_frame_transform() const
{
- // Performs a reorientation transform.
- // ret = translation o reorientation
- // ret = ireorientation o itranslation.
+ // This was previously incorrect, and has now been corrected by using
the inverse of frame_world_transform.
tmatrix ret;
-
- // A unit vector along the z_axis.
- vector z_axis = vector(0,0,1);
- if (std::fabs(axis.dot(up) / std::sqrt( up.mag2() * axis.mag2())) >
0.98) {
- if (std::fabs(axis.norm().dot( vector(-1,0,0))) > 0.98)
- z_axis = axis.cross( vector(0,0,1)).norm();
- else
- z_axis = axis.cross( vector(-1,0,0)).norm();
- }
- else {
- z_axis = axis.cross( up).norm();
- }
-
- vector y_axis = z_axis.cross(axis).norm();
- vector x_axis = axis.norm();
- /*
- x_axis /= scale.x;
- y_axis /= scale.y;
- z_axis /= scale.z;
- */
-
- ret(0,0) = x_axis.x;
- ret(0,1) = x_axis.y;
- ret(0,2) = x_axis.z;
- ret(0,3) = (pos * x_axis).sum();
- ret(1,0) = y_axis.x;
- ret(1,1) = y_axis.y;
- ret(1,2) = y_axis.z;
- ret(1,3) = (pos * y_axis).sum();
- ret(2,0) = z_axis.x;
- ret(2,1) = z_axis.y;
- ret(2,2) = z_axis.z;
- ret(2,3) = (pos * z_axis).sum();
-
+ inverse(ret, frame_world_transform(1.0));
return ret;
}
Now, the ring appears correct at all scale levels, and appears to be
correctly degraded when zoomed out.
Robert
|