Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Major Mammories

DX9 Managed (Mouse Look)

This topic is 5768 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

Hi all, This is my first post. Im writing my first app using direct x and im trying to implement mouse look. Ive been successfull except im having trouble keeping the cameras up posistion Up. Ive proberbly tried about 10 different approaches, from coz n sine to matrices and quaternions. i assumed there would be a standard way of doing this by now. Im using VB.net and DX9, and i notice it has loads of quarternion and martix related functions built in. The examples ive seen rarely make use of most of these. Are many of these new to dx9? and therefore some of the methods for free look could be updated. Im pretty sure i should be able to achive free look without mentioning the word coz or sine. Thats what im hoping. I kinda got it. Also the DX9 wizard includes an object called an arcball. I can do a kinda free look using that, although not as i hoped. is the arcball desiged for simply rotating an object using the mouse? or can it be used for free look to? I suppose what im asking for is an example of free look implemented using DX9. Thanks Kristian

Share this post

Link to post
Share on other sites
I believe that is Gimbal lock. Which is caused by mathmatics inside matrix calculations. Quaternions are supposed to fix it, but ...

The way I get around it (probably not the best way) is to create 2 matrix. Body + Head. I have the Head do the up and down (x) movement, and the body left and right (y) and the (z) rotation. It requires a few more multiply's (which are kinda slow) but it works.

If mouseY <> 0 then
D3DXMatrixRotateX(temp, mouseY)
D3DXMatrixMultiply(p_Head, p_Head, temp)
end if
If mouseX <> 0 then
D3DXMatrixRotateY(temp, mouseX)
D3DXMatrixMultiply(p_Body, p_Body, temp)
end if

D3DXMatrixMultiply(p_Camera, p_Body, p_Head)

SetTransformMatrix(D3D_TRANSFORMVIEW, p_Camera)

(sorry my VB is kinda rusty... but you probably get the idea)

[edited by - JoeyBlow2 on January 28, 2003 6:28:04 PM]

Share this post

Link to post
Share on other sites
Have you tried defining the camera''s orientation in terms of yaw and pitch and feeding that into Matrix.RotationYawPitchRoll? Constrain pitch to [-PI/2..PI/2] and you''ve got a nice and simple Quake-like camera.

Share this post

Link to post
Share on other sites
get some way the look orientation, and some way the right or left orientation, even with simple cos and sin

then u get the up position with

D3DXVec3Cross( &camUp, &camLook, &camAngles );
or( I dont''t know: )
D3DXVec3Cross( &camUp, &camAngles, &camLook );

this is very C++ , but I''m sure you''ll understand.
but I''m not sure this works.

but I think there is some very nasty free cam in some dx sample( Water, or CubeMap? I think. (DX9SDK or 8.1) You should have it.

Share this post

Link to post
Share on other sites
Heres my code, maybe you can see where its going wrong.
Is gimbal lock related to math rounding inadequcies? Coz from what i read its only a sutble effect. With mine my characters walking around at 45 degree angles sometimes.

Dim vT As New Vector3(0.0F, 0.0F, 0.0F)
Dim vR As New Vector3(0.0F, 0.0F, 0.0F)

If keyValues(Asc("W")) <> 0 Then vT.Z += 2.0F '' Move Forward
If keyValues(Asc("S")) <> 0 Then vT.Z -= 2.0F '' Move Backward
If keyValues(Asc("A")) <> 0 Then vT.X -= 1.0F '' Slide Left
If keyValues(Asc("D")) <> 0 Then vT.X += 1.0F '' Slide Right
If keyValues(CInt(Keys.Down)) <> 0 Then vT.Y -= 1.0F '' Slide Down
If keyValues(CInt(Keys.Up)) <> 0 Then vT.Y += 1.0F '' Slide Up
If keyValues(Asc("Q")) <> 0 Then vR.Y -= 1.0F '' Turn Right
If keyValues(Asc("E")) <> 0 Then vR.Y += 1.0F '' Turn Left
If keyValues(Asc("Z")) <> 0 Then vR.X -= 1.0F '' Pitch Down
If keyValues(Asc("C")) <> 0 Then vR.X += 1.0F '' Pitch Up
If keyValues(CInt(Keys.Left)) <> 0 Then vR.Z -= 2.0F '' Roll CW
If keyValues(CInt(Keys.Right)) <> 0 Then vR.Z += 2.0F '' Roll CCW

If MousePosistion.X > 1 Then
vR.Y += MousePosistion.X * 0.2F
ElseIf MousePosistion.X < -1 Then
vR.Y += MousePosistion.X * 0.2F
End If
If MousePosistion.Y > 1 Then
vR.X += MousePosistion.Y * 0.2F ''Look Up
ElseIf MousePosistion.Y < -1 Then
vR.X += MousePosistion.Y * 0.2F ''Look Down
End If

velocity = Vector3.Add(Vector3.Multiply(velocity, 0.9F), Vector3.Multiply(vT, 0.1F))
angularVelocity = Vector3.Add(Vector3.Multiply(angularVelocity, 0.9F), Vector3.Multiply(vR, 0.1F))

'' Update position and view matricies
Dim matT, matR As Matrix
Dim qR As Quaternion

vT = Vector3.Multiply(Vector3.Multiply(velocity, fSecsPerFrame), speed)
vR = Vector3.Multiply(Vector3.Multiply(angularVelocity, fSecsPerFrame), angularSpeed)

matT = Matrix.Translation(vT.X, vT.Y, vT.Z)
positionMatrix = Matrix.Multiply(matT, positionMatrix)

qR = Quaternion.RotationYawPitchRoll(vR.Y, vR.X, 0.0F)
matR = Matrix.RotationQuaternion(qR)

positionMatrix = Matrix.Multiply(matR, positionMatrix)
viewMatrix = Matrix.Invert(positionMatrix)
Device.Transform.View = viewMatrix

Any pointers will be great.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!