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.
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

Didn't knew that arrow scene node exist.

\o/ have learned something today.
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Acki wrote: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... ;)
Thanks for your suggestion.

But how can I make the XYZ arrows always appear in front of the scene node?
My problem is that the arrows are covered by the scene node......

Which API should I use?
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Image
My output

Image
Output from CopperCube

So.....Parts of the arrows are hidden by the object.....
How can I achieve the results shown in the 2nd picture?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You need to render the arrows last (maybe using a separate scene manager) and disable zbuffer test
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

hybrid wrote:You need to render the arrows last (maybe using a separate scene manager) and disable zbuffer test
:shock: It seems complicated.....

Should I use the code below to use a separate scene manager?

Code: Select all

smgr2 = smgr1->createNewSceneManager()
Is that what you mean by disabling zbuffer for the arrow?

Code: Select all

ISceneNode * arrowX = smgr2->addAnimatedMeshSceneNode(smgr2->addArrowMesh(...)); 
arrowX->setMaterialFlag(...); 
arrowX->setScale(...);
arrowX->setRotation(...);
arrowX->setMaterialFlag(video::EMF_ZBUFFER, false);
However, I have a question.
I can see the scene nodes because of the camera in smgr1.
Now, if I create smgr2, how can I see the nodes created in smgr2 using the camera created in smgr1??
macron12388
Posts: 126
Joined: Wed Sep 29, 2010 8:23 pm

Post by macron12388 »

EDIT: Nvmd, got confused
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

hybrid wrote:You need to render the arrows last (maybe using a separate scene manager) and disable zbuffer test
Could you please give me some example code?
I still do not know how to make the arrows always appear in front of the selected node. :(
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Anyone please offer help :(
I really can't understand how to make those arrows appearing in front of the selected object
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

Code: Select all

/** Example 001 HelloWorld

This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how
to write a simple HelloWorld program with it. The program will show how to use
the basics of the VideoDriver, the GUIEnvironment, and the SceneManager.
Microsoft Visual Studio is used as an IDE, but you will also be able to
understand everything if you are using a different one or even another
operating system than windows.

You have to include the header file <irrlicht.h> in order to use the engine. The
header file can be found in the Irrlicht Engine SDK directory \c include. To let
the compiler find this header file, the directory where it is located has to be
specified. This is different for every IDE and compiler you use. Let's explain
shortly how to do this in Microsoft Visual Studio:

- If you use Version 6.0, select the Menu Extras -> Options.
  Select the directories tab, and select the 'Include' Item in the combo box.
  Add the \c include directory of the irrlicht engine folder to the list of
  directories. Now the compiler will find the Irrlicht.h header file. We also
  need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries'
  in the combo box and add the \c lib/VisualStudio directory.
  \image html "vc6optionsdir.jpg"
  \image latex "vc6optionsdir.jpg"
  \image html "vc6include.jpg"
  \image latex "vc6include.jpg"

- If your IDE is Visual Studio .NET, select Tools -> Options.
  Select the projects entry and then select VC++ directories. Select 'show
  directories for include files' in the combo box, and add the \c include
  directory of the irrlicht engine folder to the list of directories. Now the
  compiler will find the Irrlicht.h header file. We also need the irrlicht.lib
  to be found, so stay in that dialog, select 'show directories for Library
  files' and add the \c lib/VisualStudio directory.
  \image html "vcnetinclude.jpg"
  \image latex "vcnetinclude.jpg"

That's it. With your IDE set up like this, you will now be able to develop
applications with the Irrlicht Engine.

Lets start!

After we have set up the IDE, the compiler will know where to find the Irrlicht
Engine header files so we can include it now in our code.
*/
#include <irrlicht.h>

/*
In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if
you want to use a class of the engine, you have to write irr:: before the name
of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice.
To get rid of the irr:: in front of the name of every class, we tell the
compiler that we use that namespace from now on, and we will not have to write
irr:: anymore.
*/
using namespace irr;

/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can
read a detailed description of them in the documentation by clicking on the top
menu item 'Namespace List' or by using this link:
http://irrlicht.sourceforge.net/docu/namespaces.html
Like the irr namespace, we do not want these 5 sub namespaces now, to keep this
example simple. Hence, we tell the compiler again that we do not want always to
write their names.
*/
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

/*
To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib.
We could set this option in the project settings, but to make it easy, we use a
pragma comment lib for VisualStudio. On Windows platforms, we have to get rid
of the console window, which pops up when starting a program with main(). This
is done by the second pragma. We could also use the WinMain method, though
losing platform independence then.
*/
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


/*
This is the main method. We can now use main() on every platform.
*/
int main()
{
	/*
	The most important function of the engine is the createDevice()
	function. The IrrlichtDevice is created by it, which is the root
	object for doing anything with the engine. createDevice() has 7
	parameters:

	- deviceType: Type of the device. This can currently be the Null-device,
	   one of the two software renderers, D3D8, D3D9, or OpenGL. In this
	   example we use EDT_SOFTWARE, but to try out, you might want to
	   change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
	   EDT_DIRECT3D9, or EDT_OPENGL.

	- windowSize: Size of the Window or screen in FullScreenMode to be
	   created. In this example we use 640x480.

	- bits: Amount of color bits per pixel. This should be 16 or 32. The
	   parameter is often ignored when running in windowed mode.

	- fullscreen: Specifies if we want the device to run in fullscreen mode
	   or not.

	- stencilbuffer: Specifies if we want to use the stencil buffer (for
	   drawing shadows).

	- vsync: Specifies if we want to have vsync enabled, this is only useful
	   in fullscreen mode.

	- eventReceiver: An object to receive events. We do not want to use this
	   parameter here, and set it to 0.

	Always check the return value to cope with unsupported drivers,
	dimensions, etc.
	*/
	IrrlichtDevice *device =
		createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
			false, false, false, 0);

	if (!device)
		return 1;

	/*
	Set the caption of the window to some nice text. Note that there is an
	'L' in front of the string. The Irrlicht Engine uses wide character
	strings when displaying text.
	*/
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	/*
	Get a pointer to the VideoDriver, the SceneManager and the graphical
	user interface environment, so that we do not always have to write
	device->getVideoDriver(), device->getSceneManager(), or
	device->getGUIEnvironment().
	*/
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	ISceneManager* smgr2 = smgr->createNewSceneManager(false);
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	/*
	We add a hello world label to the window, using the GUI environment.
	The text is placed at the position (10,10) as top left corner and
	(260,22) as lower right corner.
	*/
	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);
	

	/*
	To show something interesting, we load a Quake 2 model and display it.
	We only have to get the Mesh from the Scene Manager with getMesh() and add
	a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
	check the return value of getMesh() to become aware of loading problems
	and other errors.

	Instead of writing the filename sydney.md2, it would also be possible
	to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
	other supported file format. By the way, that cool Quake 2 model
	called sydney was modelled by Brian Collins.
	*/
	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	/*
	To let the mesh look a little bit nicer, we change its material. We
	disable lighting because we do not have a dynamic light in here, and
	the mesh would be totally black otherwise. Then we set the frame loop,
	such that the predefined STAND animation is used. And last, we apply a
	texture to the mesh. Without it the mesh would be drawn using only a
	color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
		node->setMaterialFlag(video::EMF_ZBUFFER, false);
	}

	/*
	To look at the mesh, we place a camera into 3d space at the position
	(0, 30, -40). The camera looks from there to (0,5,0), which is
	approximately the place where our md2 model is.
	*/

	ISceneNode * arrowX = smgr2->addAnimatedMeshSceneNode(smgr2->addArrowMesh("arrowZ",
		SColor(255, 255, 0, 0), SColor(255, 255, 0, 0),4,8,1.0f,0.6f,0.05f,0.2f)); 
	arrowX->setMaterialFlag(video::EMF_LIGHTING, true); 
	arrowX->setScale(vector3df(10, 10, 10));
	arrowX->setRotation(vector3df(0,0,-90));

	arrowX->setMaterialFlag(video::EMF_ZBUFFER, false);
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
	smgr2->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));


	/*
	Ok, now we have set up the scene, lets draw everything: We run the
	device in a while() loop, until the device does not want to run any
	more. This would be when the user closes the window or presses ALT+F4
	(or whatever keycode closes a window).
	*/
	while(device->run())
	{
		/*
		Anything can be drawn between a beginScene() and an endScene()
		call. The beginScene() call clears the screen with a color and
		the depth buffer, if desired. Then we let the Scene Manager and
		the GUI Environment draw their content. With the endScene()
		call everything is presented on the screen.
		*/
		driver->beginScene(true, true, SColor(255,100,101,140));

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

		driver->endScene();
	}

	/*
	After we are done with the render loop, we have to delete the Irrlicht
	Device created before with createDevice(). In the Irrlicht Engine, you
	have to delete all objects you created with a method or function which
	starts with 'create'. The object is simply deleted by calling ->drop().
	See the documentation at irr::IReferenceCounted::drop() for more
	information.
	*/
	device->drop();

	return 0;
}

/*
That's it. Compile and run.
**/

I try to modify the code in tutorial 01.
But the arrow still appears in the back :evil:
How should I fix it??
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

There you go :wink:

Code: Select all

