コード例 #1
0
 public XAnimatedActor(ref XMain X, XModel model, Vector3 Position,
                       Vector3 Velocity, float Mass) :
     base(ref X, model, Position, Velocity, Mass)
 {
     if (model != null)
     {
         model.Parent = this;
     }
 }
コード例 #2
0
 public XAnimatedActor(ref XMain X, XPhysicsObject Object, XModel model, Vector3 ModelScale,
                       Vector3 Velocity, float Mass)
     :
     base(ref X, Object, model, ModelScale, Velocity, Mass)
 {
     if (model != null)
     {
         model.Parent = this;
     }
 }
コード例 #3
0
ファイル: XProp.cs プロジェクト: bondjames12/spheregame
        public XProp(ref XMain X, XModel model, Vector3 position, Vector3 modeloffset, Matrix orient, Vector3 scale)
            : base(ref X)
        {
            DrawOrder = 100;

            if (model != null)
            {
                this.model   = model;
                model.Parent = this;
                modelNumber  = model.Number;
                //if its not loaded try and load!
                //if (!model.loaded) model.Load(X.Content);
            }
            this.position    = position;
            this.modeloffset = modeloffset;
            this.orientation = orient;
            this.scale       = scale;
        }
コード例 #4
0
ファイル: XActor.cs プロジェクト: bondjames12/spheregame
        public XActor(ref XMain X, XPhysicsObject Object, XModel model, Vector3 ModelScale, Vector3 Velocity, float Mass)
            : base(ref X)
        {
            DrawOrder = 100;

            if (model != null)
            {
                this.model       = model;
                model.Parent     = this;
                this.modelNumber = model.Number;
            }
            this.PhysicsObject = Object;
            this.PhysicsObject.SetMass(Mass);
            this.PhysicsObject.scale = ModelScale;
            this.PhysicsObject.PhysicsBody.Velocity = Velocity;
            this.PhysicsObject.PhysicsBody.SetDeactivationTime(0.1f);
            this.PhysicsObject.PhysicsBody.SetActivityThreshold(5f, 5f);
        }
コード例 #5
0
ファイル: XActor.cs プロジェクト: bondjames12/spheregame
        public XActor(ref XMain X, XModel model, Vector3 Position, Vector3 Velocity, float Mass)
            : base(ref X)
        {
            DrawOrder  = 100;
            this.Scale = Vector3.One;

            if (model != null)
            {
                this.model       = model;
                model.Parent     = this;
                this.modelNumber = model.Number;
                if (model.Model != null)
                {
                    RebuildCollisionSkin();
                    this.PhysicsObject.SetMass(Mass);
                    this.PhysicsObject.PhysicsBody.Velocity = Velocity;
                }
            }
            this.Translation = Position;
            this.Velocity    = Velocity;
            this.Mass        = Mass;
        }
コード例 #6
0
ファイル: XRenderer.cs プロジェクト: bondjames12/spheregame
        /// <summary>
        /// This method only support drawing static models. If you attempt to draw an animated (skinned) model it won't look right
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Camera"></param>
        public virtual void DrawModel(ref XModel Model, ref XCamera Camera)
        {
            for (int i = 0; i < Model.Model.Meshes.Count; i++)
            {
                ModelMesh mesh = Model.Model.Meshes[i];

                //calc new boundingsphere with new position from World/Model matrix
                BoundingSphere bs = mesh.BoundingSphere.Transform(Matrix.CreateTranslation(Model.SASData.World.Translation));

                //Is it in view?
                if (Camera.Frustrum.Contains(bs) == ContainmentType.Disjoint)
                {
                    continue;
                }


#if DEBUG
                //render boundingspheres for each mesh!
                XDebugVolumeRenderer.RenderSphere(bs, Color.Yellow, ref Camera.View, ref Camera.Projection);
#endif

                Model.SASData.ComputeModel();

                for (int j = 0; j < mesh.Effects.Count; j++)
                {
                    Effect effect = mesh.Effects[j];
                    // bind SAS shader parameters
                    for (int k = 0; k < effect.Parameters.Count; k++)
                    {
                        if (effect.Parameters[k].ParameterType == EffectParameterType.String)
                        {
                            if (effect.Parameters[k].Name.Contains("AnimationFileName"))
                            {
                                string animfilename = effect.Parameters[k].GetValueString();
                                if (!string.IsNullOrEmpty(animfilename))
                                {
                                    //there is an animated texture here
                                    foreach (EffectAnnotation anno in effect.Parameters[k].Annotations)
                                    {
                                        if (anno.Name.Contains("AnimatedMap"))
                                        {
                                            effect.Parameters[anno.GetValueString()].SetValue(
                                                Model.Giftextures[j].GetTexture());
                                        }
                                    }
                                }
                            }
                        }
                        Model.SASData.SetEffectParameterValue(effect.Parameters[k]);
                    }

                    //if rendering a depthmap
                    if (Camera.RenderType == RenderTypes.Depth)
                    {
                        //override any techniques with DepthMap technique shader
                        if (effect.Techniques["DepthMapStatic"] != null)
                        {
                            effect.CurrentTechnique = effect.Techniques["DepthMapStatic"];
                        }
                        else
                        {//if we get there there is no DepthMap shader so we can't render this into our depth MAP!!
                            break;
                        }
                        continue;
                    }

                    if (effect.Techniques["Static"] != null)
                    {
                        effect.CurrentTechnique = effect.Techniques["Static"];
                    }
                    else
                    {
                        effect.CurrentTechnique = effect.Techniques[0];
                    }
                }
                mesh.Draw(SaveStateMode.SaveState);
            }
        }
