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 / math rotation to object rotation

Author
Message
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 11th Jan 2013 15:10
Hi

in my game i use a vector for calculating rotations. it defines the axis of rotation and its length is the magnitude. how do i rotate an object using this vector? I have tried using its x y and z components as x y and z angles in the command rotate object but it doesnt seem to work well.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Jan 2013 15:57 Edited at: 11th Jan 2013 15:58
Why use a vector? You can directly rotate it:



The object will not continue rotating if that's what you want. For that, you have to calculate a new angle every loop like this:



TheComet

http://blankflankstudios.tumblr.com/
Quote: ""
- Randomness 128
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Jan 2013 16:45 Edited at: 11th Jan 2013 16:45
Can you say what your using this for cause there's loads of different uses for vectors? As it sounds for me, it's an axis angle vector I believe.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jan 2013 20:09
I just use EZ Rotate for those kinds of things...

There is a free version floating on these Forum Rivers...

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 11th Jan 2013 21:27 Edited at: 11th Jan 2013 21:29
i use a vector because the math (150+ lines of vector math) i use to calculate the behavior of my game uses such notation. it is a vector that is the axis of rotation and the length is the magnitude.
the problem isnt that i dont know how to rotate an object, it is that i dont know how to convert my vector value to euler angles which i supose DBP is using?

does EZ rotate have a function that rotates an object for a vector?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jan 2013 00:17
This looks relevant, especially the paragraph headed Rotation matrix from axis and angle

http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions

You'll need to sort out which axis is which in your DBPro application.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 12th Jan 2013 00:38 Edited at: 12th Jan 2013 00:41
And if you still struggle to find the answer, post the code so we can take a look.

I really do not understand what the problem is; if I see the code maybe I will understand the issue. I can't understand why you can't simply use POINT OBJECT, Rotate Limb Zero or something. I am sure one of the Atan direction calculations or COS/SIN functions can convert those vectors.

Ahh anyway... hope you found what you need.

MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 12th Jan 2013 17:10
So I recommend to you my little plugin Extendet rotation. With this you can make those rotations and calculate from a matrix to euler angles back.
And is completly free.

Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 13th Jan 2013 15:24
Why not just do:

?

You can get a matrix from your vector and two other orthogonal ones. For example, if you wanted an object that pointed in the positive Z direction to be rotated to point towards your vector, that would mean you would want to change:

A*{0,0,z} -> {z*x1,z*y1,z*z1} where (x1,y1,z1) is your unit vector direction. But then... what do you want {0,y,0} and {x,0,0} to be rotated to? To find a matrix, you need to figure that out, until you have unit vectors v1, v2, and v3 with v1.v2=v2.v3=v3.v1=0 (orthogonal) and v1.v1=v2.v2=v3.v3=1 (unit length). Then you construct a matrix {{x1,x2,x3},{y1,y2,y3},{z1,z2,z3}} (where each {a,b,c} is a row of the matrix) and plug it into something like what MadBit has (I also have a function somewhere in code snippets that calculates euler angles) to get the angles.

MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 13th Jan 2013 20:05
In my plugin is a function to turn any matrix (object/camera) around a vector.
XROT VECTOR ROTATION(xrotMatResult, xrotMatObject, xrotVector, Angle#)
xrotMatResult is the resulting Matrix of the calculation.
xrotMatObject is the curent Matrix.
xrotVector is the vector wich will turn around.
Angle# is how far will be turn.
xrotMat... and xrotVector are special variables of my plugin. But you can easy set and get the Matrix from an object by this.
DBOBJ GET MATRIX(xrotMatResult, ObjectID)
DBOBJ GET MATRIX xrotMatResult, ObjectID
Retrieves the object-matrix from the given object. The result is stored in xrotMatResult. The function with braces returns the variable xrotMatResult.
and
DBOBJ SET ROTATION MATRIX ObjectID, xrotMatrix
Set the rotation of the given object via the matrix.

Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 14th Jan 2013 16:57
@ green gandalf : thanks! im pretty sure thats what i need.
@ chris tate, neuro fuzzy : i cant use point object with the vector because as i tried to show with the image the vector is the axis of rotation not the axis it will point in. so a vector [0,0,1] would correspond to a rotation around the z axis.

@MadBit: looks very nice! will certainly have a deep look at this. downloaded it already but it seems to be missing a keyword file (.ini) ?
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 14th Jan 2013 17:35
cant get it to work... this is getting horribly frustrating, thanks for all the help so far. tried the wikipedia matrix thing



where
b(i).a is the axis vector and its length is the angle
v3 is a spare vector
its inside a for next loop so i+1 is the object number and i is the vector number

this results in very twitchy superfast rotation tha makes no sense.
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Jan 2013 19:09
this thread contains everything you need. Look at arbitrary axis rotations

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 14th Jan 2013 21:04
thank you! it actually worked

Login to post a reply

Server time is: 2026-07-07 05:14:48
Your offset time is: 2026-07-07 05:14:48