Ejemplo n.º 1
0
        private void PerformDeathMove(float elapsedTime)
        {
            CharacterOnSight  = false;
            DeathTimeCounter -= elapsedTime;
            var RotationStep = FastMath.PI * 0.4f * elapsedTime;

            if (FastUtils.GreaterThan(AcumulatedZRotation, Constants.MaxZRotation))
            {
                return;
            }

            AcumulatedZRotation += RotationStep;
            TotalRotation       *= TGCMatrix.RotationAxis(director, RotationStep);
            Mesh.Transform       = TotalRotation * TGCMatrix.Translation(new TGCVector3(Body.CenterOfMassPosition));
            Body.WorldTransform  = Mesh.Transform.ToBulletMatrix();
            Body.LinearVelocity  = Constants.DirectorY.ToBulletVector3() * 200;
        }
Ejemplo n.º 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);
        }