Jump to content


- - - - -

bullet direction * time problem


3 replies to this topic

#1 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 177 posts

Posted 18 May 2010 - 11:10 AM

I am rendering box's which are fired out in the ships direction

first i check is space pressed
[code]

if(fire)
{

//MessageBox(NULL,"Fire","",0);
VecStruct vs;
vs.Dir = rRotToDir;
vs.FPos = FinalPos;
Vs.push_back(vs);
fire = false;

}

then here loop on vector size, the trouble is each box spawns at the last distance , so i am stuck with this time thing , like how would you reset it without messing anything up, i know the problem , i need to find how much gTimeDela is incrementing so i can start each box from 0 and increment it, but i dont know how atm

for(int i = 0; i < Vs.size(); i++)
{
D3DXMatrixTranslation(&Vs[i].Pos,Vs[i].Dir.x*gTimeDelta*5.5f,
Vs[i].Dir.y*gTimeDelta*5.5f,
Vs[i].Dir.z*gTimeDelta*5.5f);
d3ddev->SetTransform(D3DTS_WORLD,&Vs[i].Pos);
Box->DrawSubset(0);
}

heres a video of what i mean



#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 18 May 2010 - 04:34 PM

Make a struct for your particle that contains a position and velocity. When a particle is fired, initialize its position to position of the ship's guns. Every frame, loop over the particles and update their positions, by adding their velocity multiplied by the time taken to render the last frame.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 177 posts

Posted 18 May 2010 - 06:37 PM

ive got that sorted now what i want next is a ray to move with the bullet in the pushed back drection but when i fire say in the oposite direction it says intersected , do you know why?

the bullet is intersecting with the wall no matter which rotation i fire from....

short video
http://www.youtube.com/watch?v=w4bzjo_2OE4

D3DXVECTOR3 ObjPos,NormDir;
	D3DXMATRIX matWorld;
	d3ddev->GetTransform(D3DTS_WORLD,&matWorld);

	for(int i = 0; i < Vs.size(); i++)
	{
		D3DXMatrixTranslation(&Vs[i].Pos,Vs[i].Dir.x*(gTimeDelta-Vs[i].BulletTime)*5.0f,
			                             Vs[i].Dir.y*(gTimeDelta-Vs[i].BulletTime)*5.0f,
										 Vs[i].Dir.z*(gTimeDelta-Vs[i].BulletTime)*5.0f);
		d3ddev->SetTransform(D3DTS_WORLD,&Vs[i].Pos);
		D3DXVECTOR3 BPos(Vs[i].Pos._41,Vs[i].Pos._42,Vs[i].Pos._43);
		//Vs[i].Pos._43 = -5.0f;
		//MadeEffect->Begin(NULL, NULL);    // begin using the effect
		//MadeEffect->BeginPass(0);    // begin the pass
		//MadeEffect->SetMatrix("World",&Vs[i].Pos);
		Box->DrawSubset(0);
		//gotta convert the ray to objectspace same space as the wall
		D3DXVec3TransformCoord(&ObjPos,&BPos,D3DXMatrixInverse(NULL,NULL,&(matWorld * matView))); // to object space
		D3DXVec3TransformNormal(&NormDir,&Vs[i].Dir,D3DXMatrixInverse(NULL,NULL,&(matWorld * matView))); // to object space
		D3DXVec3Normalize(&NormDir,&NormDir);

		D3DXIntersect(Wall,&BPos,&NormDir,&Hit,&Face,NULL,NULL,&Dist,NULL,0);
		if(Hit)
	{
		d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);
		d3ddev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	}
	else
	{
		d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);
		d3ddev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		Face = 0;
		Hit = false;
	}



#4 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 177 posts

Posted 19 May 2010 - 05:30 PM

Got it working






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users