Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  correct transforming  (Read 1554 times)
0 Members and 1 Guest are viewing this topic.
Offline bienator

Senior Duke




OutOfCoffeeException


« Posted 2003-03-04 12:59:42 »

Hi all!
I have some problems with moving objects in java3D.

I tryed this code:

...extends Transvorm3D

public Transformer(Vector3f pos,double heading, double pitch, double bank) {
     
     Transform3D t = new Transform3D();
     
     t.rotZ(bank);
     this.mul(t);
           
     t.rotX(pitch);
     this.mul(t);
     
     t.rotY(heading);
     this.mul(t);

     t.set(pos);
     this.mul(t);
}

the problem is that the object will not correctly moved, because it will rotated first z, then x and then y.

Is it possible to rotate it  x, y and z at the same time?
(without much math)

thanks,
bienator

Offline Breakfast

Senior Duke




for great justice!


« Reply #1 - Posted 2003-03-04 14:55:52 »

I'm not sure I quite understand the question- is there a difference between rotating something in x then y then z rather than a single simultaneous matrix operation? The object you are shifting will not be transformed until you apply the Transform3D to it, surely?
Offline bienator

Senior Duke




OutOfCoffeeException


« Reply #2 - Posted 2003-03-04 16:47:05 »

OK
I want that a object should be rotated with three values:
pitch bank and heading

The problem is, that after I rotate an object for example in the z axis(bank) it has an other position.
And THEN I rotate it in the x axis(pitch) it has an other position too, but an wrong one.  Because it will be rotated from his NEW position. This is mathematical correct but the object has not the pitch pitch and the bank bank.
This should not happen if I do this at the same time but how?
I hope you understand me now.

I am 16 and I have not very much experience with matrices, please tell me if I think wrong

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #3 - Posted 2003-03-04 18:02:51 »

The problem is that you can't do it all at the same time, I'm afraid.  When you apply a transformation (like a "roll") you change the coordinate system that is used as a reference from that point on.

What you need to do is to work out the order of transformations you need and apply them in order.  In the case of an aeroplane, for example, I think you want to pitch, yaw, then roll - I think this corresponds to pitch, heading, then bank in your code.


(I haven't played with matrices for a while - to my disgust - I'm afraid.  I *think* the above is true, but if it's wrong someone is sure to jump in and correct me!)

Hellomynameis Charlie Dobbie.
Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #4 - Posted 2003-03-04 18:26:47 »

Okay, I've just read what I've written and I think I'll clarify it a bit better. Wink

Given two matrices A and B, A multiplied by B is not necessarily equal to B multiplied by A (AB != BA).

You can apply all your transformations at the same time, but they must be gathered together in the specified order, so you want to create a matrix B as follows:

B = ApitchAheadingAbank

You can then apply matrix B to your object.  This will give the same effect as applying the transformations one after the other.

I don't know enough about the Java3D API but I'd guess from looking at your code that you shouldn't be applying the transform after setting each rotation - set all the rotations one by one and apply the lot at the end.

Hellomynameis Charlie Dobbie.
Offline bienator

Senior Duke




OutOfCoffeeException


« Reply #5 - Posted 2003-03-04 19:01:57 »

Thank you very much cfmdobbie Smiley Cheesy Grin
that is what I want to hear, I need just the right order of transformations.

bienator

Offline Thurisaz

Innocent Bystander




Java games rock!


« Reply #6 - Posted 2003-03-27 12:34:40 »

I have the exact same problem.

I am trying to program a spacecraft/airplane that moves around in java 3D, I cant get the rotations correct though..

I have tried to put the transforms together in all kinds of orders but it still wont work. Sad Sad

Are there no way to use a local set of coordinate axis (that will follow the airplanes rotation) or a matematical way to calculate how to rotate it correctly?
Offline Herkules

Senior Duke




Friendly fire isn't friendly!


« Reply #7 - Posted 2003-03-27 13:00:25 »

Working with eulers in a 6DOF environment isn't a good idea just because the order does matter. So you cannot roll a plane by just increasing a certain angle.

What I do is to define an spin vector in the local coordinate system of the aircraft where the vectors direction denotes the spin axis and its length the angle.

1  
2  
3  
spin.x = mController.getElevator() * mDesc.mKpitch;
spin.y = -mController.getRudder() * mDesc.mKyaw;
spin.z = -mController.getAileron() * mDesc.mKroll;



Later on, I scale this vector as I need it, make an AxisAngle out of it and multiply it to my transform.

1  
2  
3  
axisangle.set( spin, spin.length() * dt );
rotation.set( axisangle );
mRot.mul( rotation );


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline bienator

Senior Duke




OutOfCoffeeException


« Reply #8 - Posted 2003-04-01 10:55:27 »

How do you calculate "dt"?

Offline Herkules

Senior Duke




Friendly fire isn't friendly!


« Reply #9 - Posted 2003-04-01 11:08:48 »

Me? Oh, I always do things complicated.....

A class 'Ticker' gets called from an object of class 'Ticking' that uses an object implementing 'Clock'.

Ticker does this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
      /**
       * Ticking callback for the ticking object.
       */

      public void tick( long ticktime )
      {
            mTicks ++;
        
        mDeltaT = ticktime - mCurrentTickTime;
        mCurrentTickTime = ticktime;

        //
        // Tell all listeners.
        //
        int listenercount = mListeners.size();
        for ( int i = listenercount-1; i >= 0; i-- )
        {
            ((TickerListener)mListeners.get( i )).tick( this );
        }
      }


The caller retrieves the necessary millisecond from a 'Clock' that is implemented like that:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
public class HiResClock implements Clock
{
      private         long        mBaseMS = 0;
    
    /**
     * Creates a new instance of SystemClock.
     */

    public HiResClock()
    {
        adjust( 0 );
    }
 
    
    /**
     * Check wether hires timer is available on this installation.
     */

    public final static boolean isAvailable()
    {
        try
        {
            ClassLoader.getSystemClassLoader().loadClass( "com.sun.j3d.utils.timer.J3DTimer" );
                  return true;
        }
        catch ( ClassNotFoundException cnfe )
        {
            return false;
        }
    }
    
    /**
     * Adjust the clock to a certain value.
     * Calling <code>getCurrentTime()</code> immediately after <code>adjust()</code>
     * should return <code>refvalue</code>.
     */

    public void adjust(long refvalue)
    {        
        mBaseMS = getMS() - refvalue;
    }
    
    /**
     * The current time from the start in milliseconds.
     */

    public long getCurrentTime()
    {            
        return getMS() - mBaseMS;
    }
    
    
    /**
     * Internal time retrieval function.
     */

    private final long getMS()
    {
        return com.sun.j3d.utils.timer.J3DTimer.getValue() / 1000000;        
    }
    
}


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bienator

Senior Duke




OutOfCoffeeException


« Reply #10 - Posted 2003-04-01 11:18:56 »

cool  Smiley

Offline Herkules

Senior Duke




Friendly fire isn't friendly!


« Reply #11 - Posted 2003-04-01 11:21:20 »

I forgot, 'Ticking' is implemented by an Java3D Behavior that uses either WakeupOnElapsedFrames(0) or WakeupOnElapsedTime() for a 3D client.
For a server that needs to be ticked, I have a Thread-implementation right in place .... Smiley

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
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.

Longarmx (41 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (59 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!