Example #1
0
        /// <summary>
        /// Creates a door given its properties.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateDoor(DoorProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            HostedProperty hp   = ConvertToHosted(properties);
            FamilyInstance door = CreateHostedElement(hp, false);

            XYZ facing = door.FacingOrientation * -1;

            facing = VectorManipulator.TransformUVinXYZ(VectorManipulator.RotateVector(facing, baseRotation));
            double angle = Math.Atan2(facing.Y, facing.X);

            if (Math.Abs(angle - DeegreToRadians(properties.Rotation)) > 0.001)
            {
                door.flipFacing();
            }

            if ((door.FacingOrientation.CrossProduct(door.HandOrientation).Z < 0) ^ properties.OpenLeft)
            {
                door.flipHand();
            }

            /*
             * double offset = GetFamilyOffset(properties.Type).U;
             * XYZ translation = door.HandOrientation * offset;
             * ElementTransformUtils.MoveElement(doc, door.Id, translation);
             */

            return(door);
        }
Example #2
0
 private void ClockForm_MouseUp(object sender, MouseEventArgs e)
 {
     if (VectorManipulator.DecreaseCaptureLevel(e.Button))
     {
         VectorManipulator.Movement(e.X, e.Y);
         this.Repaint();
     }
 }
Example #3
0
 private void ClockForm_MouseMove(object sender, MouseEventArgs e)
 {
     if (VectorManipulator.CaptureMode)
     {
         VectorManipulator.Movement(e.X, e.Y);
         this.Repaint();
     }
 }
Example #4
0
 /// <summary>
 /// Rotates offsets of the rays data using provided quaternion.
 /// </summary>
 /// <param name="rayDataList">Offsets to rotate.</param>
 /// <param name="colliderRotation">Rotation info.</param>
 private void RotateOffsets(List <RayData> rayDataList, Quaternion colliderRotation)
 {
     foreach (var singleRayData in rayDataList)
     {
         singleRayData.WidthOffset  = VectorManipulator.RotateVector(colliderRotation, singleRayData.WidthOffset);
         singleRayData.HeightOffset =
             VectorManipulator.RotateVector(colliderRotation, singleRayData.HeightOffset);
     }
 }
Example #5
0
        /// <summary>
        /// Calculates the position of the rays beginnings in one corner of each wall.
        /// </summary>
        /// <param name="raysDataList">Rays data.</param>
        private void CalculateRayPositions(List <RayData> raysDataList, Vector3 colliderCenterPosition)
        {
            Vector3 boxColliderSize = _boxCollider.size * 0.5f; //We need only half of the size since the anchor is in the middle of the collider.

            foreach (var singleRayData in raysDataList)
            {
                singleRayData.rayPosition = colliderCenterPosition + VectorManipulator.MultiplyVectorParts(singleRayData.normal, boxColliderSize);
            }
        }
Example #6
0
        void Update()
        {
            _spawnerTransform = gameObject.transform;
            var offset = _spawnerTransform.localScale * 0.5f; //Scale defines whole width. We need half of it.

            offset       = VectorManipulator.RotateVector(_spawnerTransform.rotation, offset);
            _maxPosition = (_spawnerTransform.position + offset) / _smallestLengthUnit;
            _minPosition = (_spawnerTransform.position - offset) / _smallestLengthUnit;
        }
Example #7
0
 /// <summary>
 /// Adds rotated accordingly to the collider rotation normals to the list.
 /// </summary>
 /// <param name="rayDataList">List containing ray data for each of the collider's walls.</param>
 /// <param name="colliderRotation">Rotation of the collider.</param>
 /// <returns></returns>
 private void AddNormals(List <RayData> rayDataList, Quaternion colliderRotation)
 {
     rayDataList[(int)BoxColliderWallsEnum.Right].normal   = VectorManipulator.RotateVector(colliderRotation, Vector3.right);
     rayDataList[(int)BoxColliderWallsEnum.Left].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.left);
     rayDataList[(int)BoxColliderWallsEnum.Up].normal      = VectorManipulator.RotateVector(colliderRotation, Vector3.up);
     rayDataList[(int)BoxColliderWallsEnum.Down].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.down);
     rayDataList[(int)BoxColliderWallsEnum.Forward].normal = VectorManipulator.RotateVector(colliderRotation, Vector3.forward);
     rayDataList[(int)BoxColliderWallsEnum.Back].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.back);
 }
