Page 1 of 1

About Collision

PostPosted: Mon Dec 11, 2006 11:09 am
by cha_cher
I want to check collision with tiny but i don't what to do ???
please help me!!

PostPosted: Thu Dec 14, 2006 8:11 am
by Silmaryls
Hi !

What you should do, is to attach a Cylinder collision shape to tiny and move it with the mesh.

For the moment it is not really easy to do but I am currently working on it (I'm also adding tri mesh support but it won't help you if you are using skinning).

I will post here as soon as it's finished

PostPosted: Tue Jan 02, 2007 4:12 am
by cha_cher
thank you
I will try that

PostPosted: Sun Jan 21, 2007 12:24 am
by Silmaryls
Hi cha_cher !

Brume v1.5 is out. Here is a sample for attaching a sphere to the camera and then dealing with collisions (using the collision event) :

Code: Select all
// testing camera attached collision shape (fps like collisions)
BrumeSphereColored cameraSphere = new BrumeSphereColored(this, "cameraSphere");
this.ActiveCamera.AddChild(cameraSphere);
cameraSphere.AddCollisionShapes(GenerateCollisionShapes(cameraSphere));
cameraSphere.CollisionEvent += new BrumeCollisionDelegate(OnCollisionWithCamera);

...
...
...

void OnCollisionWithCamera(BrumeObject cameraSphere, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts)
{
// camera does not collide with ground
  if (!(otherShape is BrumeCollisionPlane))
  {
     cameraSphere.Parent.MoveToLastPosition();
     cameraSphere.MoveToLastPosition();
  }
}


If you want to see a demo just check the ShowRoom files on our web site.
Ah yes : be aware that objects attached to camera are not visible.
If you really want to have visible objects you can manage it by overriding the camera class and Move method.


Silmaryls

PostPosted: Tue Mar 13, 2007 2:16 am
by rubbish
What about the tiny??

PostPosted: Tue Mar 13, 2007 8:45 pm
by Silmaryls
Have you tried to add a sphere as child of Tiny ?

Then make it invisible and it should work.

PostPosted: Thu Mar 29, 2007 9:39 am
by rubbish
I read the code in the ShowRoom files,I modified it
Code: Select all
            BrumeXMesh pinguinMesh = new BrumeXMesh(this, "pinguinMesh", "tiny_4anim.x", false);
....
            BrumeObject obj = pinguin.GetChild("body");
....


It don't worked.... :?

PostPosted: Tue Apr 03, 2007 9:34 pm
by Silmaryls
Hi Rubbish,

Here is a collision sample using a cylinder shape to approximate tiny mesh.
The sample is a little bit complicated (I added a root object) because tiny mesh is not well oriented.

I will have to simplify these methods one day. But you should try that :

Code: Select all
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Brume.Tests
{
    public class TinyMove : Brume
    {
        private BrumeFPSCamera camera1 = null;
        private BrumeLight directionalLight = null;
        private BrumeLightedObject tiny = null;


        public TinyMove()
            : base()
        {
            BrumeFileManager.AddDirForAll("../../../Data/Internal");
            BrumeFileManager.AddDirForAll("../../Data");
        }

        BrumeCylinderColored collisionShape = null;
        BrumeObject root = null;
        override protected void GameInit()
        {
            camera1 = new BrumeFPSCamera(this, "camera1", new BrumeVector(0, 0, -5.0f), new BrumeVector(0.0f, 0.0f, 1.0f), new BrumeVector(0.0f, 1.0f, 0.0f));
            this.SetActiveCamera(camera1);
            this.BufferClearColor = Color.Black;
            this.GlobalAmbientLight = Color.FromArgb(255, 100, 100, 100);

            directionalLight = new BrumeDirectionalLight(this, "Directionnal Light", new BrumeVector(-1.0f, -1.0f, 1.0f), new BrumeVector(-1.0f, 1.0f, 1.0f), Color.FromArgb(255, 170, 170, 170));
            directionalLight.Specular = Color.FromArgb(255, 255, 255, 255);
            directionalLight.Enabled = true;
            directionalLight.Update();

            root = new BrumeObject(this, "root");
            root.Pos.Y = -1.5f;
            root.Pos.Z = 5.0f;


            BrumeXMesh tinyMesh = new BrumeXMesh(this, "tiny", "tiny_4anim.x", false);
            BrumeAnimationManager.AddAnimationsFromMesh(tinyMesh);
            tiny = new BrumeLightedObject(this, "tiny");
            tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
            tiny.Mesh = tinyMesh;
            tiny.Size = 0.005f;
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));

            root.AddChild(tiny);

           
            collisionShape = new BrumeCylinderColored(this, "cylinder");
            collisionShape.AddCollisionShapes(GenerateCollisionShapes(collisionShape));
            collisionShape.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
            collisionShape.CollisionEvent += new BrumeCollisionDelegate(OnCollisionWithCube);
            collisionShape.HasGlobalSize = false;
            collisionShape.ZSize = 2.5f;
            collisionShape.Pos.Y = 1.2f;
            collisionShape.Mesh = null;  // comment this line to see the cylinder shape

            root.AddChild(collisionShape);



            BrumeCubeColored cube = new BrumeCubeColored(this, "cube", Color.Blue, Color.Red);
            cube.AddCollisionShapes(GenerateCollisionShapes(cube));



        }

        void OnCollisionWithCube(BrumeObject collisionShape, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts)
        {
            root.MoveToLastPosition();
        }

        static float moveSpeed = 100.0f;
        static float factor = 0.01f;

        protected override void MoveScene(float fElapsedTime)
        {
            directionalLight.Update();

            // Tiny moves

            if (BrumeKeyboard.IsPressed(BrumeKey.UpArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
               
                 
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, -1));
                root.Pos += root.Dir * factor;
               
            }
            else if (BrumeKeyboard.IsPressed(BrumeKey.DownArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
                root.Pos += -root.Dir * factor;
               
            }
            else if (BrumeKeyboard.IsPressed(BrumeKey.RightArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(-1, 0, 0));
                root.Pos += root.Right * factor;

            }
            else if (BrumeKeyboard.IsPressed(BrumeKey.LeftArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(1, 0, 0));
                root.Pos += -root.Right * factor;

            }
            else
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Wave")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
                    tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
                }
            }


            // FPS camera move
            BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;

            if (camera != null && (this.DebugConsole.debugLevel != 2 || BrumeKeyboard.IsPressed(BrumeKey.Space)))
            {
                camera.FPSOrient((float)MouseDeltaX / (float)2, (float)MouseDeltaY / (float)2);

                // 5 - moving
                if (MouseDeltaZ > 0.0f)
                    moveSpeed *= 0.5f;
                else
                    if (MouseDeltaZ < 0.0f)
                        moveSpeed /= 0.5f;


                if (BrumeKeyboard.IsPressed(BrumeKey.W))
                    camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.S))
                    camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.D))
                    camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.A))
                    camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
            }


            // moving
            base.MoveScene(fElapsedTime);

        }
        protected override void RenderScene()
        {

            base.RenderScene();

        }
        protected override void AfterRendering()
        {
            base.AfterRendering();
            // exit ?
            if (BrumeKeyboard.IsPressed(BrumeKey.Escape))
            {
                this.Close();
                return;
            }

        }

        public static void Main()
        {
            using (TinyMove game = new TinyMove())
            {
                game.Play();
            }
        }

    }
}


