Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ?
Rotation on arbitrary axis ? Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Go Back  Xtreme Visual Basic Talk > > > > Rotation on arbitrary axis ?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2009, 07:38 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default Rotation on arbitrary axis ?


I've been tackling this problem for a while. I want to rotate all the objects in my world around one point(not the origin) say like (25,15,15). I have mastered rotating an object around it's own axis , here the code for that

Code:
                Dim N As New Matrix
                N = MeshMatrix(I)
                MeshMatrix(I) = Matrix.Translation(0, 0, 0) 'move your mesh to center or origin
                MeshMatrix(I) = Matrix.Multiply(MeshMatrix(I), Matrix.RotationX((Math.PI / 180) * Degree)) 'rotate mesh 
                MeshMatrix(I) = Matrix.Multiply(MeshMatrix(I), N) 'move mesh back to original point

this is fairly simply , move object center rotate move back to original point. Now let's say you are making a third person game and you want your character to turn left and right. You are going to have to make the objects in the world rotate around the point where the character is to make it seem like he is turning. I have tryed many different formula but nothing worked.
Anyone have any suggestions :P
Reply With Quote
  #2  
Old 05-23-2009, 10:28 AM
Qua's Avatar
QuaRotation on arbitrary axis ? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

What is the issue? You can use the Matrix.RotateAxis method to rotate your objects around an arbitrary specified axis such as the one you specified with Matrix.RotateAxis(new Vector3(25,15,15), amount). If you want to do the rotation in place, then move the object to Origo before during the rotation.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 05-23-2009, 11:41 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default

That function causes all sorts of random rotations it doesn't simply just rotate around an axis in a specific direction. I think you misunderstood me. I want the object to rotate around say (15,5,25) along the Y axis. (15,5,25) is the origin at wich I want the object to rotate around and I only want it to rotate on axis at a time x,y, or z. Say my character was at point (15,5,25) in my world and he turns around. I would need the world to rotate around that point(15,5,25) along the Y axis. I can't get the rotationsxis method to do that maybe I'm using it wrong do you have an example of how to do that.
Reply With Quote
  #4  
Old 05-23-2009, 02:48 PM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

create a matrix just for rotation, when you have the result multiply the rotation matrix by the translation matrix. Basically the rotation matrix will rotate around 0,0,0 and then be moved acording to the translation.

but there is a much easier and simpler way....

i've help u alot so far.....

Code:
                //Transform
                Vector3 POSITION, PIVOT, SCALE
                Quaternion ROTATION;
                Matrix MATRIX;

                MATRIX.Transform(PIVOT, ROTATION, SCALE, PIVOT, ROTATION, POSITION);
The matrix is filled with the required transform.

u will need to learn quaterions, there really simple anyway and much faster.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #5  
Old 05-23-2009, 05:52 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Talking

Woot !!! ty for the suggestions btw leade hehe , but I figured out how to do it without using qauternions. Complicated but it works here is the process

Code:
              Dim N As New Matrix
            N = MeshMatrix(ObjectNumber)
            Dim NewPosition As Vector3
            NewPosition = New Vector3(Position.X - N.M41, 0, Position.Z - N.M43)
            MeshMatrix(ObjectNumber) = Matrix.Translation(NewPosition) 'move your mesh to center or origin
            MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), Matrix.RotationY((Math.PI / 180) * Degree)) 'rotate mesh 
            MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), N) 'move mesh back to original poin
            MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), Matrix.Translation(NewPosition))
This will rotate an object on an point , along the Y axis.
Basically how this works is first you create a matrix to save the matrix that you want to rotate. Then you get the distance between the objects position and the center of rotation. However don't get the Y distance since that is what we will be rotating along.
Next move the object to the position corresponding to the distance between the two points. Then rotate the object. Move it back to it's original position then translate it by the distance.
Only problem with this formula is it seems to start out slowly rotating then it progressively speeds up I have yet to find out what is causing this.

