public Physic.Electrostatic_field real_to_screen(Physic.Electrostatic_field E_real) { Physic.Electrostatic_field E_screen = new Physic.Electrostatic_field(); E_screen.set_x ( real_to_screen( E1_real.get_x(), E1_screen.get_x(), E2_real.get_x(), E2_screen.get_x(), E_real.get_x()) ); E_screen.set_y ( real_to_screen( E1_real.get_y(), E1_screen.get_y(), E2_real.get_y(), E2_screen.get_y(), E_real.get_y()) ); E_screen.set_z ( real_to_screen( E1_real.get_z(), E1_screen.get_z(), E2_real.get_z(), E2_screen.get_z(), E_real.get_z()) ); E_screen.apply_to.set_x ( real_to_screen( E1_real.apply_to.get_x(), E1_screen.apply_to.get_x(), E2_real.apply_to.get_x(), E2_screen.apply_to.get_x(), E_real.apply_to.get_x()) ); E_screen.apply_to.set_y ( real_to_screen( E1_real.apply_to.get_y(), E1_screen.apply_to.get_y(), E2_real.apply_to.get_y(), E2_screen.apply_to.get_y(), E_real.apply_to.get_y()) ); E_screen.apply_to.set_z ( real_to_screen( E1_real.apply_to.get_z(), E1_screen.apply_to.get_z(), E2_real.apply_to.get_z(), E2_screen.apply_to.get_z(), E_real.apply_to.get_z()) ); return E_screen; }
public double Evaluate(Pod pod, Checkpoint t, Checkpoint t2, double time_to_target) { double new_score = 0; Checkpoint target; if (time_to_target == 0) { target = t; } else { target = t2; score += 500; } double distance_target = Math.Max(Physic.distance2(pod, target) - 50000, 0) * 0.0000001; //double triangle_area = Physic.triArea(future_pod, pod, target)*0.0001; //double dDistance = (distance_1_turn - distance_target) * -0.1; //while(angle_to_target > 180){angle_to_target = Math.Abs(angle_to_target - 360);} new_score -= distance_target - 10 * time_to_target; Console.Error.WriteLine("SCORE: " + score + "Distance" + distance_target); return(new_score); }
public virtual void Initialize() { ComponentFactory factory = new ComponentFactory(monoNet.Content); stage = new Stage(10, new Pool <Actor>(50, 10)); // TODO: LAYERS Actor serviceActor = stage.CreateActor(0); gameManager = serviceActor.AddComponent <GameManager>(); GameManager.screenDimensions = new Vector2(monoNet.GraphicsDevice.Viewport.Width, monoNet.GraphicsDevice.Viewport.Height); Physic physic = Physic.Instance; physic.collisionRules.Add(new MultiKey <int>(GameManager.physicsPlayerLayer, GameManager.physicsWeaponLayer), false); physic.collisionRules.Add(new MultiKey <int>(GameManager.physicsBulletLayer, GameManager.physicsBulletLayer), false); tiledBase = serviceActor.AddComponent <TiledBase>(); tiledBase.Set(monoNet.Content); hitboxLoader = new HitboxLoader(stage); tiledBase.OnCollisionHitboxLoaded += hitboxLoader.OnCollisionHitboxLoaded; camera = new Camera(monoNet.GraphicsDevice.Viewport); UI = new LevelUI(); }
protected virtual void Init() { moveSpeed = moveSpeedBase + increment; stats = GetComponent <CharacterStats>(); physic = GetComponent <Physic>(); gravity = GetComponent <Gravity>(); }
/// <summary> /// These can be specified in several different ways: /// ///1) actorDesc.density == 0, bodyDesc.mass > 0, bodyDesc.massSpaceInertia.magnitude() > 0 /// ///Here the mass properties are specified explicitly, there is nothing to compute. /// ///2) actorDesc.density > 0, actorDesc.shapes.size() > 0, bodyDesc.mass == 0, bodyDesc.massSpaceInertia.magnitude() == 0 /// ///Here a density and the shapes are given. From this both the mass and the inertia tensor is computed. /// ///3) actorDesc.density == 0, actorDesc.shapes.size() > 0, bodyDesc.mass > 0, bodyDesc.massSpaceInertia.magnitude() == 0 /// ///Here a mass and shapes are given. From this the inertia tensor is computed. /// ///Other combinations of settings are illegal. /// </summary> /// <param name="node"></param> /// <param name="dynamic"></param> /// <param name="shapeBuilder"></param> /// <param name="density"></param> /// <param name="mass"></param> /// <returns></returns> public Actor CreateActor(Physic physic, bool dynamic, Func <Frame, ActorShapeDesc> shapeBuilder, float density = 0, float mass = 0) { if (physic != null) { throw new NullReferenceException("Physics"); } ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass); if (shapeBuilder != null) { foreach (var child in EnumerateNodesPosOrden()) { var shapeDesc = shapeBuilder(child); if (shapeDesc != null) { actorDesc.Shapes.Add(shapeDesc); } } } var actor = physic.CreateActor(actorDesc); this.BindTo(actor); return(actor); }
protected virtual void Init() { physic = GetComponent <Physic>(); if (physic) { physic.HitActionEffects += ImpactCheck; } }
public void ShiftCheck() { if (Math.Abs(shift) >= Physic.CellWidth) { Physic.CheckGridBat(); shift = 0; } }
void Update() { result1 = Math.HeronsFormula(5, 2, 6, 7); result2 = Physic.Frequency(6); result3 = Mechanic.ResultantForce(500, 700); result4 = TechnicalDrawing.Tolerance1(5, 3); result5 = MaterialsScience.KFactor(50, 70); result6 = General.BMI(70f, 1.83f); }
public Magnetostatic_field(Physic.Position pos) { this.Km=cst.Km; this.set_x(0); this.set_y(0); this.set_z(0); this.apply_to.set_x( pos.get_x() ); this.apply_to.set_y( pos.get_y() ); this.apply_to.set_z( pos.get_z() ); }
public Electrostatic_field(Physic.Position pos) { this.Ke=cst.Ke; this.set_x(0); this.set_y(0); this.set_z(0); this.apply_to.set_x( pos.get_x() ); this.apply_to.set_y( pos.get_y() ); this.apply_to.set_z( pos.get_z() ); }
public void ShouldCorrectlyProjectVectorOntoAnother3() { // Arrage var vector = new Vector2(2, 1); var projectionVector = new Vector2(-1, 0); // Act var projectedVector = Physic.ProjectVector(vector, projectionVector); // Assert var expectedVector = new Vector2(2, 0); Assert.AreEqual(projectedVector, expectedVector); }
public void ShouldCorrectlyProjectVectorOntoAnother4() { // Arrage var vector = new Vector2(0.55242717280199, 0.55242717280199); var projectionVector = Vector2.UP_VECTOR; // Act var projectedVector = Physic.ProjectVector(vector, projectionVector); // Assert var expectedVector = new Vector2(0, 0.55242717280199); Assert.AreEqual(projectedVector, expectedVector); }
public void ShouldCorrectlyCalculateParallelVectorToNormal3() { // Arrage var vector = new Vector2(-1, -1); var normalvector = new Vector2(1, 0); // Act var parallelVector = Physic.GetParallelVectorToNormal(vector, normalvector); // Assert var expectedVector = new Vector2(0, -1); Assert.AreEqual(parallelVector.X, expectedVector.X, 0.0001); Assert.AreEqual(parallelVector.Y, expectedVector.Y, 0.0001); }
public override void Start() { this.AddComponentsFromArchetype("Wall"); Metadata mC = this.GetComponent <Metadata>(); mC.Name = "Ship hull"; mC.Description = "Thick metal plates, just inbetween space and you."; Physic pC = this.GetComponent <Physic>(); pC.PassThrough = false; RenderComp rC = this.GetComponent <RenderComp>(); rC.Char = '#'; rC.Foreground = Color4.LightGray; }
public void ShouldCorrectlyRotateVectorByNegativeAngle() { // Arrage var vector = new Vector2(0, -3); var angle = Math.PI / -2; // Act var rotatedVector = Physic.RotateVector(vector, angle); // Assert var expectedVector = new Vector2(-3, 0); Assert.AreEqual(rotatedVector.X, expectedVector.X, 0.0001); Assert.AreEqual(rotatedVector.Y, expectedVector.Y, 0.0001); }
public void ShouldCorrectlyProjectVectorOntoAnother2() { // Arrage var vector = new Vector2(-2, -1); var projectionVector = new Vector2(-1, 1); // Act var projectedVector = Physic.ProjectVector(vector, projectionVector); // Assert var expectedVector = new Vector2(-0.5, 0.5); Assert.AreEqual(projectedVector.X, expectedVector.X, 0.0001); Assert.AreEqual(projectedVector.Y, expectedVector.Y, 0.0001); }
public void ShouldCorrectlyCalculateParallelVectorToNormal4() { // Arrage var vector = new Vector2(0, 3); var normalvector = new Vector2(-1, -1); // Act var parallelVector = Physic.GetParallelVectorToNormal(vector, normalvector); // Assert var expectedVector = Vector2.Normalize(new Vector2(-1, 1)) * ((vector.Length() * Math.Sqrt(2)) / 2); Assert.AreEqual(parallelVector.X, expectedVector.X, 0.0001); Assert.AreEqual(parallelVector.Y, expectedVector.Y, 0.0001); }
public void ShouldCorrectlyRotateVector1() { // Arrage var vector = new Vector2(10, 0); var angle = Math.PI / 4; // Act var rotatedVector = Physic.RotateVector(vector, angle); // Assert var expectedVector = Vector2.Normalize(new Vector2(1, 1)) * vector.Length(); Assert.AreEqual(expectedVector.X, rotatedVector.X, 1e-6); Assert.AreEqual(expectedVector.Y, rotatedVector.Y, 1e-6); }
public void ShouldCalculateParallelVectorToIntersectionNormal2() { // Arrage var movementVector = new Vector2(-3, 3); var intersectionDistance = Math.Sqrt(2); var intersectionNormal = new Vector2(-1, 0); // Act var parallelVector = Physic.GetLeftParallelVectorToIntersectionNormal(movementVector, intersectionDistance, intersectionNormal); // Assert var expectedVector = Vector2.Normalize(new Vector2(0, 1)) * (((movementVector.Length() - intersectionDistance) * Math.Sqrt(2)) / 2); Assert.AreEqual(parallelVector.X, expectedVector.X, 0.0001); Assert.AreEqual(parallelVector.Y, expectedVector.Y, 0.0001); }
public Vehicle(Actor actor, PhysicMaterial carMaterial = null, VehicleMotor motor = null, VehicleGears gears = null) { if (actor == null) { throw new ArgumentNullException("actor"); } _transmissionEfficiency = 1.0f; _differentialRatio = 1.0f; _maxVelocity = 80; _bodyActor = actor; _scene = actor.Scene; _carMaterial = carMaterial; _bodyActor.SleepEnergyThreshold = 0.05f; _vehicleMotor = motor; _vehicleGears = gears; if (carMaterial == null) { PhysicMaterialDesc matDesc = new PhysicMaterialDesc(); matDesc.DynamicFriction = 0.4f; matDesc.StaticFriction = 0.4f; matDesc.Restitution = 0; _carMaterial = actor.Scene.CreateMaterial(matDesc); _carMaterial.FrictionCombineMode = CombineMode.MULTIPLY; } foreach (var shape in actor.Shapes) { if (shape.Material.Index == 0) { shape.Material = _carMaterial; } if (shape is WheelShape) { RayCastWheel wheel = new RayCastWheel((WheelShape)shape); _wheels.Add(wheel); } } _bodyActor.UserData = this; _motorForce = 0; SetDefaulValues(); Control(0, true, 0, true, false); }
public Electrostatic_field(Charge chg,Physic.Position pos) { this.Ke=cst.Ke; // E stands for Electrostatic_field float d = chg.get_position().distance(pos); float X = (pos-chg.get_position()).get_x(); float Y = (pos-chg.get_position()).get_y(); float Z = (pos-chg.get_position()).get_z(); this.set_x( Ke * chg.get_charge() / ((float) System.Math.Pow(d,n+1))* X ); this.set_y( Ke * chg.get_charge() / ((float) System.Math.Pow(d,n+1))* Y ); this.set_z( Ke * chg.get_charge() / ((float) System.Math.Pow(d,n+1))* Z ); this.apply_to.set_x( pos.get_x() ); this.apply_to.set_y( pos.get_y() ); this.apply_to.set_z( pos.get_z() ); }
public Actor CreateActor(Physic physic, bool dynamic, ActorShapeDesc[] shapes, float density = 0, float mass = 0) { if (physic != null) { throw new ArgumentNullException("physic"); } ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass); foreach (var item in shapes) { actorDesc.Shapes.Add(item); } var actor = physic.CreateActor(actorDesc); this.BindTo(actor); return(actor); }
public double move(double t, Checkpoint target) { double time = 0; double go_next = 0; while (time < t) { x += vx * 0.1; y += vy * 0.1; if (go_next == 0) { if (Physic.distance2(this, target) < 250000) { go_next = time + 0.1; } } time += 0.1; } return(go_next); }
public Actor CreateActor(Physic physic, bool dynamic, float density = 0, float mass = 0) { if (physic == null) { throw new ArgumentNullException("physic"); } ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass); if (_nodeObject is IFrameMesh || _nodes.Count == 1) { ActorShapeDesc shapeDesc = _CreateShapeDescriptor(Matrix.Identity); if (shapeDesc is WheelShapeDesc) { //Matrix pose = Matrix.Identity; //pose.set_Rows(3, shapeDesc.LocalPose.get_Rows(3)); //shapeDesc.LocalPose = pose; //pose.set_Rows(3, actorDesc.GlobalPose.get_Rows(3)); //actorDesc.GlobalPose = pose; actorDesc.GlobalPose = Matrix.RotationZ(-Numerics.PIover2) * actorDesc.GlobalPose; } if (shapeDesc != null) { if (density == 0 && dynamic) { shapeDesc.Mass = 1.0f; } actorDesc.Shapes.Add(shapeDesc); } } else { foreach (var child in _nodes) { ActorShapeDesc shapeDesc = child._CreateShapeDescriptor(child.LocalPose); if (shapeDesc != null) { if (shapeDesc is WheelShapeDesc) { //Matrix pose = Matrix.Identity; //pose.set_Rows(3, shapeDesc.LocalPose.get_Rows(3)); //shapeDesc.LocalPose = pose; shapeDesc.LocalPose = Matrix.RotationZ(-Numerics.PIover2) * shapeDesc.LocalPose; } if (density == 0 && dynamic) { var match = Regex.Match(child._tag, @"__m(?<X>\d+)((\.|_)(?<Y>\d+))?__"); if (match.Success) { shapeDesc.Mass = float.Parse(match.Groups["X"].Value + "." + match.Groups["Y"].Value); } } actorDesc.Shapes.Add(shapeDesc); } } } if (actorDesc.Shapes.Count == 0) { throw new InvalidOperationException("There are any shape present and it is not allowed create a empty actor"); } var actor = physic.CreateActor(actorDesc); this.BindTo(actor); return(actor); }
private void Awake() { physic = GetComponent <Physic>(); force = GameManager.instance.GravityForce; direction = GameManager.instance.GravityDirection; }
public override void AddConstraint(Physic.Constraints.IPhysicConstraint ctn) { if (ctn is BulletConstraint) { BulletConstraint BulletConstraint = ctn as BulletConstraint; world.AddConstraint(BulletConstraint.Constraint,BulletConstraint.DisableCollisionsBetweenLinkedBodies); } ctns.Add(ctn); }
public override void RemoveConstraint(Physic.Constraints.IPhysicConstraint ctn) { if (ctn is BulletConstraint) { BulletConstraint BulletConstraint = ctn as BulletConstraint; world.RemoveConstraint(BulletConstraint.Constraint); } ctns.Remove(ctn); }
//private int mode = 0; // E=0 B=1 public void set_position(Physic.Position position) { m_position = position; }
public Physic.Electrostatic_field screen_to_real(Physic.Electrostatic_field E_screen) { Physic.Electrostatic_field E_real = new Physic.Electrostatic_field(); E_real.set_x ( screen_to_real( E1_screen.get_x(), E1_real.get_x(), E2_screen.get_x(), E_real.get_x(), E_screen.get_x()) ); E_real.set_y ( screen_to_real( E1_screen.get_y(), E1_real.get_y(), E2_screen.get_y(), E_real.get_y(), E_screen.get_y()) ); E_real.set_z ( screen_to_real( E1_screen.get_z(), E1_real.get_z(), E2_screen.get_z(), E_real.get_z(), E_screen.get_z()) ); E_real.apply_to.set_x ( screen_to_real( E1_screen.apply_to.get_x(), E1_real.apply_to.get_x(), E2_screen.apply_to.get_x(), E_real.apply_to.get_x(), E_screen.apply_to.get_x()) ); E_real.apply_to.set_y ( screen_to_real( E1_screen.apply_to.get_y(), E1_real.apply_to.get_y(), E2_screen.apply_to.get_y(), E_real.apply_to.get_y(), E_screen.apply_to.get_y()) ); E_real.apply_to.set_z ( screen_to_real( E1_screen.apply_to.get_z(), E1_real.apply_to.get_z(), E2_screen.apply_to.get_z(), E_real.apply_to.get_z(), E_screen.apply_to.get_z()) ); return E_real; }
public Charge(float charge, Physic.Position position, float radius) { this.m_charge = charge; this.m_position = position; this.m_radius = radius; }