If you want to see the collision shape, just comment the 'collisionShape.Mesh = null" line.

PostPosted: Wed Apr 04, 2007 12:22 am
by rubbish
Thanks,I had tried it.
I also try the tiger mesh like the pinguin,It works.
Now I have some questions:
1:All the animation mesh must do that like the tiny??Add sphere or box??
2:If some scene meshes are very complex,I mean there are many objects in the scene,so I must add box or sphere to the objects??
And why the house mesh is so easy :o
I also try my simple desk mesh ,it works too,except some mistakes.
3:I added some sphere,Cylinder , the house mesh in this sample,the collision not so precise. :roll: :?

PostPosted: Wed Apr 04, 2007 8:01 pm
by Silmaryls
Rubbish,

1. Yes because when you animate a mesh using skinning, you cannot use TriMesh collision shape (doing so would be too slow)
2. If these are animated yes. If they are static, you can make a collision shape from the mesh (TriMesh) like for the table and walls in Brume ShowRoom
It's easier when meshes are not animated (I mean skinned animation)
3. Can you send me your sample ? I have to test it to say if it's a bug.

Silmaryls

PostPosted: Thu Apr 05, 2007 3:04 am
by rubbish
Code: Select all
override protected void GameInit() {
         camera1 = new BrumeFPSCamera(this, "camera1", new BrumeVector(0, 0, -5.0f), new BrumeVector(0.0f, 0.0f, 1.0f), new BrumeVector(0.0f, 1.0f, 0.0f));
         this.SetActiveCamera(camera1);
         this.BufferClearColor = Color.AliceBlue;
         this.GlobalAmbientLight = Color.FromArgb(255, 100, 100, 100);

         directionalLight = new BrumeDirectionalLight(this, "Directionnal Light", new BrumeVector(-1.0f, -1.0f, 1.0f), new BrumeVector(-1.0f, 1.0f, 1.0f), Color.FromArgb(255, 170, 170, 170));
         directionalLight.Specular = Color.FromArgb(255, 255, 255, 255);
         directionalLight.Enabled = true;
         directionalLight.Update();

         root = new BrumeObject(this, "root");
         root.Pos.Y = -1.5f;
         root.Pos.Z = 5.0f;

         BrumeXMesh tinyMesh = new BrumeXMesh(this, "tiny", "tiny_4anim.x", false);
         BrumeAnimationManager.AddAnimationsFromMesh(tinyMesh);
         tiny = new BrumeLightedObject(this, "tiny");
         tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
         tiny.Mesh = tinyMesh;
         tiny.Size = 0.005f;
         tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));

         root.AddChild(tiny);

         collisionShape = new BrumeCylinderColored(this, "cylinder");
         collisionShape.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
         collisionShape.CollisionEvent += new BrumeCollisionDelegate(OnCollision);
         collisionShape.HasGlobalSize = false;
         collisionShape.ZSize = 2.5f;
         collisionShape.Pos.Y = 1.2f;
         collisionShape.AddCollisionShapes(GenerateCollisionShapes(collisionShape));
         //collisionShape.Mesh = null;  // comment this line to see the cylinder shape

         root.AddChild(collisionShape);

         BrumeXMesh houseMesh = new BrumeXMesh(this, "house", "room.x", false);
         BrumeLightedObject house = new BrumeLightedObject(this, "house");
         house.Mesh = houseMesh;
         house.Pos = new BrumeVector(0, 1, 10);
         house.HasPhysicsAndCollisions = true;

         BrumeCubeColored cube = new BrumeCubeColored(this, "cube", Color.HotPink);
         cube.AddCollisionShapes(GenerateCollisionShapes(cube));

         BrumeSphereColored sph = new BrumeSphereColored(this, "sph");
         sph.AddCollisionShapes(GenerateCollisionShapes(sph));
         sph.Pos = new BrumeVector(5, 0, 0);

         BrumeCylinderColored cyl = new BrumeCylinderColored(this, "cyl");
         cyl.AddCollisionShapes(GenerateCollisionShapes(cyl));
         cyl.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
         cyl.Pos = new BrumeVector(3, 0, 0);

         BrumeOctaederColored oct = new BrumeOctaederColored(this, "oct");
         oct.AddCollisionShapes(GenerateCollisionShapes(oct));
         oct.Pos = new BrumeVector(8, 0, 0);

         BrumeConeColored cone = new BrumeConeColored(this, "cone");
         cone.AddCollisionShapes(GenerateCollisionShapes(cone));
         cone.Pos = new BrumeVector(-3, 0, 0);

         BrumeTorusColored tor = new BrumeTorusColored(this, "tor");
         tor.AddCollisionShapes(GenerateCollisionShapes(tor));
         tor.Pos = new BrumeVector(-5, 0, 0);

         BrumeXMesh tigerMesh = new BrumeXMesh(this, "tiger", "tiger.x", false);
         BrumeLightedObject tiger = new BrumeLightedObject(this, "tiger");
         tiger.Mesh = tigerMesh;
         tiger.AddCollisionShapes(GenerateCollisionShapes(tiger));
         tiger.Pos = new BrumeVector(-5, 0, -3);
         //tiger.HasPhysicsAndCollisions = true;

         BrumeXMesh deskMesh = new BrumeXMesh(this, "desk", "desk.x", false);
         BrumeLightedObject desk = new BrumeLightedObject(this, "desk");
         desk.Mesh = deskMesh;
         desk.AddCollisionShapes(GenerateCollisionShapes(desk));
         desk.Pos = new BrumeVector(0, 0, -5);
         desk.Size = 0.005f;
      }

      void OnCollision(BrumeObject collisionShape, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts) {
         root.MoveToLastPosition();
         
      }

      static float moveSpeed = 100.0f;
      static float factor = 0.03f;

      protected override void MoveScene(float fElapsedTime) {
         directionalLight.Update();

         // Tiny moves
         if (BrumeKeyboard.IsPressed(BrumeKey.NumPad8)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, -1));
            root.Pos += root.Dir * factor;

         } else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad5)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
            root.Pos += -root.Dir * factor;
         } else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad9)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            root.Pos += -root.Up * factor;
         } else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad7)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            root.Pos += root.Up * factor;
         } else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad6)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(-1, 0, 0));
            root.Pos += root.Right * factor;

         } else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad4)) {
            if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
            }
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(1, 0, 0));
            root.Pos += -root.Right * factor;

         } else {
            if (tiny.Animation == null || tiny.Animation.Name != "Wave") {
               tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
               tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
            }
         }


         // FPS camera move
         BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;

         if (camera != null && (this.DebugConsole.debugLevel != 2 || BrumeKeyboard.IsPressed(BrumeKey.Space))) {
            camera.FPSOrient((float)MouseDeltaX / (float)2, (float)MouseDeltaY / (float)2);

            // 5 - moving
            if (MouseDeltaZ > 0.0f)
               moveSpeed *= 0.5f;
            else
               if (MouseDeltaZ < 0.0f)
                  moveSpeed /= 0.5f;


            if (BrumeKeyboard.IsPressed(BrumeKey.W))
               camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
            if (BrumeKeyboard.IsPressed(BrumeKey.S))
               camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
            if (BrumeKeyboard.IsPressed(BrumeKey.D))
               camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
            if (BrumeKeyboard.IsPressed(BrumeKey.A))
               camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
         }


         // moving
         base.MoveScene(fElapsedTime);

      }

I send the desk and the tiger to your Email

PostPosted: Sat Apr 07, 2007 7:26 pm
by rubbish
Silmaryls
Have u found out the reason??

PostPosted: Thu Apr 19, 2007 8:51 am
by Silmaryls
Hi Rubbish,

Sorry for the delay. You were right, there are some precision problems with some objects in your scene.
I have to check that for next release. I will add it to my ODE tasks.

Thanks,