int main()
{
	
	// initial blatter


	ISceneNode* cube = smgr->addCubeSceneNode( 10, 0 );
	
	while( device->run() )
	{
		
		if( _device->isWindowActive() )
		{
			
			driver->setViewPort( dimension<u32>( 0, 0, 840, 480 ) ); // dimension of viewport
			driver->beginScene( true, true, video::SColor( 255, 8, 16, 32 ) );
      // ***ALL*** drawing happens between the beginScene and endScene calls
			
			// Just draw the noraml added stuff
			smgr->drawAll();

			// *** CUSTOM DRAWING *** on top of everthing

			// Create a material and set two properties
			SMaterial m;
			m.ZBuffer = false; // turn off zbuffer, thus draw on top of everthing
			m.Lighting = false; // Don't apply light as it is an visual 'edit' object

			// Apply the material
			driver->setMaterial( m );

			// Draw a line from the cube his position to 100 units up in color teal
			driver->draw3DLine( vector3df(), vector3df( 0, 100, 0 ), SColor( 255, 0, 255, 255 ) );

			driver->endScene();

		} else
		{
			_device->yield();
		};

	};

};
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:There you go :wink:

Code: Select all

int main()
{
	
	// initial blatter


	ISceneNode* cube = smgr->addCubeSceneNode( 10, 0 );
	
	while( device->run() )
	{
		
		if( _device->isWindowActive() )
		{
			
			driver->setViewPort( dimension<u32>( 0, 0, 840, 480 ) ); // dimension of viewport
			driver->beginScene( true, true, video::SColor( 255, 8, 16, 32 ) );
      // ***ALL*** drawing happens between the beginScene and endScene calls
			
			// Just draw the noraml added stuff
			smgr->drawAll();

			// *** CUSTOM DRAWING *** on top of everthing

			// Create a material and set two properties
			SMaterial m;
			m.ZBuffer = false; // turn off zbuffer, thus draw on top of everthing
			m.Lighting = false; // Don't apply light as it is an visual 'edit' object

			// Apply the material
			driver->setMaterial( m );

			// Draw a line from the cube his position to 100 units up in color teal
			driver->draw3DLine( vector3df(), vector3df( 0, 100, 0 ), SColor( 255, 0, 255, 255 ) );

			driver->endScene();

		} else
		{
			_device->yield();
		};

	};

};
Thanks for your kind help.
However, your code uses driver->draw3DLine()
but what I will try to use is an arrow mesh node which can be further selected.

Also, in your code, I cannot notice any changes if I delete

Code: Select all

driver->setViewPort(core::rect<s32>( 0, 0, 840, 480 ) ); // dimension of viewport 
Do you have any idea?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you call drawMeshbuffer or draw3dVertexPrimitiveList instead it should also work. When setting the viewport to the whole screen (or a rather huge part of it) you won't notice too much change. That call is not necessary for your purpose, so simply skip it.
Anthony
Posts: 121
Joined: Sun Jan 09, 2011 12:03 pm

Post by Anthony »

Setting viewports is only needed for multiple cameras but I am not real sure here. Myself, I don't see difference too.

So propably you can skip it wich would be (a little bit faster) faster as less is more in game programming. Leaving you more 'time/fps' for the real neat stuff
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 »

hybrid wrote:If you call drawMeshbuffer or draw3dVertexPrimitiveList instead it should also work. When setting the viewport to the whole screen (or a rather huge part of it) you won't notice too much change. That call is not necessary for your purpose, so simply skip it.
Sorry....in fact, I havent solved this problem yet.

Since I cannot find any information about draw3dVertexPrimitiveList, I assume drawMeshbuffer you mentioned may do the job.

However, I have no idea of using this API to draw an arrow.

Could someone please give me some hints?
wsw1231
Posts: 148
Joined: Fri Oct 01, 2010 7:55 am

Post by wsw1231 »

wsw1231 wrote:
hybrid wrote:You need to render the arrows last (maybe using a separate scene manager) and disable zbuffer test
:shock: It seems complicated.....

Should I use the code below to use a separate scene manager?

Code: Select all

smgr2 = smgr1->createNewSceneManager()
Is that what you mean by disabling zbuffer for the arrow?

Code: Select all

ISceneNode * arrowX = smgr2->addAnimatedMeshSceneNode(smgr2->addArrowMesh(...)); 
arrowX->setMaterialFlag(...); 
arrowX->setScale(...);
arrowX->setRotation(...);
arrowX->setMaterialFlag(video::EMF_ZBUFFER, false);
However, I have a question.
I can see the scene nodes because of the camera in smgr1.
Now, if I create smgr2, how can I see the nodes created in smgr2 using the camera created in smgr1??
I still have those questions unsolved :?
Post Reply