Mumbling about the Camera system

Published October 16, 2016
Advertisement

In preparation for being able to do some stuff with the bow aiming, I've ripped out and rewritten the [font='courier new']Camera[/font] system for the game. I've split what was one system into two classes now, [font='courier new']ViewTransform[/font] which represents a position and orientation for a point of view with the orientation being represented by a quaternion and a [font='courier new']Camera[/font] class which takes care of moving between a current and a target [font='courier new']ViewTransform[/font] and providing a current view matrix based on its internal state.

In the video below, you can see that we have manual control of the camera while holding the right mouse button down, but pressing the N and M keys set hard-coded targets for the camera at opposite ends of the map which the camera will move to whenever those keys are pressed. All can be interrupted by the others at any point.

[font='courier new']ViewTransform[/font] allows us to think in terms of both rotation (quaternion) and angles (x, y rotations) but keeps all its rotations stored in a quaternion to make interpolating between two [font='courier new']ViewTransforms[/font] a breeze.

class ViewTransform{public: ViewTransform(); ViewTransform(const Vec3 &pos, const Quaternion &rot); ViewTransform(const Vec3 &pos, const Vec2 &angle); Vec3 position() const; void setPosition(const Vec3 &value); Quaternion rotation() const; void setRotation(const Quaternion &value); Vec2 angle() const; void setAngle(const Vec2 &value); void flatVectors(Vec3 &look, Vec3 &right) const;private: Vec3 pos; Quaternion rot;};[font='courier new']Camera[/font] just maintains a current [font='courier new']ViewTransform[/font] and an optional target transform and, depending on its mode, will work out the current interpolated [font='courier new']ViewTransform[/font] between the two.

class Camera{public: Camera(); enum class Mode { Manual, Tracking, Null }; void store(); void update(float delta); ViewTransform transform() const; ViewTransform transform(float blend) const; void setTransform(const ViewTransform &transform); void setTarget(const ViewTransform &transform); Mode mode() const; Matrix viewMatrix(float blend) const; Vec3 position(float blend) const;private: Mode md; ViewTransform cur; ViewTransform tar; BlendFloat t;};We don't really need to go into details here. It is all quite fire-and-forget really. When the camera is in [font='courier new']Mode::Tracking[/font], it is moving between a current and a target position, otherwise what it returns is just based on the current position.

The [font='courier new']flatVectors()[/font] method is used when the player works out what direction to move in based on the current orientation of the camera. Eventually we'll replace this with some kind of chase camera system.

So before I can get into the bow drawing and other combat camera activity, I think I need to get the normal chase camera system working. Not sure hwo this should work yet.

There is the original Tomb Raider system of the camera trying to stay behind the player at all times as the player rotates, or the newer Tomb Raider system whereby the camera stays a fixed distance from the player, but the controller controls the angle of the camera by rotating left and right and up and down, then movement is always in the direction of the camera towards the player. Not sure which is better here.

I'm already finding it difficult to track how this should work across all the different units that look after the player now. There is [font='courier new']Pc[/font] which is the highest level unit that connects the player to the [font='courier new']Entity[/font] system, the [font='courier new']PcData[/font] unit which is owned by the [font='courier new']Pc[/font] class and provides all the state to the [font='courier new']PcStateMachine[/font] class which looks after switching the player into all of its different states.

Hard to get a good overview, especially on a weekend morning when I'm half-asleep which is when I am doing most of the work on this these days :).

I'll post this now and then have some time to reflect I think. Sorry if it is largely mumble. That is how it is in my head at the moment.

[LATER EDIT]

Woke up a bit as the day wore on and managed to figure out what I needed to get the basic chase camera working, as per this video:



It was quite a lot easier than I expected actually. You'll see I've opted for the version where the player controls the rotation with the mouse and the direction the player runs in is relative to whatever direction the camera is currently facing. Feels quite nice and natural.

Using the targetting system here, so there is a small delay between the player moving and the camera tracking actually leads to a nice smoothing out of the camera motion which I personally find quite pleasing.

I'm going to fiddle about a bit more with this, see what else I can do with this system. Been meaning to get round to getting the chase camera working for months though, so a significant step here.

Thanks for stopping by.

Previous Entry All Kitted Up
Next Entry Rag Doll is back
3 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement