FPS Camera Tutorial

A forum to store posts deemed exceptionally wise and useful
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

FPS Camera Tutorial

Post by Robomaniac »

Since a bunch of people have posted one way or another asking for this, i am going to write a short tutorial on how to set up a camera with a weapon in front of it. The code is quite simple actually :

Code: Select all

irr::scene::IAnimatedMesh* weaponMesh;
irr::scene::IAnimatedMeshSceneNode* weaponNode;
weaponMesh = mSceneMgr->getMesh("shotgun.md2");  //Your Mesh is loaded here
weaponNode = mSceneMgr->addAnimatedMeshSceneNode( weaponMesh, camera, -1);  //optionaly here, you could set the initial pos, rot, and scale in that order
This code basically creates a animated mesh and coresponding node. The mesh is loaded in the third line. The fourth line creates the node, and sets its parent to the camera. Thus, any movement occuring to the camera influences the weapon. Hope that helps everybody.

Yours Truly,
The Robomaniac
Project Head / Lead Programmer
Centaur Force
Ayanami
Posts: 24
Joined: Wed Jan 14, 2004 1:30 pm

Post by Ayanami »

yeah cool. but is not the correct way, or?

i thinking:
create the weapon in 3d app with animation and save as .avi
the .avi must load in ortho mod .. sorry, the exactly way don't know.

but in games is the weapon not a komplex rendered realtime 3d graphic ...
can you additional modify your tutorial to this?
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

Most FPS game's weapons are not AVIs as you can see them effected by light. I'm pretty sure it would be slow to do this with a bitmapped graphic.
:P
________
Bmw x6
Last edited by disanti on Tue Feb 22, 2011 8:03 am, edited 1 time in total.
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

The newest game I ever saw, which used BMPs for weapon animation was Doom II or Wolf 3D, if this is younger ;)
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Guest

Post by Guest »

ALL recent 3D FSP games, render the weapon as a 3d model.
mrbig
Posts: 29
Joined: Wed Mar 17, 2004 5:38 am
Location: lakeland, Florida
Contact:

scale

Post by mrbig »

how would you go about setting the scale and pos :?:
the gun shows up right up in your face it should be more lower right
Rat
Posts: 51
Joined: Wed Mar 10, 2004 7:05 am

Post by Rat »

actually its trial and error to get the scale and position and even rotation for a weapon. The factors that effect this is how you creted the models size, and posistion in the model editor, the axis of the editor, (some modeling programs flip the Y axis for the Z axis as the newer modeling programs have corrected an incorrect axis created long ago by good old Autodesk CAD program called AutoCad). I have gotten a weapon to display in my demo for a game idea by inserting these lines of code that you can study and see if it will work for you. Now mind you it took about an hour of tweaking just to get it right!

Code: Select all

	// need to add a camera and name it camera to use it to
	// attach the weapon to it for movement
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();

	// lets place a weapon in the scene
	scene::IAnimatedMesh* weaponMesh = smgr->getMesh("../../media/sword.x");

	// Create a node so we can attach the weapon to the camera
	scene::IAnimatedMeshSceneNode* weaponNode = smgr->addAnimatedMeshSceneNode( weaponMesh, camera, -1 );

	// Your animation speed may be different so play with the value
	weaponNode->setAnimationSpeed(20);

	// The next few lines are the ones that have to be hand
	// tweaked and you may not at first see your weapon.
	// The values below reflect my weapon setting to see
	// it in front of me. My weapon had to be rotated 180
	// degrees as thats how I modeled it and didnt want
	// to rerig it and reanimate it.
	weaponNode->setScale(core::vector3df(6,6,6));
	weaponNode->setPosition(core::vector3df(0,-52,5));
	weaponNode->setRotation(core::vector3df(0,-180,0));

	// The final setup putting the camera in the level
	// where it best suits the start of gameplay.
	camera->setPosition(core::vector3df(-60,60,-40));
HTH :D
mrbig
Posts: 29
Joined: Wed Mar 17, 2004 5:38 am
Location: lakeland, Florida
Contact:

scale

Post by mrbig »

thx man
Skyclad Monkey

Post by Skyclad Monkey »

cheers man!

the rotation was out !
Hellcat

ahhhhh

Post by Hellcat »

ahhhhhh.....my game keeps crashing every time i try to run it with that FPS weps view code....instead of a .x or whatever im using a .3ds file....but either way...it just keeps crashing when i start it...any ideas?
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Sounds like the program isn't finding the mesh, check the console for errors
The Robomaniac
Project Head / Lead Programmer
Centaur Force
Hellcatt

Post by Hellcatt »

okay, when i use the code at the very top, no problems.
BUT
if i set scale, position, or rotation, it goes wacko :shock:
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

You'll have to test with those values. They depent on the model...
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Hellcatt

Post by Hellcatt »

any values i use for them makes it crash...
Tech^salvager
Posts: 32
Joined: Sat Sep 18, 2004 11:53 pm
Location: Portland, Texas, USA

Post by Tech^salvager »

Why don't you post the code up of your having trouble with it?
Post Reply