I am making an application in that i am rendering an 360 image and i want to add an object or cross hair in front of camera i.e(billboard concept).
So i have tired alot of thing from stack overflow itself but i didn't get any idea how i can do that below is my code which i am trying to do.
Vector3 position;
float[] newPosition4 = new float[4];
position = obj.getPosition();
float[] posVec4 = {0, 0, -8, 0.0f};
float[] HeadViewMatrix_inv = new float[16];
Matrix4 HeadViewMatrix4 = new Matrix4();
HeadViewMatrix4.setAll(getCurrentCamera().getViewMatrix());
HeadViewMatrix4 = HeadViewMatrix4.inverse();
//Copy matrix to HeadViewMatrix array,
HeadViewMatrix4.toFloatArray(HeadViewMatrix_inv);
//Translation of viewMatrix
Matrix.multiplyMV(newPosition4, 0, HeadViewMatrix_inv, 0, posVec4, 0);
obj.setPosition(newPosition4[0], newPosition4[1], newPosition4[2]);
So any one can help me out in this.
If I understand what you are asking for this is pretty much the simplest thing to do. You need to construct a new matrix or simply remove the current one (use identity).
With identity by drawing a line from A(-0.5, 0.0, 0.0)
to B(0.5, 0.0, 0.0)
will draw a straight vertical line in the middle of your screen. which will take half of your screen size centered in the middle.
I suggest you use orthographical projection matrix with screen coordinates and place your object in the middle as you would do another view (width/2
, height/2
) with a constant size.
But make sure your depth buffer is disabled when you draw this element if you want to keep it always visible.
If for some reason you want to keep the object in front of you using frustum matrix and possibly even keep the depth test then you simply need to keep the same projection matrix (frustum part) and set the view matrix to identity (the one from the camera). With these being set all you need to do is place the object in front of absolute zero (.0f, .0f, distanceToObject)
.