Game Development Community

[Bug 1.0.1] Shapebase cameraMinDist (with fix) - RESOLVED

by Ryan Mounts · in Torque 3D Professional · 11/04/2009 (5:35 pm) · 3 replies

This bug has been around since the beginning. It's a small bug and just hasn't been much of a nuisance, so I hadn't reported it yet. The camera's minimum distance in 3rd person view is always located at the player's cam node, no matter what value you give cameraMinDist in the player datablock. In fact, you'll notice that if you set cameraMinDist to any non-zero value, not only will it not change your minimum camera distance, it'll mess up your maximum camera distance. I never really had a need for cameraMinDist until coding a camera dolly feature using the mouse wheel in 3rd person view (http://www.garagegames.com/community/forums/viewthread/104679). In any event, it's a really easy fix...

Make the following changes to the "getCameraTransform()" method in "T3D/shapeBase.cpp":

// Use the eye transform to orient the camera   
      VectorF vp,vec;   
      vp.x = vp.z = 0;   
      vp.y = -(max - min) * *pos;   
      eye.mulV(vp,&vec);   
  
      /// New code: start   
      VectorF minVec;   
      vp.y = -min;   
      eye.mulV(vp,&minVec);   
      /// New code: end   
  
      // Use the camera node's pos.   
      Point3F osp,sp;   
      if (mDataBlock->cameraNode != -1) {   
         mShapeInstance->mNodeTransforms[mDataBlock->cameraNode].getColumn(3,&osp);   
  
         // Scale the camera position before applying the transform   
         const Point3F& scale = getScale();   
         osp.convolve( scale );   
  
         getRenderTransform().mulP(osp,&sp);   
      }   
      else  
         getRenderTransform().getColumn(3,&sp);   
  
      // Make sure we don't extend the camera into anything solid   
      Point3F ep = sp + minVec + vec + offset;   /// Modify this line to add "minVec"

#1
11/07/2009 (11:58 pm)
Ryan, would I be correct in thinking that the 3rd Person Camera cannot penetrate the inside of the bounding box? (just that if I have my cam inside the bounds, it still gets pushed out)
#2
11/08/2009 (12:22 am)
The 3rd person camera can penetrate the bounding box. The camera can be located anywhere between cameraMaxDist and the cam node. Note, however, that cameraMinDist really does nothing in the stock shapeBase code, and I suggest leaving it at zero. The fix above just places the camera at the correct distance if you happen to set cameraMinDist, but it's really only useful if you do something custom like my mousewheel code that actually utilizes cameraMinDist. With that said, camera collisions with a wall can still push the camera all the way to the cam node. The stock code would have to be modified to get the cameraMinDist to be honored in that situation (and that really should be the way it works... maybe I'll work on that :).

If you want to see the bug I'm talking about, simply set cameraMaxDist to say, 5, and cameraMinDist to 0. Take a look at where the 3rd person camera is located in a stock copy. Five units from the cam node. Now set cameraMinDist to 4. You'd expect the camera to stay in the same place, since cameraMaxDist did not change... but instead the camera is now located 1 unit from the cam node instead of 5. My change fixes that.
#3
02/20/2010 (8:20 pm)

Thanks for the fix. Rolled in for next beta.