Coordinate confusion, and removing scene nodes

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
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Coordinate confusion, and removing scene nodes

Post by fretnoize »

I am making an asteroids clone to get familiar with using the engine. I have coordinate boundries for each object class in my game that teleport objects from one side of the screen to the other, simulating the original game when objects move off the screen. The player's ship moves around fine, and so do my asteroids. my problem is with the bullets that the player can fire. I have them fire from the player's ship just fine, meaning the fire from the player's ship, and move in the right direction, but they teleport around as if player's ship's position was thought to be (0,0,0), rather than 0,0,0 being in the middle of the screen. So enough back ground. here comes the code, the constructor i use and the move function:

Code: Select all

	Bullet(scene::ISceneManager* smgr, video::IVideoDriver* driver, core::vector3df playerLoc, core::vector3df playerRot)
	{
		
		
		moverate = 5;
		life = 200;
		node = smgr->addLightSceneNode(0, playerLoc, video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
		//node->setParent(node);
		//scene::ISceneNodeAnimator* anim = 0;
		//anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),250.0f);
		//node->addAnimator(anim);
		//anim->drop();

		// attach billboard to light

		node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(25, 25));
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
		node->setMaterialTexture(0,	driver->getTexture("../media/textures/bullet.bmp"));
		movement.Y = (cos(deg2rad(playerRot.X))* moverate);
		movement.Z = (sin(deg2rad(playerRot.X))* moverate); 
	

	}
	virtual bool Move(MyEventReceiver receiver)
	{
		
		
		life--;
		
		core::vector3df v = node->getPosition(); 
		v.Y += movement.Y;
		v.Z += movement.Z;
		if (abs(v.Y) > 150)
		v.Y > 150 ? v.Y = -150 : v.Y = 150;
		if (abs(v.Z) > 200)
		v.Z > 200 ? v.Z = -200 : v.Z = 200;

		

		node->setPosition(v);
		if(life == 0)
		{
			node->remove();
			delete this;
			return false;
		}
		else
			return true;

	}
you can see that i make my bullets based on the special FX tutorial, but i commented out the animation lines. playerLoc is the result of node->getPosition() on the player object, and playerRot is the rotation. So i'd like to know how to get my bullets to wrap around the real coordinates.

My second questionis if i am removing these bullet objects the correct way. if you notice, they have a life of 200 frames. then I get rid of them. However, I don't have any limits yet as to how many i can fire. So goofing around I shoot a whole bunch and it drops the frame rate a lot if i shoot enough. But i would expect the framerate to come back up after all the bullets cleared themselves up, but it stays low. So I'm wondering if I'm getting rid of them correctly.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

you're deleting the billboard correctly, but you forgot that you're also creating a light.

so while you are getting rid of all the billboards, you've got an infinite amount of lights that are still hanging around. instead of storing the light in node, and then putting the billboard over it, you should have a pointer just for the light so you can remove it too.

or even better, make the light a child of the billboard node, so it moves with it automatically.
a screen cap is worth 0x100000 DWORDS
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Post by fretnoize »

hmmm i thought the light was already attached in the f/x tutorial... would be easier to test if my asteroids were actually taking light.... i made them in maya, not sure why they won't light.

any thoughts about the teleporting offset i'm experiencing?
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

The offset may be due to the creation of your object in maya. I do not know too much about Maya but in Studio Max the corrinates where you created the object are saved and when the object is loaded, it is loaded at those corrdinates not (0,0,0).

Don't know if that is your problem but maybe it helps 8)
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Post by fretnoize »

well my maya objects teleport fine (they're made at 0,0,0 anyway), its the bullets that don't, and those are just a billboard. my asteroids which i made in maya, how ever, don't seem to take light, although the player's ship does, which was also made in maya(its just a cone primative at the moment
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

To make your astroids take light change this line

node->setMaterialFlag(video::EMF_LIGHTING, false);

to

node->setMaterialFlag(video::EMF_LIGHTING, true);
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Post by fretnoize »

yeah i have that.... they don't show.... i'm trying to figure out what the ship lights but not the asteroids....
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Post by fretnoize »

ok it seems that everything i make in maya now does not take light... seeing how i'm only a beginer in maya, i'm going to assume i screwed up some setting when i was messing around with maping UVs and such...

i'll have to reset my settings some how...
fretnoize
Posts: 43
Joined: Sun Feb 01, 2004 4:57 am
Location: Los Angeles

Post by fretnoize »

Okay, well reseting back to defaults in maya sure helped. can see things now. so that problem is solved for now. Still baffled about the teleportation offset.
Post Reply