Example #8
0
 /// <summary>
 /// Prompts drawing line between connected object and the glove.
 /// </summary>
 protected void DrawHookingLine()
 {
     if (HookingData.HookedObstacle != null)
     {
         float   halfDistance       = HookingData.HookingDistMagnitude * 0.5f;
         Vector3 secondControlPoint = VectorManipulator.CreateVectorFromRotation(GameConstants.PlayerRotationRefVector, transform.rotation, halfDistance);
         secondControlPoint += transform.position;
         _lineRenderer.DrawBezierSquared(transform.position, secondControlPoint, HookingData.HookedObstacle.GetPosition());
     }
 }
Example #9
0
        private void ClockForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (VectorManipulator.IncreaseCaptureLevel(e.Button))
            {
                //  Переключаем часы в режим трех управляемых мышью стрелок.
                this.RadioBtn_TestVectors.Checked = true;

                VectorManipulator.Movement(e.X, e.Y);
                this.Repaint();
            }
        }
Example #10
0
        /// <summary>
        /// Create a hosted element on a wall.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateHostedElement(HostedProperty properties, bool correctPosition)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the parameters from properties
            XYZ    point  = GetXYZFromProperties(properties.Coordinate);
            string fsName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

            offset = new UV(UnitUtils.ConvertToInternalUnits(offset.U, UnitTypeId.Meters),
                            UnitUtils.ConvertToInternalUnits(offset.V, UnitTypeId.Meters));

            FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsName);

            Wall wall = FindWall(point, baseLevel);

            // get the normal wall vector
            LocationCurve wallCurve      = wall.Location as LocationCurve;
            Line          wallLine       = wallCurve.Curve as Line;
            XYZ           wallStartPoint = wallLine.GetEndPoint(0);
            XYZ           wallEndPoint   = wallLine.GetEndPoint(1);
            XYZ           wallNormal     = VectorManipulator.CalculateNormal(wallStartPoint - wallEndPoint);

            // calculates the correct direction of the instance
            XYZ insertionPoint   = VectorManipulator.GetClosesetPointInLine(point, wallLine);
            XYZ correctDirection = (point - insertionPoint).Normalize();

            // calculates instance offset
            double angle = Math.Atan2(correctDirection.Y, correctDirection.X);

            offset = VectorManipulator.RotateVector(offset, angle + baseRotation);
            point += VectorManipulator.TransformUVinXYZ(offset);

            // Creates the element
            FamilyInstance instance = doc.Create.NewFamilyInstance(point, familySymbol, wall, baseLevel,
                                                                   Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            // if the initial orientation and the correct orientation are not equal, flip the instance
            if (!wallNormal.IsAlmostEqualTo(correctDirection) && correctPosition)
            {
                instance.flipFacing();
            }

            return(instance);
        }
Example #11
0
        /// <summary>
        /// Deals damage to the receiver.
        /// </summary>
        /// <param name="receiver">Damage receiving entity.</param>
        public void DealDamage(IDamageReceiver receiver)
        {
            var calculations        = Calculations.GetInstance();
            var receiverKineticData = receiver.GetKineticData();

            float thisKineticEnergy     = calculations.CalcKineticEnergy(_rigidBody.velocity, _rigidBody.mass);
            float receiverKineticEnergy =
                calculations.CalcKineticEnergy(receiverKineticData.Velocity, receiverKineticData.Mass);
            float velocityAngleFactor = VectorManipulator.CalcAngleBetweenVectors(_rigidBody.velocity, receiverKineticData.Velocity);

            //Head on collision means 0°. Perfect amortization means 180°. -cosa describes this relation, we get cosa.
            velocityAngleFactor = -velocityAngleFactor;

            receiverKineticEnergy *= velocityAngleFactor;
            float totalEnergy = thisKineticEnergy + receiverKineticEnergy;

            receiver.ReceiveDamage(totalEnergy);
        }
Example #12
0
        /// <summary>
        /// Create a single gable wall.
        /// </summary>
        /// <param name="line">
        /// The base line of the gable wall.
        /// </param>
        /// <param name="slope">
        /// The slope of this gable wall.
        /// </param>
        /// <returns></returns>
        private Wall CreateGableWall(Curve line, double slope)
        {
            // create the gable wall profile
            XYZ           p0      = line.GetEndPoint(0);
            XYZ           p1      = line.GetEndPoint(1);
            XYZ           p2      = VectorManipulator.FormTriangle(slope, p0, p1);
            IList <Curve> profile = new List <Curve>(3)
            {
                Line.CreateBound(p0, p1),
                Line.CreateBound(p1, p2),
                Line.CreateBound(p2, p0)
            };

            // get the wall type
            WallType type = revitDB.GetWallType(Properties.Settings.Default.WallTypeName);

            // create the gable wall
            return(Wall.Create(document, profile, type.Id, roofLevel.Id, false));
        }
