Beispiel #1
0
        public virtual void Roam()
        {
            LookDirection = new TGCVector3(LookDirection.X, 0, LookDirection.Z);  // Elimino la componente Y para que roamee al nivel que esta del agua

            timeSinceLastDirection += GameInstance.ElapsedTime;

            TGCVector3 rotationVector = TGCVector3.Empty;

            if (timeSinceLastDirection > timeToChangeDirection)
            {
                timeSinceLastDirection = 0f;
                timeToChangeDirection  = MathExtended.GetRandomNumberBetween(2, 5);

                float randomX = MathExtended.GetRandomNumberBetween(-100, 100);
                float randomZ = MathExtended.GetRandomNumberBetween(-100, 100);

                TGCVector3 lastDirection = LookDirection;
                LookDirection = TGCVector3.Normalize(new TGCVector3(randomX, LookDirection.Y, randomZ));

                float angle = MathExtended.AngleBetween(new TGCVector2(lastDirection.X, lastDirection.Z), new TGCVector2(LookDirection.X, LookDirection.Z));

                rotationVector.Y = -angle;
            }

            rotation += rotationVector;
            Position += LookDirection * roamingSpeed * GameInstance.ElapsedTime;

            TGCMatrix rot   = TGCMatrix.RotationY(rotation.Y);
            TGCMatrix trans = TGCMatrix.Translation(Position);
            TGCMatrix scal  = TGCMatrix.Scaling(scale);

            Transform = scal * rot * trans;
        }
Beispiel #2
0
        private void Chase()
        {
            LookDirection = TGCVector3.Normalize(GameInstance.Player.Position - Position);

            TGCVector3    rotationAxis = TGCVector3.Cross(InitialLookDirection, LookDirection); // Ojo el orden - no es conmutativo
            TGCQuaternion rotationQuat = TGCQuaternion.RotationAxis(rotationAxis, MathExtended.AngleBetween(InitialLookDirection, LookDirection));

            TGCVector3 nextPosition = Position + LookDirection * chasingSpeed * GameInstance.ElapsedTime;

            TGCMatrix translationMatrix = TGCMatrix.Translation(nextPosition);
            TGCMatrix rotationMatrix    = TGCMatrix.RotationTGCQuaternion(rotationQuat);

            TGCMatrix nextTransform = rotationMatrix * translationMatrix;

            SimulateAndSetTransformation(nextPosition, nextTransform);
        }