• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualAnddos

Posted 17 August 2013 - 01:55 PM

Ok i am getting stuck with the maths on how to make a box move left to right over and over none stop , i understand you change the position by the velocity but i dont understand how to get the if conditions right so it actually moves none stop,here is what i have

bool hitleft = false;
bool hitright = false;
if(hitleft == false)
{
velocity = 0.01f;
Pos.x = Pos.x + velocity;

if(Pos.x == 2.0f)
{
hitleft = true;
}
}
if(hitright == false)
{
velocity = -0.01f;
Pos.x = Pos.x + velocity;
if(Pos.x == -2.0f)
{
hitright = true;
}
}

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

d3ddev->BeginScene(); D3DXMatrixTranslation(&matTrans,Pos.x+velocity,Pos.y,Pos.z);

d3ddev->SetTransform(D3DTS_WORLD, &(matTrans));

box->DrawSubset(0); d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

### #2Anddos

Posted 17 August 2013 - 01:54 PM

Ok i am getting stuck with the maths on how to make a box move left to right over and over none stop , i understand you change the position by the velocity but i dont understand how to get the if conditions right so it actually moves none stop,here is what i have

bool hitleft = false;
bool hitright = false;
if(hitleft == false)
{
velocity = 0.01f;
Pos.x = Pos.x + velocity;

if(Pos.x == 2.0f)
{
hitleft = true;
}
}
if(hitright == false)
{
velocity = -0.01f;
Pos.x = Pos.x + velocity;
if(Pos.x == -2.0f)
{
hitright = true;
}
}

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->BeginScene(); D3DXMatrixTranslation(&matTrans,Pos.x+velocity,Pos.y,Pos.z); d3ddev->SetTransform(D3DTS_WORLD, &(matTrans)); box->DrawSubset(0); d3ddev->EndScene();  d3ddev->Present(NULL, NULL, NULL, NULL);

### #1Anddos

Posted 17 August 2013 - 01:40 PM

Ok i am getting stuck with the maths on how to make a box move left to right over and over none stop , i understand you change the position by the velocity but i dont understand how to get the if conditions right so it actually moves none stop,here is what i have

static float velocity = 0.0f;

if(Pos.x <= 1.0f)
{
velocity = 0.01f;
Pos.x = Pos.x + velocity;
}

if(Pos.x == 1.0f)
{
velocity = -0.01f;
Pos.x = Pos.x + velocity;
}

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->BeginScene();
D3DXMatrixTranslation(&matTrans,Pos.x+velocity,Pos.y,Pos.z);
d3ddev->SetTransform(D3DTS_WORLD, &(matTrans));
box->DrawSubset(0);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);


PARTNERS