2 Dimensionales Array um 90 Grad Drehen?

Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Neue Antwort erstellen

 

bruce85

Betreff: 2 Dimensionales Array um 90 Grad Drehen?

BeitragMi, Aug 04, 2010 23:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,
irgendwie schaffe ich nicht ein 2 Dimensionales Array zu Drehen.

Hier ist mal der Code:
BlitzMax: [AUSKLAPPEN]
If MouseHit(2) And MouseDown(2) Then
turnArray(tmpArray)
EndIf

Function turnArray:TtmpArray[,] (array:TtmpArray[,])
' Um 90 Grad gedreht
Local X:Int = array.Dimensions()[1], Y:Int = array.Dimensions()[0]
Local neuesArray:TtmpArray[,] = New TtmpArray[X, Y]
For Local i:Int=0 Until X
For Local j:Int=0 Until Y
neuesArray[i, j] = New TtmpArray.NewStein(0)
neuesArray[i, j].Frames = array[j, X - i - 1].Frames
Next
Next

Return neuesArray
End Function


Ich bekomme folgende fehlermeldung:
Unhandled Exception:Attempt to acces field or method of Null object.

Edit: Ich habe den Code noch um diese Zeile ergänzt:BlitzMax: [AUSKLAPPEN]

neuesArray[i, j] = New TtmpArray.NewStein(0)


Jetzt zeigt er keinen fehler mehr an, aber drehen tut sich garnix, wieso?
Ich bedanke mich schonmal im Voraus.

Edit: Jetzt funktioniert es, die zuweisung hat gefehlt, Sry.

MfG
AMD Athlon(tm) II X2 250, 8 GB DDR, MSI MSI 770-C45, GeForce GTS 250
 

bruce85

BeitragDo, Aug 05, 2010 5:22
Antworten mit Zitat
Benutzer-Profile anzeigen
Habe noch ein Problem festgestellt und zwar, wenn sich das Array ab Position 0 befindet, dann funktioniert es.

Wenn ich jetzt das Array an einer bestimmten Position positioniere, dann lässt sich das Array nicht mehr um 90 Grad drehen, sondern es bleibt genau gleich wie vorher.

Hier ist die Funktion:
BlitzMax: [AUSKLAPPEN]
Function turnArray:TtmpArray[,] (array:TtmpArray[,])
' Um 90 Grad gedreht
Local X:Int = array.Dimensions()[1], Y:Int = array.Dimensions()[0]
Local neuesArray:TtmpArray[,] = New TtmpArray[X, Y]

For Local i:Int=0 Until X
For Local j:Int=0 Until Y
neuesArray[i, j] = New TtmpArray.NewStein(0)
neuesArray[i, j].SteinFrames = array[j, X - i - 1].SteinFrames
neuesArray[i, j].X = array[j, X - i - 1].X
neuesArray[i, j].Y = array[j, X - i - 1].Y
neuesArray[i, j].Merk_X = array[j, X - i - 1].Merk_X
neuesArray[i, j].Merk_Y = array[j, X - i - 1].Merk_Y
neuesArray[i, j].Start_X = array[j, X - i - 1].Start_X
neuesArray[i, j].Start_Y = array[j, X - i - 1].Start_Y
Next
Next
Return neuesArray
End Function


Ich wäre euch sehr dankbar, wenn ihr mir helfen könntet.

MfG
AMD Athlon(tm) II X2 250, 8 GB DDR, MSI MSI 770-C45, GeForce GTS 250

mpmxyz

BeitragDo, Aug 05, 2010 20:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Die "Array-Position" kann ich in diesem Code nicht finden.
Bei nicht quadratischen Arrays wird es aber "Index out of bounds"-Fehler geben. (Überprüfe, was x,y,i und j jeweils in den beiden Arrays sind!)
mfG
mpmxyz
Moin Moin!
Projekte: DBPC CodeCruncher Mandelbrot-Renderer
 

bruce85

BeitragFr, Aug 13, 2010 6:46
Antworten mit Zitat
Benutzer-Profile anzeigen
Danke Dir.
Das hat funktioniert, jedoch habe ich mein Quellcode etwas abgeändert und nun funktioniert das mit der Drehung nicht mehr 100 %.

Hier ist mal ein Screen:
user posted image

Da stimmt irgendwas nicht.
BlitzMax: [AUSKLAPPEN]
If MouseHit(2) And MouseDown(2) Then
'Neues array erstellen
Local newArray:TtmpArray[,] = New TtmpArray[S_X, S_Y]
newArray = tmpArray
'und hier die Arrays vertauschen
For Local i:Int=0 Until S_X
For Local j:Int=0 Until S_Y
newArray[i, j].SteinFrames = tmpArray[j, S_X-i-1].SteinFrames
Next
Next
tmpArray = newArray
EndIf


Woran kann denn der fehler liegen?

Danke schonmal.

Edit: Jetzt funktioniert es, ich habe nur vergessen die ganzen Eigenschaften mit zugeben und dann zu drehen.
BlitzMax: [AUSKLAPPEN]
If MouseHit(2) And MouseDown(2) Then
'Neues array erstellen
Local newArray:TtmpArray[,] = New TtmpArray[S_X, S_Y]
For Local i:Int=0 Until S_X
For Local j:Int=0 Until S_Y
newArray[i, j] = New TtmpArray.NewStein(0)
newArray[i, j].X = tmpArray[i, j].X
newArray[i, j].Y = tmpArray[i, j].Y
...
...
...
...
...
...
...
...
...
...
Next
Next
'und hier die Arrays vertauschen
For Local i:Int=0 Until S_X
For Local j:Int=0 Until S_Y
newArray[i, j].SteinFrames = tmpArray[j, S_X-i-1].SteinFrames
newArray[i, j].Start_X = tmpArray[j, S_X-i-1].Start_X
newArray[i, j].Start_Y = tmpArray[j, S_X-i-1].Start_Y
Next
Next
tmpArray = newArray
EndIf


MfG

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group