About Collision

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

About Collision

Postby cha_cher on Mon Dec 11, 2006 11:09 am

I want to check collision with tiny but i don't what to do ???
please help me!!
cha_cher
Brume Rookie
 
Posts: 2
Joined: Mon Dec 11, 2006 5:23 am

Postby Silmaryls on Thu Dec 14, 2006 8:11 am

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
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby cha_cher on Tue Jan 02, 2007 4:12 am

thank you
I will try that
cha_cher
Brume Rookie
 
Posts: 2
Joined: Mon Dec 11, 2006 5:23 am

Postby Silmaryls on Sun Jan 21, 2007 12:24 am

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
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Tue Mar 13, 2007 2:16 am

What about the tiny??
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Tue Mar 13, 2007 8:45 pm

Have you tried to add a sphere as child of Tiny ?

Then make it invisible and it should work.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Thu Mar 29, 2007 9:39 am

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.... :?
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Tue Apr 03, 2007 9:34 pm

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.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Wed Apr 04, 2007 12:22 am

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: :?
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Wed Apr 04, 2007 8:01 pm

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
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Thu Apr 05, 2007 3:04 am

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
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby rubbish on Sat Apr 07, 2007 7:26 pm

Silmaryls
Have u found out the reason??
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Thu Apr 19, 2007 8:51 am

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,
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron