public override void Click(Entity entity, ItemStack item) { if (!(entity is CharacterEntity)) { // TODO: Non-character support? return; } CharacterEntity character = (CharacterEntity)entity; double range = RangeBase * item.GetAttributeF("range_mod", 1f); double strength = StrengthBase * item.GetAttributeF("strength_mod", 1f) * GetStrength(); Location start = character.GetEyePosition(); // TODO: ItemPosition? Location forw = character.ForwardVector(); Location mid = start + forw * range; // TODO: base the pull on extent of the entity rather than its center. IE, if the side of a big ent is targeted, it should be rotated by the force. List <Entity> ents = character.TheRegion.GetEntitiesInRadius(mid, range); foreach (Entity ent in ents) { if (ent is PhysicsEntity) // TODO: Support for primitive ents? { PhysicsEntity pent = (PhysicsEntity)ent; Location rel = (start - ent.GetPosition()); double distsq = rel.LengthSquared(); if (distsq < 1) { distsq = 1; } pent.ApplyForce((rel / distsq) * strength); } } }
private void SimulateWind() { // Calculate wind intensity fluctuation by the settings float windIntensityFluctuation = settingsWindIntensityFluctuation / 1000.0f; float windDirectionFluctuation = settingsWindDirectionFluctuation / 1000.0f; // Constant wind float constantWind = sngConstantWind.GenerateNext_Between0And1(windIntensityFluctuation); constantWind /= 2.0f; constantWind *= (settingsWindIntensity / 2.0f); // Wind gust float windGust = sngWindGust.GenerateNext_OnlyPositive(windIntensityFluctuation * 3.0f); windGust *= settingsWindIntensity; totalWindIntensity = constantWind + windGust; float windDirectionChange = 5.0f * sngWindDirectionFluctuation.GenerateNext(windDirectionFluctuation); currentWindDirectionAngle = settingsWindDirection + windDirectionChange; // Create a wind force vector with length 1 and rotate so the wind affects the multicopter from a certain direction windForceVector = MathHelper.RotateAroundAxis_Y( new Vector3(1.0f, 0.0f, 0.0f), new Vector3(), xna.MathHelper.ToRadians(currentWindDirectionAngle) ); windForceVector = MathHelper.RotateAroundAxis_X( windForceVector, new Vector3(), xna.MathHelper.ToRadians(windDirectionChange) ); // Generate oscillation of the multicopter arms torqueVector.X = sngAttitudeDisturbances.GenerateNext(Globals.RandomGenerator.Next(100, 300) / 10000.0f) / 250.0f; torqueVector.Y = sngAttitudeDisturbances.GenerateNext(Globals.RandomGenerator.Next(100, 300) / 10000.0f) / 300.0f; torqueVector.Z = sngAttitudeDisturbances.GenerateNext(Globals.RandomGenerator.Next(100, 300) / 10000.0f) / 250.0f; // Scale the direction vector with the intensity windForceVector = Vector3.Scale(windForceVector, totalWindIntensity); torqueVector = Vector3.Scale(torqueVector, totalWindIntensity + 0.5f); // Let the global wind force and torque affect the multicopter PhysicsEntity.ApplyForce(windForceVector, false); PhysicsEntity.ApplyTorque(torqueVector, false); // Sum up for debug display totalForceVector += windForceVector; }