Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) 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 3221 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

JGO Kernel

Medals: 517

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

 ivj94 (583 views) 2018-03-24 14:47:39 ivj94 (48 views) 2018-03-24 14:46:31 ivj94 (374 views) 2018-03-24 14:43:53 Solater (62 views) 2018-03-17 05:04:08 nelsongames (109 views) 2018-03-05 17:56:34 Gornova (151 views) 2018-03-02 22:15:33 buddyBro (693 views) 2018-02-28 16:59:18 buddyBro (92 views) 2018-02-28 16:45:17 xxMrPHDxx (493 views) 2017-12-31 17:17:51 xxMrPHDxx (733 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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