Smooth mixed 1st + 3rd Person Camera Scene Node (for RPG)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Smooth mixed 1st + 3rd Person Camera Scene Node (for RPG)

Post by xterminhate »

Hi,

I’m currently involved in Action-RPG game developing (see french "H.E.L.P." project). A few weeks ago, I was looking for a smooth and mixed first and third person camera (like Guild Wars camera). So, I developed my own one. As the first result is encouraging, I would like to share it with Irrlicht users.

The class CCameraRPGSceneNode handles both player and camera moves and rotations. It receives mouse and keyboard events from device. CCameraRPGSceneNode does NOT handle player animation (you have to make your own class, inherited from CCameraRPGSceneNode).

Actually, this camera is a bit complex in its implementation (nearly 1.000 line of code) and its settings. But, using this camera remains really simple.

Test video (in-game video made by jclins, mirrored by cubicool) using this camera (version 6).
LINKS >>>> VIDEO (RapidShare) | VIDEO (Mirror1) | VIDEO (Mirror2) <<<< LINKS

Test program screen :
Image

Recent update (06/11/2006) :
* Minor change.
* Tested with Irrlicht 1.1.

Previous update (23/02/2006) :
* Add a RUN control : default running key is SHIFT and default speed multiplier is 2.0 (kickBack's demand).
* SHIFT and CONTROL keys are supported (XML user defined key map).

Previous update (17/02/2006) :
* Add a timer divider for high end computers (fixed by jclins) [the default value is 1, 64-bit computer use a value of 65536 (2^16)]
* Improved first-to-third camera transition when colliding.
* Smoother camera collision animator.

Previous update (14/02/2006) :
* Key map is loaded from XML file.

Previous update (11/02/2006) :
* Rotation and move speeds decrease when reaching target angle/position (overall smoother behavior).

Previous update (31/01/2006) :
* Camera post render its children.
* Node rotation is partially updated.

Previous update (24/01/2006) :
* Camera is now a scene node, that registers it self into Irrlicht scene manager and offers camera scene node interface.
* Camera uses default settings (from source code) and user-defined settings (from XML configuration file : see "cam.xml" into release archive).
* Camera may be inherited to add "physic" into player moves (override virtual void player_physic_animator(...) method) (asked by Sudi).
* Added custom behavior (a few flags into camera settings) according needforhint and Niels demands.
* Player is now transparent when camera is passing from 3rd to 1st person and vice-versa.

CCameraRPGSceneNode initialisation :

Code: Select all

irr::scene::CCameraRPGSceneNode* cam =
   new irr::scene::CCameraRPGSceneNode(player,smgr,1,device,selector,"cam.xml");
smgr->setActiveCamera( cam );
cam->drop();
Content of release :
The Zip archive contains the source code of CCameraRPGSceneNode(.hpp/.cpp), Irrlicht 0.14 CCameraSceneNode (.h/.cpp), and a main test program where CCameraRPGSceneNode is instanced. There is also a code::block project file (with my own directory settings, you have to change according your Irrlicht install).

Irrlicht has changed (SVN) : now OnEvent has const& argument. Change my camera OnEvent callback.

Current release (Irrlicht 1.1) :
LINK >>>>PlayerCameraRPGV8.zip<<<< LINK

Deprecated release (do not use) :
LINK >>>>PlayerCameraRPGV7.zip<<<< LINK
LINK >>>>PlayerCameraRPGV6.zip<<<< LINK
LINK >>>>PlayerCameraRPGV5.zip<<<< LINK
LINK >>>>PlayerCameraRPGV4.zip<<<< LINK
LINK >>>>PlayerCameraRPGV3.zip<<<< LINK
LINK >>>>PlayerCameraRPGV2.zip<<<< LINK
LINK >>>>PlayerCameraRPGV1.zip<<<< LINK


Install release :
Copy "100. Player Camera RPG" folder into the "irrlicht/examples" directory. Run "Irrlicht.exe" to test the camera.

Do not forget to update media and cam.xml directories into source code.
There is a Visual C++ 2005 Express project inside release. Adjust its properties to suit your software environment (paths/...).

List of controls :
Z : forward
S : backward
Q : turn left (strafe left in freelook mode)
D : turn right( strafe right in freelook mode)
A : strafe left
E : strafe right
Mouse : GUI cursor or freelook
Right Mouse Button : freelook toogle
Mouse Wheel : increase/decrease camera distance and toggle 1st / 3rd party camera mode.

Key map is for AZERTY keyboard. That may be changed into the source code and XML file.

Next update :
* A detailed documentation.
* More accurate comments into source code.
* Incorporation into Irrlicht SDK (?).

Let me know what you think of the this camera. I offer free support and on-demand new features ! :)

Please, send me screenshots and short videos of your game using this camera !

Xterm-In’Hate.
Last edited by xterminhate on Mon Nov 06, 2006 1:24 am, edited 26 times in total.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Thanks for all that stuff! Ill check it out when I get home.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

This camera is pretty cool!!!! exspecially for newcomers.
But someone who is already using irrlicht and actually wants some physic behaviour with a physics api than this camera isn't the best solution cause it is really irrlicht dependend and uses irrlichts collission detectin....But other than that great peace of work! keep it up
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Thanks. :)

