I mean the one for " the BSP FAQ " (checking for Ray intersections).

Couldn’t you give me a short example that uses sphere ray intersections ?

I can’t figure out how to create the x/y coord for the ray.

I found this function:

```
```

Ray3D(Point3D const &p, Vector3D const &v):p§,v(v)

/*…*/

intersection(Ray3D const &r, Sphere3D const &s)

```
```

call:

```
float x=/*???*/;
float y=/*???*/;
Ray3D r1(Point3D(x,y,0),Vector3D(0,0,1));
Sphere3D s1(Point3D(-1.5f,0.0f,-6.0f),2.0f);
Sphere3D s2(Point3D(1.5f,0.0f,-7.0f),2.0f);
float t = intersection(r1,s1);
```

If t is #INF then there is no collision.

EDIT:

What do you think about that ?

```
POINT lMousePos;
GetCursorPos( &lMousePos );
lMousePos.y=480-lMousePos.y;
float depth[1];
GLdouble modelm[16], projm[16], pos[3];
int view[4];
// ret;
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
glGetDoublev( GL_MODELVIEW_MATRIX, modelm );
glGetDoublev( GL_PROJECTION_MATRIX, projm );
glGetIntegerv( GL_VIEWPORT, (GLint*)view );
glReadPixels(lMousePos.x,lMousePos.y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,depth);
gluUnProject(lMousePos.x,lMousePos.y,depth[0],modelm,projm,(GLint*)view,&pos[0],&pos[1],&pos[2]);
```

```
Ray3D r1(Point3D(pos[0],pos[1],pos[2]),Vector3D(0,0,1));
Sphere3D s1(Point3D(-1.5f,0.0f,-6.0f),1.0f);
Sphere3D s2(Point3D(1.5f,0.0f,-7.0f),1.0f);
float t = intersection(r1,s1);
float t2 = intersection(r1,s2);
char text[100];
sprintf(text,"Collis 1: %f
Collis 2: %f",t,t2);
MessageBox(HWND_DESKTOP,text,"",0);
```

That seems to work, I just have to Replace the “Point3D” settings to my model-translate-code