CameraModes - LuisAntonRebollo/Torque-3D-Wiki-Test GitHub Wiki
<SCRIPT SRC="../../../include/tutorial.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/prototype.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/scriptaculous.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/glossaryLookUp.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/referenceLookUp.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/component.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT SRC="../../../include/componentContainer.js" LANGUAGE="JavaScript"></SCRIPT>
<SCRIPT>DocImagePath = "../../../";</SCRIPT>
<script>
// this script chunk is to update the ToC to the current doc and expand it
pageID = 49;
parent.leftFrame.expandToItem('tree2', 'doc49');
var element = parent.leftFrame.document.getElementById('doc49');
if((element) && (element.className==parent.leftFrame.nodeClosedClass))
{
element.className = parent.leftFrame.nodeOpenClass
}
;
</script>
<title>Torque3D - Camera Modes</title>
<table border="0" cellpadding="15" cellspacing="0" width="700">
<tbody>
<tr>
<td width="700"><table id="toc" summary="Contents">
<tbody>
<tr>
<td><div id="toctitle">
<h2>Contents</h2>
<ul>
<li class="toclevel-1"><a href="#Introduction"><span class="tocnumber">1</span> <span class="toctext">Introduction</span></a></li>
<li class="toclevel-1"><a href="#Camera_Modes"><span class="tocnumber">2</span> <span class="toctext">Camera Modes</span></a></li>
<li class="toclevel-1"><a href="#Toggling_Basic_Camera_Modes"><span class="tocnumber">3</span> <span class="toctext">Toggling Basic Camera Modes</span></a></li>
<li class="toclevel-1"><a href="#Toggling_Special_Camera_Modes"><span class="tocnumber">4</span> <span class="toctext">Toggling Special Camera Modes</span></a>
<ul>
<li class="toclevel-2"><a href="#setOrbitObject.28GameBase.2C_Point3F.2C_float.2C_float.2C_.5Bfloat.5D.2C_.5Bbool.5D.2C_.5BPoint3F.5D.2C_.5Bbool.5D.29"><span class="tocnumber">4.1</span> <span class="toctext">setOrbitObject(GameBase, Point3F, float, float, [float], [bool], [Point3F], [bool])</span></a></li>
<li class="toclevel-2"><a href="#setOrbitPoint.28string.2C_float.2C_float.2C_.5Bfloat.5D.2C_.5BPoint3F.5D.2C_.5Bbool.5D.29"><span class="tocnumber">4.2</span> <span class="toctext">setOrbitPoint(string, float, float, [float], [Point3F], [bool])</span></a></li>
<li class="toclevel-2"><a href="#setTrackObject.28GameBase.2C_.5BPoint3F.5D.29"><span class="tocnumber">4.3</span> <span class="toctext">setTrackObject(GameBase, [Point3F])</span></a></li>
<li class="toclevel-2"><a href="#setFlyMode.28void.29"><span class="tocnumber">4.4</span> <span class="toctext">setFlyMode(void)</span></a></li>
<li class="toclevel-2"><a href="#setNewtonFlyMode.28void.29"><span class="tocnumber">4.5</span> <span class="toctext">setNewtonFlyMode(void)</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#Camera_Options"><span class="tocnumber">5</span> <span class="toctext">Camera Options</span></a></li>
<li class="toclevel-1"><a href="#Conclusion"><span class="tocnumber">6</span> <span class="toctext">Conclusion</span></a></li>
</ul></td>
</tr>
</tbody>
</table>
<a name="Introduction" id="Introduction"></a>
<h2> <span class="mw-headline">Introduction</span></h2>
<p>The Torque 3D Camera object has several modes and member fields to adjust the control to desired game play. Additionally, the Torque 3D Camera object has been changed from previous versions of Torque. Major changes include</p>
<ul>
<li>Smoothing effects apply to all modes </li>
<li>Two new modes are included </li>
<li>Game play and editor specific cameras </li>
<li>Usage documentation provided for all modes </li>
</ul><br />
<a name="Camera_Modes" id="Camera_Modes"></a>
<h2> <span class="mw-headline">Camera Modes</span></h2>
<ul>
<li><strong>Stationary</strong>: The camera is fixed in space and isn't allowed to move. All user input is ignored. </li>
<li><strong>FreeRotate</strong>: The camera is fixed in space, but the user is allowed to rotate it. </li>
<li><strong>Fly</strong>: The user may control the camera using
Forward/Backward/Left/Right/Up/Down. Controls are relative to the
camera's current view direction - forward moves the camera toward
whatever it's looking at. </li>
<li><strong>OrbitObject</strong>: The camera is fixed in orbit around a particular
object, with optional offset. The user may control the camera's angle,
but not what the camera is looking at. If another object comes between
the camera and orbited object, the camera will move inward so that its
view is unobstructed. </li>
<li><strong>OrbitPoint</strong>: Similar to OrbitObject, except that instead of
orbiting an object (which may be mobile), the camera orbits a fixed
point in the world. If an object comes between the camera and the
orbited point, the camera will move inward so that its view is
unobstructed. </li>
<li><strong>TrackObject</strong>: The camera is fixed in space, and rotates to
keep a particular object in the center of view( again, with optional
offset). Like the Stationary mode, user input is ignored. </li>
<li><strong>Overhead</strong>: The user may control the camera using
Forward/Backward/Left/Right/Up/Down. Unlike the Fly camera,
Forward/Backward/Left/Right movement is constrained to a horizontal
plane. </li>
<li><strong>EditOrbit</strong>: A special mode used by the World Editor. Should not be used outside of it. </li>
</ul><br />
<a name="Toggling_Basic_Camera_Modes" id="Toggling_Basic_Camera_Modes"></a>
<h2> <span class="mw-headline">Toggling Basic Camera Modes</span></h2>
<p>The camera mode may be set by using the camera.cameraMode member field, or using a member function that sets the mode. For instance, Stationary, FreeRotate, Fly and Overhead modes may be set directly using this function: </p>
<p><br />
<b>Code Sample 1</b> </p>
<pre>function serverCmdSetCameraMode(%client, %cameraMode)
{
%client.camera.setVelocity("0 0 0");
%client.camera.controlMode = %cameraMode;
%client.setControlObject(%client.camera);
}
With the code above implemented
at the end of game/server/scripts/camera.cs, you can set the camera mode using a single function call:
xform: A set of fields for position and rotation: "posX posY posZ rotX rotY rotZ"
minDistance: Minimum distance to keep from point
maxDistance: Maximum distance to keep from point
curDistance: Optional. Initial distance from point (defaults to %maxDistance)
offset: Optional. Offset from the object's center/eye point that the camera should focus on (defaults to "0 0 0")
locked: Optional. If true, the camera angle can't be controlled by the user (defaults to false)
Returns
No return value.
Examples
// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setOrbitPoint("30 50 100 0 1 0", 0, 30, 30);
setTrackObject(GameBase, [Point3F])
Puts the camera in OrbitObject mode around the specified object:
Syntax
setTrackObject(GameBase object, Point3F offset)
object: The object to track. If the object is a ShapeBase, camera tracks its eye point. Otherwise, tracks the object's center.
offset: Optional. Offset from the object's center/eye point that the camera should focus on (defaults to "0 0 0")
Returns
No return value.
Examples
// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setTrackObject(%client.player);
setFlyMode(void)
Set the camera to be able to fly freely. Same as setting Camera.cameraMode value to "Fly"
Syntax
setTrackObject(void)
Returns
No return value.
Examples
// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setFlyMode();
setNewtonFlyMode(void)
Combination of setting Camera.newtonMode value to true and Camera.cameraMode value to "Fly"
Syntax
setNewtonFlyMode(void)
Returns
No return value.
Examples
// OrbitObject mode requires an object to orbit
// %client is the LocalClientConnection
%client.camera.setNewtonFlyMode();
Camera Options
Camera.newtonRotation and TrackObject mode produce a similar effect for rotation.
The Camera.newtonMode and Camera.newtonRotation member
fields control how the camera moves and rotates. When Camera.newtonMode
is set to true, the camera will use "smoothed" movement. Controls will
affect the camera's acceleration rather than velocity. This gives the
camera a sense of weight as it moves around. Camera.newtonRotation does
the same thing, but for rotational controls. The following member
fields only apply when either newtonMode or newtonRotation are set:
Camera.mass - Simulated mass of the camera
Camera.drag - Simulated drag when moving (not rotating)
Camera.force - Force on the camera when moving (not rotating)
Camera.angularDrag - Drag on camera when rotating
Camera.angularForce - Force on the camera when rotating (torque)
Camera.speedMultiplier - Factor to increase force by when trigger[0] is activated
Camera.brakeMultiplier - Factor to increase drag by when trigger[1] is activated
Enabling these flags can give different effects in different modes. For example:
"Tether Mode" - Achieved by enabling newtonMode and OrbitObject
mode. The camera will still follow the orbited object, but with a
springiness to it. This is best used with a massive camera, or with low
moving force. Otherwise, the extra springiness will result in
"Vomit-Vision."
Conclusion
Having Torque 3D's camera system exposed to script gives you a great
deal of power and flexibility in your game. When you have tested the
various modes, you can begin to see how this will affect game play.