Ejemplo n.º 1
0
        public void ApplyAnimationToPose(List <SkeletonJoint> pose)
        {
            if (pose.Count != m_animationData.Count)
            {
                Console.WriteLine("Mis-matched number of joints in pose and number of joints in animation!");
            }

            int numJoints = Math.Min(pose.Count, m_animationData.Count);

            float ftime = (m_timeSinceStartedPlaying * kAnimFramerate) % AnimLengthInFrames;

            for (int i = 0; i < numJoints; i++)
            {
                pose[i].Scale = new Vector3(GetAnimValue(m_animationData[i].ScalesX, ftime), GetAnimValue(m_animationData[i].ScalesY, ftime), GetAnimValue(m_animationData[i].ScalesZ, ftime));

                Vector3 rot = new Vector3(GetAnimValue(m_animationData[i].RotationsX, ftime), GetAnimValue(m_animationData[i].RotationsY, ftime), GetAnimValue(m_animationData[i].RotationsZ, ftime));

                // ZYX order
                pose[i].Rotation = Quaternion.FromAxisAngle(new Vector3(0, 0, 1), WMath.DegreesToRadians(rot.Z)) *
                                   Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(rot.Y)) *
                                   Quaternion.FromAxisAngle(new Vector3(1, 0, 0), WMath.DegreesToRadians(rot.X));

                Vector3 translation = new Vector3(GetAnimValue(m_animationData[i].TranslationsX, ftime), GetAnimValue(m_animationData[i].TranslationsY, ftime), GetAnimValue(m_animationData[i].TranslationsZ, ftime));

                pose[i].Translation = translation;
            }
        }
Ejemplo n.º 2
0
        public static void PlaceStructure(Structure structure, Vector3I position, bool eraseSolid = false)
        {
            Vector3I shift   = structure.Root;
            Vector3I origin  = position - shift;
            Vector3I extents = structure.Size;

            ConcurrentDictionary <Vector2I, Chunk> chunkCache = new ConcurrentDictionary <Vector2I, Chunk>();

            ushort[] blocks = structure.Blocks;

            ushort airID = ItemCache.GetIndex("winecrash:air");

            Parallel.For(0, blocks.Length, i =>
            {
                WMath.FlatTo3D(i, extents.X, extents.Y, out int localX, out int localY, out int localZ);

                Vector3I globalBpos = new Vector3I(localX, localY, localZ) + origin;

                GlobalToLocal(globalBpos, out Vector2I cpos, out Vector3I bpos);

                Chunk c;
                if (!chunkCache.TryGetValue(cpos, out c))
                {
                    c = GetChunk(cpos, "winecrash:overworld");
                    chunkCache.TryAdd(cpos, c);
                }

                if (c && (eraseSolid || c.GetBlockIndex(bpos.X, bpos.Y, bpos.Z) == airID))
                {
                    c.SetBlock(bpos.X, bpos.Y, bpos.Z, blocks[i]);
                }
            });
Ejemplo n.º 3
0
        private static ushort[] Populate(Vector2I chunkCoords, ushort[] indices, Vector3I[] surfaces)
        {
            double treeDensity = 0.005D;

            int chunkHash = chunkCoords.GetHashCode() * Seed.Value;

            Random    treeRandom = new Random(chunkHash);
            Structure tree       = Structure.Get("Tree");

            ushort dirtID  = ItemCache.GetIndex("winecrash:dirt");
            ushort grassID = ItemCache.GetIndex("winecrash:grass");
            ushort debugID = ItemCache.GetIndex("winecrash:direction");

            // do trees
            for (int i = 0; i < surfaces.Length; i++)
            {
                int  flatten = WMath.Flatten3D(surfaces[i].X, surfaces[i].Y, surfaces[i].Z, Chunk.Width, Chunk.Height);
                bool doTree  = treeRandom.NextDouble() < treeDensity;

                if ((indices[flatten] == dirtID || indices[flatten] == grassID) && doTree)
                {
                    indices[flatten] = dirtID;

                    PlaceStructure(tree, LocalToGlobal(chunkCoords, new Vector3D(surfaces[i].X, surfaces[i].Y + 1, surfaces[i].Z)), false);
                }
            }

            return(indices);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //new ArchiveResourceToCSV(@"E:\New_Data_Drive\WindwakerModding\new_object_extract\res\extracted_archives\Object");
            //new ArcExtractorDebugging(@"E:\New_Data_Drive\WindwakerModding\root\res\Object\ff.arc");
            //Quaternion negQuat = Quaternion.FromAxisAngle(new Vector3(1, 0, 0), WMath.DegreesToRadians(-0)) * Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(-179)) * Quaternion.FromAxisAngle(new Vector3(0, 1, 0), -3.1415f) * Quaternion.FromAxisAngle(new Vector3(0, 0, 1), WMath.DegreesToRadians(-179));
            //Quaternion negQuat = Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(-165));
            //Console.WriteLine("Yaw: {0}", WMath.RadiansToDegrees(YawFromQuat(negQuat)));

            for(int i = 180; i >= -180; i-=5)
            {
                //Quaternion quat = Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(i));
                Quaternion xQuat = FromEulerAngles(new Vector3(i, 0, 0));
                Quaternion yQuat = FromEulerAngles(new Vector3(0, i, 0));
                Quaternion zQuat = FromEulerAngles(new Vector3(0, 0, i));
                //Console.WriteLine("In: {0} Out: {1:0},{2:0},{3:0}", i, WMath.RadiansToDegrees(PitchFromQuat(zQuat)), WMath.RadiansToDegrees(YawFromQuat(yQuat)), WMath.RadiansToDegrees(RollFromQuat(xQuat)));
                Console.WriteLine("In: {0} Out: {1:0},{2:0},{3:0}", i, WMath.RadiansToDegrees(PitchFromQuat(yQuat)), WMath.RadiansToDegrees(YawFromQuat(yQuat)), WMath.RadiansToDegrees(RollFromQuat(yQuat)));
            }

            //negQuat = Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(28));
            //Console.WriteLine("Yaw: {0}", WMath.RadiansToDegrees(YawFromQuat(negQuat)));

            //Vector3 eulAngles = EulerAnglesFromQuat(negQuat);
            //Console.WriteLine("Euler Angles from Quat: {0},{1},{2}", WMath.RadiansToDegrees(eulAngles.X), WMath.RadiansToDegrees(eulAngles.Y), WMath.RadiansToDegrees(eulAngles.Z));
            //Vector3 negEuler = new Vector3(WMath.RadiansToDegrees(PitchFromQuat(negQuat)), WMath.RadiansToDegrees(YawFromQuat(negQuat)), WMath.RadiansToDegrees(RollFromQuat(negQuat)));
            //Vector3 posEuler = new Vector3(WMath.RadiansToDegrees(PitchFromQuat(posQuat)), WMath.RadiansToDegrees(YawFromQuat(posQuat)), WMath.RadiansToDegrees(RollFromQuat(posQuat)));
            //Console.WriteLine("neg: {0} pos: {1}", negEuler, posEuler);
        }   
Ejemplo n.º 5
0
        public void LoadJNT1FromStream(EndianBinaryReader reader, long tagStart)
        {
            ushort numJoints = reader.ReadUInt16();

            Trace.Assert(reader.ReadUInt16() == 0xFFFF); // Padding

            int jointDataOffset      = reader.ReadInt32();
            int jointRemapDataOffset = reader.ReadInt32();
            int stringTableOffset    = reader.ReadInt32();

            // Joint Names
            reader.BaseStream.Position = tagStart + stringTableOffset;
            StringTable nameTable = StringTable.FromStream(reader);

            // Joint Index Remap
            reader.BaseStream.Position = tagStart + jointRemapDataOffset;
            JointRemapTable            = new List <short>();
            for (int i = 0; i < numJoints; i++)
            {
                JointRemapTable.Add(reader.ReadInt16());
            }

            // Joint Data
            reader.BaseStream.Position = tagStart + jointDataOffset;
            BindJoints     = new List <SkeletonJoint>(numJoints);
            AnimatedJoints = new List <SkeletonJoint>(numJoints);

            for (int j = 0; j < numJoints; j++)
            {
                SkeletonJoint joint = new SkeletonJoint();
                BindJoints.Add(joint);

                joint.Name     = nameTable[j];
                joint.Unknown1 = reader.ReadUInt16();
                joint.DoNotInheritParentScale = reader.ReadByte() == 1;
                Trace.Assert(reader.ReadByte() == 0xFF); // Padding
                joint.Scale = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                Vector3 eulerRot = new Vector3();
                for (int e = 0; e < 3; e++)
                {
                    eulerRot[e] = WMath.RotationShortToFloat(reader.ReadInt16());
                }

                // ZYX order
                joint.Rotation = Quaternion.FromAxisAngle(new Vector3(0, 0, 1), WMath.DegreesToRadians(eulerRot.Z)) *
                                 Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(eulerRot.Y)) *
                                 Quaternion.FromAxisAngle(new Vector3(1, 0, 0), WMath.DegreesToRadians(eulerRot.X));

                Trace.Assert(reader.ReadUInt16() == 0xFFFF); // Padding
                joint.Translation            = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                joint.BoundingSphereDiameter = reader.ReadSingle();
                joint.BoundingBox            = new FAABox(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()), new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));

                // Copy our bind pose skeleton over to our AnimatedJoints array so they have their names/bounding boxes/etc set.
                var animatedJoint = new SkeletonJoint();
                joint.CopyTo(ref animatedJoint);
                AnimatedJoints.Add(animatedJoint);
            }
        }
