Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  moving Camera  (Read 1860 times)
0 Members and 1 Guest are viewing this topic.
Offline adenthar

Senior Newbie




Java games rock!


« Posted 2004-06-01 17:08:33 »

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() ?
Offline DonCrudelis

Junior Member





« Reply #1 - Posted 2004-06-01 17:55:49 »

Hi adenthar!

I do like this:

1  
2  
3  
        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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
        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  Cool
Offline adenthar

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-06-01 18:18:13 »

Thanks a lot DonCrudelis  Smiley !

It works indeed fine  Cool !
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline verence

Senior Newbie




let there be rok.


« Reply #3 - Posted 2004-06-02 14:58:02 »

Quote
Hi adenthar!

I do like this:

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


somehow this does not work for me  Smiley

my initial setting for the view:

1  
2  
3  
4  
5  
        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:

1  
2  
3  
        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
Offline adenthar

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-06-02 18:25:50 »

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 :

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


Hope this will help.
Offline verence

Senior Newbie




let there be rok.


« Reply #5 - Posted 2004-06-02 19:19:28 »

damn, it just won't work  Smiley

ok, some code:

object creation (just a cube for simplicity):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
        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:

1  
2  
3  
        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?
Offline DonCrudelis

Junior Member





« Reply #6 - Posted 2004-06-02 20:15:37 »

Hi verence!

test to change your look-at to this:

1  
2  
3  
4  
5  
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  Smiley
Offline verence

Senior Newbie




let there be rok.


« Reply #7 - Posted 2004-06-02 21:03:16 »

sorry  Smiley, 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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!