Polygon picking?

Started by Kaiidyn, February 09, 2011, 11:01:35 AM

Previous topic - Next topic

EgonOlsen

You can use the same collision detection approach that are using for picking to detect the height of the terrain simply by shooting a ray from above down to the terrain and calculate the intersection point. Alien Runner does this for example. That's what i would do with a terrain on the desktop. On Android, it might be a better idea to keep some simplified data structure storing the average height of a "tile" of the terrain and interpolate between those. It's not as accurate though, but should be much faster.

paulscode

I'm not sure the procedure you used to create your terrain, so this might not apply, but in my RobotBuilder project, I have the terrain built as a tiled grid with a height for each vertice.  I can accurately know the height at a given 2D coordinate on the map by interpolating between the two horizontal and two vertical vertices, as long as the remaining "catty-corner" vertice isn't completely different than the other three (which I've made sure of when I originally created the terrain).  I can provide some example code if that is hard to visualize from my description.

Kaiidyn

I used my heightmap2serialized object generator :p (current name terragen :-\ ) to create the terrain,
some example code would not hurt (I even prefer getting some :) )

Terragen download (source)
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Kaiidyn

I still dont got this 'waling towards' a vector to work.
and have no clue on how to do this ..  :( would prefer an example ... :)
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Kaiidyn

#19
Finally figured it out.. Is is being done using Lerp

float speed = (0.5f * ticks);
float timeToGetThere = 1.0f / playerPos.distance(gotoPos) * speed;

playerPos = lerp(playerPos, gotoPos, timeToGetThere);
player.clearTranslation();
player.translate(playerPos);


Lerp function:
private SimpleVector lerp(SimpleVector start, SimpleVector end, double time){

float x = (float) (start.x + (end.x - start.x) * time);
float y = (float) (start.y + (end.y - start.y) * time);
float z = (float) (start.z + (end.z - start.z) * time);

return new SimpleVector(x, y, z);

}


What I still need though is to get the height based on terrain... at playerPos.x, playerPos.z
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Kaiidyn

The direction vector in
this.terrain.calcMinDistance(SimpleVector.create(x,y,z), direction, 100);
to cast this down, should it be 0,1,0?
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

EgonOlsen


Kaiidyn

#22
wow, that was fast :p lol ok thanks :)


Got my getTerrainHeightAtXZ function finally working now :D
public float getTerrainHeightAtXZ(float x, float y, float z){

direction = SimpleVector.create(0,1,0);
distance = this.terrain.calcMinDistance(SimpleVector.create(x,y,z), direction, 1000);

if(distance != Object3D.COLLISION_NONE){

collisionPoint = direction;
        collisionPoint.scalarMul( distance );
        collisionPoint.add( SimpleVector.create(x,y,z) );
        Log.d(collisionPoint.y + "");
        return collisionPoint.y;

}


return 0;
}


Thanks for all the help :)
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch