Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  
Evil Steve


So 3D audio is "working". I'm not entirely happy with it, but I noticed that my camera class is a bit wonky too. When you rotate around on the spot, it changes position. Which isn't ideal.

So I'll be looking for a new 3D camera class tonight. Anyone got any suggestions? It's D3D, so it's left handed coordinates, and I'm looking for your usual FPS-style camera where moving the mouse up/down/left/right causes the camera to pitch and yaw, and using the arrow keys moves forward/backwards and strafes left and right.
Should be pretty simple anyway, nothing fancy.

I've split up my music class in my engine a bit now. I used to have PMusic which played ogg vorbis music, now I have PMusic as a base class and PMusicOgg for playing ogg vorbis. My plan is to add support for something like MOD or MIDI music. Not for any real reason you understand, just for the fun of it. I'll be adding a bunch of preprocessor stuff soon to optionally compile out parts of the engine. For instance I want to be able to compile out all ogg vorbis or MOD/MIDI, be able to compile out all music completely, or all graphics or network code. I'd also like to have a preprocessor define to read data from files instead of the resource pak.
The reason for that is so I can have a properly generic engine. If I want to hammer up a quick network test for something, I can copy the engine over and commetn out everything except network code for instance.

Anyway, this is just a bit of a ramble. Back to work...
Sign in to follow this  


Recommended Comments

Ehh, I used to just have a unit vector along the Z axis that I'd rotate around the X and Y axes (axii? dunno.) by some angles that I stored for pitch & yaw. The rotated point would then be used as the "lookAt" vector.

Basically I'd use the "get a matrix from yaw, pitch & roll" function with the angles mentioned above, then transform the (0, 0, 1) point using that matrix and then offset from the eye point to get the lookAt. Pseudocode is:
1) Create transform matrix using: mat = MatrixRotateYawPitchRoll(cYaw, cPitch, 0.0f)
2) Transform point using: tPoint = Vec3Transform(Vector3(0, 0, 1), mat)
3) Offset from eyepoint: tPoint += cameraEye
4) Create view matrix using your favourite: CreatePerspectiveLookAt(cameraEye, tPoint, upVector)

For strafing, I'd take similar unit vectors (1, 0, 0 for right, -1, 0, 0 for left, etc), scale them by the distance I want to move that frame (usually multiplied by frameTimeDelta and some constant), then transform using the above matrix again to get the offset to apply to the eye position. That way you always strafe relative to the direction the camera is pointed. Eg:
1) Transform left unit vector: tPoint = Vec3Transform(Vector3(-1, 0, 0), mat)
2) Scale for smooth movement: tPoint *= timeDelta * strafeUnitsPerSecond
3) Offset the eye point: cameraEye += tPoint

Sorry, that's probably all pretty elementary, just thought I'd share how I did it in my last editor project. Plus, as you might have noticed, I can't remember the exact names of the functions in D3D anymore.

Hope that helps [smile]

Share this comment

Link to comment
Mmm, that's more or less what I have at the moment:

const EMatrix& ECamera::GetTransform()
EMatrix matTranslate, matRotateX, matRotateY, matRotateZ;
matTranslate.SetToTranslation(m_vPos.x, m_vPos.y, m_vPos.z);

m_transform = matTranslate * matRotateY * matRotateX * matRotateZ;
m_bDirty = false;

return m_transform;

Although I think there's something dodgey in my code there, it certainly looks a bit strange to me. I'm using my own hand-rolled vector and matrix classes too, so I don't have a D3DXMatrixRotationYawPitchRoll() function, unfortunately.

Actually, I just read the DX docs and they tell me that I'm doing it wrong:
The order of transformations is roll first, then pitch, then yaw. Relative to the object's local coordinate axis, this is equivalent to rotation around the z-axis, followed by rotation around the x-axis, followed by rotation around the y-axis.

*sigh* Oh well, I knew I should have RTFM [smile]

Share this comment

Link to comment
Hehehe, yeah, the order of the matrix concatenations definitely matters.

Sounds like you've got it sorted already. [smile]

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!