コード例 #7
0
        public XCar(ref XMain X, XModel Chassis, XModel Wheel, bool FWDrive, // Does the car have front wheel drive?
                    bool RWDrive,                                            // Does the car have rear wheel drive?
                    float maxSteerAngle,                                     // Max angle that the wheels can turn (wheel lock angle)
                    float steerRate,                                         // Supposed to be the max rate wheels can turn but doesn't do anything
                    float wheelFSideFriction,                                // Lateral tire friction - For an oversteering vehicle...
                    float wheelRSideFriction,                                // ...make the front value larger than the rear
                    float wheelFwdFriction,                                  // Longitutinal tire friction - try to keep these values...
                    float wheelRwdFriction,                                  // ...lower than 2.0f for reliability (larger values may be fine too)
                    float handbrakeRSideFriction,                            //Amount of lateral friction when handbrake is active
                    float handbrakeRwdFriction,                              // Ditto but longitudinal friction (make for real handbrake)
                    float startSlideFactor,                                  // The amount of drift/slide the car has - When the lateral...
                    float thresh1SlideFactor,                                // ...wheel velocity is greater than slip thresholds the wheel gets...
                    float thresh2SlideFactor,                                // ...the next slide factor. Factors are how much drift you'll get...
                    float slideThreshold1,                                   // ...and Thresholds are at what point they will get it. These...
                    float slideThreshold2,                                   // ...change the smallVel variable in Wheel.cs
                    float slideSpeed,                                        // Adjusts speed lost while drifting - make the same as...
                                                                             // ...thresh2SlideFactor to lose least speed during drift
                    float slipFactor,                                        // Standard slip factor for lateral and longitudinal friction
                    float wheelTravel,                                       // Total travel range of the suspension
                    float wheelRadius,                                       // Length of the Rays that test wheel collision
                    float wheelZOffset,                                      // Ride height adjustment - Mounting point of wheels up+/down-
                    float wheelRestingFrac,                                  // Spring rate - Stiffer at 0.1f, softer at 0.9f
                    float wheelDampingFrac,                                  // Shock dampening - More at 0.9f, less at 0.1f
                    int wheelNumRays,                                        // Number of rays testing wheel collision
                    float rollResistance,                                    // Rolling resistance - higher is more resistance
                    float topSpeed,                                          // Uhh, top speed of vehicle (units arbitrary)
                    float driveTorque,                                       // Torque of vehicle (units arbitrary)
                    float gravity,                                           // Gravity affect on the car

                    Vector3 Position)
            : base(ref X)
        {
            //since the car has alphablended windows we set this to true so in the render loop its last
            //this way you can see everything through the window!
            //remember alphablending is draw order dependent!
            AlphaBlendable = true;
            DrawOrder      = 100;
            this.Chassis   = Chassis;
            this.Wheel     = Wheel;

            Car = new CarObject(FWDrive, RWDrive, maxSteerAngle, steerRate,
                                wheelFSideFriction, wheelRSideFriction, wheelFwdFriction,
                                wheelRwdFriction, handbrakeRSideFriction, handbrakeRwdFriction,
                                startSlideFactor, thresh1SlideFactor, thresh2SlideFactor,
                                slideThreshold1, slideThreshold2, slideSpeed, slipFactor, wheelTravel,
                                wheelRadius, wheelZOffset, wheelRestingFrac, wheelDampingFrac,
                                wheelNumRays, rollResistance, topSpeed, driveTorque, gravity);

            Car.Car.EnableCar();
            //Car.PhysicsBody.SetDeactivationTime(99999999f);
            Car.Car.Chassis.Body.AllowFreezing = false;
            Car.PhysicsBody.Position           = Position;

/*
 *          //Create tailpipe particle system
 *          smoke = new XParticleSettings(ref X);
 *          smoke.ParticleEffectFile = @"Content\XEngine\Effects\ParticleEffect";
 *          smoke.ParticleTextureFile = @"Content\XEngine\Textures\smoke";
 *          smoke.TechniqueName = "RotatingParticles";
 *          smoke.MaxParticles = 600;
 *          smoke.Duration = TimeSpan.FromSeconds(10);
 *          smoke.MinHorizontalVelocity = 0;
 *          smoke.MaxHorizontalVelocity = 15;
 *          smoke.MinVerticalVelocity = 10;
 *          smoke.MaxVerticalVelocity = 20;
 *          // Create a wind effect by tilting the gravity vector sideways.
 *          smoke.Gravity = new Vector3(-20, -5, 0);
 *          smoke.EndVelocity = 0.75f;
 *          smoke.MinRotateSpeed = -1;
 *          smoke.MaxRotateSpeed = 1;
 *          smoke.MinStartSize = 5;
 *          smoke.MaxStartSize = 10;
 *          smoke.MinEndSize = 50;
 *          smoke.MaxEndSize = 200;
 *
 *          tailpipe = new XParticleSystem(ref X, smoke);
 *          tailpipe.Load(X.Content);
 *          // Use the particle emitter helper to output our trail particles.
 *          tailpipeEmitter = new XParticleEmitter(ref X, tailpipe,30, Position);
 *          tailpipe.DrawOrder = 190;
 *          tailpipeEmitter.DrawOrder = 180;
 * */
        }
