## XIDCine
Class CineRope

source: C:\XIII\XIDCine\Classes\CineRope.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Triggers
             |
             +--XIDCine.CineRope

Direct Known Subclasses:None

class CineRope
extends Engine.Triggers

    //-----------------------------------------------------------
    // CineRope
    // Created by iKi
    //-----------------------------------------------------------

States
STA_Break, STA_Tight, STA_WaitLoose, STA_Fall, STA_Wait

State STA_Break Function Summary

State STA_Tight Function Summary

State STA_WaitLoose Function Summary

State STA_Fall Function Summary

State STA_Wait Function Summary
`float` | `Magic(float f)`
    /*

Source Code

    00001	//-----------------------------------------------------------
    00002	// CineRope
    00003	// Created by iKi
    00004	//-----------------------------------------------------------
    00005	class CineRope extends Triggers;
    00006
    00007	#exec Texture Import File=Textures\Rock_ico.pcx Name=Rock_ico Mips=Off
    00008
    00009	const LinkLength = 100.0;
    00010	const LinkNumber = 30;
    00011	const RopeLength = 320;
    00012	VAR			float	LinkRealLength;
    00013	VAR			float	LinkScaleX;
    00014	//VAR			float	vA0Link[LinkNumber],vALink[LinkNumber];
    00015	VAR			float	TimeStamp;
    00016	//VAR			bool	bTendue;
    00017	VAR			int FrameCount;
    00018	const		IAPeriod=0.1;
    00019
    00020	VAR			CineRopeLink PremierFilin;
    00021
    00022	EVENT PostBeginPlay()
    00023	{
    00024		LOCAL Vector ds3d;
    00025		LOCAL Rotator Horiz;
    00026		LOCAL CineRopeLink Filin, PrevFilin;
    00027		LOCAL int i,n,v;
    00028
    00029		LinkRealLength = RopeLength / LinkNumber;
    00030		LinkScaleX = LinkRealLength / LinkLength;
    00031
    00032		Horiz = ROTATOR( vect(0,1,0) );
    00033		Horiz.Pitch=0;
    00034		PremierFilin = Spawn( class'CineRopeLink',,,Location+0.5*LinkRealLength*vect(1,0,0), Horiz );
    00035		ds3d = PremierFilin.DrawScale3D;
    00036		ds3d.X = LinkScaleX;
    00037		PremierFilin.SetDrawScale3D( ds3d );
    00038		PrevFilin = PremierFilin;
    00039
    00040		n=0;
    00041	//	v=-3072;
    00042	//	vA0Link[0]=v;
    00043
    00044		for (i=1;i<LinkNumber;i++)
    00045		{
    00046			Horiz.Pitch = 12288*i;
    00047
    00048	//		vA0Link[i]=v;
    00049
    00050			Filin = Spawn( class'CineRopeLink',,,PrevFilin.Location, Horiz );
    00051
    00052			Filin.SetDrawScale3D( ds3d );
    00053			PrevFilin.NextLink = Filin;
    00054			Filin.PrevLink = PrevFilin;
    00055			PrevFilin = Filin;
    00056		}
    00057
    00058		SetTimer( IAPeriod, true );
    00059	}
    00060
    00061	//VAR float vZ;
    00062	/* STATE STA_Wait
    00063	{
    00064		EVENT BeginState()
    00065		{
    00066			SetTimer( 3.0, false );
    00067		}
    00068	}*/
    00069	/*
    00070	FUNCTION float Magic(float f)
    00071	{
    00072		log("MAGIC"@f@1.0f - ((1.0f-f)**10));
    00073		return 1.0f - ((1.0f-f)**10);
    00074	}
    00075	*/
    00076	auto STATE STA_Fall
    00077	{
    00078		EVENT BeginState()
    00079		{
    00080		}
    00081
    00082		EVENT Timer()
    00083		{
    00084			LOCAL Rotator r;
    00085			LOCAL Vector Up;
    00086			LOCAL CineRopeLink Filin;
    00087			LOCAL int i;
    00088
    00089			Up = Location;
    00090			Filin = PremierFilin;
    00091			TimeStamp+=IAPeriod; //dt;
    00092			for (i=0;i<LinkNumber;i++)
    00093			{
    00094				r.Pitch = ( ( -16384 - Filin.Rotation.Pitch + 32768 ) & 65535 ) - 32768;
    00095				r.Yaw = ( ( -Filin.Rotation.Yaw + 32768 ) & 65535 ) - 32768;
    00096				r.Roll = ( ( -Filin.Rotation.Roll + 32768 ) & 65535 ) - 32768;
    00097				r = r*0.07 + Filin.Rotation;
    00098
    00099				Filin.SetRotation( r );
    00100				Filin.SetLocation( Up + 0.5 * LinkRealLength * VECTOR( r ) );
    00101				Up += LinkRealLength*VECTOR(r);
    00102				Filin = Filin.NextLink;
    00103			}
    00104		}
    00105
    00106	//	EVENT Tick( float dt )
    00107	/*	EVENT Timer()
    00108		{
    00109			LOCAL Rotator r;
    00110			LOCAL Vector Up;
    00111			LOCAL CineRopeLink Filin;
    00112			LOCAL int i;
    00113
    00114			Up = Location;
    00115			Filin= PremierFilin;
    00116
    00117			for (i=0;i<LinkNumber;i++)
    00118			{
    00119				r = Filin.Rotation;
    00120				if ( Abs(r.Pitch+16384)<128 )
    00121				{
    00122					if ( i+1==LinkNumber )
    00123						GotoState('STA_WaitLoose');
    00124				}
    00125				else
    00126				{
    00127					if ( (r.Pitch+vALink[i]+16384)*(r.Pitch+16384)<0)
    00128					{
    00129						vALink[i]=vA0Link[i];
    00130						vA0Link[i]=-0.9*vA0Link[i];
    00131
    00132					}
    00133					r.Pitch += vALink[i];
    00134	//				vALink[i] = vALink[i] + Magic( 0.05 + 0.001*float(LinkNumber-i)/LinkNumber)*(vA0Link[i]-vALink[i]);
    00135				}
    00136
    00137				Filin.SetRotation( r );
    00138				Filin.SetLocation( Up+Magic(0.5)*LinkRealLength*VECTOR(r));
    00139				Up += LinkRealLength*VECTOR(r);
    00140				Filin = Filin.NextLink;
    00141			}
    00142		}*/
    00143	}
    00144
    00145	STATE STA_WaitLoose
    00146	{
    00147		EVENT Timer()
    00148		{
    00149			LOCAL Rotator r;
    00150			LOCAL Vector Up;
    00151			LOCAL CineRopeLink Filin;
    00152			LOCAL int i;
    00153
    00154			Up = Location;
    00155			Filin= PremierFilin;
    00156			TimeStamp+=IAPeriod; //dt;
    00157			for (i=0;i<LinkNumber;i++)
    00158			{
    00159				r = Filin.Rotation;
    00160				r.Pitch += 0.05 *( -16384 + (i+3)*180*cos(TimeStamp*3+i*0.3+i*i)-r.Pitch);
    00161				r.Yaw += 0.05 *( (i+3)*180*sin(TimeStamp*2+i*0.3)-r.Yaw);
    00162				Filin.SetRotation( r );
    00163				Filin.SetLocation( Up+0.5*LinkRealLength*VECTOR(r));
    00164				Up += LinkRealLength*VECTOR(r);
    00165				Filin = Filin.NextLink;
    00166			}
    00167		}
    00168	}
    00169
    00170	STATE STA_Tight
    00171	{
    00172		EVENT Timer()
    00173		{
    00174			LOCAL Rotator r;
    00175			LOCAL Vector Up;
    00176			LOCAL CineRopeLink Filin;
    00177			LOCAL int i;
    00178
    00179			Up = Location;
    00180			Filin= PremierFilin;
    00181			TimeStamp+=IAPeriod; //dt;
    00182			for (i=0;i<LinkNumber;i++)
    00183			{
    00184				r.Pitch = ( ( -16384 - Filin.Rotation.Pitch + 32768 ) & 65535 ) - 32768;
    00185				r.Yaw = ( ( -Filin.Rotation.Yaw + 32768 ) & 65535 ) - 32768;
    00186				r.Roll = ( ( -Filin.Rotation.Roll + 32768 ) & 65535 ) - 32768;
    00187				r = r*0.15 + Filin.Rotation;
    00188
    00189				Filin.SetRotation( r );
    00190				Filin.SetLocation( Up+0.5*LinkRealLength*VECTOR(r));
    00191				Up += LinkRealLength*VECTOR(r);
    00192				Filin = Filin.NextLink;
    00193			}
    00194		}
    00195	}
    00196
    00197	STATE STA_Break
    00198	{
    00199		EVENT BeginState( )
    00200		{
    00201			// Keep 5 links alive, kill the others
    00202			LOCAL CineRopeLink Filin, FilinSuivant;
    00203			LOCAL int i;
    00204
    00205			Filin=PremierFilin;
    00206			while (Filin!=none)
    00207			{
    00208				i++;
    00209
    00210				FilinSuivant=Filin.NextLink;
    00211				if (i==4)
    00212					Filin.NextLink=None;
    00213				else
    00214					if (i>4)
    00215						Filin.Destroy();
    00216				Filin=FilinSuivant;
    00217			}
    00218		}
    00219
    00220	//	EVENT Tick( float dt )
    00221		EVENT Timer()
    00222		{
    00223			LOCAL Rotator r;
    00224			LOCAL Vector Up;
    00225			LOCAL CineRopeLink Filin;
    00226			LOCAL int i;
    00227
    00228			Up = Location;
    00229			Filin= PremierFilin;
    00230			TimeStamp+=IAPeriod; //dt;
    00231			for (i=0;i<4;i++)
    00232			{
    00233				r = Filin.Rotation;
    00234				r.Pitch += 0.05 *( -16384 + (i+20)*180*cos(TimeStamp*3+i*0.3+i*i)-r.Pitch);
    00235				r.Yaw += 0.05 *( (i+20)*180*sin(TimeStamp*2+i*0.3)-r.Yaw);
    00236
Filin.SetRotation( r ); 00237 Filin.SetLocation( Up+0.5*LinkRealLength*VECTOR(r)); 00238 Up += LinkRealLength*VECTOR(r); 00239 Filin = Filin.NextLink; 00240 } 00241 } 00242 } 00243 00244 EVENT Destroyed() 00245 { 00246 LOCAL CineRopeLink Filin, FilinSuivant; 00247 00248 Filin=PremierFilin; 00249 while (Filin!=none) 00250 { 00251 FilinSuivant=Filin.NextLink; 00252 Filin.Destroy(); 00253 Filin=FilinSuivant; 00254 } 00255 00256 } 00257 00258 00259 00260 00261 defaultproperties 00262 { 00263 Texture=Texture'XIDCine.Rock_ico' 00264 }

End Source Code