Ejemplo n.º 1
0
        public override void Read(BinaryReader Reader)
        {
            base.Read(Reader);

            Unk0     = Reader.ReadByte();
            Position = Vector3Utils.ReadFromFile(Reader);
            Rotation = Vector3Utils.ReadFromFile(Reader);
            Unk1     = Reader.ReadUInt32();
            Unk2     = Reader.ReadUInt32();
            Unk3     = Reader.ReadUInt32();
            Unk4     = Vector3Utils.ReadFromFile(Reader);
            Unk5     = Reader.ReadSingle();
            Unk6     = Reader.ReadByte();
            Unk7     = Reader.ReadByte();

            ushort Size = Reader.ReadUInt16();

            Unk8 = new uint[Size];
            for (int i = 0; i < Unk8.Length; i++)
            {
                Unk8[i] = Reader.ReadUInt32();
            }

            Unk9 = Reader.ReadUInt32();
        }
Ejemplo n.º 2
0
        private void AttemptToRotate()
        {
            var sumX   = BlockItems.value.Sum(block => block.Position.x);
            var sumY   = BlockItems.value.Sum(block => block.Position.y);
            var pivotX = Mathf.RoundToInt(sumX / BlockItems.value.Length);
            var pivotY = Mathf.RoundToInt(sumY / BlockItems.value.Length);

            var rotatedPositions = BlockItems.value.Slinq()
                                   .Select(block => Vector3Utils.RotateAroundPivot(
                                               new Vector3(block.Position.x, block.Position.y, 0),
                                               new Vector3(pivotX, pivotY, 0),
                                               Vector3.forward * 90))
                                   .Select(vector3Pos => new Vector2Int(
                                               Mathf.RoundToInt(vector3Pos.x),
                                               Mathf.RoundToInt(vector3Pos.y)))
                                   .ToArray();

            var doInteract = GameGrid.InteractWithExisting(rotatedPositions);

            if (doInteract)
            {
                return;
            }

            for (int i = 0; i < rotatedPositions.Length; i++)
            {
                BlockItems.value[i].Position = rotatedPositions[i];
            }
        }
        public virtual void MoveTargetToTargetIndex()
        {
            Vector3 _targetPos = Vector3Utils.Lerp(-range, range, m_targetIndex);

            DriveUtils.LockFreeAxisPosition(ref _targetPos, axis);
            _targetPos = transform.TransformPoint(_targetPos);

            _targetPos = Vector3.SmoothDamp(
                targetObject.position,
                _targetPos,
                ref targetVelocity,
                1 / speed * Time.deltaTime);

            if (!onlyMoveWithVelocity)
            {
                targetObject.position = _targetPos;
            }
            else
            {
                Vector3 positionDelta      = _targetPos - targetObject.position;
                Vector3 velocityTarget     = positionDelta / Time.deltaTime;
                Vector3 calculatedVelocity = Vector3.MoveTowards(targetRigidbody.velocity, velocityTarget, 10);
                calculatedVelocity      *= 1 / speed;
                targetRigidbody.velocity = calculatedVelocity;
            }
        }
Ejemplo n.º 4
0
        /**
         * Activate the server-side path calculation for a given ped
         *
         * @param ped Ped which path should be calculated by the server
         */
        public void AddPedMovementCalculcation(Ped ped, bool SetCurrentNavmashPositionsIndex = true)
        {
            if (ped.Freeze || ped.Dead || !ped.Wandering)
            {
                return;
            }
            if (SetCurrentNavmashPositionsIndex)
            {
                ped.CurrentNavmashPositionsIndex = GetNearestNavMeshOfPed(ped);
            }

            if (ped.CurrentNavmashPositionsIndex < 0 || ped.PathPositions.Count >= ped.CurrentNavmashPositionsIndex)
            {
                ped.Wandering = true;
                return;
            }

            ped.Position = ped.PathPositions[ped.CurrentNavmashPositionsIndex].Position;

            if (ped.PathPositions.Count < ped.CurrentNavmashPositionsIndex + 1)
            {
                ped.ContinueWandering();
                ped.CurrentNavmashPositionsIndex = 0;
            }

            AddPedMovement(
                (int)Math.Ceiling(Vector3Utils.GetDistanceBetweenPos(ped.Position, ped.PathPositions[ped.CurrentNavmashPositionsIndex + 1].Position)),
                ped
                );
        }
