Elevation - getHeightAt is calculated on the bitmap pixel

Software: Away3D 4.x

Avatar
Baush, Sr. Member
Posted: 30 August 2011 04:51 PM   Total Posts: 135

Hello, I have generated a terrain using the Elevation class. I need to adjust an object’s Y to match the terrain.

The problem is, the getHeightAt method of the Elevation class is based on the bitmap pixel. I would need to get the exact height between the 4 points of the face to avoid a “stair” effect.

Thanks!

   

Avatar
Fabrice Closier, Administrator
Posted: 31 August 2011 10:06 AM   Total Posts: 1265   [ # 1 ]

Now you test probably at one location, say the “car” position and get these intersects at the wheels. Why not ask each wheel positions to adjust the suspension?

Sure you can use a physics engine and use a prefab suspension code, but this engine will probably in the end, check more than the 4 points you need…

Another approach, also cost effective, could be to generate an objectspace normalmap of the terrain and average the 4 green values you get at the wheels, in order to generate a Y axis that you can use to orientate the body of the car. If the terrain is very rough or the car is expected to be very low on the surface, you would then need probably more than 4 points.

 

   

Avatar
Baush, Sr. Member
Posted: 31 August 2011 11:48 AM   Total Posts: 135   [ # 2 ]

Thanks Fabrice, I won’t be using a car, but simply a walking character, so I only need one point. Perhaps I could use a vertical Vector intersection with the terrain mesh to get an accurate Y value within a single face.

Note that the terrain mesh is very low poly, so points are far away from each other and the elevation is adjusted based on the closest point (which is resulting in a stair effect).

Thanks!

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 31 August 2011 01:35 PM   Total Posts: 669   [ # 3 ]

Sounds like you’re on the right track.
You need to find the y value that satisfies the equation of the plane.
You can see the maths, and many other useful mathematical stuff here…
http://paulbourke.net/geometry/planeeq/

In actual fact you are going to be finding the normal of a triangle rather than a square, as Away uses triangles rather than quads, and 4 points might not necessarily be on same plane.

 

   

Avatar
Baush, Sr. Member
Posted: 05 September 2011 10:56 PM   Total Posts: 135   [ # 4 ]

Thanks MightyAtom,

Any idea how I could get a reference on the face at x,z ? I can loop through all faces of the mesh until I find the one under the character, but I doubt this will have a good performance.

Are there any utility functions in Away3D ? Like a vertex to mesh intersection function? or get face at x,y,z or something?

Thanks again for your help, I’m not much of a math guy wink

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 06 September 2011 05:39 AM   Total Posts: 669   [ # 5 ]

If ur more of a “visual mathematician” I have a handy trick for you.
You can use Flashes inbuilt color interpolation and just read the value.
You have a height map. If you scale that and allow smoothing you will find flash finds all the colours in between the actual pixels. You need to wrap the scaled bitmap in a Sprite and read the “getPixel” values from a snapshot of that, otherwise flash ignores the scaling and gives you the same value as before. Hope that helps, unfortunately I don’t have flash infront of me, but if you need an example of what I mean, just say the word smile

 

   

Avatar
Fabrice Closier, Administrator
Posted: 06 September 2011 09:20 AM   Total Posts: 1265   [ # 6 ]

@baush.  To do this, I would use an octree. Each octant would hold refs to faces. But you could also build something way less complex for your case by simply looking at the construct of the plane or model (before it was elevated), at least if it was generated with a loop. If you know the col/rows the very same coordinates that you use for the getHeight could be used to calculate and pin point the indices of the faces you need to ray/hittest. This way no need to parse the entire buffer.
2 classes also could help you in these ray/uv’s tests, in tools.utils: Ray and BaryCentricTest.

 

   

Avatar
Baush, Sr. Member
Posted: 07 September 2011 07:43 PM   Total Posts: 135   [ # 7 ]

I’ve been trying to get this to work, but I hope someone can help me with it. Here’s what I have so far:

var indices:Vector.<uint> = _terrain.geometry.subGeometries[0].indexData;
    
    var 
mapX:Number = ((_mesh._terrain.width) * _terrain.segmentsH) + _terrain.segmentsH 2;
    var 
mapY:Number = ((_mesh._terrain.depth) * _terrain.segmentsH) + _terrain.segmentsH 2;
    
    var 
indice:int indices[Math.floor(mapX mapY) * 3];
    
    var 
vertex:Vector.<Number> = _terrain.geometry.subGeometries[0].vertexData;
    
    var 
ray:Ray = new Ray();
    
    var 
meshVector:Vector3D ray.getRayToTriangleIntersection(
     new 
Vector3D(_mesh.x5000_mesh.z), new Vector3D(_mesh.x0_mesh.z)
     ,new 
Vector3D(vertex[indice]vertex[indice 1]vertex[indice 2])
     ,new 
Vector3D(vertex[indice+3]vertex[indice 4]vertex[indice 5])
     ,new 
Vector3D(vertex[indice+6]vertex[indice 7]vertex[indice 8])
    ); 

Here’s a demo of the “stair effect”:

http://www.chitchatcity.com/beta/3d

use W and mouse drag to move around

 

   

Avatar
Baush, Sr. Member
Posted: 08 September 2011 02:23 AM   Total Posts: 135   [ # 8 ]

Also, based on the demo up there, any idea why the terrain gets clipped at the lens.far but not the sprite3Ds ?

 

   

Avatar
Ringo Blanken, Administrator
Posted: 08 September 2011 06:16 AM   Total Posts: 120   [ # 9 ]

The example isn’t working with the latest rev.
You might want to update the example to the latest player and update Away3d from github.

 

 Signature 

Freelancer: http://www.ringo.nl/en/
http://www.jiglibflash.com
http://www.awayphysics.com
http://www.away3d.com

   

Avatar
Baush, Sr. Member
Posted: 08 September 2011 01:02 PM   Total Posts: 135   [ # 10 ]

Updated the demo with the latest of everything. Adobe’s been busy lately wink

 

   

Avatar
Alejandro Santander, Administrator
Posted: 08 September 2011 01:46 PM   Total Posts: 414   [ # 11 ]

Having a ray collision checking package in Away3D would be useful for this kind of stuff. Will put in in my todo list!

 

   

Avatar
Alejandro Santander, Administrator
Posted: 08 September 2011 02:07 PM   Total Posts: 414   [ # 12 ]

Talking with Fabrice Closier he says we already have a Ray class that could be used for this. Check it out.

BUT he says you don’t need that, look at his blog for an example of how to make a character move over a terrain.

 

   

Avatar
Fabrice Closier, Administrator
Posted: 08 September 2011 02:42 PM   Total Posts: 1265   [ # 13 ]

if you want to smoothen readings, take a look at “smoothHeightMap” method. It generates a gradient map from your original map, that takes care of the bumpy readings.
Also make sure that the map you use has enough definition or use the smoothedHeightMap getter and rescale it.

Here old an tut, but still using same principles.
http://www.closier.nl/blog/?p=69

Also take a look at Terrain.as demo that David did for Broomstick. Also using same principle.

 

   

Avatar
Baush, Sr. Member
Posted: 08 September 2011 03:38 PM   Total Posts: 135   [ # 14 ]

You meant SimpleTerrainTest.as right?

From what I see, it’s adjusting the camera based on the pixel info, and smoothes the Y deltas each frame to make a smooth transition between the 2 Y values. It works fine for a camera, but for a character, you see its feet are clipped in the ground, or flying over the ground if the Y value is not exact.

Same thing will most likely happen with a smoothed height map, but I’ll give it a try.

The Ray class should do the trick once I get a reference on the face at x, z .

Thanks!

 

   

dreammagician, Newbie
Posted: 26 August 2012 01:56 AM   Total Posts: 1   [ # 15 ]

demo
http://121.22.88.100/vrbuildingdemo.html

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X