예제 #1
0
        public JointVehicleMotor ConnectWheel(VehiclePartEntity wheel, bool driving, bool powered, double susp)
        {
            TheRegion.AddJoint(new ConstWheelStepUp(wheel, wheel.StepHeight));
            wheel.SetFriction(2.5f);
            Vector3         left             = BEPUutilities.Quaternion.Transform(new Vector3(-1, 0, 0), wheel.GetOrientation());
            Vector3         up               = BEPUutilities.Quaternion.Transform(new Vector3(0, 0, 1), wheel.GetOrientation());
            JointSlider     pointOnLineJoint = new JointSlider(this, wheel, -new Location(up));
            JointLAxisLimit suspensionLimit  = new JointLAxisLimit(this, wheel, 0f, susp, wheel.GetPosition(), wheel.GetPosition(), -new Location(up));
            JointPullPush   spring           = new JointPullPush(this, wheel, -new Location(up), true);

            if (driving)
            {
                JointSpinner spinner = new JointSpinner(this, wheel, new Location(-left));
                TheRegion.AddJoint(spinner);
            }
            else
            {
                JointSwivelHinge swivelhinge = new JointSwivelHinge(this, wheel, new Location(up), new Location(-left));
                TheRegion.AddJoint(swivelhinge);
            }
            TheRegion.AddJoint(pointOnLineJoint);
            TheRegion.AddJoint(suspensionLimit);
            TheRegion.AddJoint(spring);
            JointNoCollide jnc = new JointNoCollide(this, wheel);

            TheRegion.AddJoint(jnc);
            if (powered)
            {
                JointVehicleMotor motor = new JointVehicleMotor(this, wheel, new Location(driving ? left : up), !driving);
                TheRegion.AddJoint(motor);
                return(motor);
            }
            return(null);
        }
예제 #2
0
        public JointVehicleMotor ConnectWheel(VehiclePartEntity wheel, bool driving, bool powered)
        {
            wheel.SetFriction(2.5f);
            Vector3         left             = Quaternion.Transform(new Vector3(-1, 0, 0), wheel.GetOrientation());
            Vector3         up               = Quaternion.Transform(new Vector3(0, 0, 1), wheel.GetOrientation());
            JointSlider     pointOnLineJoint = new JointSlider(this, wheel, -new Location(up));
            JointLAxisLimit suspensionLimit  = new JointLAxisLimit(this, wheel, 0f, 0.1f, wheel.GetPosition(), wheel.GetPosition(), -new Location(up));
            JointPullPush   spring           = new JointPullPush(this, wheel, -new Location(up), true);

            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(wheel.Body, this.Body, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase); // TODO: How necessary is this? Should we replicate this clientside?
            if (driving)
            {
                JointSpinner spinner = new JointSpinner(this, wheel, new Location(-left));
                TheRegion.AddJoint(spinner);
            }
            else
            {
                JointSwivelHinge swivelhinge = new JointSwivelHinge(this, wheel, new Location(up), new Location(-left));
                TheRegion.AddJoint(swivelhinge);
            }
            TheRegion.AddJoint(pointOnLineJoint);
            TheRegion.AddJoint(suspensionLimit);
            TheRegion.AddJoint(spring);
            if (powered)
            {
                JointVehicleMotor motor = new JointVehicleMotor(this, wheel, new Location(driving ? left : up), !driving);
                TheRegion.AddJoint(motor);
                return(motor);
            }
            return(null);
        }
예제 #3
0
 public JointVehicleMotor ConnectWheel(VehiclePartEntity wheel, bool driving, bool powered)
 {
     wheel.SetFriction(2.5f);
     Vector3 left = Quaternion.Transform(new Vector3(-1, 0, 0), wheel.GetOrientation());
     Vector3 up = Quaternion.Transform(new Vector3(0, 0, 1), wheel.GetOrientation());
     JointSlider pointOnLineJoint = new JointSlider(this, wheel, -new Location(up));
     JointLAxisLimit suspensionLimit = new JointLAxisLimit(this, wheel, 0f, 0.1f, wheel.GetPosition(), wheel.GetPosition(), -new Location(up));
     JointPullPush spring = new JointPullPush(this, wheel, -new Location(up), true);
     BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(wheel.Body, this.Body, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase); // TODO: How necessary is this? Should we replicate this clientside?
     if (driving)
     {
         JointSpinner spinner = new JointSpinner(this, wheel, new Location(-left));
         TheRegion.AddJoint(spinner);
     }
     else
     {
         JointSwivelHinge swivelhinge = new JointSwivelHinge(this, wheel, new Location(up), new Location(-left));
         TheRegion.AddJoint(swivelhinge);
     }
     TheRegion.AddJoint(pointOnLineJoint);
     TheRegion.AddJoint(suspensionLimit);
     TheRegion.AddJoint(spring);
     if (powered)
     {
         JointVehicleMotor motor = new JointVehicleMotor(this, wheel, new Location(driving ? left : up), !driving);
         TheRegion.AddJoint(motor);
         return motor;
     }
     return null;
 }
