Quake3 Curved Surfaces - BiQuadratic Bézier Patches
-
Hi!
Ich habe das Problem, das ich anscheinend die Curved Surfaces falsch tesseliere...Die Methode dazu(ich musste mal meine minderwetigen C++ Kentnisse nutzen):
class CBiQuadPatch { public: float Points[3][3][3]; // 3x3 ControlPoints float Vertices[][][]; // Vertices int Indices[][][]; // Indices void Tesselate(int Tesselation); } Tesselate::CBiQuadPatch(int Tesselation) { int V, U; float TV, TU; float Temp[3][3] int Index; // Allocate Memory this.Vertices = new float[Tesselation+1][Tesselation+1][3]; this.Indices = new int[Tesselation][Tesselation][6]; // Calculate Vertices for(V = 0; V < (Tesselation+1); V++) { // TV = 0.0 ... 1.0 TV = float(V)/float(Tesselation); // Temp Points for(Index = 0; Index < 3; Index++) { // Temp X (quadratic interpolation) Temp[Index, 0] = this.Points[0, Index, 0]*((1.0f-TV)*(1.0f-TV)) + this.Points[1, Index, 0]*2.0f*TV*(1.0f-TV) + this.Points[2, Index, 0]*(TV*TV); // Temp Y (quadratic interpolation) Temp[Index, 1] = this.Points[0, Index, 1]*((1.0f-TV)*(1.0f-TV)) + this.Points[1, Index, 1]*2.0f*TV*(1.0f-TV) + this.Points[2, Index, 1]*(TV*TV); // Temp Z (linear interpolation) Temp[Index, 2] = this.Points[0, Index, 2]*(1.0f-TV) + this.Points[2, Index, 2]*TV; } for(U = 0; U < (Tesselation+1); U++) { // TU = 0.0 ... 1.0 TU = float(U)/float(Tesselation); // Vertex X (linear interpolation) this.Vertices[V, U, 0] = Temp[0, 0]*(1.0f-TU) + Temp[2, 0]*TU; // Vertex Y (quadratic interpolation) this.Vertices[V, U, 1] = Temp[0, 1]*((1.0f-TU)*(1.0f-TU)) + Temp[1, 1]*2.0f*TU*(1.0f-TU)+ Temp[2, 1]*(TU*TU); // Vertex Z (quadratic interpolation) this.Vertices[V, U, 2] = Temp[0, 2]*((1.0f-TU)*(1.0f-TU)) + Temp[1, 2]*2.0f*TU*(1.0f-TU)+ Temp[2, 2]*(TU*TU); } } for(V = 0; V < Tesselation; V++) { for(U = 0; U < Tesselation; U++) { // Triangle 0 this.Indices[V, U, 0] = (V+1)*(Tesselation+1)+U+1; this.Indices[V, U, 1] = V*(Tesselation+1)+U+1; this.Indices[V, U, 2] = V*(Tesselation+1)+U; // Triangle 1 this.Indices[V, U, 3] = V*(Tesselation+1)+U; this.Indices[V, U, 4] = (V+1)*(Tesselation+1)+U; this.Indices[V, U, 5] = (V+1)*(Tesselation+1)+U+1; } } }
Man hat also 3x3 Controlpoints gegeben, und diese soll man mit Hilfe von Bézierkurven tesselieren.
Ich fahre den Patch von hinten nach vorne linear ab. Dabei berechne ich die Temppoints. Aus diesen Temppoints werden dann die Positionen der Vertices errechnet.
Dazu noch die Formel:
f(t) = P0*(1-t)² + P1*2t(1-t) + P2*t²Die Kurve geht durch die Punkte P0 und P2. P1 gibt dabei das Verhalten der Kurve an.
Hier nun das Bild zur Verdeutlichung:
http://www.blitz-pasting.net/uploads/useruploads/oapRz63633021104926_curved4.gif
(q3dm1.bps, Tesselierung = 5)mfg olli
-
Du könntest doch mal den Fehler, den ich nicht erkenne, beseitigen?
Bye, TGGC (Demo or Die)
-
Man muss anscheinend alles quadartisch interpolieren. Sprengt jetzt ersteinmal mein Vorstellungsvermögen, aber die Torbögen von q3dm1 sind nun richtig. Mein erwartetes Resultat, das noch die Zunge zu sehen ist aus dem Level, ist jedoch noch nicht eingetreten.
Das Problem ist, in 3D zu debuggen ist echt die Qual, zumal ich hier so einen scheiß Debugger hat, der Arrayinhalte mit "[...]" darstellt.
mfg olli
-
Boar, jetzt ist es mir wie Schuppen von den Augen gefallen, ich hatte immer die Controlpoints falsch geladen, wenn ein Face mehrere Patches hatte.
Ich glaube hierfür könnte ich echtmal ein Tutorial schreiben, über BSP(event. wie man ein Compiler schreibt mit illegal geometrie removing inkl.) das Dateiformat, PVS, Culling und natürlich das Rendern. Das kommt dann als techn. Informationen zu meiner 3D Engine.
mfg olli
-
Gute Idee. Dabei kannst Du auch gleichzeitig Leafs zu Blaettern umbenennen.