Last edited by Chris Ara; 05-23-2009 at 07:09 PM.
Reply With Quote
  #6  
Old 05-23-2009, 07:43 PM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

The reason the rotation speeds up is because you are adding a new rotation to the already rotated mesh, so the value in the matrix get larger and larger and the mesh rotate faster.

Basically you are resetting the position to 0,0,0 but not the angle.

you could just do this....

Code:
                    Matrix Rot = Matrix.Identity;
                    Rot.RotationY((Math.PI / 180) * Degree);

                    Matrix Pos = Matrix.Translation(0, 0, 0); // <--- Enter the translation position here
                    Pos.Multiply(Rot);
Result the mesh rotates around Y axis no matter where in 3D space it is.

all u need is the position in space and the angle of rotation to make this work..

Also, i unfortunately don't have the VB6 animation code left,cos 1 deleted it, when i reinstalled c# and uninstalled vb6.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!

Last edited by Leade; 05-23-2009 at 07:50 PM.
Reply With Quote
  #7  
Old 05-23-2009, 10:29 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default

Well I'm still at it. I got the math right atleast , now to deal with the matrix part. I'm little rusty at matrixs I've been out of school for abot 8 years. Plus microsoft provides very poor documentation with there products. What they do provide depends heavily on helper classes and it takes a very long time to decipher through the garbage to get what you want to know. I feel like I'm in class without a teacher.
Well I tryed creating a new matrix then apply rotation and multiplying it be another translation matrix. But the result ends up being just a rotation around origin. Perhaps I'm doing it wrong. I still don't see where my rotation is stacking in my original code. I only call it once.
Reply With Quote
  #8  
Old 05-24-2009, 04:47 PM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

i'm confused now, that was the right way to the rotation, you probly multiplyed the rotations as XYZ, instead on ZYX, that make a big difference to the rotation of the mesh.

XYZ rotation rotates everything around the the axis, whereas ZYX rotates the axis, (thats a very bad description sorry) ZYX is what you want.

...ZYX is used in flight sims for planes whereas XYZ would best be used for a planet orbiting a sun.

its basically the order the angles are multiplied together. you can have stupid ones like ZXY, but i ask why really.

ok lets see if i can remember this method....

Code:
Matrix Rot = Matrix.Identity;
Matrix RotX = Matrix.Identity;
Matrix RotY = Matrix.Identity;
Matrix RotZ = Matrix.Identity;
Matrix Pos = Matrix.Translation(0, 0, 0)

RotX.RotationX((Math.PI / 180) * DegreeX);
RotY.RotationY((Math.PI / 180) * DegreeY);
RotZ.RotationY((Math.PI / 180) * DegreeZ);

Rot = RotZ;                                    //Heres your ZYX rotation
Rot.Multiply(RotY);
Rot.Multiply(RotX);

Pos.Multiply(Rot);
Well what do u know i do remember it. its all coming back.
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #9  
Old 05-24-2009, 05:53 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Talking

Well that's a nifty little shortcut for writing code , but I think you missed the point. go up 2 or 3 post and see where I posted my code for rotation around an arbitrary axis. I was able to get my mesh to rotate around a point say(15,34,25) along a certain axis x,y or z. The problem was when I used the function the mesh rotation would progressively speed up. I've mixing up the code and using some of your suggestions. I still don't see where I'm stacking the rotations like you said. I'm going to keep trying but if ya could help me out here I've been working on this for days tyvm
Reply With Quote
  #10  
Old 05-24-2009, 07:20 PM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

ooops my mistake,

ok

Code:
//here you get the transform, which i take it already has the previous rotation inside
Dim N As New Matrix
N = MeshMatrix(ObjectNumber) 

//here you reset the position
Dim NewPosition As Vector3
NewPosition = New Vector3(Position.X - N.M41, 0, Position.Z - N.M43)
MeshMatrix(ObjectNumber) = Matrix.Translation(NewPosition) 'move your mesh to center or origin

