You may calculate the angle using some basic trigeometry but i think you'll run into problems when hitting the 90° barrier...at least that's what happened to me, but i'm not sure if its possible to get around this or not. SimpleVector has a getRotationMatrix()-method that can be used to simulate a kind of lookAt for objects. I've done simple example myself and it seems to work. First, i've created myself a turret with a gun out of primitives like so:
Object3D turret=Primitives.getCube(1f);
turret.setOrigin(turretPos);
w.addObject(turret);
turret.build();
Object3D gun=Primitives.getBox(0.1f,20f);
gun.rotateX(-(float)Math.PI/2);
gun.rotateMesh();
gun.setRotationMatrix(new Matrix());
w.addObject(gun);
gun.setOrigin(turretPos);
gun.build();
SimpleVector offset=new SimpleVector(0,0,3);
gun.setRotationPivot(turret.getRotationPivot().calcSub(offset));
gun.translate(offset);
You already have a model for this, i assume. So the following may look different for you depending on the orientation of it...anyway, i did this to make the turret/gun combo follow a target:
// Get the vector from the turret to the target (o2 is the target)
SimpleVector xd=turret.getTransformedCenter();
xd.scalarMul(-1f);
xd.add(o2.getTransformedCenter());
// Copy it...
SimpleVector yd=new SimpleVector(xd);
// Make the turret rotate in the x-z-plane only
xd.y=0;
// Create needed rotation matrices
Matrix rotX=xd.getRotationMatrix();
Matrix rotY=yd.getRotationMatrix();
// Apply them
turret.setRotationMatrix(rotX);
gun.setRotationMatrix(rotY);
The basic idea is, to make the turret lookAt() in the z-x-plane only, while the gun tracks the target without any limitation. I'm still not sure that this is 100% correct in all cases but it worked fine in my example.