Camera rotation doesn't show scene correct

Hi all,



Got a question regarding my scene and the camera, since the scene doesn’t show as it should.





when i rotate the camera even by 0.5f, at a 194.5f ( of 360 ) it shows the scene shown below







when i rotate the camera to 195 of ( 360 ) it shows the scene shown below









below is my input handling code.

is there some kind of problem??



cause it might also be in the jmeCanvas



if there is a request for more code i’d be happy to post.

thanks in advance Wizard





/**
 *  @author Cor Attema
 */
package project.classes.inputhandling;

import project.Sim.MyImplementor;

import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;


public class InputHandling {

    private Camera _cam;
    private float _alpha_Angle = 177f;
    private MyImplementor _simulator;
    private Quaternion quat;
   
   
    /**
     * constructor InputHandling
     * @param cam
     * @param simulator
     */
    public InputHandling(Camera cam, MyImplementor simulator)
    {
       this._cam = cam;
       this._simulator = simulator;
       this.RotateAndSetCamera();
    }
      
   
    /**
     * what happens on key press // change camera location
     *                     // application exit
     */
    public void KeyPressed() {

      Vector3f v = _cam.getLocation();
      Vector3f dir = _cam.getDirection();
      
      //if ESCAPE is pressed, we exit
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
                  
         this._simulator.Finish();
      }
      
      
      // if UP or DOWN is pressed
      if (KeyInput.get().isKeyDown(KeyInput.KEY_UP) && !KeyInput.get().isShiftDown())
      {
         _cam.setLocation( new Vector3f( v.x + ( dir.x /1 ), v.y, v.z + ( dir.z /1 ) ) );      
      }
      else if (KeyInput.get().isKeyDown(KeyInput.KEY_DOWN) && !KeyInput.get().isShiftDown())
      {
         _cam.setLocation( new Vector3f( v.x - ( dir.x /1 ), v.y, v.z - ( dir.z /1 ) ) );
      }
      
      
      //if LEFT or RIGHT is pressed
      if (KeyInput.get().isKeyDown(KeyInput.KEY_LEFT) && !KeyInput.get().isShiftDown())
      {
         if ((_alpha_Angle + 0.5f == 360) )
            _alpha_Angle = 0.0f;
            
         _alpha_Angle += 0.5f;
         RotateAndSetCamera();
         
         System.out.println(_alpha_Angle);
      }
      else if (KeyInput.get().isKeyDown(KeyInput.KEY_RIGHT) && !KeyInput.get().isShiftDown())
      {
         if ( (_alpha_Angle - 0.5f <= 0.0f) )
            _alpha_Angle = 360f;
         
         _alpha_Angle -= 0.5f;
         RotateAndSetCamera();
                  
         System.out.println(_alpha_Angle);
      }
         
      
      //if SHIFT is pressed and LEFT or RIGHT is pressed
      if (KeyInput.get().isShiftDown() && KeyInput.get().isKeyDown(KeyInput.KEY_LEFT))
      {
         _cam.setLocation( new Vector3f(v.x - 0.1f, v.y, v.z) );         
      }
      else if (KeyInput.get().isShiftDown() && KeyInput.get().isKeyDown(KeyInput.KEY_RIGHT))
      {
         _cam.setLocation( new Vector3f(v.x + 0.1f, v.y, v.z) );
      }
      
      
      //if SHIFT is pressed and at the same time UP or DOWN is pressed
      if (KeyInput.get().isShiftDown() && KeyInput.get().isKeyDown(KeyInput.KEY_UP))
      {
         _cam.setLocation( new Vector3f(v.x, v.y + 0.1f, v.z) );
      }
      else if (KeyInput.get().isShiftDown() && KeyInput.get().isKeyDown(KeyInput.KEY_DOWN))
      {
         if (v.y + 0.1f > 0)
            _cam.setLocation( new Vector3f(v.x, v.y - 0.1f, v.z) );
      }
    }
   
   
    /**
     * rotate occurs on key press left.
     */
    private void RotateAndSetCamera()
    {       
       Quaternion quat = new Quaternion();
      
       quat.x = _cam.getLocation().x;
       quat.y = _cam.getLocation().y;
       quat.z = _cam.getLocation().z;
      
       //rotate about the Y-Axis by approximately 1 pi
       Vector3f axis = Vector3f.UNIT_Y; // this equals (0, 1, 0) and does not require to create a new object
       float angle = _alpha_Angle * FastMath.DEG_TO_RAD;
      
       quat.fromAngleAxis(angle, axis);
   
       _cam.setAxes(quat);
      
       this.quat = quat;
    }


    /**
     * function getQuaternion gets the current rotation quaternion
     * @return Quaternion
     */
    public Quaternion GetQuaternion()
    {
      if (this.quat == null)
      {
         return new Quaternion(0,0,0,0);
      }
      else {
         
         return this.quat;
      }
    }
}


Does the scene vanish suddenly? Maybe your node/mesh has no boundingvolume and thus gets culled too soon.



did you do a:

node.setModelBound(new BoundingBox());

node.updateModelBound();

Core-Dump said:

Does the scene vanish suddenly? Maybe your node/mesh has no boundingvolume and thus gets culled too soon.

did you do a:
node.setModelBound(new BoundingBox());
node.updateModelBound();


Hey Core,

As far as i know i didn't apply the bounding box,

I'll look in the code and will post if it works.

Thanks :)

Worked like a charm :slight_smile:



Thanks :slight_smile:




I just had the same problem, thanks Core.



Just to clarify, I had loaded a Blender model, built some Quads on the fly, and had them both in the world. With only my Quads added to the scenegraph (within their own parent Node), all was good. But as soon as I added the loaded model to the scenegraph, this started happening – everything would be visible until I looked away from the loaded model, at which point the Quads vanished. The problem was that the parent Nodes of the Quads had to have setModelBound() called on them, since I assume that Nodes do not have bounding boxes by default, as they are not geometries.



That still doesn't explain why I could see all my Quads before I added the loaded model to the scene, though.  :?

OK, silly me, just to clarify this for other newbies:



You need to (as Core-Dump says) call setModelBound() and then updateModelBound() on everything – your rootNode included.



I assumed that using a DebugGameState took care of this on the root node for me, but I was wrong. You need to do it manually.