Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (622) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 correct transforming  (Read 1677 times) 0 Members and 1 Guest are viewing this topic.
bienator

Senior Devvie

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);

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

Breakfast

Senior Devvie

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?
bienator

Senior Devvie

OutOfCoffeeException

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

OK
I want that a object should be rotated with three values:

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

cfmdobbie

Senior Devvie

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.
cfmdobbie

Senior Devvie

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.

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:

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.
bienator

Senior Devvie

OutOfCoffeeException

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

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

bienator

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.

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?
Herkules

Senior Devvie

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
bienator

Senior Devvie

OutOfCoffeeException

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

How do you calculate "dt"?

Herkules

Senior Devvie

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 getCurrentTime() immediately after adjust()     * should return refvalue.     */    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
bienator

Senior Devvie

OutOfCoffeeException

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

cool

Herkules

Senior Devvie

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 ....

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.

 BurntPizza (26 views) 2015-04-23 03:42:11 theagentd (29 views) 2015-04-22 16:23:07 Riven (44 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (59 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 30x BurntPizza 16x wessles 15x 65K 11x Rayvolution 11x kingroka123 11x alwex 11x KevinWorkman 9x kevglass 8x phu004 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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