From seeing your comments, I can easily see that you aren't happy about the performance

As other people recommended, you can check whether the object is affected by the light, here's how with a Point Light!

**Bounding Spheres**

Bounding Spheres is if you were to collect all the vertices in the mesh and make a sphere encapsulate them, like this:

RABBITS!

To get this result, you need **two things**:

- The
**center**of the mesh - The
**radius**of the mesh from the center

**Calculating the center**:

- Declare the variable
**Loop**over all your vertices and add them to the center**Divide**the center by the number of vertices.- THAT'S IT!

D3DXVECTOR3 center = D3DXVECTOR3(0, 0, 0); for(int v = 0; v < mVertices.size(); v++ ) { center += mVertices[v]; } center /= mVertices.size();

**Calculating the radius**: (With the center)

- Declare the variable
**Loop**over all the vertices- Get the
**distance**between the vertices and the center - Find the greatest
**length**

float radius = 0.0f; for (int v = 0; v < mVertices.size(); v ++) { D3DXVECTOR3 diff = mVertices[v] - center; float length = sqrtf(D3DXVec3Dot(&diff, &diff)); if (length > radius) radius = length; }

To ** visualize **the result, you just need to

**translate**a sphere (or stuff) to this location: sphere->Translate(mesh->

**Position**+ mesh->

**Center**), and also

**scale**it by the meshes

**radius**.

**Testing for collision between Sphere-Sphere**

As you know the point light has a **radius**, and so does, hopefully, the mesh with these calculations. To see if they **collide**, just do the following

- Find the
**vector**between the mesh center and the point light's position. - Get the
**length**of that vector **Check**whether that length is smaller than both the point light's radius and the mesh's radius.- If true, they
**collide**!!!

D3DXVECTOR3 mDistance = mesh->center + pointLight.Position; float d = sqrtf( D3DXVec3Dot( &mDistance, &mDistance) ); if (d < (mesh->BoundingSphere.radius + pointLight.Range) ) // They collide!!!

In other words, if they collide, the light **will **affect the mesh.

Mini Tutorials!