Translation and rotation

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.
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Translation and rotation

Post by wsw1231 »

Image

How to make those X, Y, Z axes visible when I translate or rotate a scene node?

How can I translate or rotate it according to the axis?

Could someone give me some example code?
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

at this page you can find tutorials
http://irrlicht.sourceforge.net/tutorials.html

next link is also good for starters
http://www.irrlicht3d.org/wiki/

for more advanced info there is
http://irrlicht.sourceforge.net/docu/index.html

these are the functions to change to pos and rot
ISceneNode::setPosition( vector3df( x, y, z ) );
ISceneNode::setRotation( vector3df( x, y, z ) );

to draw the axis
vector3df pos = ISceneNode::getPosition();
driver->draw3DLine( pos, pos + vector3df( 1, 0, 0 ), SColor( 255, 255, 0, 0 ) );
driver->draw3DLine( pos, pos + vector3df( 0, 1, 0 ), SColor( 255, 0, 255, 0 ) );
driver->draw3DLine( pos, pos + vector3df( 0, 0, 1 ), SColor( 255, 0, 0, 255 ) );
No :shock: I am no noob, just checking if your not one too :roll:

Thanks to Niko and all others that made Irrlicht possible.
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Anthony wrote:at this page you can find tutorials
http://irrlicht.sourceforge.net/tutorials.html

next link is also good for starters
http://www.irrlicht3d.org/wiki/

for more advanced info there is
http://irrlicht.sourceforge.net/docu/index.html

these are the functions to change to pos and rot
ISceneNode::setPosition( vector3df( x, y, z ) );
ISceneNode::setRotation( vector3df( x, y, z ) );

to draw the axis
vector3df pos = ISceneNode::getPosition();
driver->draw3DLine( pos, pos + vector3df( 1, 0, 0 ), SColor( 255, 255, 0, 0 ) );
driver->draw3DLine( pos, pos + vector3df( 0, 1, 0 ), SColor( 255, 0, 255, 0 ) );
driver->draw3DLine( pos, pos + vector3df( 0, 0, 1 ), SColor( 255, 0, 0, 255 ) );
I have encountered some problems when using draw3DLine function.

Code: Select all

SMaterial m; 					   m.setTexture(0,0);
m.Lighting=false; 
driver->setMaterial(m); 
driver->setTransform(video::ETS_WORLD, core::matrix4()); 
driver->draw3DLine(SelectedNode->getAbsolutePosition(),vector3df(0,500,0),SColor(255,255,0,0)); 
The above code is doing a task that a red line is shown on the selected scene node. However, I cannot see any line drawn around the node when I select the node.....Why is that?
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

the code looks fine too me.

One thing - propebly not the issue - but

Code: Select all

...getAbsolutePosition(), SelectedNode->getAbsolutePosition() + vector3df(0,500,0),...
Also make sure backface and frontface culling is off.

(am a noob 8) so hope I am helping here)
No :shock: I am no noob, just checking if your not one too :roll:

Thanks to Niko and all others that made Irrlicht possible.
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Anthony wrote:the code looks fine too me.

One thing - propebly not the issue - but

Code: Select all

...getAbsolutePosition(), SelectedNode->getAbsolutePosition() + vector3df(0,500,0),...
Also make sure backface and frontface culling is off.

(am a noob 8) so hope I am helping here)
Oops....thanks for pointing out that issue...
But the line still does not appear...

How to turn off backface and frontface culling?
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

Code: Select all

	_material.BackfaceCulling	= true;
	_material.FrontfaceCulling	= false;
	// wireframe is there too among others
but don't think that would be the prob. Also I don't know why it doesn't show up. Maybe you should get the pos and not the abs pos depending of where you call it.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, absolute position is correct, as the identity matrix is used (otherwise the object transform matrix would be necessary). Maybe you did not update the absolute positions at that point?
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Code: Select all

	SMaterial m; 
	m.Lighting=false; 
	driver->setMaterial(m); 
	driver->setTransform(video::ETS_WORLD, core::matrix4()); 
	driver->draw3DLine(vector3df(100,100,100),vector3df(0,500,0),SColor(255,255,0,0)); 
	ICameraSceneNode *camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.5f);
	camera->setPosition(vector3df(0,0,0));
