getSceneNodeFromRayBB

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
jsmurthy4
Posts: 18
Joined: Mon Sep 10, 2007 4:04 pm

getSceneNodeFromRayBB

Post by jsmurthy4 »

Hi friends,

In my game i am using 3 getSceneNodeFromRayBB
1) from camera projectile to what i point(RED color)
2)&3) from enemy to camera(green and blue color)
below image u can see it.

when i start it works fine for all 3 getSceneNodeFromRayBB but when i come closer to enemy's they don't shoot i mean they getSceneNodeFromRayBB returns 0, camera works fine the below image u can see all three colors where camera works, enemy's return's 0
i try to move diff positions when i am close they don't shoot if i again go back it works fine they will shoot.

[img]

http://mur_games.googlegroups.com/web/raybb.jpg?gda=YoL9UjoAAAAYX6oU0cKgFz_wdT-NSh-pbkCaA-59EVr7d9Qagc6P6GG1qiJ7UbTIup-M2XPURDQIyxPbQtd0z0b05LmKITSx&gsc=qFlYkwsAAAA685YMqY-SGgX0QBfsotsu

[/img]

my code

Code: Select all

      f32 z=killer->getPosition().Z;
		f32 x=killer->getPosition().X;
		line.start=killer->getPosition();
		line.start.Y=50;
		line.end=camera->getPosition();
		scene::ISceneNode *kil=smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(line,32);
		if(kil)
		{
			if(kil->getID()==32)
			{
				fire=true;
				t1->fire=true;
			}
			 else
				 t1->fire=false;
		}
camera id =32,in a loop i pass both the enemy node to killer node.

starting of the program it works fine as camera is distance when i move closer it won't shoot it returns 0(kil=0) if i again go back they will fire.

:?: is there any wrong in my coding?

help me :shock:
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'm a little confused here.

1) If the rays shown in the image end at the camera's position, how are they visible? Axiomatically, any ray projected to or from the camera's position won't be visible.

2) You're passing a bitmask of 32 (1<<5) to getSceneNodeFromRayBB(), and then checking the returned node's ID. If you've got your bitmasking right, then that second check shouldn't be necessary.

Can you post more source please, ideally a fully compilable example.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
jsmurthy4
Posts: 18
Joined: Mon Sep 10, 2007 4:04 pm

Post by jsmurthy4 »

thanks roger,
1)i am using 2 camera's, but only one camera is targeting

2)yes u are right there is no need to check 2 time but it is not wrong to check 2 times.when i am debuging i just wrote it.

main while loop

Code: Select all

while(device->run() && driver)
	{
//main update fn
myupdate::update(); // funtion enemy  position and fire		
driver->beginScene(true,true,0);
		smgr->drawAll();

		//below camera fireand checking enemy

		line.start=pointer->getAbsolutePosition();
		line.end = line.start-(camera->getTarget() - line.start).normalize()*800.0f ;
		scene::ISceneNode *chk=smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(line,8);
		
		core::stringw str="Camera-X=";

//rp->lm is for mouse ckick 
	
		if((chk)&&(rp->lm==1))
		 {
			if((chk->getID()& 8)==8)
			{
			if (smgr->getSceneCollisionManager()->getCollisionPoint(line,killselector,intersection,tri))
			{
				
// for blood particals 	
			scene::IParticleSystemSceneNode *ps=smgr->addParticleSystemSceneNode(false,0,-1,intersection);
				ps->setParticleSize(core::dimension2d<f32>(20.0f,20.0f));
				scene::IParticleEmitter *em=ps->createBoxEmitter(core::aabbox3d<f32>(-5,-5,-5,5,5,5),core::vector3df(0.01f,0.01f,0.01f),
					100,120,video::SColor(0,255,255,255),video::SColor(0,255,255,255),800,1000,20);
				ps->setEmitter(em);
				em->drop();
				scene::IParticleAffector *paf=ps->createGravityAffector(core::vector3df(0.0f,-0.01f,0.0f),1000);
				ps->addAffector(paf);
				paf->drop();
				ps->setMaterialFlag(video::EMF_LIGHTING, false);
				ps->setMaterialTexture(0, hitimg);
				ps->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);   
				scene::ISceneNodeAnimator *anim=smgr->createDeleteAnimator(1000);
				ps->addAnimator(anim);
				anim->drop();	   
				} 
			}
		}	
		rp->lm=0;

//below is for the line drawing only
		
		driver->setTransform(video::ETS_WORLD, core::matrix4());
		driver->setMaterial(lineMaterial);	
		driver->draw3DLine(line.start,line.end,video::SColor(0, 255,0,0));
		
	line.start=killer[0]->getPosition();
		line.end=camera->getPosition();line.start.Y=40;
		driver->draw3DLine(line.start,line.end,video::SColor(0, 0,0,255)); 
		line.start=killer[1]->getPosition();line.start.Y=40;
		line.end=camera->getPosition();
		driver->draw3DLine(line.start,line.end,video::SColor(0, 0,255,0));
	
		driver->endScene();
	}
	 driver->drop();
	 return 0;

}
funtion of update
i put all the enemys data in single linked list (datastructure ex:struct node t1) only data.

Code: Select all

void myupdate::update()
{	
	tick *t1;
	t1=st;   //st holds 1st address of linked list	
f32 a=0,b=0;
	bool fire=false;
	core::line3d<f32> geta;
	while(t1!=NULL)
	{
		scene::IAnimatedMeshSceneNode *man;
		u8 in=(t1->id-8);

		man=killer[in]; [b] //killer[] is enemys nodes[/b]
		f32 z=man->getPosition().Z;
		f32 x=man->getPosition().X;
		geta.start=man->getPosition();
		geta.start.Y=50;
		geta.end=camera->getPosition();

////////////////kil returns 32 when i am back 0 when i am front////////

		scene::ISceneNode *kil=smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(geta,32);
		if(kil)
		{
			if(kil->getID()==32)
			{
				fire=true;
				t1->fire=true;
			}
			 else
				 t1->fire=false;
		}

/////////////////////////

		if((t1->j==0)&&(t1->k==0))
		{
			f32 y;
			u8 pos=rp->postion(man->getPosition());
			s8 campos=rp->postion(camera->getPosition());
			s8 tgt=t[pos][campos];	
			tick *t2=st;


			while(t2!=NULL)
			{
//2 enemy's will not stand at same place 
				if(((t2->tgt==-1)&&(tgt==t2->pos))||(t2->tgt==tgt))
				{
					tgt=-1;
					break;
				}
				t2=t2->next;
			}
			t1->pos=pos;
			t1->tgt=tgt;
			t1->j=1;
			t1->k=1;

[//below code is to just move enemy to the camera x-axis and z-axis
//to find the exact where the camera and rotatation deg

			if(tgt!=-1)
			{ 
			a=(ax[tgt]-x);
			b=(az[tgt]-z);
			if((az[tgt]!=(int)z)&&(ax[tgt]!=(int)x))
				y=(atan2(a,b)*(180/(float)3.14159265));
			else if	(ax[tgt]==(int)x)
			{
				if(az[tgt]>z)
					y=0;
				else
					y=180;
			}
			else if(ax[tgt]>x)
				y=90;
			else
				y=-90;
			t1->y=y;
			}
		}
		s16 tgt=t1->tgt;
		a=abs(ax[tgt]-x);
		b=abs(az[tgt]-z);

//moves x-axis and z-axis closer to camera

		if((i==4)&&(tgt!=-1))
		{
			if(stpt>20)
				stpt=0;
			else
				stpt+=(f32).4;	
			if((t1->j!=0)&&(b>=a))
			{
			if(az[tgt]==(int)z)
				t1->j=0;
			else if(az[tgt]>man->getPosition().Z)
				z+=(f32)1.0;
			else 
				z-=(f32)1.0;
			b=b-t1->j;
			}
			
			if((t1->k!=0)&&(a>=b))
			{
			if(ax[tgt]==(int)x)
				t1->k=0;
			else if(ax[tgt]>man->getPosition().X)
				x+=(f32)1.0;
			else 
				x-=(f32)1.0;
			a=a-t1->k;
			}
			
						
			man->setPosition(core::vector3df(x,5,z));
			man->setCurrentFrame(stpt);
			man->setRotation(core::vector3df(0,t1->y,0)); 
			
		}
		else
		{
			t1->j=0;
			t1->k=0;
		}
		t1=t1->next;
	}

//here the enemy fire 

	if(fire==true)
		rp->fire(8);
}  
i hope it will help u

main point
only if i press key-6(i==4) the enemy will start following camera and shoot. until i press key-6 they will not move
this for my convenience i wrote

if enemy is not moving problem appears.
if enemy moves there is no problem most of the time.

but my point is when i am back getSceneNodeFromRayBB(kil=32) returns 32 if i move front it returns 0(when enemy is not move)

in game enemy will move so i think they will be no problem.but still why i get this problem i didn't understand?
its difficult to understand my code and respond i just paste some imp code only i think i will help u

thanks once again for helping me
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Apart from the curious idioms ( u8 in=(t1->id-8); ) your method looks fundamentally fine.

Two things spring to mind:

1) How big is your 'camera' (the one you're testing against) scene node's bounding box?

2) If you're tracing a ray to the centre of a known node, and the ray doesn't intersect any other node (i.e. getSceneNodeFromRayBB() returns 0) then you're probably safe to assume that the ray did reach (or should have reached) the target node, i.e. your killer can 'see' the target node.

I can't think of anything else offhand, and would have to actually debug the behaviour.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply