moving Camera

Hello everybody,

i’m a new user of Xith 3D and i’m starting to discover step by step the API.

I have a question : If i want to move the view object, must i use matrix3D, vector3F operation to do the right transformation or is it better to do Transformation using appropriate Transform3D and view.setTransform() ?

Hi adenthar!

I do like this:


        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(xPosition, yPosition, zPosition));
        view.setTransform3D(transform);

But there could be a better solution :wink:

if you want to rotate your view use this:


        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(xPosition, yPosition, zPosition));
        
        Transform3D xRotation = new Transform3D();
        xRotation.rotX((float)Math.toRadians(xAngle));

        Transform3D yRotation = new Transform3D();
        xRotation.rotY((float)Math.toRadians(yAngle));

        yRotation.mul(xRotation);
        transform.mul(yRotation);
        
        view.setTransform3D(transform);

good luck 8)

Thanks a lot DonCrudelis :slight_smile: !

It works indeed fine 8) !

[quote]Hi adenthar!

I do like this:


        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(xPosition, yPosition, zPosition));
        view.setTransform3D(transform);

somehow this does not work for me :slight_smile:

my initial setting for the view:


        view.getTransform().lookAt(
                new Vector3f(0, 0, 0),
                new Vector3f( 0, 0, 10),
                new Vector3f( 0, 1, 0)
        );

i can see my objects, and the current translation of the view is 0, 0, 0 (surprise). but when i do this:


        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(0, 0, 1));
        view.setTransform(transform);

i can see nothing. what did i do wrong?

thanks in advance

Hello verence !

you forgot to say where is the object you want to see in space coords ?
if it’s near your view it can disapear with a translation because of the frontClipDistance of your view (i.e. distance where the object is ignored for rendering)

check this :


view.setFrontClipDistance(0.1f);
view.setBackClipDistance(100f);

Hope this will help.

damn, it just won’t work :slight_smile:

ok, some code:

object creation (just a cube for simplicity):


        Geometry g = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
        Shape3D shape = new Shape3D(g);
        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(0, 0, 4.0f));
        TransformGroup transformGroup = new TransformGroup(transform);
        transformGroup.addChild(shape);
        scene.addChild(transformGroup);
        
        view.getTransform().lookAt(
                new Vector3f(0, 0, 0),
                new Vector3f(0, 0, 10f),
                new Vector3f(0, 1, 0)
        );

        view.setFrontClipDistance(0.1f);
        view.setBackClipDistance(100f);

so the cube is 4 units away from the view which is at the origin.

but when this:


        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3f(0, 0, -1.0f));
        view.setTransform(transform);

gets executed (via keylistener), the cube vanishes. the view is now one unit farther away from the cube, so it should still be visible (it doesn’t matter to what point the view is translated, i tried many things). is it possible that the information which way is up is somehow lost (last param from lookat())? or did i forget something?

Hi verence!

test to change your look-at to this:


view.getTransform().lookAt( 
      new Vector3f(0, 0, 0), 
      new Vector3f(0, 0, -10f), 
      new Vector3f(0, 1, 0) 
);

i think that would solve the problem :slight_smile:

sorry :), now i see nothing even in the first place. imho it has no effect on the camera movement, since lookat() is a method of the view’s current transformation, which is getting overwritten by view.setTransform() during the movement.

so i checked the rotation matrices before and after the movement and (surprise again) the view’s orientation is different.

so i just store the rotation matrix of the view everytime it rotates and do a Tranform3D.mul() everytime the view translates. it works. but now that i read that, it sounds quite obvious… hm, even einstein said that simply talking about can solve a problem :wink:

btw, does xith provide methods for “local” translations ie translations relative to the object’s coordinate system (meaning that (0, 0, 1f) always moves you forward regardless how the cameras rotation is)? in plain opengl i used some simple trigs for this, but then, this was c.

ok, thanks.