Beispiel #1
0
        public override IEnumerator <Triangle> GetEnumerator()
        {
            double angularStep = 2 * Math.PI / Resolution;
            var    basis       = new Basis();
            var    id          = Transformation.Identity();

            basis = new Basis(Quat.FromToRotation(Vec3.K, this.Original.Tangent(0)) * id);

            for (float t = StepDistance; t <= 1; t += StepDistance)
            {
                var previousFrontVec = basis.Y;
                var previousSideVec  = basis.X;

                basis = new Basis(Quat.FromToRotation(Vec3.K, this.Original.Tangent(t)) * id);
                var nextFrontVec = basis.Y;
                var nextSideVec  = basis.X;

                for (int i = 1; i <= Resolution; i++)
                {
                    // Position on 2D XY plane
                    double previousAngle = (i - 1) * angularStep;
                    double xi            = TubeRadius * Math.Cos(previousAngle);
                    double yi            = TubeRadius * Math.Sin(previousAngle);

                    double nextAngle = (i) * angularStep;
                    double xe        = TubeRadius * Math.Cos(nextAngle);
                    double ye        = TubeRadius * Math.Sin(nextAngle);

                    // Convert to 3D positions
                    Vec3 previousMidline = this.Original[t - StepDistance];
                    Vec3 nextMidline     = this.Original[t];

                    Vec3 be = previousMidline + previousFrontVec * ye + previousSideVec * xe;
                    Vec3 bi = previousMidline + previousFrontVec * yi + previousSideVec * xi;
                    Vec3 te = nextMidline + nextFrontVec * ye + nextSideVec * xe;
                    Vec3 ti = nextMidline + nextFrontVec * yi + nextSideVec * xi;

                    /* CREATE TRIANGLES
                     *  te -- ti
                     |   /  |
                     |  /   |
                     |  be -- bi
                     */
                    yield return(new Triangle(be, te, ti));

                    yield return(new Triangle(be, ti, bi));
                }
            }
        }
Beispiel #2
0
 public Vec3 VectorToLocal(Vec3 point)
 {
     return(Quat.Inverse(Quat.FromToRotation(Vec3.right, this.property.direction)) * point);
 }
Beispiel #3
0
 public Vec3 VectorToWorld(Vec3 point)
 {
     return(Quat.FromToRotation(Vec3.right, this.property.direction) * point);
 }
Beispiel #4
0
 public Vec3 PointToLocal(Vec3 point)
 {
     return(Quat.Inverse(Quat.FromToRotation(Vec3.right, this.property.direction)) * (point - this.property.position));
 }
Beispiel #5
0
 public Vec3 PointToWorld(Vec3 point)
 {
     return(this.property.position + Quat.FromToRotation(Vec3.right, this.property.direction) * point);
 }
Beispiel #6
0
        public void Quat4()
        {
            FQuat fq  = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88));
            FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f));
            Quat  q   = Quat.Euler(45, -23, -48.88f);
            Quat  q2  = Quat.Euler(23, -78, -132.43f);
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(1, 0, 0);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(1, 0, 0);

            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            this._output.WriteLine(fq2.ToString());
            this._output.WriteLine(q2.ToString());
            Fix64 fa = FQuat.Angle(fq, fq2);
            float a  = Quat.Angle(q, q2);

            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv);
            q  = Quat.AngleAxis(-123.324f, v);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fa = FQuat.Dot(fq, fq2);
            a  = Quat.Dot(q, q2);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.FromToRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Lerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Normalize(fq);
            q.Normalize();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.Inverse();
            q = Quat.Inverse(q);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fv = FQuat.Orthogonal(fv);
            v  = Quat.Orthogonal(v);
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Slerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.LookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.ToAngleAxis(out fa, out fv);
            q.ToAngleAxis(out a, out v);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = fq.Conjugate();
            q  = q.Conjugate();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.SetLookRotation(FVec3.Normalize(fv), fv2);
            q.SetLookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
        }
Beispiel #7
0
 public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection)
 {
     this = Quat.FromToRotation(fromDirection, toDirection);
 }
Beispiel #8
0
        public override IEnumerator <Triangle> GetEnumerator()
        {
            var    extruding   = false;
            var    id          = Transformation.Identity();
            double angularStep = 2 * Math.PI / Resolution;
            var    basis       = new Basis();

            // Print head
            var  x        = 0.0;
            var  y        = 0.0;
            var  z        = 0.0;
            bool relative = false;

            foreach (var command in this.Original)
            {
                if (command.Type != 'G')
                {
                    continue;
                }

                switch (command.Number)
                {
                case 90:
                    // Behaviour is MoveTo
                    relative = false;
                    break;

                case 91:
                    // Behaviour is MoveBy
                    relative = true;
                    break;

                case 0:
                    if (extruding)
                    {
                        // Create end cap at the previous position
                    }

                    if (command.X.HasValue)
                    {
                        x = command.X.Value + (relative ? x : 0);
                    }
                    if (command.Y.HasValue)
                    {
                        y = command.Y.Value + (relative ? y : 0);
                    }
                    if (command.Z.HasValue)
                    {
                        z = command.Z.Value + (relative ? z : 0);
                    }

                    extruding = false;
                    break;

                case 1:
                    if (!extruding)
                    {
                        // Create start cap at the new position
                    }
                    var  start   = new Vec3(x, y, z);
                    bool changed = false;

                    if (command.X.HasValue)
                    {
                        x       = command.X.Value + (relative ? x : 0);
                        changed = true;
                    }
                    if (command.Y.HasValue)
                    {
                        y       = command.Y.Value + (relative ? y : 0);
                        changed = true;
                    }
                    if (command.Z.HasValue)
                    {
                        z       = command.Z.Value + (relative ? z : 0);
                        changed = true;
                    }
                    var end = new Vec3(x, y, z);

                    // Didn't actually move or not actually extruding
                    if (!changed || start == end || !command.E.HasValue)
                    {
                        continue;
                    }

                    // New extrusion, new starting basis, otherwise if continuing, reuse last basis
                    if (!extruding)
                    {
                        basis = new Basis(Quat.FromToRotation(Vec3.K, end - start) * id);
                    }

                    for (int i = 1; i <= Resolution; i++)
                    {
                        double previousAngle = (i - 1) * angularStep;
                        double xi            = TubeRadius * Math.Cos(previousAngle);
                        double yi            = TubeRadius * Math.Sin(previousAngle);

                        double nextAngle = (i) * angularStep;
                        double xe        = TubeRadius * Math.Cos(nextAngle);
                        double ye        = TubeRadius * Math.Sin(nextAngle);

                        Vec3 be = start + basis.Y * ye + basis.X * xe;
                        Vec3 bi = start + basis.Y * yi + basis.X * xi;

                        basis = new Basis(Quat.FromToRotation(Vec3.K, end - start) * id);
                        Vec3 te = end + basis.Y * ye + basis.X * xe;
                        Vec3 ti = end + basis.Y * yi + basis.X * xi;

                        yield return(new Triangle(be, te, ti));

                        yield return(new Triangle(be, ti, bi));
                    }

                    extruding = true;
                    break;

                default:
                    continue;
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// Look at a point in world space
 /// </summary>
 /// <param name="position">world space position</param>
 public void LookAt(Vec3 position)
 {
     this.Rotate(Quat.FromToRotation(this.Basis.Y, position - this.LocalPosition));
 }