Tiles vermischen?

Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Neue Antwort erstellen

M0rgenstern

Betreff: Tiles vermischen?

BeitragDi, Jun 08, 2010 21:24
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey Leute.

Ich hab in der Suche jetzt nix entsprechendes gefunden, deshalb mache ich einfach mal nen neuen Thread auf.

Undzwar habe ich folgendes Problem: Da ich anfange, AlienShooter2D neu zu schreiben, will ich von Anfang an alles sauberer und korrekter machen. So wie die Tiles bisher angeordnet waren, hat das nicht sehr zusammenhängend ausgesehen. Ich möchte aber auch kein riesen Tileset haben, in dem ich dann für jede Mögliche Tilekombination die Ecken und Kanten habe.
Ich würde das gerne so machen, wie in diesem Projekt: https://www.blitzforum.de/worklogs/222/ Am besten zu sehen im Beitrag vom 15.Juni 2009.
Leider habe ich keine Ahnung und auch keinen Ansatz wie das zu bewerkstelligen wäre.

Wenn jemand von euch da ne Möglichkeit oder nen Ansatz hätte wäre das wirklich super.

Lg, M0rgenstern

Xaymar

ehemals "Cgamer"

BeitragDi, Jun 08, 2010 21:52
Antworten mit Zitat
Benutzer-Profile anzeigen
Ist zwar in Blitzbasic, sollte aber leicht auf BlitzMax übertragbar sein:
BlitzBasic: [AUSKLAPPEN]
Dim ColorDim(0, 0, 0)
Function RGBMap(Red_Source, Green_Source, Blue_Source, ColorMap)
W = ImageWidth(ColorMap)
H = ImageHeight(ColorMap)
Dim ColorDim(W, H, 2)

CMapBuffer = ImageBuffer(ColorMap)

LockBuffer(CMapBuffer)
For X = 0 To W-1
For Y = 0 To H-1
RGB = ReadPixelFast(X, Y, CMapBuffer)
ColorDim(X, Y, 0) = (RGB And $FF0000) / $10000 ;Rot
ColorDim(X, Y, 1) = (RGB And $FF00) / $100 ;Green
ColorDim(X, Y, 2) = (RGB And $FF) ;Blue
Next
Next
UnlockBuffer(CMapBuffer)

OutIMG = CreateImage(W, H)

RBuffer = ImageBuffer(Red_Source)
GBuffer = ImageBuffer(Green_Source)
BBuffer = ImageBuffer(Blue_Source)
OBuffer = ImageBuffer(OutIMG)

LockBuffer RBuffer
LockBuffer GBuffer
LockBuffer BBuffer
LockBuffer OBuffer

WR = ImageWidth(Red_Source)
HR = ImageHeight(Red_Source)

WG = ImageWidth(Green_Source)
HG = ImageHeight(Green_Source)

WB = ImageWidth(Blue_Source)
HB = ImageHeight(Blue_Source)

For X2 = 0 To W-1
For Y2 = 0 To H-1
X = X2 Mod WR
Y = Y2 Mod HR
RGB = ReadPixelFast(X, Y, RBuffer)
R1 = (RGB And $FF0000) / $10000 ;Rot
G1 = (RGB And $FF00) / $100 ;Green
B1 = (RGB And $FF) ;Blue

X = X2 Mod WG
Y = Y2 Mod HG
RGB = ReadPixelFast(X, Y, GBuffer)
R2 = (RGB And $FF0000) / $10000 ;Rot
G2 = (RGB And $FF00) / $100 ;Green
B2 = (RGB And $FF) ;Blue

X = X2 Mod WB
Y = Y2 Mod HB
RGB = ReadPixelFast(X, Y, BBuffer)
R3 = (RGB And $FF0000) / $10000 ;Rot
G3 = (RGB And $FF00) / $100 ;Green
B3 = (RGB And $FF) ;Blue

X = X2
Y = Y2
R4 = R1 * (Float(ColorDim(X, Y, 0)) / 255) + R2 * (Float(ColorDim(X, Y, 1)) / 255) + R3 * (Float(ColorDim(X, Y, 2)) / 255)
If R4 > 255 R4 = 255
G4 = G1 * (Float(ColorDim(X, Y, 0)) / 255) + G2 * (Float(ColorDim(X, Y, 1)) / 255) + G3 * (Float(ColorDim(X, Y, 2)) / 255)
If G4 > 255 G4 = 255
B4 = B1 * (Float(ColorDim(X, Y, 0)) / 255) + B2 * (Float(ColorDim(X, Y, 1)) / 255) + B3 * (Float(ColorDim(X, Y, 2)) / 255)
If B4 > 255 B4 = 255

