how to draw an arrow object or a line object in the scene?

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
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

how to draw an arrow object or a line object in the scene?

Post by humorstar »

I am trying to add a line which connects two objects, and an arrow pointing away from an object in the scene.

Do I have to create a scene node for an arrow or line? Such as creating an ArrowSceneNode?
Or can I use OpenGL to directly draw some lines there? It doesn't look I can use OpenGL to draw directly. No complaint when compiling but I see no opengl graphics output.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can simply use the arrowmesh provided by Irrlicht, and render it using a mesh scene node.
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

hybrid wrote:You can simply use the arrowmesh provided by Irrlicht, and render it using a mesh scene node.
Thank you for the reply. Where is this arrowmesh? I did not see it under the \media folder. I need to dynamically change the size of arrow or line. Is that possible?
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Code: Select all

IAnimatedMesh* arrowMesh = smgr->addArrowMesh ("arrowMesh");
There are serveral ways of making a scene node of the mesh one way is:

Code: Select all

IAnimatedSceneNode* arrowNode = smgr->addAnimatedMeshSceneNode (arrowMesh);
another way is:

Code: Select all

ISceneNode* arrowNode = smgr->addSceneNode ("arrowMesh");

There are extra parameters, default values are used if you don't pass these member functions some parameters, the only essential ones are the first though. - look in the Irrlicht documentation in the 'irrlicht/docs/' folder. A search for "arrow mesh" sends you to irr::scene::ISceneManager Class Reference where you'll find what you need.


As for changing the size of the arrow:

Code: Select all

arrowNode->setScale (vector3df(x value, y value, z value) );

You need to look in the documentation when you have questions like this in the future. And i'm sure by doing this you'll also be able to find out about drawing lines.
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

Thank you for the help. I am trying to convert a direction vector, i.e., a vector pointing from one point to another, to a 'rotation' matrix, so that I can assign this rotation matrix to the arrowMesh. How to do it properly?

I am a bit confused by the coordinate system of Irrlicht. Is it a left-hand system?

Thanks again,
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Why do you need a matrix? Simply give the scenenode rotation setter function your vector.

Code: Select all

sceneNode->setRotation ( yourVector );
Where your vector is of type irr::core::vector3df

:wink:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I think what humorstar may be wanting is something like this:

Code: Select all

#include "irrlicht.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif

int main()
{
	IrrlichtDevice *device = createDevice( EDT_OPENGL,
								 dimension2d<s32>(800, 600),
								 32);
	ISceneManager* smgr  = device->getSceneManager();
	IVideoDriver* driver = device->getVideoDriver();

	(void)smgr->addCameraSceneNode();

	IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
	bill->setMaterialType(video::EMT_SOLID );
	bill->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);

	ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(vector3df(0, 0, 100), 40.f, 0.005f, vector3df(1, 1, 1).normalize());
	bill->addAnimator(animator);
	animator->drop();

	// The arrow mesh points towards +Y, but getHorizontalAngle() assumes +Z
	// so we'll use a parent node to rotate the arrow mesh node by 90 degrees.
	ISceneNode * arrowParent = smgr->addEmptySceneNode();
	arrowParent->setPosition(vector3df(0, 0, 100));
	ISceneNode * arrow = smgr->addAnimatedMeshSceneNode(smgr->addArrowMesh("arrow", 
				SColor(255, 255, 0, 0), SColor(255, 0, 255, 0)), arrowParent);
	arrow->setMaterialFlag(video::EMF_LIGHTING, false);
	arrow->setRotation(vector3df(90, 0, 0));
	arrow->setScale(vector3df(20, 20, 20));

	while (device->run())
	{
		driver->beginScene(true, true, video::SColor(0,100,100,100));
		smgr->drawAll();
		driver->endScene();

		const vector3df toBillboard = (bill->getAbsolutePosition() - arrow->getAbsolutePosition()).normalize();
		const vector3df rotations = toBillboard.getHorizontalAngle();
		arrowParent->setRotation(rotations);
	}
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
humorstar
Posts: 25
Joined: Sat Oct 04, 2008 3:50 am

Post by humorstar »

Yes, this is exactly what I am looking for. Your program, when compiled with irrlicht 1.4.2, needs a minor change:
const vector3df toBillboard
to
vector3df toBillboard

Otherwise it is all right to compile. Thank you very much,
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Ah, right, getHorizontalAngle() wasn't made const until after 1.4.2. Happy to help.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply