Matrix/Vertex

WebKill2k

Member
Joined
May 15, 2008
Messages
14
Programming Experience
1-3
Ok, I'm working with some DirectX, trying to learn as I go along. So far I have created a mesh and plopped the camera inside a mesh box that has a brick pattern. I have figured out how to rotate the camera left and right, up and down fluidly; but there are a few weird things (code below).

I can turn left and right smoothly, but if I go up or down the camera resets it's position before moving; same deal with up and down, it goes smooth back and forth but when I go left or right it resets it's position.

Now this code may be screwy, but like I said I've been trying to figure this out with trial and error (if anyone knows a good site I can read I'd appreciate it). I set a new vector ans set the x or y to 1 so that it will work on that axis, then the second item of rotationaxis calls for angle. Well, I want it to remember where it's at so that it wont jump when I stop rotating, so I didn't use the code I saw online about using the system time; instead I set a variable to increase each pass and add it to a very large number divided by 1000. Why I have to add to a large number and divide by 1000 I do not know, but I do know that if I just use increments of a single or double digit, the camera moves with lighting fast speed.

Any insight or resources would be appreciated; I really want to learn this properly.


VB.NET:
        Public Sub LookLeft()
            Dim tempMatrix As Matrix

            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
            axisX = axisX + 4.0F
            tempMatrix = Matrix.RotationAxis(New Vector3(0, 1, 0), (axisX + 2123489) / 1000.0)

            device.Transform.World = tempMatrix

        End Sub

        Public Sub LookRight()
            Dim tempMatrix As Matrix

            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
            axisX = axisX - 4.0F
            tempMatrix = Matrix.RotationAxis(New Vector3(0, 1, 0), (axisX + 2123489) / 1000.0)

            device.Transform.World = tempMatrix
        End Sub

        Public Sub LookUp()
            Dim tempMatrix As Matrix

            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
            axisY = axisY + 4.0F
            tempMatrix = Matrix.RotationAxis(New Vector3(1, 0, 0), (axisY + 2123489) / 1000.0)

            device.Transform.World = tempMatrix
        End Sub

        Public Sub LookDown()
            Dim tempMatrix As Matrix

            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
            axisY = axisY - 4.0F
            tempMatrix = Matrix.RotationAxis(New Vector3(1, 0, 0), (axisY + 2123489) / 1000.0)

            device.Transform.World = tempMatrix
        End Sub
 
Back
Top