Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (780) Games in Android Showcase (233) games submitted by our members Games in WIP (856) 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 3562 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: 518

 « 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

 hadezbladez (695 views) 2018-11-16 13:46:03 hadezbladez (342 views) 2018-11-16 13:41:33 hadezbladez (677 views) 2018-11-16 13:35:35 hadezbladez (167 views) 2018-11-16 13:32:03 EgonOlsen (2359 views) 2018-06-10 19:43:48 EgonOlsen (2468 views) 2018-06-10 19:43:44 EgonOlsen (1461 views) 2018-06-10 19:43:20 DesertCoockie (2126 views) 2018-05-13 18:23:11 nelsongames (1896 views) 2018-04-24 18:15:36 nelsongames (2566 views) 2018-04-24 18:14:32
 SkyAphid 19x orange451 13x gouessej 10x VaTTeRGeR 10x philfrei 7x Zemlaynin 7x dime26 6x ral0r2 5x CJC 5x KaiHH 4x cygnus 3x Pilvinen 3x Shatterhand 2x torbuntu 2x WinterGuardian 2x Abuse 1x
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 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