Ejemplo n.º 5
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);

            NumFrames = stream.ReadInt32(isBigEndian);
            Frames    = new FrameData[NumFrames];

            for (int i = 0; i < NumFrames; i++)
            {
                FrameData frames = new FrameData();
                frames.Unk01     = stream.ReadInt32(isBigEndian);
                frames.Unk02     = stream.ReadInt32(isBigEndian);
                frames.Unk03     = stream.ReadByte8();
                frames.SoundFile = stream.ReadString16(isBigEndian);
                frames.Unk04     = stream.ReadByte8();
                frames.Unk05     = stream.ReadSingle(isBigEndian);
                frames.Unk06     = stream.ReadSingle(isBigEndian);
                frames.Unk07     = stream.ReadSingle(isBigEndian);
                frames.Unk08     = stream.ReadInt32(isBigEndian);
                frames.Unk09     = stream.ReadSingle(isBigEndian);
                frames.Unk10     = stream.ReadInt32(isBigEndian);
                frames.Unk11     = stream.ReadSingle(isBigEndian);
                frames.Unk12     = stream.ReadInt32(isBigEndian);
                frames.Unk13     = stream.ReadSingle(isBigEndian);
                frames.Unk14     = stream.ReadSingle(isBigEndian);
                frames.Unk15     = stream.ReadByte8();
                frames.Position  = Vector3Utils.ReadFromFile(stream, isBigEndian);
                frames.Rotation  = QuaternionExtensions.ReadFromFile(stream, isBigEndian);
                frames.Unk16     = stream.ReadByte8();
                Frames[i]        = frames;
            }

            Unk05 = stream.ReadUInt16(isBigEndian);
        }
Ejemplo n.º 6
0
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt16() != Magic)
            {
                return;
            }

            ushort animalInsCount = reader.ReadUInt16();

            instances = new AnimalTrafficInstance[animalInsCount];

            if (reader.ReadInt32() != Version)
            {
                return;
            }

            for (int i = 0; i < animalInsCount; i++)
            {
                AnimalTrafficInstance instance = new AnimalTrafficInstance();
                instance.Name = new HashName();
                instance.Name.ReadFromFile(reader);
                instances[i] = instance;
            }

            ushort pathCount = reader.ReadUInt16();

            paths = new AnimalTrafficPath[pathCount];

            for (int i = 0; i < pathCount; i++)
            {
                AnimalTrafficPath path = new AnimalTrafficPath();
                byte pathSize          = reader.ReadByte();
                byte count1            = reader.ReadByte();
                byte count2            = reader.ReadByte();
                byte count3            = reader.ReadByte();
                path.Data0       = reader.ReadBytes(count1);
                path.Data1       = reader.ReadBytes(count2);
                path.Data2       = reader.ReadBytes(count3);
                path.BoundingBox = BoundingBoxExtenders.ReadFromFile(reader);
                path.Hash        = new HashName();
                path.Hash.ReadFromFile(reader);     //decompiled exe says this is a hash but its always empty
                path.Unk0    = reader.ReadSingle(); //5
                path.Unk1    = reader.ReadSingle(); //15
                path.Unk2    = reader.ReadByte();   //1 257 or 513.
                path.Unk3    = reader.ReadBytes(path.Unk2);
                path.Vectors = new PathVectors[pathSize];

                for (int x = 0; x < pathSize; x++)
                {
                    PathVectors vector = new PathVectors();
                    vector.Position = Vector3Utils.ReadFromFile(reader); //Very large differences between these two
                    vector.Rotation = Vector3Utils.ReadFromFile(reader); //2nd one could be rotation, in radians.
                    vector.Unk0     = reader.ReadByte();                 //7 or 4
                    path.Vectors[x] = vector;
                }


                paths[i] = path;
            }
        }