RGB = R4 * $10000 + G4 * $100 + B4
WritePixelFast X, Y, RGB, OBuffer
Next
Next

UnlockBuffer RBuffer
UnlockBuffer GBuffer
UnlockBuffer BBuffer
UnlockBuffer OBuffer

Return OutIMG
End Function


Was die funktion macht:
Liest die RGB werte aus der ColorMap(Image) und berechnet dann aus allen anderen bildern die richtigen farbwerte. 255R würde also Red_Source Pixelfarbe sein, 255G würde Green_Source pixelfarbe sein, usw. Gemischt wird durch addition aller teile.

Also rein theoretisch generierst du nur neues Tiles in den Speicher.
Warbseite

M0rgenstern

BeitragMi, Jun 09, 2010 21:44
Antworten mit Zitat
Benutzer-Profile anzeigen
Frage... Ist das Echtzeittauglich? Bei Scrolling etc müssten dann fast in jedem Frame die Tiles neu berechnet werden^^

Lg, M0rgenstern
 

PhillipK

BeitragDo, Jun 10, 2010 3:07
Antworten mit Zitat
Benutzer-Profile anzeigen
Das würde mich allerdings auch mal Intressieren, ob das Echtzeittauglich ist.

Ein ähnliches problem hatten wir in unserm jetzigen projekt auch.. Und es lag nicht daran, das wir die tiles nicht erstellen wollten (mit Blender und Gimp + ein paar scripten hätte jedes tile nur wenige sekunden gebraucht) sondern eher an der angst, das gleich mal 50mb speicher draufgehen, um alle möglichen (wichtigen!) tiles zu laden..

Eine mischfunktion die auch halbwegs schnell ist (ich glaub, wir würden auf knapp 20mischungen pro bewegtem bild (nicht frame!) kommen), wäre klasse ^^

Da ich nicht in unserer mapengine eingeweiht bin, leite ich das einfach mal an die zuständige person weiter Wink
 

Matthias

BeitragDo, Jun 10, 2010 10:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Hay. Ich denke nicht das das echtzeitfähig ist.

Schon alleine das 4mal LockBuffer/UnlockBuffer

Besser wäre wenn mann einmal die Tiles läd und die R,G,B Werte in Dim Felder unter bringt.

Auserdem dürfen beim Scrollen nur die Tiles aktualiesiert werden die neu dazu gekommen sind.
Und nicht alle neu.

Ich denke dann könnte es klappen.

Xaymar

ehemals "Cgamer"

BeitragDo, Jun 10, 2010 17:32
Antworten mit Zitat
Benutzer-Profile anzeigen
Der Code selbst ist nur bedingt Realtime fähig(16fps auf einer Dualcore maschine mit Threading in B3D an)

Geht noch schneller indem ihr das per shader macht.
GLSL Vertex Shader:
Code: [AUSKLAPPEN]
void main()
{
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   gl_TexCoord[0] = gl_MultiTexCoord0;
}

GLSL Fragment Shader:
Code: [AUSKLAPPEN]
uniform sampler2D s2D_RGBMap;
uniform sampler2D s2D_RedMap;
uniform sampler2D s2D_GrnMap;
uniform sampler2D s2D_BluMap;

vec4 v4_Color;
vec4 v4_RedMap;
vec4 v4_GrnMap;
vec4 v4_BluMap;
vec3 v3_ColorFragments;

void main()
{
   v3_ColorFragments = texture2D(s2D_RGBMap, gl_TexCoord[0].xy).xyz;
   v4_RedMap = texture2D(s2D_RedMap, gl_TexCoord[0].xy);
   v4_GrnMap = texture2D(s2D_GrnMap, gl_TexCoord[0].xy);
   v4_BluMap = texture2D(s2D_BluMap, gl_TexCoord[0].xy);
   
   v4_Color = v4_RedMap * v3_ColorFragments.x;
   v4_Color += v4_GrnMap * v3_ColorFragments.y;
   v4_Color += v4_BluMap * v3_ColorFragments.z;
   
   if (v4_Color.x > 255.0) { v4_Color.x = 255.0; }
   if (v4_Color.y > 255.0) { v4_Color.y = 255.0; }
   if (v4_Color.z > 255.0) { v4_Color.z = 255.0; }
   if (v4_Color.t > 255.0) { v4_Color.t = 255.0; }
   
   gl_FragColor = vec4(v4_Color.xyz,v4_Color.t*texture2D(s2D_RGBMap, gl_FragCoord.xy).t);
}



