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.

DarkBASIC Professional Discussion / Roll object with Trig

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 5th Oct 2013 17:14
This one totally lost me. I want to rotate round the Y axis but be able to roll or tilt the object left or right. You can cheat this by doing this (thought technically that's pitching):

y# = y# + 90.0
x# = rollAngle# * sin(90)
z# = rollAngle# * cos(90)

But I need to do this without adding to the y axis by 90. So any idea's guys?

"Get in the Van!" - Van B
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Oct 2013 18:13
Does the X and Z axis not rotate when you turn your object along the Y? It's been a long time since I did 3D.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 5th Oct 2013 18:55 Edited at: 5th Oct 2013 18:56
To do this you'd have to rotate x and z axises in relation to the y axis plus the roll angle. But I can't work out the trig to roll an object simply.

You could do it with a bit of complex math involving direction vectors and matrices but there much be a simple approach using trig I would of thought.

"Get in the Van!" - Van B
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Oct 2013 02:28
A typical me type of thing to do is to rotate limb zero on the X / Z axis then rotate the object on the Y axis; or vise versa. Not sure about the trig either.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Oct 2013 12:35 Edited at: 7th Oct 2013 12:47
My god this is a lot harder than I thought. The problem is not knowing what needs to be done to do this. Because it's basically two different types rotations that don't combine together well.

But if you can do it with Roll Object then there must be math for that! I imagine quaternions work but I don't know how to use them to do this sort of thing.

The Mission - Make object 2 rotate like object 1 purely with math:


"Get in the Van!" - Van B
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Oct 2013 21:31
Good luck. Any challengers?

My surrender flag is already up; or perhaps lets through up my hand

Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 7th Oct 2013 22:39
"3D" + "Challenge" = "Le Verdier"...
But before trying to answer, let's clarify:
By "trig", do you mean "trigonometry" ???
So what you want is to handle any arbitrary rotation of an object (tedious maths..)? or just this specific case of z axis/ y axis(just reverse rotation axes order on this object..)???

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Oct 2013 22:50
Basically, I need to recreate this rotation with tedious math:


And trigonometry yes. I've been looking into arbitrary axis rotation since I have experience with that and matrix based rotation but this has lost me!

"Get in the Van!" - Van B
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 7th Oct 2013 23:14 Edited at: 7th Oct 2013 23:17
I already post something on this:
[href=http://forum.thegamecreators.com/?m=forum_view&t=203213&b=1&msg=2429624#m2429624
]http://forum.thegamecreators.com/?m=forum_view&t=203213&b=1&msg=2429624#m2429624[/href]
For the math logic..

The problem is transform matrix of an object cannot be changed directly in DBP(or I didnot find how to do this...)
It is why I used a costly workaround:



The principle is to create and multiply your matrices,
And this function converts it to xyz angles..
Rotate object 1, x vector3(1), y vector3(1),z vector3(1)

Quite heavy...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Oct 2013 23:31 Edited at: 8th Oct 2013 01:46
Believe me, I've tried this but I'll take another look into matrices Edit: Got and idea... let's hope

Also, you can extract the EularXYZ from a matrix using set vector3 to matrix4 rotation from IanM's Plugin.

Edit2: What I want to do is rotate the y axis using the look vector then rotate around that axis. Hmmmm

"Get in the Van!" - Van B
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 8th Oct 2013 13:32 Edited at: 8th Oct 2013 13:48
Okay, doing the math on paper this makes sense:

1. Work out the Right/Up/Look vectors for the current angle Pitch/Yaw/Roll(XYZ)
2. Build a rotation matrix from them
3. Work out the Right/Up/Look vectors only for the Roll(Z) angle
4. Build a rotation matrix from them
5. Multiply them in reverse order and the result matrix is the final rotation
6. Convert the rotation matrix to Eular

After doing testing it finally worked! Thank GOD!!!!

So I made this function to work with whatever eular angle and can rotate every axis PitchYawRoll:


What I would do now is change the function so it doesn't use objects and just outputs the resulting vector based on my given values: rotate_PitchYawRoll( axisVector, angleVector, amount )

Thou, for most object based rotations that requires this type of rotation I'll just used a dummy object cause it's 5 times quicker (just tested)

"Get in the Van!" - Van B
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Oct 2013 02:43
You mean Euler.


Formerly OBese87.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Oct 2013 05:49
Quote: "You mean Euler."


Hehe Whoops

"Get in the Van!" - Van B
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Oct 2013 07:13 Edited at: 12th Oct 2013 07:15
I am reading a book on trigonometry at the moment. I can't answer this problem yet but it's a nice challenge.

I can't remember how rotations behave but I remember having similar problems. Is the problem that rotating on any axis tilts the other axes? Do you want to rotate the object on the x and z axis without tilting the y axis?


Formerly OBese87.
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 12th Oct 2013 16:49 Edited at: 12th Oct 2013 17:01
oops, dbl post..

Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 12th Oct 2013 17:00 Edited at: 12th Oct 2013 18:10
Quote: "
// build rotation matrix on current object angle
pitch = object angle x(id)
yaw = object angle y(id)
roll = object angle z(id)"


This is not literally exact. Object Angle X/Y/Z() doesnot provide YPR values as the standard rotation order is XYZ!!.

There is also a ROTATE YPR MATRIX4 function to directly build an YPR Matrix, but with radian values..

Here's an equivalent in degrees:



Back to your problem, just use this updating Yaw and Roll values...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Oct 2013 21:47 Edited at: 12th Oct 2013 21:47
Quote: "This is not literally exact. Object Angle X/Y/Z() doesnot provide YPR values as the standard rotation order is XYZ!!."


This I know (I think), it's just simpler to look at when creating up/right/look vectors. Rather than using XYZ in the trig calc. It's just for readability. Also since DBP trig command convert things into radians I just left them in degrees.

Quote: "Back to your problem, just use this updating Yaw and Roll values..."

Quote: "Is the problem that rotating on any axis tilts the other axes? Do you want to rotate the object on the x and z axis without tilting the y axis?"


Um... you guys realise I've already solved the problem right?

"Get in the Van!" - Van B
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Oct 2013 22:27 Edited at: 12th Oct 2013 22:28
It just realise what I'm doing is the exact same as this:



So basically what I'm doing (or have already done) is the Maths Equivalent of rotation in ZYX order for XYZ order! - That explains it's better... I think

"Get in the Van!" - Van B

Login to post a reply

Server time is: 2026-07-06 20:15:41
Your offset time is: 2026-07-06 20:15:41