rotating around different coordinates

ehlo…
i just started yesterday with Xith3d and i’m trying to figure out the update of the camera position.

i used tutorial code and some code from here to get it working…

i can rotate the camera, i can move the camera, but when i move the camera, i want to be able to rotate around the new point…and not the center of the scene…

i have a galaxy…full 3d and i need to implement free movement and rotation around the new point and rotation around selected objects (which are quite simila i think)
i just need to know how to tell him, which coordinates to use…
i tried:


translate is Transform3D
and objTranslate is TransformGroup
transXTmp, transYTmp, transZTmp are new coordinates

private void performTranslation() {
        translate.setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp));

        objTranslate.setTransform(translate);

       // performCameraChange();

    }

or

view.getTransform().setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp));

and many other combinations of whatever was available :slight_smile: but no success

id be happy, if anyone could tell me how to do that…or at least point me in the right direction…as i’m lost after many hours of struggle…

i’ve read IMHO all the camera topics here, but couldn’t fing the answer…

i even tried the lookAt method…but i can’t figure out what 3 vectors i have to put in…cause i need total freedom (the up vector is not always 0,1,0…and im not a mathematical genius :wink:

update:

i made some progress regarding this issue.

first i had this:

objTranslate.addChild(objRotate);
objRoot.addChild(objTranslate);

well…basicaly…it was rotating around the universe point (0,0,0)

then i got the idea to reverse the rotate and translate TransformGroups:

objRotate.addChild(objTranslate);
objRoot.addChild(objRotate);

and i got nearly exactly what i wanted, but it messed up the movement part…

i mean…i rotated aroun any object i wanted…but the mvement part was on the oiginal X0,Y0,Z0 axis … i mean…when i went straight…it went by the X axis…it did not count in the camera rotation…

i don’t know what to do…i stayed up all day and all night trying to figure this out…browsed the WHOLE forum… but stil nthing…

hey…it’s my 5th java day…never did java before and now i have a galaxy generator (5000+ stars inncuding planets) and a nearly working 3d representation ;))

your nearly at it!

I repeat what you want:
You have a Point3f p, where you’r camera currently is.
You have a Rotation (a Matrix3f) m, that specifies your rotation - if you haven’t got that Matrix simply call RotationTransform3D.getRotation();
And you have a Vector3f v that specifies the direction you want to move the camera relative to the camera’s local coordinate system.

Now you do this:


v = m.transform(v); // this transforms v into global coordinate system
p.add(v);
TranslationTransform3D.set(p);

Arne

v = m.transform(v); // this transforms v into global coordinate system

thanks for reply…but…maybe i’m stupid, but m.transform wants a Tuple3f and not a Vector3f and also Tuple3f is abstract, so i can;t initialize it :frowning:

i’m not native english, so i don’t know what a tuple is :slight_smile: and i’m lost here…as i think i know what u saying, but i don’t know how to apply it :frowning:

Vector3f extends Tuple3f,
This has the advantage, that you can everywhere, where a Tuple3f is required use a Vector3f, Point3f, Color3f…

well…i’m trying to figue that out…just in case you could take a look, here is a part of the code:


the endless render loop:

  while (true) {

            view.renderOnce();

            if (isRotationScheduled) {
                performRotation();
                isRotationScheduled = false;

            }
            if (isTranslationScheduled) {
                performTranslation();
                isTranslationScheduled = false;

            }

        }

the methods:

    private void mousePressed(MouseEvent e) {
        startDragX = e.getX();
        startDragY = e.getY();
    }

    public void mouseDragged(MouseEvent e) {
        switch (e.getModifiers()) {
            case MouseEvent.BUTTON1_MASK:
                leftDrag(e);
                break;
            case MouseEvent.BUTTON2_MASK:
                middleDrag(e);
                break;
            case MouseEvent.BUTTON3_MASK:
                rightDrag(e);
                break;
        }
    }

private void leftDrag(MouseEvent e) {
        rotXTmp = rotX + (e.getY() - startDragY) / 100f;
        rotYTmp = rotY + (e.getX() - startDragX) / 100f;

        isRotationScheduled = true;
    }

 
    private void middleDrag(MouseEvent e) {
        transZTmp = transZ + (e.getY() - startDragY) / 5f;

        isTranslationScheduled = true;
    }

    private void rightDrag(MouseEvent e) {
        transXTmp = transX + (e.getX() - startDragX) / 5f;
        transYTmp = transY - (e.getY() - startDragY) / 5f;

        isTranslationScheduled = true;
    }


    private void performRotation() {

        translate.set(new Vector3f(transXTmp, transYTmp, transZTmp));
        rotate.rotXYZ(rotXTmp, rotYTmp, 0);

        m = new Matrix3f();
        rotate.getRotation(m);
        v = new Vector3f(transXTmp, transYTmp, transZTmp);
        m.transform(v);

        translate.set(m);
        objTranslate.setTransform(translate);

    }


   private void performTranslation() {


        translate.setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp));
        objTranslate.setTransform(translate);


    }

    private void mouseReleased(MouseEvent e) {
        rotX = rotXTmp;
        rotY = rotYTmp;
        transX = transXTmp;
        transY = transYTmp;
        transZ = transZTmp;
        System.out.println(transX + " " + transY + " " + transZ);



    }