Ejemplo n.º 7
0
        //Function to determine the nearest navMesh to the ped
        public static int GetNearestNavMeshOfPed(Ped Ped)
        {
            if (Ped.PathPositions.Count == 0)
            {
                return(-1);
            }

            int    MinimumPos      = -1;
            double MinimumDistance = 1000;

            int i = 0;

            foreach (IPathElement NavMesh in Ped.PathPositions)
            {
                double Distance = Vector3Utils.GetDistanceBetweenPos(Ped.Position, NavMesh.Position);

                if (MinimumDistance > Distance)
                {
                    MinimumPos      = i;
                    MinimumDistance = Distance;
                }
                i++;
            }

            return(MinimumPos);
        }
Ejemplo n.º 8
0
 public void ReadFromFile(BinaryReader reader)
 {
     Position = Vector3Utils.ReadFromFile(reader);
     Rotation = Vector3Utils.ReadFromFile(reader);
     Hash     = reader.ReadUInt64();
     Unk4     = reader.ReadInt32();
     Unk5     = reader.ReadByte();
 }
Ejemplo n.º 9
0
        private void LoadPhysics()
        {
            //Physics
            BufferPool = new BufferPool();

            Radii = new List <float>();

            SphereHandles = new List <BodyHandle>();

            var targetThreadCount = Math.Max(1,
                                             Environment.ProcessorCount > 4 ? Environment.ProcessorCount - 2 : Environment.ProcessorCount - 1);

            ThreadDispatcher = new SimpleThreadDispatcher(targetThreadCount);

            Simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(),
                                           new PoseIntegratorCallbacks(new NumericVector3(0, -500, 0)), new PositionFirstTimestepper());

            //     Simulation.Statics.Add(new StaticDescription(new NumericVector3(0, 0, 0),
            //new CollidableDescription(Simulation.Shapes.Add(new Box(2000, 100, 5000)), 1)));
            //  for (int i=0;i<MatrixWorld.Count;i++)
            //  {
            //      Matrix world = MatrixWorld[i];
            //      Simulation.Statics.Add(new StaticDescription(new NumericVector3(world.Translation.X, world.Translation.Y, world.Translation.Z),
            //     new CollidableDescription(Simulation.Shapes.Add(new Box(200, 100, 500)), 1)));
            //  }
            //Simulation.Statics.Add(new StaticDescription(new NumericVector3(0, -20, 0),
            //  new CollidableDescription(Simulation.Shapes.Add(new Box(200, 100, 500)), 1)));

            //Simulation.Statics.Add(new StaticDescription(new NumericVector3(9, 28, 200), new CollidableDescription(Simulation.Shapes.Add(new Sphere(2f)),1)));
            //Simulation.Statics.Add(new StaticDescription(new ))

            /* for (int i = 0; i < MatrixWorld.Count(); i++)
             * {
             *   Simulation.Statics.Add(new StaticDescription(MatrixWorld[i].))
             *   Floor.Draw(MatrixWorld[i], Camera.View, Camera.Projection);
             * }*/


            //Simulation.Statics.Add(new StaticDescription(new NumericVector3(0, -20, 0), new CollidableDescription(Simulation.Shapes.Add(
            //  new Box(2000, 100, 2000)), 1)));
            //Esfera
            SpheresWorld = new List <Matrix>();


            var radius          = 5f;
            var sphereShape     = new Sphere(radius);
            var position        = Vector3Utils.toNumeric(PlayerInitialPosition);
            var bodyDescription = BodyDescription.CreateConvexDynamic(position, 1 / radius * radius * radius,
                                                                      Simulation.Shapes, sphereShape);

            var bodyHandle = Simulation.Bodies.Add(bodyDescription);

            SphereHandles.Add(bodyHandle);

            Radii.Add(radius);
        }