Ejemplo n.º 6
0
        private CollisionTriangle Raycast(FRay ray)
        {
            if (World.Map == null || ActiveCollisionMesh == null)
            {
                return(null);
            }

            CollisionTriangle closestResult   = null;
            float             closestDistance = float.MaxValue;

            foreach (var tri in ActiveCollisionMesh.Triangles)
            {
                float dist = float.MaxValue;

                if (WMath.RayIntersectsTriangle(ray, tri.Vertices[1], tri.Vertices[0], tri.Vertices[2], true, out dist))
                {
                    if (dist < closestDistance)
                    {
                        closestDistance = dist;
                        closestResult   = tri;
                    }
                }
            }

            return(closestResult);
        }
Ejemplo n.º 7
0
        public void AddForce(Vector2 forceDirection, float deltaTime)
        {
            Vector2 acceleration = forceDirection * force / mass * deltaTime;

            Velocity = (1 / dragCoefficient) * (float)WMath.Exp(-dragCoefficient / mass * deltaTime) *
                       (dragCoefficient * Velocity + mass * acceleration) - (mass * acceleration / dragCoefficient);
        }
Ejemplo n.º 8
0
        public bool IntersectsWith(Circle circle)
        {
            Vector2 endPoint = Position + (Direction * Length);

            if (Vector2.Distance(circle.Position, Position) <= circle.Radius ||
                Vector2.Distance(circle.Position, endPoint) <= circle.Radius)
            {
                return(true);
            }

            float dot = (circle.Position.x - Position.x) * (endPoint.x - Position.x) +
                        (circle.Position.y - Position.y) * (endPoint.y - Position.y);

            dot /= (float)WMath.Pow(Length, 2);
            Vector2 closest = new Vector2(Position.x + (dot * (endPoint.x - Position.x)),
                                          Position.y + (dot * (endPoint.y - Position.y)));

            float d1 = Vector2.Distance(Position, closest);
            float d2 = Vector2.Distance(endPoint, closest);

            if (d1 + d2 <= Length + 0.1 && d1 + d2 >= Length - 0.1f)
            {
                return(Vector2.Distance(circle.Position, closest) <= circle.Radius);
            }
            return(false);
        }
Ejemplo n.º 9
0
        public bool Raycast(FRay ray, out float hitDistance, bool returnFirstHit = false)
        {
            // Raycast against the bounding box of the entire mesh first to see if we can save ourself a bunch of time.
            bool hitsAABB = WMath.RayIntersectsAABB(ray, BoundingBox.Min, BoundingBox.Max, out hitDistance);

            if (!hitsAABB)
            {
                return(false);
            }

            // Okay, they've intersected with our big bounding box, so now we'll trace against individual mesh bounding box.
            // However, if they've applied skinning data to the meshes then these bounding boxes are no longer valid, so this
            // optimization step only counts if they're not applying any skinning.
            bool canSkipShapeTriangles = m_currentBoneAnimation == null;
            bool rayDidHit             = false;

            foreach (var shape in SHP1Tag.Shapes)
            {
                if (canSkipShapeTriangles)
                {
                    hitsAABB = WMath.RayIntersectsAABB(ray, shape.BoundingBox.Min, shape.BoundingBox.Max, out hitDistance);

                    // If we didn't intersect with this shape, just go onto the next one.
                    if (!hitsAABB)
                    {
                        continue;
                    }
                }

                // We either intersected with this shape's AABB or they have skinning data applied (and thus we can't skip it),
                // thus, we're going to test against every (skinned!) triangle in this shape.
                bool hitTriangle = false;
                var  vertexList  = shape.OverrideVertPos.Count > 0 ? shape.OverrideVertPos : shape.VertexData.Position;

                for (int i = 0; i < shape.Indexes.Count; i += 3)
                {
                    float triHitDist;
                    hitTriangle = WMath.RayIntersectsTriangle(ray, vertexList[shape.Indexes[i]], vertexList[shape.Indexes[i + 1]], vertexList[shape.Indexes[i + 2]], true, out triHitDist);

                    // If we hit this triangle and we're OK to just return the first hit on the model, then we can early out.
                    if (hitTriangle && returnFirstHit)
                    {
                        hitDistance = triHitDist;
                        return(true);
                    }

                    // Otherwise, we need to test to see if this hit is closer than the previous hit.
                    if (hitTriangle)
                    {
                        if (triHitDist < hitDistance)
                        {
                            hitDistance = triHitDist;
                        }
                        rayDidHit = true;
                    }
                }
            }

            return(rayDidHit);
        }
