2
« on: February 27, 2009, 02:20:38 am »
Of course! And thank you for the fast reply.
I'm using WinXp Sp3 32 Bit and no fancy keyboard or mouse.
This is my main loop:
while(Win->IsOpened())
{
while(Win->GetEvent(*Ereignis))
{
if(Ereignis->Type == Event::Closed)
{
Win->Close();
}
if((Ereignis->Type == Event::KeyPressed) && (Ereignis->Key.Code == Key::Escape))
{
Win->Close();
}
if((Ereignis->Type == Event::KeyPressed) && (Ereignis->Key.Code == Key::C))
{
Feld.Neu();
}
if((Ereignis->Type == Event::KeyPressed) && (Ereignis->Key.Code == Key::D))
{
DichteAusgabe = !DichteAusgabe;
}
if((Ereignis->Type == Event::KeyPressed) && (Ereignis->Key.Code == Key::V))
{
GeschwAusgabe = !GeschwAusgabe;
}
}
Ausfuehrzeit += Win->GetFrameTime();
while(Ausfuehrzeit > dt)
{
//eingabe
//physik
Manager->Update(); //THIS IS IMPORTANT!!!
Ausfuehrzeit -= dt;
}
//grafik
Render->BeginneMalen();
if(GeschwAusgabe)
{
Manager->MaleGeschw();
}
if(DichteAusgabe)
{
Manager->MaleDichte();
}
Render->StoppeMalen();
}
The if-statement in the main loop is for a constant time step. Manager->Update(); This is where all the calculations and the input are handled. All it does is reset some values each frame then it takes care of the input and then it does the calculations. The function for the input which is shown below is called directly here.
mx = Eingabe->MausX();
my = Render->GetHoehe() - Eingabe->MausY();
if(!Win->GetInput().IsMouseButtonDown(sf::Mouse::Left) && !Win->GetInput().IsMouseButtonDown(sf::Mouse::Right))
{
mx0 = mx;
my0 = my;
return false;
}
i = (int)((Eingabe->MausX() / (skalar)Render->GetBreite()) * Feld.N + 1);
j = (int)((((skalar)Render->GetHoehe() - Eingabe->MausY()) / (skalar)Render->GetHoehe()) * Feld.N + 1);
if(i < 1 || i > (signed)Feld.N || j < 1 || j > (signed)Feld.N)
{
mx0 = mx;
my0 = my;
return false;
}
if(Win->GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
Feld.u[Feld.IX(i, j)] = MAUSKRAFT * (mx-mx0);
Feld.v[Feld.IX(i, j)] = MAUSKRAFT * (my-my0);
}
if(Win->GetInput().IsMouseButtonDown(sf::Mouse::Right))
{
Feld.roh[Feld.IX(i, j)] = DICHTESTAERKE;
}
if(Win->GetInput().IsKeyDown(sf::Key::Left)) //HERE IS THE PROBLEM
{
Feld.roh[Feld.IX(i, j)] = -DICHTESTAERKE;
}
mx0 = mx;
my0 = my;
return true;
}
The input through events in the main loop works.
If it helps I can translate the names into English.