Ejemplo n.º 10
0
        public override void Read(BinaryReader Reader)
        {
            base.Read(Reader);

            Unk0 = Reader.ReadByte();
            Unk1 = Vector3Utils.ReadFromFile(Reader);
            Unk2 = Vector3Utils.ReadFromFile(Reader);
            Unk3 = Vector3Utils.ReadFromFile(Reader);
            Unk4 = Reader.ReadUInt32(); // int32 (could be split into two shorts)
        }
        public void ShouldNotFailIfOnShotHitHasNoSubscribes()
        {
            BuildFirstPersonModePlayer(
                out FirstPersonMode firstPerson,
                out _,
                out _
                );

            var randomPoint = Vector3Utils.RandomPoint();

            Assert.DoesNotThrow(() => firstPerson.ShootHit(randomPoint));
        }
Ejemplo n.º 12
0
        public override void ReadFromFile(MemoryStream stream, bool isBigEndian)
        {
            base.ReadFromFile(stream, isBigEndian);

            NumSounds = stream.ReadInt32(isBigEndian);
            Sounds    = new SoundData_Type19[NumSounds];

            for (int i = 0; i < NumSounds; i++)
            {
                SoundData_Type19 SoundInfo = new SoundData_Type19();
                SoundInfo.Unk01     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk02     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk03     = stream.ReadByte8();
                SoundInfo.SoundFile = stream.ReadString16(isBigEndian);
                SoundInfo.Unk04     = stream.ReadByte8();
                SoundInfo.Unk05     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk06     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk07     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk08     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk10     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk11     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk12     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk13     = stream.ReadInt32(isBigEndian);
                SoundInfo.Unk14     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk15     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk16     = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk17     = stream.ReadSingle(isBigEndian);

                SoundInfo.Unk18    = stream.ReadByte8();
                SoundInfo.Position = Vector3Utils.ReadFromFile(stream, isBigEndian);
                SoundInfo.Unk19    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk20    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk21    = stream.ReadSingle(isBigEndian);
                SoundInfo.Unk22    = stream.ReadSingle(isBigEndian);

                SoundInfo.IsMeshAvailableFlags = stream.ReadByte8();
                if (SoundInfo.IsMeshAvailableFlags == 3)
                {
                    SoundInfo.FrameName     = stream.ReadString16(isBigEndian);
                    SoundInfo.MainJointHash = stream.ReadUInt64(isBigEndian);
                    SoundInfo.FrameHash     = stream.ReadUInt64(isBigEndian);
                }
                else if (SoundInfo.IsMeshAvailableFlags == 1)
                {
                    SoundInfo.FrameName     = stream.ReadString16(isBigEndian);
                    SoundInfo.MainJointHash = stream.ReadUInt64(isBigEndian);
                }

                Sounds[i] = SoundInfo;
            }

            Unk05 = stream.ReadUInt16(isBigEndian);
        }
Ejemplo n.º 13
0
 public void WriteToFile(BinaryWriter writer)
 {
     writer.Write(position.Length);
     for (int i = 0; i < position.Length; i++)
     {
         Vector3Utils.WriteToFile(position[i], writer);
     }
     writer.Write(sphere.Length);
     for (int i = 0; i < sphere.Length; i++)
     {
         Vector3Utils.WriteToFile(sphere[i], writer);
     }
 }