Und es ist dann sogar realtime tauglich, nur ihr müsst euch um Shader kümmern.
uniform Eingaben:
int s2D_RGBMap
int s2D_RedMap
int s2D_GrnMap
int s2D_BluMap
Warbseite

M0rgenstern

BeitragFr, Jun 11, 2010 20:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Hui.. Mit Shadern habe ich mich jetzt noch nie befasst.
Und dein Quellcode ist doch in C oder C++, oder?

@ PhillipK:
Hast du inzwischen eine Antwort von deinem Team? Würde mich mal interessieren wie man das macht.

Lg, M0rgenstern

mpmxyz

BeitragFr, Jun 11, 2010 20:19
Antworten mit Zitat
Benutzer-Profile anzeigen
Weit gefehlt! Wink
Es ist GLSL-Code.
GLSL ist die Shader-Sprache von OpenGL.
Dieser Code mischt 3 Texturen mit Hilfe einer weiteren Textur zusammen. (die Rot-, Grün- und Blauanteile bestimmen das Mischungsverhältnis)
mfG
mpmxyz
Moin Moin!
Projekte: DBPC CodeCruncher Mandelbrot-Renderer

M0rgenstern

BeitragFr, Jun 11, 2010 20:21
Antworten mit Zitat
Benutzer-Profile anzeigen
Okay.
Sorry. Das "Void Main()" hat mich halt direkt dadrauf gebracht.

Wie nutzt mann denn dan die Funktion? Ich blick da ehrlich gesagt, überhaupt nicht durch.

Lg, M0rgenstern

mpmxyz

BeitragFr, Jun 11, 2010 20:47
Antworten mit Zitat
Benutzer-Profile anzeigen
Dafür sollte man sich erst einmal mit OpenGL beschäftigen.
Ich kann aber mal das Prinzip erklären:
Code: [AUSKLAPPEN]
1. Man liest die Shader-Codes irgendwie ein bzw. hat ihn direkt im Code gespeichert.
2. Man erstellt zwei Shader-Objekte - einen Vertex-Shader und einen Fragment-Shader
3. Man weist den Shadern ihren Code zu.
4. Man kompiliert die Shader.
5. Man erstellt ein "Programmobjekt" und fügt ihm die Shader hinzu.
6. Man bindet das Programm.
7. Man aktiviert das Programm.
8. Man setzt die Eingabewerte des Shaders.
9. Man zeichnet etwas, was vom Shader bearbeitet wird.

Falls du mal OpenGL lernen möchtest, kann ich dir diese Seite empfehlen:
http://wiki.delphigl.com/index.php/Hauptseite
mfG
mpmxyz
Moin Moin!
Projekte: DBPC CodeCruncher Mandelbrot-Renderer

Lastmayday

BeitragFr, Jun 11, 2010 23:08
Antworten mit Zitat
Benutzer-Profile anzeigen
Servus M0rgenstern,

ich meld mich mal nach langer zeit mal wieder :p

mein orginal code ist schnell und evetuell "massen" echtzeit tauglich... das problem bei einer tile sind die 8 nachbarn mit insgesamt 9 kobinationen also kurz: 9^9 möglichkeiten. ( 387.420.489 ) der trick ist das man alle unsinnigen kombis ausschaltet und da bleiben pro ecke ~17 möglichkeiten über und die lassen sich auf die anderen ecken spiegeln... natürlich gets auch einfacher aber das was ich gebastelt habe merkt sich die tiles und bei erneuter anfrage wird das schon vorhandene tile rausgesucht und zurückgegeben. auch wird beim zusammen mischen die nachbar tiles gezielt abgefragt usw...

aufjedenfall waren die lade zeiten sehr schnell und auch im editor konnte ich in echtzeit mappen. nur meine map-speicher methode war *hust* abenteuerlich.

hier der total verwirrende code (nicht ausführbar):

Code: [AUSKLAPPEN]



