Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (775) Games in Android Showcase (230) 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
 Rotating a Vector3f by a Vector3f in LWJGL  (Read 6032 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: 508
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

JGO Kernel

Medals: 518

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

JGO Kernel

Medals: 518

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

 hadezbladez (42 views) 2018-11-16 13:46:03 hadezbladez (44 views) 2018-11-16 13:41:33 hadezbladez (25 views) 2018-11-16 13:35:35 hadezbladez (19 views) 2018-11-16 13:32:03 EgonOlsen (1894 views) 2018-06-10 19:43:48 EgonOlsen (1930 views) 2018-06-10 19:43:44 EgonOlsen (1285 views) 2018-06-10 19:43:20 DesertCoockie (1716 views) 2018-05-13 18:23:11 nelsongames (1404 views) 2018-04-24 18:15:36 nelsongames (2036 views) 2018-04-24 18:14:32
 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