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.
m3ltd0wn
Posts: 107
Joined: Wed Dec 12, 2007 8:32 am
Location: Romania

reply

Post by m3ltd0wn »

thus the camera works like a charm, seems i can't get IrrNewt to make the character to collide with other stuff in the world i haven't sleep all night trying to figure out how to add phisycs to the actor mesh and in the same time to use this camera ...


here is my code:

Code: Select all

p_world = createPhysicsWorld(device);
	
	// add terrain scene node
	scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( 
		"media/terrain-heightmap.bmp");
	terrain->setScale(core::vector3df(10, 1.1f, 10));

	terrain->setMaterialFlag(video::EMF_LIGHTING, false);
	terrain->setMaterialTexture(0, driver->getTexture("media/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, driver->getTexture("media/detailmap3.jpg"));
	terrain->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false);
	terrain->setMaterialType(video::EMT_DETAIL_MAP);
	terrain->scaleTexture(1.0f, 30.0f);
	
	//create terrain body
	irr::newton::SBodyFromNode terrainData;
	terrainData.Node=terrain;
	terrainData.Type = newton::EBT_AUTODETECT;
	terrainData.TerrainLOD = 1;
	terrain_body = p_world->createBody(terrainData);
	terrain_body->setMass(5.9736*1000000000000); //earth's mass
	terrain_body->addForceContinuous(vector3df(0,-9.81,0));	
	terrain_material=p_world->createMaterial();
	terrain_body->setMaterial(terrain_material);

	//create an actor to test the rpg camera
	scene::IAnimatedMeshSceneNode *actor = smgr->addAnimatedMeshSceneNode(smgr->getMesh("media/sydney.md2"),0,-1);
	actor->setMaterialTexture(0, driver->getTexture("media/sydney.bmp"));
	actor->setPosition(vector3df(280,56,693));
	actor->setMaterialFlag(video::EMF_LIGHTING, false);
	actor->setLoopMode(true);
	actor->setMD2Animation(scene::EMAT_STAND);

	//create actor body
	irr::newton::SBodyFromNode actorData;
	actorData.Type = newton::EBT_AUTODETECT;
	actorData.Node = actor;
	actor_body = p_world->createBody(actorData);
	actor_body->setMass(56.f);
	actor_body->setCentreOfMass(vector3df(0,-1,0));
	  //actor_body->addForceContinuous(vector3df(0,-9.81*actor_body->getMass(),0));
	actor_body->setContinuousCollisionMode(true);
	actor_material=p_world->createMaterial();
	actor_body->setMaterial(actor_material);
	actor_material->setFriction(terrain_material, 0, 0);
	actor_material->setCollidable(terrain_material, true);

	//terrain triangle selector, used for camera
	scene::ITriangleSelector* selector = 0; 	
	selector = smgr->createTerrainTriangleSelector(terrain, 0); 
	terrain->setTriangleSelector(selector);
	selector->drop();

	scene::ISceneNodeAnimator * anim = smgr->createCollisionResponseAnimator( selector, actor, core::vector3df(10,24.5,10),	core::vector3df(0,-9.81,0), core::vector3df(0,-0.1,0));
	actor->addAnimator(anim);
	anim->drop();

	//camera RPG (test)
	irr::scene::CCameraRPGSceneNode* camera = new irr::scene::CCameraRPGSceneNode(actor, smgr, 1, device, selector); 
	camera->configure("cam.xml");
	smgr->setActiveCamera(camera);
    camera->drop();
and i can't bind the camera to actor_body ...

any help is appreciated.

now i can go to sleep :)
veegun
Posts: 59
Joined: Mon May 29, 2006 1:58 am

Post by veegun »

Is it possible to re-write this camera so that it inherits from CCameraSceneNode instead of having to copy it from irrlicht source folder every time a new version of irrlicht comes out?

I've tried a couple of time and failed. :evil: I may try again with v1.5 of irrlicht.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

That can seems to live longer than I expected !

Well, I would like to update the first post of this thread with the link of the current source code of this camera. Anybody has a link of can someone can seend me the cam files ?

Xter.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
veegun
Posts: 59
Joined: Mon May 29, 2006 1:58 am

Post by veegun »

xterminhate wrote:That can seems to live longer than I expected !

Well, I would like to update the first post of this thread with the link of the current source code of this camera. Anybody has a link of can someone can seend me the cam files ?

Xter.
Huh? Are you asking for someone to send you a link to the old camera files? Don't you still have it?

Anyway, I tried with 1.5 irrlicht and failed (trying to make it inherit instead of copying CCameraSceneNode).

Hey, cool. If you use opera 10 alpha, it underlines your typos for you. :)

Update:

ssexton posted the whole source a page or so back.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The suggested way of creating a new camera for Irrlicht 1.5 is to make a new camera animator!
veegun
Posts: 59
Joined: Mon May 29, 2006 1:58 am

Post by veegun »

hybrid wrote:The suggested way of creating a new camera for Irrlicht 1.5 is to make a new camera animator!
Hmmm...I'll look into it, thanks hybrid. Camera and animator doesn't seem like it should be in the same sentence. :lol:

Anyway, would some mod move this to the 'project announcement' thread? xterminhate posted in the wrong forum and it's been stuck here since. :(

If I can get a 'new camera animator' version working, I'll post it here for everyone to use. But it might take some time. I probably end up butchering it to pieces then it won't build or nothing any more. :oops:
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'll move it to code snippets :)
tinhtoitrangtay
Posts: 70
Joined: Tue Oct 28, 2008 12:59 pm

Post by tinhtoitrangtay »

I cannot download. Please reupload or mirror link. Thanks
veegun
Posts: 59
Joined: Mon May 29, 2006 1:58 am

Post by veegun »

tinhtoitrangtay wrote:I cannot download. Please reupload or mirror link. Thanks
See ssexton's post a page or so back.

Thanks, hybrid!
Post Reply