• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineCustom Collision Object?Custom Collision Object?
Previous
 
Next
New Post
12/25/2011 4:06 PM
 
mavonic
No Ranking

www.mavonic.de
Joined: 9/26/2011
Posts: 26
Custom Collision Object? 

Hello,

in my Game, i have a World of Cube (like Minecraft). Each side of the Cube has his own Transform-Matrix. How can i implement this Matrixes from the Cubes to the Phsysics/Collision Engine of DigitalRune? 

 thanks! And relly nice engine.

 
New Post
12/27/2011 8:48 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Custom Collision Object? 

Hi, each geometric object has a Pose property. (See also interface IGeometricObject, which is implemented by, e.g. class GeometricObject or class RigidBody.) We use the type Pose instead of a general transformation matrix. Here are some related articles from our blog:

Pose = Position and Orientation

How to use a Pose to define World and View matrix

A cube can be created for example using GeometricObject or a RigidBody with a BoxShape. You only need one Pose to position a cube. Why do you need 6 transformation matrices for a cube? Do you want to represent the cube using 6 rectangles?

 
New Post
12/27/2011 3:52 PM
 
mavonic
No Ranking

www.mavonic.de
Joined: 9/26/2011
Posts: 26
Re: Custom Collision Object?  Modified By mavonic  on 12/27/2011 4:52:48 PM

Hey,

Yes i want. One Cube in my Game is created of 6 Rectangles. And this Rectangles  must be implemented by the Collision/Physics Engine of DigitalRune :D

 heres my Code to Create the Matrixes:


public class Transforms
        {
            //Variables
            private v3 ChunkPos;
            public Matrix[] Matrixes = null;

            //Funktions
            public Transforms(v3 ChunkPosition)
            {
                ChunkPos = ChunkPosition;
            }
            public void Create(Vector3 InChunkPosition, float Scale, Vector3 Rotation, int MatrixID)
            {
                //Check Matrix
                if (Matrixes == null)
                    Matrixes = new Matrix[6];

                //Create Position
                Vector3 Position = new Vector3((ChunkPos.X * Static.MapChunkSize) + InChunkPosition.X, (ChunkPos.Y * Static.MapChunkSize) + InChunkPosition.Y, (ChunkPos.Z * Static.MapChunkSize) + InChunkPosition.Z);

                //Create Scale/Rotation/Position
                Matrixes[MatrixID] = Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotation.X) *
                                Matrix.CreateRotationY(Rotation.Y) *
                                Matrix.CreateRotationZ(Rotation.Z) *
                                Matrix.CreateTranslation(Position);
            }

            //0 = FRONT
            //1 = BACK
            //2 = LEFT
            //3 = RIGHT
            //4 = TOP
            //5 = DOWN
        }

My Cube is created of 6 Transform Matrixes (instead of one Cube Model), because my whole Map is based on the Cubes. So i cant draw 129837198237 Cube-Models (because this would lag and 90% percent of the cubes arent seen by the player).

I do it like this:

//Left  = 0
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, 0, 0, 1)) == true)
                transforms.Create(new Vector3(TX, TY, TZ + Scale), Scale, new Vector3(Full / 2, 0, 0), 0);
            //Right = 1
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, 0, 0, -1)) == true)
                transforms.Create(new Vector3(TX, TY, TZ - Scale), Scale, new Vector3(Full / 2, Full, 0), 1);
            //Front = 2
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, -1, 0, 0)) == true)
                transforms.Create(new Vector3(TX - Scale, TY, TZ), Scale, new Vector3(0, 0, Full / 2), 2);
            //Back  = 3
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, 1, 0, 0)) == true)
                transforms.Create(new Vector3(TX + Scale, TY, TZ), Scale, new Vector3(Full, Full, Full / 2), 3);
            //Top   = 4
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, 0, 1, 0)) == true)
                transforms.Create(new Vector3(TX, TY + Scale, TZ), Scale, new Vector3(0, 0, 0), 4);
            //Down  = 5
            if (Static.Game.World.IsTransCube(Static.helper.AddV(TotalPosition, 0, -1, 0)) == true)
                transforms.Create(new Vector3(TX, TY - Scale, TZ), Scale, new Vector3(0, 0, Full), 5);

I check each side of the cube.

 

My Map looks like this:

selfworld_firstcreateon.PNG 

 


 
New Post
12/27/2011 5:41 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Custom Collision Object? 

I recommend to use boxes instead of rectangles. Of course only for the visible boxes.This reduces the number of collision objects (by up to 6 in the worst case).

And boxes behave better: Rectangles are "thin" objects. Tunneling artifacts (=missed collisions) are more likely with rectangles, unless continuous collision detection is enabled (which costs performance). And the collision detection can compute better contact information (contact positions + normals). The contact info of thin objects is often ambiguous.

