Camera Movements (34 posts)

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 2 weeks ago:

    I implemented hotkeys to control my camera like A,S,D,W, etc

    I need to implement a button that triggers the camera moving AROUND a certain point like the following:

    http://i.imgur.com/S7zBh.png

    I want the camera to rotate around a given point (or axis) in a circular motion. How do I go to implement that?

    thanks!!!!!!!!!

  • Profile picture of normen normen1290p said 3 months, 2 weeks ago:

    http://jmonkeyengine.org/wiki/doku.php/jme3:math_for_dummies

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    OK so I’ve done the math for dummies and got a better understand of quaternions and how things work. However, I still don’t know whats the approach to take on rotating around the Z-Axis from the camera.

    - how can I get the center of the scene I am looking at as I want to rotate around the center of the map or whatever scene I am seeing.

    - the harder questions is how do I do it?

    could it be something as simple as adding a quat or vect to the cam like:

    cam.setLocation(cam.getLocation().add(x, y, z));
    cam.setRotation(quat);

    thanks

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    No, you simply rotate a vector with length=radius to get the locations and then you use lookAt to determine the direction.

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    not sure I got you, can you provide an example?

     Quaternion qRot = cam.getRotation();
                        Quaternion rot = new Quaternion();
                        rot.fromAngleNormalAxis(5, Vector3f.UNIT_Z); // something like this??? that flips it over to the other side of the map
                        cam.setRotation(rot);

    thanks

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    *sigh*.. a Vector

    Vector3f camPos = new Vector3f(0,0,1);
    Quaternion camRot = new Quaternion();
    Quaternion tempQuat = new Quaternion();
    simpleupdate(tpf){
    //rotate the vector
    tempQuat.fromAngles(0,tpf,0).multLocal(camPos);
    camRot.lookAt(center.subtract(camPos));
    cam.setLocation(camPos);
    cam.setRotation(camRot);
    }
  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    it doesn’t work :S I am sorry I’m still new at this.

    is center a Vector3f(0,0,0) ??

    I used camRot.lookAt(center.subtract(camPos)); but need to add another Vector3f to it as lookAt takes two vectors anyways my code is:

     else if (name.equals("moveAroundPositive") && keyPressed) {
    
                        System.out.println("Rotating camera around Z axis Positively");
    
                        // position must be on a circle around the Z axis
                        // Vector with radius length = 10
                        Vector3f camPos = new Vector3f(0,0,10);
                        Vector3f center = new Vector3f (0,0,0);
    
                        Quaternion camRot = new Quaternion();
                        Quaternion tempQuat = new Quaternion();
    
                        // create a quaternion based on the angles passed
                        // and multiplied by camPos
                        tempQuat.fromAngles(0,tpf,0).multLocal(camPos);
                        //tempQuat.fromAngles(0,rota,0).multLocal(camPos);
    
                        camRot.lookAt(center.subtract(camPos), camPos);
                        //camRot.lookAt(new Vector3f(0,0,0), new Vector3f(0,1,0));
                        //rota +=1;
    
                        cam.setLocation(camPos);
                        cam.setRotation(camRot);
                    }
    

    again, i’m sorry but although I have some expertise in java, I never played with graphics before, thanks for your help

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    Like said in the javadoc, its the up-vector, so Vector3f.UNIT_Y or new Vector(0,1,0); Also how am I supposed to know where the center in your image is?

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    well thats what I used (I had it there uncommented) and my center is (0,0,0) however it does go BELOW the object as if I am rotating around the x or Y axes.

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    ..the x-axis is that whats “right” with the default cam view, y is up and z is towards you..

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    as if I am rotating around the x or Y axes

    in case you misunderstood me.

    In other words, say the center is (0,0,0) and my object is at the center also, I want to rotate my camera AROUND it.

     if (name.equals("moveAroundPositive") && keyPressed) {
    Vector3f center = new Vector3f (0,0,0);
    Quaternion camRot = new Quaternion();
    Quaternion tempQuat = new Quaternion();
    tempQuat.fromAngles(0,rota,0).multLocal(camPos); //rota = 1 initially
    camRot.lookAt(new Vector3f(0,0,0), new Vector3f(Vector3f.UNIT_Y));
    rota +=1;
    cam.setLocation(camPos);
    cam.setRotation(camRot);
    }
    

    This won’t work as intended – it will rotate around the object but not even consistently.

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    why you do that “rota” shit ? you don’t even consider the framerate.. you cannot just add 1 every frame and then expect to run smoothly. Also the camPos vector obviously has to be kept so you can keep rotating it, so a field in the class. Also to make the center work properly you should add it to the

    if (name.equals("moveAroundPositive") && keyPressed) {
    Vector3f center = new Vector3f (0,0,0);
    Quaternion camRot = new Quaternion();
    Quaternion tempQuat = new Quaternion();
    tempQuat.fromAngles(0,tpf,0).multLocal(camPos);
    camRot.lookAt(center.subtract(camPos), new Vector3f(Vector3f.UNIT_Y));
    cam.setLocation(center.add(camPos));
    cam.setRotation(camRot);
    }

    I think I only misunderstood you when I thought you said you the read math for dummies doc. Try to see what I am doing here, I keep rotating a vector bit by bit each frame so that I get a circle in the end. Each frame the tip of the vector is where the cam should be.

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    Lol, do you still have the flyCam enabled? xD

  • Profile picture of normen normen1290p said 3 months, 1 week ago:

    Also, its still “center.subtract(camPos)” for the lookAt (corrected above).. Why do you keep changing my code? You are the one making the mistakes..

  • Profile picture of nightwolf911 nightwolf9114p said 3 months, 1 week ago:

    flycam is off

    and I tried camRot.lookAt(center.subtract(camPos), new Vector3f(Vector3f.UNIT_Y));

    what will happen is that it will place the camera in a 2D view with a camPos distance :S