Rotate the scene -90 degrees

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
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Rotate the scene -90 degrees

Post by tracerx »

I've been messign around with camera rotation but I think what I really need is to rotate the entire scene by -90 degrees (for landscape on mobile device).

How do I do this?


thanks!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

use an empty scene node as parent for all nodes and rotate it... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

check this code out ;) :

Code: Select all

//load b3d scene
	IAnimatedMesh* mapMesh = smgr->getMesh("./data/maps/interior/interior_01.b3d");
	IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode( mapMesh );
	mapnode->setScale(core::vector3df(150,150,150));
	mapnode->setRotation( irr::core::vector3df(0,180,0) );
	mapnode->setMaterialFlag(EMF_LIGHTING, false);
After you create a node for your mesh you can do any operation on it (move, rotate, scale). the "setrotation" line is the one that interests you, just make sure to adapt the code according to your paths and files, and change the angle from 180 to 90. ;)

regards,
Alvaro
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Post by tracerx »

afecelis wrote:check this code out ;) :

Code: Select all

//load b3d scene
	IAnimatedMesh* mapMesh = smgr->getMesh("./data/maps/interior/interior_01.b3d");
	IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode( mapMesh );
	mapnode->setScale(core::vector3df(150,150,150));
	mapnode->setRotation( irr::core::vector3df(0,180,0) );
	mapnode->setMaterialFlag(EMF_LIGHTING, false);
After you create a node for your mesh you can do any operation on it (move, rotate, scale). the "setrotation" line is the one that interests you, just make sure to adapt the code according to your paths and files, and change the angle from 180 to 90. ;)

regards,
Alvaro
Thanks. It doesn't seem to be working though.
I am working with example 12 terrain (possibly something
I'm doing after cancels it out?):


Code: Select all

	// add terrain scene node
	terrain = smgr->addTerrainSceneNode(
		MakeIntoResourcePath("terrain-heightmap.bmp"),
		0,					// parent node
		-1,					// node id
		core::vector3df(0.f, 0.f, 0.f),		// position
		core::vector3df(0.f, 0.f, 0.f),		// rotation
		core::vector3df(40.f, 4.4f, 40.f),	// scale
		video::SColor ( 255, 255, 255, 255 ),	// vertexColor
		5,					// maxLOD
		scene::ETPS_17,				// patchSize
		4					// smoothFactor
		);
	


	terrain->setMaterialFlag(video::EMF_LIGHTING, false);

	terrain->setMaterialTexture(0,
			driver->getTexture(MakeIntoResourcePath("terrain-texture.jpg")));
	terrain->setMaterialTexture(1,
			driver->getTexture(MakeIntoResourcePath("detailmap3.jpg")));
	
	terrain->setMaterialType(video::EMT_DETAIL_MAP);

	terrain->scaleTexture(1.0f, 20.0f);
	//terrain->setDebugDataVisible ( true );
	
#ifdef FORCE_LANDSCAPE
	terrain->setRotation(core::vector3df(0, -90, 0));
#endif	

	scene::ITriangleSelector* selector
		= smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(60,100,60),
		core::vector3df(0,0,0),
		core::vector3df(0,50,0));
	selector->drop();
	camera->addAnimator(anim);
	anim->drop();
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

	scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(
		driver->getTexture(MakeIntoResourcePath("irrlicht2_up.jpg")),
		driver->getTexture(MakeIntoResourcePath("irrlicht2_dn.jpg")),
		driver->getTexture(MakeIntoResourcePath("irrlicht2_lf.jpg")),
		driver->getTexture(MakeIntoResourcePath("irrlicht2_rt.jpg")),
		driver->getTexture(MakeIntoResourcePath("irrlicht2_ft.jpg")),
		driver->getTexture(MakeIntoResourcePath("irrlicht2_bk.jpg")));
	scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("skydome.jpg"),16,8,0.95f,2.0f);

	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);

	// create event receiver
	MyEventReceiver receiver(terrain, skybox, skydome);
	device->setEventReceiver(&receiver);


tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Post by tracerx »

I just realized the above won't work anyway because the sky and 2D bitmaps would not also be rotated as well.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Re: Rotate the scene -90 degrees

Post by vitek »

tracerx wrote:I've been messign around with camera rotation but I think what I really need is to rotate the entire scene by -90 degrees (for landscape on mobile device).
I'm fairly certain that this isn't really what you want to do. If you want landscape mode, you just create a window that is taller than it is wide and then tell the camera about the new aspect ratio.

Travis
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Re: Rotate the scene -90 degrees

Post by tracerx »

vitek wrote:
tracerx wrote:I've been messign around with camera rotation but I think what I really need is to rotate the entire scene by -90 degrees (for landscape on mobile device).
I'm fairly certain that this isn't really what you want to do. If you want landscape mode, you just create a window that is taller than it is wide and then tell the camera about the new aspect ratio.

Travis
Thanks.

I'm doing that, but what happens is it renders it in portrait mode with the
left and right sides cutoff. I need the engine to think that the bottom left
of the screen is the top left of the screen.


In my old 2D OpenGLES code I just swap the vertices coordinates to
draw my one quad with a different orientation.

I'm starting to think this is something that needs to be done at the
driver level.
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Re: Rotate the scene -90 degrees

Post by tracerx »

vitek wrote:
tracerx wrote:I've been messign around with camera rotation but I think what I really need is to rotate the entire scene by -90 degrees (for landscape on mobile device).
I'm fairly certain that this isn't really what you want to do. If you want landscape mode, you just create a window that is taller than it is wide and then tell the camera about the new aspect ratio.

Travis
OK, I'm trying messing with the aspect ratio directly now, using

Code: Select all

	core::dimension2d<u32> size(480, 320); 
	m_pDriver->OnResize(size);
	f32 oldAspectRatio = m_pCamera->getAspectRatio();
   m_pCamera->setAspectRatio(1.f * 480 / 320);
   f32 oldFieldOfView = m_pCamera->getFOV();
   m_pCamera->setFOV(oldFieldOfView * 480 / (480 - 2));
Its different.

But its now just pushed the 480 wide scene to the bottom, so the top half
of the screen is black, and the bottom half has the 480 wide scene (I
think) just cutoff on the side(s).

Somehow I need to tell it that the bottom left corner if the top left
corner. Can SetTranform do this? HOw would I tell it to rotate -90
degrees?
Post Reply