home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Engine / Classes / KHinge.uc < prev    next >
Text File  |  2003-06-23  |  5KB  |  170 lines

  1. //=============================================================================
  2. // The Hinge joint class.
  3. //=============================================================================
  4.  
  5. #exec Texture Import File=Textures\S_KHinge.pcx Name=S_KHinge Mips=Off MASKED=1
  6.  
  7.  
  8. class KHinge extends KConstraint
  9.     native
  10.     placeable;
  11.  
  12. cpptext
  13. {
  14. #ifdef WITH_KARMA
  15.     virtual void KUpdateConstraintParams();
  16.     virtual void preKarmaStep(FLOAT DeltaTime);
  17. #endif
  18. }
  19.  
  20. // Spatial light effect to use.
  21. var(KarmaConstraint) enum EHingeType
  22. {
  23.     HT_Normal,
  24.     HT_Springy,
  25.     HT_Motor,
  26.     HT_Controlled
  27. } KHingeType;
  28.  
  29.  
  30. // SPRINGY - around hinge axis, default position being KDesiredAngle (below)
  31. var(KarmaConstraint) float KStiffness;
  32. var(KarmaConstraint) float KDamping;
  33.  
  34. // MOTOR - tries to achieve angular velocity
  35. var(KarmaConstraint) float KDesiredAngVel; // 65535 = 1 rotation per second
  36. var(KarmaConstraint) float KMaxTorque;
  37.  
  38. // CONTROLLED - achieve a certain angle
  39. // Uses AngularVelocity and MaxForce from above.
  40. // Within 'ProportionalGap' of DesiredAngle, 
  41. var(KarmaConstraint) float KDesiredAngle; // 65535 = 360 degrees
  42. var(KarmaConstraint) float KProportionalGap; // 65535 = 360 degrees
  43.  
  44. // This is the alternative 'desired' angle, and the bool that indicates whether to use it.
  45. // See ToggleDesired and ControlDesired below.
  46. var(KarmaConstraint) float KAltDesiredAngle; // 65535 = 360 degrees
  47. var                     bool  KUseAltDesired;
  48.  
  49. // output - current angular position of joint // 65535 = 360 degrees
  50. var const float KCurrentAngle;
  51.  
  52. // In this state nothing will happen if this hinge is triggered or untriggered.
  53. auto state Default
  54. {
  55. ignores Trigger, Untrigger;
  56.  
  57. }
  58.  
  59. // In this state, Trigger will cause the hinge type to change to HT_Motor.
  60. // Another trigger will toggle it to HT_Controlled, and it will try and maintain its current angle.
  61. state() ToggleMotor
  62. {
  63. ignores Untrigger;
  64.     function Trigger( actor Other, pawn EventInstigator )
  65.     {
  66.         //Log("ToggleMotor - Trigger");
  67.         if(KHingeType == HT_Motor)
  68.         {
  69.             KDesiredAngle = KCurrentAngle;
  70.             KUseAltDesired = False;
  71.             KHingeType = HT_Controlled;
  72.         }
  73.         else
  74.             KHingeType = HT_Motor;
  75.  
  76.         KUpdateConstraintParams();
  77.         KConstraintActor1.KWake(); // force re-enable of simulation on this actor.
  78.     }
  79.  
  80. Begin:
  81.     KHingeType = HT_Controlled;
  82.     KUseAltDesired = False;
  83.     KUpdateConstraintParams();
  84. }
  85.  
  86. // In this state, Trigger will turn motor on.
  87. // Untrigger will turn toggle it to HT_Controlled, and it will try and maintain its current angle.
  88. state() ControlMotor
  89. {
  90.     function Trigger( actor Other, pawn EventInstigator )
  91.     {
  92.         //Log("ControlMotor - Trigger");
  93.         if(KHingeType != HT_Motor)
  94.         {
  95.             KHingeType = HT_Motor;
  96.             KUpdateConstraintParams();
  97.             KConstraintActor1.KWake();
  98.         }
  99.     }
  100.  
  101.     function Untrigger( actor Other, pawn EventInstigator )
  102.     {
  103.         //Log("ControlMotor - Untrigger");
  104.         if(KHingeType == HT_Motor)
  105.         {
  106.             KDesiredAngle = KCurrentAngle;
  107.             KUseAltDesired = False;
  108.             KHingeType = HT_Controlled;
  109.             KUpdateConstraintParams();
  110.             KConstraintActor1.KWake();
  111.         }
  112.     }
  113.  
  114. Begin:
  115.     KHingeType = HT_Controlled;
  116.     KUseAltDesired = False;
  117.     KUpdateConstraintParams();
  118. }
  119.  
  120. // In this state a trigger will toggle the hinge between using KDesiredAngle and KAltDesiredAngle.
  121. // It will use whatever the current KHingeType is to achieve this, so this is only useful with HT_Controlled and HT_Springy.
  122. state() ToggleDesired
  123. {
  124. ignores Untrigger;
  125.  
  126.     function Trigger( actor Other, pawn EventInstigator )
  127.     {
  128.         //Log("ToggleDesired - Trigger");
  129.         if(KUseAltDesired)
  130.             KUseAltDesired = False;
  131.         else
  132.             KUseAltDesired = True;
  133.         //Log("UseAlt"$KUseAltDesired);
  134.         KUpdateConstraintParams();
  135.         KConstraintActor1.KWake();
  136.     }
  137. }
  138.  
  139. // In this state, trigger will cause the hinge to use KAltDesiredAngle, untrigger will caus it to use KAltDesiredAngle
  140. state() ControlDesired
  141. {
  142.     function Trigger( actor Other, pawn EventInstigator )
  143.     {
  144.         //Log("ControlDesired - Trigger");
  145.         KUseAltDesired = True;
  146.         //Log("UseAlt"$KUseAltDesired);
  147.         KUpdateConstraintParams();
  148.         KConstraintActor1.KWake();
  149.     }
  150.  
  151.     function Untrigger( actor Other, pawn EventInstigator )
  152.     {
  153.         //Log("ControlDesired - Untrigger");
  154.         KUseAltDesired = False;
  155.         //Log("UseAlt"$KUseAltDesired);
  156.         KUpdateConstraintParams();
  157.         KConstraintActor1.KWake();
  158.     }
  159. }
  160.  
  161. defaultproperties
  162. {
  163.     KHingeType=HT_Normal
  164.     KStiffness=50
  165.     KProportionalGap=8200
  166.     KUseAltDesired=False
  167.  
  168.     bDirectional=True
  169.     Texture=S_KHinge
  170. }