total newbie -> move various nodes question

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
woodruff
Posts: 4
Joined: Thu Nov 20, 2003 5:38 pm
Location: vienna, austria

total newbie -> move various nodes question

Post by woodruff »

okay, i wrote a class called CObjects:

Code: Select all

class CObject
{
private:
	float m_X, m_Y, m_Z; // die position
	float m_Xspeed, m_Yspeed; // die geschwindigkeit
	IAnimatedMeshSceneNode *m_pNode;

public:
	CObject();
	void create(float x, float y, float z, IAnimatedMeshSceneNode *node);
	void accelerate(float xdelta, float ydelta); // beschleunigung
	void move();
	
};
so in main.cpp I can create various animatedmeshnodes using

Code: Select all

beep.create(10.0, 10.0, 20.0, star);
everthing works fine so far... in the keyboard handler I use

Code: Select all

beep.accelerate(-0.1,0.0);
to change the speed of the objects. but here is my problem:

In the while-loop of the game I want to use beep.move(); to update the position of the nodes. but how do I create a loop, that goes throught all nodes created on the screen an changes their position?

Code: Select all

void CObject::move()
{
	float xdelta, ydelta;
	xdelta=m_Xspeed;
	ydelta=m_Yspeed;

	m_X+=xdelta;
	m_Y+=ydelta;

	vector3df p;
	p.X = m_X;
	p.Y = m_Y;
	p.Z = m_Z;
	
	//???
	//?->setPosition(p);
}
please help!


BTW: Thanks Niko, Irrlicht is GREAT!!!
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

From your code, I'm guessing that you store the node pointer passed in from CObject.create into m_pNode.

In CObject.move:
m_pNode->setPosition(irr::vector3df(m_X,m_Y,m_Z);

Now, for you to iterate through all of your CObject's, it would be just like iterating through any other construct. What constructor type are you storing your set of CObject classes in? List? Array? stlList?

Psuedo-code:
for each CObject in CObjectList
CObject.move();
Crud, how do I do this again?
woodruff
Posts: 4
Joined: Thu Nov 20, 2003 5:38 pm
Location: vienna, austria

Post by woodruff »

thank you for your reply!

I tried m_pNode->setPosition(vector3df(m_X,m_Y,m_Z)); but with this line the programm crashes!
this is the constructor and the create memberfunction:

Code: Select all

CObject::CObject()
{
m_pNode=NULL;
}

void CObject::create(float x, float y, float z, IAnimatedMeshSceneNode *node)
{
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* sm = device->getSceneManager();

	// die position:
	m_X=x;
	m_Y=y;
	m_Z=z;
	m_pNode=node;

	// beep wird geladen:
	  node = sm->addAnimatedMeshSceneNode(sm->getMesh("media/heart.3ds"),0, 1);

	node->setMaterialTexture(0, driver->getTexture("media/test.tga"));
	node->setPosition(vector3df(m_X,m_Y,m_Z));
	node->setScale(vector3df(1,1,1));

}
what am I doing wrong?
woodruff
Posts: 4
Joined: Thu Nov 20, 2003 5:38 pm
Location: vienna, austria

Post by woodruff »

ok, I found it:

i replaced all "node" in the create function with m_pNode and now it works!

STUPID ME!
WingedWarrior
Posts: 8
Joined: Mon Nov 10, 2003 2:34 pm

Post by WingedWarrior »

Hi

You have the basic idea and Saigumi was right in his explaination about how it should be done. From your code segment above the problem is that you are assigning m_pNode before you call addAnimatedMeshSceneNode! :roll:

Try something like this...
// die position:
m_X=x;
m_Y=y;
m_Z=z;

// beep wird geladen:
node = sm->addAnimatedMeshSceneNode(...);
m_pNode=node;

Hope this helps :D
Post Reply