applying force to more than one object
<p>hi i have been working with chai-3d and opengl for creating a simulation for haptic device . i have drawn a sphere which is positioned at center and another small spheres positioned around the center sphere, for each 15deg a sphere will be drawn based on the center sphere.below piece of code will draw center sphere.</p>

<pre><code>cShapeSphere *sphere;  
cShapeSphere* sphere2;
void sphere(void)
{
float r1=0.020;
float a=0.0;
float b=0.0;
float r2=r1/6;
float th=15;
double pi=3.14159265;
sphere =new cShapeSphere(r1);
world-&gt;addChild(sphere);
sphere-&gt;setPos(0,a,b);

//this will draw small sphere around the main sphere
for(int j=1;j&lt;=24;j++)
{
sphere2 =new cShapeSphere(r2);
world-&gt;addChild(sphere2);
sphere2-&gt;setPos(0,a+(r1+r2)*cos(th*j*pi/180),b+(r1+r2)*sin(th*j*pi/180));

 //this were i apply the force
 double strength = pow((sphere2-&gt;getRadius() - length) * 8000,2);
 force = (c_pos - spos) * strength;
 //the calculated force is sent to haptic device
  hapticDevice-&gt;setForce(force);
}
}
</code></pre>

<p>when i tried to apply the force for all the smaller spheres,the force is detected only on the first smaller sphere positioned at 15 degree.cant apply force for the spheres positioned at 30 degrees to 360 degrees.the calculated force is sent to the haptice device.the problem is with the spheres,were 24 smaller spheres are drawn around the center sphere.the variable that i used to draw the 24 spheres is sphere2.let us consider iam drawing the spheres by giving different variable name say sphere 1 to 24,there i can apply the force without any problem because i use different variables but if i use same name for drawing all the spheres then the force is applied only at the first iteration...the force is not applied for other 23 iterations out of 24.i have to iterate the force along with the sphere position.</p>
