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

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.

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.

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.

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.

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!!!

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.

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.

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

//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!!!

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.

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!!!

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

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

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