Use the Pose to handle the translation + rotation (see linked articles above). Apply the scale directly to the shape by setting the rectangle/box widths to the scaled values.

Do you use many small cubes or do you plan to merge adjacent cubes to reduce the number of collision objects in the world?

 

 
New Post
12/28/2011 6:54 PM
 
mavonic
No Ranking

www.mavonic.de
Joined: 9/26/2011
Posts: 26
Re: Custom Collision Object? 

 Okay Thanks. I will use many small cubes (in a normal map: 4.600.000 cubes). And no, i dont want to merge them because that would be to complicated for me. (im 15 Years old) :D

I will try to do it with "Pose" or whatever, thanks.
 
New Post
12/28/2011 10:00 PM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 446
Re: Custom Collision Object? 

Oh wow, that's a lot of cubes. ;-)

It is unlikely that DigitalRune Physics - or any other general purpose physics engine - can handle such a large amount. I recommend to drastically reduce the number cubes.

 
New Post
12/29/2011 9:33 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Custom Collision Object? 
If your game world is voxel-based (=made up of cubes of the same size and same alignment, like Minecraft), then you can use specialized algorithms and data structures (like sparse voxel octrees). A general purpose collision detection library, like DigitalRune Geometry, is not optimized for this very, very special case. A general collision detection and physics system assumes that each collison object has unique properties (shape, position, rotation, mass, material, etc.) - therefore, a lot of computing power and memory is wasted when it is used to represent a voxel-based world.
 
New Post
12/29/2011 3:17 PM
 
mavonic
No Ranking

www.mavonic.de
Joined: 9/26/2011
Posts: 26
Re: Custom Collision Object?  Modified By mavonic  on 12/29/2011 4:58:32 PM

Hm... i need to check the Collision with the Map<>Player , so can i just make all cubes in a radius of 5 (or less) of the players-position to Collision Objects? If i do that, i will just have 20 Collision-Cubes. And if the player moves, the cubes (of the player-position) will Update to Collision Cubes.

 You think, that this will work?

 and yes, my cubes are Minecraft-Style. But i dont want to program a clone, i just want the terrain-style cube based.

 and sorry for my bad english :(

edit: I just bought the Engine!  :D

 
New Post
12/30/2011 9:27 AM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 446
Re: Custom Collision Object? 
mavonic wrote:

Hm... i need to check the Collision with the Map<>Player , so can i just make all cubes in a radius of 5 (or less) of the players-position to Collision Objects? If i do that, i will just have 20 Collision-Cubes. And if the player moves, the cubes (of the player-position) will Update to Collision Cubes.

 You think, that this will work?

Yes, that should work just fine. I suggest you start small and see how far you can increase the radius.

Here is a tip: 
The collision domain uses the "sweep and prune" as the broad phase algorithm. (Don't worry if you don't exactly know what this means. It is not necessary to know this stuff.) This algorithm might not be optimal in your case. At the start of your game of your game you can select a different broad phase algorithm, for example:

// This is the default:
_simulation.CollisionDomain.BroadPhase = new SweepAndPruneSpace<CollisionObject>();
 
// Here are other examples:
_simulation.CollisionDomain.BroadPhase = new DualPartition<CollisionObject>();
_simulation.CollisionDomain.BroadPhase = new DynamicAabbTree<CollisionObject> { EnableMotionPrediction = true, OptimizationPerFrame = 0.01f };
_simulation.CollisionDomain.BroadPhase = new AdaptiveAabbTree<CollisionObject>();

That's just something you try and see if it improves performance.

mavonic wrote:

edit: I just bought the Engine!  :D

I hope you enjoy working with the engine! :-)
If something is unclear or not working as expected, just let us know!

 
New Post
12/30/2011 7:18 PM
 
mavonic
No Ranking

www.mavonic.de
Joined: 9/26/2011
Posts: 26
Re: Custom Collision Object?  Modified By mavonic  on 12/30/2011 8:19:09 PM

Ah Danke. (habe gerade festgestellt das sie Österreicher sind, von daher können wir also Deutsch reden da mein English nicht so perfekt ist ;-) )

Ich werde es mal so versuchen. Aber "_simulation", braucht man das? also ich benutze es gerade so: "public CollisionDomain _CollisionDomain;" ... also ohne Simulation.


Und noch eine andere Frage:  Wie kann ich ein Textured-Model (ganz normales XNA-Model) in die Collision-Engine laden? ich meine das man nicht die vorgegebenen Geometry.Shapes verwendet? :D

mfg,

Marvin

 

 
 Page 1 of 2
12Next 
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineCustom Collision Object?Custom Collision Object?


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement