I’m making a new spell-type for my game that works like a laser beam. I’ve managed to generate a flat plane between the start of the beam and the end of the beam, but now I’m having trouble getting the plane to rotate around its axis so that it faces the camera.
So far I’ve been trying to use the
.fromAngleAxis();method - the only problem is I cannot seem to supply the correct degree value based on the current camera angle
Vector3f dirToCam = app.getCamera().getLocation().subtract(beamLocation);
float degrees; // = ????;
//some of my failed attempts at math....
// degrees = beamDir.dot(dirToCam);
// Vector3f cross = beamDir.normalize().cross(dirToCam.normalize());
// tempQuat.lookAt(beamDir, upVec);
// degreese = tempQuat.toAngleAxis(cross);;
// degrees = FastMath.pi * 3/2 ; constant value to test a working rotation during my trial and error attempts
beamGeometry.getLocalRotation().fromAngleAxis(degrees * FastMath.RAD_TO_DEG , beamDir);`
I found through trial and error that if I set a constant values for the degree parameter, then I can get my shape to face that direction. So I was able to find out that this method does what I want if I give it the right paramaters…
But I’m unable to find how I should calculate the proper degree value based on the beam direction and the camera angle.
The first thing I tried was crossing the beamDirection with the cameraDirection, but I don’t know how to get an angle value based on the crossed vector.
This is what the beam looks like when I set it to a constant 90 degrees with Fasmath.pi * 3/2 as the degrees paramater
Thanks in advance for any help