terrain

Discuss any questions about BEPUphysics or problems encountered.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

terrain

Post by ron »

i wanna make the level for my game
i have normal shapes like cuboid and slopes for my level's platform

i dont wanna use separate entities as they will get into heavy calculation and lag;
so i thought of using StaticTriangleGroup to deal with these shapes ,
but the collision doesn't happen to be proper.
i used the example code to test,

Code: Select all

StaticTriangleGroup.StaticTriangleGroupVertex[] vertices;
int[] indices;
TriangleMesh triangleMesh;
 public StaticTriangleGroup triangleGroup;

StaticTriangleGroup.GetVerticesAndIndicesFromModel(ground, out vertices, out indices);
            triangleMesh = new TriangleMesh(vertices, indices);
            triangleGroup = new StaticTriangleGroup(triangleMesh);
            triangleGroup.WorldMatrix = worldmatrix;
           
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

Depending on what kind of behavior you're seeing, it may be related to this bug:
http://www.bepu-games.com/forums/viewto ... f=4&t=1079

If your model is composed of multiple meshes which have their own transforms, it will happen.

If it's something else, I would need more context to figure out what's wrong.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

my models are of simple geometery like cube and prism,
which i want as platforms for my level where the character will stand on,
so i am using this "StaticTriangleGroup",
but i have loads of doubt in it
what would be the best way of making my level(should i use StaticTriangleGroup or anything else)

Code: Select all

StaticTriangleGroup.StaticTriangleGroupVertex[] vertices;
int[] indices;
StaticTriangleGroup.GetVerticesAndIndicesFromModel(PlaygroundModel, out vertices, out indices);
in the above code is it extracting the model's vertices and indices.
if yes then can i change the position of vertices of the triangle mesh, so as to make it big for proper collision?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

what would be the best way of making my level(should i use StaticTriangleGroup or anything else)
For static, unchanging level geometry, StaticTriangleGroup is indeed the suggested option.
in the above code is it extracting the model's vertices and indices.
if yes then can i change the position of vertices of the triangle mesh, so as to make it big for proper collision?
It is indeed extracting the model's vertices and indices. That particular function is just for convenience though, so it's not the only way to extract vertices. You can check the thread I linked earlier for alternatives if you find them necessary (in case you are encountering a known bug in the convenience function).

The vertices and indices you give to the mesh and group define the collision. You can change them to whatever you'd like beforehand, but if you modify the mesh data after the mesh/group has been created, you'll need to update the mesh's hierarchy.

If you just want to transform the shape using a matrix, just use the world matrix property that the StaticTriangleGroup exposes.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

i have a mesh with two faces
the top face and the front face
and all the other faces are culled so as to reduce the mesh load, as the other faces are unwanted,
but when i am using static triangle group for it (as it my level making entity(basically platform for my level))
The collision is happening between the mesh(the cube) and the entity but the character(box entity) is unable to stand over the mesh and is falling through the mesh.
The code below is my level editor class ,
where the constructor is taking the world matrix the model name and the instance of the main game class to draw the platform with Statictrianglegroup.

Code: Select all

class leveleditor:DrawableGameComponent
    {
        Matrix worldmatrix;
        Game1 chetangame;
        public Model ground;
        StaticTriangleGroup.StaticTriangleGroupVertex[] vertices;
        SceneObject sceneobj;
        int[] indices;
        TriangleMesh triangleMesh;
        public StaticTriangleGroup triangleGroup;
        
        
        SpriteBatch spriteBatch
        {
            get;
            set;
        }
        public leveleditor(Matrix world,Game1 game,String name):base(game) 
        {
            worldmatrix = world;
            chetangame = game;
            ground = chetangame.Content.Load<Model>(name);
            sceneobj = new SceneObject(ground);
            sceneobj.ObjectType = ObjectType.Dynamic;
            sceneobj.Visibility = ObjectVisibility.RenderedAndCastShadows;
            sceneobj.World = worldmatrix;
            chetangame.sceneInterface.ObjectManager.Submit(sceneobj);
            spriteBatch = new SpriteBatch(chetangame.GraphicsDevice);
            StaticTriangleGroup.GetVerticesAndIndicesFromModel(ground, out vertices, out indices);
            triangleMesh = new TriangleMesh(vertices, indices,4.5f);
            
            triangleGroup = new StaticTriangleGroup(triangleMesh);
            triangleGroup.WorldMatrix = worldmatrix;
           // ter = new Terrain(worldmatrix.Translation);
            
            
           
        }
         public override void Draw(GameTime gametime)
        {


            // Render the scene.
           
            // Add custom rendering that should occur before the scene is rendered.

           
            Matrix Transform;
            Matrix[] boneTransforms;
            Transform = worldmatrix;
            foreach (ModelMesh modelMesh in ground.Meshes)
            {
                
                boneTransforms = new Matrix[ground.Bones.Count];
                ground.CopyAbsoluteBoneTransformsTo(boneTransforms);
               
                foreach (BasicEffect effect in modelMesh.Effects)
                {
                    effect.World = boneTransforms[modelMesh.ParentBone.Index] * Transform;
                    //effect.LightingEnabled = true;
                    //effect.SpecularColor = new Vector3(0, 0, 0);
                    //effect.PreferPerPixelLighting = true;
                    //effect.SpecularPower = 1.0f;
                    //effect.AmbientLightColor = new Vector3(1, 0, 1);
                    //effect.DiffuseColor = new Vector3(0, 1.5f, 1);
                    //effect.EnableDefaultLighting();
                    //effect.EmissiveColor = new Vector3(0, 1, 1);
                    effect.View = chetangame.camera.ViewMatrix;
                    effect.Projection = chetangame.camera.ProjectionMatrix;
                    
                }
                modelMesh.Draw();
            }
            

        }
      
    }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

