http://www.sagescholars4scholars.com/Game.rar
First run the executable. When it loads, zoom your camera out with your mouse scroller. Then, hold down either mouse button (left or right) and move your camera around so it collides with the building. You'll notice that it freaks out and goes crazy. However, based on what I'm doing, I cannot figure out why this is happening. It has something to do (I think) with the updateCameraPosition() function within the Camera class as it gets called every loop. Here is what it looks like:
Code: Select all
void Cam::updateCameraPosition(Character* target)
{
vector3df targetLoc = target->getCenter();
// Calculate our new positions to move to.
double xMove = targetLoc.X + (globalDistance * sin(angleToTarget * DEGTORAD));
double zMove = targetLoc.Z + (globalDistance * cos(angleToTarget * DEGTORAD));
// Keep our camera above or below the target at the specified height.
double yMove = targetLoc.Y + heightModifier;
// Finally, set the position.
position = vector3df(xMove, yMove, zMove);
// If there is an object in between the character and the camera
// let's move the camera to just in front (0.90) of that object.
line3d<f32> line(targetLoc, position);
triangle3df someTri;
vector3df collisionPoint;
if (cmgr->getCollisionPoint(line, cameraSelector, collisionPoint, someTri))
{
position = (collisionPoint + line.start) * f32(0.90);
}
cam->setPosition(position);
cam->setTarget(targetLoc);
}