Recent Forum Posts
From categories:
page 1123...next »
TriangleMeshObject Error
Ricsh (guest) 1259029362|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » TriangleMeshObject Error

cant get my triangle mesh objec to create a trianglemesh. here is my trainglemeshobject code

using System;
using System.Collections.Generic;
using JigLibX.Collision;
using JigLibX.Geometry;
using JigLibX.Math;
using JigLibX.Physics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace qkGames
{
    // A physics object that simulates all the individual polygons in a model
    public class TriangleMeshObject : PhysicsObject
    {
        // The generated mesh
        TriangleMesh triangleMesh;
        //string modelName;
        public List<Vector3> vertexList;
        // Constructors
        public List<TriangleVertexIndices> indexList;
        public TriangleMeshObject()
            : base()
        {
            Setup(null, Vector3.Zero, Vector3.Zero);
        }

        public TriangleMeshObject(string ModelName, Vector3 Position, Vector3 Rotation)
            : base()
        {
            Setup(ModelName, Position, Rotation);
        }

        public TriangleMeshObject(string ModelName, Vector3 Position, Vector3 Rotation,
        GameScreen Parent)
            : base(Parent)
        {
            Setup(ModelName, Position, Rotation);
        }

        // Sets up the object
        void Setup(string ModelName, Vector3 Position, Vector3 Rotation)
        {
            Model Model = Engine.Content.Load<Model>(ModelName);

            Body = new Body();
            CollisionSkin = new CollisionSkin(null);

            //Body.CollisionSkin = CollisionSkin;

            //this.modelName = ModelName;

            //CollisionSkin.RemoveAllPrimitives();
            triangleMesh = new TriangleMesh();

            vertexList = new List<Vector3>();
            indexList =
            new List<TriangleVertexIndices>();

            ExtractData(vertexList, indexList, Model);
            //triangleMesh.CreateMesh(
            triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);
            CollisionSkin.AddPrimitive(triangleMesh,
            new MaterialProperties(0.8f, 0.7f, 0.6f));

            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(CollisionSkin);

            //Mass = Mass;
            this.Position = Position;
            CollisionSkin.ApplyLocalTransform(new Transform(-Position, Matrix.Identity));

           // CollisionSkin.
            //this.EulerRotation = Rotation;
        }

        // Sets the model being simulated, extracts vertices, etc.
        public void SetModel(string ModelName)
        {

        }

        // Extracts the neccesary information from a model to
        // simulate physics on it
     public void ExtractData(List<Vector3> vertices, List<TriangleVertexIndices> indices,Model model)
        {
            Matrix[] bones_ = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones_);
            foreach (ModelMesh mm in model.Meshes)
            {
                Matrix xform = bones_[mm.ParentBone.Index];
                foreach (ModelMeshPart mmp in mm.MeshParts)
                {
                    int offset = vertices.Count;
                    Vector3[] a = new Vector3[mmp.NumVertices];
                    mm.VertexBuffer.GetData<Vector3>(mmp.StreamOffset + mmp.BaseVertex * mmp.VertexStride,
                        a, 0, mmp.NumVertices, mmp.VertexStride);
                    for (int i = 0; i != a.Length; ++i)
                        Vector3.Transform(ref a[i], ref xform, out a[i]);
                    vertices.AddRange(a);

                    if (mm.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits)
                        throw new Exception(
                            String.Format("Model uses 32-bit indices, which are not supported."));
                    short[] s = new short[mmp.PrimitiveCount * 3];
                    mm.IndexBuffer.GetData<short>(mmp.StartIndex * 2, s, 0, mmp.PrimitiveCount * 3);
                    JigLibX.Geometry.TriangleVertexIndices[] tvi = new JigLibX.Geometry.TriangleVertexIndices[mmp.PrimitiveCount];
                    for (int i = 0; i != tvi.Length; ++i)
                    {
                        tvi[i].I0 = s[i * 3 + 2] + offset;
                        tvi[i].I1 = s[i * 3 + 1] + offset;
                        tvi[i].I2 = s[i * 3 + 0] + offset;
                    }
                    indices.AddRange(tvi);
                }
            }
        }
        }

}

triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);