Global rendertexlist:TList = CreateList()
Function renderTile(x:Int, y:Int, l:Int)
   If emap[x, y, l] <> Null Then
      If emap[x, y, l].isRendert = 1 Then emap[x, y, l] = emap[x, y, l].orginal
   Else
      Return
   EndIf
   'umgebung feststellen
   If x > 0 And x < 999 And y > 0 And y < 999 And emap[x, y, l] <> Null Then
      Local renderdat:Ttextur[3, 3], renderdatst:Ttextur[8], cst:Int, othercheck:Int = 0
      
      For Local cy:Int = y - 1 To y + 1
         For Local cx:Int = x - 1 To x + 1
            If cx = x And cy = y Then
               If emap[cx, cy, l] <> Null Then
                  renderdat[1, 1] = emap[cx, cy, l]
               EndIf
            Else
               If emap[cx, cy, l] = Null Then
                  
               Else
                  If emap[cx, cy, l].isRendert = 0 Then
                     renderdat[cx - x + 1, cy - y + 1] = emap[cx, cy, l]
                     renderdatst[cst] = emap[cx, cy, l]
                     othercheck = othercheck + 1
                  Else
                     renderdat[cx - x + 1, cy - y + 1] = emap[cx, cy, l].orginal
                     renderdatst[cst] = emap[cx, cy, l].orginal
                     othercheck = othercheck + 1
                  EndIf
               End If
               cst = cst + 1   
            End If
         Next
      Next
      cst = 0
      If othercheck > 0 Then
         'datenbank abfragen
         Local found:Int = 0
         For Local rTtextur:Ttextur = EachIn emap[x, y, l].redertlist
            Local infound:Int = 1
            For Local sst:Int = 0 To 7
               If rTtextur.render[sst] <> renderdatst[sst] Then
                  infound = 0
               EndIf
            Next
            If infound = 1 Then
               emap[x, y, l] = rTtextur
               found = 1
               Exit
            End If
         Next
         'bild berechnen
         If found = 0 Then
            Local nTtextur:Ttextur = New Ttextur
            rendertexlist.AddLast(nTtextur)
            nTtextur.isRendert = 1
            nTtextur.orginal = emap[x, y, l]
            For Local sst:Int = 0 To 7
               nTtextur.render[sst] = renderdatst[sst]
            Next
            emap[x, y, l].redertlist.AddLast(nTtextur)
            
            
            Local bild:TPixmap = CopyPixmap(emap[x, y, l].pic)
            
            Local asdliste:TPixmap[9]
            
            If renderdat[1, 0] <> Null Then asdliste[0] = renderdat[1, 0].pic Else asdliste[0] = bodenpix
            If renderdat[2, 0] <> Null Then asdliste[1] = renderdat[2, 0].pic Else asdliste[1] = bodenpix
            If renderdat[2, 1] <> Null Then asdliste[2] = renderdat[2, 1].pic Else asdliste[2] = bodenpix
            If renderdat[2, 2] <> Null Then asdliste[3] = renderdat[2, 2].pic Else asdliste[3] = bodenpix
            If renderdat[1, 2] <> Null Then asdliste[4] = renderdat[1, 2].pic Else asdliste[4] = bodenpix
            If renderdat[0, 2] <> Null Then asdliste[5] = renderdat[0, 2].pic Else asdliste[5] = bodenpix
            If renderdat[0, 1] <> Null Then asdliste[6] = renderdat[0, 1].pic Else asdliste[6] = bodenpix
            If renderdat[0, 0] <> Null Then asdliste[7] = renderdat[0, 0].pic Else asdliste[7] = bodenpix
            asdliste[8] = renderdat[1, 1].pic
            
            drawTile(bild, asdliste[8], asdliste)
            
            nTtextur.pic = CopyPixmap(bild)
            nTtextur.img = LoadImage(bild)
            nTtextur.img.flags = emap[x, y, l].img.flags
            
            bild = ResizePixmap(bild, 32, 32)
               
            Local r:Int = 0, g:Int = 0, b:Int = 0
            For Local xr:Int = 0 To 31
               For Local yr:Int = 0 To 31
                  Local colorm:Int = bild.ReadPixel(xr, yr)
                  r = r + ((colorm Shr 16) & $ff)
                  g = g + ((colorm Shr 8) & $ff)
                  b = b + ((colorm) & $ff)
               Next
            Next
            bild = Null
               
            nTtextur.r = r / 1024
            nTtextur.g = g / 1024
            nTtextur.b = b / 1024
            
            emap[x, y, l] = nTtextur
         End If
      EndIf
   EndIf
End Function

Global feedcount:Int = -1, feeddata:Int[4], feedfactor:Float, feedpixel:Int, feedposx:Int, feedposy:Int, feedtexA:Int, feedtexB:Int, feedtexACT:Int
Global combospeicher:Int[16, 9]




Function loadtheshit()
   Local indata:TStream = ReadFile("colordatabase.dat")
   
   For Local x:Int = 0 To 15
      For Local y:Int = 0 To 8
         combospeicher[x, y] = indata.ReadInt()
      Next
   Next
   
   indata.Close()
End Function


