Fixed object in front of camera

Started by Peter Dym, November 21, 2011, 05:00:52 PM

Previous topic - Next topic

Peter Dym

I'm playing with jPCT-AE instead of playing real games :-)  I'm getting familiar with jPCT-AE by creating a simple fly simulator. I have created a terrain, I'm able to load a biplane, animate it and control the plane by sensors or by touch screen. I'm able to add buttons and other controlling features to the scene by blitting images.
And I would like to add a cockpit panel to the screen. I have a camera, its position and direction and I need an object (e.g. textured sphere) which will be added to the one fixed position. I can move arround my world, follow my plane but the object - actually the artifical horint (AF) should be fxed in one point in my view. I am faling to do that. My AF is always moving with my plane across the screen. I also wanted to test to create a new frame bufffer  with world with cockpit and render  it to texture - then blit it - but to have two different fb failed also. I feel that the solution can be simple and obvious. Any suggestions?

EgonOlsen

There's an align method in Object3D to align an object with the camera. It only affects the rotation though, so you have clear the objects translation and translate it to the camera's position plus some offset in the camera's direction. That should actually do the trick.

Peter Dym

#2
Thanx for the answer. This is exactly what I'm trying. But probably wrongly and I'm not able to get it work. That's why I'm bothering the forum. The rotation of the artifical horizont is given by the actual rotation of the airplane so it cannot be aligned. Only the position is important for me.
I do not know what actually to do with the cam.getPosition() to set the object's position to "a little" bit in the cam.getDirection() direction :-)
It is always jumping and moving around the screen. Sorry.

EgonOlsen

The problem with all these rotation/position based solutions will be, that you have to compensate for the rotation of the camera. It might be easier to use a second instance of World. Add your sphere to another World instead in a way that it's located where you want it to, don't move the camera in that world at all and render it after rendering the normal world (maybe with an additional clear of the zbuffer in between). That should actually do the trick without any matrix magic involved.

Peter Dym


Peter Dym