Example #13
0
        /// <summary>
        /// Checks which of the normals point in the direction of the velocity vector. If the angle between given normal
        /// and the velocity vector is at least 90° - the normal is omitted and removed from normals list.
        /// </summary>
        /// <param name="rayDataList">List of normals.</param>
        /// <param name="velocityVector">Velocity vector.</param>
        private void ChkMovement(List <RayData> rayDataList, Vector3 velocityVector)
        {
            Vector3 normalizedVelocity = velocityVector.normalized;
            var     rayIndexesToRemove = new List <int>();

            for (int i = 0; i < rayDataList.Count; i++)
            {
                rayDataList[i].dpAgainstVelocity = VectorManipulator.CalcDotProduct(rayDataList[i].normal, normalizedVelocity);
                if (rayDataList[i].dpAgainstVelocity <= _zeroTreshold)
                {
                    rayIndexesToRemove.Add(i);
                }
            }

            for (int i = rayIndexesToRemove.Count - 1; i >= 0; i--)
            {
                rayDataList.RemoveAt(rayIndexesToRemove[i]);
            }
        }
Example #14
0
        void Update()
        {
            Vector3 distanceVector = transform.position - _blockedEntityTransform.position;
            float   distance       = VectorManipulator.CastVectorOntoVector(distanceVector, _normalVector).magnitude;

            distance = Math.Abs(distance);

            if (distance <= _reactionDistance)
            {
                float colorScale = 1 - distance * _reactionDistanceFactor;
                colorScale *= _biggestColorIntensity;

                if (colorScale < _smallestColorIntensity)
                {
                    colorScale = _smallestColorIntensity;
                }
                Debug.DrawRay(transform.position, _normalVector, Color.magenta);
                _renderer.material.color = _blockerColor * colorScale;
            }
        }
Example #15
0
        /// <summary>
        /// Creates a piece of furniture.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateFurniture(FurnitureProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the properties
            double rotation = DeegreToRadians(properties.Rotation);
            XYZ    p0       = GetXYZFromProperties(properties.Coordinate.ElementAt(0));
            XYZ    p1       = GetXYZFromProperties(properties.Coordinate.ElementAt(1));
            XYZ    point    = (p0 + p1) / 2;

            string fsFamilyName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

            offset = new UV(UnitUtils.ConvertToInternalUnits(offset.U, UnitTypeId.Meters),
                            UnitUtils.ConvertToInternalUnits(offset.V, UnitTypeId.Meters));

            offset = VectorManipulator.RotateVector(offset, rotation + baseRotation);

            // Creates a point above the furniture to serve as a rotation axis
            XYZ            axisPoint = new XYZ(point.X, point.Y, baseLevel.Elevation + 1);
            Line           axis      = Line.CreateBound(point, axisPoint);
            FamilyInstance furniture;

            try
            {
                FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsFamilyName);
                Autodesk.Revit.DB.Structure.StructuralType structuralType = Autodesk.Revit.DB.Structure.StructuralType.NonStructural;
                furniture = doc.Create.NewFamilyInstance(point, familySymbol, structuralType);
                ElementTransformUtils.RotateElement(doc, furniture.Id, axis, rotation + baseRotation);
                ElementTransformUtils.MoveElement(doc, furniture.Id, VectorManipulator.TransformUVinXYZ(offset));
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao inserir mobiliario \"" + fsFamilyName + "\".", e);
            }
            return(furniture);
        }
Example #16
0
    /// <summary>
    /// Performs player movement.
    /// </summary>
    /// <param name="axes">Axes along which the movement shall be performed. Must be normalized.</param>
    void MovePlayer(Vector3 axes)
    {
        float timeDelta = Time.deltaTime;

        _currentVelocity  = axes;
        _currentVelocity *= _maxVelocity;
        _currentVelocity *= timeDelta;

        //The editor itself applies correction to movement accordingly to player rotation,
        //but the deployed app does not. Apply it manually so the player will walk forward always
        //in the direction they're looking.
        if (_inputController.ControllerDetected)
        {
            _currentVelocity = VectorManipulator.RotateVector(_mainCameraTransform.rotation, _currentVelocity);
        }

        _currentVelocity = _collisionResolver.SolveCollisions(_movingTransform.position, _currentVelocity, _movingTransform.rotation);


        _movingTransform.Translate(_currentVelocity);
    }
