Author Topic: Fixed object in front of camera  (Read 4063 times)

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Fixed object in front of camera
« on: November 21, 2011, 05:00:52 pm »
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?
« Last Edit: November 21, 2011, 05:12:25 pm by Peter Dym »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Fixed object in front of camera
« Reply #1 on: November 21, 2011, 05:59:32 pm »
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.

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Fixed object in front of camera
« Reply #2 on: November 21, 2011, 06:53:15 pm »
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.
« Last Edit: November 21, 2011, 06:56:06 pm by Peter Dym »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Fixed object in front of camera
« Reply #3 on: November 22, 2011, 06:52:16 am »
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.

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Fixed object in front of camera
« Reply #4 on: November 22, 2011, 09:07:02 am »
Thank you very much.

Offline Peter Dym

  • byte
  • *
  • Posts: 24
    • View Profile
Re: Fixed object in front of camera
« Reply #5 on: November 22, 2011, 02:59:19 pm »
And works with new world perfectly.