예제 #4
0
        public void ConnectFlap(VehiclePartEntity flap, FDSSection flapDat)
        {
            JointBallSocket jbs = new JointBallSocket(this, flap, flap.GetPosition()); // TODO: necessity?

            TheRegion.AddJoint(jbs);
            JointNoCollide jnc = new JointNoCollide(this, flap);

            TheRegion.AddJoint(jnc);
            string      mode = flapDat.GetString("mode");
            VehicleFlap vf   = new VehicleFlap()
            {
                MaxAngle = flapDat.GetDouble("max_angle", 10).Value,
                Speed    = flapDat.GetDouble("corrective_speed", 2.25).Value
            };

            if (mode == "roll/l")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_RollL.Add(vf);
            }
            else if (mode == "roll/r")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_RollR.Add(vf);
            }
            else if (mode == "yaw")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(0, 0, 1));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(0, 0, 1), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_Yaw.Add(vf);
            }
            else if (mode == "pitch")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_Pitch.Add(vf);
            }
        }
예제 #5
0
 public VehiclePartEntityTag(VehiclePartEntity ent)
 {
     Internal = ent;
 }
예제 #6
0
 public void HandleWheels()
 {
     if (!hasWheels)
     {
         Model mod = TheServer.Models.GetModel(model);
         if (mod == null) // TODO: mod should return a cube when all else fails?
         {
             return;
         }
         Model3D scene = mod.Original;
         if (scene == null) // TODO: Scene should return a cube when all else fails?
         {
             return;
         }
         SetOrientation(Quaternion.Identity);
         List <Model3DNode>       nodes       = GetNodes(scene.RootNode);
         List <VehiclePartEntity> frontwheels = new List <VehiclePartEntity>();
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix      mat   = nodes[i].MatrixA;
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     mat   = tnode.MatrixA * mat;
                     tnode = tnode.Parent;
                 }
                 Location          pos   = GetPosition() + new Location(mat.M14, mat.M34, mat.M24) + offset; // NOTE: wtf happened to this matrix?
                 VehiclePartEntity wheel = new VehiclePartEntity(TheRegion, "vehicles/" + vehName + "_wheel", true);
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(Quaternion.Identity);
                 wheel.Gravity = Gravity;
                 wheel.CGroup  = CGroup;
                 wheel.SetMass(30);
                 wheel.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(wheel);
                 wheel.SetPosition(pos);
                 if (name.After("wheel").StartsWith("f"))
                 {
                     SteeringMotors.Add(ConnectWheel(wheel, false, true));
                     frontwheels.Add(wheel);
                 }
                 else if (name.After("wheel").StartsWith("b"))
                 {
                     DrivingMotors.Add(ConnectWheel(wheel, true, true));
                 }
                 else
                 {
                     ConnectWheel(wheel, true, false);
                 }
                 wheel.Body.ActivityInformation.Activate();
             }
         }
         if (frontwheels.Count == 2)
         {
             JointSpinner js = new JointSpinner(frontwheels[0], frontwheels[1], new Location(1, 0, 0));
             TheRegion.AddJoint(js);
         }
         hasWheels = true;
     }
 }
