5 Replies - 647 Views - Last Post: 06 August 2013 - 08:20 PM Rate Topic: -----

#1 football1994  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 01-July 13

Collision map on a heightmap

Posted 04 August 2013 - 03:20 PM

Hi guys

I read a post in the forums that was about 2d collision detection(link below)
and one reply suggested that a collision map be used so I started researching the subject
an wanted to know if something like this had been implemented on a 3D terrain(2D heightmap)I came across
different answers like how its good to have a pattern map on a procedurally created terrain
so you wont have to calculate texture coordinates(z,x) on the fly everytime, what I would like to do is have a ray collision method return the texture coordinates of the heightmap using the collision map as the coordinate info source, but I have yet to find something like a tutorial that has a process as to how to create a collision map for a heightmap, if anyone has any suggestions or tips on what I should be researchig it would be much appreciated.


Thankyou


the 2D collision link

http://www.dreaminco...sion-detection/




I think what Im looking for is a 3d version of the link below

http://www.xnaresour...ial:ColorKeyMap




below is a link to provide a visual of what Im trying to do, having my
character shootout particles depending on what texture is being stepped on.
I know that I have a long way to go but this youtube video provides a perfect
illustration of what Im trying to accomplish.


http://www.youtube.c...h?v=azBWIT2d36Y

Is This A Good Question/Topic? 0
  • +

Replies To: Collision map on a heightmap

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Collision map on a heightmap

Posted 04 August 2013 - 06:31 PM

So you want to know how to walk a heighmap without falling through?
Was This Post Helpful? 1
  • +
  • -

#3 football1994  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 01-July 13

Re: Collision map on a heightmap

Posted 04 August 2013 - 10:43 PM

Thanks for replying ButchDean.Ive been using a heightmap project from a website(riemers) as a platform to learn different areas of programming(collision detection, shaders,etc,...)and during my research and learning I came across a project that uses riemers terrain as a platform as well(youtube link below) and decided to try to modify it so that the highlighted triangles would change color depending on what texture was being intersected(ex. if ray intersect grass texture triangles turn green,if intersect sand texture triangles turn yellow),so I did more research to find out how this is done and came across and tested different triangle uv methods and decided to use a barycentric based method(link and code below) but after different approaches using the method I still couldnt implement the effect I wanted, so I figured maybe its the terrain itself and did even more research on that, which brings me to the latest advice that I received in which I was told that I needed some kind of underlying map or pattern map to use as a guide to pick up the texture coordinates, but the research Ive done on this hasnt turned up many results and the info I did find, only had to do with 2D collision maps.



to give you a visual, below is a youtube link from the original version of the project Ive been working on trying to modify by adding an underneath collision map.

http://www.youtube.c...h?v=_mrzVoorhCY


riemers terrain tutorial
http://www.riemers.n...arp/series4.php


barycentric link
http://www.blackpawn...ts/pointinpoly/




and the barycentric method Im using

 public   bool RayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction,
                    Vector3 vert0, Vector3 vert1, Vector3 vert2,
                    out float? t, out float u, out float v)
        {
            t = 0; u = 0; v = 0; 

            Vector3 edge1 = vert1 - vert0;
            Vector3 edge2 = vert2 - vert0;

            Vector3 tvec, pvec, qvec;
            float det, inv_det;

            pvec = Vector3.Cross(ray_direction, edge2);

            det = Vector3.Dot(edge1, pvec);

            if (det > -0.00001f)
                return false;

            inv_det = 1.0f / det;

            tvec = ray_origin - vert0;

            u = Vector3.Dot(tvec, pvec) * inv_det;
            if (u < -0.001f || u > 1.001f)
                return false;

            qvec = Vector3.Cross(tvec, edge1);

            v = Vector3.Dot(ray_direction, qvec) * inv_det;
            if (v < -0.001f || u + v > 1.001f)
                return false;

            t = Vector3.Dot(edge2, qvec) * inv_det;

            if (t <= 0)
                return false;

         





            return true;
        }
     
    }
}





Thanks again
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Collision map on a heightmap

Posted 05 August 2013 - 04:41 AM

It looks to me like your final goal is to simply walk the terrain, and if this is the case then you do not need to analyze the textures at a point, just the height map data and interpolate between vertices to get the current height.
Was This Post Helpful? 1
  • +
  • -

#5 BBeck  Icon User is online

  • Here to help.
  • member icon


Reputation: 536
  • View blog
  • Posts: 1,191
  • Joined: 24-April 12

Re: Collision map on a heightmap

Posted 06 August 2013 - 05:12 AM

I got to thinking about the problem that you are wanting to solve and doing a tutorial on it. And that got me to thinking about how I would approach the problem.

So, if I wanted to do particle effects based on the type of terrain that the user is over, here's what I would do.


First of all, I would start with two "maps". A map is just a picture/photo/image/Texture2D that is used to store data, whether that's a picture or not.

The two maps would overlay one another and perfectly match the integer size (width and depth) of my grid. The first map would be my height map to determine terrain height for each corner of each grid quad. The second map would store an integer that determines the terrain type, and thus texture, used at that corner of the grid quad. So, the textures would be blended between the corners of the grid quads. Set all 4 corners to one terrain type and the entire quad represents that type of terrain, plus at least a quarter to a half of all the surrounding quads.

Once I had this, then all I have to do is figure out which quad the user is in, just like determining terrain collision and I can simply look at the terrain map value array to determine what type of terrain the user is over.


So, user's position is X=28.7, Y=14.4. The "cheat" method just to get started is to round values to the nearest integer (the right way to do it is interpolate). So, that would make the user's position X=29, Y=14 and you would look that up in the terrain map at position 29,14 in the map and read the value. Maybe the value is 4 which means grass. So, you produce grass particles because the user is on grass. Maybe 5 means sand and so you produce sand particles when the value is 5 and maybe 1 is concrete and you produce no particles.

Likewise, I would write a multi-texture shader in HLSL to shade the terrain based on the terrain map values. Here you would almost have to interpolate to transition visually from one terrain type to the other. XNA has a multi-shader built in, but I think it only handles two textures and so I don't think you can use it to do 20+ different terrain types and would have to write your own.

This post has been edited by BBeck: 06 August 2013 - 05:14 AM

Was This Post Helpful? 1
  • +
  • -

#6 football1994  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 01-July 13

Re: Collision map on a heightmap

Posted 06 August 2013 - 08:20 PM

Quote

I got to thinking about the problem that you are wanting to solve and doing a tutorial on it.



YESSS A TUTORIAL,FANTASTIC!!!! :yes:/>

Thanks for replying also BBeck,this is something Ive been stuck on forever and a forum tutorial would be great!,



Thanks again and GOOD LUCK :D/>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1