Move 3D Object

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
jadephoenix1988
Posts: 14
Joined: Fri May 29, 2009 2:12 pm

Move 3D Object

Post by jadephoenix1988 »

Hello!

I saw the hello world project from irrlicht and now I want to move "sydney".
I in the main.cpp i just saw the camera calibration, but somewhere must be a method to set the coordinates of the mesh.

Where do I find it?
Thanks for your help :).

Edit: Ach, ist ja ein deutsches Forum :D!
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

What about virtual void irr::scene::ISceneNode::setPosition(const core::vector3df & newpos)?

And you can find it here of course: Irrlicht Engine 1.5 API documentation
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Re: Move 3D Object

Post by Sylence »

jadephoenix1988 wrote:Edit: Ach, ist ja ein deutsches Forum :D!
Eh no this is not the german forum. Take a look at my signature for it ;)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
jadephoenix1988
Posts: 14
Joined: Fri May 29, 2009 2:12 pm

Post by jadephoenix1988 »

Thanks arras for the link of the API! It will be very useful for me :).

I thought could coude something like

Code: Select all

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
		node->setPosition(55, 0, 0);
	}
to move the mesh on the x-axis. But I'm doing something not so well... which parameters do i have to add in this method? type is "const core::vector3df & newpos "
what does this explicitly mean?

Thank you very much!

@ Sylence: Thanks for the hint :O
jadephoenix1988
Posts: 14
Joined: Fri May 29, 2009 2:12 pm

Post by jadephoenix1988 »

In the last post i answered my own question, I'm such a fool :D.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

don't worry :)
should be node->setPosition(vector3df(55, 0, 0));

And you can find API in Irrlicht "doc" folder on your disk too.
Quillraven
Posts: 62
Joined: Fri Aug 22, 2008 7:22 am

Post by Quillraven »

i wonder if the setposition function checks for collision when moving long distances.

i got a weird problem. you all should know games like super mario. when you fall down in a hole, you start again at the start location and try it agaiin.


i tried to use that with irrlicht.

like this:
if cameraposition.Y < 100 then set camerposition to vector3df( 0, 100, 0 ).


the cmaera has a collision an in its way to the specified position are (of course) other scenenodes who have a collision. my camera always "hit its head" on one of these scenenodes and falls down again -> endless loop.

so i tried to turn off the collision before calling setposition but don't know how?
i tried it with setvisibility to false but the problem wasn' solved that way.

any good workarounds or functions for resetting the player to his startlocation?





second thing (not topic of this thread):
any good tutorials or threads for animatedscenenode animation? i want the faerie to move, when pressing wasd, jump when pressing jump and stand when pressing nothing
but when calling setMD2Animation the animation is instantly resetted before the old animation stops, so this is a little bit stupid :( any ideas for that?

my code looks like this

Code: Select all

// device-> run loop
if( receiver->keyPressed( KEY_KEY_W ) || receiver->keyPressed( KEY_KEY_A ) || receiver->keyPressed( KEY_KEY_S ) || receiver->keyPressed( KEY_KEY_D ) )
				faernode->setMD2Animation( scene::EMAT_RUN );
			else if( receiver->keyPressed( KEY_SPACE ) )
				faernode->setMD2Animation( scene::EMAT_JUMP );
			else
				faernode->setMD2Animation( scene::EMAT_STAND );
// ...
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Quillraven wrote:so i tried to turn off the collision before calling setposition but don't know how?
You should be able to remove the collision response animator, then move the camera, update its position, then attach a new collision response animator. I'm pretty sure this worked with old versions of Irrlicht (1.4 and older).

Looking at the source on 1.5, it looks like you could just call collisionResponseAnimator->setNode(node) after setting the position of node.

Travis
Quillraven
Posts: 62
Joined: Fri Aug 22, 2008 7:22 am

Post by Quillraven »

You should be able to remove the collision response animator
here is my problem - how?!

if you have something liek this

Code: Select all

// find all meshes
	core::array<scene::ISceneNode*> nodes;
    smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes);

    for (u32 i=0; i < nodes.size(); ++i)
    {
		scene::ISceneNode* node = nodes[i];
		scene::ITriangleSelector* selector = 0;

		switch(node->getType())
		{
		case scene::ESNT_CUBE:
		case scene::ESNT_ANIMATED_MESH:
			// Because the selector won't animate with the mesh,
			// and is only being used for camera collision, we'll just use an approximate
			// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
			selector = smgr->createTriangleSelectorFromBoundingBox(node);
			break;

		case scene::ESNT_MESH:
		case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
			selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
			break;

		case scene::ESNT_TERRAIN:
			selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
			break;

		case scene::ESNT_OCT_TREE:
			selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
			break;
		default:
			// Don't create a selector for this node type
			break;
		}

		if(selector)
		{
			// Add it to the meta selector, which will take a reference to it
			meta->addTriangleSelector(selector);
			// And drop my reference to it, so that the meta selector owns it.
			selector->drop();
		}
    }
	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( meta, 
																			 camera, 
																			 core::vector3df(3,6,3), 
																			 core::vector3df(0,-0.5,0),
																			 core::vector3df( 0, 20, 0 ) );
    meta->drop(); // I'm done with the meta selector now

    camera->addAnimator(anim);
    anim->drop(); // I'm done with the animator now
how do i get the animator anim from the camera? and even if i don't drop it ... i don't think it's a good idea to do not drop these animators. in a more complex game i don't want all the animators to be undropped.

and i don't find any getCollsionResponseAnimator function. i only found the getAnimators function from the scenenodes, but how can i find out, if it is my collresponseanimator i wish to edit?


edit:

k i now drop the collanimator at the end of the programe before i call device->drop() and inside the code i use this:

Code: Select all

// if collidiing with a windparticlesystem let the player fly
if( !HasNoCollision && windup->getTransformedBoundingBox().isPointInside( camera->getAbsolutePosition() ) )
			{
				HasNoCollision = true;
				camera->removeAnimator( anim );
				anim = smgr->createCollisionResponseAnimator( meta, 
															  camera, 
															  core::vector3df(3,6,3), 
															  core::vector3df(0,50.0,0),
															  core::vector3df( 0, 20, 0 ) );
				camera->addAnimator( anim );
			}
			else if( HasNoCollision )
			{
				HasNoCollision = false;
				camera->removeAnimator( anim );
				anim = smgr->createCollisionResponseAnimator( meta, 
															  camera, 
															  core::vector3df(3,6,3), 
															  core::vector3df(0,-0.5,0),
															  core::vector3df( 0, 20, 0 ) );
				camera->addAnimator( anim );
			}






// if falling down somewhere reset player's startlocation
if( camera->getAbsolutePosition().Y <= -100 )
			{
				camera->removeAnimator( anim );
				camera->setPosition( startlocvec );
				camera->updateAbsolutePosition();
				anim = smgr->createCollisionResponseAnimator( meta, 
															  camera, 
															  core::vector3df(3,6,3), 
															  core::vector3df(0,-0.5,0),
															  core::vector3df( 0, 20, 0 ) );
				camera->addAnimator( anim );
			}

is this a good way to do it? i don't think so ?:D
Post Reply