Once again on the prowl for directx and 3d knowledge.
I have two questions to ask. The first one is the probally the most simple so I'll start there.

I wantto know how to rotate a matrix around it's current axis?
say I have a matrix and I translate it from it's origin (0,0,0) by say (50,-25,100) now I want to rotate the Z axis around its current position 100 units back. if I use the direct3d matrix multiply it will automatically default to the origin (0,0,0) and rotate around the Z axis at 0 ,

doing this will cause the image to jump back to the origin (0,0,0) and rotate there when I want it to rotate it in place around its new origin (50,-25,100)

I have tried building a transform matrix using matrix one but I don't to much about this function and can't figure it out

Some one help me out here how is this done?

O.k the second question might be a little simpler can some one point in the direction of a tutorial on converting 3d co-ordinates to 2d Screen space or maybe explain the basics to me?

With regards your first question, could you post the bit of code where you are trying to do the rotation. I might be able to help you on this if I can see what code you already have.

As for the second question, have you done a search on google?

Public Sub RotateTank(ByVal Tank As Integer)
If Tank = 1 Then
TankOneCurrentTexture += 1
If TankOneCurrentTexture >= 15 Then
TankOneCurrentTexture = 1
End If
TankOneMatrix = Matrix.Multiply(TankOneMatrix, Matrix.RotationZ(Z * Math.PI / 180))
Exit Sub
ElseIf Tank = 2 Then
TankTwoCurrentTexture += 1
If TankTwoCurrentTexture >= 15 Then
TankTwoCurrentTexture = 1
End If
TankTwoMatrix = Matrix.Multiply(TankTwoMatrix, Matrix.RotationZ(Z * Math.PI / 180))
Exit Sub
ElseIf Tank = 3 Then
TankThreeCurrentTexture += 1
If TankThreeCurrentTexture >= 15 Then
TankThreeCurrentTexture = 1
End If
TankThreeMatrix = Matrix.Multiply(TankThreeMatrix, Matrix.RotationZ(Z * Math.PI / 180))
Exit Sub
ElseIf Tank = 4 Then
TankFourCurrentTexture += 1
If TankFourCurrentTexture >= 15 Then
TankFourCurrentTexture = 1
End If
TankFourMatrix = Matrix.Multiply(TankFourMatrix, Matrix.RotationZ(Z * Math.PI / 180))
Exit Sub
End If
End Sub

what I am trying to do here is make a tank game and the basic movements of the tanks is one button would rotate the tank left or right and the other would move the tank foward in the direction the tank is facing after the rotation but my problem is when I rotate any of tanks matrixs they always start rotating around the origin of the matrix (0,0,0) when I want the tank to rotate in place in it's current position. kind of like when you rotate a 3d model in a modeller how it just rotates in a static position and not aroung the worlds origin

I have tried using the yaw , pitch , roll function to multiply with the matrix but it still defaults back to the origin

I know this problem has something to with the matrixs transform settings because when you multiply the view matrixs transform by a rotation matrix it rotates in its current spot not around the origin

Code:

Public Sub RotateCamera(ByVal Vec As Vector3)
Device.Transform.View = Matrix.Multiply(Device.Transform.View, Matrix.Rotatioz(Z * math.pi / 180))
End Sub

this is one of the reason I am trying to learn myself how matrixs work and how 3d points are converted to 2d space because with this knowledge learing to program in 3d will be very hard and what I know about the way a computer works in 3d would be superficial. just mindless building off of someones else's hard work

ok enough rambling , back to the drawing board
much gratefull for any help

Maybe I'm not using your function right or something but it's seem to me your code for rotation is the same as doing this

Code:

Public Sub RotateZ(ByVal Angle As Double)
Angle = Z * Math.PI / 180
TankOneMatrix.M11 = Math.Cos(Angle)
TankOneMatrix.M12 = Math.Sin(Angle)
TankOneMatrix.M21 = -Math.Sin(Angle)
TankOneMatrix.M22 = Math.Cos(Angle)
TankOneMatrix.M33 = 1
TankOneMatrix.M44 = 1
End Sub

it does rotate the tank around it's current matrix but not the way I am looking for , I'm trying to get the object to spin in place like if you stood and the middle of your room and just spun around , this code is giving the effect of like if you where walking around a pole it does rotate but not without moving the object in huge loop ....... maybe I don't understand the math or something I do need to brush up on my geometry or maybe it's just the computer
(Gives the computer a threatening look) " Do as I say , not as I type. "

Hey it has been a while since I last worked on my 3d Engine here.
I am still working on the basics with rotation though

I Figured out how to make an object rotate around its current axis in odd ways though

here m is the matrix

Code:

Public Sub RotateAroundAxis()
M = Matrix.Multiply(M, Matrix.RotationAxis(GetCurrentAxis, 0.15))
End Sub

but when you do this the object rotates in a wild fashion
what I need is the object to rotate around its current matrix location in a specific direction

such as just have it rotate to the left or right like on the X axis

like when I hold a soda bottle and spin it in one direction on my desk

A matrix can be used to apply rotations, translations, scalings, and skewings to a vector or set of vectors, in any combination and in any order, in one matrix * vector multiplication.

Now, from what I gather.. you have a matrix which already performs a transformation (at a minimum, its already translating) and you wish to add a rotation around an arbitrary point P at the tail of this transformation

Now, I don't know the specifics of DirectX under .NET so I dont know if you've got operator overloading or whatnot on your matrices.. but basic mathematical the process is:

Public Sub RotateObject( ByVal Degree As Single,ByVal MeshMatrix as Matrix)

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

The simplest way to transform and to take into acount scaling rotation and position is to use the built in function on the matrix. its what i use and it works fine, you may have to calucalte the angles using radians but its a lot easier than the other processes.

This code will allow you to position a mesh and allow for sling and rotation, all you have to do is edit the variables.

Code:

Quaternion ROTATION = Quaternion.Identity; //Default value
Vector3 PIVOT, POSITION = new Vector3();
Vector3 SCALE = Vector3(1,1,1); //Default value
Matrix MAT;
MAT.Transform(PIVOT, ROTATION, SCALE, PIVOT, ROTOTAION, POSITION);

Now to get the screen position of a 3D vector use this code. the code is in C#, but the process is the same in vb.net

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