[Plib-users] Intersection Testing / 3ds loading
Brought to you by:
sjbaker
|
From: Thomas G. <pin...@we...> - 2001-09-05 16:53:59
|
I am writing a game with PLIB it's a kind of 3d jump n run (like "tux a =
quest fo herring"). First I used heightmaps (modified majik-example), =
but now I wanted to use models for my terrain.
I made some models using anim8or and tried to load them. Most of them =
were white, although I applied materials and if i applied textures they =
were stretched over the whole model (but I think that's a problem in =
anim8or). Can I apply states to ssgEntities? How can I modify the =
VtxTables (or whatever the loader uses to store the veritces) of the =
model I loaded?
Problem No. 2:
Intersection Testing. The HOT-Testing works fine, I've always been doing =
it like this:
invmat[3][0] =3D -ppos.xyz[0] ;
invmat[3][1] =3D -ppos.xyz[1] ;
invmat[3][2] =3D 0.0f ;
test_vec [0] =3D 0.0f ;
test_vec [1] =3D 0.0f ;
test_vec [2] =3D 100000.0f ;
ssgHit *results ;
int num_hits =3D ssgHOT ( tscene, test_vec, invmat, &results ) ;
phits=3Dnum_hits;
float hot =3D -1000000.0f ;
for ( i =3D 0 ; i < num_hits ; i++ )
{
ssgHit *h =3D &results [ i ] ;
float hgt =3D - h->plane[3] / h->plane[2] ;
if ( hgt >=3D hot )
hot =3D hgt ;
}
Now (that I have models for the terrain with some walls and steep =
planes) I wanted to use the LOS-intersection testing for checking if I =
am running against a wall.
But it didn't work. I tried it this way:
sgVec3 test_vec ;
sgMat4 invmat ;
sgMakeIdentMat4 ( invmat ) ;
invmat[3][0] =3D -pos[0] ;
invmat[3][1] =3D -pos[1] ;
invmat[3][2] =3D -(pos[2]+1.5) ;
test_vec [0] =3D 2.0*sin(turn*M_PI/180.0) ;
test_vec [1] =3D 2.0*cos(turn*M_PI/180.0) ;
test_vec [2] =3D 1.5 ;
ssgHit *results ;
int num_hits =3D ssgIsect ( tscene, sphere, invmat, &results ) ;
float ehot =3D -1000000.0f ;
for ( int i =3D 0 ; i < num_hits ; i++ )
{
ssgHit *eh =3D &results [ i ] ;
float ehgt =3D - eh->plane[3] / eh->plane[2] ;
if ( ehgt >=3D ehot )
ehot =3D ehgt ;
}
But it only showed my player's z-distance to the terrain and the normals =
of the polygons I am running on (I guess).
Well, very useful, too, but I wanted to know if my player is running =
against a wall (if the vector test_vec touches a plane).
What do I have to change?
Then I tried the Isect-method with a sphere:
sgVec3 test_vec ;
sgMat4 invmat ;
sgMakeIdentMat4 ( invmat ) ;
sgSphere *sphere;
invmat[3][0] =3D -pos[0] ;
invmat[3][1] =3D -pos[1] ;
invmat[3][2] =3D -(pos[2]+1.5) ;
sphere =3D new sgSphere;
sphere->setCenter(0.0,0.0,1.2);
sphere->setRadius(1.0);
ssgHit *results ;
int num_hits =3D ssgIsect ( tscene, sphere, invmat, &results ) ;
float ehot =3D -1000000.0f ;
for ( int i =3D 0 ; i < num_hits ; i++ )
{
ssgHit *eh =3D &results [ i ] ;
float ehgt =3D - eh->plane[3] / eh->plane[2] ;
if ( ehgt >=3D ehot )
ehot =3D ehgt ;
}
The Program crashes when I increase the sphere's radius, and plane[0] =
and plane[1] (A and B in the equation, I guess) change with the =
direction my player is looking in, plane[2 and 3] don't change. But the =
sphere touches neither the ground nor any other part of my scene.
Sorry for the long mail, but I am pretty in despair.
Cheeers, Thomas Gahr
|