Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (603) Games in Android Showcase (171) games submitted by our members Games in WIP (652) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Quat4f and rotation around local axis  (Read 2083 times) 0 Members and 1 Guest are viewing this topic.
ernest210

Senior Newbie

 « Posted 2012-03-06 18:59:50 »

I assume there is a better way to do what I want to do.
I haven't problem with rotation cube around axis unfortunately global axis.
When I want to make the rotation around local axis I just remember central point of my cube then move cube to position x=0, y=0, z=0 and I start rotation.
After rotation I move cube back to saved position.
Is there any way to do it without moving cobe?
This is my code responsible for rotation.
 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 `private static float angle = 4;   private Quat4f roll = new Quat4f();   private Quat4f quantBase = new Quat4f();   private AxisAngle4f angle4f = new AxisAngle4f();   private void update(boolean rotX, boolean rotY, boolean rotZ){      if(rotX){         angle4f.set(new Vector3f(1, 0, 0), angle * (float) (Math.PI / 180));      } if(rotY) {         angle4f.set(new Vector3f(0, 1, 0), angle * (float) (Math.PI / 180));      } if(rotZ) {         angle4f.set(new Vector3f(0, 0, 1), angle * (float) (Math.PI / 180));      }      roll.set(angle4f);            for(int i = 0;i

For clarity, this is how I understand the local and global axis.

Roquen
 « Reply #1 - Posted 2012-03-06 19:59:12 »

If you're going to transform more than a couple of points, you want to convert to a matrix.  see here: http://www.java-gaming.org/topics/skeletal-animation/25483/view.html
ernest210

Senior Newbie

 « Reply #2 - Posted 2012-03-15 19:41:26 »

I did it in this way
When i press key to rotate my cube I call this method which only remember central point cube.
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 `float localX = 0;float localY = 0;float localZ = 0;private void setPosition(){   float lX = 0;   float lY = 0;   float lZ = 0;   for(int i = 0;i

and then start the rotation
 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  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80 `private Vector4f vBase = new Vector4f();private Vector4f angle = new Vector4f();private void update(boolean rotX, boolean rotY, boolean rotZ){   if (rotX) {      angle = rotationX(angle, DEGTORAD);   }   if (rotY) {      angle = rotationY(angle, DEGTORAD);   }   if (rotZ) {      angle = rotationZ(angle, DEGTORAD);   }      for(int i = 0;i

All this works quite well.
But now I want to something more I want to change size but not all cube only width or height or thickness and I want to do this
on rotated cube.
I know I must to do something like this
Px' = S1 * Px
but it is not enough beacause from this

I'm geting this

Scaling works only on not rotated cube. I assume that I need to add a multiplication by the angle but I am not store information about angle.
Can you give me some advice?
Stranger

Senior Devvie

Medals: 9
Exp: 9 years

I'm going slightly mad. It finally happened.

 « Reply #3 - Posted 2012-03-16 18:24:39 »

Try to apply this:
 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 `    public static void mul(Vector4f q, Vector3f vCoord, Vector3f scale, Vector3f result) {        Matrix3f m1 = new Matrix3f();        setFromQuat(q.getX(), q.getY(), q.getZ(), q.getW(), m1);        Matrix3f tmp = new Matrix3f();        tmp.setIdentity();        tmp.m00(scale.getX());        tmp.m11(scale.getY());        tmp.m22(scale.getZ());        m1.mul(tmp);        transform(m1, vCoord, result);    }    private static void setFromQuat(float a, float b, float c, float d, Matrix3f m) {        final float n = a * a + b * b + c * c + d * d;        final float s = (n > 0.0f) ? (2.0f / n) : 0.0f;        final float xs = a * s, ys = b * s, zs = c * s;        final float wx = d * xs, wy = d * ys, wz = d * zs;        final float xx = a * xs, xy = a * ys, xz = a * zs;        final float yy = b * ys, yz = b * zs, zz = c * zs;        m.m00(1.0f - (yy + zz));        m.m01(xy - wz);        m.m02(xz + wy);        m.m10(xy + wz);        m.m11(1.0f - (xx + zz));        m.m12(yz - wx);        m.m20(xz - wy);        m.m21(yz + wx);        m.m22(1.0f - (xx + yy));    }    private static void transform(Matrix3f m, Vector3f t3f, Vector3f result) {        result.set(m.m00() * t3f.getX() + m.m01() * t3f.getY() + m.m02() * t3f.getZ(),                m.m10() * t3f.getX() + m.m11() * t3f.getY() + m.m12() * t3f.getZ(),                m.m20() * t3f.getX() + m.m21() * t3f.getY() + m.m22() * t3f.getZ()        );    }`

It's a draft solution. Unfortunately, I can't test it now, so hopefully it will work with a little changes.

Anton
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (21 views) 2015-08-01 03:58:20 Jesse (19 views) 2015-07-29 04:35:27 Riven (39 views) 2015-07-27 16:38:00 Riven (21 views) 2015-07-27 15:35:20 Riven (24 views) 2015-07-27 12:26:13 Riven (14 views) 2015-07-27 12:23:39 BurntPizza (35 views) 2015-07-25 00:14:37 BurntPizza (46 views) 2015-07-24 22:06:39 BurntPizza (28 views) 2015-07-24 06:06:53 NoxInc (36 views) 2015-07-22 22:16:53
 theagentd 51x wessles 45x basil_ 35x KaiHH 26x orangepascal 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x CelestialCreator 11x princec 11x klaus 11x Jesse 10x pquiring 9x Zaneris 9x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How 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:21
 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