Function getdiff:Int(bild:TPixmap, bilduse:TPixmap, bildpos:TPixmap, bildneg:TPixmap)
   Local ret:Int
   
   If bild = bilduse Then ret = ret + 1
   If bild = bildpos Then ret = ret + 2
   If bild = bildneg Then ret = ret + 4
   
   If bilduse = bildpos Then ret = ret + 8
   If bilduse = bildneg Then ret = ret + 16

   If bildpos = bildneg Then ret = ret + 32
   
   Return ret
End Function



Function drawTile(tobild:TPixmap Var, orginalbild:TPixmap Var, fromlist:TPixmap[] Var)
   
   If combospeicher[0, 8] = 0 Then loadtheshit()

   Local asdasf:Int = 1

For Local y:Int = 0 To 31
   For Local x:Int = 0 To 31
      Local used_combox:Int = 0
      If ((x < 10 Or x > 21) And (y < 10 Or y > 21)) Or ((x >= 10 And x <= 21) Or (y >= 10 And y <= 21)) Then
         Local use:Int, pos:Int, neg:Int, fromx:Int, tox:Int, fromy:Int, toy:Int, flipx:Int, flipy:Int, turn90:Int, turn45:Int, invert:Int
         If x >= 10 And x <= 21 And y < 10 Then '0
            use = 0; pos = 1 ; neg = 7
            fromx = 10 ; tox = 21 ; fromy = 0 ; toy = 9
            flipx = 0 ; flipy = 0 ; turn90 = 0; turn45 = 0; invert = 0
         ElseIf x > 21 And y < 10 '1
            use = 1; pos = 2 ; neg = 0
            fromx = 22 ; tox = 31 ; fromy = 0 ; toy = 9
            For Local x:Int = 0 To 15
               If getdiff(orginalbild, fromlist[use], fromlist[pos], fromlist[neg]) = combospeicher[x, 8] Then used_combox = x
            Next
            flipx = 1 + combospeicher[used_combox, 0] ; flipy = 1 + combospeicher[used_combox, 1]
            turn90 = 1 + combospeicher[used_combox, 2] ; turn45 = 1 + combospeicher[used_combox, 3] ; invert = 0 + combospeicher[used_combox, 4]
         ElseIf x > 21 And y >= 10 And y <= 21  '2
            use = 2; pos = 3 ; neg = 1
            fromx = 22 ; tox = 31 ; fromy = 10 ; toy = 21
            flipx = 0 ; flipy = 0 ; turn90 = 1; turn45 = 0; invert = 0
         ElseIf x > 21 And y > 21 '3
            use = 3; pos = 4 ; neg = 2
            fromx = 22 ; tox = 31 ; fromy = 22 ; toy = 31
            For Local x:Int = 0 To 15
               If getdiff(orginalbild, fromlist[use], fromlist[pos], fromlist[neg]) = combospeicher[x, 8] Then used_combox = x
            Next
            'If asdasf = 1 Then Notify(getdiff(orginalbild, fromlist[use], fromlist[pos], fromlist[neg]) + " ; " + used_combox) ; asdasf = 0
            flipx = 0 + combospeicher[used_combox, 0] ; flipy = 0 + combospeicher[used_combox, 1]
            turn90 = 0 + combospeicher[used_combox, 2] ; turn45 = 1 + combospeicher[used_combox, 3] ; invert = 0 + combospeicher[used_combox, 4]
         ElseIf x >= 10 And x <= 21 And y > 21 '4
            use = 4; pos = 5 ; neg = 3
            fromx = 10 ; tox = 21 ; fromy = 22 ; toy = 31
            flipx = 1 ; flipy = 0 ; turn90 = 0; turn45 = 0; invert = 0
         ElseIf x < 10 And y > 21 '5
            use = 5; pos = 6 ; neg = 4
            fromx = 0 ; tox = 9 ; fromy = 22 ; toy = 31
            For Local x:Int = 0 To 15
               If getdiff(orginalbild, fromlist[use], fromlist[pos], fromlist[neg]) = combospeicher[x, 8] Then used_combox = x
            Next
            flipx = 0 + combospeicher[used_combox, 0] ; flipy = 0 + combospeicher[used_combox, 1]
            turn90 = 1 + combospeicher[used_combox, 2] ; turn45 = 1 + combospeicher[used_combox, 3] ; invert = 0 + combospeicher[used_combox, 4]
         ElseIf x < 10 And y >= 10 And y <= 21
            use = 6; pos = 7 ; neg = 5 '6
            fromx = 0 ; tox = 9 ; fromy = 10 ; toy = 21
            flipx = 0 ; flipy = 1 ; turn90 = 1; turn45 = 0; invert = 0
         ElseIf x < 10 And y < 10 '7
            use = 7; pos = 0 ; neg = 6
            fromx = 0 ; tox = 9 ; fromy = 0 ; toy = 9
            For Local x:Int = 0 To 15
               If getdiff(orginalbild, fromlist[use], fromlist[pos], fromlist[neg]) = combospeicher[x, 8] Then used_combox = x
            Next
            flipx = 1 + combospeicher[used_combox, 0] ; flipy = 1 + combospeicher[used_combox, 1]
            turn90 = 0 + combospeicher[used_combox, 2] ; turn45 = 1 + combospeicher[used_combox, 3] ; invert = 0 + combospeicher[used_combox, 4]
         End If
         If used_combox = -1 Then
            drawPixel(tobild, fromlist, use, pos, neg, x, y, fromx, tox, fromy, toy, 10, 31, flipx, flipy, turn90, turn45, invert)
         Else
            drawPixel(tobild, fromlist, use, pos, neg, x, y, fromx, tox, fromy, toy, 10, 31, flipx, flipy, turn90, turn45, invert, combospeicher[used_combox, 5], 1 - combospeicher[used_combox, 6], 1 - combospeicher[used_combox, 7])
         EndIf
      EndIf
      'drawPixel(testpic, texmapstrip, 3, 4, 2, x, y, 0, 31, 0, 31, 31, 31, 0, 0, 0, 1)
   Next
Next

End Function

Function drawPixel(tobild:TPixmap Var, frombild:TPixmap[] Var, nrUSE:Int, nrPOS:Int, nrNEG:Int, x:Int, y:Int, fromx:Int, tox:Int, fromy:Int, toy:Int, amay:Float, pixel:Int, flipX:Int = 0, flipY:Int = 0, turn90:Int = 0, turn45:Int = 0, invert:Int = 0, usetexuse:Int = 0, usetexA:Int = 1, usetexB:Int = 1)
   Local red_x:Int, red_y:Int
   
   If x < fromx Or x > tox Then Return
   If y < fromy Or y > toy Then Return
   
   amay = (toy - fromy)
   Local texACT:Int = 0
   Local x6:Int = (x - fromx), y6:Int = (y - fromy), texAx:Int = (x - fromx), texAy:Int = (y - fromy), texBx:Int = (x - fromx), texBy:Int = (y - fromy)
   If Flipx = 1 Then
      y6 = (toy - fromy) - y6
      texAy = (toy - fromy) - texAy
      texBy = (toy - fromy) - texBy
   EndIf
   If Flipy = 1 Then
      x6 = (tox - fromx) - x6
      texAx = (tox - fromx) - texAx
      texBx = (tox - fromx) - texBx
   EndIf
   
   If turn90 = 1 Then
      Local tmp:Int = x6
      x6 = y6
      y6 = (tox - fromx) - tmp
      amay = tox - fromx
      
      Local tmpA:Int = texAx
      Local tmpB:Int = texBx
      texAx = texAy
      texBx = texBy
      texAy = (toy - fromy) - tmpA
      texBy = (toy - fromy) - tmpB
   EndIf
   
   If turn45 = 1 Then
      If y6 < x6 Then
         Local tmp:Int = x6
         x6 = y6
         y6 = (tox - fromx) - tmp
      Else
         Local tmp:Int = y6
         x6 = y6
         y6 = (toy - fromy) - tmp
      EndIf
      texAx = (tox - fromx) - texAx
      texAy = (toy - fromy) - texAy
      
      Local tmpB:Int = texBx
      texBx = texBy
      texBy = (toy - fromy) - tmpB
      texACT = 1
   End If
   
   If invert = 1 Then
      If (tox - fromx) = (toy - fromy) Then
         x6 = (tox - fromx) - x6
         y6 = (toy - fromy) - y6
         texAx = (tox - fromx) - texAx
         texBx = (tox - fromx) - texBx
         texAy = (toy - fromy) - texAy
         texBy = (toy - fromy) - texBy
      EndIf
   End If
   

   Local tcolorm:Int
   If red_x > 0 Then
      If red_Y > 0 Then
         tcolorm = getAllColors(tobild, frombild, nrUSE, nrPOS, nrNEG, red_X - x, red_y - y, x6, y6, texACT, usetexuse, usetexA, usetexB, texAx, texBx, amay, pixel)
         WritePixel(tobild, red_X - x, red_y - y, tcolorm)
      Else
         tcolorm = getAllColors(tobild, frombild, nrUSE, nrPOS, nrNEG, red_X - x, y, x6, y6, texACT, texAx, usetexuse, usetexA, usetexB, texBx, amay, pixel)
         WritePixel(tobild, red_X - x, y, tcolorm)
      End If
   Else
      If red_Y > 0 Then
         tcolorm = getAllColors(tobild, frombild, nrUSE, nrPOS, nrNEG, x, red_y - y, x6, y6, texACT, usetexuse, usetexA, usetexB, texAx, texBx, amay, pixel)
         WritePixel(tobild, x, red_y - y, tcolorm)
      Else
         tcolorm = getAllColors(tobild, frombild, nrUSE, nrPOS, nrNEG, x, y, x6, y6, texACT, usetexuse, usetexA, usetexB, texAx, texBx, amay, pixel)
         WritePixel(tobild, x, y, tcolorm)
      End If
   End If
   
