Autor Beitrag
florian
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

Win XP Home
D5 Enterprise
BeitragVerfasst: Do 14.08.03 16:36 
Hallo erstmal.
ich habe folgendes problem:
ich versuche ein autorennen mit Delphi und OpenGL zu programmieren.
für die Bewegung habe ich bisher folgenden code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
if Keys[VK_LEFT] then begin
    yrot:=yrot - 0.5;
    if yrot<0 then
      yrot:=yrot + 360;
  end;
  if Keys[VK_RIGHT] then begin
    yrot:=yrot + 0.5;
    if yrot>360 then
      yrot:=yrot - 360;
  end;

  If Keys[VK_UP] then
  begin
       PlayerPos.X:=PlayerPos.X + Sin(-yrot * (PI / 180)) * (0.1);
   PlayerPos.Z:=PlayerPos.Z + Cos(-yrot * (PI / 180)) * (0.1);
  end;
  If Keys[VK_DOWN] then
  begin

   PlayerPos.X:=PlayerPos.X - sin(-yrot * (PI / 180)) * (0.1);
   PlayerPos.Z:=PlayerPos.Z - cos(-yrot * (PI / 180)) * (0.1);
  end;


1. allerdings fährt man, wenn man rückwärts fährt genau seitenverkehrt, d.h. wenn ich nach hinten und rechts lenke, fahre ich nach hinten links. wie kann ich das umkehren???? :?:

2. wie kann ich eine beschleunigung realisieren, dass das auto nach einer weile schneller wird??

danke im voraus

ciao
florian


Zuletzt bearbeitet von florian am Sa 16.08.03 11:07, insgesamt 1-mal bearbeitet
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Do 14.08.03 16:54 
Hi,

zu 1) Einfach dort wo du yrot:=yrot + 0.5; machst überprüfen ob man vorwärts oder rückwärts fährt und jenachdem + 0,5 bzw - 0,5 rechnen.

zu 2) Mit ner e-funktion sollte das machbar sein, aber am besten schau einfach mal in ne Physik-Formelsammlung wie man beschleunigung berechnet.

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
madbrain
Hält's aus hier
Beiträge: 6

Win 2000
Delphie 7 Enterprise
BeitragVerfasst: Do 14.08.03 18:05 
@aya:
mit ner e-funktion?
du meinst "e hoch x" ?

das ergebe doch aber eine etwas unrealistische beschleunigung, oder?
bei kleinen x (angenommen x ist die geschwindigleit) wäre die beschleunigung viel kleiner als bei grossen x.
Normalerweise nimmt die beschleunigung eines Fahrzeugs aber mit der grösse der geschwindigkeit ab :D

ich würde mal a = v / t vorschlagen mit a = beschleunigung; v = geschwindigkeit; t = zeit.

ich geh mal davon aus, dass du die momentane geschwindigkeit als v speicherst. du brauchst also pro auto eine kleine tabelle, womit du die beschleunigung berechnen kannst. daraus kannst du dann wiederum die neue geschwindigkeit berechnen.
für die tabelle würd ich ne wurzelfunktion vorschlagen ( a = wurzel(v)).

wär cool, wenn ich das fertige (oder auch halbfertige) spiel mal sehen könnte. will auch mal sowas in der art machen und brauche inspiration :lol:
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Do 14.08.03 18:34 
Hi,
madbrain hat folgendes geschrieben:
@aya:
mit ner e-funktion?
du meinst "e hoch x" ?

das ergebe doch aber eine etwas unrealistische beschleunigung, oder?

Er frage nicht nach etwas realistischem *g* und mit ner e-Funktion wird das Auto nach ner Zeit immer shcneller *grinst frech*
Ich hab ihm doch auch den hinweis gegeben mal nach der Formel für die Beschleunigung zu gucken.

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Do 14.08.03 18:40 
Also ich hab das bis jetzt immer so gemacht:
ausblenden Delphi-Quelltext
1:
2:
if Speed < MaxSpeed then
  Speed := Speed + Acceleration;

Also ohne große Formeln...
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Do 14.08.03 18:41 
Hi,
Alibi hat folgendes geschrieben:
Also ich hab das bis jetzt immer so gemacht:
ausblenden Delphi-Quelltext
1:
2:
if Speed < MaxSpeed then
  Speed := Speed + Acceleration;

Also ohne große Formeln...

das is aber ne lineare beschleunigung... also eigentlich eher unrealistisch *g*

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Fr 15.08.03 04:14 
Richtig, aber das ganze Spiel, wozu das gehört, ist unrealistisch, insofern. ;)
florian Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

Win XP Home
D5 Enterprise
BeitragVerfasst: So 17.08.03 12:07 
Titel: also ich habs jetzt so gemacht:
hi,
ich habs jetzt so gemacht, geht viell. auch einfacher:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
if not Keys[VK_SPACE] then begin
if (Keys[VK_UP]) then begin
   if Speed<MaxSpeed then begin
      if Speed>0 then begin
      Beschleunigung:=sqrt(0.01*Speed);
      end else
      if Speed=0 then begin
      Speed:=0.1;
      end else
      if Speed<0 then begin
      Beschleunigung:=sqrt(0.01*Abs(Speed));
      end;
      Speed:=Speed+Beschleunigung;
   end;
end else
if (Keys[VK_DOWN]) then begin
   if Speed>-MaxSpeed then begin
      if Speed>0 then begin
      Beschleunigung:=sqrt(0.01*Speed);
      end else
      if Speed=0 then begin
      Speed:=0.1;
      end else
      if Speed<0 then begin
      Beschleunigung:=sqrt(0.01*Abs(Speed));
      end;
      Speed:=Speed-Beschleunigung;
   end;
  end;
end else begin
if Speed<-0.0001 then
Speed:=Speed+0.1;
if Speed>0.0001 then
Speed:=Speed-0.1;
end;
if Speed<-0.0001 then
Speed:=Speed+sqrt(0.0001*Abs(Speed));
if Speed>0.0001 then
Speed:=Speed-sqrt(0.0001*Speed);
if Speed<0 then begin
   PlayerPos.X:=PlayerPos.X - sin(-yrot * (PI / 180)) * Abs(Speed);
   PlayerPos.Z:=PlayerPos.Z - cos(-yrot * (PI / 180)) * Abs(Speed);
end;
if Speed>0 then begin
   PlayerPos.X:=PlayerPos.X + sin(-yrot * (PI / 180)) * Speed;
   PlayerPos.Z:=PlayerPos.Z + cos(-yrot * (PI / 180)) * Speed;
end;
if Speed>0.2 then begin
     if Keys[VK_LEFT] then begin
    yrot:=yrot - 0.5;
    if yrot<0 then
      yrot:=yrot + 360;
  end;
   if Keys[VK_RIGHT] then begin
    yrot:=yrot + 0.5;
    if yrot>360 then
      yrot:=yrot - 360;
  end;
end;
if Speed<-0.2 then begin
    if Keys[VK_LEFT] then begin
    yrot:=yrot + 0.75;
    if yrot<0 then
      yrot:=yrot - 360;
  end;
   if Keys[VK_RIGHT] then begin
    yrot:=yrot - 0.75;
    if yrot>360 then
      yrot:=yrot + 360;
  end;
end;

danke für euere hilfe. jetzt muss ich noch ne kollisioinsabfrage basteln und irgendwie nen sound abspielen, beim fahren und bremsen und so.
hat da jemand eine idee wie man das machen könnte???

ciao
florian