Skip to main content

History: Simple 3rd person camera

Preview of version: 5

Introduction

Pre-requisites

This is an average tutorial, I encourage you to follow at least the two firsts basic tutorials before reading this one. This tutorial assumes you know how to manipulate the entities, the camera and the scene nodes.

Main goal

The idea of this tutorial is to have a camera orbiting freely around a character so that it can rotate with or without the camera.

It can be seen in many games, where the camera follows a character, but the user can modify the angle from where the character is seen. An example of an orbit camera is the one in Soul Reaver, or Splinter Cell (IIRC. Someone confirm this!), where the player can choose the angle, and move in different directions, always watching from the same angle.

Getting started

How it works

There will be three scene nodes:

Copy to clipboard
'''Movement''' '''Node''' / / / / '''Player''' '''Camera''' '''Node''' '''Node'''

Both PlayerNode and CameraNode will be children of the MovementNode one. All the three nodes are at the same position. The translations will be executed on the movement node while the rotations will be executed either on the camera node, or on the player node. We'll have to be careful on the movements because they depend directly to the player's direction.

Prepare the sources

Files list

For the foundations, we will use the ExampleApplication.h and ExampleFrameListener.h files and we will directly modify these files. We can't derived the classes because there is already a camera management that we need to rewrite.

  • ExampleApplication.h
  • ExampleFrameListener.h

Source code

To be written

Let's get it on!

Creation of the nodes

To be written

Creation of the listener

To be written

Just a Pseudocode snippet

Create the Node Structure

Copy to clipboard
MainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MainNode"); MainNode->translate(Vector3(0, 100, 0)); PlayerNode = MainNode->createChildSceneNode("PlayerNode"); CameraNode = MainNode->createChildSceneNode("CameraNode"); CameraPitchNode = CameraNode->createChildSceneNode("CameraPitchNode"); CameraPitchNode->attachObject (mCam); CameraNode->setPosition(0, 150, 150); PlayerEntity = mSceneMgr->createEntity("Robot.mesh"); mAnimationState = PlayerEntity->getAnimationState( "Idle" ); mAnimationState->setLoop( true ); mAnimationState->setEnabled( true );

Update the System with Input

Copy to clipboard
Ogre::Vector3 Direction = MainNode->getOrientation()*Ogre::Vector3::NEGATIVE_UNIT_Z; Direction.normalise(); Ogre::Vector3 Movement; Movement = Vector3(0,0,0); mAnimationState->setEnabled(false); if(Input->Up) { Movement += Direction; } if(Input->Down) { Movement += -Direction; } if(Input->Right) { Movement.x += Direction.z * -1; Movement.z += Direction.x; } if(Input->Left) { Movement.z += Direction.x * -1; Movement.x += Direction.z; } if(Movement.x == 0 && Movement.z == 0) { mAnimationState = PlayerEntity->getAnimationState( "Idle" ); } else { Movement = Movement * Time * mWalkSpeed; MainNode->translate(Movement); mAnimationState = PlayerEntity->getAnimationState( "Walk" ); } MainNode->yaw(Input->mRotX); CameraPitchNode->pitch(Input->mRotY); mAnimationState->setLoop( true ); mAnimationState->setEnabled( true ); mAnimationState->addTime(Time);

Afterwords


This tutorial is based on the 3rd person camera system tutorial tutorial by Kencho.

You can see also Quaternion and Rotation Primer and especially the part about the dual SceneNode trick to manipulate easily the camera.


History

Information Version
Sat 16 of May, 2015 22:29 GMT-0000 kabbotta 117
Sat 16 of May, 2015 22:28 GMT-0000 kabbotta 116
Thu 07 of May, 2015 00:08 GMT-0000 kabbotta Total rewrite and update. 115
Thu 07 of May, 2015 00:06 GMT-0000 kabbotta 114
Thu 07 of May, 2015 00:01 GMT-0000 kabbotta 113
Wed 06 of May, 2015 23:59 GMT-0000 kabbotta 112
Wed 06 of May, 2015 23:55 GMT-0000 kabbotta 111
Wed 06 of May, 2015 23:54 GMT-0000 kabbotta 110
Wed 06 of May, 2015 23:54 GMT-0000 kabbotta 109
Wed 06 of May, 2015 23:52 GMT-0000 kabbotta 108
Wed 06 of May, 2015 23:44 GMT-0000 kabbotta 107
Wed 06 of May, 2015 09:42 GMT-0000 kabbotta 106
Wed 06 of May, 2015 09:40 GMT-0000 kabbotta 105
Wed 06 of May, 2015 09:40 GMT-0000 kabbotta 104
Wed 06 of May, 2015 09:37 GMT-0000 kabbotta 103
Wed 06 of May, 2015 09:36 GMT-0000 kabbotta 102
Wed 06 of May, 2015 09:32 GMT-0000 kabbotta 101
Wed 06 of May, 2015 09:32 GMT-0000 kabbotta 100
Wed 06 of May, 2015 09:29 GMT-0000 kabbotta 99
Tue 05 of May, 2015 06:15 GMT-0000 kabbotta 98
Tue 05 of May, 2015 06:12 GMT-0000 kabbotta 97
Tue 05 of May, 2015 06:08 GMT-0000 kabbotta 96
Tue 05 of May, 2015 05:55 GMT-0000 kabbotta 95
Tue 05 of May, 2015 05:52 GMT-0000 kabbotta 94
Tue 05 of May, 2015 05:51 GMT-0000 kabbotta 93