Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (564) Games in Android Showcase (151) games submitted by our members Games in WIP (605) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Rotating a Vector3f by a Vector3f in LWJGL  (Read 2392 times) 0 Members and 1 Guest are viewing this topic.
CyanPrime
 « Posted 2012-06-14 02:39:25 »

Alright, So I got this code where I punch in these values:

 1  2 `    rot      :1.0416666   0.0   -0.0    pos      :-71.25   67.5   91.875`

And get these values back:

 1 `    rotPos   :-71.25   67.500015   91.874985`

Now I'm clearly trying to rotate a Vector3f by another Vector3f, but the following code isn't rotating anything. Can someone tell me what I'm doing wrong?

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 `    public Vector3f rotV3fByV3f(Vector3f npos, Vector3f nrot){              Vector3f pos = new Vector3f(0,0,0);               Vector3f rot = new Vector3f(0,0,0);               Matrix4f  matrix = new Matrix4f();               matrix.setIdentity();                              pos = new Vector3f(npos);                              matrix.m03 = pos.x;               matrix.m13 = pos.y;               matrix.m23 = pos.z;                              rot = new Vector3f(nrot);               Matrix4f.rotate((float) Math.toRadians(360), rot, matrix, matrix);                   return new Vector3f(matrix.m03, matrix.m13, matrix.m23);       }`
ra4king

JGO Kernel

Medals: 367
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #1 - Posted 2012-06-14 07:58:04 »

I'm trying to wrap my head around how you can even rotate a vector by another vector....how does that make any sense?

Now do you want to rotate your vector around another vector by a certain angle?

Roquen
 « Reply #2 - Posted 2012-06-14 08:14:03 »

I'm assuming one represents the axis of rotation...you additionally need an angle.  The code example doesn't make any sense.  You're shoving what I'm assuming to be the axis of rotation into a translation slot..assuming that's the convention you've chosen.
matheus23

JGO Kernel

Medals: 121
Projects: 3

You think about my Avatar right now!

 « Reply #3 - Posted 2012-06-14 13:36:59 »

Oh okey... seems like, you've been really tired at the time you wrote this... ?

First, you create the Vector3f's "pos" and "rot" 2 times. In lines 2 and 3, and in lines 7 and 13 again.

Also, that code seems to work just as it should.
But wtf???
You rotate the matrix by 360 ° ?!? Of course you get the same vector again
 1 `Matrix4f.rotate((float) Math.toRadians(360), rot, matrix, matrix);`

These guys above me are right, you can only rotate a vector by another vector and an angle (or just by another Quaternion).
So I'd suggest:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15 `public Vector3f rotV3fByV3f(Vector3f npos, Vector3f nrot, float rotation) {   Matrix4f matrix = new Matrix4f();   Vector3f pos = new Vector3f(npos);   matrix.m03 = pos.x;   matrix.m13 = pos.y;   matrix.m23 = pos.z;   Vector3f rot = new Vector3f(nrot);   Matrix4f.rotate((float) Math.toRadians(rotation), rot, matrix, matrix);   return new Vector3f(matrix.m03, matrix.m13, matrix.m23);}`

EDIT: Removed "matrix.setIdentity()". The matrix is already an identity matrix, if you create it

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Roquen
 « Reply #4 - Posted 2012-06-14 14:45:46 »

Still not a rotation matrix.  A quick glance at the API yields:

public Matrix4f rotate(float angle, Vector3f axis)
public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest)

Which I'd assume create rotation matrices from an axis and an angle.
CyanPrime
 « Reply #5 - Posted 2012-06-16 19:27:09 »

I was wondering what the correct way to rotate Matrix4fs by 3 axises is.

This is what I got so far:

 1  2  3  4  5 `Matrix4f x =new Matrix4f(mat_transform.rotate(rotationVector.x , new Vector3f(1,0,0)));              Matrix4f y =new Matrix4f(mat_transform.rotate(rotationVector.y , new Vector3f(0,1,0)));              Matrix4f z =new Matrix4f(mat_transform.rotate(rotationVector.z , new Vector3f(0,0,1)));                            mat_transform = Matrix4f.mul(Matrix4f.mul(x,y,null), z, null);`
Tim Spekler

« JGO Spiffy Duke »

Medals: 58
Projects: 2
Exp: 4 years

 « Reply #6 - Posted 2012-06-19 21:29:18 »

If you 're wondering how to correctly use rotation to move in a 3D world,then there is not just one way to rotate matrix in a 3D space. You always have to choose in which order you're going to apply your rotation (first x, then y and the z, or another way) and each order implies different results.
In conclusion, you have to choose the correct order that matches to your expectation.

If your talking about the implementation, here is what I do for a FPS:
 1  2  3  4 `Matrix4f camera = new Matrix4f();camera.translate(new Vector3f(X, Y, Z));camera.rotate(Yangle,new Vector3f(0,1,0));camera.rotate(Xangle,new Vector3f(1,0,0));`

Hope it helps
Pages: [1]
 ignore  |  Print

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

 wxwsk8er (51 views) 2015-03-20 15:39:46 Fairy Tailz (42 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (33 views) 2015-03-13 17:50:16 Olo (40 views) 2015-03-13 17:47:07 ClaasJG (30 views) 2015-03-10 11:36:42 ClaasJG (38 views) 2015-03-10 11:33:01 Pippogeek (45 views) 2015-03-05 14:36:23 Pippogeek (37 views) 2015-03-05 13:56:12
 LiquidNitrogen 23x BurntPizza 21x KevinWorkman 21x basil_ 21x theagentd 18x Riven 18x EgonOlsen 17x Roquen 14x princec 12x SHC 9x Varkas 9x Slyth2727 9x NegativeZero 9x teletubo 7x Ecumene 7x nsigma 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