How to set camera orientation to see a sphere that is ON polydata actor.

Hi,
In my render window I have 2 actors, a little red sphere and a brain surface, the sphere takes different positions on the brain surface in each render.

I need to change the orientation of the camera depending on the position of the sphere to see the right (good) side of the brain where the sphere is.

I managed to change the orientation of the camera using the setDirectionOfProjection function but I don’t know the right value to give.

image

image

Thank you

You can check the highest normalized vector component value of the vector contructed from the center to the red sphere.
if the center of the brain is [10,10,10], and the red sphere is [20,-3,9], the vector is [10,-13,-1], and something like [0.6, -0.7,-0.1], hence the highest normalized vector component value is -0.7, and the camera should be looking in [0,1,0], aka +Y.

2 Likes

Thank you so much!

This is how I did it, maybe it will help someone:

    let v = [0,0,0]
    const xyzSphere = sphere3D.current.getCenter();
    const xyzBrain = [90.5,127.5,127.5] // the center of the brain
    const diff = [xyzSphere[0]-xyzBrain[0], xyzSphere[1]-xyzBrain[1], xyzSphere[2] xyzBrain[2]];
    const absDiff = diff.map(Math.abs);
    let max =  {
      value:0
    };
    absDiff.map((abs,i)=>{
      if(abs>max.value){
        max = {
          value: abs,
          i: i
         }
      }
       
    });
    const plusOrMinus = diff[max.i] > 0 ? -1 : 1;
    v[max.i] = plusOrMinus;
    GLWindow.getRenderer().getActiveCamera().setViewUp(viewUp);
    GLWindow.getRenderer()
    .getActiveCamera()
    .setDirectionOfProjection(v[0],v[1],v[2]);