Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

AdvKit.AdvKitSplineActor


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
/**
 * The main extended Spline Actor used in the adventure kit
 * 
 * 2013 by FreetimeCoder
 * www.freetimestudio.net
 */
class AdvKitSplineActor extends SplineActor
	abstract
	ClassGroup(AdvKit);

/**the next actor to activate the connection to for a bridge*/
var(Bridge) AdvKitSplineActor nextActor;
/**the previous actor to activate the connection to for a bridge*/
var(Bridge) AdvKitSplineActor prevActor;

/**is the bridge active or not*/
var(Bridge) bool bBridgeActive;

/**
 * storing the last location to only update
 * spline components when they change
 */
var Vector  vLastLocation;
/**
 * storing the last rotation to only update
 * spline components when they change
 */
var Rotator rLastRotation;

/**Set initial variables*/
function PostBeginPlay()
{
	vLastLocation = Location;
	rLastRotation = Rotation;
}

/**Called every frame to update
 * 
 * @param   _fDeltaTime     the time passed since last call
 */
event Tick(float _fDeltaTime)
{
	//only update if the actor is movable
	if(bMovable)
	{
		//only update if the actor's transformation changed
		if(vLastLocation!=Location || rLastRotation != Rotation)
		{
			//update components
			UpdateSplineComponents();
		}
	}
}

/**Query if this actor has a next connection
 * 
 * @return  if there is a next connection
 */
final function bool HasNext()
{
	//return bridge or connection size
	return (bBridgeActive && nextActor!=none) || (Connections.Length>0);
}

/**Query if this actor has a previous connection
 * 
 * @return  if there is a next connection
 */
final function bool HasPrevious()
{
	//return bridge or linksfrom size
	return (bBridgeActive && prevActor!=none) || (LinksFrom.Length>0);
}

/**Get the next AdvKitSplineActor on the curve
 * 
 * @return  the next spline
 */
function AdvKitSplineActor GetNext()
{
	//bridge connection is primary
	if(bBridgeActive && nextActor!=none)
	{
		return nextActor;
	}

	//return the first connection if there are any
	if(Connections.Length>0)
	{
		return AdvKitSplineActor(Connections[0].ConnectTo);
	}

	//there is no next
	return none;
}

/**Get the previous AdvKitSplineActor on the curve
 * 
 * @return  the previous spline
 */
function AdvKitSplineActor GetPrevious()
{
	//bridge connection is primary
	if(bBridgeActive && prevActor!=none)
	{
		return prevActor.GetPrevious();
	}

	//return the first connection if there are any
	if(LinksFrom.Length>0)
	{
		return AdvKitSplineActor(LinksFrom[0]);
	}

	//there is no next
	return none;
}

/**Get the length of the first connection from this to the next actor
 * 
 * @return  the length
 */
final function float GetSplineLength()
{
	//make sure there is a connection
	if(Connections.Length>0)
	{
		return Connections[0].SplineComponent.GetSplineLength();
	}

	//no connection
	return 0;
}

/**Calculate the tangent of the spline curve at a given location on the spline
 * This function wraps the tangent function for the first spline component
 * 
 * @param   _fDistance  the location on the curve
 * @return              the tangent
 */
final function Vector GetTangentAtDistanceAlongSpline(float _fDistance)
{
	if(Connections.Length>0)
	{
		return Connections[0].SplineComponent.GetTangentAtDistanceAlongSpline(_fDistance);
	}

	return SplineActorTangent;
}

/**Calculate the normal of the spline curve at a given location on the spline
 * 
 * @param   _fDistance  the location on the curve
 * @return              the normal
 */
final function Vector GetNormalAtDistanceAlongSpline(float _fDistance)
{
	local Vector vNormal;
	vNormal = GetTangentAtDistanceAlongSpline(_fDistance);
	vNormal = Normal(vNormal cross vect(0,0,-1));
	return vNormal;
}

/**Calculate the location of the spline curve at a given location on the spline
 * This function wraps the location function for the first spline component
 * 
 * @param   _fDistance  the location on the curve
 * @return              the 3d location in global space
 */
final function Vector GetLocationAtDistanceAlongSpline(float _fDistance)
{
	if(Connections.Length>0)
	{
		return Connections[0].SplineComponent.GetLocationAtDistanceAlongSpline(_fDistance);
	}

	return Location;
}

/**Find the closest location on the spline curve to a given location in global space
 * using binary search
 * 
 * @param   _vRefPosition   the location in global space
 * @param   _vOutPosition   the found location on the spline
 * @param   _fOutLength     the distance on the spline of the found location
 * @param   _fEpsilon       how precise the result should be
 * @param   _iMaxIterations how many iterations to allow before to break even if targeted precision was not reached
 * @return                  the distance to the found location
 */
final function float GetClosestPositionOnSplineTo(Vector _vRefPosition, optional out Vector _vOutPosition, optional out float _fOutLength, optional float _fEpsilon, optional int _iMaxIterations)
{
	local float fLengthLeft, fLengthMid, fLengthRight;
	local Vector vLocLeft, vLocMid, vLocRight;
	local float fDistLeft, fDistMid, fDistRight;
	local float fLastDistance, fSplineLength;
	local float fCurrentEps;
	local int iCurrentIteration;

	if(_iMaxIterations<=0)
	{
		_iMaxIterations = 50;
	}

	fSplineLength = GetSplineLength();

	fLengthLeft = 0;
	fLengthRight = fSplineLength;

	fLastDistance = 1000000;
	iCurrentIteration = 0;

	//Basically this is just a simple binary search with left, mid and right value
	vLocLeft = GetLocationAtDistanceAlongSpline(fLengthLeft);
	vLocRight = GetLocationAtDistanceAlongSpline(fLengthRight);
	fDistLeft = VSize(vLocLeft - _vRefPosition);
	fDistRight = VSize(vLocRight - _vRefPosition);

	do
	{
		fLengthMid = (fLengthLeft + fLengthRight)*0.5;
		vLocMid = GetLocationAtDistanceAlongSpline(fLengthMid);
		fDistMid = VSize(vLocMid - _vRefPosition);

		if(fDistLeft < fDistRight)
		{
			fLengthRight = fLengthMid;
			vLocRight = vLocMid;
			fDistRight = fDistMid;
		}
		else
		{
			fLengthLeft = fLengthMid;
			vLocLeft = vLocMid;
			fDistLeft= fDistMid;
		}

		fCurrentEps = Abs(fLastDistance - fDistMid);
		fLastDistance = fDistMid;
		iCurrentIteration++;
	}
	//abort when the delta distance is smaller than epsilon, too many iterations have been made, both borders are the same or the point is either of the splines ends
	until(fCurrentEps<=_fEpsilon || iCurrentIteration>=_iMaxIterations || fDistLeft==fDistRight || fDistMid==0 || fDistMid==fSplineLength);

	_vOutPosition = vLocMid;
	_fOutLength = fLengthMid;

	return fDistMid;
}

DefaultProperties
{
	Begin Object Name=Sprite
		Sprite=Texture2D'EditorResources.Spline.T_Loft_Spline'
		Scale = 0.1
	End Object

	Physics=PHYS_Interpolating

	bNoDelete=true
	bEdShouldSnap=true
	bMovable = true
	bStatic = false
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sa 10.8.2013 21:29:04.000 - Creation time: Di 17.9.2013 17:47:16.857 - Created with UnCodeX