Node not changing position with setPosition()

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
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Node not changing position with setPosition()

Post by Anteater »

Hi. I'm having a problem with setPosition() in Irrlicht 1.4. I have an animated mesh scene node, loaded from an .md3 file.

Code: Select all

IAnimatedMesh* mainCharMesh;
	IAnimatedMeshSceneNode* mainChar;
        mainCharMesh = smgr->getMesh("data/mainchar.md3");
	mainChar =  smgr->addAnimatedMeshSceneNode(mainCharMesh,NULL,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),false);
		mainChar->setMaterialTexture(0,driver->getTexture("data/mainChar.bmp"));
Now I want to move it:

Code: Select all

mainChar->setPosition(mainChar->getAbsolutePosition()+vector3df(-90*delta,0,0));
		
The problem is, it doesn't move. At all. I've tried setting the position to an absolute value (i.e. setPosition(vector3df(0,10,20));) but that didn't work either. What am I doing wrong?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Eurgh, I dunno. I can't see anything wrong with the code that you've posted, so perhaps it's in the code that you haven't posted. Do you want to do it one line at a time, or just dump it all on us and get a solution in 5 minutes?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

The code is really bad, but not unreadable. This is all the code that has anything to do with gameplay.

Code: Select all

#pragma once
#include "frame.h"

class Game :
	public Frame
{
public:
	Game(void);
	SIrrlichtCreationParameters params;
	IrrlichtDevice* engine;
	ISceneManager* smgr;
	IVideoDriver* driver;
	IGUIEnvironment* guienv;
	ITexture* renderTexture;
	IGUIInOutFader* fader;
	ICameraSceneNode* cam;
	ISoundEngine* sound;
	IGUIFont* font;
	IGUIFont* fontSpecial;
	IGUIFont* fontDebug;
	stringw debugString;
	int control;
	float delta;
	bool intro(float time, int numberOfFrames);
	bool run(void);
	int getControlVar(void);
	int getDelta(void);
	int setControlVar(int val);
	struct sceneStandard
	{
		IMesh* baseMesh;
		ISceneNode* base;
		ILightSceneNode* light[8];
		ISceneNode* inter[64];
		ISceneNode* enemy[1024];
		ISceneNode* item[256];

	};
	
	IAnimatedMesh* mainCharMesh;
	IAnimatedMeshSceneNode* mainChar;
	float mainCharFriction;
	float mainCharSpeed;
	
	sceneStandard setUpScene(IAnimatedMesh* m);
	ISceneNode* addItem(vector3df pos, int type);
	bool getState();
	bool renderBg();
	virtual bool OnEvent(const SEvent& event);
	bool keys[KEY_KEY_CODES_COUNT];
	~Game(void);

private:
	float then;
	float now;
};

Code: Select all

#include "Game.h"
#include "ItemTypes.h"
Game::Game(void)
{

	params.AntiAlias = true;
	params.Bits = 32;
	params.DriverType = EDT_OPENGL;
	params.EventReceiver = this;
	params.Fullscreen = false;
	params.HighPrecisionFPU = true;
	params.Stencilbuffer = true;
	params.Vsync = true;
	params.WindowId = 0;
	params.WindowSize = dimension2d<s32>(1024,768);
	
	engine = createDeviceEx(params);
	engine->setWindowCaption(L"Steel Eden Engine");
	sound = createIrrKlangDevice();
	smgr = engine->getSceneManager();
	driver = engine->getVideoDriver();
	guienv = engine->getGUIEnvironment();
	renderTexture = driver->createRenderTargetTexture(dimension2d<s32>(640,480),"renderTexture");
	fader = guienv->addInOutFader(&rect<s32>(0,0,1024,768), NULL, -1);
	cam = smgr->addCameraSceneNode(NULL, vector3df(0,0,100),vector3df(0,0,0),-1);
	/*if(!engine->getFileSystem()->addZipFileArchive("pakfiles.pk3", false ,false))
	{
		MessageBox(NULL, "Pak3 file not implemented. Please bash head into OK button to continue.","Josh screwed up.",NULL);
		engine->closeDevice();
	}*/
	for (int x=0;x<KEY_KEY_CODES_COUNT;x++)
	{
		keys[x]=false;
	}
	font = guienv->getFont("fonts/font2.xml");
	fontSpecial = guienv->getFont("fonts/font1.xml");
	fontDebug = guienv->getBuiltInFont();

	
	control = 0;
	
}
bool Game::intro(float time, int numberOfFrames)
{
	
	engine->setWindowCaption(IT_GAME_NAME);
	ISceneNode* cube = smgr->addCubeSceneNode(50,NULL,1);
	array<ITexture*> textures;
	
	for(int j = 0; j < numberOfFrames; j++)
	{
		char i[256];
		sprintf(i,"intro/intro%04d.jpg",j);
		textures.push_back(driver->getTexture(i));
	}
	ISceneNodeAnimator* tanim = smgr->createTextureAnimator(textures,time,false);
	ISceneNodeAnimator* remove = smgr->createDeleteAnimator(time * numberOfFrames);
	cube->setMaterialFlag(EMF_LIGHTING, false);
	cube->addAnimator(tanim);
	cube->addAnimator(remove);
	tanim->drop();
	remove->drop();
	textures.clear();

	//cube->remove();
	return true;
}

