Game Development Community

Poof* Gone? O_o

by D B · in Torque Game Engine · 02/11/2006 (1:10 pm) · 2 replies

I was working with Thomas Lund's Advanced Camera, and everything with it was working out just fine, with the exception of one bug where the camera starts at (0,0,0) before moving to focus on the player (a problem that many were having).

I browsed around through resources and forums on it, trying to see if anyone had a solution to fixing it. No such solution was available, so I took matters into my own hands and started messing around with various files, including game.cs, and the .cc and .h files of camera, player, trackingCamera, advancedCamera and shapeBase. Still no luck there.

I was speaking of the problem to a friend of mine and wanted to show him the bug ingame.

However, when I showed it to him... the bug wasn't there. The camera automatically started at the player. And it did so for each time the map was loaded after. Even today, there is still no problem with the (0,0,0) bug.

Any idea on how it got fixed? It seems really weird that I didn't change anything (I reverted all of the files after ideas didn't work) and yet the problem was fixed and stayed fixed.

#1
02/13/2006 (2:32 pm)
You mght either be setting the camera's initial position to match the players, or maybe interpolation was turned off.

The interpolation code is found in 'void AdvancedCamera::setPosition(const Point3F& pos)'.

For my project, I actually modified the code by adding a flag to disable interpolation while attaching the camera to a player. So a quick code fix would be to only interpolate if the previous position is not <0,0,0>

Point3F tPos = getPosition();

	if((tPos[0] | tPos[1] | tPos[2]) != 0) // ugly, but cheap?
	{
		F32 tInterpolation = 0.333333333;
		tPos = pos*tInterpolation + tPos*(1.0-tInterpolation);
	}
	else
	{
		// Move directly to position specified
		tPos = pos;
	}

-Jeff
#2
02/13/2006 (3:35 pm)
FWIW, I commented out the interpolation code altogether from AdvancedCamera::setPosition.
My code looks like this now:

//	F32 tInterpolation = 0.333333333;
//	tPos = pos*tInterpolation + tPos*(1.0-tInterpolation);
	Point3F tPos = pos;

This solved a jittering problem I was having with the advanced camera. It also solved the interpolating from (0,0,0) issue. There is some discussion of this in the resource comments.