4 element mathematical vector.
Example #1
0
 public double Dot(Vector vector)
 {
     return this.X * vector.X +
            this.Y * vector.Y +
            this.Z * vector.Z +
            this.W * vector.W;
 }
Example #2
0
 public Vector Multiply(Vector vector)
 {
     return new Vector(m11 * vector.X + m12 * vector.Y + m13 * vector.Z + m14 * vector.W,
                       m21 * vector.X + m22 * vector.Y + m23 * vector.Z + m24 * vector.W,
                       m31 * vector.X + m32 * vector.Y + m33 * vector.Z + m34 * vector.W,
                       m41 * vector.X + m42 * vector.Y + m43 * vector.Z + m44 * vector.W);
 }
Example #3
0
 public override List<Triangle> GetTriangles()
 {
     List<Triangle> triangles = new List<Triangle>();
     foreach (int[] pArray in ps) {
         for (int pBaseIndex = 0; pBaseIndex < pArray.Length; pBaseIndex += 3 * pStride) {
             int indexA = pArray[pBaseIndex + 0 * pStride + positionOffset];
             int indexB = pArray[pBaseIndex + 1 * pStride + positionOffset];
             int indexC = pArray[pBaseIndex + 2 * pStride + positionOffset];
             Vector a = new Vector(positions[3 * indexA], positions[3 * indexA + 1], positions[3 * indexA + 2]);
             Vector b = new Vector(positions[3 * indexB], positions[3 * indexB + 1], positions[3 * indexB + 2]);
             Vector c = new Vector(positions[3 * indexC], positions[3 * indexC + 1], positions[3 * indexC + 2]);
             triangles.Add(new Triangle(a, b, c));
         }
     }
     return triangles;
 }
Example #4
0
        public void Animate()
        {
            foreach(object item in this.Items) {
                Channel channel = item as Channel;
                if (channel != null) {
                    Sampler sampler = Sampler.IDs[channel.Source.Remove(0,1)];
                    float[] input = null;
                    float[] output = null;
                    float[] inTangent = null;
                    float[] outTangent = null;
                    string[] interpolation = null;
                    foreach(InputLocal samplerInput in sampler.Input) {
                        Source source = Source.IDs[samplerInput.Source.Remove(0,1)];
                        switch(samplerInput.Semantic) {
                            case "INPUT": input = ((FloatArray)source.Item).ValuesAsFloats; break;
                            case "OUTPUT": output = ((FloatArray)source.Item).ValuesAsFloats; break;
                            case "IN_TANGENT": inTangent = ((FloatArray)source.Item).ValuesAsFloats; break;
                            case "OUT_TANGENT": outTangent = ((FloatArray)source.Item).ValuesAsFloats; break;
                            case "INTERPOLATION": interpolation = ((NameArray)source.Item).Values; break;
                        }
                    }

                    float time = (float)GlobalSettings.RunningTime.TotalSeconds;
                    time = time % input[input.Length - 1];
                    int index = -1;
                    for(int i = 0; i < input.Length - 1; i++) {
                        if (input[i] <= time && time < input[i+1]) {
                            index = i;
                            break;
                        }
                    }
                    if (index != -1) {
                        // Bezier interpolation. See https://collada.org/public_forum/viewtopic.php?t=559
                        float s = (time - input[index]) / (input[index+1] - input[index]);
                        Math.Vector S = new Math.Vector(s*s*s, s*s, s, 1);
                        Math.Matrix M = new Math.Matrix(-1,  3, -3,  1,
                                                         3, -6,  3,  0,
                                                        -3,  3,  0,  0,
                                                         1,  0,  0,  0);
                        Math.Vector C = new Math.Vector(output[index],
                                                        output[index] + outTangent[index] / 3,
                                                        output[index+1] - inTangent[index+1] / 3,
                                                        output[index+1]);
                        double interpolatedValue = S * (M * C);

                        string[] target = channel.Target.Split(new char[] {'/', '.'});
                        string id = target[0];
                        string sid = target[1];
                        string property = target[2];
                        if (Node.IDs.ContainsKey(id)) {
                            Node node = Node.IDs[id];
                            foreach(object transform in node.Items) {
                                if (transform is Rotate && ((Rotate)transform).Sid == sid) {
                                    double[] values = ((Rotate)transform).Values;
                                    values[3] = interpolatedValue;
                                    ((Rotate)transform).Text = "";
                                    foreach(double val in values) {
                                        ((Rotate)transform).Text += val.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #5
0
 public Triangle(Vector a, Vector b, Vector c)
 {
     this.a = a;
     this.b = b;
     this.c = c;
 }