The code seems fine at a glance other than the TriangleMesh having a margin of 4.5. Take that parameter out; it won't fix what you're seeing probably, but it's best to not define it without having a reason.

The most likely reason for the objects appearing to fall through your mesh is that the graphics are in a different place than the actual collision mesh. You can look for this directly if you'd like by adding the TriangleMesh that you created the StaticTriangleGroup with to the BEPUphysicsDemos ModelDrawer and seeing where it is.

This could be a known bug with the vertex extraction convenience method like I said before. In the link I posted in my first reply, there's a description and workaround offered.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

how about using terrain as an entity for my level platforms
but my platforms wont be of complicated shapes,they'll be all simple shapes like cubes, and normal slopes like a mario level,
plzzzzzz help me with this
i saw with the model drawer also and its showing the same result
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

If you have level geometry which can be represented as a heightfield, then yes, you could use a Terrain instead. The other parts of your level could indeed be represented by kinematic Entities of varying kinds, though it's a good idea to avoid using a massive number of them.

However, the StaticTriangleGroup should be able to do what you want. A video or reproduction case may help me figure out what exact behavior you're seeing, and what could be causing that behavior.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

http://www.youtube.com/user/ron3662?feature=mhum
in the above video the character is a box entity and is falling over a The statictrianglemesh, but is going through it even after colliding
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

What are the dimensions of the triangles and the box? That could be related to numerical problems where the triangles sizes are too large/small to handle effectively. It's recommended that individual dimensions of any object stay within the 1-10 units range. This is a soft range; the engine can usually handle dimensions outside of the range very easily, but staying within the range provides a guarantee of stability.

I can't quite tell how much speed the box gets relative to its size on impact either. Enabling CCD might help (once any size issues are addressed). The default integration mode is discrete, which means collisions can be missed until it's too late, letting an object penetrate too far and possibly make its way through another object. You can enable continuous collision detection to address this by setting Space.SimulationSettings.CollisionDetection.CollisionDetectionType to LinearContinuous or FullyContinuous.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

it worked i scaled the character entity(box entity) and it worked
thnks for the help.
but wht could be the best entity type for my character, currently i am using a box but on slope the box gets turned(as the box is physically reacting to the space) so the character also gets turned as i am using the entity translation as my character translation.
http://www.youtube.com/user/ron3662?feature=mhum
Now in the above video you might have seen the shake in the screen that is because the target of my camera is the character
so according to the character's translation the camera's translation is happening.
any solution for this?
Last edited by ron on Mon Feb 07, 2011 9:26 pm, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

One of the more common character shapes is Capsule, but it will fall over too unless you lock the rotation. You can do this by setting the entity's LocalInertiaTensorInverse to the zero matrix.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

it worked i scaled the character entity(box entity) and it worked
thnks for the help.
but wht could be the best entity type for my character, currently i am using a box but on slope the box gets turned(as the box is physically reacting to the space) so the character also gets turned as i am using the entity translation as my character translation.
http://www.youtube.com/user/ron3662?feature=mhum
Now in the above video you might have seen the shake in the screen that is because the target of my camera is the character
so according to the character's translation the camera's translation is happening.
any solution for this?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: terrain

Post by Norbo »

I'd recommend drawing the entity itself to get a better idea of what is happening. I suspect it may be related to what I mentioned before about numerical precision.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: terrain

Post by ron »

how about using the displaytriangletest class for drawing the mesh
because it draws the trianglemesh

i am actually confused because there r so many drawing helpers
Post Reply