pathCamera.cpp

Engine/source/T3D/pathCamera.cpp

More...

Public Functions

ConsoleDocClass(PathCamera , "@brief A camera that moves along <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path. The camera can then be made <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> travel along this path forwards or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">backwards.\n\n</a>" "A camera's path is made up of knots, which define <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position, rotation and speed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera. Traversal from one knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "another may be either linear or using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Catmull-Rom spline. If the knot is part of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spline, then it may be <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> normal knot " "or defined as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> kink. Kinked knots are <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> hard transition on the spline rather than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> smooth one. A knot may also be defined " "as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position only. In this case the knot is treated as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> normal knot but is ignored when determining how <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> smoothly rotate " "the camera <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a0e48c1f64b558d03d870367324920354">while</a> it is travelling along the path(the algorithm moves on <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the next knot in the path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> determining rotation).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "The datablock field <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classpathcamera/">PathCamera</a> is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously created PathCameraData)
ConsoleDocClass(PathCameraData , "@brief General interface <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classpathcamera/">PathCamera</a> object from the script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">level.\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PathCamera\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "datablock <a href="/coding/class/structpathcameradata/">PathCameraData</a>(LoopingCam)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "		<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> = \"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PathCameras\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
DefineEngineMethod(PathCamera , popFront , void , () , "Removes the knot at the front of the camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Remove the first knot in the camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "%pathCamera.popFront();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" )
DefineEngineMethod(PathCamera , pushBack , void , (TransformF transform, F32 speed, const char *type, const char *path) , (1.0f, "Normal", "Linear") , "@brief Adds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the back of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param transform Transform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. In the form of \"x y z ax ay az aa\" such as returned by <a href="/coding/class/classsceneobject/#classsceneobject_1ac8ee2e9706e1a0d2505e35789c41a243">SceneObject::getTransform</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param speed Speed setting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">knot.\n</a>" "@param type Knot type (Normal, Position Only, Kink).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param path %Path type (Linear, Spline).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Transform vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. (Pos_X Pos_Y Pos_Z Rot_X Rot_Y Rot_Z Angle)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% transform)
DefineEngineMethod(PathCamera , pushFront , void , (TransformF transform, F32 speed, const char *type, const char *path) , (1.0f, "Normal", "Linear") , "@brief Adds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the front of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param transform Transform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. In the form of \"x y z ax ay az aa\" such as returned by <a href="/coding/class/classsceneobject/#classsceneobject_1ac8ee2e9706e1a0d2505e35789c41a243">SceneObject::getTransform</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param speed Speed setting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">knot.\n</a>" "@param type Knot type (Normal, Position Only, Kink).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param path %Path type (Linear, Spline).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Transform vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. (Pos_X,Pos_Y,Pos_Z,Rot_X,Rot_Y,Rot_Z,Angle)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% transform)
DefineEngineMethod(PathCamera , reset , void , (F32 speed) , (1.0f) , "@brief Clear the camera's path and set the camera's current transform as the start of the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n\n</a>" "What specifically occurs is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot is created from the camera's current transform. Then the current path " "is cleared and the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot is pushed onto the path. Any previous target is cleared and the camera's movement " "state is set <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> Forward. The camera is now ready <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">defined.\n</a>" "@param speed Speed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move along its path after being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reset.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Determine the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> movement speed of this camera. If not set, the speed will default <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> 1.0.\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% speed)
DefineEngineMethod(PathCamera , setPosition , void , (F32 position) , (0.0f) , "Set the current position of the camera along the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param position Position along the path, from 0. 0, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> place the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the camera on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position along its path from 0.0 - 1.0.\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% position)
DefineEngineMethod(PathCamera , setState , void , (const char *newState) , ("forward") , "Set the movement state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param newState New movement state type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera. Forward, Backward or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Stop.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the state type(forward, backward, stop).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//In this example, the camera will travel from the first <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">node\n</a>" "//<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the last node(or target <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> given with setTarget())\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% state)
DefineEngineMethod(PathCamera , setTarget , void , (F32 position) , (1.0f) , "@brief Set the movement target <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera along its <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n\n</a>" "The camera will attempt <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move along the path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the given target in the direction provided " "by setState() (the default is forwards). Once the camera moves past this target it will come " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> stop, and the target state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cleared.\n</a>" " @param position Target position, between 0. 0, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> along its <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the position target, between 0. 0, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to.\n</a>" "% position)
IMPLEMENT_CALLBACK(PathCamera , onNode , void , (S32 node) , (node) , "A script callback that indicates the path camera has arrived at <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific node in its path. Server side <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n</a>" "@param Node Unique ID assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">node.\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(PathCamera , "@brief A camera that moves along <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path. The camera can then be made <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> travel along this path forwards or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">backwards.\n\n</a>" "A camera's path is made up of knots, which define <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position, rotation and speed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera. Traversal from one knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "another may be either linear or using <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Catmull-Rom spline. If the knot is part of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spline, then it may be <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> normal knot " "or defined as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> kink. Kinked knots are <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> hard transition on the spline rather than <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> smooth one. A knot may also be defined " "as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position only. In this case the knot is treated as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> normal knot but is ignored when determining how <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> smoothly rotate " "the camera <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a0e48c1f64b558d03d870367324920354">while</a> it is travelling along the path(the algorithm moves on <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the next knot in the path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> determining rotation).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "The datablock field <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classpathcamera/">PathCamera</a> is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previously created PathCameraData)

ConsoleDocClass(PathCameraData , "@brief General interface <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classpathcamera/">PathCamera</a> object from the script <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">level.\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PathCamera\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "datablock <a href="/coding/class/structpathcameradata/">PathCameraData</a>(LoopingCam)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "		<a href="/coding/file/zipobject_8cpp/#zipobject_8cpp_1ac6c3dfb4c3a68f849f32cbfb21da4e77">mode</a> = \"\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "	};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">PathCameras\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

DefineEngineMethod(PathCamera , popFront , void , () , "Removes the knot at the front of the camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Remove the first knot in the camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "%pathCamera.popFront();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n</a>" )

DefineEngineMethod(PathCamera , pushBack , void , (TransformF transform, F32 speed, const char *type, const char *path) , (1.0f, "Normal", "Linear") , "@brief Adds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the back of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param transform Transform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. In the form of \"x y z ax ay az aa\" such as returned by <a href="/coding/class/classsceneobject/#classsceneobject_1ac8ee2e9706e1a0d2505e35789c41a243">SceneObject::getTransform</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param speed Speed setting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">knot.\n</a>" "@param type Knot type (Normal, Position Only, Kink).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param path %Path type (Linear, Spline).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Transform vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. (Pos_X Pos_Y Pos_Z Rot_X Rot_Y Rot_Z Angle)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% transform)

DefineEngineMethod(PathCamera , pushFront , void , (TransformF transform, F32 speed, const char *type, const char *path) , (1.0f, "Normal", "Linear") , "@brief Adds <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the front of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> path camera's <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param transform Transform <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. In the form of \"x y z ax ay az aa\" such as returned by <a href="/coding/class/classsceneobject/#classsceneobject_1ac8ee2e9706e1a0d2505e35789c41a243">SceneObject::getTransform</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param speed Speed setting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">knot.\n</a>" "@param type Knot type (Normal, Position Only, Kink).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@param path %Path type (Linear, Spline).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Transform vector <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot. (Pos_X,Pos_Y,Pos_Z,Rot_X,Rot_Y,Rot_Z,Angle)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% transform)

DefineEngineMethod(PathCamera , reset , void , (F32 speed) , (1.0f) , "@brief Clear the camera's path and set the camera's current transform as the start of the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n\n</a>" "What specifically occurs is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot is created from the camera's current transform. Then the current path " "is cleared and the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> knot is pushed onto the path. Any previous target is cleared and the camera's movement " "state is set <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> Forward. The camera is now ready <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">defined.\n</a>" "@param speed Speed <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move along its path after being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">reset.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Determine the <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> movement speed of this camera. If not set, the speed will default <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> 1.0.\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% speed)

DefineEngineMethod(PathCamera , setPosition , void , (F32 position) , (0.0f) , "Set the current position of the camera along the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" "@param position Position along the path, from 0. 0, <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> place the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the camera on <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> position along its path from 0.0 - 1.0.\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% position)

DefineEngineMethod(PathCamera , setState , void , (const char *newState) , ("forward") , "Set the movement state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this path <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param newState New movement state type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera. Forward, Backward or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Stop.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the state type(forward, backward, stop).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "//In this example, the camera will travel from the first <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">node\n</a>" "//<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the last node(or target <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> given with setTarget())\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "% state)

DefineEngineMethod(PathCamera , setTarget , void , (F32 position) , (1.0f) , "@brief Set the movement target <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera along its <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n\n</a>" "The camera will attempt <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move along the path <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the given target in the direction provided " "by setState() (the default is forwards). Once the camera moves past this target it will come " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> stop, and the target state will be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cleared.\n</a>" " @param position Target position, between 0. 0, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> along its <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">path.\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Set the position target, between 0. 0, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this camera <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> move <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to.\n</a>" "% position)

IMPLEMENT_CALLBACK(PathCamera , onNode , void , (S32 node) , (node) , "A script callback that indicates the path camera has arrived at <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific node in its path. Server side <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n</a>" "@param Node Unique ID assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">node.\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(PathCameraData )

IMPLEMENT_CO_NETOBJECT_V1(PathCamera )

resolveKnotPath(const char * arg)

resolveKnotType(const char * arg)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "math/mMath.h"
 26#include "math/mathIO.h"
 27#include "console/simBase.h"
 28#include "console/console.h"
 29#include "console/consoleTypes.h"
 30#include "core/stream/bitStream.h"
 31#include "core/dnet.h"
 32#include "scene/pathManager.h"
 33#include "app/game.h"
 34#include "T3D/gameBase/gameConnection.h"
 35#include "T3D/fx/cameraFXMgr.h"
 36#include "console/engineAPI.h"
 37#include "math/mTransform.h"
 38
 39#include "T3D/pathCamera.h"
 40
 41
 42//----------------------------------------------------------------------------
 43
 44IMPLEMENT_CO_DATABLOCK_V1(PathCameraData);
 45
 46ConsoleDocClass( PathCameraData,
 47   "@brief General interface to control a PathCamera object from the script level.\n"
 48   "@see PathCamera\n"
 49   "@tsexample\n"
 50      "datablock PathCameraData(LoopingCam)\n"
 51      "  {\n"
 52      "     mode = \"\";\n"
 53      "  };\n"
 54   "@endtsexample\n"
 55   "@ingroup PathCameras\n"
 56   "@ingroup Datablocks\n"
 57);
 58
 59void PathCameraData::consoleInit()
 60{
 61}
 62
 63void PathCameraData::initPersistFields()
 64{
 65   Parent::initPersistFields();
 66}
 67
 68void PathCameraData::packData(BitStream* stream)
 69{
 70   Parent::packData(stream);
 71}
 72
 73void PathCameraData::unpackData(BitStream* stream)
 74{
 75   Parent::unpackData(stream);
 76}
 77
 78
 79//----------------------------------------------------------------------------
 80
 81IMPLEMENT_CO_NETOBJECT_V1(PathCamera);
 82
 83ConsoleDocClass( PathCamera,
 84   "@brief A camera that moves along a path. The camera can then be made to travel along this path forwards or backwards.\n\n"
 85
 86   "A camera's path is made up of knots, which define a position, rotation and speed for the camera.  Traversal from one knot to "
 87   "another may be either linear or using a Catmull-Rom spline.  If the knot is part of a spline, then it may be a normal knot "
 88   "or defined as a kink.  Kinked knots are a hard transition on the spline rather than a smooth one.  A knot may also be defined "
 89   "as a position only.  In this case the knot is treated as a normal knot but is ignored when determining how to smoothly rotate "
 90   "the camera while it is travelling along the path (the algorithm moves on to the next knot in the path for determining rotation).\n\n"
 91
 92   "The datablock field for a PathCamera is a previously created PathCameraData, which acts as the interface between the script and the engine "
 93   "for this PathCamera object.\n\n"
 94
 95   "@see PathCameraData\n"
 96
 97      "@tsexample\n"
 98         "%newPathCamera = new PathCamera()\n"
 99         "{\n"
100         "  dataBlock = LoopingCam;\n"
101         "  position = \"0 0 300 1 0 0 0\";\n"
102         "};\n"
103      "@endtsexample\n"
104
105   "@ingroup PathCameras\n"
106);
107
108IMPLEMENT_CALLBACK( PathCamera, onNode, void, (S32 node), (node),
109               "A script callback that indicates the path camera has arrived at a specific node in its path.  Server side only.\n"
110               "@param Node Unique ID assigned to this node.\n");
111
112PathCamera::PathCamera()
113{
114   mNetFlags.clear(Ghostable);
115   mTypeMask |= CameraObjectType;
116   delta.time = 0;
117   delta.timeVec = 0;
118
119   mDataBlock = 0;
120   mState = Forward;
121   mNodeBase = 0;
122   mNodeCount = 0;
123   mPosition = 0;
124   mTarget = 0;
125   mTargetSet = false;
126
127   MatrixF mat(1);
128   mat.setPosition(Point3F(0,0,700));
129   Parent::setTransform(mat);
130}
131
132PathCamera::~PathCamera()
133{
134}
135
136
137//----------------------------------------------------------------------------
138
139bool PathCamera::onAdd()
140{
141   if(!Parent::onAdd())
142      return false;
143
144   // Initialize from the current transform.
145   if (!mNodeCount) {
146      QuatF rot(getTransform());
147      Point3F pos = getPosition();
148      mSpline.removeAll();
149      mSpline.push_back(new CameraSpline::Knot(pos,rot,1,
150         CameraSpline::Knot::NORMAL, CameraSpline::Knot::SPLINE));
151      mNodeCount = 1;
152   }
153
154   //
155   mObjBox.maxExtents = mObjScale;
156   mObjBox.minExtents = mObjScale;
157   mObjBox.minExtents.neg();
158   resetWorldBox();
159
160   if (mShapeInstance)
161   {
162      mNetFlags.set(Ghostable);
163      setScopeAlways();
164   }
165
166   addToScene();
167
168   return true;
169}
170
171void PathCamera::onRemove()
172{
173   removeFromScene();
174
175   Parent::onRemove();
176}
177
178bool PathCamera::onNewDataBlock( GameBaseData *dptr, bool reload )
179{
180   mDataBlock = dynamic_cast< PathCameraData* >( dptr );
181   if ( !mDataBlock || !Parent::onNewDataBlock( dptr, reload ) )
182      return false;
183
184   scriptOnNewDataBlock();
185   return true;
186}
187
188//----------------------------------------------------------------------------
189
190void PathCamera::onEditorEnable()
191{
192   mNetFlags.set(Ghostable);
193}
194
195void PathCamera::onEditorDisable()
196{
197   mNetFlags.clear(Ghostable);
198}
199
200
201//----------------------------------------------------------------------------
202
203void PathCamera::initPersistFields()
204{
205   Parent::initPersistFields();
206}
207
208void PathCamera::consoleInit()
209{
210}
211
212
213//----------------------------------------------------------------------------
214
215void PathCamera::processTick(const Move* move)
216{
217   // client and server
218   Parent::processTick(move);
219
220   // Move to new time
221   advancePosition(TickMs);
222
223   // Set new position
224   MatrixF mat;
225   interpolateMat(mPosition,&mat);
226   Parent::setTransform(mat);
227
228   updateContainer();
229}
230
231void PathCamera::interpolateTick(F32 dt)
232{
233   Parent::interpolateTick(dt);
234   MatrixF mat;
235   interpolateMat(delta.time + (delta.timeVec * dt),&mat);
236   Parent::setRenderTransform(mat);
237}
238
239void PathCamera::interpolateMat(F32 pos,MatrixF* mat)
240{
241   CameraSpline::Knot knot;
242   mSpline.value(pos - mNodeBase,&knot);
243   knot.mRotation.setMatrix(mat);
244   mat->setPosition(knot.mPosition);
245}
246
247void PathCamera::advancePosition(S32 ms)
248{
249   delta.timeVec = mPosition;
250
251   // Advance according to current speed
252   if (mState == Forward) {
253      mPosition = mSpline.advanceTime(mPosition - mNodeBase,ms);
254      if (mPosition > F32(mNodeCount - 1))
255         mPosition = F32(mNodeCount - 1);
256      mPosition += (F32)mNodeBase;
257      if (mTargetSet && mPosition >= mTarget) {
258         mTargetSet = false;
259         mPosition = mTarget;
260         mState = Stop;
261      }
262   }
263   else
264      if (mState == Backward) {
265         mPosition = mSpline.advanceTime(mPosition - mNodeBase,-ms);
266         if (mPosition < 0)
267            mPosition = 0;
268         mPosition += mNodeBase;
269         if (mTargetSet && mPosition <= mTarget) {
270            mTargetSet = false;
271            mPosition = mTarget;
272            mState = Stop;
273         }
274      }
275
276   // Script callbacks
277   if (int(mPosition) != int(delta.timeVec))
278      onNode(int(mPosition));
279
280   // Set frame interpolation
281   delta.time = mPosition;
282   delta.timeVec -= mPosition;
283}
284
285
286//----------------------------------------------------------------------------
287
288void PathCamera::getCameraTransform(F32* pos, MatrixF* mat)
289{
290   // Overide the ShapeBase method to skip all the first/third person support.
291   getRenderEyeTransform(mat);
292
293   // Apply Camera FX.
294   mat->mul( gCamFXMgr.getTrans() );
295}
296
297
298//----------------------------------------------------------------------------
299
300void PathCamera::setPosition(F32 pos)
301{
302   mPosition = mClampF(pos, (F32)mNodeBase, (F32)(mNodeBase + mNodeCount - 1));
303   MatrixF mat;
304   interpolateMat(mPosition,&mat);
305   Parent::setTransform(mat);
306   setMaskBits(PositionMask);
307}
308
309void PathCamera::setTarget(F32 pos)
310{
311   mTarget = pos;
312   mTargetSet = true;
313   if (mTarget > mPosition)
314      mState = Forward;
315   else
316      if (mTarget < mPosition)
317         mState = Backward;
318      else {
319         mTargetSet = false;
320         mState = Stop;
321      }
322   setMaskBits(TargetMask | StateMask);
323}
324
325void PathCamera::setState(State s)
326{
327   mState = s;
328   setMaskBits(StateMask);
329}
330
331
332//-----------------------------------------------------------------------------
333
334void PathCamera::reset(F32 speed)
335{
336   CameraSpline::Knot *knot = new CameraSpline::Knot;
337   mSpline.value(mPosition - mNodeBase,knot);
338   if (speed)
339      knot->mSpeed = speed;
340   mSpline.removeAll();
341   mSpline.push_back(knot);
342
343   mNodeBase = 0;
344   mNodeCount = 1;
345   mPosition = 0;
346   mTargetSet = false;
347   mState = Forward;
348   setMaskBits(StateMask | PositionMask | WindowMask | TargetMask);
349}
350
351void PathCamera::pushBack(CameraSpline::Knot *knot)
352{
353   // Make room at the end
354   if (mNodeCount == NodeWindow) {
355      delete mSpline.remove(mSpline.getKnot(0));
356      mNodeBase++;
357   }
358   else
359      mNodeCount++;
360
361   // Fill in the new node
362   mSpline.push_back(knot);
363   setMaskBits(WindowMask);
364
365   // Make sure the position doesn't fall off
366   if (mPosition < mNodeBase) {
367      mPosition = (F32)mNodeBase;
368      setMaskBits(PositionMask);
369   }
370}
371
372void PathCamera::pushFront(CameraSpline::Knot *knot)
373{
374   // Make room at the front
375   if (mNodeCount == NodeWindow)
376      delete mSpline.remove(mSpline.getKnot(mNodeCount));
377   else
378      mNodeCount++;
379   mNodeBase--;
380
381   // Fill in the new node
382   mSpline.push_front(knot);
383   setMaskBits(WindowMask);
384
385   // Make sure the position doesn't fall off
386   if (mPosition > F32(mNodeBase + (NodeWindow - 1)))
387   {
388      mPosition = F32(mNodeBase + (NodeWindow - 1));
389      setMaskBits(PositionMask);
390   }
391}
392
393void PathCamera::popFront()
394{
395   if (mNodeCount < 2)
396      return;
397
398   // Remove the first node. Node base and position are unaffected.
399   mNodeCount--;
400   delete mSpline.remove(mSpline.getKnot(0));
401
402   if( mPosition > 0 )
403      mPosition --;
404}
405
406
407//----------------------------------------------------------------------------
408
409void PathCamera::onNode(S32 node)
410{
411   if (!isGhost())
412      onNode_callback(node);
413   
414}
415
416U32 PathCamera::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
417{
418   Parent::packUpdate(con,mask,stream);
419
420   if (stream->writeFlag(mask & StateMask))
421      stream->writeInt(mState,StateBits);
422
423   if (stream->writeFlag(mask & PositionMask))
424      stream->write(mPosition);
425
426   if (stream->writeFlag(mask & TargetMask))
427      if (stream->writeFlag(mTargetSet))
428         stream->write(mTarget);
429
430   if (stream->writeFlag(mask & WindowMask)) {
431      stream->write(mNodeBase);
432      stream->write(mNodeCount);
433      for (S32 i = 0; i < mNodeCount; i++) {
434         CameraSpline::Knot *knot = mSpline.getKnot(i);
435         mathWrite(*stream, knot->mPosition);
436         mathWrite(*stream, knot->mRotation);
437         stream->write(knot->mSpeed);
438         stream->writeInt(knot->mType, CameraSpline::Knot::NUM_TYPE_BITS);
439         stream->writeInt(knot->mPath, CameraSpline::Knot::NUM_PATH_BITS);
440      }
441   }
442
443   // The rest of the data is part of the control object packet update.
444   // If we're controlled by this client, we don't need to send it.
445   if(stream->writeFlag(getControllingClient() == con && !(mask & InitialUpdateMask)))
446      return 0;
447
448   return 0;
449}
450
451void PathCamera::unpackUpdate(NetConnection *con, BitStream *stream)
452{
453   Parent::unpackUpdate(con,stream);
454
455   // StateMask
456   if (stream->readFlag())
457      mState = stream->readInt(StateBits);
458
459   // PositionMask
460   if (stream->readFlag()) 
461   {
462      stream->read(&mPosition);
463      delta.time = mPosition;
464      delta.timeVec = 0;
465   }
466
467   // TargetMask
468   if (stream->readFlag())
469   {
470      mTargetSet = stream->readFlag();
471      if (mTargetSet)
472         stream->read(&mTarget);
473   }
474
475   // WindowMask
476   if (stream->readFlag()) 
477   {
478      mSpline.removeAll();
479      stream->read(&mNodeBase);
480      stream->read(&mNodeCount);
481      for (S32 i = 0; i < mNodeCount; i++)
482      {
483         CameraSpline::Knot *knot = new CameraSpline::Knot();
484         mathRead(*stream, &knot->mPosition);
485         mathRead(*stream, &knot->mRotation);
486         stream->read(&knot->mSpeed);
487         knot->mType = (CameraSpline::Knot::Type)stream->readInt(CameraSpline::Knot::NUM_TYPE_BITS);
488         knot->mPath = (CameraSpline::Knot::Path)stream->readInt(CameraSpline::Knot::NUM_PATH_BITS);
489         mSpline.push_back(knot);
490      }
491   }
492
493   // Controlled by the client?
494   if (stream->readFlag())
495      return;
496
497}
498
499
500//-----------------------------------------------------------------------------
501// Console access methods
502//-----------------------------------------------------------------------------
503
504DefineEngineMethod(PathCamera, setPosition, void, (F32 position),(0.0f), "Set the current position of the camera along the path.\n"
505                                       "@param position Position along the path, from 0.0 (path start) - 1.0 (path end), to place the camera.\n"
506                                       "@tsexample\n"
507                                          "// Set the camera on a position along its path from 0.0 - 1.0.\n"
508                                          "%position = \"0.35\";\n\n"
509                                          "// Force the pathCamera to its new position along the path.\n"
510                                          "%pathCamera.setPosition(%position);\n"
511                                       "@endtsexample\n")
512{
513   object->setPosition(position);
514}
515
516DefineEngineMethod(PathCamera, setTarget, void, (F32 position),(1.0f), "@brief Set the movement target for this camera along its path.\n\n"
517                                       "The camera will attempt to move along the path to the given target in the direction provided "
518                                       "by setState() (the default is forwards).  Once the camera moves past this target it will come "
519                                       "to a stop, and the target state will be cleared.\n"
520                                       "@param position Target position, between 0.0 (path start) and 1.0 (path end), for the camera to move to along its path.\n"
521                                       "@tsexample\n"
522                                          "// Set the position target, between 0.0 (path start) and 1.0 (path end), for this camera to move to.\n"
523                                          "%position = \"0.50\";\n\n"
524                                          "// Inform the pathCamera of the new target position it will move to.\n"
525                                          "%pathCamera.setTarget(%position);\n"
526                                       "@endtsexample\n")
527{
528   object->setTarget(position);
529}
530
531DefineEngineMethod(PathCamera, setState, void, (const char* newState),("forward"), "Set the movement state for this path camera.\n"
532                                       "@param newState New movement state type for this camera. Forward, Backward or Stop.\n"
533                                       "@tsexample\n"
534                                          "// Set the state type (forward, backward, stop).\n"
535                                          "// In this example, the camera will travel from the first node\n"
536                                          "// to the last node (or target if given with setTarget())\n"
537                                          "%state = \"forward\";\n\n"
538                                          "// Inform the pathCamera to change its movement state to the defined value.\n"
539                                          "%pathCamera.setState(%state);\n"
540                                       "@endtsexample\n")
541{
542   if (!dStricmp(newState,"forward"))
543      object->setState(PathCamera::Forward);
544   else
545      if (!dStricmp(newState,"backward"))
546         object->setState(PathCamera::Backward);
547      else
548         object->setState(PathCamera::Stop);
549}
550
551DefineEngineMethod(PathCamera, reset, void, (F32 speed),(1.0f), "@brief Clear the camera's path and set the camera's current transform as the start of the new path.\n\n"
552                                       "What specifically occurs is a new knot is created from the camera's current transform.  Then the current path "
553                                       "is cleared and the new knot is pushed onto the path.  Any previous target is cleared and the camera's movement "
554                                       "state is set to Forward.  The camera is now ready for a new path to be defined.\n"
555                                       "@param speed Speed for the camera to move along its path after being reset.\n"
556                                       "@tsexample\n"
557                                          "//Determine the new movement speed of this camera. If not set, the speed will default to 1.0.\n"
558                                          "%speed = \"0.50\";\n\n"
559                                          "// Inform the path camera to start a new path at"
560                                          "// the camera's current position, and set the new "
561                                          "// path's speed value.\n"
562                                          "%pathCamera.reset(%speed);\n"
563                                       "@endtsexample\n")
564{
565   object->reset(speed);
566}
567
568static CameraSpline::Knot::Type resolveKnotType(const char *arg)
569{
570   if (dStricmp(arg, "Position Only") == 0) 
571      return CameraSpline::Knot::POSITION_ONLY;
572   if (dStricmp(arg, "Kink") == 0) 
573      return CameraSpline::Knot::KINK;
574   return CameraSpline::Knot::NORMAL;
575}
576
577static CameraSpline::Knot::Path resolveKnotPath(const char *arg)
578{
579   if (!dStricmp(arg, "Linear"))
580      return CameraSpline::Knot::LINEAR;
581   return CameraSpline::Knot::SPLINE;
582}
583
584DefineEngineMethod(PathCamera, pushBack, void, (TransformF transform, F32 speed, const char* type, const char* path),
585                                    (1.0f, "Normal", "Linear"), 
586                                       "@brief Adds a new knot to the back of a path camera's path.\n"
587                                       "@param transform Transform for the new knot.  In the form of \"x y z ax ay az aa\" such as returned by SceneObject::getTransform()\n"
588                                       "@param speed Speed setting for this knot.\n"
589                                       "@param type Knot type (Normal, Position Only, Kink).\n"
590                                       "@param path %Path type (Linear, Spline).\n"
591                                       "@tsexample\n"
592                                          "// Transform vector for new knot. (Pos_X Pos_Y Pos_Z Rot_X Rot_Y Rot_Z Angle)\n"
593                                          "%transform = \"15.0 5.0 5.0 1.4 1.0 0.2 1.0\"\n\n"
594                                          "// Speed setting for knot.\n"
595                                          "%speed = \"1.0\"\n\n"
596                                          "// Knot type. (Normal, Position Only, Kink)\n"
597                                          "%type = \"Normal\";\n\n"
598                                          "// Path Type. (Linear, Spline)\n"
599                                          "%path = \"Linear\";\n\n"
600                                          "// Inform the path camera to add a new knot to the back of its path\n"
601                                          "%pathCamera.pushBack(%transform,%speed,%type,%path);\n"
602                                       "@endtsexample\n")
603{
604   QuatF rot(transform.getOrientation());
605
606   object->pushBack( new CameraSpline::Knot(transform.getPosition(), rot, speed, resolveKnotType(type), resolveKnotPath(path)) );
607}
608
609DefineEngineMethod(PathCamera, pushFront, void, (TransformF transform, F32 speed, const char* type, const char* path),
610                                    (1.0f, "Normal", "Linear"), 
611                                       "@brief Adds a new knot to the front of a path camera's path.\n"
612                                       "@param transform Transform for the new knot. In the form of \"x y z ax ay az aa\" such as returned by SceneObject::getTransform()\n"
613                                       "@param speed Speed setting for this knot.\n"
614                                       "@param type Knot type (Normal, Position Only, Kink).\n"
615                                       "@param path %Path type (Linear, Spline).\n"
616                                       "@tsexample\n"
617                                          "// Transform vector for new knot. (Pos_X,Pos_Y,Pos_Z,Rot_X,Rot_Y,Rot_Z,Angle)\n"
618                                          "%transform = \"15.0 5.0 5.0 1.4 1.0 0.2 1.0\"\n\n"
619                                          "// Speed setting for knot.\n"
620                                          "%speed = \"1.0\";\n\n"
621                                          "// Knot type. (Normal, Position Only, Kink)\n"
622                                          "%type = \"Normal\";\n\n"
623                                          "// Path Type. (Linear, Spline)\n"
624                                          "%path = \"Linear\";\n\n"
625                                          "// Inform the path camera to add a new knot to the front of its path\n"
626                                          "%pathCamera.pushFront(%transform, %speed, %type, %path);\n"
627                                       "@endtsexample\n")
628{
629   QuatF rot(transform.getOrientation());
630
631   object->pushFront( new CameraSpline::Knot(transform.getPosition(), rot, speed, resolveKnotType(type), resolveKnotPath(path)) );
632}
633
634DefineEngineMethod(PathCamera, popFront, void, (),, "Removes the knot at the front of the camera's path.\n"
635                                       "@tsexample\n"
636                                          "// Remove the first knot in the camera's path.\n"
637                                          "%pathCamera.popFront();\n"
638                                       "@endtsexample\n")
639{
640   object->popFront();
641}
642