CreateTorus von ??? |
Hi, Vertex/Freax hat diese Funktion im alten Forum schon mal gepostet, da es aber durch besondere umstände(:lol:) dieses Forum heute nicht mehr gibt, ist die Funktion verschwunden. Darum hab ich sie mit der Hilfe von Freax/Vertex neu geschrieben. Ist eigentlich zu benutzen, wie die anderen Primitives. Hier ist der Code mit Beispiel: [code:1:bbc3ca8a4f]Graphics3D 800,600,32,2 AppTitle("Torus") SetBuffer BackBuffer() Global camera = CreateCamera() Global light = CreateLight() Global torus = CreateTorus() PositionEntity torus,0,0,5 Repeat TurnEntity torus,1,2,3 UpdateWorld RenderWorld Flip Until KeyDown(1) End Function CreateTorus(Radius1#=1,Radius2#=0.5,Segments1=10,Segments2=10) Local XPos1#,YPos1#,XPos2#,YPos2#,X1#,Y1#,Z1#,X2#,Y2#,Z2#,X3#,Y3#,Z3#,X4#,Y4#,Z4#,V1,V2,V3,V4 Local torus = CreateMesh() Local surface = CreateSurface(torus) i = 0 Repeat i=i+(360 / Segments2) XPos1# = Cos(i) * Radius2# + Radius1# YPos1# = Sin(i) * Radius2# + Radius1# XPos2# = Cos(i + (360 / Segments2)) * Radius2# + Radius1# YPos2# = Sin(i + (360 / Segments2)) * Radius2# + Radius1# j = 0 Repeat j = j+(360 / Segments1) X1# = Cos(j) * XPos1# Y1# = YPos1# Z1# = Sin(j) * XPos1# X2# = Cos(j + (360 / Segments1)) * XPos1# Y2# = YPos1# Z2# = Sin(j + (360 / Segments1)) * XPos1# X3# = Cos(j) * XPos2# Y3# = YPos2# Z3# = Sin(j) * XPos2# X4# = Cos(j + (360 / Segments1)) * XPos2# Y4# = YPos2# Z4# = Sin(j + (360 / Segments1)) * XPos2# V1 = AddVertex(surface,X1#,Y1#,Z1#) V2 = AddVertex(surface,X2#,Y2#,Z2#) V3 = AddVertex(surface,X3#,Y3#,Z3#) V4 = AddVertex(surface,X4#,Y4#,Z4#) AddTriangle(surface,V3,V2,V1) AddTriangle(surface,V4,V2,V3) Until j > 360 - (360 / Segments1) Until i > 360 - (360 / Segments2) UpdateNormals torus PositionMesh torus,0,-Radius1#,0 Return torus End Function[/code:1:bbc3ca8a4f] |
von ??? |
Moin. Ich hab das Torus mal mit ner UV Map erweitert: [code:1:1ef7d05b87]Graphics3D 800,600,32,2 AppTitle("Torus") SetBuffer BackBuffer() Global camera = CreateCamera() Global light = CreateLight() Global torus = CreateTorus() Global pla = LoadTexture("C: est.bmp") PositionEntity torus,0,0,5 EntityTexture torus, pla Repeat TurnEntity torus,1,2,3 UpdateWorld RenderWorld Flip Until KeyDown(1) End Function CreateTorus(Radius1#=1,Radius2#=0.5,Segments1=10,Segments2=10) Local XPos1#,YPos1#,XPos2#,YPos2#,X1#,Y1#,Z1#,X2#,Y2#,Z2#,X3#,Y3#,Z3#,X4#,Y4#,Z4#,V1,V2,V3,V4 Local torus = CreateMesh() Local surface = CreateSurface(torus) i = 0 Repeat i=i+(360 / Segments2) XPos1# = Cos(i) * Radius2# + Radius1# YPos1# = Sin(i) * Radius2# + Radius1# XPos2# = Cos(i + (360 / Segments2)) * Radius2# + Radius1# YPos2# = Sin(i + (360 / Segments2)) * Radius2# + Radius1# j = 0 Repeat j = j+(360 / Segments1) X1# = Cos(j) * XPos1# Y1# = YPos1# Z1# = Sin(j) * XPos1# X2# = Cos(j + (360 / Segments1)) * XPos1# Y2# = YPos1# Z2# = Sin(j + (360 / Segments1)) * XPos1# X3# = Cos(j) * XPos2# Y3# = YPos2# Z3# = Sin(j) * XPos2# X4# = Cos(j + (360 / Segments1)) * XPos2# Y4# = YPos2# Z4# = Sin(j + (360 / Segments1)) * XPos2# V1 = AddVertex(surface,X1#,Y1#,Z1#, 0, 1) V2 = AddVertex(surface,X2#,Y2#,Z2#, 1, 1) V3 = AddVertex(surface,X3#,Y3#,Z3#) V4 = AddVertex(surface,X4#,Y4#,Z4#) AddTriangle(surface,V3,V2,V1) AddTriangle(surface,V4,V2,V3) Until j > 360 - (360 / Segments1) Until i > 360 - (360 / Segments2) UpdateNormals torus PositionMesh torus,0,-Radius1#,0 Return torus End Function[/code:1:1ef7d05b87] cu, ST. |
von ??? |
Und was bringen jetzt diese 2 Zeilen mehr? :shock: An der Funktion(um die es geht) hast du doch nix verändert, oder hab ich da was übersehen? Mfg Skate |
von ??? |
Moin. [code:1:906dc624bf] V1 = AddVertex(surface,X1#,Y1#,Z1#, 0, 1) V2 = AddVertex(surface,X2#,Y2#,Z2#, 1, 1)[/code:1:906dc624bf] Da wo jetzt "0, 1" und "1, 1" steht, habe ich die UV Map fest gelegt. Kannts ja gerne versuchen bei deiner oben geposteten Routine eine Textur zu laden. Da wird nur die Farbe kommen. Aber die Parameter bei AddVertex bei V1 und V2 bestimmen die UV Map. Dadurch weis DirectX welchen teil der Textur auf das Polygon gerendert werden soll. cu, ST. |
von ??? |
Ohh, hab nur auf die einzellnen Zeilen geschaut, sorry :) |
von ??? |
Schon ok! :) cu, ST. |
von ??? |
He, wenn du plaudern willst dann im Chat! Spam hier nciht meine schöne Funktion zu :) |
von ??? |
Du hast doch damit angefangen! ;) cu, ST. |
von ??? |
lol sauber ST ^^ |