Ejemplo n.º 14
0
        public override void Read(BinaryReader Reader)
        {
            base.Read(Reader);

            Unk0      = Reader.ReadUInt16();
            Position  = Vector3Utils.ReadFromFile(Reader);
            Direction = Vector3Utils.ReadFromFile(Reader);
            Unk2      = Vector3Utils.ReadFromFile(Reader);
            Unk3      = Reader.ReadUInt32();

            Minimum = new Vector3(-Unk2.Y, -Unk2.X, -Unk2.Z);
            Maximum = new Vector3(Unk2.Y, Unk2.X, Unk2.Z);
        }
        public override void MoveTarget(Vector3 newPos)
        {
            newPos = relativeForward.TransformDirection(newPos);

            if (removeY)
            {
                base.MoveTarget(Vector3Utils.RemoveY(newPos));
            }
            else
            {
                base.MoveTarget(newPos);
            }
        }
Ejemplo n.º 16
0
        public bool UpdateInput()
        {
            bool  bCameraUpdated = false;
            float Multiplier     = ToolkitSettings.CameraSpeed;

            if (Input.IsKeyDown(Keys.ShiftKey))
            {
                Multiplier *= 2.0f;
            }

            float speed = Profile.DeltaTime * Multiplier;

            if (Input.IsKeyDown(Keys.A))
            {
                Camera.Position -= Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(0), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.D))
            {
                Camera.Position += Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(0), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.W))
            {
                Camera.Position -= Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(2), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.S))
            {
                Camera.Position += Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(2), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.Q))
            {
                Camera.Position.Z += speed;
                bCameraUpdated     = true;
            }

            if (Input.IsKeyDown(Keys.E))
            {
                Camera.Position.Z -= speed;
                bCameraUpdated     = true;
            }

            return(bCameraUpdated);
        }
Ejemplo n.º 17
0
        public void WriteToFile(NavigationWriter writer)
        {
            writer.Write(unk0);
            writer.Write(fileIDHPD);
            writer.Write(unk3HPD);
            writer.Write(bitFlagsHPD);
            writer.Write(vertSize);
            writer.Write(triSize);

            for (int i = 0; i < vertices.Length; i++)
            {
                var vertex = vertices[i];
                writer.Write(vertex.Unk7); // | 0x80000000

                Vector3 pos = vertex.Position;
                float   z   = pos.Z; // TODO: Construct KynogonUtils to accomodate this
                pos.Z = -pos.Y;
                pos.Y = z;
                Vector3Utils.WriteToFile(pos, writer); // NB: DO NOT SET vertex.Position as pos!!
                writer.Write(vertex.Unk0);
                writer.Write(vertex.Unk1);
                writer.Write(vertex.Unk2);
                writer.Write(vertex.Unk3);
                writer.Write(vertex.Unk4);
                writer.Write(vertex.Unk5);
                writer.Write(vertex.Unk6);
            }

            for (int i = 0; i < connections.Length; i++)
            {
                var connection = connections[i];
                writer.Write(connection.Flags | 0x80000000);
                writer.Write(connection.NodeID);
                writer.Write(connection.ConnectedNodeID);
            }

            runtimeMesh.WriteToFile(writer);

            writer.Write(Footer);

            // write footer

            /* if (!runtimeMesh.bDEBUG_HASEXTRADATA)
             * {
             *   writer.Write(Padding);
             *   StringHelpers.WriteString(writer, Name);
             *   writer.Write(Name.Length + 1); // extra 1 is the padding
             *   writer.Write(303296513);
             * }*/
        }
