# Disapearing Objects from the scene

I created a camera that floats around a target. When I test it object in the scene disappear and reappear when i move around the object.

Video: http://www.sharebigfile.com/file/191885/javaw-2007-07-11-21-15-09-93-avi.html

package entropy.input.camera;

import com.jme.math.FastMath;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;

public class ChaseCamera implements FocusedCamera {
Camera cam;
Node target;

float elevation = 0;
float rotation = 0;
float distance = 0;

public ChaseCamera(Camera cam, Node target){
this.cam = cam;
this.target = target;
}

public float getDistance(){
return distance;
}

public void setDistance(float distance){
this.distance = distance;
}

public void changeDistance(float delta){
distance += delta;
}

public float getElevation(){
return elevation;
}

public void setElevation(float elevationAngle){
this.elevation = elevationAngle;
}

public void changeElevation(float deltaAngle){
elevation += deltaAngle;
}

public float getRotation(){
return rotation;
}

public void setRotation(float rotationAngle){
this.rotation = rotationAngle;
}

public void changeRotation(float deltaAngle){
rotation += deltaAngle;
}

public void update(){
System.out.println("updating");
elevation = clamp(elevation,MAX_ROT,MIN_ROT);
distance = clamp(distance,MAX_DIST,MIN_DIST);

tempVa.set(0,0,-distance);

//Elevation above target
tempVb.x = tempVa.x;
tempVb.y = FastMath.cos(elevation)*tempVa.y - FastMath.sin(elevation)*tempVa.z;
tempVb.z = FastMath.sin(elevation)*tempVa.y + FastMath.cos(elevation)*tempVa.z;

tempVa.set(tempVb);

//Rotation around target
tempVb.x = FastMath.sin(rotation)*tempVa.z + FastMath.cos(rotation)*tempVa.x;
tempVb.y = tempVa.y;
tempVb.z = FastMath.cos(rotation)*tempVa.z - FastMath.sin(rotation)*tempVa.x;

tempVa.set(tempVb);

cam.setLocation(tempVa);
cam.setDirection(tempVb.negateLocal().normalize());
cam.update();
}

public static float clamp(float value, float max, float min){
if(value>max)
value = max;
if(value<min)
value = min;
return value;
}
}

Test code is a modification of TestObjectWalking
I chopped out the most boring parts, parts that were unchanged from TestObjectWalking.

...........................................
Node maggieNode = new Node("maggie");
maggieNode.setLocalTranslation(new Vector3f(100,terrain.getHeight(100, 100),100));
maggieNode.attachChild(maggie);

// Attach Children

pickNode = new Node("Pick");
pickNode.attachChild(maggieNode);
....................................

//camResults.setCheckDistance(true);

//cam.setLocation(new Vector3f(50, terrain.getHeight(50,50)+10, 50));
//cam.setDirection(new Vector3f(0.5f,0,0.5f));
//cam.setLeft(new Vector3f(0.5f,0,-0.5f));
//cam.update();

//oldCamLoc = new Vector3f(cam.getLocation());

//pickNode.lockBounds();
//pickNode.lockTransforms();

//OnBoardCamera obc = new OnBoardCamera(cam,maggieNode);
obc = new ChaseCamera(cam,maggieNode);
input = new KeyCameraHandler(obc,null);
//input = new MouseCameraHandler(obc,null);
}
.......................
// This is called every frame. Do changing of values here.
protected void simpleUpdate() {
obc.update();
//lock camera to objects
//camRay.getOrigin().set(cam.getLocation());
//camResults.clear();
//pickNode.calculatePick(camRay, camResults);
}
}

video didnt work for me ?

Just a quick guess (without really looking at it):

Are your bounding volumes setup right?

When something was disappearing in my game, I usually forgot to set or to update my BoundingBoxes…

i tried:

rootNode.updateWorldBound();
rootNode.updateModelBound();
rootNode.updateGeometricState(0, true);

none of them worked, is there something else I'm supposed to do?

rootNode.setModelBound(new BoundingBox());

rootNode.updateModelBound();

Otherwise, check that your camera setup (direction, up, left) and frustum values all make sense.  A poorly setup camera can affect the construction of the frustum planes.

renanse said:

rootNode.setModelBound(new BoundingBox());
rootNode.updateModelBound();

Didn't work

renanse said:

Otherwise, check that your camera setup (direction, up, left) and frustum values all make sense.  A poorly setup camera can affect the construction of the frustum planes.

I have to designs for the floating camera, the first doesn't have the disappearance problem. So i checked the up, left, frustrum between working and not working design and they are exactly the same.
The two designs are very different and can't do what the other can, thats why i need this second design to work.

Camera that makes things disappear:

Camera that doesn't make things disappear

The terrain is obvisouly different but the target object(maggie) is in the same position and the camera data is almost exactly the same.
Not sure what to do now.

Um, to me this does not look like disappearing objects.  It just looks like the terrain is positioned in such a was as to be cutting her in half…?

did you watch the clip?

these images only show the camera values.

Got the movie.  Really looks like a bounding issue to me.  Can you toggle boundings (B if you are using simple game) and show what that looks like?

Thanks!

http://www.sharebigfile.com/file/195666/Movie-0001-wmv.html

its obviously a bounding issue but I’m not sure where it is coming from.

If you noticed in the first capture the pupils, bow, eyes, and head all disappeared separately(they have separate bounding boxes),  the head being the last to disappear.

Ok, well that is very odd.  It looks like you have a good test for this though.  Can you send it to me to debug?

http://www.sharebigfile.com/file/195734/entropy-zip.html

my project has a lot of tests in it so i cut out all the stuff you didn’t need, please telling me if there is anything i forgot to keep in it

the controls are the arrow keys and the +/- keys for zoom

EDIT: Sorry about the hack job I did in putting the test together, I never thought anyone else would need to read it.

Just a vague guess, could it be that your camera's up vector is always (0,1,0), even though the camera is tilted down a bit? As far as I understand frustrum culling (without ever looking at the actual code involved), it might use the up vector to determine the frustrum orientation…

hevee said:

Just a vague guess, could it be that your camera's up vector is always (0,1,0), even though the camera is tilted down a bit? As far as I understand frustrum culling (without ever looking at the actual code involved), it might use the up vector to determine the frustrum orientation...

Yep, it is always up. Currently all I'm changing on the camera is the direction and location of the camera. Do i need to set the up and left too? I thought update camera would do the calculations for those, guess not.

Good point.  (Sorry, I got your code by email but have not had a chance to look at it yet.)  up/left/dir are not autoset by the camera (except in the case of lookAt)  Try passing in correct values for all three and seeing if that makes things work.

I'm working on setting the right vectors but it is hard because my geometrical think seems right and the camera looks like it is right but that doesn't actually mean that they are right.