当前位置: 首页>>代码示例>>C#>>正文


C# Vector2f.Dot方法代码示例

本文整理汇总了C#中Vector2f.Dot方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2f.Dot方法的具体用法?C# Vector2f.Dot怎么用?C# Vector2f.Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2f的用法示例。


在下文中一共展示了Vector2f.Dot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Projection

        public Projection(Vector2f axis, List<Vector2f> vertices)
        {
            this.axis = axis;

            min = axis.Dot(vertices[0]);
            max = min;

            for(int i = 1; i < vertices.Count; ++i)
            {
                float p = axis.Dot(vertices[i]);

                if(p < min)
                    min = p;
                else if(p > max)
                    max = p;
            }
        }
开发者ID:dabbertorres,项目名称:PhysicsPlayground,代码行数:17,代码来源:Projection.cs

示例2: GetVisMesh

        public VertexArray GetVisMesh()
        {
            if (_boundsNeedUpdate)
            {
                ComputeBoundaries();
                _boundsNeedUpdate = false;
            }

            // if segments state is clean, no need to calculate mesh again
            if (!_visMeshNeedsUpdate)
                return _visMesh;

            // add all segments to a temp list
            _visibleSegments = new List<Segment>(_segments);

            // get all unique VISIBLE segments' endpoints + bound endpoints
            var points = new HashSet<Vector2f>();
            for (var i = _visibleSegments.Count - 1; i >= 0; i--)
            {
                var s = _visibleSegments[i];

                var edge = s.Start - s.End;
                var normal = new Vector2f(edge.Y, -edge.X);

                // is the segment visible from the ray origin?
                var distVector = s.End - _center;

                var dot = normal.Dot(distVector);

                if (dot > 0 && distVector.Length() <= _radius)
                {
                    points.Add(s.Start);
                    points.Add(s.End);
                }
                else
                {
                    _visibleSegments.RemoveAt(i);
                }
            }

            // add bounding points
            foreach (var s in _bounds)
            {
                points.Add(s.Start);
                points.Add(s.End);
            }

            // add bounding segments to visible segments
            _visibleSegments.AddRange(_bounds);

            // get all angles
            var angles = new List<float>();
            foreach (
                var angle in
                    points.Select(p => Math.Atan2(p.Y - _center.Y, p.X - _center.X)).Select(angle => (float) angle))
            {
                angles.Add(angle - 0.0001f);
                angles.Add(angle);
                angles.Add(angle + 0.0001f);
            }

            // rays to all visible endpoints
            var intersections = new List<Ray>();
            foreach (var angle in angles)
            {
                var dx = Math.Cos(angle);
                var dy = Math.Sin(angle);

                var rayStart = _center;
                var rayEnd = new Vector2f(_center.X + (float) dx, _center.Y + (float) dy);

                // find closest intersection
                Ray closestIntersect = null;

                foreach (
                    var intersect in
                        _visibleSegments
                            .Select(s => MathUtils.GetIntersection(rayStart, rayEnd, s.Start, s.End))
                            .Where(intersect => intersect != null)
                            .Where(intersect => closestIntersect == null || intersect.Length < closestIntersect.Length))
                    closestIntersect = intersect;

                if (closestIntersect == null) continue;

                closestIntersect.Angle = angle;

                intersections.Add(closestIntersect);
            }

            // sort intersects by angle
            intersections.Sort((a, b) => a.Angle.CompareTo(b.Angle));

            // make visibility mesh
            _visMesh.Clear();

            _visMesh.Append(new Vertex(_center, _center));

            foreach (var hit in intersections)
                _visMesh.Append(new Vertex(hit.Position, hit.Position));

//.........这里部分代码省略.........
开发者ID:Tetramputechture,项目名称:Ending_0.1b,代码行数:101,代码来源:VisbilityMap.cs

示例3: ApplyTorque

        // apply a force at 'fromCenter' relative to center of the shape
        public void ApplyTorque(Vector2f force, Vector2f fromCenter)
        {
            var radius = fromCenter.Magnitude();

            // check if 'fromCenter' is outside of the shape.
            if(radius > GetRadiusOn(fromCenter))
                return;

            // torque is the amount of force in the perpendicular direction
            var torque = force.Cross(fromCenter);

            // linear force is the amount of force in the parallel direction
            var linearForce = force.Dot(fromCenter) / (radius != 0 ? radius : 1f);

            // moment of inertia of the mass at this radius
            var inertia = mass * radius * radius;

            AngularAcceleration += -torque / (inertia != 0 ? inertia : 1);
            ApplyForce(linearForce * force.Unit());
        }
开发者ID:dabbertorres,项目名称:PhysicsPlayground,代码行数:21,代码来源:Shape.cs


注:本文中的Vector2f.Dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。