Author Topic: Object not turning sideways with Camera  (Read 1894 times)

Offline Mohit

  • byte
  • *
  • Posts: 4
    • View Profile
Object not turning sideways with Camera
« on: January 09, 2013, 08:43:26 pm »
Hi Everyone

First let me introduce myself. I am Mohit. I have been playing with JPCT for about 10 days now.
Thank you Egon for creating it. It makes things so much easier.

I was trying to make an FPS with gun demo.
The weapon moves up and down as well as forward and backward BUT does not turn left and right with the camera.

Also if I set orientation landscape in manifest. The overlays' position are not as expected. But if i dont use it in the manifest and rotate the device in landscape mode, the position of overlays is fine.

I have attached the source code. I will be very thankful if someone can help me.

Let me know if I can provide any other details.

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Object not turning sideways with Camera
« Reply #1 on: January 09, 2013, 08:58:21 pm »
I'm not sure, but instead of doing this

Code: [Select]
gun.rotateX(PI/2f);
gun.rotateAxis(gun.getYAxis(), PI);

in onDrawFrame(), i suggest to do this

Code: [Select]
Object3D gun=....;

gun.rotateX(PI/2f);
gun.rotateAxis(gun.getYAxis(), PI);
gun.rotateMesh();
gun.clearRotation();

gun.build();

right after loading the gun (from storage... ;) ). That might help already and if not, it will ease debugging. Also, remove the call to build() in onDrawFrame()...it hurts performance and serves no purpose there. About the overlays...i think that comes from the fact that you create the position variables based on the width and height in onCreate(). You should better use w and h in onSurfaceChanged(), because that will reflect that actual change in orientation.

Offline Mohit

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Object not turning sideways with Camera
« Reply #2 on: January 10, 2013, 11:18:16 am »
Thanks Egon for being there.

I followed your instructions. Works perfectly now. 8)

One more line in the onSurfaceChanged method was also needed.

Code: [Select]
gun.setRotationPivot(cam.getYAxis());
Thanks