is throwing a
System.ArrayTypeMismatchException was unhandled
Message="Source array type cannot be assigned to destination array type."
Source="mscorlib"
StackTrace:
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
at System.Collections.Generic.List`1.CopyTo(T[] array)
at JigLibX.Geometry.Octree.AddTriangles(List`1 _positions, List`1 _tris)
at JigLibX.Geometry.TriangleMesh.CreateMesh(List`1 vertices, List`1 triangleVertexIndices, Int32 maxTrianglesPerCell, Single minCellSize)

TriangleMeshObject Error by Ricsh (guest), 1259029362|%e %b %Y, %H:%M %Z|agohover

Hello,

I've just started playing around with this library and one of the first things I tried was to remove the heightmap and use a custom .x model as a Triangle Mesh Object instead, this seems to work fine for the cubes and spheres, however the car seems to have problems, the wheels sink though the mesh, and the the chassis stops the car falling through the world. Is there something obvious I could be doing wrong?

Here's a few screen shots:

car1.jpg
car2.jpg
car3.jpg

Is this a known bug?

Problems with the car wheels and TriangleMeshObject by e66n06e66n06, 1259005790|%e %b %Y, %H:%M %Z|agohover
Re: Catching Collision events
Ricsh (guest) 1258997082|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

Thanks alot. i knew what the problem was i jus couldnt see it clearly. i added external data to my box object and it seems to be working. cant thank you enough for you fast and clear response. You dont have a more direct method of contacting you incase i run into more problems, or do you check these forums rather often.

Re: Catching Collision events by Ricsh (guest), 1258997082|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
MikeTsourisMikeTsouris 1258997005|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

Great. Good luck with JigLibX on xbox. If you are interested, i built a XBOX project out of the JigLibX sample and altered it to support the xbox gamepad.

You should try to load it on your xbox when you get a chance, so you can get an idea of what you are up against when it comes to XBOX performance…..

That project is NOT thelast stable release. Instead, it's the latest patch release, which is actually supposed to be faster on xbox…..

http://files.tsouris.net/fd/JigLibX_Xbox360/_zip.aspx

Re: Charchter controller flying off by MikeTsourisMikeTsouris, 1258997005|%e %b %Y, %H:%M %Z|agohover
Re: Catching Collision events
MikeTsourisMikeTsouris 1258995759|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

Well, ExternalData is NOT set by default. I see that you are setting ExternalData for your character, but nothing else is going to have it, so it's like saying:

"I have external data, but nothing else i collide with will have it".

As you build more objects and have those new objects set their external data to something, and populate your world, then you will have something to work with. Until then, just work with OWNER and skin1.

So, try changing that top line in the collision call back from:

            if (skin1.Owner == null || skin1.Owner.ExternalData == null)
                return true;

to:

            if (skin1.Owner == null)
                return true;

So don't be set back because the External Data is null. It's basically an empty field that JigLibX creator put in to add extra data to the collision skins. That's why it's of type OBJECT.

Re: Catching Collision events by MikeTsourisMikeTsouris, 1258995759|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
Ricsh (guest) 1258989878|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

i Did manage to fix this problem, and it turns out that it was the body.SetBodyInvInertia

i was using an old version of jiglibx which did not support it.

as for the Physics physics = Engine.Services.GetService<Physics>();

its there so that i can turn off the physics engine later in that update method. i wont be leaving it there as i know its not a good idea to be calling this every update. Im rushed for time at the moment. as i have a deadline to complete this by so ive taken a game engine ive been working on and ripping bits to finsih this project, which is making for some very messy and untidy code.

Thanks alot for the advice and im gonna look into how i can use singleton's as i do wish to port the engine to the XBox at a later date and effeiceny is very important to me.

Re: Charchter controller flying off by Ricsh (guest), 1258989878|%e %b %Y, %H:%M %Z|agohover
Re: Catching Collision events
Helpplz (guest) 1258985363|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

Thank you very much for taking the time to Post that example. It really did help and ive made some progress. but still stuck im affraid. my skin1.owner.externaldata always seems to be nulll and im not sure if that is what is causing the problem, while debugging i can see that the collision call back class is being called when i move the character into the box but it seems to skip the rest as external data is null. Am i surpose to be settting this sumwhere.

Here is my base class physics object class:

using JigLibX.Collision;
using JigLibX.Geometry;
using JigLibX.Physics;
using Microsoft.Xna.Framework;

namespace qkGames
{ // Provides a base object type for physics simulation
    public abstract class PhysicsObject : Component
    {
        // Local copy of the mass of the object
        float mass = 1;

        // The Body managed by the PhysicsObject
        public Body Body;

        // The CollisionSkin managed by the PhysicsObject
        public CollisionSkin CollisionSkin;

        // The mass of the PhysicsObject
        public float Mass
        {
            get { return mass; }
            set
            {
                // Set the new value
                mass = value;

                // Fix transforms
                Vector3 com = SetMass(value);
                if (CollisionSkin != null)
                    CollisionSkin.ApplyLocalTransform(
                        new JigLibX.Math.Transform(-com, Matrix.Identity));
            }
        }

        // The PhysicsObject's position
        public Vector3 Position
        {
            get { return Body.Position; }
            set { Body.MoveTo(value, Body.Orientation); }
        }

        // The PhysicsObject's orientation
        public Matrix Rotation
        {
            get { return Body.Orientation; }
            set { Body.MoveTo(Body.Position, value); }
        }

        // The PhysicsObject's rotation as a Euler Vector
        public Vector3 EulerRotation
        {
            get { return MathUtil.MatrixToVector3(Rotation); }
            set { Rotation = MathUtil.Vector3ToMatrix(value); }
        }

        // Whether or not the physics object is locked in place
        public bool Immovable
        {
            get { return Body.Immovable; }
            set { Body.Immovable = value; }
        }

        // Returns the PhysicsObject's BoundingBox
        public BoundingBox BoundingBox
        {
            get
            {
                if (Body.CollisionSkin != null)
                    return Body.CollisionSkin.WorldBoundingBox;
                else
                    return new BoundingBox(Position - Vector3.One,
                        Position + Vector3.One);
            }
        }

        // The body's velocity
        public Vector3 Velocity
        {
            get { return Body.Velocity; }
            set { Body.Velocity = value; }
        }

        // Constructors
        public PhysicsObject() : base() {
            //Body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionCallBack);

        }
        public PhysicsObject(GameScreen Parent) : base(Parent) { }

        // Sets up the body and collision skin
        protected void InitializeBody()
        {
            Body = new Body();
            CollisionSkin = new CollisionSkin(Body);
            Body.CollisionSkin = this.CollisionSkin;
            Body.EnableBody();
        }

        // Sets the mass of the PhysicsObject
        public Vector3 SetMass(float mass)
        {
            PrimitiveProperties primitiveProperties =
                new PrimitiveProperties(
                    PrimitiveProperties.MassDistributionEnum.Solid,
                    PrimitiveProperties.MassTypeEnum.Density, mass);

            float junk; Vector3 com; Matrix it, itCoM;

            CollisionSkin.GetMassProperties(primitiveProperties,
                out junk, out com, out it, out itCoM);
            Body.BodyInertia = itCoM;
            Body.Mass = junk;

            return com;
        }

        // Rotates and moves the model relative to the physics object to
        // better align the model with the object
        public void OffsetModel(Vector3 PositionOffset,
            Matrix RotationOffset)
        {
            CollisionSkin.ApplyLocalTransform(
                new JigLibX.Math.Transform(PositionOffset, RotationOffset));
        }

        // Disables physics body and component
        public override void DisableComponent()
        {
            Body.DisableBody();
            base.DisableComponent();
        }
    }
}

and here is my charachter class

//**************************CharacterObject***********************************
using JigLibX.Collision;
using JigLibX.Geometry;
using JigLibX.Physics;
using Microsoft.Xna.Framework;
using JigLibX.Math;

namespace qkGames
{
    public class CharacterObject : PhysicsObject
    {
        public virtual bool CollisionCallBack(CollisionSkin skin0, CollisionSkin skin1)
        {

            if (skin1.Owner == null || skin1.Owner.ExternalData == null)
                return true;

            // if you wanted to know the position of the box you collided with....
            Vector3 otherBoxesPosition = skin1.Owner.Position;

            // xxxxxxxxxxxxxxxxxxxxxxxx
            // Using a little reflection, we can see exactly what kind of object we collided with.
            // WARNING: No Guarantee that the members 'ExternalData' or even 'Owner' won't be null

            if (skin1.Owner.ExternalData is BoxObject)
            {
                // i collided with another instance of my type of object
                PauseScreen pause = new PauseScreen("Pause");
                return false; // allow this object to pass through
            }

            // if you inherit from this class, and set the 'body.ExternalData' to the gameComponent instance
            // you can kill that instance when you collide with it....
            if (skin1.Owner.ExternalData is GameComponent)
                ((GameComponent)skin1.Owner.ExternalData).Enabled = false;

            if (skin1.Owner.ExternalData is DrawableGameComponent)
                ((DrawableGameComponent)skin1.Owner.ExternalData).Visible = false;

            // for everything else, we still want the collision handled by the physics engine after our logic
            // so we return true
            return false;
        }

        public Character CharacterBody { get; set; }
        CollisionCallbackFn col;
        public CharacterObject(Vector3 position)
            : base()
        {
            InitializeBody();
            Body = new Character();
            Vector3 Posi = position;
            //collision = new CollisionSkin(Body);
            Body.ExternalData = this;

            CollisionSkin = new CollisionSkin(Body);
            Body.CollisionSkin = this.CollisionSkin;
            //col = new CollisionCallbackFn(CollisionCheck);
            //Body.CollisionSkin.callbackFn += col;
            Capsule capsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.0f);
            //Body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionCallBack);
            CollisionSkin.AddPrimitive(capsule, new MaterialProperties(0.0f, 0.5f, 0.3f));
            //body.CollisionSkin = this.collision;
            Vector3 com = SetMass(1.0f);

            Body.MoveTo(position + com, Matrix.Identity);
            CollisionSkin.ApplyLocalTransform(new Transform(-com, Matrix.Identity));

            Body.SetBodyInvInertia(0.0f, 0.0f, 0.0f);

            CharacterBody = Body as Character;

            Body.AllowFreezing = false;
            Body.EnableBody();
            Body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionCallBack);

        }
    }

    class ASkinPredicate : CollisionSkinPredicate1
    {
        public override bool ConsiderSkin(CollisionSkin skin0)
        {
            if (!(skin0.Owner is Character))
                return true;
            else
                return false;
        }
    }

    public class Character : Body
    {

        public Character()
            : base()
        {
        }

        public Vector3 DesiredVelocity { get; set; }

        private bool doJump = false;

        public void DoJump()
        {
            doJump = true;
        }

        public override void AddExternalForces(float dt)
        {
            ClearForces();

            if (doJump)
            {
                foreach (CollisionInfo info in CollisionSkin.Collisions)
                {
                    Vector3 N = info.DirToBody0;
                    if (this == info.SkinInfo.Skin1.Owner)
                        Vector3.Negate(ref N, out N);

                    if (Vector3.Dot(N, Orientation.Up) > 0.7f)
                    {
                        Vector3 vel = Velocity; vel.Y = 5.0f;
                        Velocity = vel;
                        break;
                    }
                }
            }

            Vector3 deltaVel = DesiredVelocity - Velocity;

            bool running = true;

            if (DesiredVelocity.LengthSquared() < JiggleMath.Epsilon) running = false;
            else deltaVel.Normalize();

            deltaVel.Y = 0.0f;

            // start fast, slow down slower
            if (running) deltaVel *= 10.0f;
            else deltaVel *= 2.0f;

            float forceFactor = 1000.0f;

            AddBodyForce(deltaVel * Mass * dt * forceFactor);

            doJump = false;
            AddGravityToExternalForce();
        }
        //bool CollisionCheck(CollisionSkin skin0, CollisionSkin skin1)
     //   {
         //   return true;
        //}

    }

}

And here is my box object

using JigLibX.Collision;
using JigLibX.Geometry;
using JigLibX.Physics;
using Microsoft.Xna.Framework;

namespace qkGames
{
    public class BoxObject : PhysicsObject
    {
        Vector3 sideLengths;

        // teh length of the sides of the box
        public Vector3 SideLengths
        {
            get { return sideLengths; }
            set
            {
                // Set the new value
                sideLengths = value;

                // Update the collision skin
                CollisionSkin.RemoveAllPrimitives();
                CollisionSkin.AddPrimitive(
                    new Box(-0.5f * value, Body.Orientation, value),
                    new MaterialProperties(0.8f, 0.8f, 0.7f));

                // Set the mass to itself to fix the local transform
                // on the CollisionSkin in the set accessor
                this.Mass = this.Mass;
            }
        }

//contructors

        public BoxObject()
             : base()
        {
            InitializeBody();
             SideLengths = Vector3.One;
        }

        public BoxObject(Vector3 SideLengths)
            :base()
        {

        SetupSkin(SideLengths, Vector3.Zero, Vector3.Zero);
        }

        public BoxObject(Vector3 SideLengths, Vector3 Position,
            Vector3 Rotation)
            : base()
        {
            SetupSkin(SideLengths, Position, Rotation);
        }

       public BoxObject(Vector3 SideLengths, Vector3 Position,
            Vector3 Rotation, GameScreen Parent)
            : base(Parent)
        {
            SetupSkin(SideLengths, Position, Rotation);
        }

        //setup object with parameters

        void SetupSkin(Vector3 SideLengths, Vector3 Position,
            Vector3 Rotation)
        {
            //setup body

            InitializeBody();

            //Set Properties
            this.SideLengths = SideLengths;
            this.Position = Position;
            this.EulerRotation = Rotation;
        }
    }
}
Re: Catching Collision events by Helpplz (guest), 1258985363|%e %b %Y, %H:%M %Z|agohover
Re: Catching Collision events
MikeTsourisMikeTsouris 1258955924|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

To take it a step further, lets say we want 3 types of boxes….

The Floor : We don't need anything special if we collide with floor, just regular physics. Also, the floor should not move

GoodGuy Boxes: If GoodGuys crash into other GoodGuys, nothing bad happens

BadGuyBoxes : If a BadGuy crashes into a GoodGuy, the bad guy calls the 'Destroy' method on the 'GoodGuy'.

So i can do that with very little code if i inherit from the class above.

Special note, i would have to modify the member 'body' to be protected instead of private…….

    // this class inherits from CollidableObject and simply builds a flat floor plane, 100 X 100, and only 3 units high.
    // also, i had to add the 'protected' modifier to the 'body' member, so i could get to it in this class
    public class Floor : CollidableObject
    {
        public Floor(Game game)
            : base(game, Vector3.Zero, Quaternion.Identity, new Vector3(100, 3, 100))
        {
            this.body.Immovable = true;
        }
    }

    // this class inherits from CollidableObject and overrides the CollisionCallBack
    public class GoodGuyBox : CollidableObject
    {
        public GoodGuyBox(Game game, Vector3 pos, Quaternion rot, Vector3 scl)
            : base(game, pos, rot, scl)
        {

        }

        public override bool CollisionCallBack(CollisionSkin skin0, CollisionSkin skin1)
        {
            if (skin1.Owner.ExternalData is GoodGuyBox)
            {
                // it's ok to collide with other good guys, 
                return true;
            }

            return base.CollisionCallBack(skin0, skin1);
        }
    }

    // this class inherits from CollidableObject and overrides the CollisionCallBack
    public class BadGuyBox : CollidableObject
    {
        public BadGuyBox(Game game, Vector3 pos, Quaternion rot, Vector3 scl)
            : base(game, pos, rot, scl)
        {

        }

        public override bool CollisionCallBack(CollisionSkin skin0, CollisionSkin skin1)
        {
            if (skin1.Owner.ExternalData is GoodGuyBox)
            {
                // since this instance is a 'bad guy' he deactivates 'Good Guys' when it collides with them

                ((GoodGuyBox)skin1.Owner.ExternalData).Destroy();

                return true;
            }

            return base.CollisionCallBack(skin0, skin1);
        }
    }
Re: Catching Collision events by MikeTsourisMikeTsouris, 1258955924|%e %b %Y, %H:%M %Z|agohover
Re: Catching Collision events
MikeTsourisMikeTsouris 1258954196|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

Ok, here is a class

It's a simple template for a physics object that would fall from where ever you place it, and collide
with whatever else is in the world, if you instantiate a few of these. It also draws a model and keeps the model's position synched with the BODY.

As you see, the class simply inherits from DrawableGameComponent. Update and Draw are not needed for the physics to work, as long as in your main game, you are updating the actual physics engine. I just use update to keep the model's position synched with the BODY, and Draw to draw the model only.

Also, this shows that i am not inheriting from any other objects in the physics library. I'm simply using a couple of members: Body, Skin, and that's all you really need.

To know how to catch the event when collsion occurs, look at how i subscribe to the object's own collision event :

body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionCallBack);

Look at my comments and examples in there for more…..

In the CollisionCallBack:
- return 'true' if you want the collision to be considered, and 'false' if you want it to be ignored (walk through an item).

There is actually more to know with what you can do in those methods, but i'll let other people on the forum add to it, or i will later.

    public class CollidableObject : DrawableGameComponent
    {

        #region Constructor / Init / Load

        public CollidableObject(Game game, Vector3 pos, Quaternion rot, Vector3 scl)
            : base(game)
        {

            body = new Body();

            // this makes it possible to get back up to this object, when you detect a collision from an event
            body.ExternalData = this;

            _materialProperties = new MaterialProperties(0.0001f, 0.5f, 0.5f);

            this.position = pos;
            this.scale = scl;
            this.rotation = Matrix.CreateFromQuaternion(rot);

            this._skin = new CollisionSkin(body);

            body.CollisionSkin = _skin;

            RebuildSkinPrimitive(scl);

            com = SetMass(200);

            body.MoveTo(position, rotation);

            this._skin.ApplyLocalTransform(new Transform(-com, rotation));

            body.EnableBody();

            body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionCallBack);

        }

        protected override void LoadContent()
        {
            base.LoadContent();

            model = Game.Content.Load<Model>("model/monkeyhead123");
            bones = new Matrix[model.Bones.Count];
        }

        #endregion

        #region Propeties

        Model model;

        Vector3 com;
        Body body;

        private Matrix[] bones;
        private Vector3 position;
        private Vector3 scale;
        private Matrix rotation;
        private bool isDestroyed = false;
        private bool isCleanedUp = false;
        private CollisionSkin _skin;
        public CollisionSkin Skin { get { return _skin; } }

        private MaterialProperties _materialProperties;

        #endregion

        #region XNA Overrides

        public override void Update(GameTime gameTime)
        {

            this.position = body.Position;
            this.rotation = body.Orientation;

            if (isDestroyed && !isCleanedUp)
                Release();
        }

        public override void Draw(GameTime gameTime)
        {
            model.CopyAbsoluteBoneTransformsTo(bones);

            // Render the skinned mesh.
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.View = Global3dGame.CurrentCamera.View;
                    effect.Projection = Global3dGame.CurrentCamera.Projection;
                    effect.World = bones[mesh.ParentBone.Index] * GetWorldMatrix();

                    effect.EnableDefaultLighting();

                    effect.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                    effect.GraphicsDevice.RenderState.DepthBufferEnable = true;
                }

                mesh.Draw();
            }
        }

        #endregion

        #region Methods

        public virtual bool CollisionCallBack(CollisionSkin skin0, CollisionSkin skin1)
        {

            if (skin1.Owner == null || skin1.Owner.ExternalData == null)
                return true;

            // if you wanted to know the position of the box you collided with....
            Vector3 otherBoxesPosition = skin1.Owner.Position;

            // xxxxxxxxxxxxxxxxxxxxxxxx
            // Using a little reflection, we can see exactly what kind of object we collided with.
            // WARNING: No Guarantee that the members 'ExternalData' or even 'Owner' won't be null

            if (skin1.Owner.ExternalData is CollidableObject)
            {
                // i collided with another instance of my type of object

                return false; // allow this object to pass through
            }

            // if you inherit from this class, and set the 'body.ExternalData' to the gameComponent instance
            // you can kill that instance when you collide with it....
            if (skin1.Owner.ExternalData is GameComponent)
                ((GameComponent)skin1.Owner.ExternalData).Enabled = false;

            if (skin1.Owner.ExternalData is DrawableGameComponent)
                ((DrawableGameComponent)skin1.Owner.ExternalData).Visible = false;

            // for everything else, we still want the collision handled by the physics engine after our logic
            // so we return true
            return true;
        }

        public void MoveTo(Vector3 pos, Quaternion rot)
        {

            body.MoveTo(pos, Matrix.CreateFromQuaternion(rot));
            _skin.ApplyLocalTransform(new Transform(-com, Matrix.CreateFromQuaternion(rot)));

        }

        private Vector3 SetMass(float mass)
        {
            PrimitiveProperties primitiveProperties = new PrimitiveProperties(
                PrimitiveProperties.MassDistributionEnum.Solid,
                PrimitiveProperties.MassTypeEnum.Mass, mass);

            float junk;
            Vector3 com;
            Matrix it;
            Matrix itCoM;

            Skin.GetMassProperties(primitiveProperties, out junk, out com, out it, out itCoM);

            body.BodyInertia = itCoM;
            body.Mass = junk;

            return com;
        }

        private void RebuildSkinPrimitive(Vector3 newScale)
        {
            this._skin.RemoveAllPrimitives();

                Box box = new Box(-(newScale * 0.5f), Matrix.Identity, newScale);
                _skin.AddPrimitive(box, _materialProperties);

        }

        public void SetScale(Vector3 newScale)
        {
            this.scale = newScale;
            RebuildSkinPrimitive(scale);
        }

        private Matrix GetWorldMatrix()
        {
            return
                Matrix.CreateScale(scale) *
                rotation *
                Matrix.CreateTranslation(position);
        }

        public void Destroy()
        {
            isDestroyed = true;
        }

        private void Release()
        {
            this.body.DisableBody();

            isCleanedUp = true;

            this.Enabled = false;
            this.Visible = false;

        }

        #endregion
    }
Re: Catching Collision events by MikeTsourisMikeTsouris, 1258954196|%e %b %Y, %H:%M %Z|agohover
Catching Collision events
Helpplz (guest) 1258934442|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Catching Collision events

Hi.

Is there anyone who can give an actuall example of catching collision events pls. ive looked at both the tutorial and fourm, but it seems they both assume i know more than i do.i half understand the code but Im unsure where to be putting each bit of code. and wat to be changing in each part :/

Catching Collision events by Helpplz (guest), 1258934442|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
MikeTsourisMikeTsouris 1258932637|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

Also, I noticed you have quite a lot of allocations and you create a lot of scope level variables.

.NET on XBOX sucks, so for that kind of stuff (garbage collection), create a class level field, and keep reassigning. It's not the best OOP, but for XBOX, you need optimize for that kind of stuff.

Also, maybe i'm wrong, but i prefer a singletons for my common engine hooks to using that service pattern.

1. Constantly casting the same objects over and over can be costly.

2. A method call costs more than accessing a singleton.

3. Reflection is Expensive. You should get a handle on it at Init, and hold on to it, instead of using Expensive REFLECTION, in every update. Doing it update is only useful if you plan on swapping the whole physics implementation during gameplay.

I really shouldn't talk because i'm not a game developer, as much as a general software person, and i'm wrong a lot.

Re: Charchter controller flying off by MikeTsourisMikeTsouris, 1258932637|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
MikeTsourisMikeTsouris 1258931321|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

Hey,

i had the same problem when i was starting out with jigLibX. With me, i would be able to move around for a few seconds, then my character would start spinning, then orbiting, the fly off. I don't remember exactly what the issue was, because it was a few months ago.

I do have some suggestions. You should try all of these at least once, and see what effect it has on the controllability of your character when dealing with bumpy terrain.

For me, i used a combination of making my character much smaller, finely tuning the speed at which it moves, restricting possible rotation, and adjusting MaterialProperties.

I don't think it's an issue of the hieghtMap object. However, make sure the heightMap object is NOT internally setting some SMOOTH or BOUNCY MaterialProperty. If it is, change the property type to something ROUGH and NOT BOUNCY

So check these……..

1. What are the MaterialProperties you are giving to the HeightMap object?

2. What are the MaterialProperties you are giving to the character?

3. Are you manually setting body.Orientation of your character anywhere? If you are, don't.

4. How big is your sphere or capsule that you are using as your character on your height map? Try making it 10 times smaller. Try making it 10 times bigger. Do any of those help calm down the out of control spinning?

**
5. On each update cycle, before you start calculating your movement stuff, try setting your body.DesiredVelicity = Vector.Zero;. Then, if there is any movement you add from I personally do that so that when i am not touching my controller, my character does not move. Since my game is not about people on ice, this works just fine for me. Be setting it back to Zero, you are ensuring that it is not accumulating value from any other weirdness you might have in your code.
*

6. Try only applying rotation on the Y axis ONLY. So, basically, it's like saying that your character can only turn right and left. Now, since your game is First Person Camera, you can still apply the Pitch rotation to the camera, just don't apply it to the character. This might not be what you want in your final game, but it's worth trying to see if it solves the 'spinning out of control' problem.
So mine looks like this:

Rotation *= Matrix.CreateRotationY(changeRotationY * 0.1f);

Regarding MaterialProperties: You assign MaterialProperties when you add a primitive to a collision skin, so if i add a sphere it looks like this….

collision.AddPrimitive(sphere, MaterialId)

And if you want to know what the possible material Id's are:

// MaterialTable
//Unset = 0,
//UserDefined = 1,
//NotBouncySmooth = 2,
//NotBouncyNormal = 3,
//NotBouncyRough = 4,
//NormalSmooth = 5,
//NormalNormal = 6,
//NormalRough = 7,
//BouncySmooth = 8,
//BouncyNormal = 9,
//BouncyRough = 10,
//NumMaterialTypes = 11,

Try picking a Material that is not smooth or bouncy at all. MaterialProperies have a huge impact of how controllable something will be in the physics system.

Also try setting your mass to 500.

Also, i don't know why you are executing in your Update:

Physics physics = Engine.Services.GetService<Physics>();

What else are you doing in that whacky Update method of yours?

Re: Charchter controller flying off by MikeTsourisMikeTsouris, 1258931321|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
Ricsh (guest) 1258744053|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

ah, the reason i have that commented out is cause my jiblibx dosnt support it, cant get a complited version of the latest.

Re: Charchter controller flying off by Ricsh (guest), 1258744053|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
Ricsh (guest) 1258677804|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

anyone can upload the latest jiglibx with heightmapinfo included?

Re: Charchter controller flying off by Ricsh (guest), 1258677804|%e %b %Y, %H:%M %Z|agohover
Re: Charchter controller flying off
Ricsh (guest) 1258677755|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Charchter controller flying off

Affraid i had no luck with that, tried commenting it out but it still behaves in the same way.

anymore suggestions

Re: Charchter controller flying off by Ricsh (guest), 1258677755|%e %b %Y, %H:%M %Z|agohover
Re: NaN when trying to rotate my character
Thiago (guest) 1258636359|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » NaN when trying to rotate my character

OK, i will, but can you post all the code that make your character move when/if you are done

Re: NaN when trying to rotate my character by Thiago (guest), 1258636359|%e %b %Y, %H:%M %Z|agohover

I'll check jiglib code's soon. If I solve it, i'll post it here the solution. Do the same if you solve it:D

Thanks

Re: NaN when trying to rotate my character by vandopvandop, 1258624793|%e %b %Y, %H:%M %Z|agohover
Re: NaN when trying to rotate my character
Thiago (guest) 1258398782|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » NaN when trying to rotate my character

i have exactely the SAME problem. If you solve your problem pls Post here
vandop, Can you post all your code, maybe you can help me ?
if you prefer mail me moc.liamg|rotsapsaidogaiht#moc.liamg|rotsapsaidogaiht

thank you

Re: NaN when trying to rotate my character by Thiago (guest), 1258398782|%e %b %Y, %H:%M %Z|agohover

I've got a character which is pretty much the same as yours.
So I've just copy and pasted some of your code. (CharacterObject,CharacterBody)

I found the problem to be
//Body.SetBodyInvInertia(0.0f, 0.0f, 0.0f);
This shouldn't be commented out, once I uncommented it everything work fine.

If this doesn't work I'm more then happy to post some of my code.
Hope this helps.

Re: Charchter controller flying off by BlackSpiderWolfBlackSpiderWolf, 1258322930|%e %b %Y, %H:%M %Z|agohover
Limit orientation constraint
Camal (guest) 1258306315|%e %b %Y, %H:%M %Z|agohover
in discussion General / Help » Limit orientation constraint

I try to write a constraint which limits orientation of a body. (spherical joint)
For example, i want to limit orientation from (-30, -30, 0) to (+30,+30, 0).

I have tried to use two hinge joints (X axis and Y axis) but the
result seems unstable.
I have tried to compute axis angle from orientation matrix, in order
to deduce torque to apply. The results seems unstable too.

Any idea?

Thank you

Limit orientation constraint by Camal (guest), 1258306315|%e %b %Y, %H:%M %Z|agohover
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License