Author Topic: Keep the camera view  (Read 2287 times)

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Keep the camera view
« on: November 07, 2013, 05:55:40 pm »
In my project I use a a camera on a cube. When the cube is clicked it is scaled up until one surface fills all the camera view. When clicked again it zooms back. But now the cube looks smaller so the camera seems to have changed.

I guess it has something to do with camera collision but did't find how to fix it. I put the position and fov of the camera in a textfield but it had not changed.

My camera definition looks like this.
Code: [Select]
cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 22);

cam.lookAt(cube.getTransformedCenter());
        // tried this to fix it but it didn't
cam.setEllipsoidMode(Camera.ELLIPSOID_ALIGNED);


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Keep the camera view
« Reply #1 on: November 07, 2013, 08:52:04 pm »
Collision detection is triggered only if your code uses one of the methods to do it. There's no magic that moves the camera without you doing it explicitly in your code. In your case, i would assume that the final scale simply doesn't match the scale at the beginning. You can check this by calling getScale() on the Object3D in question.

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Keep the camera view
« Reply #2 on: November 07, 2013, 11:18:54 pm »
I checked it with getScale but the displayed object looks 6 times smaller than it was before is the same when it was scaled at 6. Is there something else that scales the view?

I took the HelloWorld example and added (bigger) quads by getPlane to each side of the cube (rotate them and use addChild)  then saved the scale by getScale and it was 1. At click I scaled it up to 20 scale, rotate the cube to the quad direction with matrix.interpolate and after another click scaled it back to 6 which is displayed the same size as it was before (that was scale 1. If I scale to that it is a more tiny cube).

Do I have to wait a frame until the object is updated or something? Is there something to care about when using the interpolate function?
« Last Edit: November 07, 2013, 11:37:47 pm by FredAxis »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Keep the camera view
« Reply #3 on: November 08, 2013, 07:37:13 am »
I'm not sure. Maybe the interpolation somehow intermingles with the scale (which is part of the matrix). Try to store the current scale, set it to one, then do the interpolation, then set the scale back to what it was. Also make sure to use setScale(), not scale() (which is relative).

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Keep the camera view
« Reply #4 on: November 08, 2013, 11:04:43 am »
You were right. Saving the scale and putting it to one before interpolate did work. Scale 1 gives me the size that it was before. Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Keep the camera view
« Reply #5 on: November 08, 2013, 01:33:25 pm »
...still strange... ???

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Keep the camera view
« Reply #6 on: November 08, 2013, 05:48:32 pm »
Yes it is. When I remove the setScale (1f) the scaling gets a bit confuzing.


Code: [Select]

float sc = cube.getScale();

// fix scaling
cube.setScale(1f);

Matrix rotMat = cube.getRotationMatrix();

Matrix rotToMat = new Matrix();

// degree to radian
rotToMat.rotateX(rotAim[0] * rad);
rotToMat.rotateY(rotAim[1] * rad);

// factor calculated from the click time
float f = Math.min(1,(float) (time (startAiming)/450) );
rotMat.interpolate(rotMat, rotToMat,f );

cube.setRotationMatrix(rotMat);

cube.setScale( (sc*11 + 4f) /12   );

« Last Edit: November 08, 2013, 06:12:59 pm by FredAxis »