Game Development Community

small bugfix to ShapeBase::getCameraTransform()

by Orion Elenzil · in Torque Game Engine · 01/21/2009 (1:51 pm) · 4 replies

this is present in TGE 1.4.2, and probably in TGE 1.5 and TGEA and will probably be present in T3D as well.

ShapeBase::getCameraTransform() is responsible for determining where the camera should be positioned given a shapeBase. ie, the typical over-the-shoulder view.

this task includes making sure that the camera doesn't get backed-up into a wall or something. to do that, the routine casts a ray from the shapeBase object to the target eyepoint, and if it hits something, it moves the eyepoint to "just in front of" the the collision point.

this "just in front of" amount is calculated as follows (code has been simplified)
// project vec onto the normal: (divide by veclen because it may be != 1)
adjust = 0.1 * dot(vec, normal) / veclen;
and used later to move the camera away from the collision like this:
eyePointFinal = eyePointTarget - (vec * adjust);

see the problem ?
if vec is not unit-lengthed, then vec * adjust is going to vary with the length of vec, when what we really want is an offset from the wall which doesn't vary with the length of the target eyeVector.

how does this affect you ?
probably not at all,
since in stock TGE the camera distance is always either 0 or 1.
but if you should want to let the user adjust the camera distance (say for filming machinima), and the camera is backed up against a wall, the final eyePoint will vary as the target camera distance changes. which looks funny.

the solution is to divide the adjust term one more time by vecLen, so that their product is independant of vec's length.

along the way we get to eliminate a square root as well. always satisfying.

shapeBase.cc
change these two lines:
F32 veclen = vec.len();
         F32 adj = (-mDot(vec, collision.normal) / veclen) * 0.1;
to this:
F32 vecLenSq = vec.lenSquared();
         F32 adj = (-mDot(vec, collision.normal) / vecLenSq) * 0.1f;



#1
01/21/2009 (2:06 pm)
Yup its in tgea1.8. Thanks for finding this Orion.


Quote:this is present in TGE 1.4.2, and probably in TGE 1.5 and TGEA and will probably be present in T3D as well

heh, yes im playing with TGEA right now, and finding small bugs that the community have posted bug fix for over 3 years ago. One more reason GG dreams if they expect a T3D price raise to be effective. Im starting to feel that i overpay for TGEA. Back when i had active license with EPIC i could post a bug report at 4AM on the weekend and Tim Sweeney would often have a bug fix ready and posted by noon that very day - THIS is the reason they have an AAA engine NOT just the EYE candy. I post a 'show stopping bug' last Friday and its still biting my ass today, with not a peep from GG.


EDIT: just to clarify, I DO see a difference between BUG fix, and code improvements. I expect any engine SDK CO to incorporate any found bug fix. I dont expect them to incorporate code improvements.
#2
01/21/2009 (2:14 pm)
i too wish GG would put regular effort into merging community bugfixes into Trunk. some of them make it in, but it seems to be a very ad-hoc selection process. it's definitely a big task tho, changes really need to be vetted for correctness and backwards-compatibility and ideally understood and possibly improved.

also anecdotally, a coworker recently found & fixed a bug in ehcache, and the fix was merged into trunk in like twelve hours. .. which is perhaps a bit *too* responsive - maybe the fix was bad! but illustrates a difference.
#3
01/21/2009 (5:45 pm)
Good catch Orion!

You probably haven't noticed but pretty much since TGEA 1.7.1 the GG crew has been much better about merging bug fixes from the community now that the different code bases are merged.

In fact i think you'll find that Rene Damm has been keeping on top of this for TGEA 1.8 and now Torque 3D.

I suspect you'll see him drop by on this thread any second now.
#4
01/21/2009 (5:53 pm)
I should list the ones i have found and hand them off to Rene. My email is in my profile, toss me a note when you read this Rene...