コード例 #8
0
        public TriangleMeshObject(XModel model, Matrix orientation, Vector3 position)
        {
            body      = new Body();
            collision = new CollisionSkin(null);

            triangleMesh = new TriangleMesh();

            foreach (ModelMesh mesh in model.Model.Meshes)
            {
                //declare an array of correct size to hold the models vertices
                VertexPositionNormalTexture[] vertices =
                    new VertexPositionNormalTexture[mesh.VertexBuffer.SizeInBytes / VertexPositionNormalTexture.SizeInBytes];
                //do again, debug this see which one is right??????????
                vertices =
                    new VertexPositionNormalTexture[mesh.VertexBuffer.SizeInBytes / mesh.MeshParts[0].VertexStride];

                //get a copy of the vertices
                mesh.VertexBuffer.GetData <VertexPositionNormalTexture>(vertices);

                List <Vector3> verts = new List <Vector3>();
                //Loop through each vertex and store in vector array
                for (int k = 0; k < vertices.Length; k++)
                {
                    verts.Add(vertices[k].Position);  //may have to transform position relative to something??????
                }
                //Create a list of TriangleVertexIndices from the Index buffer taking into account it could be ints or shorts
                List <TriangleVertexIndices> indexList = new List <TriangleVertexIndices>();
                if (mesh.IndexBuffer.IndexElementSize == IndexElementSize.SixteenBits)
                {
                    short[] tempshorts = new short[mesh.IndexBuffer.SizeInBytes / sizeof(short)];
                    mesh.IndexBuffer.GetData <short>(tempshorts);
                    for (int i = 0; i < tempshorts.Length / 3; i++)
                    {
                        indexList.Add(new TriangleVertexIndices((int)tempshorts[i * 3 + 2], (int)tempshorts[i * 3 + 1], (int)tempshorts[i * 3 + 0]));
                    }
                }

                if (mesh.IndexBuffer.IndexElementSize == IndexElementSize.ThirtyTwoBits)
                {
                    //create index array of correct size
                    int[] tempInts = new int[mesh.IndexBuffer.SizeInBytes / sizeof(int)];
                    mesh.IndexBuffer.GetData <int>(tempInts);
                    for (int i = 0; i < tempInts.Length / 3; i++)
                    {
                        indexList.Add(new TriangleVertexIndices(tempInts[i * 3 + 2], tempInts[i * 3 + 1], tempInts[i * 3 + 0]));
                    }
                }



                triangleMesh.CreateMesh(verts, indexList, 4, 1.0f);
                collision.AddPrimitive(triangleMesh, new MaterialProperties(0.8f, 0.7f, 0.6f));
            }//do next mesh

            /*
             * List<object> tagData = ((ModelData)model.Model.Tag).VertexData as List<object>;
             * List<Vector3> vertices = (List<Vector3>)tagData[0];
             * List<int> indices = (List<int>)tagData[1];
             *
             * Vector3[] verts = new Vector3[vertices.Count];
             * int[] inds = new int[indices.Count];
             *
             * for (int i = 0; i < vertices.Count; i++)
             *  verts[i] = vertices[i];
             *
             * for (int i = 0; i < indices.Count; i++)
             *  inds[i] = indices[i];
             *
             * List<Vector3> vertexList = new List<Vector3>();
             * List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>();
             *
             * for (int i = 0; i < inds.Length / 3; i++)
             * {
             *  indexList.Add(new TriangleVertexIndices(indices[i * 3 + 2], indices[i * 3 + 1], indices[i * 3 + 0]));
             * }
             *
             * for (int i = 0; i < verts.Length; i++)
             * {
             *  vertexList.Add(vertices[i]);
             * }
             *
             * triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);
             *
             * collision.AddPrimitive(triangleMesh, 1, new MaterialProperties(0.8f, 0.7f, 0.6f));
             */
            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);

            body.CollisionSkin = collision;
            body.MoveTo(position, orientation);
        }