Ejemplo n.º 10
0
        public ItemAmount[] NextHarvestDrop(double minChance = 0.0, double maxChance = 1.0)
        {
            // sanitize inputs
            if (minChance < 0.0 || minChance > 1.0) throw new ArgumentOutOfRangeException(nameof(minChance), minChance, "The minimal drop chance must be in the [0.0, 1.0] range.");
            if (maxChance < 0.0 || maxChance > 1.0) throw new ArgumentOutOfRangeException(nameof(maxChance), maxChance, "The maximal drop chance must be in the [0.0, 1.0] range.");
            if (minChance > maxChance) throw new ArgumentOutOfRangeException(nameof(minChance), minChance, "The minimal drop chance must be lower than the maximal one.");
            
            
            ItemAmount[] results = null;
            
            // if no table, return an empty array *but not null*
            if (HarvestTables.Count > 0)
            {
                //if (HarvestTables.Count == 1) results = HarvestTables[0].Results;
                if (minChance == 1.0) results = HarvestTables.Last().Results;
                else
                {
                    double selected = Winecrash.Random.NextDouble();
                    // if needed move the selected chance range to the minimal chance one
                    if (minChance != 0 || maxChance != 0) selected = WMath.Remap(selected, 0.0, 1.0, minChance, maxChance);
                    // invert the range in order to get the least chance
                    
                    // this will take the one with the least chance to appear
                    // (considering the tables are sorted by chance, cf HarvestTable's constructor)
                    HarvestTable table = HarvestTables.FirstOrDefault(ht => ht.Chance >= selected);
                    if (table.Block != null) results = table.Results;
                }
            }

            return results ?? Array.Empty<ItemAmount>();
        }
Ejemplo n.º 11
0
        // Ignore, doesn't work. Bad.
        private static Vector3 EulerAnglesFromQuat(Quaternion q)
        {
            float singularityTest      = q.Z * q.X - q.W * q.Y;
            float yawY                 = 2f * (q.W * q.Z + q.X * q.Y);
            float yawX                 = (float)(1f - 2f * (Math.Pow(q.Y, 2) + Math.Pow(q.Z, 2)));
            float singularityThreshold = 0.4999995f;

            Vector3 eulerAngles = Vector3.Zero;

            if (singularityTest < singularityThreshold)
            {
                eulerAngles.X = -90f;
                eulerAngles.Y = (float)Math.Atan2(yawY, yawX);
                eulerAngles.Z = WMath.Clamp(-eulerAngles.Y - (2f * (float)Math.Atan2(q.X, q.W)), (float)-Math.PI, (float)Math.PI);
            }
            else if (singularityTest > singularityThreshold)
            {
                eulerAngles.X = 90;
                eulerAngles.Y = (float)Math.Atan2(yawY, yawX);
                eulerAngles.Z = WMath.Clamp(eulerAngles.Y - (2f * (float)Math.Atan2(q.X, q.W)), (float)-Math.PI, (float)Math.PI);
            }
            else
            {
                eulerAngles.X = (float)Math.Asin(2f * (singularityTest));
                eulerAngles.Y = (float)Math.Atan2(yawY, yawX);
                eulerAngles.Z = (float)Math.Atan2(-2f * (q.W * q.X + q.Y * q.Z), (1f - 2f * (Math.Pow(q.X, 2) + Math.Pow(q.Y, 2))));
            }

            return(eulerAngles);
        }
