Inserting models such as a weapon into irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Wikipediaboi

Inserting models such as a weapon into irrlicht

Post by Wikipediaboi »

Hello all,
Im new to this engine and C++, but would like to put a 3ds model gun in the engine. Can anyone explain how to do this?
GameCreator
Posts: 22
Joined: Wed Jun 08, 2005 2:44 pm

Post by GameCreator »

If you're new to C++, and if you haven't done it yet, I suggest first seeing if you can even compile and run an example. Look through the tutorials on how to do this.

After that try changing an example from loading one of their meshes to one of yours.
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

Code: Select all

//! Adds a weapon model to the Players camera
//! The weapon must be aligned manualy due to different model origins etc.
//! Staff (staff.ms3d): Scale(5,5,5), Position(40,-40,40), Rotation(10,0,0)
//! Sword (sword.md2) : Scale(5,5,5), Position(40,-40,40), Rotation(10,0,0)
//! Mace  (mace.md2)  : Scale(1,1,1), Position(10,-20,0),  Rotation(10,180,-65)		
void CGamePlayer::AddFPSWeapon(IrrlichtDevice* pDevice)
{
	// load FPS weapon to Camera
	m_pWeaponMesh = pDevice->getSceneManager()->getMesh("media/models/morning_star.md2"); 
	irr::scene::IAnimatedMeshSceneNode* m_pWeaponNode;
	irr::scene::IAnimatedMeshMD2* m_pMd2WepMesh = static_cast<irr::scene::IAnimatedMeshMD2*>(m_pWeaponMesh);
	m_pWeaponNode = pDevice->getSceneManager()->addAnimatedMeshSceneNode( m_pMd2WepMesh, getCamera(), -1); 
	m_pWeaponNode->setMaterialFlag(video::EMF_LIGHTING, false);
    m_pWeaponNode->setMD2Animation(scene::EMAT_STAND);
	m_pWeaponNode->setAnimationSpeed(60);
	m_pWeaponNode->setMaterialTexture(0, pDevice->getVideoDriver()->getTexture("media/models/morning_star.bmp"));
	// manualy position model based on origin, scale etc
	m_pWeaponNode->setScale(core::vector3df(1,1,1)); //1,1,1
	m_pWeaponNode->setPosition(core::vector3df(10,-20, 0)); //20,-20,0
	m_pWeaponNode->setRotation(core::vector3df(10,180,-65)); //10,180,-65
}
This is for an MD2 model, although 3DS will be very similar. Just change the IAnimatedMeshMD2 to IAnimatedMesh.
________
Honda VTR250 history
Last edited by area51 on Tue Feb 22, 2011 1:05 pm, edited 1 time in total.
wikipediaboi

Post by wikipediaboi »

Thanks area 51!
wikikpediaboi

Post by wikikpediaboi »

Do I have to create a new "Hello world" type file, or do I add this to the camera source?
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

I wish people would put more effort into learning something themselfs before posting on the forums... Game Design is an artform and a rather complex skill or set of skills to learn and do and alot of people seem to have the dark basic idea about it.

as though it were as simple to build a game as it is to play it.

I think alot of the more elite programmers and designers should think more clearly about who what when where and why they are helping.

Just think to yourself maybe you are creating your compatition.

good luck getting a model into Irrlicht btw it's not like there aren't 12 or more examples of how to do it if you know how to READ.

sigh...
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

BTW I will no longer help ANYONE that isn't properly registered and signed in that is the first symbol that you'll actually stay with it longer then a week.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Ok Midnight that is it .... Stop flaming and being such a clever "game designer & programmer"! Your problem is that you think you have made many games before (maybe u have :D :) ?) and u think u are a "mega-great-hyper - pro designer and programmer?" . If you are okay, i am proud of you, but stop complaining about other noobs and people, and if someone is asking about for example -> gun node with camera, which was asked thousand times, just show this person some code and help. (i think newbies in irrlicht wouldn't even think of searching the forums; they are making the new thread in which we could help such noobs will show them how alive this forum is - maybe they want to check if they won't be alone here)

Or if you think that NO ONE should release any form of code , because it is STEALING a lot of your hard work, try being on NETRUAL position , because you are too nervous on that i think. Just don't bother about that my friend.

PS Remember that many people are too ambitious this times, and they think they can make a little game on 2 days without hearing the name o programming : "c++"... Only thing they dont have is patience ...
Last edited by dawasw on Thu Jun 30, 2005 6:31 pm, edited 1 time in total.
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

You will need to create a "Hello world" type file, yes.

Here is some code that can be inserted after the camera is added to the SceneManager in the "Hello World" or "Quake 3 Map" tutorial:

Code: Select all

 // load FPS weapon to Camera 
   irr::scene::IAnimatedMesh* m_pWeaponMesh = smgr->getMesh("sword.3ds"); 
   irr::scene::IAnimatedMeshSceneNode* m_pWeaponNode;  
   m_pWeaponNode = smgr->addAnimatedMeshSceneNode( m_pWeaponMesh, smgr->getActiveCamera(), -1); 
   m_pWeaponNode->setMaterialFlag(video::EMF_LIGHTING, false); 
   m_pWeaponNode->setMaterialTexture(0, driver->getTexture("sword.bmp")); 
   m_pWeaponNode->setScale(core::vector3df(1,1,1)); 
   m_pWeaponNode->setPosition(core::vector3df(10,-20, 0)); 
   m_pWeaponNode->setRotation(core::vector3df(10,180,-65)); 
The original code was a function I created, and would need to be modified slightly to work.

If you can't see your weapon at first, then change the position and rotation parameters as it could be behind or above the camera.
________
Zx14 Vs Hayabusa
Post Reply