End Function

Function getAllColors:Int(tobild:TPixmap Var, frombild:TPixmap[] Var, nrUSE:Int, nrPOS:Int, nrNEG:Int, x:Int, y:Int, posx:Int, posy:Int, texACT:Int, usetexuse:Int, usetexA:Int, usetexB:Int, texA:Int, texB:Int, factor:Int, pixel:Int)
   Local ret:Int
   
   setfeedColor(posx, posy, texA, texB, texACT, factor, pixel)
   
   feedColor(tobild.ReadPixel(x, y))
   
   If frombild[nrUSE] <> Null Then
      If usetexuse = 0 Then
         feedColor(frombild[nrUSE].ReadPixel(x, y))
      ElseIf usetexuse = 1
         feedColor(tobild.ReadPixel(x, y))
      ElseIf usetexuse = 2
         If frombild[nrNEG] <> Null Then feedColor(frombild[nrNEG].ReadPixel(x, y))
      ElseIf usetexuse = 3
         If frombild[nrPOS] <> Null Then feedColor(frombild[nrPOS].ReadPixel(x, y))
      EndIf
   EndIf
   
   If frombild[nrNEG] <> Null And usetexA = 1 Then feedColor(frombild[nrNEG].ReadPixel(x, y))
   If frombild[nrPOS] <> Null And usetexB = 1 Then feedColor(frombild[nrPOS].ReadPixel(x, y))
            
   ret = pokefeedColor()
   
   Return ret
End Function

' COLOR FEEEEEEEEEEDDDDD!!!!
Function setfeedColor(pos_x:Int, pos_y:Int, texA:Int, texB:Int, texACT:Int, facor:Float, pixel:Int)
   feedfactor = facor
   feedpixel = pixel
   feedposx = pos_x
   feedposy = pos_y
   feedtexA = texA
   feedtexB = texB
   feedtexACT = texACT
End Function

Function feedColor(value:Int)
   feedcount = feedcount + 1
   If feedcount = 5 Then Notify("to mutch colors") ;End
   feeddata[feedcount] = value
End Function

