Mastering the OrbitMode T1.4
by Geoffrey Ritter · 08/17/2006 (12:01 pm) · 14 comments
Download Code File
I. Fixes
Fix 1 - My Fix - Make the orbit camera able to zoom in through script.
Fix 2 - Chris Shark (Nov 24, 2005) - Fix jittery movement when following moving objects.
Fix 3 - My Fix - Make it possible to orbit a point rather than an object.
Fix 4 - Orion Elenzil (Jul 03, 2006) - Fix initial OrbitMode camera orientation.
II. Examples
Option 1 - Refer to document - Use two keyboard keys to move the camera in and out.
Option 2 - Refer to document - Use the mouse y axis plus the right button to move the camera in and out.
Quickly Set the Orbit Mode - One example of setting up the orbit camera.
III. Notes About the Camera
God Mode - Diablo style view
Orbit Mode - Fly around an object always looking at it
Static Mode - A fixed camera
Free Fly Mode - Standard editing camera
First Person Mode - Standard First Person Mode
Third Person Mode - Standard Third Person Mode
I. Fixes
Fix 1
There are two options to completing this task. The first would be to make a setCurOrbitDist() console function. The second (the one I outline) is to make mCurOrbitDist accessible to the the script directly. This is done with camera speed and I have seen no ill effects by doing the same with mCurOrbitDist.
camera.h
1.1 - at line 53
camera.cc
1.2 - at line 48
1.3 - void Camera::consoleInit() - around line 456
1.4 - void Camera::validateEyePoint(F32 pos, MatrixF *mat) - around line 584
EDIT: another option is to pass mCurOrbitDist into the pos variable for validateEyePoint but I haven't tested this.
Now that you made those fixes you can recompile and set up a key binding to change $Camera::curOrbitDist in the scripts.
---------------------------------------
Fix 2
camera.cc
2.1 - void Camera::interpolateTick(F32 dt) - around line 280
2.2 - void Camera::interpolateTick(F32 dt) - around line 285
Fix 3
camera.cc
3.1 - ConsoleMethod( Camera, setOrbitMode ...) - around line 479
Fix 4
camera.cc
4.1 - void Camera::setOrbitMode([...]) - around line 573
II. examples
Quickly Set the Orbit Mode
default.bind.cs
config.cs
III. Notes About the Camera
The camera that comes with Torque 1.4 can be a bit funky at times. I will try to list some possible combinations and how to get things working again if you happen to mess with something.
God mode
camera.setOrbitMode() - Set the orbit mode to be above the player
client.setControlObject(player) - Set the control object to the player
client.setCameraObject(camera) - Set the camera object to the camera
The result will be a fixed camera above the player. It's not going to orbit because we are controlling the player. (at least not without some extra altering)
Orbit Mode
camera.setOrbitMode(object, object.getTransform(), min, max, cur, 0)
client.setCameraObject(camera)
client.setControlObject(camera)
The result will be a camera that orbits around the object. You will not be controlling the player
Static Mode
camera.setFlyMode()
client.setCameraObject(camera)
client.setControlObject(player)
client.setFirstPerson(false)
EDIT: camera.setTransform(object.getTransform()) - I believe there is more proper because it marks the information as dirty so the ghosts are updated.
The result will be a camera that cannot be controlled and will be at whatever position you tell it to be at.
EDIT: See File for more information. Also if anybody needs me to, I'll change the format to PDF... however Open Office is free and a nice substitute for Microsoft Office
I. Fixes
Fix 1 - My Fix - Make the orbit camera able to zoom in through script.
Fix 2 - Chris Shark (Nov 24, 2005) - Fix jittery movement when following moving objects.
Fix 3 - My Fix - Make it possible to orbit a point rather than an object.
Fix 4 - Orion Elenzil (Jul 03, 2006) - Fix initial OrbitMode camera orientation.
II. Examples
Option 1 - Refer to document - Use two keyboard keys to move the camera in and out.
Option 2 - Refer to document - Use the mouse y axis plus the right button to move the camera in and out.
Quickly Set the Orbit Mode - One example of setting up the orbit camera.
III. Notes About the Camera
God Mode - Diablo style view
Orbit Mode - Fly around an object always looking at it
Static Mode - A fixed camera
Free Fly Mode - Standard editing camera
First Person Mode - Standard First Person Mode
Third Person Mode - Standard Third Person Mode
I. Fixes
Fix 1
There are two options to completing this task. The first would be to make a setCurOrbitDist() console function. The second (the one I outline) is to make mCurOrbitDist accessible to the the script directly. This is done with camera speed and I have seen no ill effects by doing the same with mCurOrbitDist.
camera.h
1.1 - at line 53
// FIX: OrbitMode - 1.1 - This is now a static variable so that it can be exposed // to the script. // F32 mCurOrbitDist; static F32 mCurOrbitDist;
camera.cc
1.2 - at line 48
// FIX: OrbitMode - 1.2 - Initialize the variable F32 Camera::mCurOrbitDist = 0;
1.3 - void Camera::consoleInit() - around line 456
// FIX: OrbitMode - 1.3 - Expose the mCurOrbitDist to the script
Con::addVariable("Camera::curOrbitDist",TypeF32,&mCurOrbitDist);1.4 - void Camera::validateEyePoint(F32 pos, MatrixF *mat) - around line 584
EDIT: another option is to pass mCurOrbitDist into the pos variable for validateEyePoint but I haven't tested this.
// FIX: OrbitMode - 1.4 - The default calculation gives a distance base
// upon mMaxOrbitDist and mMinOrbitDist to decide the distance of the
// camera from the object. Now that the mCurOrbitDist is exposed to the
// script we can make a new calculation based upon the mCurOrbitDist.
// validateEyePoint is called twice from within camera.cc and both times
// pos is passed in as 1.0f. Looking at further calculations it appears
// that pos is a scaler value so any calculation involving mCurOrbitDist
// will work. The added lines also make sure to limit the value of
// mCurOrbitDist within the parameters set up by calling the setOrbitMode
// function from within script.
// pos *= mMaxOrbitDist - mMinOrbitDist;
if(mCurOrbitDist > mMaxOrbitDist)
mCurOrbitDist = mMaxOrbitDist;
if(mCurOrbitDist <= mMinOrbitDist)
mCurOrbitDist = mMinOrbitDist + 0.1f; // <-- 0.1 is your choice to add.
pos *= mCurOrbitDist; // <-- put any calculation with mCurOrbitDist. Now that you made those fixes you can recompile and set up a key binding to change $Camera::curOrbitDist in the scripts.
---------------------------------------
Fix 2
camera.cc
2.1 - void Camera::interpolateTick(F32 dt) - around line 280
// FIX: OrbitMode - 2.1 - was getting jittery movement for moving objects // setRenderPosition(mPosition, rot); // validateEyePoint(1.0f, &mRenderObjToWorld); setPosition(mPosition, rot); validateEyePoint(1.0f, &mObjToWorld);
2.2 - void Camera::interpolateTick(F32 dt) - around line 285
// FIX: OrbitMode - 2.2 - was getting jittery movement for moving objects // setRenderPosition(pos,rot); setPosition(pos,rot);----------------------------------
Fix 3
camera.cc
3.1 - ConsoleMethod( Camera, setOrbitMode ...) - around line 479
// Either make the changes listed or just comment out the old function and past this one in
ConsoleMethod( Camera, setOrbitMode, void, 7, 8, "(GameBase orbitObject, transform mat, float minDistance,"
" float maxDistance, float curDistance, bool ownClientObject)"
"Set the camera to orbit around some given object.\n\n"
"@param orbitObject Object we want to orbit.\n"
"@param mat A set of fields: posX posY posZ aaX aaY aaZ aaTheta\n"
"@param minDistance Minimum distance to keep from object.\n"
"@param maxDistance Maximum distance to keep from object.\n"
"@param curDistance Distance to set initially from object.\n"
"@param ownClientObj Are we observing an object owned by us?")
{
Point3F pos;
AngAxisF aa;
F32 minDis, maxDis, curDis;
GameBase *orbitObject = NULL;
// FIX: OrbitMode - 3.1 - Move the line that parses the transformation
dSscanf(argv[3],"%g %g %g %g %g %g %g",
&pos.x,&pos.y,&pos.z,&aa.axis.x,&aa.axis.y,&aa.axis.z,&aa.angle);
// END
if(Sim::findObject(argv[2],orbitObject) == false)
{
Con::warnf("Invalid object. Attempting to orbit point.");
// FIX: OrbitMode - 3.2 - Check to see if we have a valid point
if(!bool(pos))
{
// Tell the player that we have an invalid point
Con::warnf("Invalid point. Setting Fly Mode.");
object->setFlyMode();
return;
}
// END
}
// FIX: OrbitMode - 3.3 - comment out the line of code that we moved.
// dSscanf(argv[3],"%g %g %g %g %g %g %g",
// &pos.x,&pos.y,&pos.z,&aa.axis.x,&aa.axis.y,&aa.axis.z,&aa.angle);
// END
minDis = dAtof(argv[4]);
maxDis = dAtof(argv[5]);
curDis = dAtof(argv[6]);
object->setOrbitMode(orbitObject, pos, aa, minDis, maxDis, curDis, (argc == 8) ? dAtob(argv[7]) : false);
}----------------------------------Fix 4
camera.cc
4.1 - void Camera::setOrbitMode([...]) - around line 573
// FIX: OrbitMode - 4.1 - initial orientation fix // Point3F dir; //<- new variable // tempMat.getColumn(1, &dir); //<- grabbing garbage data EulerF dir = tempMat.toEuler(); //<- computes a Euler for tempMat
II. examples
Quickly Set the Orbit Mode
default.bind.cs
// This should be a command to the server but for
// a simple example this will do
// Track if we are in orbitMode
$orbitMode = false;
// Toggle the Orbit Mode by pushing a button
function toggleOrbitMode(%val)
{
// If the button is pushed
if (%val)
{
// If we ar not in orbit mode
if (!$orbitMode)
{
// The camera can be a bit fickle so we have to
// pay attention to what we are doing with it
// Put the camera object into orbit mode around the player
// This mode takes a game base object, transform, min distance,
// max distance, current distance, and if the client owns the object
LocalClientConnection.camera.setOrbitMode(
LocalClientConnection.player,
LocalClientConnection.player.getTransform(),
2, 20, 10, 0);
// We need to tell the client that the camera object is now the
// camera versus the player object
LocalClientConnection.setCameraObject(
LocalClientConnection.camera);
// We want to be able to control the camera so we will tell the client
// the control object is the camera
LocalClientConnection.setControlObject(
LocalClientConnection.camera);
// we have just set up the orbit mode so set the variable to true.
$orbitMode = true;
}
else
{
// We are in orbit mode so we want to set things back to normal.
// Set the camera into fly mode
LocalClientConnection.camera.setFlyMode();
// Tell the client we want to view the scene through the player.
LocalClientConnection.setCameraObject(
LocalClientConnection.player);
// Tell the client we want to control the player again.
LocalClientConnection.setControlObject(
LocalClientConnection.player);
// We are now out of orbit mode.
$orbitMode = false;
}
}
}
// Middle Mouse Button
moveMap.bind(mouse0, button1, toggleOrbitRadiusChange);config.cs
moveMap.bind(mouse0, "button2", toggleOrbitMode);
III. Notes About the Camera
The camera that comes with Torque 1.4 can be a bit funky at times. I will try to list some possible combinations and how to get things working again if you happen to mess with something.
God mode
camera.setOrbitMode() - Set the orbit mode to be above the player
client.setControlObject(player) - Set the control object to the player
client.setCameraObject(camera) - Set the camera object to the camera
The result will be a fixed camera above the player. It's not going to orbit because we are controlling the player. (at least not without some extra altering)
Orbit Mode
camera.setOrbitMode(object, object.getTransform(), min, max, cur, 0)
client.setCameraObject(camera)
client.setControlObject(camera)
The result will be a camera that orbits around the object. You will not be controlling the player
Static Mode
camera.setFlyMode()
client.setCameraObject(camera)
client.setControlObject(player)
client.setFirstPerson(false)
EDIT: camera.setTransform(object.getTransform()) - I believe there is more proper because it marks the information as dirty so the ghosts are updated.
The result will be a camera that cannot be controlled and will be at whatever position you tell it to be at.
EDIT: See File for more information. Also if anybody needs me to, I'll change the format to PDF... however Open Office is free and a nice substitute for Microsoft Office
#2
08/17/2006 (6:03 pm)
Very nice job! This has been a mystery for a long time!
#3
08/21/2006 (1:33 am)
Kewl... Will give this a bash tonight
#4
Giving this a 5.
Great work, thanks.
09/11/2006 (8:03 pm)
Just what I needed for my spectator mode as it was jumping all the time. Will make it nice and smooth and may even add more views.Giving this a 5.
Great work, thanks.
#5
09/13/2006 (12:29 pm)
This looks like just what the doctor ordered!
#6
Any ideas?
10/13/2006 (9:12 am)
Great resource though I am having trouble getting the zoom fuction to work with it. Orbit mode works but regardless of what I make for the zooming in and out it doesn't work.Any ideas?
#7
If you exposed the mCurrOrbitDist variable to script using my fix OR made accessor functions for the script AND you changed the calculation in side
A note on the original calculation.
pos *= mMaxOrbitDist - mMinOrbitDist;
note that there is no use of mCurrOrbitDist and if you scroll the rest of the function and the rest of the class mCurrOrbitDist isn't used anywhere. From my findings this is the only function that takes the camera's position into account for the orbit mode and as long as you some how get mCurrOrbitDist to be added or multiplied or some how calculated with pos inside of validateEyePoint you will get some result by changing mCurrOrbitDist through your desired method. I checked this code and the script within the .doc and it all works with torque 1.4 from a fresh install.
On another note. Sometimes things are just thrown in to get it out of the way and "Make it work for now" this is how it seems a lot of the code in side of the engine is. There are a ton of things that you can tweak that it looks like that's what was going to be done but was left out for whatever reason. Much like the orbit point mode. It's inside the code already but there was no script implementation. For whatever reason. So you can just feed my alteration an object id of 0 (zero) and give it a valid transformation from another object and you are good to go.
10/15/2006 (12:44 am)
I would really have to see if you are getting any errors....If you exposed the mCurrOrbitDist variable to script using my fix OR made accessor functions for the script AND you changed the calculation in side
void Camera::validateEyePoint(F32 pos, MatrixF *mat) - around line 584 for the pos variable then you should just have to change mCurrOrbitDist and be good to go.... However I did all my testing on a single player game. Now that I think of it, it could have some issues on multi player with passing it between client and server. I haven't really messed with scopeing things but I'm assuming that if you scope the camera object to the client then you should have no problem.A note on the original calculation.
pos *= mMaxOrbitDist - mMinOrbitDist;
note that there is no use of mCurrOrbitDist and if you scroll the rest of the function and the rest of the class mCurrOrbitDist isn't used anywhere. From my findings this is the only function that takes the camera's position into account for the orbit mode and as long as you some how get mCurrOrbitDist to be added or multiplied or some how calculated with pos inside of validateEyePoint you will get some result by changing mCurrOrbitDist through your desired method. I checked this code and the script within the .doc and it all works with torque 1.4 from a fresh install.
On another note. Sometimes things are just thrown in to get it out of the way and "Make it work for now" this is how it seems a lot of the code in side of the engine is. There are a ton of things that you can tweak that it looks like that's what was going to be done but was left out for whatever reason. Much like the orbit point mode. It's inside the code already but there was no script implementation. For whatever reason. So you can just feed my alteration an object id of 0 (zero) and give it a valid transformation from another object and you are good to go.
#8
11/06/2006 (9:53 am)
Thanks for this resource. It was extremely helpful in getting my camera setup. I also spent the time to get zoom changes through the movemanager and add client side interporlation on zoom changes. In addition to that I'm adding the capability to move the focus point via standard movement bindings as well. Would you want to update this resource or should I post a new one?
#9
11/08/2006 (5:33 pm)
either or... personaly this resource was just about the orbit mode but I added the extra information at the end of the attached document to help people more with how the camera is actually interacting.
#10
I cant seem to ever get GOD mode to work in torque1.5.1
Has anybody else had this issue, and is there something new in the engine source that prevents this.
Other than that, i like the example code supplied, its cool
05/09/2007 (7:08 am)
In torque 1.5.1I cant seem to ever get GOD mode to work in torque1.5.1
Has anybody else had this issue, and is there something new in the engine source that prevents this.
Other than that, i like the example code supplied, its cool
#11
07/22/2007 (8:53 pm)
Hey, sorry about the no responce Sean. I just got Troque 1.5.2 and will be working on a project soon. I'll post my findings on the camera when I get a chance.
#12
Out of the box 1.5.2 will place the render point right at the eyenode of the player.
With the OrbitPoint fix, it will render right at the point chosen instead.
As to GOD mode for 1.4 you needed to supply the playerid, an orientation that was facing down, then max, min, curdist, 0. The current distance (or Max - Min out of the box) would determine the height to render from the player. Because of the bugs with the orbit mode in 1.5.2 I don't know what's going on... Me or somebody else will have to release another resource to fix the orbit mode.
08/05/2007 (12:44 pm)
It appears the orbitmode in 1.5.2 is broken.Out of the box 1.5.2 will place the render point right at the eyenode of the player.
With the OrbitPoint fix, it will render right at the point chosen instead.
As to GOD mode for 1.4 you needed to supply the playerid, an orientation that was facing down, then max, min, curdist, 0. The current distance (or Max - Min out of the box) would determine the height to render from the player. Because of the bugs with the orbit mode in 1.5.2 I don't know what's going on... Me or somebody else will have to release another resource to fix the orbit mode.
#13
[url]
http://www.garagegames.com/mg/forums/result.thread.php?qt=62187 [/url]
02/28/2008 (6:54 am)
There is a fix HERE[url]
http://www.garagegames.com/mg/forums/result.thread.php?qt=62187 [/url]
#14
05/08/2016 (4:38 pm)
Is there some way to control the camera and the player at the same time creating a fully working orbit camera such as in games like GTA or Tomb Raider? 
Torque Owner Dreamer
Default Studio Name