Object not turning sideways with Camera

Started by Mohit, January 09, 2013, 08:43:26 PM

Previous topic - Next topic

Mohit

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]

EgonOlsen

I'm not sure, but instead of doing this


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


in onDrawFrame(), i suggest to do this


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.

Mohit

Thanks Egon for being there.

I followed your instructions. Works perfectly now. 8)

One more line in the onSurfaceChanged method was also needed.

gun.setRotationPivot(cam.getYAxis());

Thanks