Even though I use the above code (i.e. ignore the SelectedNode), I still cannot see any line drawn.....
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh, you must put the draw3DLine inside the render loop. This is not a scene node by itself, but needs to be called each frame :wink:
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

hybrid wrote:Oh, you must put the draw3DLine inside the render loop. This is not a scene node by itself, but needs to be called each frame :wink:

Code: Select all

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


int main()
{
	IrrlichtDevice *device =
		createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
			false, false, false, 0);

	if (!device)
		return 1;


	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();


	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);


	smgr->addCameraSceneNodeFPS(0, 100.0f, 0.5f);

	while(device->run())
	{	
		SMaterial material;
		material.setFlag(video::EMF_LIGHTING, false); 
		material.setTexture(0, 0);
		material.Lighting = false;
		material.Wireframe=true;
		driver->setMaterial(material);
		driver->setTransform(video::ETS_WORLD, core::matrix4()); 
		driver->draw3DLine(vector3df(0,0,0), vector3df(100,100,100), SColor(255,255,0,0));

		driver->beginScene(true, true, SColor(255,100,101,140));


		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}

I have modified the code from tutorial 1 and put the draw3DLine in the render loop now....but I still cannot see the line :(
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Argh, between beginScene and endScene of course :roll:
And maybe use a decent video driver, which supports all features. Use EDT_OPENGL
Last edited by hybrid on Tue Jan 11, 2011 10:01 pm, edited 1 time in total.
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

[SOLVED]

Post by Anthony »

Code: Select all

#include <irrlicht.h> 

using namespace irr; 

using namespace core; 
using namespace scene; 
using namespace video; 
using namespace io; 
using namespace gui; 

#ifdef _IRR_WINDOWS_ 
#pragma comment(lib, "Irrlicht.lib") 
// leave commented out to see some debug information: #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") 
#endif 


int main() 
{ 
   // Set it to a device that works,  EDT_HYBRID maybe :P
   IrrlichtDevice *device = 
      createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, 
         false, false, false, 0); 

   if (!device) 
      return 1; 


   device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo"); 
   IVideoDriver* driver = device->getVideoDriver(); 
   ISceneManager* smgr = device->getSceneManager(); 
   IGUIEnvironment* guienv = device->getGUIEnvironment(); 


   guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!", 
      rect<s32>(10,10,260,22), true); 


   ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.5f); 

	 // offset the camera a bit or you won't see the line either
	 camera->setPosition( vector3df( 10, 10, 10 ) );
	 camera->setTarget( vector3df( 0, 0, 0 ) );

   while(device->run()) 
   {    
      
			driver->beginScene(true, true, SColor(255,100,101,140)); 
			// All rendering stuff happen between beginScene() and endScene()

      SMaterial material; 
      material.Lighting = false; 
      driver->setMaterial(material); 

      // for this not needed: driver->setTransform(video::ETS_WORLD, core::matrix4()); 

      driver->draw3DLine(vector3df(0,0,0), vector3df(-10,10,10), SColor(255,0,0,255)); 


      smgr->drawAll(); 
      guienv->drawAll(); 

      driver->endScene(); 
   } 

   device->drop(); 

   return 0; 
} 
8)
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

......amazing.....
thanks you guys :D
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Image

Now there are X Y Z axes shown when selecting the node.
How can I add a text near the line to indicate which line is which axis?
Should I use ITextSceneNode to do this?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I wouldn't use draw3DLine, instead I would use the errow scene node, like it was used in the 1st screenshot with the cube... ;)
this way you can select them (draw3DLine you wouldn't be able to select) and you can attach other nodes (maybe a text-billboard) to the axis... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply