Vector3f "add" function

I’m trying to add two vector3fs together. Is there any specific reason why the below shouldn’t be happening? My result is (0.0f, 1.0f, 0.0f). Why?..



…//the usual



private Vector3f a = new Vector3f(0.0f, -1.0f, 0.0f);

private Vector3f b = new Vector3f(0.0f, -1.0f, 0.0f);



private void onePlusOne(){

a.add(b);

System.out.print(a);

}

… //end class



And the resulting printout reading:

(0.0f, -2.0f, 0.0f)





Any help appreciated!

I’m sorry, what do you mean by your result being 0,1,0?

(-1) + (-1) should be (-2), so the print out would be correct if you used the addLocal method or printed out the returned value. Surely you could impossibly get 0,1,0 however.



Edit: Fixed answer as I misread what variable was actually printed out.

1 Like

-1 + -1 = -2



also vectorA.add(b) returns the result, it does not store it in the vector ‘a’. So you will just get the starting value. Use vectorA.addLocal(b)

3 Likes

Thanks guys, I did try addLocal before but it didn’t work, but probably for some other reason (read: fault riddled code :D)



Thanks a tonne, addLocal does indeed store, which is what I needed!