Ejemplo n.º 18
0
    void Awake()
    {
        tetrominoGravity      = new GameObject().AddComponent <Gravity>();
        tetrominoGravity.name = "TetrominoGravity";

        gridGravity      = new GameObject().AddComponent <Gravity>();
        gridGravity.name = "GridGravity";


        scaleFactor           = 16;
        scaleVector           = Vector3Int.one * (scaleFactor - 1);
        transform.localScale += scaleVector;

        transform.position = new Vector3Int(1, -10 * scaleFactor, 0);

        mainCamera = GameObject.Find("Main Camera").GetComponent <Camera>();
        mainCamera.orthographicSize = 12 * scaleFactor;

        basePosition = Vector3Utils.ToVector3Int(transform.position) + new Vector3Int(scaleFactor, scaleFactor, 0);

        tetrominoSpawner = Instantiate(tetrominoSpawnerPrefab).GetComponent <TetrominoSpawner>();
        tetrominoSpawner.Initialize(this);

        pistonSpawner = Instantiate(pistonSpawnerPrefab).GetComponent <PistonSpawner>();
        pistonSpawner.Initialize(this);

        pistonMask = GameObject.Find("PistonMask");
        pistonMask.transform.position    = transform.position + scaleFactor * new Vector3(5.5f, 10.5f, 0);
        pistonMask.transform.localScale += scaleVector;

        debugMap = GameObject.Find("DebugMap").GetComponent <DebugMap>();
        debugMap.transform.position    = scaleFactor * debugMap.transform.position;
        debugMap.transform.localScale += scaleVector;

        grid = new Transform[gridWidth, gridHeight];

        gridUtils.Initialize(grid);

        //rowSlider = new GameObject().AddComponent<RowSlider>();
        //rowSlider.name = "RowSlider";
        //rowSlider.Initialize(this);

        SpawnNextTetromino();

        rowPosition = new Vector3[Map.gridHeight];
        ResetRowPosition();

        currentTetromino.ImmediateFall(playerPrefab);
    }
Ejemplo n.º 19
0
        public virtual void FixedUpdate()
        {
            LimitChildrenVeloctiy();

            if (moveToTarget)
            {
                Vector3 targetPos = Vector3Utils.Lerp(-range, range, m_targetIndex);
                targetPos = transform.TransformPoint(targetPos);

                for (int i = 0; i < children.Length; i++)
                {
                    children[i].transform.position = Vector3.SmoothDamp(children[i].transform.position, targetPos, ref targetVelocities[i], 1 / speed);
                }
            }
        }
Ejemplo n.º 20
0
        public Ray GetPickingRay(Vector2 pos, Vector2 screenDims)
        {
            Matrix4x4 InvertedViewProj = Matrix4x4.Identity;

            Matrix4x4.Invert(ViewMatrix * ProjectionMatrix, out InvertedViewProj);
            var farPoint = Vector3Utils.TransformCoordinate(
                new Vector3(2.0f * pos.X / screenDims.X - 1.0f, -2.0f * pos.Y / screenDims.Y + 1.0f, 1f),
                InvertedViewProj
                );

            Vector3 NormalisedDir = Vector3.Normalize(farPoint - Position);
            var     ray           = new Ray(Position, NormalisedDir);

            return(ray);
        }
