public void writeWithInterpolationBuffer(InterpolationBuffer buffer, Vector3 prevDevOut, Vector3 postDevOut) { requestSize(buffer.N + 1); for (int i = 0; i <= buffer.N; i++) { //cyForward[i] = new CPIMatrix(buffer.normals[i], buffer.devs[i], prevDevOut); //cyBackward[i] = new CPIMatrix(buffer.normals[i], buffer.devs[i], postDevOut); cyForward[i] = new CPIMatrix(buffer.normals[i], buffer.normals[0], prevDevOut); cyBackward[i] = new CPIMatrix(buffer.normals[i], buffer.normals[buffer.N], postDevOut); } }
public void Set(InterpolationBuffer buffer, InterpolationBuffer prev, InterpolationBuffer next) { this.buffer = buffer; this.prev = prev; this.next = next; //s0 = 1; Vector3 A0 = buffer.vertices[0]; Vector3 AN = buffer.vertices[buffer.N]; Vector3 B = prev.vertices[0]; Vector3 C = next.vertices[next.N]; //Vector3 B_AB = A0 - CPNGuideEvaluator.ONE_THIRD * prev.devLast; Vector3 B_BA = B + CPNGuideEvaluator.ONE_THIRD * prev.devFirst; //Vector3 C_AB = AN + CPNGuideEvaluator.ONE_THIRD * next.devFirst; Vector3 C_BA = C - CPNGuideEvaluator.ONE_THIRD * next.devLast; s1 = 3; s2 = 3; s3 = 1; //float distance0 = Vector3.Distance(A0, AN); float distance0 = Vector3.Dot(A0 - AN, A0 - AN); if (distance0 > 0) { //this.s1 = 1.5f + 1.5f * Vector3.Dot(B_AB - C_AB, B_AB - C_AB) / distance0; //this.s2 = 1.5f + 1.5f * (Vector3.Dot(B_BA - C_BA, B_BA - C_BA) / distance0); this.s3 = Vector3.Dot(B - C, B - C) / distance0; //this.s1 = 3.0f + 0.0f * Vector3.Dot(B_AB - C_AB, B_AB - C_AB) / distance0; this.s2 = (3f - ShapeControlValue) + ShapeControlValue * (Vector3.Dot(B_BA - C_BA, B_BA - C_BA) / distance0); } firtsOrder = new Vector3[buffer.N + 1]; Vector3 DBs = -prev.devLast; Vector3 DCs = next.devFirst; Vector3 N0 = buffer.normals[0]; Vector3 NN = buffer.normals[buffer.N]; Vector3 axis0 = buffer.axis[0]; Vector3 axisN = buffer.axis[buffer.N]; float step = buffer.step; //So: now the 'First order' is wrong. for (int i = 0; i < firtsOrder.Length; i++) { float t = i * step; Vector3 delta = (1 - t) * DBs + t * DCs; Vector3 A = buffer.vertices[i]; Vector3 N = buffer.normals[i]; Vector3 axis = buffer.axis[i]; //firtsOrder[i] = getFirstOrder(N, N0, NN, DBs, DCs, axis0, axisN, axis, t); //private Vector3 getFirstOrder(Vector3 N, Vector3 N0, Vector3 NN, Vector3 DB0, Vector3 DBN, // Vector3 axis0, Vector3 axisN, Vector3 axis, float t) //{ //Vector3 At = (1 - t) * A0 + t * AN; //Vector3 PA = (A - At) * size; //Vector3 PBC = (1 - t) * B + t * C; //if (CPNCornerSet.applySecondOrderControl) // return PA + PBC + firstOrder * (1 - s) * (1 - s) * s /** (1 - s * s)+ // ((1 - t) * B + t * C ) * (s * s)*/; Vector3 Delta = DBs * (1 - t) + DCs * t + (s1 - 3) * (A - A0 * (1 - t) - AN * t); Vector3 CorrectDelta = Delta * buffer.thickness - Vector3.Dot(N, Delta) * N; firtsOrder[i] = CorrectDelta - Delta; } }
public void Set(InterpolationBuffer bufferA, InterpolationBuffer bufferB) { this.bufferA = bufferA; this.bufferB = bufferB; int sizeA = bufferA.N; int sizeB = bufferB.N; if (cyA.Length < sizeA + 1) { cyA = new CurvedCorrection[sizeA + 1]; } if (cyB.Length < sizeB + 1) { cyB = new CurvedCorrection[sizeB + 1]; } Vector3 v0 = bufferA.vertices[0]; Vector3 normal0 = bufferA.normals[0]; Vector3 DA0 = bufferA.devFirst; Vector3 DB0 = -bufferB.devLast; for (int i = 0; i <= sizeA; i++) { cyA[i] = new CurvedCorrection(bufferA.normals[i], normal0, DB0, v0, bufferA.vertices[i], bufferA.devs[i], bufferA.axis[0], bufferA.axis[i]); } for (int backBIndex = 0; backBIndex <= sizeB; backBIndex++) { cyB[backBIndex] = new CurvedCorrection(bufferB.normals[backBIndex], normal0, DA0, v0, bufferB.vertices[backBIndex], bufferB.devs[backBIndex], -bufferB.axis[sizeB], -bufferB.axis[backBIndex]); } Vector3 finalA = bufferA.vertices[bufferA.N]; Vector3 finalNA = bufferA.normals[bufferA.N]; Vector3 finalB = bufferB.vertices[0]; Vector3 finalNB = bufferB.normals[0]; finalAB = (finalB - finalA) * 0.333333f; finalBA = -finalAB; finalAB = finalAB - Vector3.Dot(finalAB, finalNA) * finalNA; finalBA = finalBA - Vector3.Dot(finalBA, finalNB) * finalNB; float distance = Vector3.Distance(finalA, finalB) * 0.707107f; finalAB = finalAB * (0.58578643762f) * distance / finalAB.magnitude; finalBA = finalBA * (0.58578643762f) * distance / finalBA.magnitude; float weight = 0.80473785f; finalAB = finalAB + finalA; finalBA = finalBA + finalB; float t = 0; int index = 0; for (int i = 0; i <= sizeA; i++) { int Aindex = i; float U = bufferA.ts[Aindex]; float V = 1 - U;//This is pretty important. Vector3 vA = bufferA.vertices[Aindex]; GetInterpolation(1 - V, bufferB.N, out t, out index); Vector3 vB = bufferB.vertices[index] * (1 - t) + bufferB.vertices[index + 1] * (t); Vector3 firstOrder = cyA[Aindex].firstOrder; Vector3 finalPosition = vA + vB - v0 + firstOrder * V; Vector3 realFinalPosition = (U * U * U * finalA + 3 * U * U * V * weight * finalAB + 3 * U * V * V * weight * finalBA + V * V * V * finalB) / (U * U * U + 3 * U * U * V * weight + 3 * U * V * V * weight + V * V * V); cyA[Aindex].secondOrder2 = realFinalPosition - finalPosition; cyA[Aindex].secondOrder2 *= cyA[Aindex].secondOrderCorrectorModulation; cyA[Aindex].secondOrder2Factor = i == sizeA ? 0 : 1 / V; } for (int i = 0; i <= sizeB; i++) { int backBIndex = bufferB.N - i; float V = 1 - bufferB.ts[backBIndex]; float U = 1 - V; Vector3 vB = bufferB.vertices[backBIndex]; GetInterpolation(U, bufferA.N, out t, out index); Vector3 vA = bufferA.vertices[index] * (1 - t) + bufferA.vertices[index + 1] * (t); Vector3 firstOrder = cyB[backBIndex].firstOrder; Vector3 finalPosition = vB + vA - v0 + firstOrder * U; Vector3 realFinalPosition = (U * U * U * finalA + 3 * U * U * V * weight * finalAB + 3 * U * V * V * weight * finalBA + V * V * V * finalB) / (U * U * U + 3 * U * U * V * weight + 3 * U * V * V * weight + V * V * V); cyB[backBIndex].secondOrder2 = realFinalPosition - finalPosition; cyB[backBIndex].secondOrder2 *= cyB[backBIndex].secondOrderCorrectorModulation; cyB[backBIndex].secondOrder2Factor = i == sizeB ? 0 : 1 / U; } }
public void Set(InterpolationBuffer buffer, InterpolationBuffer prev, InterpolationBuffer next) { this.buffer = buffer; this.prev = prev; this.next = next; //s0 = 1; //Normal and Vector at the beginnig of A (where B begins) Vector3 A0 = buffer.vertices[0]; Vector3 A0N = buffer.normals[0]; //Normal and Vector at the end of A (A Final, where C begins) Vector3 AF = buffer.vertices[buffer.N]; Vector3 AFN = buffer.normals[buffer.N]; //Normal and Vector on the opposite end of B (B Final) Vector3 BNF = prev.normals[0]; Vector3 BF = prev.vertices[0]; //Normal and Vector on the opposite end of C (C Final) Vector3 CNF = next.normals[next.N]; Vector3 CF = next.vertices[next.N]; BTransforms = new CPDerivativeRotationMatrix[buffer.N + 1]; CTransforms = new CPDerivativeRotationMatrix[buffer.N + 1]; resize = new float[buffer.N + 1]; // Vector3 Ortho = AF - A0; //CPNormalsRotationMatrix BFRot = new CPNormalsRotationMatrix(A0N, BNF, Ortho); //CPNormalsRotationMatrix CFRot = new CPNormalsRotationMatrix(AFN,CNF, Ortho); float BResize = Vector3.Dot(buffer.devFirst.normalized, -prev.devLast.normalized); float CResize = Vector3.Dot(-buffer.devLast.normalized, next.devFirst.normalized); BResize = 1 - BResize * 0.5f; CResize = 1 - CResize * 0.5f; //Distance between BF and A0 //float sizeB = Vector3.Magnitude(BF - A0); //Distance between CF and AF //float sizeC = Vector3.Magnitude(CF - AF); Vector3 DB0 = -prev.devLast.normalized; Vector3 DC0 = next.devFirst.normalized; float step = 1.0f / buffer.N; for (int i = 0; i <= buffer.N; i++) { Vector3 normal = buffer.normals[i]; BTransforms[i] = new CPDerivativeRotationMatrix(normal, DB0); CTransforms[i] = new CPDerivativeRotationMatrix(normal, DC0); float t = i * step; float tm = 1 - t; //resize[i] = t * t * t + tm * tm * tm + 3 * t * tm * (tm * BResize + t * CResize); //Anche questo resize รจ inutile sai? resize[i] = t * t + tm * tm + 2 * t * tm * (BResize + CResize); resize[i] = 1; //Vector3 A = buffer.vertices[i]; //Vector3 AB = BFRot.Rotate(A - A0) + BF; //Vector3 AC = CFRot.Rotate(A - AF) + CF; //Vector3 Aend = AB * (1 - t) + AC * t; //float expectedSize = sizeB * (1 - t) + sizeC * t; //float size = Vector3.Magnitude(Aend - A); //resize[i] = size / expectedSize; } }
public NGonInterpolation(int sides) { this.sides = sides; this.cos_ = new float[sides]; this.sin_ = new float[sides]; //actually : angle dimension for the center piece float alpha = 2 * Mathf.PI / sides; //O, wow. what is dX2 = 1.5f? float dX2 = 1.5f; //Cos and sin of angle. Good float dx1 = (float)Mathf.Cos(alpha); float dy1 = (float)Mathf.Sin(alpha); //Need to understand the meaning of a and b this.a = 1.0f / (dX2 * dX2); this.b = ((1 - a * dx1 * dx1) / (dy1 * dy1)); //absolutely clear this is for (int i = 0; i < sides; i++) { cos_[i] = (float)Mathf.Cos(-alpha * i); sin_[i] = (float)Mathf.Sin(-alpha * i); } { //here we calculate the cornerCoordsMatrix, which is //the reciproc matrix to // | cos_[sides-1] - cos_[0] sin_[sides-1] - sin_[0]| // | cos_[1] - cos_[0] sin_[1] - sin_[0]| int i = 0; int next = 1; int prev = sides - 1; float a = cos_[prev] - cos_[i]; float b = sin_[prev] - sin_[i]; float c = cos_[next] - cos_[i]; float d = sin_[next] - sin_[i]; float det = a * d - b * c; float recDelta = 1.0f / det; cornerCoordsMatrix[0] = d * recDelta; cornerCoordsMatrix[1] = -b * recDelta; cornerCoordsMatrix[2] = -c * recDelta; cornerCoordsMatrix[3] = a * recDelta; //wait float length1 = (cornerCoordsMatrix[0] * cornerCoordsMatrix[0] + cornerCoordsMatrix[1] * cornerCoordsMatrix[1]); float length2 = (cornerCoordsMatrix[2] * cornerCoordsMatrix[2] + cornerCoordsMatrix[3] * cornerCoordsMatrix[3]); relativeTriangleFactorX = (cornerCoordsMatrix[0] * (-1)); relativeTriangleFactorY = (cornerCoordsMatrix[3] * (-1)); } this.val = new float[sides]; //cornerSurfacesSet.Init(sides); tmpInterpolations = new Vector3[sides]; tmpInterpolationsUV = new Vector3[sides]; buffers = new InterpolationBuffer[sides]; backBuffers = new InterpolationBuffer[sides]; for (int i = 0; i < tmpInterpolations.Length; i++) { buffers[i] = new InterpolationBuffer(); backBuffers[i] = new InterpolationBuffer(); } slicePosition = new int[sides]; }
private float GetBufferLength(InterpolationBuffer buffer) { return(Vector3.Distance(buffer.vertices[0], buffer.vertices[buffer.N])); }