Aligning Models

Can put two points on the model and get it to align with the camera or something?

This is what I want to do with it:

It’s truly easiest if the two points are already aligned along z… as in tipSight.x - buttSight.x = 0 and tipSight.y - buttSight.y = 0

And if tipSight.z - buttSight.z = positive value then the rotation to apply is just the camera rotation.

Edit: else step 1 is to figure out the model’s rotation necessary for the above conditions to be true… which is possible but not as trivial as if they are already lined up. So I thought I’d figure out the requirements first.

what? Little confused by what you mean


Which part?

tipSight.z - buttSight.z = positive value, what does this mean
and tipSight and buttSight is what kind of object

Ok… how do you define the two points on your model? Because it seems you don’t have enough imagination to know what I mean from your picture.

So tell me SPECIFICALLY what you start with IN CODE.

public void setViewModel(Gun g) {

this.viewModel = (Node) g.getViewModel();
viewModel.rotate(new Quaternion().fromAngleAxis(FastMath.PI  ,   new Vector3f(0,1,0)));
viewModel.setLocalTranslation(4, -12, -11);


I don’t know how to do the aligning part…

I have two nodes set up on the sight but thats all I got

And what do you call those? Because my names didn’t work for you.

backSight and frontSight

So, those would have been my buttSight and tipSight.

What is the value of frontSight.getLocalTranslation().subtract(backSight.getLocalTranslation())?

(0.0, 0.0, 19.0)

Great… so to ‘align’ the model all you have to do is like I said in the first post. Set the gun’s rotation to the same as the camera rotation.

And by set the gun’s rotation, I mean gun setLocalRotation() and by camera’s rotation I mean camera.getRotation().


And as a bonus, if you want the gun sights to be in the middle of the screen then you will also want to move the model down:
g.getViewModel().move(0, -backSight.getLocalTranslation().y, 0);