Camera - rubberband effect

Hi All,

Anybody know how to add the Rubberband effect
to a camera.
so that a camera following a moved model will drift to its position behind that model after a short time.

Thanks

Rmdire

A dead easy way to get a smooth drift into position is to get the new position by a weighted avarage of the current position and the target position. Do that every frame with a sufficiently high weight (about 0.98 usually works well) and it’ll gently drift into place.

One snag is that this method depends on your framerate. Theres a slightly complex way to make it framerate-independant but I can’t remember that off hand (don’t usually need it though).

Hi - I’ve tried to implement a weighted average on the view - as follows:

public Vector3f getWeightedDistance(float weighting,Vector3f modelPosition,Vector3f correctDistance,Vector3f cameraPosition)
{
float xDistance = 0.0f;
float yDistance = 0.0f;
float zDistance = 0.0f;

        float xWeightedDistance=0.0f;
        float yWeightedDistance=0.0f;
        float zWeightedDistance=0.0f;
        
        

     xDistance = modelPosition.x-cameraPosition.x;
     yDistance = modelPosition.y-cameraPosition.y;
     zDistance = modelPosition.z-cameraPosition.z;

    if(xDistance>correctDistance.x)
    {
        xWeightedDistance=(correctDistance.x + xDistance)/2*weighting;
    }
    if(yDistance>correctDistance.y)
    {
        yWeightedDistance=(correctDistance.y + yDistance)/2*weighting;
    }
    if(zDistance>correctDistance.z)
    {
        zWeightedDistance=(correctDistance.z + zDistance)/2*weighting;
    }

    if(xDistance<correctDistance.x)
        {
          xWeightedDistance=(correctDistance.x + xDistance)/2*1.2f;
        }
        if(yDistance<correctDistance.y)
        {
          yWeightedDistance=(correctDistance.y + yDistance)/2*1.2f;
        }
        if(zDistance<correctDistance.z)
        {
          zWeightedDistance=(correctDistance.z + zDistance)/2*1.2f;
        }

  cameraPosition.x+=xWeightedDistance;
    cameraPosition.y+=yWeightedDistance;
    cameraPosition.z+=zWeightedDistance;
    
   
    
    
    
    return cameraPosition;
    }

}

and then used View.getTransform.lookAt()

as follows

view.getTransform().lookAt(getWeightedDistance(0.98f,characterControl.getXYZ(),new Vector3f(5.0f,1.0f,5.0f), v), new Vector3f((float)characterControl.getXYZ().x, 1.0f, (float)characterControl.getXYZ().z ),new Vector3f(0, 1, 0));

this seems to work - but how can I apply this to rotating the camera around the model position?

rmdire

note - in reference to above code,

the method :

characterControl.getXYZ()

returns a vector3f of the model current position.

Thanks for your Help

rmdire

I found the following link - which appears to do what I want - in c/c++.

http://www.firestorm.go.ro/Tutorial1.htm

If people want it - after I convert the code , I’ll post a Java version.

Rmdire