コード例 #9
0
        public XBoneMapObject(Vector3 position, ref XModel model)
        {
            //create a list to hold the collision primitives
            List <Primitive> prims = new List <Primitive>();

            //parse for collision bones
            foreach (ModelBone bone in model.Model.Bones)
            {
                string[] keypairs = bone.Name.ToLower().Split('_');
                //if checks for valid naming convention on collision bones
                if ((keypairs.Length == 2) && ((keypairs[0] == "sphere") || (keypairs[0] == "box") || (keypairs[0] == "capsule")))
                {
                    //determine object number
                    int objectnum;
                    if ((keypairs[1] != "") || (keypairs[1] != null))
                    {
                        objectnum = int.Parse(keypairs[1]);
                    }
                    else
                    {
                        objectnum = 0;
                    }

                    //decompose bone transforms to components
                    Vector3    pos;
                    Vector3    scale;
                    Quaternion qrot;
                    bone.Transform.Decompose(out scale, out qrot, out pos);
                    Matrix rot = Matrix.CreateFromQuaternion(qrot);

                    //create  collision primitive objects and add to list
                    switch (keypairs[0])
                    {
                    case ("sphere"):
                        JigLibX.Geometry.Sphere sph = new JigLibX.Geometry.Sphere(pos, scale.X);
                        prims.Add(sph);
                        break;

                    case ("box"):
                        Box box = new Box(pos, rot, scale);
                        prims.Add(box);
                        break;

                    case ("capsule"):
                        break;
                    }
                }
            }

            body      = new Body();
            collision = new CollisionSkin(body);

            if (prims.Count > 0)
            {
                foreach (Primitive prim in prims)
                {
                    //TODO: Add ability to specify physics material type in art editor somehow
                    collision.AddPrimitive(prim, (int)JigLibX.Collision.MaterialTable.MaterialID.NormalSmooth);
                }
            }
            else
            {//no collision prims detected from XSI so create a default one here using the mesh bounding spheres
                foreach (ModelMesh mesh in model.Model.Meshes)
                {
                    //collision.AddPrimitive(new JigLibX.Geometry.Sphere(mesh.BoundingSphere.Center, mesh.BoundingSphere.Radius), new MaterialProperties(0.8f, 0.8f, 0.7f));
                    collision.AddPrimitive(new JigLibX.Geometry.Box(position, Matrix.Identity, new Vector3(mesh.BoundingSphere.Radius / 2f)), (int)JigLibX.Collision.MaterialTable.MaterialID.NormalRough);
                }
            }

            body.CollisionSkin = this.collision;

            Vector3 com = SetMass(1.0f);

            body.MoveTo(position, Matrix.Identity);
            collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
            body.EnableBody();
        }