private void makeSpring(NodeInfo node1, NodeInfo node2, SpringType springType) { SpringInfo newSpringInfo = new SpringInfo(); newSpringInfo.Node1 = node1; newSpringInfo.Node2 = node2; newSpringInfo.SpringType = springType; springs.Add(newSpringInfo); if (initSpringRenderers == true) { GameObject nodeRender = (GameObject)Instantiate(debugRenderer, Vector3.zero, Quaternion.identity); LineDraw nodeDraw = nodeRender.GetComponent <LineDraw>(); nodeDraw.vertices.Add(node1.WorldPosition); nodeDraw.vertices.Add(node2.WorldPosition); nodeDraw.colorStart = Color.white; nodeDraw.colorEnd = Color.red; nodeRender.transform.parent = transform; springLineRenderers[newSpringInfo] = nodeDraw; } }
/// <summary> /// Change the spring types to the specified type. /// </summary> /// <param name="type">The type to change the value to.</param> private void ChangeSpringType(SpringType type) { // Don't switch types if the type is equal to the current type or if the enable state event is active. This will occur if a new button is pressed // within the time that it takes to invoke the scheduled event. if (m_SpringType == type || m_EnableStateEvent != null) { return; } // Reset the button color and deactivate the previous character. The same character may be activated again depending on the spring type. if (m_SpringType != SpringType.None) { SetButtonColor((int)m_SpringType, m_NormalColor); if (m_ActiveCharacter != null) { m_ActiveCharacter.GetCachedComponent <UltimateCharacterLocomotion>().SetActive(false); StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SpringType), m_SpringType), false); } } // Remember the old spring type and activate the new. The button should reflect the selected spring type. var prevSpringType = m_SpringType; m_SpringType = type; SetButtonColor((int)m_SpringType, m_PressedColor); // If the previous spring type isn't None then a button was pressed. Activate the new character. if (prevSpringType != SpringType.None) { var prevCharacter = m_ActiveCharacter; // The active character depends on the spring type. if (m_SpringType == SpringType.Astronaut || m_SpringType == SpringType.DrunkPerson) { m_ActiveCharacter = m_DrunkAstronautCharacter; } else if (m_SpringType == SpringType.Giant) { m_ActiveCharacter = m_GiantCharacter; } else { m_ActiveCharacter = m_Character; } // Activate the correct character and set the camera to the character if that character changed. This shouldn't be done if the character didn't // change so the camera doesn't snap into position. var characterChange = m_ActiveCharacter != prevCharacter; m_ActiveCharacter.GetCachedComponent <UltimateCharacterLocomotion>().SetActive(true); if (characterChange) { m_CameraController.Character = m_ActiveCharacter; } // Wait a small amount of time if the springs are off so the item can get back into the correct position while the springs are enabled. m_EnableStateEvent = Scheduler.Schedule(m_SpringType == SpringType.SpringsOff ? 0.4f : 0, EnableSpringState, characterChange); } EnableInput(); }
/// <summary> /// Initializes a new instance of the <see cref="Spring" /> class. /// </summary> /// <param name="variableService">The variable service.</param> /// <param name="resourceService">The resource service.</param> public Spring(IVariableService variableService, IResourceService resourceService, IAudioService audioService) : base(variableService, resourceService) { if (resourceService == null) { throw new ArgumentNullException(nameof(resourceService)); } if (variableService == null) { throw new ArgumentNullException(nameof(variableService)); } if (audioService == null) { throw new ArgumentNullException(nameof(audioService)); } _variableService = variableService; _resourceService = resourceService; _audioService = audioService; _resourceService.PreloadResource <Sprite>("spring"); _resourceService.PreloadResource <Sound>("spring"); _springType = SpringType.Red; _isOpen = false; }
public ClothConstraint(ClothPoint p1, ClothPoint p2, float restLength, SpringType type) { this.p1 = p1; this.p2 = p2; this.restLength = restLength; this.type = type; }
/// <summary> /// Sets entity properties from a key/value dictionary. /// </summary> /// <param name="properties">Dictionary containing the properties.</param> public override void SetProperties(IDictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } string val; if (properties.TryGetValue("direction", out val)) { Direction dir; if (!Enum.TryParse(val, out dir)) { dir = Direction.Up; } _direction = dir; } if (properties.TryGetValue("spring_type", out val)) { SpringType sType; if (!Enum.TryParse(val, out sType)) { sType = SpringType.Red; } _springType = sType; } base.SetProperties(properties); }
public CatchableRopeService(int nrOfMasses, Vector3 initialPos, float springConstant, float springLength, float springFrictionConstant, bool isCollide, Vector3 rigidSize, SpringType springType, RigidType rigidType) : base(springConstant, springLength, springFrictionConstant, null, springType) { this._nrOfMasses = nrOfMasses; this._initialPos = initialPos; this._isCollide = isCollide; this._normalLength = springLength; this._rigidSize = rigidSize; this._rigidType = rigidType; this.IsVisible = false; this.Masses = DefaultAdder.GetMassesRope(2, _initialPos, null, _rigidSize, this._normalLength, this._rigidType, this._isCollide); this.Masses[0].TextureType = TextureType.Pin; this.Masses[0].IsDrawable = true; this.Masses[0].IsFixedRigid = true; BuildSprings(springConstant, springLength, springFrictionConstant); //this.Radius = radius; SetPinRingFirstTime(); }
public SpringEventConfig(string animationEvent, Vector3 force, int frames, SpringType type) { AnimationEvent = animationEvent; Force = force; Frames = frames; Type = type; }
void bAddRope_Click(object sender, EventArgs e) { try { StaticData.ManipulationGameMode = ManipulationGameMode.AddRopesMode; int nrOfMasses = (int)UIControlsParser.GetFloat(tbNrOfMasses); float springConstant = UIControlsParser.GetFloat(tbSpringConstant); float normalLength = UIControlsParser.GetFloat(tbNormalLength); float springInnerFriction = UIControlsParser.GetFloat(tbSpringInnerFriction); Vector3 initialPosition = UIControlsParser.GetVector3(tbPositionRope); RigidType rigidType = (RigidType)UIControlsParser.GetIndexOfSelection(ddTypeRigidRope); Vector3 rigidSize = UIControlsParser.GetVector3(tbRigidSizeRope); bool isCollidable = cbIsCollidableRope.Checked; SpringType type = (SpringType)UIControlsParser.GetIndexOfSelection(cbSpringType); if (rigidSize != Vector3.Zero) { StaticData.EngineManager.SpringsManagerEngine.AddNewService( DefaultAdder.GetDefaultSpringRope(initialPosition, StaticData.EngineManager.CookieRB.PositionXNA, nrOfMasses, springConstant, normalLength, springInnerFriction, rigidType, rigidSize, isCollidable, type)); } } catch (Exception) { } }
public void SetDampingConstant(Widget widget, SpringType type, float dampingConstant) { this.SetValue(widget, type, dampingConstant, delegate(Widget w, SpringType t, float value) { value = FMath.Clamp(value, 0f, 1f); this.widgetInfos[w].dampingConstants[(int)t] = -10f * value; }); }
public float GetDisplacement(Widget widget, SpringType type) { if (this.widgetInfos.ContainsKey(widget) && type != SpringType.All) { return(this.widgetInfos[widget].displacements[(int)type]); } return(0f); }
public void SetDisplacement(Widget widget, SpringType type, float displacement) { this.SetValue(widget, type, displacement, delegate(Widget w, SpringType t, float value) { this.widgetInfos[w].displacements[(int)t] = value; this.widgetInfos[w].useSpecifiedValues[(int)t] = true; }); }
public void SetSpringConstant(Widget widget, SpringType type, float springConstant) { this.SetValue(widget, type, springConstant, delegate(Widget w, SpringType t, float value) { value = FMath.Clamp(value, 0f, 1f); this.widgetInfos[w].springConstants[(int)t] = 4f * value + 1f; this.widgetInfos[w].springLimitations[(int)t] = 1f - FMath.Pow(value, 5f); }); }
public void SetSpringValues(SpringType type, float bias, float softness) { for (int i = 0; i < springs.Count; i++) { if ((springs[i].SpringType & type) != 0) { springs[i].Softness = softness; springs[i].BiasFactor = bias; } } }
Spring CreateSpring(Particle a, Particle b, float ks, float kd, SpringType type) { Spring spring = new Spring(); spring.particleA = a; spring.particleB = b; spring.stiffness = ks; spring.damping = kd; spring.restLength = (a.position - b.position).magnitude; spring.type = type; return(spring); }
private void SetValue(Widget widget, SpringType type, float value, Action <Widget, SpringType, float> setAction) { foreach (Widget current in this.Children) { if (widget == null || widget == current) { foreach (SpringType springType in Enum.GetValues(typeof(SpringType))) { if ((type == SpringType.All || type == springType) && this.widgetInfos.ContainsKey(current)) { setAction.Invoke(current, springType, value); } } } } }
public static CatchableRopeService GetDefaultCatchableRope(Vector3 initialPosition, Vector3?targetPos, int nrOfMasses, float springConstant, float normalLength, float springInnerFriction, RigidType type, Vector3 rigidSize, bool isCollidable, SpringType springType) { //List<RigidBody> masses = GetMassesRope(nrOfMasses, initialPosition, targetPos, rigidSize, normalLength, type, isCollidable); CatchableRopeService springService = new CatchableRopeService(nrOfMasses, initialPosition, springConstant, // springConstant In The Rope normalLength, // Normal Length Of Springs In The Rope springInnerFriction, // Spring Inner Friction Constant isCollidable, rigidSize, springType, type); return(springService); }
public SpringService(float springConstant, float springLength, float springFrictionConstant, List <RigidBody> masses, SpringType type // how stiff the springs are // the length that a spring does not exert any force // inner friction constant of spring ) //The super class creates masses with weights m of each { this.SpringType = type; this.Masses = masses; this.SpringConstant = springConstant; this.SpringLength = springLength; this.SpringFrictionConstant = springFrictionConstant; //this.RopeConnectionPos = Masses[0].PositionXNA; this.Id = StaticData.EngineManager.SpringsManagerEngine.GetNextRopeId(); if (!(this is CatchableRopeService)) { this.Masses[0].TextureType = TextureType.Pin; if (SpringType == SpringType.StrictRope) { this.Masses[0].IsFixedRigid = true; } BuildSprings(springConstant, springLength, springFrictionConstant); } }
public Spring(SpringType t, int id) { type = t; unique_id = id; }
//The Range x and Range y variables control how far away and in which direction this method should look for a particle public static spring GetSpring(int x, int y, int rows, out int connectedParticleIndex, int rangeX, int rangeY, ClothSimulator.SpringVariables vars, SpringType type) { spring Spring = new spring(); Spring.connectionA = y + (x * rows); Spring.connectionB = (y + ((x + rangeX) * rows) + rangeY); Spring.stiffness = vars.stiffness; Spring.damping = vars.damping; Spring.springType = (int)type; Spring.restLength = Vector3.Distance(GetParticlePos((x * rows), y, rows), GetParticlePos((x + rangeX) * rows, y + rangeY, rows)); connectedParticleIndex = (y + ((x + rangeX) * rows) + rangeY); return(Spring); }
public Spring(Node a, Node b, SpringType s) { nodeA = a; nodeB = b; springType = s; }
private float CalculateExternalAcceleration(LiveSpringPanel.WidgetInfo info, SpringType type) { float acceleration = 0f; switch (type) { case SpringType.AngleAxisX: case SpringType.PositionY: acceleration = this.sensorAcceleration.Y + this.moveAcceleration.Y + this.userAcceleration.Y; break; case SpringType.AngleAxisY: acceleration = -(this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X); break; case SpringType.AngleAxisZ: { bool flag = false; bool[] useSpecifiedValues = info.useSpecifiedValues; for (int i = 0; i < useSpecifiedValues.Length; i++) { bool flag2 = useSpecifiedValues[i]; flag |= flag2; } if (!flag) { float num = info.displacements[3]; float num2 = info.displacements[4]; float num3 = FMath.Abs(num); float num4 = FMath.Abs(num2); bool flag3; if (num * num2 > 0f) { flag3 = (num3 > num4); } else { flag3 = (num3 < num4); } float num5 = FMath.Min(FMath.Abs(num3 - num4), FMath.Min(num3, num4)) / 200f; float num6 = flag3 ? num5 : (-num5); float num7 = info.displacements[0]; float num8 = info.displacements[1]; float num9 = FMath.Abs(num7); float num10 = FMath.Abs(num8); if (-num7 * num8 > 0f) { flag3 = (num9 < num10); } else { flag3 = (num9 > num10); } num5 = FMath.Min(FMath.Abs(num9 - num10), FMath.Min(num9, num10)) / 20f; float num11 = flag3 ? num5 : (-num5); acceleration = num6 + num11; } break; } case SpringType.PositionX: acceleration = this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X; break; case SpringType.PositionZ: acceleration = this.sensorAcceleration.Z + this.moveAcceleration.Z + this.userAcceleration.Z; break; } if (type == SpringType.PositionX || type == SpringType.PositionY || type == SpringType.PositionZ) { return(this.ClipAcceleration(acceleration)); } return(this.ClipAcceleration(acceleration) * 0.0125663709f); }