int Game::getControlVar()
{
	return control;
}
int Game::getDelta()
{
	return delta;
}
int Game::setControlVar(int val)
{
	control = val;
	return control;
}

Game::sceneStandard Game::setUpScene(irr::scene::IAnimatedMesh *m)
{
	if(!m)
	{
		MessageBox(NULL, "Level not implemented. Please bash head into OK button to continue.","Josh screwed up.",NULL);
		engine->closeDevice();
	}
	cam->setPosition(vector3df(0,333,666));
	cam->updateAbsolutePosition();
	sceneStandard scene1;
	scene1.baseMesh = m;
	scene1.base = smgr->addAnimatedMeshSceneNode(m);
	scene1.base->setRotation(vector3df(0,180,0));
	scene1.light[0] = smgr->addLightSceneNode(NULL,vector3df(0,1024,0),SColor(255,255,255,255),65525,-1);
	return scene1;
}
bool Game::getState()
{
	if(control == 0 && !smgr->getSceneNodeFromId(1))
	{
		sceneStandard scene = setUpScene(smgr->getMesh("data/scene1.x"));
		
		mainCharMesh = smgr->getMesh("data/mainchar.md3");
		mainChar = smgr->addAnimatedMeshSceneNode(mainCharMesh,NULL,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),false);
		mainChar->setMaterialTexture(0,driver->getTexture("data/mainChar.bmp"));
		mainCharFriction = 0.1;
		mainCharSpeed = 90;
		if(!mainChar)
		{
			MessageBox(NULL, "Character not implemented. Please bash head into OK button to continue.","Josh screwed up.",NULL);
			engine->closeDevice();
		}
		fader->fadeIn(1000);
		control = 1;
	}
	if(control >= 1)
	{
	}
	if(keys[KEY_ESCAPE])
	{
		engine->closeDevice();
	}
	if(keys[KEY_KEY_A])
	{
		mainChar->setPosition(mainChar->getAbsolutePosition()+vector3df(-mainCharSpeed*delta,0,0));
		
	}
	if(keys[KEY_KEY_D])
	{
		mainChar->setPosition(mainChar->getAbsolutePosition()+vector3df(mainCharSpeed*delta,0,0));
		
	}
	if(keys[KEY_KEY_W])
	{
		mainChar->setPosition(mainChar->getAbsolutePosition()+vector3df(0,0,-mainCharSpeed*delta));
		
	}
	if(keys[KEY_KEY_S])
	{
		mainChar->setPosition(mainChar->getAbsolutePosition()+vector3df(0,0,mainCharSpeed*delta));
		
	}

	
	
	
	return true;
}
bool Game::renderBg()
{
	driver->draw2DImage(driver->getTexture("data/bg.bmp"),position2d<s32>(0,0));
	
	return true;
}

ISceneNode* Game::addItem(vector3df pos, int type)
{
	IAnimatedMesh* mesh;
	rect<s32> itemRect;
	switch(type)
	{
	case 0:
		MessageBox(NULL, "Item not implemented. Please bash head into OK button to continue.","Josh screwed up.",NULL);
		break;
	case 256:
		mesh = smgr->getMesh("data/item1.obj");
		if(!mesh)
		{
			MessageBox(NULL, "Mesh not implemented. Please bash head into OK button to continue.","Josh screwed up.",NULL);
			engine->closeDevice();
		}
	
		break;
	}
	IAnimatedMeshSceneNode* item = smgr->addAnimatedMeshSceneNode(mesh, NULL, type,pos);
	return item;
}
bool Game::run()
{
	while(engine->run())
	{
		then = engine->getTimer()->getTime();
		driver->beginScene(true,true,SColor(0,0,0,0));
		getState();
		renderBg();
		smgr->drawAll();
		guienv->drawAll();
		
		debugString = "";
		debugString += "Mouse: "; 
		debugString += engine->getCursorControl()->getPosition().X;
		debugString += ", ";
		debugString += engine->getCursorControl()->getPosition().Y;

		fontDebug->draw(debugString.c_str(),rect<s32>(0,0,640,480),SColor(255,255,255,255),false,false,0);
		driver->endScene();
		engine->getTimer()->tick();
		now = engine->getTimer()->getTime();
		delta = now - then;
		
	}
	return false;
}
bool Game::OnEvent(const SEvent& event)
{
	if(event.EventType == EET_KEY_INPUT_EVENT)
	{
		
		
		
		keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
		return true;
		
	}
	
	return false;
	
}
Game::~Game(void)
{
	engine->drop();
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

md3 meshes are not transformable. There's a bug in the implementation somewhere, but there's currently no one working on fixing it (basically because the node uses some strange non-irrlicht like way of working with some internal positioning stuff).
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

Oh.
Post Reply