position issues

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
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

position issues

Post by dreamport »

i have a main level (map)

then add some objects..

but all the objects have the position 0, 0, 0,

how can i get its position with relative to may map?

thnx
opensource = freedom
<br>
how can you face the problem if the problem is your face?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Depends on how your objects and your scene looks like exactly.
But maybe if you are talking about lots of mesh scene nodes in your scene, but all with the position (0,0,0), maybe simply getting their absolute bounding box (getTransformedBoundingBox()), and getting the center of the box can help.
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

already tried... but still the same..

ive also tried to set my level as the parent of my ojects but still the same...

hmmm hope i can get answers...

thnx
opensource = freedom
<br>
how can you face the problem if the problem is your face?
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

If your map is one sceneNode you can make the other objects children of this node. SetPosition will then always set a relative position with the transformation of the map node defining the coordinate system.

If you want the center of your map to be the center of the world without parenting, then you have to add this position to every positioning command: node->setPosition(position+centerposition);

greetings
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

ive tried to add them as a child... but still in 0, 0, 0, coordinates

one thing...

after loading each mesh, scale up all my things by 10,

then by getting their transformedbox, it seems that the scale was ignored...

so the distance are very near to each other...

is there a way to also relate the position with the scale?

thnx
opensource = freedom
<br>
how can you face the problem if the problem is your face?
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

ok just to be precise...

here's exactly what i did...

create a level....

then add about 30 respawn point (separately) for my objects...

but the problem is all my respawn point coordinates are 0, 0, 0..

because its absolute..

ive already set my objects to be the child of my level,
and vice versa(set my level to be the parent of my objects)

but still in 0, 0, 0 coordinates...

so is there any way around in doing what im trying to do?

thnx
opensource = freedom
<br>
how can you face the problem if the problem is your face?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It's just the code that will help here. Your vague explanations only add to the confusion.
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

here's my code

Post by dreamport »

when i set the staticnode to the position of node, its still at its default position...


Code: Select all



#include <irrlicht.h>


using namespace irr;

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


int main()
{
	

	IrrlichtDevice *device =
		createDevice( video::EDT_SOFTWARE, dimension2d<u32>(800, 600), 32,
			false, true, true, 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();

	IAnimatedMesh *levelMesh = smgr->getMesh("..\\Documents\\exported_blender_files\\battlecity1.b3d");
	IAnimatedMeshSceneNode *levelNode = smgr->addAnimatedMeshSceneNode(levelMesh);
	levelNode->setScale(irr::core::vector3df(10, 10, 10));
	levelNode->setMaterialFlag(EMF_LIGHTING, false);

	IAnimatedMesh *staticMesh = smgr->getMesh("..\\Documents\\exported_blender_files\\stop0.b3d");
	IAnimatedMeshSceneNode *staticNode = smgr->addAnimatedMeshSceneNode(staticMesh);
	//staticNode->setScale(irr::core::vector3df(10, 10, 10));
	staticNode->setParent(levelNode);
	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);


	

	IAnimatedMesh* mesh = smgr->getMesh("..\\Documents\\exported_blender_files\\sydney.md2");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh, levelNode );

	
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("..\\Documents\\exported_blender_files\\sydney.bmp") );
	}

	staticNode->setPosition(node->getPosition());
	
	smgr->addCameraSceneNodeFPS();//(0, vector3df(0,30,-40), vector3df(0,5,0));

	
	while(device->run())
	{
		
		driver->beginScene(true, true, SColor(255,100,101,140));

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

		driver->endScene();
	}

	
	device->drop();

	return 0;
}
opensource = freedom
<br>
how can you face the problem if the problem is your face?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Did i miss the code where you set the other position? Anyway, positions are only updated either after calling updateAbsolutePositions or in the next frame.
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

b3d files have their position already set when loaded...

like ive created them in blender.. and when i export them to b3d and load it to irrlicht.. their positions are already the same in blender....

but the problem is their holding on to their positons as (0, 0, 0) as their origin (for each object)...

so when i add another object, set it to the position of that already loaded b3d files, the value that i get was always 0, 0, 0 so instead of being placed on the position of that object, i was placed at the center of the scene...
opensource = freedom
<br>
how can you face the problem if the problem is your face?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Now, these are two different things. The scene node has a position. The mesh has a local coord system, where the center of the mesh might be offset from the (0,0,0) center. Also, when animating (even if only one frame exists) the mesh might move. But these positions are not the scene node position. The scene node stays static while the animated mesh moves. You might be able to get a vertex position from the mesh at its absolute position. This would move while the mesh animates. But it would be pretty costly to check this.
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

about having an IanimatedMeshSceneNode and load my b3d,

can i add my b3d to some "NOT" animatedSceneNode?

thnx..
opensource = freedom
<br>
how can you face the problem if the problem is your face?
Post Reply