Manipulating camera

umm… i really do not know where to post this… but I think the graphics section would do… I need help on manipulating camera… I'd like a camera that moves  over a circular orbit and that adjusts whenever you click and drag the mouse over the game screen… ahmmm… like your looking on a globe using a satellite… I think that's the best description of what im doing… for any replies thanks in advance xD

ummm, by the way…



here's my understanding of how the camera works…



in the function…



cam.setFrame(loc , left , up , dir);



where…



loc = location of the camera

left = left-axis of the camera

up = up-axis of the camera

dir = direction the camera is pointing



on my understanding… the only significant parameters that you should provide with Vector3fs are those of loc and dir… and the other can be given a value of "new Vector3f( 0.0f , 0.0f , 0.0f)"



then… I tried to make a scene wherein I'll be estimating the location of the camera… because I'm not really good at estimating without me actually seeing where I would put it… and the code goes like this…


import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.system.DisplaySystem;
import com.jme.bounding.*;
import com.jme.renderer.Camera;
import com.jme.math.Quaternion;;

public class testCamera extends SimpleGame
{
   private Box box;
   private Quaternion rotQuat = new Quaternion();
   private float angle =0;
   private Vector3f axis = new Vector3f(0,1,0);
   
   public static void main(String args[]){
      testCamera app = new testCamera();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.start();
   }
   
   protected void simpleInitGame(){
      box = new Box("box1", new Vector3f(0,0,0),10,10,10);
      box.setModelBound(new BoundingBox());
      box.updateModelBound();
      rootNode.attachChild(box);
      
      Box cameraBox = new Box("Camera Box",new Vector3f(-30,30,30),1,1,1);
      cameraBox.setModelBound(new BoundingBox());
      cameraBox.updateModelBound();
      rootNode.attachChild(cameraBox);

      rootNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();
   }
   
}



with this code... I'll have rendered two boxes... a big one with a location or should we say localTranslation of new Vector3f(0,0,0) and a small one having 1px in size located in Vector3f(-30,30,30)... the big one, named box, is what I would want to view and the small one, named cameraBox, is the location wherein I'd like my camera to view from... when you navigate through your screen to get a better view it would look like this....


and when you would navigate towards cameraBox, and view pointing towards the big box located in Vector3f(0,0,0).... it would look like this....



^ this is what I want my view to look like when I would set my camera....
although... when I try to edit my code with....

import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.system.DisplaySystem;
import com.jme.bounding.*;
import com.jme.renderer.Camera;
import com.jme.math.Quaternion;;

public class testCamera extends SimpleGame
{
   private Box box;
   private Camera cam;
   private Vector3f location, up , left, direction;
   
   public static void main(String args[]){
      testCamera app = new testCamera();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.start();
   }
   
   protected void simpleInitGame(){
      cam = display.getRenderer().createCamera(settings.getWidth(), settings.getHeight());
      location  = new Vector3f(-30,30,30);
      up = new Vector3f(0,0,0);
      left = new Vector3f(0,0,0);
      direction = new Vector3f(0,1,0);
      cam.setFrame(location, left, up, direction);
      display.getRenderer().setCamera(cam);
      box = new Box("box1", new Vector3f(0,0,0),10,10,10);
      box.setModelBound(new BoundingBox());
      box.updateModelBound();
      rootNode.attachChild(box);
      /*
       * Comment on cameraBox so it wouldn't be added to the rootNode
      Box cameraBox = new Box("Camera Box",new Vector3f(-30,30,30),1,1,1);
      cameraBox.setModelBound(new BoundingBox());
      cameraBox.updateModelBound();
      rootNode.attachChild(cameraBox);
      */
      
      rootNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();
   }
   
}



It would come blank... please help me on this...

Hey, to handle the camera like a node within the scene there is the class CameraNode.



Then you might use the SpatialTransformer class to setup a looping transformation, which let rotate the cameraNode around your globeNode.

Therefor have a look into the jmetest.renderer.TestSpatialTransformer.java and jmetest.scene.TestRotateAboutPoint.java



I guess these 2 are the ones you'll need to setup your rotation-animation.



Afterwards you'll have to check in which way you'd like to be able to adjust the camera, by clicking onto targets on the globe's surface.

Therefor check the TestSpatialLookAt.java for the camNode, and the TestPick.java.



With those 4 tests you should get a pretty good insight on how to achieve your goal…



…hope this helps.


thanks… i'll be sure to check those out…



do you know which java file could I locate the CameraNode so I could check that out too???

sure,

jmetest.renderer.TestCameraNode.java

bump

you should check the info provided :wink:



take this one as a start… and try to get an understanding of the code.


package com.pass.vb3d.quickwin.test;

import com.jme.animation.SpatialTransformer;
import com.jme.app.SimpleGame;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;

public class TestSateliteCam extends SimpleGame {

   /**
    * @param args
    */
   public static void main(String[] args) {
      new TestSateliteCam().start();

   }

   private CameraNode camNode;

   @Override
   protected void simpleInitGame() {

      Sphere sphere = new Sphere("sphere", Vector3f.ZERO, 20, 20, 4);
      rootNode.attachChild(sphere);

      Node cameraRotationCenter = new Node("rotationCenter");

      camNode = new CameraNode("camNode", cam);
      camNode.setLocalTranslation(0, 4, -30);

      SpatialTransformer camRotationTransformer = new SpatialTransformer(1);

      camRotationTransformer.setObject(cameraRotationCenter, 0, -1);

      camRotationTransformer.setRotation(0, 0, new Quaternion()
            .fromAngleAxis(0 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

      camRotationTransformer.setRotation(0, 2, new Quaternion()
            .fromAngleAxis(90 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

      camRotationTransformer.setRotation(0, 3, new Quaternion()
            .fromAngleAxis(180 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

      camRotationTransformer.setRotation(0, 4, new Quaternion()
            .fromAngleAxis(270 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

      camRotationTransformer.setRotation(0, 5, new Quaternion()
            .fromAngleAxis(360 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

      // Prepare my controller to start moving around
      camRotationTransformer.interpolateMissing();
      camRotationTransformer.setRepeatType(SpatialTransformer.RT_WRAP);
      cameraRotationCenter.addController(camRotationTransformer);

      cameraRotationCenter.attachChild(camNode);
      rootNode.attachChild(cameraRotationCenter);

   }

   @Override
   protected void simpleUpdate() {
      super.simpleUpdate();
      cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
   }

}

Thanks… I'll try this one first…

Hi I'm here again to ask some help… according to the examples you have given me such as the TestSatelliteCam and the others. I found the common function used in achieving camera rotations is the setLocalRotation… which I observed to only rotate on the x axis… I'm building CAD-like project in JME and I also need rotations on the y axis… could you please give me some sample code if it is possible to rotate the scene via the x-axis…

I'm sorry if I had to post on the general support section regarding this thread… its just because its like no one would like to comment on this… and since im a newbie… I was quite gotten taken away by the rush my coordinator was giving me… well, any way thnx for enlightening  me



and here it is…



bump


Quaternion q = new Quaternion().fromAngleNormalAxis(90 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0));
spatial.setLocalRotation(q);



90 degress around X axis rotation, there you go

after your replies, i think you should start a bit more “lowlevel” … if you have problems to understand essential math of vectors and Quaternions, axis and stuff, u might think about dig a bit more into this topics. So you will be able to understand code better.



there is one really good collection of tutorials and information under http://www.essentialmath.com/

no offense!

keep going

thnx… of course I won't be offended sir… I'm a noob after all… I'll be looking at this right away… and come back only when I need help on other topics or when I foud something difficult to understand… thnx… :smiley: