Aus 2 Pixeln Winkel rausfinden

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Xaymar

ehemals "Cgamer"

Betreff: Aus 2 Pixeln Winkel rausfinden

BeitragSa, Feb 27, 2010 11:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich versuche derzeit einen TerrainAlphaMapGenerator zu erstellen. Klappt nur leider das mit den Slopes nicht da ich nicht weiß wie man einen Winkel aus denen bekommt.
Immoment mache ich das so:
BlitzMax: [AUSKLAPPEN]
Local C:Int = 90 - Int(Abs(((InPMap.ReadPixel(X, Y) Shl 24 Shr 24) - (InPMap.ReadPixel(X + 1, Y) Shl 24 Shr 24))) / 255.0 * 90)

Aber da scheint es anscheinend keine 45°-90° und 0° winkel zu geben.
wie kann ich den Winkel nun errechnen?
Warbseite

BladeRunner

Moderator

BeitragSa, Feb 27, 2010 11:32
Antworten mit Zitat
Benutzer-Profile anzeigen
Atan2(y-diff,x-diff).

Edit: ich vermute mal du willst die Höheninformation aus einer Heightmap auslesen und anhand der Höhendifferenz die Steigung berechnen. Das Vorgehen bleibt gleich. Die X-Differenz ist dann 'Maßstab deiner Heightmap', die Y-Differenz entspricht der Differenz der ausgelesenen Werte * dem Höhenmaßstab.
Zu Diensten, Bürger.
Intel T2300, 2.5GB DDR 533, Mobility Radeon X1600 Win XP Home SP3
Intel T8400, 4GB DDR3, Nvidia GF9700M GTS Win 7/64
B3D BMax MaxGUI

Stolzer Gewinner des BAC#48, #52 & #92

Xaymar

ehemals "Cgamer"

BeitragSa, Feb 27, 2010 12:29
Antworten mit Zitat
Benutzer-Profile anzeigen
Ah danke BladeRunner. ih hatte mich schon gewundert warum das ständig nur weiße bilder zurücklieferte

Edit: Von Links nach Rechts und Oben nach Unten gehts andersrum allerdings nicht:
BlitzMax: [AUSKLAPPEN]
Function GenerateOutImage()
'Height Processing
Local HMax:Int = Int(GadgetText(InHeightMax)), HMin:Int = Int(GadgetText(InHeightMin)), HTR:Int = Int(GadgetText(InHeightTR))
Local SMax:Int = Int(GadgetText(InSlopeMax)), SMin:Int = Int(GadgetText(InSlopeMin)), STR:Int = Int(GadgetText(InSlopeTR))

If ButtonState(CBHeightMin) = False Then HMin = 0
If ButtonState(CBHeightMax) = False Then HMax = 255
If ButtonState(CBHeightTR) = False Then HTR = 0
If ButtonState(CBSlopeMin) = False Then SMin = 0
If ButtonState(CBSlopeMax) = False Then SMax = 90
If ButtonState(CBSlopeTR) = False Then STR = 0

Local InPMap:TPixmap = LockImage(InIMG)
Local OutPMap:TPixmap = LockImage(OutIMG)
OutPMap.ClearPixels($FF000000)

If ButtonState(CBHeight) And (ButtonState(CBHeightMin) = True Or ButtonState(CBHeightMax) = True)
Local HeightAlphaTable:Byte[256]

For Local C:Int = 0 To 255
If C - HMin <= HTR And C - HMin >= - HTR And HMin > 0
HeightAlphaTable[C] = 255 - (255.0 / HTR / 2.0) * Distance1(C, HMin + HTR)
ElseIf C - HMin <= HTR And C - HMin >= - HTR
HeightAlphaTable[C] = 255
EndIf
If C - HMax <= HTR And C - HMax >= - HTR And HMax < 255
HeightAlphaTable[C] = 255 - (255.0 / HTR / 2.0) * Distance1(C, HMax - HTR)
ElseIf C - HMax <= HTR And C - HMax >= - HTR
HeightAlphaTable[C] = 255
EndIf
If (C >= HMin + HTR And C <= HMax - HTR) Then HeightAlphaTable[C] = 255
Next

