Der Code nimmt Punkte mit (x,y,z), und wandelt sie in eine isometrische Darstellung um. Die Punkte kann man mit linien verbinden, und die so entstandenen Flächen mit Farben füllen. YAY!
iso.pb
Code: Alles auswählen
; Isometrisches Dingsbumsens
; © 2005 chromaX, Sinn&Zwecklos GmbH.
InitSprite()
InitKeyboard()
screenw = 1280
OpenScreen(screenw, 1024, 32, "Test")
Structure _3d
x.l
y.l
z.l
EndStructure
Structure _2d
x.l
y.l
EndStructure
Structure _li
P1.l
P2.l
col.l
EndStructure
Structure _ae
P1.l
P2.l
P3.l
col.l
EndStructure
winkelx.f = 26.565 / 180 * ACos(-1)
winkelz.f = 26.565 / 180 * ACos(-1)
xfaktor.f = 1
yfaktor.f = 1
zfaktor.f = 1
separate = RGB(5,5,5)
linecol = separate
areacol = RGB(255,255,255)
NewList ploties._3d()
NewList lines._li()
NewList areas._ae()
ReadFile(0, "file.iso")
Repeat
line.s = ReadString()
If multilinecomment = 1
If FindString(line, "*/", 0)
multilinecomment = 0
line = StringField(line, 2, "*/")
Else
Continue
EndIf
EndIf
If FindString(line, "/*", 0)
line = StringField(line, 1, "/*")
multilinecomment = 1
EndIf
line = Trim(StringField(line , 1, "//"))
If LCase(Left(line , 4)) = "plot"
line = Mid(line, 6, Len(line) - 6)
AddElement(ploties())
ploties()\x = Val(Trim(StringField(line, 1, ",")))
ploties()\y = Val(Trim(StringField(line, 2, ",")))
ploties()\z = Val(Trim(StringField(line, 3, ",")))
EndIf
If LCase(Left(line , 4)) = "line"
line = Mid(line, 6, Len(line) - 6)
AddElement(lines())
lines()\P1 = Val(Trim(StringField(line, 1, ",")))
lines()\P2 = Val(Trim(StringField(line, 2, ",")))
If Val(Trim(StringField(line, 3, ",")))
lines()\col = RGB(Val(Trim(StringField(line, 3, ","))),Val(Trim(StringField(line, 4, ","))),Val(Trim(StringField(line, 5, ","))))
Else
lines()\col = linecol
EndIf
EndIf
If LCase(Left(line , 4)) = "area"
line = Mid(line, 6, Len(line) - 6)
AddElement(areas())
areas()\P1 = Val(Trim(StringField(line, 1, ",")))
areas()\P2 = Val(Trim(StringField(line, 2, ",")))
areas()\P3 = Val(Trim(StringField(line, 3, ",")))
If Val(Trim(StringField(line, 4, ",")))
areas()\col = RGB(Val(Trim(StringField(line, 4, ","))), Val(Trim(StringField(line, 5, ","))), Val(Trim(StringField(line, 6, ","))))
Else
areas()\col = areacol
EndIf
EndIf
If LCase(Left(line , 4)) = "lcol"
line = Mid(line, 6, Len(line) - 6)
linecol = RGB(Val(Trim(StringField(line, 1, ","))), Val(Trim(StringField(line, 2, ","))), Val(Trim(StringField(line, 3, ","))))
EndIf
If LCase(Left(line , 4)) = "acol"
line = Mid(line, 6, Len(line) - 6)
areacol = RGB(Val(Trim(StringField(line, 1, ","))), Val(Trim(StringField(line, 2, ","))), Val(Trim(StringField(line, 3, ","))))
EndIf
;Debug line
Until Eof(0)
maxp = CountList(ploties()) - 1
Dim points._2d(maxp)
durchlauf = 0
ForEach ploties()
points(durchlauf)\x = Cos(winkelx)*ploties()\x*xfaktor + Cos(winkelz)*ploties()\z*zfaktor
points(durchlauf)\y = Sin(winkelz)*ploties()\z*zfaktor - Sin(winkelx)*ploties()\x*xfaktor - ploties()\y*yfaktor
If maxy < points(durchlauf)\y
maxy = points(durchlauf)\y
EndIf
durchlauf + 1
Next
yoffset = 1024 - maxy - 200
xoffset = 200
Repeat
Delay(10)
StartDrawing(ScreenOutput())
ClearScreen(0, 0, 0)
FrontColor(255, 0, 0)
ForEach lines()
LineXY(points(lines()\P1)\x + xoffset, points(lines()\P1)\y + yoffset, points(lines()\P2)\x + xoffset, points(lines()\P2)\y + yoffset, separate)
Next
ForEach areas()
FillArea((points(areas()\P1)\x + points(areas()\P2)\x + points(areas()\P3)\x)/3 + xoffset, (points(areas()\P1)\y + points(areas()\P2)\y + points(areas()\P3)\y)/3 + yoffset, separate, areas()\col)
Next
ForEach lines()
LineXY(points(lines()\P1)\x + xoffset, points(lines()\P1)\y + yoffset, points(lines()\P2)\x + xoffset, points(lines()\P2)\y + yoffset, lines()\col)
Next
StopDrawing()
FlipBuffers()
For x = 1 To 15
Delay(1)
ExamineKeyboard()
If KeyboardPushed(#PB_KEY_A)
Ergebnis = GrabSprite(0, 0, 0, 1280, 1024)
SaveSprite(0, "c:\"+Str(Minute(Date()))+Str(Second(Date()))+".bmp")
EndIf
Next
Until KeyboardPushed(1)
Dat ding hier macht ein Haus.
file.iso
Code: Alles auswählen
plot(0,0,0) //P0(x|y|z)
plot(0,0,50)
plot(50,0,50)
plot(0,50,0)
plot(0, 50, 50)
plot(50, 50, 50)
plot(50, 50, 0)
plot(25, 70, 0)
plot(25, 70, 50)
lcol(255,0,0) //Linienfarbe festlegen
line(0,1) //Punkt 0 mit Punkt 1 verbinden, Farbe ist lcol
line(0,3)
line(1,2)
line(1,4)
line(2,5)
line(3,4)
line(3,7)
line(4,5)
line(4,8)
line(5,6)
line(5,8)
line(6,7)
line(7,8,99,0,0) //Linie mit Farbe RGB(99,0,0) von Punkt 7 zu Punkt 8
acol(255,255,255) //Füllfarbe festlegen (Weiss)
area(0,1,3) //Fläche zwischen diesen drei Punkten mit Füllfarbe füllen
area(1,2,4)
area(4,5,8)
area(4,7,3,99,0,0)
area(5,7,6,99,0,0)