Пример #1
0
        private void PerformNormalMove(float elapsedTime, float speed, TGCVector3 headPosition)
        {
            CharacterOnSight = false;
            var XRotation = 0f;
            var YRotation = 0f;

            ChangeDirectionTimeCounter -= elapsedTime;
            Terrain.world.InterpoledHeight(headPosition.X, headPosition.Z, out float floorHeight);
            var distanceToFloor = Body.CenterOfMassPosition.Y - floorHeight;
            var XRotationStep   = FastMath.PI * 0.1f * elapsedTime;
            var YRotationStep   = FastMath.PI * 0.4f * elapsedTime;

            var        distanceToWater    = Constants.WATER_HEIGHT - floorHeight - 200;
            TGCVector2 sharkRangePosition =
                new TGCVector2(Constants.SHARK_HEIGHT.X, FastMath.Min(distanceToWater, Constants.SHARK_HEIGHT.Y));

            if (distanceToFloor < sharkRangePosition.X - 150 && AcumulatedXRotation < Constants.MaxAxisRotation)
            {
                XRotation = XRotationStep;
            }
            else if (FastUtils.IsNumberBetweenInterval(distanceToFloor, sharkRangePosition) && AcumulatedXRotation > 0.0012)
            {
                XRotation = -XRotationStep;
            }
            else if (distanceToFloor > sharkRangePosition.Y + 150 && AcumulatedXRotation > -Constants.MaxAxisRotation)
            {
                XRotation = -XRotationStep;
            }
            else if (FastUtils.IsNumberBetweenInterval(distanceToFloor, sharkRangePosition) && AcumulatedXRotation < -0.0012)
            {
                XRotation = XRotationStep;
            }

            if (ChangeDirectionTimeCounter <= 0)
            {
                if (FastMath.Abs(AcumulatedYRotation) < Constants.MaxYRotation)
                {
                    YRotation = YRotationStep * RotationYSign();
                }
                else
                {
                    ChangeDirectionTimeCounter = Constants.CHANGE_DIRECTION_TIME;
                }
            }
            else
            {
                AcumulatedYRotation = 0;
            }

            AcumulatedXRotation += XRotation;
            AcumulatedYRotation += YRotation;

            Body.ActivationState = ActivationState.ActiveTag;
            TGCMatrix rotation = TGCMatrix.Identity;

            if (XRotation != 0 || FastMath.Abs(AcumulatedXRotation) > 0.0012)
            {
                var rotationAxis = TGCVector3.Cross(TGCVector3.Up, director);
                director.TransformCoordinate(TGCMatrix.RotationAxis(rotationAxis, XRotation));
                rotation = TGCMatrix.RotationAxis(rotationAxis, XRotation);
                speed   /= 1.5f;
            }
            else if (YRotation != 0)
            {
                director.TransformCoordinate(TGCMatrix.RotationY(YRotation));
                rotation = TGCMatrix.RotationY(YRotation);
            }
            TotalRotation      *= rotation;
            Mesh.Transform      = TotalRotation * TGCMatrix.Translation(new TGCVector3(Body.CenterOfMassPosition));
            Body.WorldTransform = Mesh.Transform.ToBulletMatrix();
            Body.LinearVelocity = director.ToBulletVector3() * -speed;
        }
Пример #2
0
        private void PerformNormalMove(float elapsedTime, float speed, TGCVector3 headPosition)
        {
            time -= elapsedTime;
            ChangeDirectionTimeCounter -= elapsedTime;

            float XRotation = 0f, YRotation = 0f;
            var   meshPosition = GetMeshPosition();

            Terrain.world.InterpoledHeight(headPosition.X, headPosition.Z, out float floorHeight);
            var distanceToFloor = FastUtils.Distance(meshPosition.Y, floorHeight);

            var XRotationStep = FastMath.PI * 0.1f * elapsedTime;
            var YRotationStep = FastMath.PI * 0.03f * elapsedTime;

            if (FastUtils.LessThan(distanceToFloor, Constants.FishHeight.X - 40) && FastUtils.LessThan(acumulatedXRotation, Constants.MaxAxisRotation))
            {
                XRotation = XRotationStep;
            }
            else if (FastUtils.IsNumberBetweenInterval(distanceToFloor, Constants.FishHeight) && FastUtils.GreaterThan(acumulatedXRotation, 0.0012f))
            {
                XRotation = -XRotationStep;
            }

            if (FastUtils.GreaterThan(distanceToFloor, Constants.FishHeight.Y + 40) && FastUtils.GreaterThan(acumulatedXRotation, -Constants.MaxAxisRotation))
            {
                XRotation = -XRotationStep;
            }
            else if (FastUtils.IsNumberBetweenInterval(distanceToFloor, Constants.FishHeight) && FastUtils.LessThan(acumulatedXRotation, -0.0012f))
            {
                XRotation = XRotationStep;
            }

            if (ChangeDirectionTimeCounter <= 0)
            {
                if (FastUtils.LessThan(FastMath.Abs(acumulatedYRotation), Constants.MaxYRotation))
                {
                    YRotation = YRotationStep * RotationYSign();
                }
                else
                {
                    ChangeDirectionTimeCounter = Constants.CHANGE_DIRECTION_TIME;
                }
            }
            else
            {
                acumulatedYRotation = 0;
            }

            acumulatedXRotation += XRotation;
            acumulatedYRotation += YRotation;

            TGCMatrix rotation = TGCMatrix.Identity;

            if (XRotation != 0 || FastUtils.GreaterThan(FastMath.Abs(acumulatedXRotation), 0.0012f))
            {
                var rotationAxis = TGCVector3.Cross(TGCVector3.Up, director);
                director.TransformCoordinate(TGCMatrix.RotationAxis(rotationAxis, XRotation));
                rotation = TGCMatrix.RotationAxis(rotationAxis, XRotation);
                speed   /= 1.5f;
            }
            else if (YRotation != 0)
            {
                director.TransformCoordinate(TGCMatrix.RotationY(YRotation));
                rotation = TGCMatrix.RotationY(YRotation);
            }

            TotalRotation *= rotation;
            TGCMatrix traslation = TGCMatrix.Translation(meshPosition + director * -speed * elapsedTime);

            Mesh.Mesh.Transform = TGCMatrix.Scaling(Constants.Scale) * TotalRotation * traslation;
            Mesh.Mesh.BoundingBox.transform(Mesh.Mesh.Transform);
        }
Пример #3
0
 public bool InPerimeterSkyBox(float posX, float posZ) =>
 FastUtils.IsNumberBetweenInterval(posX, (CurrentPerimeter.xMin, CurrentPerimeter.xMax)) &&