Keep the camera view

Started by FredAxis, November 07, 2013, 05:55:40 PM

Previous topic - Next topic

FredAxis

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.

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);


EgonOlsen

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.

FredAxis

#2
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?

EgonOlsen

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).

FredAxis

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.

EgonOlsen


FredAxis

#6
Yes it is. When I remove the setScale (1f) the scaling gets a bit confuzing.




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   );