Function pokefeedColor:Int()
   Local ret:Int, workedtex:Int
   Local splitColor:Float[5, 4]
   
   
   If feedcount >= 0 Then
      
      splitColor[0, 0] = (feeddata[0] Shr 24)
      splitColor[0, 1] = ((feeddata[0] Shr 16) & $ff)
      splitColor[0, 2] = ((feeddata[0] Shr 8) & $ff)
      splitColor[0, 3] = (feeddata[0] & $ff)                  
      splitColor[0, 0] = (splitColor[0, 0] * ((feedposy + feedfactor) / (feedfactor * 2)))
      splitColor[0, 1] = (splitColor[0, 1] * ((feedposy + feedfactor) / (feedfactor * 2)))
      splitColor[0, 2] = (splitColor[0, 2] * ((feedposy + feedfactor) / (feedfactor * 2)))
      splitColor[0, 3] = (splitColor[0, 3] * ((feedposy + feedfactor) / (feedfactor * 2)))
      workedtex = workedtex + 1
      
      If feedcount >= 1 Then
         If feedtexACT = 0 Then
            splitColor[1, 0] = (feeddata[1] Shr 24)
            splitColor[1, 1] = ((feeddata[1] Shr 16) & $ff)
            splitColor[1, 2] = ((feeddata[1] Shr 8) & $ff)
            splitColor[1, 3] = (feeddata[1] & $ff)
            splitColor[1, 0] = (splitColor[1, 0] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[1, 1] = (splitColor[1, 1] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[1, 2] = (splitColor[1, 2] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[1, 3] = (splitColor[1, 3] * ((- feedposy + feedfactor) / (feedfactor * 2)))
         Else
            splitColor[1, 0] = (feeddata[1] Shr 24)
            splitColor[1, 1] = ((feeddata[1] Shr 16) & $ff)
            splitColor[1, 2] = ((feeddata[1] Shr 8) & $ff)
            splitColor[1, 3] = (feeddata[1] & $ff)
         EndIf
         workedtex = workedtex + 1
      EndIf
      rem
      endrem
      
      If feedcount >= 2 And feedtexACT = 1 Then
         splitColor[2, 0] = (feeddata[2] Shr 24)
         splitColor[2, 1] = ((feeddata[2] Shr 16) & $ff)
         splitColor[2, 2] = ((feeddata[2] Shr 8) & $ff)
         splitColor[2, 3] = (feeddata[2] & $ff)
         splitColor[1, 0] = (splitColor[1, 0] * ((feedtexA + feedfactor) / (feedfactor * 2))) + (splitColor[2, 0] * ((- feedtexA + (feedfactor)) / (feedfactor * 2)))
         splitColor[1, 1] = (splitColor[1, 1] * ((feedtexA + feedfactor) / (feedfactor * 2))) + (splitColor[2, 1] * ((- feedtexA + (feedfactor)) / (feedfactor * 2)))
         splitColor[1, 2] = (splitColor[1, 2] * ((feedtexA + feedfactor) / (feedfactor * 2))) + (splitColor[2, 2] * ((- feedtexA + (feedfactor)) / (feedfactor * 2)))
         splitColor[1, 3] = (splitColor[1, 3] * ((feedtexA + feedfactor) / (feedfactor * 2))) + (splitColor[2, 3] * ((- feedtexA + (feedfactor)) / (feedfactor * 2)))
         workedtex = workedtex + 1
      End If
      rem
      endrem
      
      If feedcount = 3 And feedtexACT = 1 Then
         splitColor[3, 0] = (feeddata[3] Shr 24)
         splitColor[3, 1] = ((feeddata[3] Shr 16) & $ff)
         splitColor[3, 2] = ((feeddata[3] Shr 8) & $ff)
         splitColor[3, 3] = (feeddata[3] & $ff)
         splitColor[1, 0] = (splitColor[1, 0] * ((- feedtexB + (feedfactor * 2)) / (feedfactor * 2))) + (splitColor[3, 0] * ((feedtexB) / (feedfactor * 2)))
         splitColor[1, 1] = (splitColor[1, 1] * ((- feedtexB + (feedfactor * 2)) / (feedfactor * 2))) + (splitColor[3, 1] * ((feedtexB) / (feedfactor * 2)))
         splitColor[1, 2] = (splitColor[1, 2] * ((- feedtexB + (feedfactor * 2)) / (feedfactor * 2))) + (splitColor[3, 2] * ((feedtexB) / (feedfactor * 2)))
         splitColor[1, 3] = (splitColor[1, 3] * ((- feedtexB + (feedfactor * 2)) / (feedfactor * 2))) + (splitColor[3, 3] * ((feedtexB) / (feedfactor * 2)))
         workedtex = workedtex + 1
      End If
      rem
      endrem
      If feedcount >= 1 Then
         If feedtexACT = 0 Then
            splitColor[0, 0] = splitColor[0, 0] + splitColor[1, 0]
            splitColor[0, 1] = splitColor[0, 1] + splitColor[1, 1]
            splitColor[0, 2] = splitColor[0, 2] + splitColor[1, 2]
            splitColor[0, 3] = splitColor[0, 3] + splitColor[1, 3]
         Else
            splitColor[0, 0] = splitColor[0, 0] + (splitColor[1, 0] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[0, 1] = splitColor[0, 1] + (splitColor[1, 1] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[0, 2] = splitColor[0, 2] + (splitColor[1, 2] * ((- feedposy + feedfactor) / (feedfactor * 2)))
            splitColor[0, 3] = splitColor[0, 3] + (splitColor[1, 3] * ((- feedposy + feedfactor) / (feedfactor * 2)))
         EndIf
      EndIf
      
      Local nextcolor:Int
      Local bytes2:Byte Ptr = Varptr nextcolor
      bytes2[0] = Int(splitColor[0, 3])
      bytes2[1] = Int(splitColor[0, 2])
      bytes2[2] = Int(splitColor[0, 1])
      bytes2[3] = Int(splitColor[0, 0])
      
      ret = nextcolor
   EndIf
   
   feedcount = -1
   Return ret
End Function


Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group