at this state…when i move…i move fine…when i rotate, the camera resets its position and rotates…
when i move again…it resets to the position i left when i was moving last time…

jsut put the code of the translation methon inside the rotation method likt this:

private void performRotation() {

    translate.set(new Vector3f(transXTmp, transYTmp, transZTmp));
    rotate.rotXYZ(rotXTmp, rotYTmp, 0);

    m = new Matrix3f();
    rotate.getRotation(m);
    v = new Vector3f(transXTmp, transYTmp, transZTmp);
    m.transform(v);

    translate.set(m);

    translate.setTranslation(new Vector3f(transXTmp, transYTmp, transZTmp));
    objTranslate.setTransform(translate);


}

unfortunately, it won’t work as expected.

the camera moves right, but rotation goes to point zero…movemen continues from last moved point…weird…

the thing is…

what i really want:

i want the rotation center point to always be on the galaxy plane (XY) …
i’ll try to draw it:




             ^ 4
            /
           /
      <-  * 1 ->
         /|
        / |
       /  | 2
------+---*------------- the XY plane
      3

1 - camera eye - arrows pointing in direction of movement
2 - camera - plane intersection
3 - rotation point/viewing point = what am i looking at

<3,4> zooming ... i want zooming/rotating to apply to the viewing vector



then i want to be able to swith (picking) to a star, ,that i could rotate around and zoom in/out (without moving) (there will be a KeyPressed for the switch to free and locked camera mode)

my math is not that good…i know about the lookAt() method…but i don’t know how to compute the right 3 vectors, when i have coordinates of the camera and the rotX, rotY (which i have from the code above)…i can compute the rotation point (camX, camY, 0) but i can’t compute the arrow up, i don’t know the equation and all my tries ended with “can not invert matrix” …

as i’m new to Xith3D and i don’t want to bother you with ideas and problems…but i feel i really need help in this :frowning:

thanks

NOTE: firste version of the graph was with an error…this one is good ;))

don’t bother about the up vector it’ll be fine as long the up vector doesn’t show directly to your target.
e.g. if you never look straight down or straight up up=(0|0|1) will be ok (assuming z is up, if y is up you’ll have to use up=(0|1|0))

tried it with lookAt() now…not working :frowning:

i’d hate to leave a project just because of me not understanding how the hell does the camera work :frowning:

another night without sleep? – been up for 37 hours now

NOTE:

rotation - camera movement around the same viewing point in space (which is on the XY plane)

movement - camera movement and the viewing point are moving at the same time, the same direction…another plane, that is paralell to XY plane

zoom - camera movement to and from the viewing point (whih is the same)

I’ll make another try:


Transform3D t = new Transform3D();
Matrix3f m = new Matrix3f();
Vector3f pos = new Vector3f();
Vector3f temp = new Vector3f();
Vector3f up = new Vector3f(0,0,1);
float zoom = 10;

public void setZoom(float zoom) {
  this.zoom = zoom;
}

public void move(Vector3f v) {
  m.transform(v);
  pos.add(v);
  updateView();
}

public void rotate(Matrix3f rot) {
  m.mul(rot);
  updateView();
}

public void updateView() {
  temp.x = zoom;
  temp.y = 0;
  temp.z = 0;
  m.transform(temp);
  temp.add(pos);
  t.lookAt(pos,temp,up);
}

//---------------------------Example for using the code---------------------------------
public void actionPerformed(KeyEvent e) {
  if(e.getKeyCode() == KeyEvent.VK_UP) move(new Vector3f(1,0,0));
  else if(e.getKeyCode() == KeyEvent.VK_DOWN) move(new Vector3f(-1,0,0));
  else if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
    Matrix3f rot = new Matrix3f();
    rot.rotZ(0.1);
    rotate(rot);
  }
  else if(e.getKeyCode() == KeyEvent.VK_LEFT) {
    Matrix3f rot = new Matrix3f();
    rot.rotZ(-0.1);
    rotate(rot);
  }
}

You can also set zoom by changing the field of view in View.

[quote]another night without sleep? – been up for 37 hours now
[/quote]
Try with some sleep - often sleep helps. Or how urgent is this project?

Arne

well…hello…

the good thing is, i managed to apply textures to the stars…the bad thing is, i still can’t figure out the camera :frowning:

and i found out, that until i figure out the camera completly, i won’t be able to do the star picking :frowning: which is what i’m trying now…so basically i’m f…ed :frowning:

i knew that doing this size game alone is nearly suicide…