예제 #7
0
 public void HandleWheels()
 {
     if (!hasWheels)
     {
         string wheelsModFront  = SourceFile.GetString("vehicle.wheels.front.model");
         string wheelsModBack   = SourceFile.GetString("vehicle.wheels.back.model");
         double wheelsSuspFront = SourceFile.GetDouble("vehicle.wheels.front.suspension", 0.1).Value;
         double wheelsSuspBack  = SourceFile.GetDouble("vehicle.wheels.back.suspension", 0.1).Value;
         Model  mod             = TheServer.Models.GetModel(model);
         if (mod == null) // TODO: mod should return a cube when all else fails?
         {
             return;
         }
         Model3D scene = mod.Original;
         if (scene == null) // TODO: Scene should return a cube when all else fails?
         {
             return;
         }
         SetOrientation(BEPUutilities.Quaternion.Identity); // TODO: Track and reset orientation maybe?
         List <Model3DNode>       nodes       = GetNodes(scene.RootNode);
         List <VehiclePartEntity> frontwheels = new List <VehiclePartEntity>();
         Location centerOfMass = Location.Zero;
         double   mass         = 0;
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 centerOfMass += (new Location(mat.M41, -mat.M43, mat.M42) + offset) * 30; // TODO: Arbitrary constant
                 mass         += 30;                                                       // TODO: Arbitrary constant
             }
             else if (name.Contains("flap"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 centerOfMass += (new Location(mat.M41, -mat.M43, mat.M42) + offset) * 20; // TODO: Arbitrary constant
                 mass         += 20;                                                       // TODO: Arbitrary constant
             }
         }
         if (mass > 0)
         {
             centerOfMass /= mass;
         }
         Body.CollisionInformation.LocalPosition = -centerOfMass.ToBVector() - CenterOfMassOffset.ToBVector();
         ForceNetwork();
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 Location          pos   = GetPosition() + new Location(Body.CollisionInformation.LocalPosition) + new Location(mat.M41, -mat.M43, mat.M42) + offset; // TODO: matrix gone funky?
                 VehiclePartEntity wheel = new VehiclePartEntity(TheRegion, (name.After("wheel").Contains("f") ? wheelsModFront : wheelsModBack), true);
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(BEPUutilities.Quaternion.Identity);
                 wheel.Gravity = Gravity;
                 wheel.CGroup  = CGroup;
                 wheel.SetMass(30); // TODO: Arbitrary constant
                 wheel.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(wheel);
                 wheel.ForceNetwork();
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(BEPUutilities.Quaternion.Identity);
                 if (name.After("wheel").Contains("f"))
                 {
                     SteeringMotors.Add(ConnectWheel(wheel, false, true, wheelsSuspFront));
                     frontwheels.Add(wheel);
                 }
                 else if (name.After("wheel").Contains("b"))
                 {
                     DrivingMotors.Add(ConnectWheel(wheel, true, true, wheelsSuspBack));
                 }
                 else
                 {
                     ConnectWheel(wheel, true, false, wheelsSuspBack);
                 }
                 wheel.Body.ActivityInformation.Activate();
             }
             else if (name.Contains("flap"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 mat.Transpose();
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     Matrix mb = tnode.MatrixA;
                     mb.Transpose();
                     mat   = mat * mb;
                     tnode = tnode.Parent;
                 }
                 Location          pos     = GetPosition() + new Location(Body.CollisionInformation.LocalPosition) + new Location(mat.M41, -mat.M43, mat.M42) + offset; // TODO: matrix gone funky?
                 FDSSection        flapDat = SourceFile.GetSection("vehicle.flaps").GetSection(name.After("flap").Replace("_", ""));
                 VehiclePartEntity flap    = new VehiclePartEntity(TheRegion, flapDat.GetString("model"), true);
                 flap.SetPosition(pos);
                 flap.SetOrientation(BEPUutilities.Quaternion.Identity);
                 flap.Gravity = Gravity;
                 flap.CGroup  = CGroup;
                 flap.SetMass(20);
                 flap.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(flap);
                 flap.ForceNetwork();
                 flap.SetPosition(pos);
                 flap.SetOrientation(BEPUutilities.Quaternion.Identity);
                 ConnectFlap(flap, flapDat);
             }
         }
         if (frontwheels.Count == 2)
         {
             JointSpinner js = new JointSpinner(frontwheels[0], frontwheels[1], new Location(1, 0, 0));
             TheRegion.AddJoint(js);
         }
         hasWheels = true;
     }
 }
예제 #8
0
 public void HandleWheels()
 {
     if (!hasWheels)
     {
         Model mod = TheServer.Models.GetModel(model);
         if (mod == null) // TODO: mod should return a cube when all else fails?
         {
             return;
         }
         Model3D scene = mod.Original;
         if (scene == null) // TODO: Scene should return a cube when all else fails?
         {
             return;
         }
         SetOrientation(Quaternion.Identity);
         List<Model3DNode> nodes = GetNodes(scene.RootNode);
         List<VehiclePartEntity> frontwheels = new List<VehiclePartEntity>();
         for (int i = 0; i < nodes.Count; i++)
         {
             string name = nodes[i].Name.ToLowerFast();
             if (name.Contains("wheel"))
             {
                 Matrix mat = nodes[i].MatrixA;
                 Model3DNode tnode = nodes[i].Parent;
                 while (tnode != null)
                 {
                     mat = tnode.MatrixA * mat;
                     tnode = tnode.Parent;
                 }
                 Location pos = GetPosition() + new Location(mat.M14, mat.M34, mat.M24) + offset; // NOTE: wtf happened to this matrix?
                 VehiclePartEntity wheel = new VehiclePartEntity(TheRegion, "vehicles/" + vehName + "_wheel", true);
                 wheel.SetPosition(pos);
                 wheel.SetOrientation(Quaternion.Identity);
                 wheel.Gravity = Gravity;
                 wheel.CGroup = CGroup;
                 wheel.SetMass(30);
                 wheel.mode = ModelCollisionMode.CONVEXHULL;
                 TheRegion.SpawnEntity(wheel);
                 wheel.SetPosition(pos);
                 if (name.After("wheel").StartsWith("f"))
                 {
                     SteeringMotors.Add(ConnectWheel(wheel, false, true));
                     frontwheels.Add(wheel);
                 }
                 else if (name.After("wheel").StartsWith("b"))
                 {
                     DrivingMotors.Add(ConnectWheel(wheel, true, true));
                 }
                 else
                 {
                     ConnectWheel(wheel, true, false);
                 }
                 wheel.Body.ActivityInformation.Activate();
             }
         }
         if (frontwheels.Count == 2)
         {
             JointSpinner js = new JointSpinner(frontwheels[0], frontwheels[1], new Location(1, 0, 0));
             TheRegion.AddJoint(js);
         }
         hasWheels = true;
     }
 }