Changing Projectile Exit Angle in TechDemo Code

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
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Changing Projectile Exit Angle in TechDemo Code

Post by Robomaniac »

I'm trying to implement a shotgun code template using the techdemo shooting function, and i was wondering how i would change the position of end. I want to do this in order to create gradually spreading shots. Thanks in advance.

--The Robomanaic
:twisted: :twisted: :shock:

{edit} -- I figured it out, i found the setLine function. If anyone wants me to post the code, just reply
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

Well :D ofcource!
Thanks in advance
Visit my website @ www.venex.be
Plethora project will be added to the site
AMD AthlonXP 2600+, 512MB DDR, Radeon M10 (mobile 9600) PRO 64MB, WinXP
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Well, heres the whole code for the function, mostly lifted straight from the Tech Demo (actually, all of it but maybe 3 lines). It basically adds a certain amount to end and make lines from that.

Code: Select all

void CGameClass::shootShotgun()
{	
   if (device)
   {
      smgr = device->getSceneManager();
      camera = smgr->getActiveCamera();
   }
   else
   {
      printf("device null");
      //=wait();
      exit(1);
   }
   

	if (!camera)
		return;

	SParticleImpact imp; 
	imp.when = 0;

	// get line of camera

	core::vector3df start = camera->getPosition();
	core::vector3df end = (camera->getTarget() - start);
	end.normalize();
	
	end = start + (end * camera->getFarValue());

	core::triangle3df triangle;
	
	core::line3d<f32> line[4];
 
   line[0].setLine(start, end + core::vector3df(200, 100, 0));
   line[1].setLine(start, end + core::vector3df(100, -50, 0));
   line[2].setLine(start, end + core::vector3df(0, 0, 0));
   line[3].setLine(start, end + core::vector3df(-100, -50, 0));
   line[4].setLine(start, end + core::vector3df(-200, 130, 0));



   for (int i = 0; i < 5; i++)
	{
	// get intersection point with map

	if (smgr->getSceneCollisionManager()->getCollisionPoint(
		line[i], selector, end, triangle))
	{
		// collides with wall
		core::vector3df out = triangle.getNormal();
		out.setLength(0.03f);

		imp.when = 1;
		imp.outVector = out;
		imp.pos = end;
	}
	else
	{
		// doesnt collide with wall
		end = (camera->getTarget() - start);
		end.normalize();
		end = start + (end * 1000);
	}
	// create fire ball
	scene::ISceneNode* node[4];

	node[i] = smgr->addBillboardSceneNode(0,
		core::dimension2d<f32>(25,25), start);

	node[i]->setMaterialFlag(video::EMF_LIGHTING, false);
	node[i]->setMaterialTexture(0, device->getVideoDriver()->getTexture("Data/Images/fireball.jpg"));
	node[i]->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
   
		
	f32 length = (f32)(end - start).getLength();
	const f32 speed = 2.0f;
	u32 time = (u32)(length / speed);

	scene::ISceneNodeAnimator* anim = 0;

	// set flight line

	anim = smgr->createFlyStraightAnimator(start, end, time);
	node[i]->addAnimator(anim);	
	anim->drop();

	anim = smgr->createDeleteAnimator(time);
	node[i]->addAnimator(anim);
	anim->drop();
   }
   
	/*if (imp.when)
	{
		// create impact note
		imp.when = device->getTimer()->getTime() + (time - 100);
		Impacts.push_back(imp);
	}*/
}
--The Robomaniac
Post Reply