Jump to content
  • Advertisement
Sign in to follow this  
Nevile Moofe

Arcball camera help appreciated

This topic is 3043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to write my first DirectX app in VB.NET. It won't require game-type animation: at present all I want to do is load a high-poly mesh from an .OBJ file, display it and allow the user to move around it and look at it from different angles (other functionality will come later). At present my app loads the mesh (at a snail's pace) and allows the user to alter the lookat vector and the eye (camera) vector by dragging the mouse over controls. However, in addition to this I really want the user to be able to orbit the mesh with an arcball-type camera, which would involve clicking and dragging the mouse over a picture of a ball. The lookat vector would be the centre of the rotation, and ideally I'd like my code to simply update the eye vector so I can continue using this in my viewport update routine: device.Transform.View = Matrix.LookAtLH(eyeVector, lookatVector, upVector) I've tried adapting the Arcball class that comes with the DirectX Utilities but with no great success. My code looks like this: Private Sub picRotCam_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRotCam.MouseDown camArc.OnBegin(e.X, e.Y) End Sub Private Sub picRotCam_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRotCam.MouseMove Static OldMouseVector As New Vector2() If e.Button = Windows.Forms.MouseButtons.Left Then camArc.OnBegin(OldMouseVector.X, OldMouseVector.Y) camArc.OnMove(e.X, e.Y) eyeRotMat = camArc.GetRotationMatrix eyeVector.TransformCoordinate(eyeRotMat) '!! is this right? picMain.Refresh() 'this calls the viewport update routine where I use LookAtLH End If OldMouseVector.X = e.X OldMouseVector.Y = e.Y End Sub My simplified version of the ArcBall OnBegin and OnMove routines looks like this: Public Sub OnBegin(ByVal nX As Integer, ByVal nY As Integer) m_qDown = m_qNow m_vDownPt = ScreenToVector(CSng(nX), CSng(nY)) End Sub Public Sub OnMove(ByVal nX As Integer, ByVal nY As Integer) m_vCurrentPt = ScreenToVector(CSng(nX), CSng(nY)) m_qNow *= QuatFromBallPoints(m_vDownPt, m_vCurrentPt) End Sub I can supply more of my adapted code from the ArcBall class if necessary but I think this gives the idea. When I try this out, instead of rotating around the mesh, the camera just wiggles weakly up and down like a moribund mackerel. I suspect it might be rotating around itself instead of around the lookat vector, which isn't surprising as I can't see any way of actually passing the lookat vector to the ArcBall class. You do need to specify a radius of rotation, and I've tested with a variety of wildly different values for radius but they don't seem to make much difference. I'd be grateful if someone could help me out with some pointers. As I said I don't want to just pass a rotation matrix directly to Device.View since I want to continue keeping track of my lookat and eye vectors. I've scoured the web for help for two days now and although there are lots of code samples of ArcBall cameras none of them seem to use LookAtLH or directly update the eye vector. Thanks in advance for any help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!