Ejemplo n.º 21
0
        public virtual void EventCalls()
        {
            if (targetObject)
            {
                if (Vector3.Distance(previousPos, targetObject.position) >= float.Epsilon)
                {
                    Vector3 localPos = transform.InverseTransformPoint(targetObject.position);
                    //localPos += range;
                    localPos  = Vector3Utils.Divide(localPos, range);
                    localPos += Vector3.one;
                    localPos /= 2;

                    normalizeMoved?.Invoke(localPos);
                    MovedX?.Invoke(localPos.x);
                    MovedY?.Invoke(localPos.y);
                    MovedZ?.Invoke(localPos.z);

                    if (axisValueEvents != null)
                    {
                        foreach (AxisValueListener axisListener in axisValueEvents)
                        {
                            switch (axisListener.axis)
                            {
                            case AxisValueListener.SingleAxis.X:
                                axisListener.Receive(localPos.x);
                                break;

                            case AxisValueListener.SingleAxis.Y:
                                axisListener.Receive(localPos.y);
                                break;

                            case AxisValueListener.SingleAxis.Z:
                                axisListener.Receive(localPos.z);
                                break;
                            }
                        }
                    }

                    if (vec3ValueEvents != null)
                    {
                        foreach (Vector3ValueListener _event in vec3ValueEvents)
                        {
                            _event.Receive(localPos);
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private int GetMaterial(ref Vector3 WorldPosition, Ray CameraRay)
        {
            var lowest     = float.MaxValue;
            var materialID = -1;

            Matrix4x4 InvertedWM = Matrix4x4.Identity;

            Matrix4x4.Invert(GizmoModel.Transform, out InvertedWM);
            var localRay = new Ray(
                Vector3Utils.TransformCoordinate(CameraRay.Position, InvertedWM),
                Vector3.TransformNormal(CameraRay.Direction, InvertedWM)
                );

            var bbox = GizmoModel.BoundingBox;

            if (localRay.Intersects(bbox) > 0.0f)
            {
                return(-1);
            }

            for (var i = 0; i < GizmoModel.LODs[0].ModelParts.Length; i++)
            {
                var ModelPart  = GizmoModel.LODs[0].ModelParts[i];
                var StartIndex = ModelPart.StartIndex / 3;
                for (var x = StartIndex; x < StartIndex + ModelPart.NumFaces; x++)
                {
                    var   v0 = GizmoModel.LODs[0].Vertices[GizmoModel.LODs[0].Indices[x * 3]].Position;
                    var   v1 = GizmoModel.LODs[0].Vertices[GizmoModel.LODs[0].Indices[x * 3 + 1]].Position;
                    var   v2 = GizmoModel.LODs[0].Vertices[GizmoModel.LODs[0].Indices[x * 3 + 2]].Position;
                    float t  = 1.0f;

                    /*if (!localRay.Intersects(v0, v1, v2, out t))
                     * {
                     *  continue;
                     * }*/

                    WorldPosition = CameraRay.Position + t * CameraRay.Direction;
                    var distance = (WorldPosition - CameraRay.Position).LengthSquared();
                    if (distance < lowest)
                    {
                        lowest     = distance;
                        materialID = i;
                    }
                }
            }

            return(materialID);
        }
        public void OnShootHitBehaviour()
        {
            BuildFirstPersonModePlayer(
                out FirstPersonMode firstPerson,
                out _,
                out _
                );

            var randomPoint = Vector3Utils.RandomPoint();

            void expected(Vector3 point) => Assert.AreEqual(randomPoint, point);

            firstPerson.OnShotHit += expected;

            firstPerson.ShootHit(randomPoint);
        }
Ejemplo n.º 24
0
        private float RotateXWheels()
        {
            if (Vector3Utils.NearlyEqual(rg.velocity, Vector3.zero, 0.3f))
            {
                rotateX = 0f;
                return(0f);
            }


            if (Vector3.Dot(rg.velocity, transform.forward) < 0)
            {
                return(-1f);
            }

            return(1f);
        }
Ejemplo n.º 25
0
    public DrawQueueItem(string json)
    {
        JSONObject item = JSONObject.Parse(json);

        position = Vector3Utils.StringToVector3(item.GetString("position"));
        start    = item.GetBoolean("start");
        end      = item.GetBoolean("end");
        velocity = Vector3Utils.StringToVector3(item.GetString("velocity"));

        if (string.IsNullOrEmpty(item.GetString("character")) == false)
        {
            character = item.GetString("character");
        }

        touched = item.GetBoolean("touched");
    }
Ejemplo n.º 26
0
        /// <summary>
        /// Read data from stream.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            numLods = reader.ReadByte8();
            unk01   = reader.ReadInt16(isBigEndian);

            decompressionOffset = Vector3Utils.ReadFromFile(reader, isBigEndian);
            decompressionFactor = reader.ReadSingle(isBigEndian);

            LOD = new FrameLOD[numLods];

            for (int i = 0; i < numLods; i++)
            {
                LOD[i] = new FrameLOD();
                LOD[i].ReadFromFile(reader, isBigEndian);
            }
        }
Ejemplo n.º 27
0
        public void EventCalls()
        {
            if (interactable)
            {
                if (Vector3.Distance(previousPos, interactable.transform.position) >= float.Epsilon)
                {
                    Vector3 localPos = transform.InverseTransformPoint(interactable.transform.position);
                    localPos += range;
                    localPos  = Vector3Utils.Clamp01(localPos);

                    normalizeMoved?.Invoke(localPos);
                    MovedX?.Invoke(localPos.x);
                    MovedY?.Invoke(localPos.y);
                    MovedZ?.Invoke(localPos.z);

                    if (axisValueEvents != null)
                    {
                        foreach (AxisValueListener axisListener in axisValueEvents)
                        {
                            switch (axisListener.axis)
                            {
                            case AxisValueListener.SingleAxis.X:
                                axisListener.Receive(localPos.x);
                                break;

                            case AxisValueListener.SingleAxis.Y:
                                axisListener.Receive(localPos.y);
                                break;

                            case AxisValueListener.SingleAxis.Z:
                                axisListener.Receive(localPos.z);
                                break;
                            }
                        }
                    }

                    if (vec3ValueEvents != null)
                    {
                        foreach (Vector3ValueListener _event in vec3ValueEvents)
                        {
                            _event.Receive(localPos);
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        public override void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            base.ReadFromFile(reader, isBigEndian);
            unk_08_int = reader.ReadInt32(isBigEndian);
            planesSize = reader.ReadInt32(isBigEndian);

            planes = new Vector4[planesSize];
            for (int i = 0; i != planes.Length; i++)
            {
                planes[i] = Vector4Extenders.ReadFromFile(reader, isBigEndian);
            }

            bounds         = BoundingBoxExtenders.ReadFromFile(reader, isBigEndian);
            unk_13_vector3 = Vector3Utils.ReadFromFile(reader, isBigEndian);
            unk_14_vector3 = Vector3Utils.ReadFromFile(reader, isBigEndian);
            sectorName     = new HashName(reader, isBigEndian);
        }
Ejemplo n.º 29
0
    public virtual bool Act(double x, double y, double z, ref Voxel voxel)
    {
        if (x >= from.x && x <= to.x &&
            y >= from.y && y <= to.y &&
            z >= from.z && z <= to.z)
        {
            voxel.Value = Math.Max(voxel.Value, -Vector3Utils.DistanceTo(bounds, converter.VoxelToUnityPosition(x, y, z).ToUnityOrigin()));
            if (voxelType != null)
            {
                voxel.VoxelType = voxelType;
            }

            return(true);
        }

        return(false);
    }
Ejemplo n.º 30
0
        //Calculate a random path starting with the given navMesh
        public List <IPathElement> GetWanderingPath()
        {
            //Prepare the path
            List <IPathElement> path = new List <IPathElement>();

            //Add start navMesh to the path
            path.Add(this);

            //If the given navMesh doesn't have a neighbour: Stop
            if (this.GetNeighbours().Count == 0)
            {
                return(path);
            }

            //Select a random neighbour of this navMesh to start
            IPathElement randomNavMesh = this.GetRandomNeighbour();

            //If the random navMesh is null (no neighbours could be selected): Stop
            if (randomNavMesh == null)
            {
                return(path);
            }

            //Add random navMesh to the path
            path.Add(randomNavMesh);

            //Repeat till the path includes 50 stations
            for (int i = path.Count; i < 200; i++)
            {
                //Expand the previous navMesh, select the neighbour by the given directional angle
                IPathElement?pathMesh = path[path.Count - 1].GetRandomNewNeighbourByDirectionAndPath(
                    Vector3Utils.directionalAngle(path[path.Count - 2].Position, path[path.Count - 1].Position), path);

                //If this new station is noll (no neighbours could be selected): Stop
                if (pathMesh == null)
                {
                    return(path);
                }

                //Add this navMesh to the path
                path.Add(pathMesh);
            }

            return(path);
        }