Ejemplo n.º 12
0
        public static Vector2D ScreenToUISpace(Vector2F screenCoords)
        {
            Vector2D extents = Canvas.Main.Extents;

            Vector2D remapped = WMath.Remap(screenCoords, Vector2D.Zero, Vector2D.One, -Canvas.Main.Extents, Canvas.Main.Extents);

            remapped.X *= -1D;
            return(remapped);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates an expansion of vector relation
        /// </summary>
        /// <param name="paragraph">Represents a paragraph to add MathML element</param>
        private void CreateVectorRelation(IWParagraph paragraph)
        {
            WordDocument document = paragraph.Document;
            //Creates a MathML element
            WMath math = new WMath(document);

            IOfficeMath officeMath = math.MathPara.Maths.Add(0);

            //Adds an accent equation
            AddMathAccent(document, officeMath, 8407, "A");

            //Adds a math text
            string middleDot = "\u00B7";

            officeMath = math.MathPara.Maths.Add(1);
            IOfficeMathParaItem officeMathParaItem = AddMathText(document, officeMath, 0, middleDot);

            //Adds an accent equation
            officeMath = math.MathPara.Maths.Add(2);
            AddMathAccent(document, officeMath, 8407, "B");

            //Adds a math text
            officeMath         = math.MathPara.Maths.Add(3);
            officeMathParaItem = AddMathText(document, officeMath, 0, "×");

            //Adds an accent equation
            officeMath = math.MathPara.Maths.Add(4);
            AddMathAccent(document, officeMath, 8407, "C");

            //Adds a math text
            officeMath         = math.MathPara.Maths.Add(5);
            officeMathParaItem = AddMathText(document, officeMath, 0, "=");

            //Adds an accent equation
            officeMath = math.MathPara.Maths.Add(6);
            AddMathAccent(document, officeMath, 8407, "A");

            //Adds a math text
            officeMath         = math.MathPara.Maths.Add(7);
            officeMathParaItem = AddMathText(document, officeMath, 0, "×");

            //Adds an accent equation
            officeMath = math.MathPara.Maths.Add(8);
            AddMathAccent(document, officeMath, 8407, "B");

            //Adds a math text
            officeMath         = math.MathPara.Maths.Add(9);
            officeMathParaItem = AddMathText(document, officeMath, 0, middleDot);

            //Adds an accent equation
            officeMath = math.MathPara.Maths.Add(10);
            AddMathAccent(document, officeMath, 8407, "C");
            //Adds the math to the paragraph
            paragraph.Items.Add(math);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates an expansion of vector relation
        /// </summary>
        /// <param name="paragraph">Represents a paragraph to add MathML element</param>
        private void CreateVectorRelation(IWParagraph paragraph)
        {
            WordDocument document = paragraph.Document;
            //Creates a MathML element
            WMath math = paragraph.AppendMath();

            IOfficeMath officeMath = math.MathParagraph.Maths.Add();

            //Adds an accent equation
            AddMathAccent(document, officeMath, 8407, "A");

            //Adds a math text
            string middleDot = "\u00B7";

            officeMath = math.MathParagraph.Maths.Add();
            IOfficeMathRunElement officeMathParaItem = AddMathText(document, officeMath, middleDot);

            //Adds an accent equation
            officeMath = math.MathParagraph.Maths.Add();
            AddMathAccent(document, officeMath, 8407, "B");

            //Adds a math text
            officeMath = math.MathParagraph.Maths.Add();
            string multiplicationSign = "\u00D7";

            officeMathParaItem = AddMathText(document, officeMath, multiplicationSign);

            //Adds an accent equation
            officeMath = math.MathParagraph.Maths.Add();
            AddMathAccent(document, officeMath, 8407, "C");

            //Adds a math text
            officeMath         = math.MathParagraph.Maths.Add();
            officeMathParaItem = AddMathText(document, officeMath, "=");

            //Adds an accent equation
            officeMath = math.MathParagraph.Maths.Add();
            AddMathAccent(document, officeMath, 8407, "A");

            //Adds a math text
            officeMath         = math.MathParagraph.Maths.Add();
            officeMathParaItem = AddMathText(document, officeMath, multiplicationSign);

            //Adds an accent equation
            officeMath = math.MathParagraph.Maths.Add();
            AddMathAccent(document, officeMath, 8407, "B");

            //Adds a math text
            officeMath         = math.MathParagraph.Maths.Add();
            officeMathParaItem = AddMathText(document, officeMath, middleDot);

            //Adds an accent equation
            officeMath = math.MathParagraph.Maths.Add();
            AddMathAccent(document, officeMath, 8407, "C");
        }
Ejemplo n.º 15
0
        private void CameraRotation()
        {
            Vector2D deltas = Input.MouseDelta;

            double ax = (Angles.X + (deltas.X * Input.MouseSensivity * Time.DeltaTime)) % 360.0D;
            double ay = WMath.Clamp((Angles.Y + (deltas.Y * Input.MouseSensivity * Time.DeltaTime)), -89.9D, 89.9D);

            Angles = new Vector2D(ax, ay);

            this.FPSCamera.WObject.Rotation = new Engine.Quaternion(-ay, ax, 0.0F);
        }
        private void DoApplicationTick()
        {
            // Poll the mouse at a high resolution
            System.Drawing.Point mousePos = m_glControl.PointToClient(System.Windows.Forms.Cursor.Position);

            mousePos.X = WMath.Clamp(mousePos.X, 0, m_glControl.Width);
            mousePos.Y = WMath.Clamp(mousePos.Y, 0, m_glControl.Height);
            WInput.SetMousePosition(new Vector2(mousePos.X, mousePos.Y));

            ProcessTick();
            WInput.Internal_UpdateInputState();

            m_glControl.SwapBuffers();
        }
Ejemplo n.º 17
0
        protected override void Update()
        {
            if (!ReferenceLabel)
            {
                return;
            }

            double pctAnimation = (Time.TimeSinceStart / AnimationTime) % 1.0D;

            pctAnimation = WMath.Remap(Math.Cos(WMath.Remap(pctAnimation, 0.0, 1.0, -1.0, 1.0)), 0.5, 1.0, 0.0, AnimationScale);

            ReferenceLabel.MinAnchor = LbBaseMin - new Vector2D(0.0, pctAnimation);
            ReferenceLabel.MaxAnchor = LbBaseMax + new Vector2D(0.0, pctAnimation);
        }
Ejemplo n.º 18
0
        private void AnimateDisplayName()
        {
            ItemNameCooldown -= Time.Delta;

            if (ItemNameCooldown < 0.0)
            {
                ItemNameLabel.Enabled = false;
            }
            else if (ItemNameCooldown < ItemNameTime)
            {
                Color256 col = ItemNameLabel.Color;
                col.A = WMath.Clamp(ItemNameCooldown / ItemNameDisappearTime, 0, 1);
                ItemNameLabel.Color = col;
            }
        }
Ejemplo n.º 19
0
        protected override void LateUpdate()
        {
            float size = 5.0F;

            Vector2I mp = Input.MousePosition;

            float mpScreenRight = (float)WMath.Remap(mp.X, -Canvas.Main.Extents.X, Canvas.Main.Extents.X, 0.0F, Canvas.Main.Extents.X * 4.0D);
            float mpScreenTop   = (float)WMath.Remap(mp.Y, -Canvas.Main.Extents.Y, Canvas.Main.Extents.Y, 0.0F, Canvas.Main.Extents.Y * 4.0D);

            img.Right = mpScreenRight - size;
            img.Left  = (Canvas.Main.Extents.X * 4.0F) - mpScreenRight - size;

            img.Bottom = mpScreenTop - size;
            img.Top    = (Canvas.Main.Extents.Y * 4.0F) - mpScreenTop - size;
        }
Ejemplo n.º 20
0
        public void ToDZBFile(EndianBinaryWriter writer, List <OctreeNode> octree, Vector3[] verts)
        {
            writer.Write((int)0); // Name offset
            writer.Write(m_Scale.X);
            writer.Write(m_Scale.Y);
            writer.Write(m_Scale.Z);

            Vector3 rotation = m_Rotation.ToEulerAngles();

            writer.Write(WMath.RotationFloatToShort(rotation.X));
            writer.Write(WMath.RotationFloatToShort(rotation.Y));
            writer.Write(WMath.RotationFloatToShort(rotation.Z));
            writer.Write((short)-1);

            writer.Write(m_Translation.X);
            writer.Write(m_Translation.Y);
            writer.Write(m_Translation.Z);

            writer.Write(m_ParentIndex);
            writer.Write(m_NextSiblingIndex);
            writer.Write(m_FirstChildIndex);

            // Unknown 1
            if (Parent == null)
            {
                writer.Write((short)0);
            }
            else
            {
                writer.Write((short)-1);
            }

            if (Triangles.Count > 0)
            {
                writer.Write(FirstVertexIndex); // Unknown 2
            }
            else
            {
                writer.Write((short)0);
            }

            // The first octree object to have this group assigned to it is the root of its octree.
            writer.Write((short)octree.IndexOf(octree.Find(x => x.Group == this)));

            writer.Write((short)0);
            writer.Write((byte)Terrain);
            writer.Write((byte)0);
        }
Ejemplo n.º 21
0
        public void AnimateWalk(Vector3D velocity)
        {
            if (PlayerLeftLeg == null || PlayerRightLeg == null)
            {
                return;
            }
            double speed = WMath.Clamp(velocity.XZ.Length, 0, Player.WalkSpeed);

            CurrentWalkAnimationTime += Time.Delta * speed * WalkAnimationSpeedCoef;

            double t = WMath.Remap(Math.Cos(CurrentWalkAnimationTime), -1, 1, 0, 1);

            double speedCoef = speed <= 0.05D ? 0.0D : speed / Player.WalkSpeed;

            double currentAngle = WMath.Lerp(-WalkAnimationMaxAngle * speedCoef, WalkAnimationMaxAngle * speedCoef, t);//WMath.Remap(CurrentWalkAnimationTime, 0, 1, -WalkAnimationMaxAngle * speedCoef, WalkAnimationMaxAngle * speedCoef);


            Quaternion leftRotLeg  = new Quaternion(-currentAngle * WalkAnimationLegCoef, 0, 0);
            Quaternion rightRotLeg = new Quaternion(currentAngle * WalkAnimationLegCoef, 0, 0);

            Quaternion rightRotArm = new Quaternion(-currentAngle, 0, 0);
            Quaternion leftRotArm  = new Quaternion(currentAngle, 0, 0);


            PlayerLeftLeg.LocalRotation  = leftRotLeg;
            PlayerRightLeg.LocalRotation = rightRotLeg;

            PlayerRightArm.LocalRotation *= rightRotArm;
            PlayerLeftArm.LocalRotation  *= leftRotArm;


            Vector3D flattenVel   = new Vector3D(velocity.X, 0, velocity.Z);
            Vector3D flattenDir   = flattenVel.Normalized;
            double   flattenSpeed = flattenVel.Length;

            if (flattenSpeed >= 0.1D)
            {
                double currentTorsoAngle = Quaternion.AngleY(PlayerTorso.Rotation, Quaternion.Identity);
                double rawNewAngle       = (Math.Atan2(flattenDir.X, flattenDir.Z) * WMath.RadToDeg) * -1;

                double deltaAngle = WMath.DeltaAngle(currentTorsoAngle, rawNewAngle);

                deltaAngle = WMath.Clamp(deltaAngle, -HeadMaxAngleToBody, HeadMaxAngleToBody);

                PlayerTorso.LocalRotation *= new Quaternion(0, -deltaAngle * WalkAnimationTorsoOrientCoef * Time.Delta, 0);
            }
        }
Ejemplo n.º 22
0
        protected override void LateUpdate()
        {
            base.LateUpdate();

            Vector2D rawmp = Input.MousePosition;
            Vector2D ss    = Graphics.Window.SurfaceResolution;
            Vector2D shift = new Vector2D(
                WMath.Remap(rawmp.X, -(ss.X / 2), ss.X / 2, 0, ss.X) - ss.X,
                WMath.Remap(rawmp.Y, -(ss.Y / 2), ss.Y / 2, 0, ss.Y)
                );

            this.Shift = new Vector3D(shift + Offset, -4000);

            double xmax    = (Label.CurrentWidth / ss.X) * 4;
            double padding = 0.025;

            this.MaxAnchor = new Vector2D(xmax + padding, MaxAnchor.Y);
        }
Ejemplo n.º 23
0
        protected void GetSHCoefficients( WMath.Vector _Direction, ref double[] _Coefficients )
        {
            float	x = -_Direction.z;
            float	y = _Direction.y;
            float	z = _Direction.x;

            // Build the SH coefficients from analytical formulae given in http://www-graphics.stanford.edu/papers/envmap/
            _Coefficients[0] = 0.282095;					// Y00

            _Coefficients[1] = 0.488603 * z;				// Y1-1
            _Coefficients[2] = 0.488603 * y;				// Y10
            _Coefficients[3] = 0.488603 * x;				// Y1+1

            _Coefficients[4] = 1.092548 * x * z;			// Y2-2
            _Coefficients[5] = 1.092548 * y * z;			// Y2-1
            _Coefficients[6] = 0.315392 * (3*y*y - 1);		// Y20
            _Coefficients[7] = 1.092548 * x * y;			// Y2+1
            _Coefficients[8] = 0.546274 * (x*x - z*z);		// Y2+2
        }
Ejemplo n.º 24
0
        public void AnimateIdle()
        {
            if (PlayerLeftArm == null || PlayerRightArm == null)
            {
                return;
            }

            PlayerLeftArm.LocalRotation = PlayerRightArm.LocalRotation = Quaternion.Identity;

            CurrentIdleAnimationTime += Time.Delta * IdleAnimationSpeed;

            double t = WMath.Remap(Math.Cos(CurrentIdleAnimationTime), -1, 1, 0, 1);

            double currentZAngle = WMath.Lerp(IdleAnimationArmMinAngle, IdleAnimationArmMaxAngle, t);

            double currentXAngle = currentZAngle * 0.25D;

            PlayerLeftArm.LocalRotation  = new Quaternion(currentXAngle, 0, currentZAngle);
            PlayerRightArm.LocalRotation = new Quaternion(-currentXAngle, 0, -currentZAngle);
        }
Ejemplo n.º 25
0
        public CollisionGroupNode(EndianBinaryReader reader)
        {
            Children  = new ObservableCollection <CollisionGroupNode>();
            Triangles = new List <CollisionTriangle>();

            int  name_offset = reader.ReadInt32();
            long cur_offset  = reader.BaseStream.Position;

            reader.BaseStream.Seek(name_offset, System.IO.SeekOrigin.Begin);
            Name = Encoding.ASCII.GetString(reader.ReadBytesUntil(0));
            reader.BaseStream.Seek(cur_offset, System.IO.SeekOrigin.Begin);

            m_Scale = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            Vector3 eulerRot = new Vector3();

            for (int e = 0; e < 3; e++)
            {
                eulerRot[e] = WMath.RotationShortToFloat(reader.ReadInt16());
            }
            // ZYX order
            m_Rotation = OpenTK.Quaternion.FromAxisAngle(new Vector3(0, 0, 1), WMath.DegreesToRadians(eulerRot.Z)) *
                         OpenTK.Quaternion.FromAxisAngle(new Vector3(0, 1, 0), WMath.DegreesToRadians(eulerRot.Y)) *
                         OpenTK.Quaternion.FromAxisAngle(new Vector3(1, 0, 0), WMath.DegreesToRadians(eulerRot.X));

            m_Unknown1 = reader.ReadUInt16();

            m_Translation = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            m_ParentIndex      = reader.ReadInt16();
            m_NextSiblingIndex = reader.ReadInt16();
            m_FirstChildIndex  = reader.ReadInt16();

            m_RoomNum = reader.ReadInt16();

            FirstVertexIndex = reader.ReadInt16();

            reader.SkipInt16(); // Octree index, we don't need it for loading from dzb

            m_Bitfield = reader.ReadInt32();
        }
Ejemplo n.º 26
0
        private static Quaternion FromEulerAngles(Vector3 e)
        {
            e.X = WMath.DegreesToRadians(e.X);
            e.Y = WMath.DegreesToRadians(e.Y);
            e.Z = WMath.DegreesToRadians(e.Z);

            double c1 = Math.Cos(e.Y / 2f);
            double s1 = Math.Sin(e.Y / 2f);
            double c2 = Math.Cos(e.X / 2f);
            double s2 = Math.Sin(e.X / 2f);
            double c3 = Math.Cos(e.Z / 2f);
            double s3 = Math.Sin(e.Z / 2f);
            double c1c2 = c1 * c2;
            double s1s2 = s1 * s2;

            float w = (float)(c1c2 * c3 - s1s2 * s3);
            float x = (float)(c1c2 * s3 + s1s2 * c3);
            float y = (float)(s1 * c2 * c3 + c1 * s2 * s3);
            float z = (float)(c1 * s2 * c3 - s1 * c2 * s3);
            return new Quaternion(x, y, z, w);
        }
Ejemplo n.º 27
0
        public static void GlobalToLocal(Vector3F global, out Vector3I ChunkPosition, out Vector3I LocalPosition)
        {
            ChunkPosition = new Vector3I(
                ((int)global.X / Chunk.Width) + (global.X < 0.0F ? -1 : 0), //X position
                ((int)global.Z / Chunk.Depth) + (global.Z < 0.0F ? -1 : 0), //Y position
                0);                                                         //Z dimension

            float localX = global.X % Chunk.Width;

            if (localX < 0)
            {
                localX += Chunk.Width;
            }

            float localZ = global.Z % Chunk.Depth;

            if (localZ < 0)
            {
                localZ += Chunk.Depth;
            }

            LocalPosition = new Vector3I((int)localX, WMath.Clamp((int)global.Y, 0, 255), (int)localZ);
        }
        public IActionResult EditEquation(string Button, string Group1)
        {
            if (Button == null)
            {
                return(View());
            }
            string basePath    = _hostingEnvironment.WebRootPath;
            string dataPath    = basePath + @"/DocIO/Mathematical Equation.docx";
            string contenttype = "application/vnd.ms-word.document.12";
            // Load Template document stream.
            FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (Button == "View Template")
            {
                return(File(fileStream, contenttype, "Mathematical Equation.docx"));
            }

            // Creates an empty Word document instance.
            WordDocument document = new WordDocument();

            // Opens template document.
            document.Open(fileStream, FormatType.Docx);
            fileStream.Dispose();
            fileStream = null;
            //Gets the last section in the document
            WSection section = document.LastSection;
            //Gets paragraph from Word document
            WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph;

            //Gets MathML from the paragraph
            WMath math = paragraph.ChildEntities[0] as WMath;
            //Gets the radical equation
            IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical;
            //Gets the fraction equation in radical
            IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction;
            //Gets the n-array in fraction
            IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray;
            //Gets the math script in n-array
            IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript;
            //Gets the delimiter in math script
            IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter;

            //Gets the math script in delimiter
            mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;

            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the math bar in delimiter
            IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar;

            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph;
            //Gets MathML from the paragraph
            math = paragraph.ChildEntities[0] as WMath;
            //Gets the math script equation
            mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph;
            //Gets MathML from the paragraph
            WMath math2 = paragraph.ChildEntities[0] as WMath;

            //Gets bar equation
            mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar;
            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Gets the math text
            (mathParaItem.Item as WTextRange).Text = "x";

            string       filename = "";
            MemoryStream ms       = new MemoryStream();

            #region Document SaveOption
            if (Group1 == "WordDocx")
            {
                filename    = "EditEquation.docx";
                contenttype = "application/msword";
                document.Save(ms, FormatType.Docx);
            }
            else
            {
                filename    = "EditEquation.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                renderer.ConvertToPDF(document).Save(ms);
            }
            #endregion Document SaveOption
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Ejemplo n.º 29
0
        public bool Raycast(FRay ray, out float hitDistance, bool returnFirstHit = false)
        {
            // Raycast against the bounding box of the entire mesh first to see if we can save ourself a bunch of time.
            bool hitsAABB = WMath.RayIntersectsAABB(ray, BoundingBox.Min, BoundingBox.Max, out hitDistance);

            if (!hitsAABB)
            {
                return(false);
            }

            // Okay, they've intersected with our big bounding box, so now we'll trace against individual mesh bounding box.
            // However, if they've applied skinning data to the meshes then these bounding boxes are no longer valid, so this
            // optimization step only counts if they're not applying any skinning.
            bool canSkipShapeTriangles = m_currentBoneAnimation == null;
            bool rayDidHit             = false;

            foreach (var shape in SHP1Tag.Shapes)
            {
                if (canSkipShapeTriangles)
                {
                    hitsAABB = WMath.RayIntersectsAABB(ray, shape.BoundingBox.Min, shape.BoundingBox.Max, out hitDistance);

                    // If we didn't intersect with this shape, just go onto the next one.
                    if (!hitsAABB)
                    {
                        continue;
                    }
                }

                // We either intersected with this shape's AABB or they have skinning data applied (and thus we can't skip it),
                // thus, we're going to test against every (skinned!) triangle in this shape.
                bool hitTriangle = false;

                /*foreach (SHP1.Packet pak in shape.MatrixGroups)
                 * {
                 *  List<Vector3> vertexList = new List<Vector3>();
                 *
                 *  for (int i = 0; i < pak.Indexes.Count; i++)
                 *  {
                 *      Matrix4 cur_mat = DRW1Tag.Matrices[pak.MatrixDataTable.MatrixTable[pak.VertexData.PositionMatrixIndexes[i]]];
                 *      vertexList.Add(Vector3.Transform(pak.VertexData.Position[i], cur_mat));
                 *  }
                 *
                 *  for (int i = 0; i < pak.Indexes.Count; i += 3)
                 *  {
                 *      float triHitDist;
                 *      hitTriangle = WMath.RayIntersectsTriangle(ray, vertexList[pak.Indexes[i]], vertexList[pak.Indexes[i + 1]], vertexList[pak.Indexes[i + 2]], true, out triHitDist);
                 *
                 *      // If we hit this triangle and we're OK to just return the first hit on the model, then we can early out.
                 *      if (hitTriangle && returnFirstHit)
                 *      {
                 *          hitDistance = triHitDist;
                 *          Console.WriteLine($"{Name}:{hitDistance}");
                 *          return true;
                 *      }
                 *
                 *      // Otherwise, we need to test to see if this hit is closer than the previous hit.
                 *      if (hitTriangle)
                 *      {
                 *          if (triHitDist < hitDistance)
                 *              hitDistance = triHitDist;
                 *          rayDidHit = true;
                 *      }
                 *  }
                 * }*/
            }

            return(rayDidHit);
        }
Ejemplo n.º 30
0
    private bool ClipByPlane(Plane plane, WMesh originMesh, out WMesh slicedMesh, out WMesh remainedMesh)
    {
        slicedMesh   = null;
        remainedMesh = null;

        List <WTriangle> bodyTris = originMesh.GetBodyTris();

        List <WTriangle> slicedTris   = new List <WTriangle>();
        List <WTriangle> remainedTris = new List <WTriangle>();

        List <WClipEdge> clipedEdges = new List <WClipEdge>();

        //Plane clipPlane = new Plane(plane.normal, Vector3.zero);
        Plane clipPlane = plane;

        for (int i = 0; i < bodyTris.Count; i++)
        {
            WTriangle tri = bodyTris[i];

            Vector3 worldPos = Target.GetPosition();
            // Using modified Sutherland-Hodgman
            Vector3 a = tri.a + worldPos;
            Vector3 b = tri.b + worldPos;
            Vector3 c = tri.c + worldPos;

            float da = clipPlane.GetDistanceToPoint(a);
            float db = clipPlane.GetDistanceToPoint(b);
            float dc = clipPlane.GetDistanceToPoint(c);


            if (WMath.InFront(da) && WMath.InFront(db) && WMath.InFront(dc))
            {
                slicedTris.Add(tri);
            }
            else if (WMath.Behind(da) && WMath.Behind(db) && WMath.Behind(dc))
            {
                remainedTris.Add(tri);
            }
            else if (WMath.InFront(da) && WMath.InFront(db) && WMath.Behind(dc))
            {
                Vector3 ac = WMath.Intersect(a, c, da, dc);
                Vector3 bc = WMath.Intersect(b, c, db, dc);

                slicedTris.Add(new WTriangle(ac, a, b, worldPos));
                slicedTris.Add(new WTriangle(b, bc, ac, worldPos));
                remainedTris.Add(new WTriangle(ac, bc, c, worldPos));

                clipedEdges.Add(new WClipEdge(ac, bc, worldPos));
            }
            else if (WMath.Behind(da) && WMath.Behind(db) && WMath.InFront(dc))
            {
                Vector3 ac = WMath.Intersect(a, c, da, dc);
                Vector3 bc = WMath.Intersect(b, c, db, dc);

                remainedTris.Add(new WTriangle(ac, a, b, worldPos));
                remainedTris.Add(new WTriangle(b, bc, ac, worldPos));
                slicedTris.Add(new WTriangle(ac, bc, c, worldPos));

                clipedEdges.Add(new WClipEdge(bc, ac, worldPos));
            }
            else if (WMath.InFront(da) && WMath.Behind(db) && WMath.InFront(dc))
            {
                Vector3 ab = WMath.Intersect(a, b, da, db);
                Vector3 bc = WMath.Intersect(b, c, db, dc);

                slicedTris.Add(new WTriangle(a, ab, c, worldPos));
                slicedTris.Add(new WTriangle(ab, bc, c, worldPos));
                remainedTris.Add(new WTriangle(ab, b, bc, worldPos));

                clipedEdges.Add(new WClipEdge(bc, ab, worldPos));
            }
            else if (WMath.Behind(da) && WMath.InFront(db) && WMath.Behind(dc))
            {
                Vector3 ab = WMath.Intersect(a, b, da, db);
                Vector3 bc = WMath.Intersect(b, c, db, dc);

                remainedTris.Add(new WTriangle(a, ab, c, worldPos));
                remainedTris.Add(new WTriangle(ab, bc, c, worldPos));
                slicedTris.Add(new WTriangle(ab, b, bc, worldPos));

                clipedEdges.Add(new WClipEdge(ab, bc, worldPos));
            }
            else if (WMath.Behind(da) && WMath.InFront(db) && WMath.InFront(dc))
            {
                Vector3 ab = WMath.Intersect(a, b, da, db);
                Vector3 ac = WMath.Intersect(a, c, da, dc);

                slicedTris.Add(new WTriangle(ab, b, c, worldPos));
                slicedTris.Add(new WTriangle(c, ac, ab, worldPos));
                remainedTris.Add(new WTriangle(ac, a, ab, worldPos));

                clipedEdges.Add(new WClipEdge(ab, ac, worldPos));
            }
            else if (WMath.InFront(da) && WMath.Behind(db) && WMath.Behind(dc))
            {
                Vector3 ab = WMath.Intersect(a, b, da, db);
                Vector3 ac = WMath.Intersect(a, c, da, dc);

                remainedTris.Add(new WTriangle(ab, b, c, worldPos));
                remainedTris.Add(new WTriangle(c, ac, ab, worldPos));
                slicedTris.Add(new WTriangle(ac, a, ab, worldPos));

                clipedEdges.Add(new WClipEdge(ac, ab, worldPos));
            }
        }

        MakeCap(clipedEdges, out List <WTriangle> slicedCap, out List <WTriangle> remainedCap);

        if (slicedTris.Count > 0 && remainedTris.Count > 0)
        {
            slicedMesh   = new WMesh(slicedTris, slicedCap);
            remainedMesh = new WMesh(remainedTris, remainedCap);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 31
0
        /// <summary>
        /// Creates a Fourier series equation
        /// </summary>
        /// <param name="paragraph">Represents a paragraph to add MathML element</param>
        private void CreateFourierseries(IWParagraph paragraph)
        {
            WordDocument document = paragraph.Document;
            //Creates a new MathML element
            WMath math = paragraph.AppendMath();

            //Adds a math
            IOfficeMath officeMath = math.MathParagraph.Maths.Add();

            //Adds a math text
            AddMathText(document, officeMath, "f");

            //Adds a math delimiter
            IOfficeMathDelimiter mathDelimiter = math.MathParagraph.Maths.Add().Functions.Add(MathFunctionType.Delimiter) as IOfficeMathDelimiter;

            //Adds a math in the delimiter
            officeMath = mathDelimiter.Equation.Add() as IOfficeMath;
            //Adds a math text
            AddMathText(document, officeMath, "x");
            AddMathText(document, math.MathParagraph.Maths.Add(), "=");
            //Adds a Subscript equation
            IOfficeMathScript mathScript = AddMathScript(math.MathParagraph.Maths.Add(), MathScriptType.Subscript);

            //Adds a math text
            AddMathText(document, mathScript.Equation, "a");
            AddMathText(document, mathScript.Script, "0");

            //Adds a math text
            AddMathText(document, math.MathParagraph.Maths.Add(), "+");

            //Adds a math n-array
            IOfficeMathNArray mathNAry = math.MathParagraph.Maths.Add().Functions.Add(MathFunctionType.NArray) as IOfficeMathNArray;
            //Unicode value of n-array summation
            string sigma = "\u2211";

            //Sets the value as the n-array character
            mathNAry.NArrayCharacter = sigma;
            mathNAry.HasGrow         = true;
            //Adds a math text
            AddMathText(document, mathNAry.Subscript, "n=1");

            //Adds a math text
            string infinitySymbol = "\u221E";

            AddMathText(document, mathNAry.Superscript, infinitySymbol);
            //Adds a math delimiter
            mathDelimiter = mathNAry.Equation.Functions.Add(MathFunctionType.Delimiter) as IOfficeMathDelimiter;
            //Adds an math in the delimiter equation collection
            officeMath = mathDelimiter.Equation.Add() as IOfficeMath;
            //Adds a math script
            mathScript = AddMathScript(officeMath, MathScriptType.Subscript);

            //Adds a math text
            AddMathText(document, mathScript.Equation, "a");

            //Adds a math text
            AddMathText(document, mathScript.Script, "n");

            //Adds a math function
            IOfficeMathFunction mathFunction = officeMath.Functions.Add(MathFunctionType.Function) as IOfficeMathFunction;
            //Adds a math text
            IOfficeMathRunElement mathParaItem = AddMathText(document, mathFunction.FunctionName, "cos");

            mathParaItem.MathFormat.Style = MathStyleType.Regular;

            //Adds a math fraction
            IOfficeMathFraction mathFraction = mathFunction.Equation.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction;
            //Adds a math text
            //Unicode value of PI
            string pi   = "\uD835\uDF0B";
            string text = "n" + pi + "x";

            AddMathText(document, mathFraction.Numerator, text);
            AddMathText(document, mathFraction.Denominator, "L");

            //Adds a math text
            AddMathText(document, officeMath, "+");
            //Adds a math script
            mathScript = AddMathScript(officeMath, MathScriptType.Subscript);
            //Adds a math text
            AddMathText(document, mathScript.Equation, "b");
            AddMathText(document, mathScript.Script, "n");

            //Adds a function
            mathFunction = officeMath.Functions.Add(MathFunctionType.Function) as IOfficeMathFunction;
            //Adds a math text
            mathParaItem = AddMathText(document, mathFunction.FunctionName, "sin");
            mathParaItem.MathFormat.Style = MathStyleType.Regular;

            //Adds a math fraction element
            mathFraction = mathFunction.Equation.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction;
            //Adds a math text for numerator
            AddMathText(document, mathFraction.Numerator, text);
            //Adds a math text for denominator
            AddMathText(document, mathFraction.Denominator, "L");
        }
Ejemplo n.º 32
0
		public void		SampleCubeMap( WMath.Vector _View, CubeMapSampler _Sampler, out byte _R, out byte _G, out byte _B )
		{
			AbsView.Set( Math.Abs( _View.x ), Math.Abs( _View.y ), Math.Abs( _View.z ) );
			float	MaxComponent = Math.Max( Math.Max( AbsView.x, AbsView.y ), AbsView.z );

			fXYZ.Set( _View.x / MaxComponent, _View.y / MaxComponent, _View.z / MaxComponent );
			int		FaceIndex = 0;
			if ( Math.Abs( fXYZ.x ) > 1.0-1e-6 )
			{	// +X or -X
				if ( _View.x > 0.0 )
				{
					FaceIndex = 0;
					fXY.Set( -fXYZ.z, fXYZ.y );
				}
				else
				{
					FaceIndex = 1;
					fXY.Set( fXYZ.z, fXYZ.y );
				}
			}
			else if ( Math.Abs( fXYZ.y ) > 1.0-1e-6 )
			{	// +Y or -Y
				if ( _View.y > 0.0 )
				{
					FaceIndex = 2;
					fXY.Set( fXYZ.x, -fXYZ.z );
				}
				else
				{
					FaceIndex = 3;
					fXY.Set( fXYZ.x, fXYZ.z );
				}
			}
			else // if ( Math.Abs( fXYZ.z ) > 1.0-1e-6 )
			{	// +Z or -Z
				if ( _View.z > 0.0 )
				{
					FaceIndex = 4;
					fXY.Set( fXYZ.x, fXYZ.y );
				}
				else
				{
					FaceIndex = 5;
					fXY.Set( -fXYZ.x, fXYZ.y );
				}
			}

			fXY.y = -fXY.y;

			int		X = (int) (Probe.CUBE_MAP_SIZE * 0.5 * (1.0 + fXY.x));
			int		Y = (int) (Probe.CUBE_MAP_SIZE * 0.5 * (1.0 + fXY.y));

// 			if ( X < 0 || X > Probe.CUBE_MAP_SIZE-1 )
// 				throw new Exception();
// 			if ( Y < 0 || Y > Probe.CUBE_MAP_SIZE-1 )
// 				throw new Exception();

			X = Math.Min( Probe.CUBE_MAP_SIZE-1, X );
			Y = Math.Min( Probe.CUBE_MAP_SIZE-1, Y );

			Probe.Pixel[,]	CubeMapFace = m_Probe.m_CubeMap[FaceIndex];

			_Sampler( CubeMapFace[X,Y], out _R, out _G, out _B );
		}