Well, Irrlicht collision detection is only used to prevent camera to pass through wall in interior scene. That concerns only one line of code. I think you can adapt my class with another collision mechanism
... but I'm not familliar with physics APIs ! I'm new comer :wink:
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

works very strange for me, don't know what I got messed up
what is this thing...
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Plz explain !

It is maybe the default settings of the camera (they make camera and player rotations really slow, it is what i wanted in my game).... you can speed up all that behavior.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Perhaps, it is the Guild Wars camera style ....
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

I have just performed an update of source code.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

I don't have time right now to integrate it right now.

But If it will work (as good as you say in the first post) can I use it for free in my LOTR project including your work in credits :D ?
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

I have just tried it! Aaannnddd:

IT IS EXCELLENT & GREAT & AWESOME RPG Camera I have ever seen in irrlicht from those presented before.

Awesome and extravagant job!

I definately would like to use it in my project.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Thank for all. I hope it will serve you well. Do not hesitate to contact me if you find bugs or if you have improvment suggestion.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

I have run the camera, it is cool 3rd person camera realy,,,,, how come Xterminhate that in the example you don't create a triangle selector for fairy??? but in animator response you add fairy with q3node?.....!!jeeeeee at this very point I got it alll :lol: , i am cool
what is this thing...
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

if you could tell me one more thing Xterminhate, how do I make the playernode rotate with camera even if I don't move but only spectate? tried to change the source code but can't get the efect
what is this thing...
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

needforhint wrote:I have run the camera, it is cool 3rd person camera realy,,,,, how come Xterminhate that in the example you don't create a triangle selector for fairy??? but in animator response you add fairy with q3node?.....!!jeeeeee at this very point I got it alll :lol: , i am cool
Thank you.

But, I'm afraid I do not understand well. Selector and Animator are created according irrlicht examples.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

needforhint wrote:if you could tell me one more thing Xterminhate, how do I make the playernode rotate with camera even if I don't move but only spectate? tried to change the source code but can't get the efect
I see.

Just comment lines from 262 to 269, and from 283 to 303 in cpp file.

The code should look like that after modification :

Code: Select all

// player and cam rotation
	_cursor_position = _device->getCursorControl()->getRelativePosition();
	if( _control_instant_copy_freelook )
	{
        // when entering freelook...
	    if( ! _old_control_instant_copy_freelook )
	    {
	        // store cursor position
	        _cursor_out_of_freelook_position = _cursor_position;

	        // reset cursor position
            _device->getCursorControl()->setPosition( 0.5f, 0.5f );

            // update old status
            _old_control_instant_copy_freelook = true;
	    }
	    else // ignore player/cam rotation when entering !
	    {
            // cursor changes
            irr::f32 change_xy = ( _cursor_position.X - 0.5f ) * 256.0f;
            irr::f32 change_z = ( _cursor_position.Y - 0.5f ) * 256.0f;

//            // xy rotation/orientation
//            if( _player_is_moving )
//            {
//                if( ! _old_player_is_moving )
//                {
//                    // update old status
//                    _old_player_is_moving = true;
//                }

                // camera orientation is locked on player rotation when moving in freelook
                _camera_target_y_rotation += change_xy;

                // limit target angle // current
                if( _camera_target_y_rotation > ( _camera_current_y_rotation + _camera_to_target_y_max_angle ) )
                    _camera_target_y_rotation = _camera_to_target_y_max_angle + _camera_current_y_rotation;
                else if( _camera_target_y_rotation < ( _camera_current_y_rotation - _camera_to_target_y_max_angle ) )
                    _camera_target_y_rotation = _camera_current_y_rotation - _camera_to_target_y_max_angle;

                // lock player orientation on cam orientation in fps cam
                _player_target_y_rotation.Y = _camera_target_y_rotation;

//            }
//            else
//            {
//                if( _old_player_is_moving )
//                {
//                    // update old status
//                    _old_player_is_moving = false;
//                }
//
//                _camera_target_y_rotation += change_xy;
//
//                // limit target angle // current
//                if( _camera_target_y_rotation > ( _camera_current_y_rotation + _camera_to_target_y_max_angle ) )
//                    _camera_target_y_rotation = _camera_to_target_y_max_angle + _camera_current_y_rotation;
//                else if( _camera_target_y_rotation < ( _camera_current_y_rotation - _camera_to_target_y_max_angle ) )
//                    _camera_target_y_rotation = _camera_current_y_rotation - _camera_to_target_y_max_angle;
//
//                // lock player orientation on cam orientation in fps cam
//                if( _camera_fps_mode )
//                     _player_target_y_rotation.Y = _camera_target_y_rotation;
//            }

            // z orientation
            _camera_target_z_rotation -= change_z;

            // limit target angle // current
            if( _camera_target_z_rotation > ( _camera_current_z_rotation + _camera_to_target_z_max_angle ) )
                _camera_target_z_rotation = _camera_to_target_z_max_angle + _camera_current_z_rotation;
            else if( _camera_target_z_rotation < ( _camera_current_z_rotation - _camera_to_target_z_max_angle ) )
                _camera_target_z_rotation = _camera_current_z_rotation - _camera_to_target_z_max_angle;
Is that ok ?
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Post Reply