For Local X:Int = 0 To ImageWidth(InIMG) - 1
For Local Y:Int = 0 To ImageHeight(InIMG) - 1
Local C:Byte = (InPMap.ReadPixel(X, Y) Shl 24 Shr 24)
OutPMap.WritePixel(X, Y, 255 Shl 24 + HeightAlphaTable[C] Shl 16 + HeightAlphaTable[C] Shl 8 + HeightAlphaTable[C])
Next
Next
HeightAlphaTable = Null
EndIf

If ButtonState(CBSlope) And (ButtonState(CBSlopeMin) = True Or ButtonState(CBSlopeMax) = True)
Local SlopeAlphaTable:Byte[91]

Local MW:Float = Float(GadgetText(InTerrainW)) / ImageWidth(InIMG)
Local MH:Float = Float(GadgetText(InTerrainH)) / ImageHeight(InIMG)
Local MD:Float = Float(GadgetText(InTerrainD)) / 256

For Local C:Int = 0 To 90
If C - SMin <= STR And C - SMin >= - STR And SMin > 0
SlopeAlphaTable[C] = 255 - (255.0 / STR / 2.0) * Distance1(C, SMin + STR)
ElseIf C - SMin <= STR And C - SMin >= - STR
SlopeAlphaTable[C] = 255
End If
If C - SMax <= STR And C - SMax >= - STR And SMax < 90
SlopeAlphaTable[C] = 255 - (255.0 / STR / 2.0) * Distance1(C, SMax - STR)
ElseIf C - SMax <= STR And C - SMax >= - STR
SlopeAlphaTable[C] = 255
End If
If C >= SMin + STR And C <= SMax - STR Then SlopeAlphaTable[C] = 255
Next

'Horizontal Slope
'Left to Right
' For Local X:Int = 0 To ImageWidth(InIMG) - 2
' For Local Y:Int = 0 To ImageHeight(InIMG) - 1
' Local C:Int = CMin((ATan2(MW, (GetGrey(InPmap, X, Y) - GetGrey(InPmap, X + 1, Y)) * MD)) - 90, 0)
' Local G:Byte = CMin(SlopeAlphaTable[C], OutPMap.ReadPixel(X, Y) Shl 24 Shr 24)
' OutPMap.WritePixel(X, Y, $FF000000 + G Shl 16 + G Shl 8 + G)
' Next
' Next
'Right to Left
For Local X:Int = 1 To ImageWidth(InIMG) - 1 Step - 1
For Local Y:Int = 0 To ImageHeight(InIMG) - 1
Local C:Int = CMin((ATan2(MW, (GetGrey(InPmap, X, Y) - GetGrey(InPmap, X - 1, Y)) * MD)) - 90, 0)
Local G:Byte = CMin(SlopeAlphaTable[C], OutPMap.ReadPixel(X, Y) Shl 24 Shr 24)
OutPMap.WritePixel(X, Y, $FF000000 + C Shl 16 + C Shl 8 + C)
Next
Next

'Vertical Slope
' For Local Y:Int = 0 To ImageHeight(InIMG) - 2
' For Local X:Int = 0 To ImageWidth(InIMG) - 1
' Local C:Int = CMin((ATan2(MH, (GetGrey(InPmap, X, Y) - GetGrey(InPmap, X, Y + 1)) * MD)) - 90, 0)
' Local G:Byte = CMin(SlopeAlphaTable[C], OutPMap.ReadPixel(X, Y) Shl 24 Shr 24)
' OutPMap.WritePixel(X, Y, $FF000000 + G Shl 16 + G Shl 8 + G)
' Next
' Next
' For Local Y:Int = 1 To ImageHeight(InIMG) - 1 Step - 1
' For Local X:Int = 0 To ImageWidth(InIMG) - 1
' Local C:Int = CMin((-ATan2(MH, (GetGrey(InPmap, X, Y) - GetGrey(InPmap, X, Y - 1)) * MD)) - 90, 0)
' Local G:Byte = CMin(SlopeAlphaTable[C], OutPMap.ReadPixel(X, Y) Shl 24 Shr 24)
' OutPMap.WritePixel(X, Y, $FF000000 + G Shl 16 + G Shl 8 + G)
' Next
' Next

SlopeAlphaTable = Null
End If

UnlockImage(InIMG) ;InPMap = Null
UnlockImage(OutIMG) ;OutPMap = Null
End Function


Mach ich was falsch?

Edit2: ah verdammt
Hab mich bei der For...Next schleife versehen
Warbseite

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group