Example #17
0
        /// <summary>
        /// Aplies the slope in a determined FootPrintRoof.
        /// </summary>
        /// <param name="overhang">The overhang value.</param>
        /// <param name="slope">The slope of the roof</param>
        /// <param name="slopeDirection">The vector that represents the directions that the slope should be applied.</param>
        /// <param name="footPrintRoof">The Roof</param>
        /// <param name="footPrintToModelCurveMapping">The ModelCurveArray generated with the roof instance.</param>
        private static void ApplySlope(double overhang, double slope, XYZ slopeDirection, FootPrintRoof footPrintRoof, ModelCurveArray footPrintToModelCurveMapping)
        {
            ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator();

            iterator.Reset();

            while (iterator.MoveNext())
            {
                ModelCurve modelCurve     = iterator.Current as ModelCurve;
                Curve      curve          = modelCurve.GeometryCurve;
                XYZ        curveDirection = VectorManipulator.GetCurveDirection(curve);

                if (curveDirection.DotProduct(slopeDirection) == 0)
                {
                    footPrintRoof.set_DefinesSlope(modelCurve, true);
                    footPrintRoof.set_SlopeAngle(modelCurve, slope);
                }

                double elevation = -(overhang - UnitUtils.ConvertToInternalUnits(0.1, UnitTypeId.Meters)) / 3;
                footPrintRoof.set_Offset(modelCurve, elevation);
            }
        }
Example #18
0
        /// <summary>
        /// Create the gables walls of a building.
        /// </summary>
        /// <param name="vectorDirection">
        /// The gable walls will be construct at the walls that its normal
        /// vector is parallel with the vectorDirection.
        /// </param>
        /// <param name="slope">
        /// The slope of the gable, must match the slope of the roof.
        /// </param>
        public void CreateAllGableWalls(XYZ vectorDirection, double slope, CurveArray perimeter, List <Wall> gableWalls)
        {
            Polygon perimiterPolygon = new Polygon(perimeter);

            perimiterPolygon.Normalize();
            perimeter = perimiterPolygon.CurveArray;
            foreach (Curve line in perimeter)
            {
                XYZ lineDirection = VectorManipulator.GetCurveDirection(line);
                if (lineDirection.CrossProduct(vectorDirection).IsZeroLength())
                {
                    Wall newGableWall     = CreateGableWall(line, slope);
                    Wall intersectionWall = FindIntersectionWall(gableWalls, newGableWall);
                    bool insert           = true;
                    if (intersectionWall != null)
                    {
                        LocationCurve intersectionWallLocation = intersectionWall.Location as LocationCurve;
                        LocationCurve newGableWallLocation     = newGableWall.Location as LocationCurve;
                        Wall          deleteWall;

                        if (intersectionWallLocation.Curve.Length > newGableWallLocation.Curve.Length)
                        {
                            deleteWall = newGableWall;
                            insert     = false;
                        }
                        else
                        {
                            deleteWall = intersectionWall;
                        }
                        gableWalls.Remove(deleteWall);
                        document.Delete(deleteWall.Id);
                    }
                    if (insert)
                    {
                        gableWalls.Add(newGableWall);
                    }
                }
            }
        }
Example #19
0
        void Start()
        {
            if (_reactionDistance <= 0.0f)
            {
                throw new Exception("Error: _reaction distance cannot be lesser or equal to 0!");
            }

            _reactionDistanceFactor = 1 / _reactionDistance;
            _normalVector           = VectorManipulator.RotateVector(gameObject.transform.rotation, _normalVector);

            if (_renderer == null)
            {
                throw new Exception("Error: EntityBlockerScript has no renderer attached!");
            }

            if (_blockedEntityTransform == null)
            {
                throw new Exception(
                          "Error: EntityBlockerScript has no blocked entity transform attached. How is it supposed to check for distance?");
            }

            _renderer.material.color = _blockerColor * _smallestColorIntensity;
        }
Example #20
0
        /// <summary>
        /// Verifies if the curve is collinear and have atleast one point in common with any line in the given list of lines.
        /// </summary>
        /// <param name="curve">The curve that will be compared with the list.</param>
        /// <param name="lines">The list of lines that the first will be compared with.</param>
        /// <returns>Returns true if the curve intersects and is parallel to any line in the array.</returns>
        private bool VerifyIntersectionInArray(Curve curve, List <Line> lines)
        {
            Transform transform = Transform.CreateTranslation(new XYZ(0, 0, -curve.GetEndPoint(0).Z));

            curve = curve.CreateTransformed(transform);
            foreach (Line line in lines)
            {
                // verifiy is the line is equal or a subset of the curve
                SetComparisonResult result = line.Intersect(curve);
                if (result == SetComparisonResult.Equal ||
                    result == SetComparisonResult.Subset)
                {
                    return(true);
                }
                // verify if the line intersects and is parallel
                if (result == SetComparisonResult.Overlap && (line.Direction.CrossProduct(VectorManipulator.GetCurveDirection(curve)).IsZeroLength()))
                {
                    return(true);
                }
            }
            return(false);
        }