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.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

You can easly change camera settings into the XML file to slow down.

The vertical rotation speed of the camera :
<camera_default_z_rotation_speed speed="0.1"/>
You can decrease this value to 0.05 for instance.

The horizontal rotation speed of the camera :
<camera_default_y_rotation_speed speed="0.2"/>
You can decrease this value to 0.1 for instance.

The player move speed :
<player_move_step distance="10"/>
You can decrease this value to 5 for instance.

You cal also change mouse sensitivity for freelook mode :
<mouse_sensitivity distance="256.0"/>
You can decrease this value to 128 for intance.

About keys, I have got a AZERTY keyboard. If you have a QWERTY one, just change the source code.

In freelook mode, key map is Quake-like compliant. Keys allow run forward and backwar, and strafe left and right.

In non freeelook mode, key replaced mouse. Keys allow run forward and backward, strafe left and right and turn left and right .

Xterm-In'Hate.
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 »

shouldn't this thread be moved to project announcments forum?
every time I read the subject I wander "who wants 3rd person camera again" and uala I see xterminhate and am clear again 8)
what is this thing...
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Thanks :D

Although the camera is used in my project (and I hope in other projects), this camera is not yet mature (i'm dealing with physics now). I am still working on it. Soon, I will ask for moving the thread in a better place.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
jclins
Posts: 86
Joined: Thu Jan 01, 2004 10:29 pm
Location: Texas, USA

Post by jclins »

xterminhate -- I made the adjustment like you suggested (well, a bit more than you suggested). It still moves too fast. Is there any way to adjust the fps based on system spec? :cry:
<camera_default_y_rotation_speed speed="0.0001"/>
<camera_default_z_rotation_speed speed="0.0001"/>
...
<player_default_move_speed speed="0.02"/>
<player_move_step distance="1"/>
...
<mouse_sensitivity distance="64.0"/>
It would be nice if the keys are changeable in the xml file. *hint* *hint* :D

The other thing wierd is that when I push forward, the player mesh and camera goes out of range of the level. :? Maybe my world coordinate is different than yours?

This is an excellent cam. Keep it up! :o
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Ok. I will improve XML-oriented settings to take in account user defined key map.

Moves and rotations are all time-based. For instance a rotation speed of 0.0001 means that the camera makes a 360° in .... about 1 hour ! With such values, the cam should not move at all. :shock:

What is your hardware (hyperthreading, 64-bit platform,...) ? Are you sure that Irrlicht tutorials run well on your hardware ? If you made changes into the code, please send me your project.
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 updated the camera. Key map is loaded from XML config file, default key map still in code (default : AZERTY GW-like key map).

Do not hesitate to give me your impression.

Enjoy,
Xterm-In'Hate.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
jclins
Posts: 86
Joined: Thu Jan 01, 2004 10:29 pm
Location: Texas, USA

Post by jclins »

xterminhate -- I just tried out v5. Those values don't seem to make a difference on my desktop machine (dual core athlon AMD X2 4200+ 64-bit with ATI X800 256 MB 3D video card). It does work fine on my notebook though (1.2 Ghz Pentium M with 64 MB integrated graphics). Anyway, I hope that helps. I guess what needs to be done is some sort of FPS limiter. If running at 500 fps sync to 30 fps? Something like that... :wink:
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

V5 allow key map configuration through XML.

I haven't got such hardware platform so I won't be able to validate the code until (or send me cash :lol: ).

Try to rebuild the example from source.

If the problem remains, I think taht comes from your compiler (do not use GCC for windows) and/or its settings. Desactivating Hyperthreading in to your BIOS. Compile and link with the settings that suit your hardware.

Anyway, I will investigate.

Thanks,
Xterminhate.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Guest

Post by Guest »

Seems to me to be an internal problem with irrlicht animator:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11344

BTW, AMD Athlon X2 dual cores processor does not have "hyperthreading." That's an Intel only feature.

I have a similar system to jclins. I have rebuilt the example in VS C++ but the speed issue is the same -- too fast.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

The camera is a node, so that it is updated at each frame. Then, the camera supports time based operation. I use device->getTimer()->getRealTime() to retreive time en calculate elapsed time from the last update..... it could be interesting to check the value returned by this function on your platform.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
jclins
Posts: 86
Joined: Thu Jan 01, 2004 10:29 pm
Location: Texas, USA

Post by jclins »

xterminhate wrote:The camera is a node, so that it is updated at each frame. Then, the camera supports time based operation. I use device->getTimer()->getRealTime() to retreive time en calculate elapsed time from the last update..... it could be interesting to check the value returned by this function on your platform.
_last_frame_time = 34944136
_current_frame_time = 34955690

I only put a bp so this may not be as accurate as logging the values to a file in realtime instead of stopping the game. :D
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

That makes 11.5 secondes between frames..... according Irrlicht timer !!!!
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
jclins
Posts: 86
Joined: Thu Jan 01, 2004 10:29 pm
Location: Texas, USA

Post by jclins »

xterminhate -- I finally got it to slow down:

Code: Select all


    // elapsed time between current and last frames (sorry, I prefered ignore timeMs argument)
    _last_frame_time = _current_frame_time;
    _current_frame_time = _device->getTimer()->getRealTime();

	// calculate player's deltas
    irr::f32 player_delta_y_angle = ( (_current_frame_time - _last_frame_time)/90000.0f ) * _player_default_rotation_speed;
	irr::f32 player_delta_move    = ( (_current_frame_time - _last_frame_time)/90000.0f ) * _player_default_move_speed;

    // calculate camera's deltas
    irr::f32 camera_delta_y_angle = ( (_current_frame_time - _last_frame_time)/90000.0f ) * _camera_default_y_rotation_speed;
    irr::f32 camera_delta_z_angle =  ( (_current_frame_time - _last_frame_time)/90000.0f ) * _camera_default_z_rotation_speed;
	irr::f32 camera_delta_distance = ( (_current_frame_time - _last_frame_time)/90000.0f ) * _camera_default_move_speed;

Thanks to Saku's post from this thread:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11344

Instead of "/1000.0f," I used "/90000.0f."
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

Thank you very much ! :D It seems to be a hack...

Anyway, I can refactor the camera code and add a user-defined divider (default 1:1000 for poor hardware based on one processor, and 1:90.000 for NASA computers 8) ) into the XML config file. Is that ok for the V6 ?
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
jclins
Posts: 86
Joined: Thu Jan 01, 2004 10:29 pm
Location: Texas, USA

Post by jclins »

xterminhate wrote:Thank you very much ! :D It seems to be a hack...

Anyway, I can refactor the camera code and add a user-defined divider (default 1:1000 for poor hardware based on one processor, and 1:90.000 for NASA computers 8) ) into the XML config file. Is that ok for the V6 ?
:lol: Yeah, that sounds like a good idea to add an XML tag to adjust the scale. I also agree that it is a hack. I wished I knew more about timing and stuff. That way I could recommend a better solution for you. But it does slow it down. That fact I can attest to. :)
Post Reply