//here you are adding the old matrix to the new matrix
MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), 

//now is is where you create the new rotation
Matrix.RotationY((Math.PI / 180) * Degree)) 'rotate mesh 

//and add it to the already rotated matrix
//example: angle inside matrix is lets say 45 degrees, then you are rotating it
//again by the new degrees in the new matrix, then when its called again,
//the angle is wateva the answer was previously rotated by the new degree
//again. making the angle rotate faster and faster. i would say its here where it is going wrong
MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), N) 


//add the transform again
'move mesh back to original poin
MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), Matrix.Translation(NewPosition))
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #11  
Old 05-24-2009, 09:54 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default

Well that's it I give up for now. The code I as using earlier that worked but with speeding up the rotations now doesn't work...... that's right I was trying new things then I gave up and uncommented my original code and saved it. When I ran the project the object just rotated in it's place and not around the the point like it did before. I have no idea what happened :< oh well :> is there anyone out there who knows the code to rotate around an arbitrary axis if there is please post it . Don't post ideas or suggestions just code lol I'm tired of guess work grrrrrrr.... well ty anyways maybe I'll come back to this later.
Reply With Quote
  #12  
Old 05-25-2009, 04:49 AM
Leade's Avatar
Leade Leade is offline
Junior Contributor
 
Join Date: Jul 2005
Location: Wherever i fall over
Posts: 222
Default

i really don't understand what its is u want then, do u want it so the vertecies on the left rotate behind and the vertcies on the right rotate in front.

what exactly are you tring to rotate then? can you put a diagram up?
__________________
Fact: The best ideas come when your smashed of your face. So drink beer and be merry!!!
Reply With Quote
  #13  
Old 05-25-2009, 06:08 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default

I just want to apply transformations to a matrix that will make in rotate around an arbitrary point in space along a certain axis(direction) that's all
Reply With Quote
  #14  
Old 05-31-2009, 07:37 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default The Solution

Here is the solution for rotating around an arbitrary axis in Directx

Code:
            Dim N As New Matrix
            N = MeshMatrix(ObjectNumber)
            Dim NewPosition As Vector3
            NewPosition = New Vector3(Position.X - N.M41, 0, Position.Z - N.M43)
            MeshMatrix(ObjectNumber) = Matrix.Translation(NewPosition)
            MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), Matrix.RotationY((Math.PI / 180) * DegreeY)) 'rotate mesh 
            Dim Mat As Matrix
            Mat = MeshMatrix(ObjectNumber)
            NewPosition = New Vector3(NewPosition.X - Mat.M41, 0, NewPosition.Z - Mat.M43)
            MeshMatrix(ObjectNumber) = Matrix.Translation(N.M41, N.M42, N.M43)
            MeshMatrix(ObjectNumber) = Matrix.Multiply(MeshMatrix(ObjectNumber), Matrix.Translation(NewPosition.X, 0, NewPosition.Z))

A few quick things to note MeshMatrix(ObjectNumber) is just an array list containing matrixes. The variable Position is where your current matrix is located this would be the m.41 = x , m.42 = y and m.43 = z values. DegreeY is just a variable storing the degrees to rotate by. Plus this rotates around the Y axis. o change the axis of rotation you would just need to subtract the differences of x and y to make z or z and y to make x.

K now for the explanation.
First Get the distance between the position you wish to rotate around and the position of your object. This distance is stored in the variable NewPosition.
next move your object to that position.
Now Rotate your object
Next get the distance between the position before rotated and the position after rotation This will be your angle.
Next Move the object back to it's original position.
Finally translate it by the angle wich is stored in newposition variable.

Bam this gives you rotation about an arbitrary axis. GL and have fun friends

Last edited by Chris Ara; 05-31-2009 at 07:44 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ? Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ? Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
 
Rotation on arbitrary axis ?
Rotation on arbitrary axis ?
 
-->