Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Rotate Vector3

Author
Message
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 03:55 Edited at: 22nd Sep 2010 00:53
Edit: Sven B posted a function using DBP commands:


Edit:
This function is based on a function lib I found for matrixes. I made a working function first and now I think I might try making it work with DBP matrixes.

New Snippet:


End Edit

I managed to finish my RotateVector3 function, but I can't figure if I did everything correctly. Please check my algorithm and make sure I did everything correctly. I made a few assumptions on multipling a vector3 to a matrix4.

Old Snippet:


Let me know what you think.

DigitalFury
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 14th Sep 2010 06:36 Edited at: 14th Sep 2010 06:58
: separates two commands on the same line, not join together one command on two different lines
Also, I didn't actually know "set matrix4" existed o.O
I'll check this code. BRB.

[edit]
all your math looks correct
[edit2]
actually... not so sure... I'm pretty sure you have a right handed system there, while DBPro uses directx (which uses a left handed coordinate system).

Also, It should be noted that the command "multiply matrix" is retarded.
multiply matrix4 C, A, B
actually means
C=B*A

which is horribly retarded 'cuz matrices aren't commutative!!!

Also also ()... I *think* that multiplying an euler rotation matrix (lets say angles a,b,c) by another euler rotation matrix (angles x,y,z) does NOT have the same rotation as a matrix angles (a+x,b+y,c+z). So... In my opinion... that makes iteratively multiplying vectors by an euler rotation matrix pretty pointless. Not so pointless is rotation about an arbitrary axis. You could read up on quaternions or matrices to learn about this, OR you could just use DBPro's commands. Something like this:


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Sep 2010 12:43
Quote: "I *think* that multiplying an euler rotation matrix (lets say angles a,b,c) by another euler rotation matrix (angles x,y,z) does NOT have the same rotation as a matrix angles (a+x,b+y,c+z)."


Hi there!

When multiplying another rotation matrix, the angles can only be added if the axis is the same as the previous one. Just throwing that in there that you're right on your *thinking* .

DigitalFury,

If you're unsure about your stuff, you can compare with the commands:


I also advise you to use transform vector4 instead of filling a matrix4 with the vector components. It leads to a deal of calculations that aren't necessary...

Cheers!
Sven B

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 19:37
I really wanted to get my function working with native DBP matrixes. Anyways, I finally got a working function. I didn't have any way of testing it until I finished working on a small demo. If anyone can figure out how to get it working with matrixes I might give it a go. First time working with matrixes seemed to turned out ok.

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 14th Sep 2010 20:05 Edited at: 14th Sep 2010 20:12
I played around with matrixes again and I still can't get it to work.



Edit:
Took the rotation matrix from the working example and it seemed to work. I think my math might be off somewhere in the rotation matrix. It almost makes matrixes un-necessary.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Sep 2010 04:12
I think you skipped over what I said. What you have is NOT a left-handed matrix. I haven't worked with right-handed matrix, but in a left handed coordinate system:
z*y*x (where each matrix is a rotation around its corresponding axis)
=

Very different from what you had. You should be doing:
Z*Y*X*ColumnVector

The commands sphenB posted build a matrix that rotates a vector around an axis, so build those three matrices, multiply them together (multiply matrix4 result,a,b is saying result=b*a), and then transform your vector.

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 15th Sep 2010 04:52
@ Neuro Fuzzy - Was trying to figure what u mean.
Quote: "What you have is NOT a left-handed matrix"
I am quite new to matrixes and tried applying what I was able to pick up off the forums. I will try to give it a shot tomorrow. I have been working on another demo all day.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Sep 2010 21:46
Quote: "sphenB"


Lol... sorry

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 21st Sep 2010 05:24
I'm not to good with matrix multiplication.

How would I duplicate this function using dbp matrixes? (Multiplying X, Y, Z Rotation Matrixes)


Thanks
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Sep 2010 23:32 Edited at: 21st Sep 2010 23:32


The end result will be stored in a 4D vector, but you can just ignore the last component of the vector.

Cheers!
Sven B

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 22nd Sep 2010 00:52 Edited at: 22nd Sep 2010 00:55
@Sven B - Nice. Didn't know you could get the rotation matrixes and then just transform the vector to get the result. Thanks.

Only thing I don't understand is: Why do you need: 180.0 * 3.141592654?

Thanks again
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Sep 2010 02:54
The DBPro rotation matrix commands use radians
degrees*pi/180=radians

Login to post a reply

Server time is: 2024-11-21 20:31:05
Your offset time is: 2024-11-21 20:31:05