• Advertisement
Sign in to follow this  

Directx Camera

This topic is 2506 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've written this camera code, and it kinda works okay. but i wanna make some changes to the way it works. Mainly when i move the mouse i just want the camera to rotate.
Currently the camera rotates with the mouse, but it seems to be rotating from (0,0,0). Hopefully somebody can offer a hand with this issue.

dim m_previousposition2d as point
dim m_cameraposition as new Vector3(0,1,-75)
dim m_cameratarget as new Vector3(0,0,0)

public sub OnMouseMove()
If e.Button = MouseButtons.Right Then
leftrightrot += Calculate_Angle(e.x - m_previousposition2d)
updownrot += Calculate_Angle(x.y - m_previousposition2d)
m_previosuposition2d = e.location
End Sub

public function Calculate_Angle(byval opposite as single) as single
return Math.Atan(opposite / Math.Abs(m_cameraposition.z))
end function

public readonly property Transform() as Matrix
dim camerarotation as matrix = matrix.rotationx(updownrot) * matrix.rotationy(leftrightrot)
dim camerafinalposition as vector3 = vector3.transformcoordinate(m_cameraposition, camerarotation)
dim camerafinaltarget as vector3 = vector3.transformcoordinate(m_cameratarget, camerarotation)
dim camerafinalupvector as vector3 = vector3.transformcoordinate(new vector3(0,1,0), camerarotation)
return matrix.LookAtLH(camerafinalposition, camerafinaltarget,camerafinalupvector)
End Get


Share this post

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

  • Advertisement