This sounded so simple in my head

Please excuse my odd variable and method names


    /**
     *This should come up with a point between p1 and p2 that is desiredDistance from p2.
     */
     private Vector3f calculateLineDistance( Vector3f p1, Vector3f p2, float desiredDistance ) {
  
            /*
             * P = P1 + k * (P2 - P1)
             */
           
            float length = p1.distance(p2);
        
            float k = 1 / length;
           
            k = 1 - k * desiredDistance;
           
           
            Vector3f P1_plus_P2minusP1 = new Vector3f(p1);
         
            Vector3f P2_minus_P1 = new Vector3f(p2).subtract(p1);//
               
            P2_minus_P1 = P2_minus_P1.mult( k );
        
            P1_plus_P2minusP1 = P1_plus_P2minusP1.add(P2_minus_P1);
           
            return P1_plus_P2minusP1;
        
     }



It's almost 4 am here and I've been hitting my head against this one for a bit.  Can someone who has a firmer grasp on jME and 3D tell me why that bit of horror above doesn't work?

I'm trying to make some objects in my scene tag along a certain distance from the camera.  It only works on a couple of the objects out of the 50 in total depending on what angle I'm looking at them while moving the firstperson controller around.  The call to it looks something like this:



object.setLocalTranslation( calculateLineDistance( objectLocation, cameraLocation, 1000 )  );




...at this point I don't trust my eyes or ears or....thoughts anymore.  :P

Thanks for any help - jME is awesome.

too lazy to read your code, but the formula should be



v2+(v1-v2)*0.5

v2.add(v1.sub(v2).mult(0.5)) or something

wooyay said:

too lazy to read your code, but the formula should be

v2+(v1-v2)*0.5
v2.add(v1.sub(v2).mult(0.5)) or something


I don't want to read it anymore either  ;)  Thanks for your help wooyay!  I was being stupid.  :)