Esempio n. 1
0
        private void UpdateTransforms(SimulateMethodArgs args)
        {
            MataliPhysicsObject mataliPhysicsObj = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            mataliPhysicsObj.MainWorldTransform.GetTransformMatrix(ref tempMat1);
            ((IPhysicsObject)mataliPhysicsObj.UserTagObj).PhysicsWorldTransform = tempMat1;
        }
Esempio n. 2
0
        void Go(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            objectBase.MainLocalTransform.GetScale(ref scale);

            if (((scene.SimulationFrameCount % 200) == 0) && (scale.Y < 4.0f))
            {
                Vector3.Multiply(ref scale, 1.1f, out scale);

                objectBase.MainLocalTransform.SetScale(ref scale);

                objectBase.UpdateFromMainLocalTransform();
            }

            if (moveUp)
            {
                GoUp(args);
            }
            else
            {
                GoAhead(args);
            }
        }
Esempio n. 3
0
        public void MoveCursor(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }
            if (!objectBase.Camera.Active)
            {
                return;
            }

            float time = (float)args.Time;

            DemoMouseState mouseState = demo.GetMouseState();

            mousePosition.X = mouseState.X;
            mousePosition.Y = mouseState.Y;

            objectBase.Camera.View.GetViewMatrix(ref view);
            objectBase.Camera.Projection.GetProjectionMatrix(ref projection);

            ScreenToRayController screenToRayController = objectBase.InternalControllers.ScreenToRayController;

            screenToRayController.SetViewport(0, 0, demo.WindowWidth, demo.WindowHeight, 0.0f, 1.0f);
            screenToRayController.SetViewMatrix(ref view);
            screenToRayController.SetProjectionMatrix(ref projection);
            screenToRayController.SetScreenPosition(ref mousePosition);
            screenToRayController.MouseButton = true;
            screenToRayController.Update();
        }
        public void Flash(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (objectBase.Light == null)
            {
                return;
            }

            if ((intensity >= minIntensity) && (intensity <= maxIntensity))
            {
                intensity += stepIntensity;
            }

            if (intensity < minIntensity)
            {
                intensity     = minIntensity;
                stepIntensity = -stepIntensity;
            }

            if (intensity > maxIntensity)
            {
                intensity     = maxIntensity;
                stepIntensity = -stepIntensity;
            }

            objectBase.Light.Intensity = intensity;
        }
Esempio n. 5
0
        public void MoveCursor(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }
            if (!objectBase.Camera.Active)
            {
                return;
            }

            float time = (float)args.Time;

            bool  mouseButton      = false;
            float mouseScrollWheel = 0.0f;

            DemoMouseState mouseState = demo.GetMouseState();

            mousePosition.X  = mouseState.X;
            mousePosition.Y  = mouseState.Y;
            mouseScrollWheel = mouseState.Wheel;
            mouseButton      = mouseState[MouseButton.Left];

            bool hitMenu = false;

            if (demo.EnableMenu)
            {
                hitMenu = (demo.MenuScene.MenuAnimation1.CurrentSwitch != null);
            }

            objectBase.Camera.View.GetViewMatrix(ref view);
            objectBase.Camera.Projection.GetProjectionMatrix(ref projection);

            CursorController cursorController = objectBase.InternalControllers.CursorController;

            cursorController.SetViewport(0, 0, demo.WindowWidth, demo.WindowHeight, 0.0f, 1.0f);
            cursorController.SetViewMatrix(ref view);
            cursorController.SetProjectionMatrix(ref projection);
            cursorController.SetMousePosition(ref mousePosition);
            cursorController.MouseButton      = mouseButton && !hitMenu;
            cursorController.MouseScrollWheel = mouseScrollWheel;
            cursorController.DragWheelSpeed   = 50.0f;
            cursorController.WindowActive     = true;
            cursorController.Update();
        }
Esempio n. 6
0
        void Switch(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            objectBase.UpdateCollidingPhysicsObjects(false);

            PhysicsObject switchShape = objectBase.RigidGroupOwner.FindChildPhysicsObject(switchShapeName, true, false);

            if (switchShape != null)
            {
                if (objectBase.CollidingPhysicsObjectCount != 0)
                {
                    switchShape.Material.TransparencyFactor = 1.0f;
                }
                else
                {
                    switchShape.Material.TransparencyFactor = 0.5f;
                }
            }
        }
Esempio n. 7
0
        public void Flame(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if (objectBase.IsBrokenRigidGroup || (bodyEmitter == null) || (constraint1 == null) || constraint1.IsBroken)
            {
                if ((bodyLight != null) && (bodyLight.Light != null) && bodyLight.Light.Enabled)
                {
                    bodyLight.Light.Enabled = false;
                }

                return;
            }

            frameCount++;

            if (frameCount > maxParticleFrameCount)
            {
                frameCount = 0;

                bodyLight.Light.Intensity = (float)random.NextDouble() * 0.2f + 0.8f;

                particleCount = (particleCount + 1) % maxParticleCount;
                particleNameBuilder.Remove(particleNameLength, particleNameBuilder.Length - particleNameLength);
                particleNameBuilder.Append(particleCount);
                particleInstanceIndexName = particleNameBuilder.ToString();

                particle = scene.Factory.PhysicsObjectManager.FindOrCreate(particleInstanceIndexName);

                particle.Shape                           = sphere;
                particle.UserDataStr                     = sphereName;
                particle.Material.UserDataStr            = yellowName;
                particle.Material.TransparencyFactor     = 0.9f;
                particle.Material.TransparencyStepFactor = -0.01f;
                particle.CreateSound(true);
                particle.Sound.Range              = 50.0f;
                particle.Sound.AmplitudeFactor    = 1000.0f;
                particle.Sound.MinAmplitudeFactor = 0.0f;
                particle.Sound.UserDataStr        = soundName;

                bodyEmitter.MainWorldTransform.GetPosition(ref position);

                particle.InitLocalTransform.SetRotation(ref matrixIdentity);
                particle.InitLocalTransform.SetPosition(ref position);

                Vector3 velocity = vectorZero;

                scene.GetGravityDirection(ref velocity);

                Vector3.Multiply(ref velocity, -10.0f, out velocity);

                particle.InitLocalTransform.SetLinearVelocity(ref velocity);
                particle.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                particle.Integral.SetDensity(0.002f);
                particle.DisableCollision(bodyMain, true);
                particle.MaxSimulationFrameCount       = maxParticleSimulationFrameCount;
                particle.MaxDisableCollisionFrameCount = 10;
                particle.EnableCursorInteraction       = false;
                particle.EnableLocalGravity            = true;
                particle.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;
                particle.Material.TransparencySecondPass = false;

                scene.UpdateFromInitLocalTransform(particle);
            }
        }
Esempio n. 8
0
        void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsObject cameraBody = physicsObjectWithActiveCamera.RigidGroupOwner.FindChildPhysicsObject(cameraBodyName, true, true);
            PhysicsObject cameraDown = physicsObjectWithActiveCamera.RigidGroupOwner.FindChildPhysicsObject(cameraDownName, true, true);

            if ((bodyBox0 == null) || (engineSwitch == null) || (cameraBody == null) || (cameraDown == null))
            {
                return;
            }

            Constraint CameraConstraint = objectBase.Scene.Factory.ConstraintManager.Find(cameraConstraintName);

            bool rotorWorking = true;

            if (constraint2 != null)
            {
                if (constraint2.PhysicsObject1 != null)
                {
                    if (constraint2.PhysicsObject1.IsBrokenRigidGroup || constraint2.IsBroken)
                    {
                        rotorWorking = false;
                    }
                }

                if (constraint2.PhysicsObject2 != null)
                {
                    if (constraint2.PhysicsObject2.IsBrokenRigidGroup || constraint2.IsBroken)
                    {
                        rotorWorking = false;
                    }
                }
            }
            else
            {
                rotorWorking = false;
            }

            if (objectBase.IsBrokenRigidGroup || !rotorWorking)
            {
                if (constraint1 != null)
                {
                    constraint1.EnableControlAngleY = false;
                }

                if ((CameraConstraint != null) && (CameraConstraint.PhysicsObject1 == cameraDown))
                {
                    objectBase.Scene.Factory.ConstraintManager.Remove(CameraConstraint);
                    physicsObjectWithActiveCamera.Camera.EnableControl = false;

                    cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 0.0f;
                    cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 0.0f;

                    Vector3 euler       = vectorZero;
                    Vector3 cameraEuler = vectorZero;
                    Vector3 objectEuler = vectorZero;

                    physicsObjectWithActiveCamera.Camera.GetEuler(ref cameraEuler);
                    physicsObjectWithActiveCamera.MainWorldTransform.GetTransposeRotation(ref objectRotation);
                    physicsObjectWithActiveCamera.InitLocalTransform.GetRotation(ref objectInitRotation);
                    Matrix4.Mult(ref objectRotation, ref objectInitRotation, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);
                    physicsObjectWithActiveCamera.Camera.GetEuler(ref objectEuler);
                    Vector3.Add(ref objectEuler, ref cameraEuler, out euler);

                    Matrix4 rotationX, rotationY;
                    Matrix4.CreateRotationX(-euler.X, out rotationX);
                    Matrix4.CreateRotationY(-euler.Y, out rotationY);
                    Matrix4.Mult(ref rotationY, ref rotationX, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref euler);
                    physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);

                    Matrix4.CreateRotationY(euler.Y, out rotation);

                    physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                    physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();
                }

                return;
            }

            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (physicsObjectWithActiveCamera.Camera.EnableControl && (CameraConstraint != null) && (CameraConstraint.PhysicsObject1 == cameraDown))
            {
                if (keyboardState[Key.Space] && !oldKeyboardState[Key.Space])
                {
                    if (constraint1 != null)
                    {
                        constraint1.EnableControlAngleY = false;
                    }

                    objectBase.Scene.Factory.ConstraintManager.Remove(CameraConstraint);
                    physicsObjectWithActiveCamera.Camera.EnableControl = false;

                    cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 0.0f;
                    cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 0.0f;

                    Vector3 euler       = vectorZero;
                    Vector3 cameraEuler = vectorZero;
                    Vector3 objectEuler = vectorZero;

                    physicsObjectWithActiveCamera.Camera.GetEuler(ref cameraEuler);
                    physicsObjectWithActiveCamera.MainWorldTransform.GetTransposeRotation(ref objectRotation);
                    physicsObjectWithActiveCamera.InitLocalTransform.GetRotation(ref objectInitRotation);
                    Matrix4.Mult(ref objectRotation, ref objectInitRotation, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);
                    physicsObjectWithActiveCamera.Camera.GetEuler(ref objectEuler);
                    Vector3.Add(ref objectEuler, ref cameraEuler, out euler);
                    euler.Z = 0.0f;

                    Matrix4 rotationX, rotationY;
                    Matrix4.CreateRotationX(-euler.X, out rotationX);
                    Matrix4.CreateRotationY(-euler.Y, out rotationY);
                    Matrix4.Mult(ref rotationY, ref rotationX, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref euler);
                    physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);

                    Matrix4.CreateRotationY(euler.Y, out rotation);

                    physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                    physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();

                    oldKeyboardState = keyboardState;

                    return;
                }

                if (keyboardState[Key.W])
                {
                    if ((engine != null) && (engineRotor != null))
                    {
                        Vector3.Multiply(ref unitZ, -10.0f, out velocity);

                        engineRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);

                        if (engineRotor.IsUnderFluidSurface)
                        {
                            Vector3.Multiply(ref unitZ, 5.0f, out velocity);

                            engine.MainWorldTransform.AddLocalLinearVelocity(ref velocity);
                        }
                    }
                }

                if (keyboardState[Key.S])
                {
                    if ((engine != null) && (engineRotor != null))
                    {
                        Vector3.Multiply(ref unitZ, 10.0f, out velocity);

                        engineRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);

                        if (engineRotor.IsUnderFluidSurface)
                        {
                            Vector3.Multiply(ref unitZ, -5.0f, out velocity);

                            engine.MainWorldTransform.AddLocalLinearVelocity(ref velocity);
                        }
                    }
                }

                if (keyboardState[Key.D])
                {
                    if (constraint1 != null)
                    {
                        constraint1.ControlDegAngleY += 0.5f;
                    }
                }

                if (keyboardState[Key.A])
                {
                    if (constraint1 != null)
                    {
                        constraint1.ControlDegAngleY -= 0.5f;
                    }
                }
            }
            else
            {
                if (constraint1 != null)
                {
                    constraint1.EnableControlAngleY = false;
                }

                if (engineSwitch.IsColliding(cameraBody))
                {
                    if (keyboardState[Key.Space] && !oldKeyboardState[Key.Space])
                    {
                        physicsObjectWithActiveCamera.Camera.EnableControl = true;

                        if (constraint1 != null)
                        {
                            constraint1.EnableControlAngleY = true;
                        }

                        constraint1.ControlDegAngleY = 0.0f;

                        cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 1000.0f;
                        cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 1000.0f;

                        Quaternion cameraOrientationX  = quaternionIdentity;
                        Quaternion cameraOrientationY  = quaternionIdentity;
                        Quaternion cameraOrientationZ  = quaternionIdentity;
                        Quaternion cameraOrientationXY = quaternionIdentity;
                        Quaternion cameraOrientation   = quaternionIdentity;

                        Quaternion.Multiply(ref cameraOrientationX, ref cameraOrientationY, out cameraOrientationXY);
                        Quaternion.Multiply(ref cameraOrientationXY, ref cameraOrientationZ, out cameraOrientation);
                        rotation = Matrix4.CreateFromQuaternion(cameraOrientation);

                        physicsObjectWithActiveCamera.Camera.SetOrientation(ref cameraOrientation);
                        physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);
                        physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);

                        objectOrientation = quaternionIdentity;
                        objectRotation    = Matrix4.CreateFromQuaternion(objectOrientation);

                        Vector3 boatDeckPosition = vectorZero;
                        Matrix4 boatDeckRotation = matrixIdentity;

                        bodyBox0.MainWorldTransform.GetPosition(ref boatDeckPosition);
                        bodyBox0.MainWorldTransform.GetRotation(ref boatDeckRotation);

                        Matrix4.Mult(ref objectRotation, ref boatDeckRotation, out rotation);

                        Vector3.TransformVector(ref driverLocalPosition, ref boatDeckRotation, out position);
                        Vector3.Add(ref boatDeckPosition, ref position, out position);

                        physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                        physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetPosition(ref position);
                        physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();

                        if (CameraConstraint == null)
                        {
                            CameraConstraint = scene.Factory.ConstraintManager.Create(cameraConstraintName);
                            CameraConstraint.PhysicsObject1 = cameraDown;
                            CameraConstraint.PhysicsObject2 = bodyBox0;
                            CameraConstraint.PhysicsObject1.MainWorldTransform.GetPosition(ref position1);
                            CameraConstraint.PhysicsObject1.MainWorldTransform.GetOrientation(ref orientation1);
                            CameraConstraint.PhysicsObject2.MainWorldTransform.GetOrientation(ref orientation2);

                            boatDeckPosition.X = boatDeckPosition.Z = 0.0f;
                            boatDeckPosition.Y = 2.0f;
                            Vector3.Subtract(ref position1, ref boatDeckPosition, out position1);

                            CameraConstraint.SetAnchor1(ref position1);
                            CameraConstraint.SetAnchor2(ref position1);
                            CameraConstraint.SetInitWorldOrientation1(ref orientation1);
                            CameraConstraint.SetInitWorldOrientation2(ref orientation2);
                            CameraConstraint.EnableLimitAngleX = true;
                            CameraConstraint.EnableLimitAngleY = true;
                            CameraConstraint.EnableLimitAngleZ = true;
                            CameraConstraint.LimitAngleForce   = 0.6f;
                            CameraConstraint.Update();
                        }
                    }
                }

                if (enableExternalMoving)
                {
                    if (keyboardState[Key.Up])
                    {
                        if (constraint1 != null)
                        {
                            constraint1.EnableControlAngleY = true;
                        }

                        if ((engine != null) && (engineRotor != null))
                        {
                            Vector3.Multiply(ref unitZ, -10.0f, out velocity);

                            engineRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);

                            if (engineRotor.IsUnderFluidSurface)
                            {
                                Vector3.Multiply(ref unitZ, 5.0f, out velocity);

                                engine.MainWorldTransform.AddLocalLinearVelocity(ref velocity);
                            }
                        }
                    }

                    if (keyboardState[Key.Down])
                    {
                        if (constraint1 != null)
                        {
                            constraint1.EnableControlAngleY = true;
                        }

                        if ((engine != null) && (engineRotor != null))
                        {
                            Vector3.Multiply(ref unitZ, 10.0f, out velocity);

                            engineRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);

                            if (engineRotor.IsUnderFluidSurface)
                            {
                                Vector3.Multiply(ref unitZ, -5.0f, out velocity);

                                engine.MainWorldTransform.AddLocalLinearVelocity(ref velocity);
                            }
                        }
                    }

                    if (keyboardState[Key.Right])
                    {
                        if (constraint1 != null)
                        {
                            constraint1.EnableControlAngleY = true;
                        }

                        if (constraint1 != null)
                        {
                            constraint1.ControlDegAngleY += 0.5f;
                        }
                    }

                    if (keyboardState[Key.Left])
                    {
                        if (constraint1 != null)
                        {
                            constraint1.EnableControlAngleY = true;
                        }

                        if (constraint1 != null)
                        {
                            constraint1.ControlDegAngleY -= 0.5f;
                        }
                    }
                }
            }

            oldKeyboardState = keyboardState;
        }
Esempio n. 9
0
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if ((turretGun == null) || (turretConstraint == null) || (turretGunConstraint == null))
            {
                return;
            }

            Vector3 deltaTranslation = vectorZero;

            bool turretWorking = true;

            if (objectBase.IsBrokenRigidGroup || turretConstraint.IsBroken)
            {
                turretWorking = false;
            }

            bool turretGunWorking = true;

            if (!turretWorking || turretGun.IsBrokenRigidGroup || turretGunConstraint.IsBroken)
            {
                turretGunWorking = false;
            }

            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (keyboardState[Key.Up])
            {
                deltaTranslation.Z += 10000.0f;
            }

            if (keyboardState[Key.Down])
            {
                deltaTranslation.Z -= 10000.0f;
            }

            if (deltaTranslation.LengthSquared != 0.0f)
            {
                objectBase.WorldAccumulator.AddLocalForce(ref deltaTranslation);
            }

            if (turretWorking)
            {
                if (keyboardState[Key.Right])
                {
                    turretConstraint.ControlDegAngleY -= 2.0f;
                }

                if (keyboardState[Key.Left])
                {
                    turretConstraint.ControlDegAngleY += 2.0f;
                }
            }

            if (turretGunWorking)
            {
                if (keyboardState[Key.PageUp])
                {
                    turretGunConstraint.ControlDegAngleX += 1.0f;
                }

                if (keyboardState[Key.PageDown])
                {
                    turretGunConstraint.ControlDegAngleX -= 1.0f;
                }

                if (keyboardState[Key.F] && !oldKeyboardState[Key.F])
                {
                    shotCount = (shotCount + 1) % maxShotCount;
                    string shotCountName = shotCount.ToString();

                    if (turretGun1 != null)
                    {
                        shot      = scene.Factory.PhysicsObjectManager.FindOrCreate(shot1Name + shotCountName);
                        shotBase  = scene.Factory.PhysicsObjectManager.FindOrCreate(shot1BaseName + shotCountName);
                        shotLight = scene.Factory.PhysicsObjectManager.FindOrCreate(shot1LightName + shotCountName);

                        shot.AddChildPhysicsObject(shotBase);
                        shot.AddChildPhysicsObject(shotLight);

                        Vector3 turretGunPosition = vectorZero;
                        Matrix4 turretGunRotation = matrixIdentity;

                        turretGun1.MainWorldTransform.GetPosition(ref turretGunPosition);
                        turretGun1.MainWorldTransform.GetRotation(ref turretGunRotation);

                        Vector3 shotPosition      = vectorZero;
                        Vector3 shotLocalPosition = vectorZero;

                        shotLocalPosition.X = 0.0f;
                        shotLocalPosition.Y = 2.0f;
                        shotLocalPosition.Z = 0.0f;

                        Vector3.TransformVector(ref shotLocalPosition, ref turretGunRotation, out shotPosition);
                        Vector3.Add(ref shotPosition, ref turretGunPosition, out shotPosition);

                        Vector3 shotDirection = vectorZero;
                        Vector3 shotScale     = vectorZero;

                        shotDirection.X = turretGunRotation.Row1.X;
                        shotDirection.Y = turretGunRotation.Row1.Y;
                        shotDirection.Z = turretGunRotation.Row1.Z;

                        shotScale.X = shotScale.Y = shotScale.Z = 0.5f;

                        shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                        shot.InitLocalTransform.SetPosition(ref shotPosition);

                        Vector3.Multiply(ref shotDirection, 200.0f, out shotDirection);

                        shot.InitLocalTransform.SetLinearVelocity(ref shotDirection);
                        shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                        shot.MaxSimulationFrameCount = 100;
                        shot.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;

                        shotBase.Shape               = sphere;
                        shotBase.UserDataStr         = sphereName;
                        shotBase.Material.RigidGroup = true;
                        shotBase.InitLocalTransform.SetScale(ref shotScale);
                        shotBase.Integral.SetDensity(1.0f);
                        shotBase.EnableCollisions = true;
                        shotBase.DisableCollision(turretGun1, true);
                        shotBase.MaxDisableCollisionFrameCount = 10;
                        shotBase.EnableBreakRigidGroup         = false;
                        shotBase.CreateSound(true);

                        shotLight.Shape       = sphere;
                        shotLight.UserDataStr = sphereName;
                        shotLight.CreateLight(true);
                        shotLight.Light.Type  = PhysicsLightType.Point;
                        shotLight.Light.Range = 20.0f;
                        shotLight.Light.SetDiffuse(1.0f, 0.7f, 0.0f);
                        shotLight.InitLocalTransform.SetScale(20.0f);
                        shotLight.Material.RigidGroup     = true;
                        shotLight.Material.UserDataStr    = yellowName;
                        shotLight.EnableBreakRigidGroup   = false;
                        shotLight.EnableCollisions        = false;
                        shotLight.EnableCursorInteraction = false;
                        shotLight.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                        scene.UpdateFromInitLocalTransform(shot);
                    }

                    if (turretGun2 != null)
                    {
                        shot      = scene.Factory.PhysicsObjectManager.FindOrCreate(shot2Name + shotCountName);
                        shotBase  = scene.Factory.PhysicsObjectManager.FindOrCreate(shot2BaseName + shotCountName);
                        shotLight = scene.Factory.PhysicsObjectManager.FindOrCreate(shot2LightName + shotCountName);

                        shot.AddChildPhysicsObject(shotBase);
                        shot.AddChildPhysicsObject(shotLight);

                        Vector3 turretGunPosition = vectorZero;
                        Matrix4 turretGunRotation = matrixIdentity;

                        turretGun2.MainWorldTransform.GetPosition(ref turretGunPosition);
                        turretGun2.MainWorldTransform.GetRotation(ref turretGunRotation);

                        Vector3 shotPosition      = vectorZero;
                        Vector3 shotLocalPosition = vectorZero;

                        shotLocalPosition.X = 0.0f;
                        shotLocalPosition.Y = 2.0f;
                        shotLocalPosition.Z = 0.0f;

                        Vector3.TransformVector(ref shotLocalPosition, ref turretGunRotation, out shotPosition);
                        Vector3.Add(ref shotPosition, ref turretGunPosition, out shotPosition);

                        Vector3 shotDirection = vectorZero;
                        Vector3 shotScale     = vectorZero;

                        shotDirection.X = turretGunRotation.Row1.X;
                        shotDirection.Y = turretGunRotation.Row1.Y;
                        shotDirection.Z = turretGunRotation.Row1.Z;

                        shotScale.X = shotScale.Y = shotScale.Z = 0.5f;

                        shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                        shot.InitLocalTransform.SetPosition(ref shotPosition);

                        Vector3.Multiply(ref shotDirection, 200.0f, out shotDirection);

                        shot.InitLocalTransform.SetLinearVelocity(ref shotDirection);
                        shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                        shot.MaxSimulationFrameCount = 100;
                        shot.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;

                        shotBase.Shape               = sphere;
                        shotBase.UserDataStr         = sphereName;
                        shotBase.Material.RigidGroup = true;
                        shotBase.InitLocalTransform.SetScale(ref shotScale);
                        shotBase.Integral.SetDensity(1.0f);
                        shotBase.EnableCollisions = true;
                        shotBase.DisableCollision(turretGun1, true);
                        shotBase.MaxDisableCollisionFrameCount = 10;
                        shotBase.EnableBreakRigidGroup         = false;
                        shotBase.CreateSound(true);

                        shotLight.Shape       = sphere;
                        shotLight.UserDataStr = sphereName;
                        shotLight.CreateLight(true);
                        shotLight.Light.Type  = PhysicsLightType.Point;
                        shotLight.Light.Range = 20.0f;
                        shotLight.Light.SetDiffuse(1.0f, 0.7f, 0.0f);
                        shotLight.InitLocalTransform.SetScale(20.0f);
                        shotLight.Material.RigidGroup     = true;
                        shotLight.Material.UserDataStr    = yellowName;
                        shotLight.EnableBreakRigidGroup   = false;
                        shotLight.EnableCollisions        = false;
                        shotLight.EnableCursorInteraction = false;
                        shotLight.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                        scene.UpdateFromInitLocalTransform(shot);
                    }
                }
            }
            else
            {
                if (turretGunConstraint.IsBroken)
                {
                    turretBodyDown.DisableCollision(turretGun1, false);
                    turretBodyDown.DisableCollision(turretGun2, false);
                }
            }

            oldKeyboardState = keyboardState;
        }
Esempio n. 10
0
        void SwitchLeft(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            MenuData userData = (MenuData)args.UserDataObj;

            string switchSliderConstraintName = userData.SwitchSliderConstraintName;
            int    sceneIndex  = userData.SceneIndex;
            int    switchIndex = userData.SwitchIndex;

            if (baseSceneIndex > 0)
            {
                objectBase.Material.SetAmbient(0.4f, 0.4f, 0.25f);
            }
            else
            {
                objectBase.Material.SetAmbient(0.4f, 0.4f, 0.4f);
            }

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithActiveCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            Vector3 switchVelocity;

            ScreenToRayController screenToRayController = physicsObjectWithActiveCamera.InternalControllers.ScreenToRayController;

            Constraint switchSliderConstraint = scene.Factory.ConstraintManager.Find(switchSliderConstraintName);

            string sceneName = demo.Scenes[sceneIndex].SceneName;

            DemoMouseState mouseState    = demo.GetMouseState();
            DemoMouseState oldMouseState = userData.OldMouseState;
            int            deltaX        = mouseState.X - oldMouseState.X;
            int            deltaY        = mouseState.Y - oldMouseState.Y;

            if (switchSliderConstraint != null)
            {
                if (screenToRayController.IsHitPhysicsObject && (screenToRayController.HitPhysicsObject == objectBase))
                {
                    if (((switchPhysicsObject != objectBase) && !mouseState[MouseButton.Left] && !mouseState[MouseButton.Middle] && !mouseState[MouseButton.Right] && (Math.Abs(deltaX) + Math.Abs(deltaY) != 0)) || ((switchPhysicsObject == objectBase) && (switchSliderConstraint.ControlDistanceZ < -4.95f)) || ((switchPhysicsObject == objectBase) && (Math.Abs(deltaX) + Math.Abs(deltaY) != 0)))
                    {
                        enableStartInfo = false;

                        if (infoScreen != null)
                        {
                            infoScreen.EnableDrawing = false;
                        }

                        if (infoDescription != null)
                        {
                            infoDescription.EnableDrawing = false;
                        }

                        switchPhysicsObject = objectBase;

                        Vector3.Multiply(ref unitZ, -10.0f, out switchVelocity);
                        objectBase.MainWorldTransform.SetLinearVelocity(ref switchVelocity);
                        objectBase.MainWorldTransform.SetAngularVelocity(ref vectorZero);
                    }

                    if ((switchPhysicsObject == objectBase) && mouseState[MouseButton.Left] && !oldMouseState[MouseButton.Left] && (switchSliderConstraint.ControlDistanceZ <= -0.5f))
                    {
                        baseSceneIndex = Math.Max(baseSceneIndex - 1, 0);
                    }
                }
                else
                {
                    if ((switchPhysicsObject == objectBase) && (switchSliderConstraint.ControlDistanceZ >= -0.05))
                    {
                        if (infoScreen != null)
                        {
                            infoScreen.EnableDrawing = false;
                        }

                        if (infoDescription != null)
                        {
                            infoDescription.EnableDrawing = false;
                        }

                        switchPhysicsObject = null;
                    }
                }
            }

            userData.OldMouseState = mouseState;
            args.UserDataObj       = userData;
        }
Esempio n. 11
0
        void GoAhead(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if (rightFront1AngleXStep > 0.0f)
            {
                if (rightLimbFront1Constraint.ControlDegAngleX <= rightLimbFront1Constraint.MinLimitDegAngleX)
                {
                    if (rightLimbFront1Constraint.ControlDegAngleY >= maxAhead1AngleY)
                    {
                        rightFront1AngleXStep = -rightFront1AngleXStep;
                        rightFront1AngleYStep = -rightFront1AngleYStep;
                    }
                    else
                    {
                        rightLimbFront1Constraint.ControlDegAngleY += rightFront1AngleYStep;
                    }
                }
                else
                {
                    rightLimbFront1Constraint.ControlDegAngleX -= rightFront1AngleXStep;
                }
            }
            else
            if (rightFront1AngleXStep < 0.0f)
            {
                if (rightLimbFront1Constraint.ControlDegAngleX >= maxUp1AngleX)
                {
                    if (rightLimbFront1Constraint.ControlDegAngleY <= maxAhead2AngleY)
                    {
                        rightFront1AngleXStep = -rightFront1AngleXStep;
                        rightFront1AngleYStep = -rightFront1AngleYStep;
                    }
                    else
                    {
                        rightLimbFront1Constraint.ControlDegAngleY += rightFront1AngleYStep;
                    }
                }
                else
                {
                    rightLimbFront1Constraint.ControlDegAngleX -= rightFront1AngleXStep;
                }
            }


            if ((rightMiddleFront1AngleXStep > 0.0f) && (leftFront1AngleXStep < 0.0f))
            {
                if (rightLimbMiddleFront1Constraint.ControlDegAngleX <= rightLimbMiddleFront1Constraint.MinLimitDegAngleX)
                {
                    if (rightLimbMiddleFront1Constraint.ControlDegAngleY >= maxAhead2AngleY)
                    {
                        rightMiddleFront1AngleXStep = -rightMiddleFront1AngleXStep;
                        rightMiddleFront1AngleYStep = -rightMiddleFront1AngleYStep;
                    }
                    else
                    {
                        rightLimbMiddleFront1Constraint.ControlDegAngleY += rightMiddleFront1AngleYStep;
                    }
                }
                else
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleX -= rightMiddleFront1AngleXStep;
                }
            }
            else
            if ((rightMiddleFront1AngleXStep < 0.0f) && (leftFront1AngleXStep > 0.0f))
            {
                if (rightLimbMiddleFront1Constraint.ControlDegAngleX >= maxUp1AngleX)
                {
                    if (rightLimbMiddleFront1Constraint.ControlDegAngleY <= maxAhead3AngleY)
                    {
                        rightMiddleFront1AngleXStep = -rightMiddleFront1AngleXStep;
                        rightMiddleFront1AngleYStep = -rightMiddleFront1AngleYStep;
                    }
                    else
                    {
                        rightLimbMiddleFront1Constraint.ControlDegAngleY += rightMiddleFront1AngleYStep;
                    }
                }
                else
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleX -= rightMiddleFront1AngleXStep;
                }
            }


            if ((rightMiddleBack1AngleXStep > 0.0f) && (leftMiddleFront1AngleXStep < 0.0f))
            {
                if (rightLimbMiddleBack1Constraint.ControlDegAngleX <= rightLimbMiddleBack1Constraint.MinLimitDegAngleX)
                {
                    if (rightLimbMiddleBack1Constraint.ControlDegAngleY >= maxAhead3AngleY)
                    {
                        rightMiddleBack1AngleXStep = -rightMiddleBack1AngleXStep;
                        rightMiddleBack1AngleYStep = -rightMiddleBack1AngleYStep;
                    }
                    else
                    {
                        rightLimbMiddleBack1Constraint.ControlDegAngleY += rightMiddleBack1AngleYStep;
                    }
                }
                else
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleX -= rightMiddleBack1AngleXStep;
                }
            }
            else
            if ((rightMiddleBack1AngleXStep < 0.0f) && (leftMiddleFront1AngleXStep > 0.0f))
            {
                if (rightLimbMiddleBack1Constraint.ControlDegAngleX >= maxUp1AngleX)
                {
                    if (rightLimbMiddleBack1Constraint.ControlDegAngleY <= maxAhead4AngleY)
                    {
                        rightMiddleBack1AngleXStep = -rightMiddleBack1AngleXStep;
                        rightMiddleBack1AngleYStep = -rightMiddleBack1AngleYStep;
                    }
                    else
                    {
                        rightLimbMiddleBack1Constraint.ControlDegAngleY += rightMiddleBack1AngleYStep;
                    }
                }
                else
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleX -= rightMiddleBack1AngleXStep;
                }
            }


            if ((rightBack1AngleXStep > 0.0f) && (leftMiddleBack1AngleXStep < 0.0f))
            {
                if (rightLimbBack1Constraint.ControlDegAngleX <= rightLimbBack1Constraint.MinLimitDegAngleX)
                {
                    if (rightLimbBack1Constraint.ControlDegAngleY >= maxAhead4AngleY)
                    {
                        rightBack1AngleXStep = -rightBack1AngleXStep;
                        rightBack1AngleYStep = -rightBack1AngleYStep;
                    }
                    else
                    {
                        rightLimbBack1Constraint.ControlDegAngleY += rightBack1AngleYStep;
                    }
                }
                else
                {
                    rightLimbBack1Constraint.ControlDegAngleX -= rightBack1AngleXStep;
                }
            }
            else
            if ((rightBack1AngleXStep < 0.0f) && (leftMiddleBack1AngleXStep > 0.0f))
            {
                if (rightLimbBack1Constraint.ControlDegAngleX >= maxUp1AngleX)
                {
                    if (rightLimbBack1Constraint.ControlDegAngleY <= maxAhead5AngleY)
                    {
                        rightBack1AngleXStep = -rightBack1AngleXStep;
                        rightBack1AngleYStep = -rightBack1AngleYStep;
                    }
                    else
                    {
                        rightLimbBack1Constraint.ControlDegAngleY += rightBack1AngleYStep;
                    }
                }
                else
                {
                    rightLimbBack1Constraint.ControlDegAngleX -= rightBack1AngleXStep;
                }
            }



            if ((leftFront1AngleXStep < 0.0f) && (rightFront1AngleXStep < 0.0f))
            {
                if (leftLimbFront1Constraint.ControlDegAngleX >= leftLimbFront1Constraint.MaxLimitDegAngleX)
                {
                    if (leftLimbFront1Constraint.ControlDegAngleY <= -maxAhead1AngleY)
                    {
                        leftFront1AngleXStep = -leftFront1AngleXStep;
                        leftFront1AngleYStep = -leftFront1AngleYStep;
                    }
                    else
                    {
                        leftLimbFront1Constraint.ControlDegAngleY += leftFront1AngleYStep;
                    }
                }
                else
                {
                    leftLimbFront1Constraint.ControlDegAngleX -= leftFront1AngleXStep;
                }
            }
            else
            if ((leftFront1AngleXStep > 0.0f) && (rightFront1AngleXStep > 0.0f))
            {
                if (leftLimbFront1Constraint.ControlDegAngleX <= -maxUp1AngleX)
                {
                    if (leftLimbFront1Constraint.ControlDegAngleY >= -maxAhead2AngleY)
                    {
                        leftFront1AngleXStep = -leftFront1AngleXStep;
                        leftFront1AngleYStep = -leftFront1AngleYStep;
                    }
                    else
                    {
                        leftLimbFront1Constraint.ControlDegAngleY += leftFront1AngleYStep;
                    }
                }
                else
                {
                    leftLimbFront1Constraint.ControlDegAngleX -= leftFront1AngleXStep;
                }
            }


            if ((leftMiddleFront1AngleXStep < 0.0f) && (rightFront1AngleXStep > 0.0f))
            {
                if (leftLimbMiddleFront1Constraint.ControlDegAngleX >= leftLimbMiddleFront1Constraint.MaxLimitDegAngleX)
                {
                    if (leftLimbMiddleFront1Constraint.ControlDegAngleY <= -maxAhead2AngleY)
                    {
                        leftMiddleFront1AngleXStep = -leftMiddleFront1AngleXStep;
                        leftMiddleFront1AngleYStep = -leftMiddleFront1AngleYStep;
                    }
                    else
                    {
                        leftLimbMiddleFront1Constraint.ControlDegAngleY += leftMiddleFront1AngleYStep;
                    }
                }
                else
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleX -= leftMiddleFront1AngleXStep;
                }
            }
            else
            if ((leftMiddleFront1AngleXStep > 0.0f) && (rightFront1AngleXStep < 0.0f))
            {
                if (leftLimbMiddleFront1Constraint.ControlDegAngleX <= -maxUp1AngleX)
                {
                    if (leftLimbMiddleFront1Constraint.ControlDegAngleY >= maxAhead3AngleY)
                    {
                        leftMiddleFront1AngleXStep = -leftMiddleFront1AngleXStep;
                        leftMiddleFront1AngleYStep = -leftMiddleFront1AngleYStep;
                    }
                    else
                    {
                        leftLimbMiddleFront1Constraint.ControlDegAngleY += leftMiddleFront1AngleYStep;
                    }
                }
                else
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleX -= leftMiddleFront1AngleXStep;
                }
            }


            if ((leftMiddleBack1AngleXStep < 0.0f) && (rightMiddleFront1AngleXStep > 0.0f))
            {
                if (leftLimbMiddleBack1Constraint.ControlDegAngleX >= leftLimbMiddleBack1Constraint.MaxLimitDegAngleX)
                {
                    if (leftLimbMiddleBack1Constraint.ControlDegAngleY <= maxAhead3AngleY)
                    {
                        leftMiddleBack1AngleXStep = -leftMiddleBack1AngleXStep;
                        leftMiddleBack1AngleYStep = -leftMiddleBack1AngleYStep;
                    }
                    else
                    {
                        leftLimbMiddleBack1Constraint.ControlDegAngleY += leftMiddleBack1AngleYStep;
                    }
                }
                else
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleX -= leftMiddleBack1AngleXStep;
                }
            }
            else
            if ((leftMiddleBack1AngleXStep > 0.0f) && (rightMiddleFront1AngleXStep < 0.0f))
            {
                if (leftLimbMiddleBack1Constraint.ControlDegAngleX <= -maxUp1AngleX)
                {
                    if (leftLimbMiddleBack1Constraint.ControlDegAngleY >= -maxAhead4AngleY)
                    {
                        leftMiddleBack1AngleXStep = -leftMiddleBack1AngleXStep;
                        leftMiddleBack1AngleYStep = -leftMiddleBack1AngleYStep;
                    }
                    else
                    {
                        leftLimbMiddleBack1Constraint.ControlDegAngleY += leftMiddleBack1AngleYStep;
                    }
                }
                else
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleX -= leftMiddleBack1AngleXStep;
                }
            }


            if ((leftBack1AngleXStep < 0.0f) && (rightMiddleBack1AngleXStep > 0.0f))
            {
                if (leftLimbBack1Constraint.ControlDegAngleX >= leftLimbBack1Constraint.MaxLimitDegAngleX)
                {
                    if (leftLimbBack1Constraint.ControlDegAngleY <= -maxAhead4AngleY)
                    {
                        leftBack1AngleXStep = -leftBack1AngleXStep;
                        leftBack1AngleYStep = -leftBack1AngleYStep;
                    }
                    else
                    {
                        leftLimbBack1Constraint.ControlDegAngleY += leftBack1AngleYStep;
                    }
                }
                else
                {
                    leftLimbBack1Constraint.ControlDegAngleX -= leftBack1AngleXStep;
                }
            }
            else
            if ((leftBack1AngleXStep > 0.0f) && (rightMiddleBack1AngleXStep < 0.0f))
            {
                if (leftLimbBack1Constraint.ControlDegAngleX <= -maxUp1AngleX)
                {
                    if (leftLimbBack1Constraint.ControlDegAngleY >= -maxAhead5AngleY)
                    {
                        leftBack1AngleXStep = -leftBack1AngleXStep;
                        leftBack1AngleYStep = -leftBack1AngleYStep;
                    }
                    else
                    {
                        leftLimbBack1Constraint.ControlDegAngleY += leftBack1AngleYStep;
                    }
                }
                else
                {
                    leftLimbBack1Constraint.ControlDegAngleX -= leftBack1AngleXStep;
                }
            }
        }
Esempio n. 12
0
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            PhysicsObject physicsObjectWithActiveCamera = scene.GetPhysicsObjectWithActiveCamera(0);

            if (physicsObjectWithActiveCamera == null)
            {
                return;
            }

            PhysicsObject cameraBody = physicsObjectWithActiveCamera.RigidGroupOwner.FindChildPhysicsObject(cameraBodyName, true, true);
            PhysicsObject cameraDown = physicsObjectWithActiveCamera.RigidGroupOwner.FindChildPhysicsObject(cameraDownName, true, true);

            if ((chassisMiddleDown == null) || (steeringGearSwitch == null))
            {
                return;
            }

            Constraint CameraConstraint = objectBase.Scene.Factory.ConstraintManager.Find(cameraConstraintName);

            bool steeringGearWorking = true;

            if (steeringGearConstraint != null)
            {
                if (steeringGearConstraint.PhysicsObject1 != null)
                {
                    if (steeringGearConstraint.PhysicsObject1.IsBrokenRigidGroup || steeringGearConstraint.IsBroken)
                    {
                        steeringGearWorking = false;
                    }
                }

                if (steeringGearConstraint.PhysicsObject2 != null)
                {
                    if (steeringGearConstraint.PhysicsObject2.IsBrokenRigidGroup || steeringGearConstraint.IsBroken)
                    {
                        steeringGearWorking = false;
                    }
                }
            }
            else
            {
                steeringGearWorking = false;
            }

            if (!steeringGearWorking)
            {
                steeringGearDown.DisableCollision(chassisUpPanel, false);
                steeringGearDown.DisableCollision(chassisDownPanel, false);
                steeringGearDown.DisableCollision(upBodyFront, false);
                steeringGearDown.DisableCollision(upBodyDownBack, false);
            }

            if (objectBase.IsBrokenRigidGroup || !steeringGearWorking)
            {
                if ((CameraConstraint != null) && (CameraConstraint.PhysicsObject1 == cameraDown))
                {
                    objectBase.Scene.Factory.ConstraintManager.Remove(CameraConstraint);
                    physicsObjectWithActiveCamera.Camera.EnableControl = false;

                    cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 0.0f;
                    cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 0.0f;

                    cameraDown.DisableCollision(steeringWheel, false);
                    cameraDown.DisableCollision(chassisBack, false);
                    cameraDown.DisableCollision(chassisMiddleBack, false);
                    cameraDown.DisableCollision(upBodyFront, false);
                    cameraDown.DisableCollision(upBodyDownBack, false);

                    cameraBody.DisableCollision(steeringGearDown, false);
                    cameraBody.DisableCollision(steeringWheel, false);
                    cameraBody.DisableCollision(chassisBack, false);
                    cameraBody.DisableCollision(chassisMiddleBack, false);
                    cameraBody.DisableCollision(upBodyFront, false);
                    cameraBody.DisableCollision(upBodyDownBack, false);

                    Vector3 euler       = vectorZero;
                    Vector3 cameraEuler = vectorZero;
                    Vector3 objectEuler = vectorZero;

                    physicsObjectWithActiveCamera.Camera.GetEuler(ref cameraEuler);
                    physicsObjectWithActiveCamera.MainWorldTransform.GetTransposeRotation(ref objectRotation);
                    physicsObjectWithActiveCamera.InitLocalTransform.GetRotation(ref objectInitRotation);
                    Matrix4.Mult(ref objectRotation, ref objectInitRotation, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);
                    physicsObjectWithActiveCamera.Camera.GetEuler(ref objectEuler);
                    Vector3.Add(ref objectEuler, ref cameraEuler, out euler);

                    Matrix4 rotationX, rotationY;
                    Matrix4.CreateRotationX(-euler.X, out rotationX);
                    Matrix4.CreateRotationY(-euler.Y, out rotationY);
                    Matrix4.Mult(ref rotationY, ref rotationX, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref euler);
                    physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);

                    Matrix4.CreateRotationY(euler.Y, out rotation);

                    physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                    physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();
                }

                return;
            }

            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (physicsObjectWithActiveCamera.Camera.EnableControl && (CameraConstraint != null) && (CameraConstraint.PhysicsObject1 == cameraDown))
            {
                if (keyboardState[Key.Space] && !oldKeyboardState[Key.Space])
                {
                    objectBase.Scene.Factory.ConstraintManager.Remove(CameraConstraint);
                    physicsObjectWithActiveCamera.Camera.EnableControl = false;

                    cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 0.0f;
                    cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 0.0f;

                    cameraDown.DisableCollision(steeringWheel, false);
                    cameraDown.DisableCollision(chassisBack, false);
                    cameraDown.DisableCollision(chassisMiddleBack, false);
                    cameraDown.DisableCollision(upBodyFront, false);
                    cameraDown.DisableCollision(upBodyDownBack, false);

                    cameraBody.DisableCollision(steeringGearDown, false);
                    cameraBody.DisableCollision(steeringWheel, false);
                    cameraBody.DisableCollision(chassisBack, false);
                    cameraBody.DisableCollision(chassisMiddleBack, false);
                    cameraBody.DisableCollision(upBodyFront, false);
                    cameraBody.DisableCollision(upBodyDownBack, false);

                    Vector3 euler       = vectorZero;
                    Vector3 cameraEuler = vectorZero;
                    Vector3 objectEuler = vectorZero;

                    physicsObjectWithActiveCamera.Camera.GetEuler(ref cameraEuler);
                    physicsObjectWithActiveCamera.MainWorldTransform.GetTransposeRotation(ref objectRotation);
                    physicsObjectWithActiveCamera.InitLocalTransform.GetRotation(ref objectInitRotation);
                    Matrix4.Mult(ref objectRotation, ref objectInitRotation, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);
                    physicsObjectWithActiveCamera.Camera.GetEuler(ref objectEuler);
                    Vector3.Add(ref objectEuler, ref cameraEuler, out euler);
                    euler.Z = 0.0f;

                    Matrix4 rotationX, rotationY;
                    Matrix4.CreateRotationX(-euler.X, out rotationX);
                    Matrix4.CreateRotationY(-euler.Y, out rotationY);
                    Matrix4.Mult(ref rotationY, ref rotationX, out rotation);

                    physicsObjectWithActiveCamera.Camera.SetEuler(ref euler);
                    physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);

                    Matrix4.CreateRotationY(euler.Y, out rotation);

                    physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                    physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();

                    oldKeyboardState = keyboardState;

                    return;
                }

                if (keyboardState[Key.W])
                {
                    if (wheel1 != null)
                    {
                        Vector3.Multiply(ref unitY, 5.0f, out velocity);

                        wheel1.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                    }

                    if (wheel2 != null)
                    {
                        Vector3.Multiply(ref unitY, 5.0f, out velocity);

                        wheel2.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                    }
                }

                if (keyboardState[Key.S])
                {
                    if (wheel1 != null)
                    {
                        Vector3.Multiply(ref unitY, -5.0f, out velocity);

                        wheel1.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                    }

                    if (wheel2 != null)
                    {
                        Vector3.Multiply(ref unitY, -5.0f, out velocity);

                        wheel2.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                    }
                }

                if (keyboardState[Key.D])
                {
                    if (steeringGearConstraint != null)
                    {
                        steeringGearConstraint.ControlDegAngleY -= 2.0f;
                    }

                    if (constraint1 != null)
                    {
                        constraint1.ControlDegAngleY += 1.0f;
                    }

                    if (constraint4 != null)
                    {
                        constraint4.ControlDegAngleY += 1.0f;
                    }
                }

                if (keyboardState[Key.A])
                {
                    if (steeringGearConstraint != null)
                    {
                        steeringGearConstraint.ControlDegAngleY += 2.0f;
                    }

                    if (constraint1 != null)
                    {
                        constraint1.ControlDegAngleY -= 1.0f;
                    }

                    if (constraint4 != null)
                    {
                        constraint4.ControlDegAngleY -= 1.0f;
                    }
                }
            }
            else
            {
                if ((cameraBody != null) && steeringGearSwitch.IsColliding(cameraBody))
                {
                    if (keyboardState[Key.Space] && !oldKeyboardState[Key.Space])
                    {
                        physicsObjectWithActiveCamera.Camera.EnableControl = true;

                        cameraDown.RigidGroupOwner.MaxPreUpdateAngularVelocity  = 1000.0f;
                        cameraDown.RigidGroupOwner.MaxPostUpdateAngularVelocity = 1000.0f;

                        cameraDown.DisableCollision(steeringWheel, true);
                        cameraDown.DisableCollision(chassisBack, true);
                        cameraDown.DisableCollision(chassisMiddleBack, true);
                        cameraDown.DisableCollision(upBodyFront, true);
                        cameraDown.DisableCollision(upBodyDownBack, true);

                        cameraBody.DisableCollision(steeringGearDown, true);
                        cameraBody.DisableCollision(steeringWheel, true);
                        cameraBody.DisableCollision(chassisBack, true);
                        cameraBody.DisableCollision(chassisMiddleBack, true);
                        cameraBody.DisableCollision(upBodyFront, true);
                        cameraBody.DisableCollision(upBodyDownBack, true);

                        Quaternion cameraOrientationX  = quaternionIdentity;
                        Quaternion cameraOrientationY  = quaternionIdentity;
                        Quaternion cameraOrientationZ  = quaternionIdentity;
                        Quaternion cameraOrientationXY = quaternionIdentity;
                        Quaternion cameraOrientation   = quaternionIdentity;

                        Quaternion.Multiply(ref cameraOrientationX, ref cameraOrientationY, out cameraOrientationXY);
                        Quaternion.Multiply(ref cameraOrientationXY, ref cameraOrientationZ, out cameraOrientation);
                        rotation = Matrix4.CreateFromQuaternion(cameraOrientation);

                        physicsObjectWithActiveCamera.Camera.SetOrientation(ref cameraOrientation);
                        physicsObjectWithActiveCamera.Camera.SetRotation(ref rotation);
                        physicsObjectWithActiveCamera.Camera.SetEuler(ref rotation);

                        objectOrientation = Quaternion.FromAxisAngle(unitY, MathHelper.DegreesToRadians(180.0f));
                        objectRotation    = Matrix4.CreateFromQuaternion(objectOrientation);

                        Vector3 carChassisPosition = vectorZero;
                        Matrix4 carChassisRotation = matrixIdentity;

                        chassisMiddleDown.MainWorldTransform.GetPosition(ref carChassisPosition);
                        chassisMiddleDown.MainWorldTransform.GetRotation(ref carChassisRotation);

                        Matrix4.Mult(ref objectRotation, ref carChassisRotation, out rotation);

                        Vector3.TransformVector(ref driverLocalPosition, ref carChassisRotation, out position);
                        Vector3.Add(ref carChassisPosition, ref position, out position);

                        physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                        physicsObjectWithActiveCamera.RigidGroupOwner.MainWorldTransform.SetPosition(ref position);
                        physicsObjectWithActiveCamera.RigidGroupOwner.RecalculateMainTransform();

                        if (CameraConstraint == null)
                        {
                            CameraConstraint = scene.Factory.ConstraintManager.Create(cameraConstraintName);
                            CameraConstraint.PhysicsObject1 = cameraDown;
                            CameraConstraint.PhysicsObject2 = chassisMiddleDown;
                            CameraConstraint.PhysicsObject1.MainWorldTransform.GetPosition(ref position1);
                            CameraConstraint.PhysicsObject1.MainWorldTransform.GetOrientation(ref orientation1);
                            CameraConstraint.PhysicsObject2.MainWorldTransform.GetOrientation(ref orientation2);

                            carChassisPosition.X = carChassisPosition.Z = 0.0f;
                            carChassisPosition.Y = 2.0f;
                            Vector3.Subtract(ref position1, ref carChassisPosition, out position1);

                            CameraConstraint.SetAnchor1(ref position1);
                            CameraConstraint.SetAnchor2(ref position1);
                            CameraConstraint.SetInitWorldOrientation1(ref orientation1);
                            CameraConstraint.SetInitWorldOrientation2(ref orientation2);
                            CameraConstraint.EnableLimitAngleX          = true;
                            CameraConstraint.EnableLimitAngleY          = true;
                            CameraConstraint.EnableLimitAngleZ          = true;
                            CameraConstraint.LimitAngleForce            = 0.4f;
                            CameraConstraint.MinResponseLinearVelocity  = 0.005f;
                            CameraConstraint.MinResponseAngularVelocity = 0.005f;
                            CameraConstraint.Update();
                        }
                    }
                }

                if (enableExternalMoving)
                {
                    if (keyboardState[Key.Up])
                    {
                        if (wheel1 != null)
                        {
                            Vector3.Multiply(ref unitY, 5.0f, out velocity);

                            wheel1.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                        }

                        if (wheel2 != null)
                        {
                            Vector3.Multiply(ref unitY, 5.0f, out velocity);

                            wheel2.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                        }
                    }

                    if (keyboardState[Key.Down])
                    {
                        if (wheel1 != null)
                        {
                            Vector3.Multiply(ref unitY, -5.0f, out velocity);

                            wheel1.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                        }

                        if (wheel2 != null)
                        {
                            Vector3.Multiply(ref unitY, -5.0f, out velocity);

                            wheel2.MainWorldTransform.AddLocalAngularVelocity(ref velocity);
                        }
                    }

                    if (keyboardState[Key.Right])
                    {
                        if (steeringGearConstraint != null)
                        {
                            steeringGearConstraint.ControlDegAngleY -= 2.0f;
                        }

                        if (constraint1 != null)
                        {
                            constraint1.ControlDegAngleY += 1.0f;
                        }

                        if (constraint4 != null)
                        {
                            constraint4.ControlDegAngleY += 1.0f;
                        }
                    }

                    if (keyboardState[Key.Left])
                    {
                        if (steeringGearConstraint != null)
                        {
                            steeringGearConstraint.ControlDegAngleY += 2.0f;
                        }

                        if (constraint1 != null)
                        {
                            constraint1.ControlDegAngleY -= 1.0f;
                        }

                        if (constraint4 != null)
                        {
                            constraint4.ControlDegAngleY -= 1.0f;
                        }
                    }
                }
            }

            oldKeyboardState = keyboardState;
        }
Esempio n. 13
0
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }
            if (!objectBase.Camera.Active)
            {
                return;
            }

            float time = (float)args.Time;

            Vector3 deltaRotation       = vectorZero;
            Vector3 deltaTranslation    = vectorZero;
            float   rotationSpeed       = 8.0f;
            float   translationSpeed    = 8.0f;
            float   soundPositionFactor = 0.1f;
            bool    enableShot          = false;

            DemoMouseState    mouseState    = demo.GetMouseState();
            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (mouseState[MouseButton.Right])
            {
                deltaRotation.Y += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.X - oldMouseState.X) * time);
                deltaRotation.X += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.Y - oldMouseState.Y) * time);
            }

            mousePosition.X = mouseState.X;
            mousePosition.Y = mouseState.Y;

            if (mouseState[MouseButton.Middle] && !oldMouseState[MouseButton.Middle])
            {
                enableShot = true;
            }

            if ((keyboardState[Key.ControlRight] && !oldKeyboardState[Key.ControlRight]) ||
                (keyboardState[Key.ControlLeft] && !oldKeyboardState[Key.ControlLeft]))
            {
                enableShot = true;
            }

            PhysicsObject cursorA = scene.Factory.PhysicsObjectManager.Find(cursorAName);
            PhysicsObject cursorB = scene.Factory.PhysicsObjectManager.Find(cursorBName);

            if (!demo.EnableMenu)
            {
                if (cursorA != null)
                {
                    cursorA.EnableDrawing = true;
                }

                if (cursorB != null)
                {
                    cursorB.EnableDrawing = true;
                }
            }
            else
            {
                if (cursorA != null)
                {
                    cursorA.EnableDrawing = false;
                }

                if (cursorB != null)
                {
                    cursorB.EnableDrawing = false;
                }
            }

            if (keyboardState[Key.W])
            {
                deltaTranslation.Z += translationSpeed * time;
            }

            if (keyboardState[Key.S])
            {
                deltaTranslation.Z -= translationSpeed * time;
            }

            if (keyboardState[Key.D])
            {
                deltaTranslation.X += translationSpeed * time;
            }

            if (keyboardState[Key.A])
            {
                deltaTranslation.X -= translationSpeed * time;
            }

            oldMouseState    = mouseState;
            oldKeyboardState = keyboardState;

            if (deltaRotation.LengthSquared != 0.0f)
            {
                Vector3 euler = vectorZero;
                objectBase.Camera.GetEuler(ref euler);
                Vector3.Add(ref euler, ref deltaRotation, out euler);
                objectBase.Camera.SetEuler(ref euler);

                Matrix4 rotationX, rotationY;
                Matrix4.CreateRotationX(-euler.X, out rotationX);
                Matrix4.CreateRotationY(-euler.Y, out rotationY);
                Matrix4.Mult(ref rotationY, ref rotationX, out cameraRotation);

                objectBase.Camera.SetRotation(ref cameraRotation);

                objectBase.MainWorldTransform.SetTransposeRotation(ref cameraRotation);
                objectBase.RecalculateMainTransform();
            }

            if (deltaTranslation.LengthSquared != 0.0f)
            {
                objectBase.MainWorldTransform.GetRotation(ref rotation);
                Vector3.TransformVector(ref deltaTranslation, ref rotation, out direction);

                objectBase.MainWorldTransform.GetPosition(ref position);
                Vector3.Add(ref position, ref direction, out position);
                objectBase.MainWorldTransform.SetPosition(ref position);

                objectBase.RecalculateMainTransform();
            }

            objectBase.Camera.Projection.CreatePerspectiveLH(1.0f, 11000.0f, 70.0f, demo.WindowWidth, demo.WindowHeight);

            objectBase.MainWorldTransform.GetPosition(ref position);
            objectBase.Camera.GetTransposeRotation(ref cameraRotation);

            objectBase.Camera.View.CreateLookAtLH(ref position, ref cameraRotation, 0.0f);
            objectBase.Camera.UpdateFrustum();

            objectBase.Camera.View.GetViewMatrix(ref view);
            objectBase.Camera.Projection.GetProjectionMatrix(ref projection);

            Vector3 rayPosition, rayDirection;

            rayPosition = rayDirection = vectorZero;

            objectBase.UnProjectToRay(ref mousePosition, 0, 0, demo.WindowWidth, demo.WindowHeight, 0.0f, 1.0f, ref view, ref matrixIdentity, ref projection, ref rayPosition, ref rayDirection);

            PhysicsObject cursor = scene.Factory.PhysicsObjectManager.Find(cursorName);

            if (cursor != null)
            {
                Vector3 cursorPosition      = vectorZero;
                Matrix4 cursorLocalRotation = matrixIdentity;
                Matrix4 cursorWorldRotation = matrixIdentity;

                cursor.InitLocalTransform.GetPosition(ref cursorPosition);
                cursor.InitLocalTransform.GetRotation(ref cursorLocalRotation);
                cursor.MainWorldTransform.GetRotation(ref cursorWorldRotation);

                objectBase.Camera.GetTransposeRotation(ref cameraRotation);
                Matrix4.Mult(ref cursorLocalRotation, ref cameraRotation, out rotation);

                Vector3.TransformVector(ref cursorPosition, ref cursorWorldRotation, out position);

                cursor.MainWorldTransform.SetRotation(ref rotation);
                Vector3.Add(ref position, ref rayPosition, out position);
                Vector3.Add(ref position, ref rayDirection, out position);
                cursor.MainWorldTransform.SetPosition(ref position);

                cursor.RecalculateMainTransform();
            }

            CursorController cursorController = objectBase.InternalControllers.CursorController;

            if (cursorController.IsDragging)
            {
                if (cursorController.HitPhysicsObject.Integral.IsStatic && (cursorController.HitPhysicsObject.Shape != null) && (cursorController.HitPhysicsObject.Shape.ShapePrimitive != null) && (cursorController.HitPhysicsObject.Shape.ShapePrimitive.ShapePrimitiveType == ShapePrimitiveType.TriangleMesh))
                {
                    Vector3 cursorStartPosition = vectorZero;
                    Vector3 cursorEndPosition   = vectorZero;

                    cursorController.GetAnchor1(ref cursorStartPosition);
                    cursorController.GetAnchor2(ref cursorEndPosition);

                    Vector3.Subtract(ref cursorEndPosition, ref cursorStartPosition, out direction);

                    if (direction.LengthSquared != 0.0f)
                    {
                        cursorController.HitPhysicsObject.MainWorldTransform.GetPosition(ref cursorStartPosition);

                        Vector3.Add(ref cursorStartPosition, ref direction, out cursorStartPosition);

                        cursorController.HitPhysicsObject.MainWorldTransform.SetPosition(ref cursorStartPosition);
                        cursorController.HitPhysicsObject.RecalculateMainTransform();
                    }
                }
            }

            objectBase.MainWorldTransform.GetPosition(ref listenerPosition);
            objectBase.Camera.GetTransposeRotation(ref rotation);

            Vector3.Multiply(ref listenerPosition, soundPositionFactor, out position);
            listenerTopDirection.X   = rotation.Row1.X;
            listenerTopDirection.Y   = rotation.Row1.Y;
            listenerTopDirection.Z   = rotation.Row1.Z;
            listenerFrontDirection.X = rotation.Row2.X;
            listenerFrontDirection.Y = rotation.Row2.Y;
            listenerFrontDirection.Z = rotation.Row2.Z;

            listener.Position       = position;
            listener.TopDirection   = listenerTopDirection;
            listener.FrontDirection = listenerFrontDirection;
            listenerRange           = objectBase.Sound.Range;

            if (enableShot)
            {
                Vector3 shotScale, shotColor;

                shotCount = (shotCount + 1) % shotTab.Length;
                string shotCountName = shotCount.ToString();

                PhysicsObject shot      = scene.Factory.PhysicsObjectManager.FindOrCreate(shotName + shotCountName);
                PhysicsObject shotBase  = scene.Factory.PhysicsObjectManager.FindOrCreate(shotBaseName + shotCountName);
                PhysicsObject shotLight = scene.Factory.PhysicsObjectManager.FindOrCreate(shotLightName + shotCountName);

                shot.AddChildPhysicsObject(shotBase);
                shot.AddChildPhysicsObject(shotLight);

                shotTab[shotCount] = shotBase;
                enableShotTab      = true;

                shotScale = shotColor = vectorZero;

                shotScale.X = shotScale.Y = shotScale.Z = 0.5f;
                Vector3.Multiply(ref rayDirection, 300.0f, out rayDirection);

                shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot.InitLocalTransform.SetPosition(ref rayPosition);
                shot.InitLocalTransform.SetLinearVelocity(ref rayDirection);
                shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot.MaxSimulationFrameCount = 200;
                shot.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;
                //shot.EnableLocalGravity = true;

                shotBase.Shape       = sphere;
                shotBase.UserDataStr = sphereName;
                shotBase.InitLocalTransform.SetScale(ref shotScale);
                shotBase.Integral.SetDensity(10.0f);
                shotBase.Material.RigidGroup   = true;
                shotBase.EnableBreakRigidGroup = false;
                shotBase.EnableCollisions      = true;
                shotBase.DisableCollision(objectBase, true);
                shotBase.MaxDisableCollisionFrameCount = 50;
                shotBase.CreateSound(true);

                shotLight.Shape       = sphere;
                shotLight.UserDataStr = sphereName;
                shotLight.CreateLight(true);
                shotLight.Light.Type  = PhysicsLightType.Point;
                shotLight.Light.Range = 20.0f;

                shotColor.X = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Y = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Z = (float)Math.Max(random.NextDouble(), random.NextDouble());

                shotLight.Light.SetDiffuse(ref shotColor);
                shotLight.InitLocalTransform.SetScale(20.0f);
                shotLight.Material.UserDataStr    = yellowName;
                shotLight.Material.RigidGroup     = true;
                shotLight.EnableBreakRigidGroup   = false;
                shotLight.EnableCollisions        = false;
                shotLight.EnableCursorInteraction = false;
                shotLight.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                scene.UpdateFromInitLocalTransform(shot);

                shotSoundGroup = demo.SoundGroups[hitName];
                shotSoundGroup.MaxHitRepeatTime = 0.0f;

                if (shotSound == null)
                {
                    shotSound = shotSoundGroup.GetSound(objectBase.Sound, listener, emitter);
                }

                shotSound.Update(time);

                Vector3.Multiply(ref rayPosition, soundPositionFactor, out shotSound.HitPosition);
                shotSound.HitVolume = 1.0f;

                shotSound.FrontDirection.X = rotation.Row2.X;
                shotSound.FrontDirection.Y = rotation.Row2.Y;
                shotSound.FrontDirection.Z = rotation.Row2.Z;

                demo.SoundQueue.EnqueueSound(shotSound);
            }
            else
            {
                PhysicsObject shotBase;
                DemoSound     shotBaseSound;

                if (shotSound != null)
                {
                    shotSound.Update(time);

                    if (shotSound.Stop())
                    {
                        shotSound.SoundGroup.SetSound(shotSound);
                        shotSound = null;
                    }
                }

                if (enableShotTab)
                {
                    enableShotTab = false;

                    for (int i = 0; i < shotTab.Length; i++)
                    {
                        shotBase = shotTab[i];

                        if (shotBase != null)
                        {
                            if (shotBase.Sound.UserDataObj != null)
                            {
                                enableShotTab = true;
                                shotBaseSound = (DemoSound)shotBase.Sound.UserDataObj;
                                shotBaseSound.Update(time);

                                if (shotBaseSound.Stop())
                                {
                                    shotBaseSound.SoundGroup.SetSound(shotBaseSound);
                                    shotBase.Sound.UserDataObj = null;
                                    shotTab[i] = null;
                                }
                            }
                        }
                    }
                }
            }

            objectBase.Camera.UpdatePhysicsObjects(true, true, true);
            objectBase.Camera.SortDrawPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortTransparentPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortLightPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);

            PhysicsObject  currentPhysicsObject;
            PhysicsSound   currentSound;
            DemoSoundGroup soundGroup;
            DemoSound      sound;

            if (demo.SoundQueue.SoundCount > 0)
            {
                return;
            }

            for (int i = 0; i < scene.TotalPhysicsObjectCount; i++)
            {
                if (demo.SoundQueue.SoundCount >= demo.SoundQueue.MaxSoundCount)
                {
                    break;
                }

                currentPhysicsObject = scene.GetPhysicsObject(i);

                currentSound = !currentPhysicsObject.EnableSoundFromRigidGroupOwner ? currentPhysicsObject.Sound : currentPhysicsObject.RigidGroupOwner.Sound;

                if (currentSound == null)
                {
                    continue;
                }

                if (!currentSound.Enabled)
                {
                    continue;
                }

                if (currentSound.UserDataStr == null)
                {
                    soundGroup = demo.SoundGroups[defaultName];
                }
                else
                {
                    soundGroup = demo.SoundGroups[currentSound.UserDataStr];
                }

                if (currentPhysicsObject.IsSleeping && (currentSound.UserDataObj == null) && !soundGroup.EnableBackground)
                {
                    continue;
                }

                if (currentPhysicsObject.GetSoundData(ref listenerPosition, listenerRange, soundGroup.EnableHit, soundGroup.EnableRoll, soundGroup.EnableSlide, soundGroup.EnableBackground, currentSound.BackgroundVolumeVelocityModulation, ref hitPosition, ref rollPosition, ref slidePosition, ref backgroundPosition, ref hitVolume, ref rollVolume, ref slideVolume, ref backgroundVolume))
                {
                    if (currentSound.UserDataObj == null)
                    {
                        sound = soundGroup.GetSound(currentSound, listener, emitter);
                        currentSound.UserDataObj = sound;
                    }
                    else
                    {
                        sound = (DemoSound)currentSound.UserDataObj;
                    }

                    sound.Update(time);

                    currentPhysicsObject.MainWorldTransform.GetTransposeRotation(ref rotation);

                    Vector3.Multiply(ref hitPosition, soundPositionFactor, out sound.HitPosition);
                    Vector3.Multiply(ref rollPosition, soundPositionFactor, out sound.RollPosition);
                    Vector3.Multiply(ref slidePosition, soundPositionFactor, out sound.SlidePosition);
                    Vector3.Multiply(ref backgroundPosition, soundPositionFactor, out sound.BackgroundPosition);

                    sound.HitVolume        = hitVolume;
                    sound.RollVolume       = rollVolume;
                    sound.SlideVolume      = slideVolume;
                    sound.BackgroundVolume = backgroundVolume;

                    sound.FrontDirection.X = rotation.Row2.X;
                    sound.FrontDirection.Y = rotation.Row2.Y;
                    sound.FrontDirection.Z = rotation.Row2.Z;

                    demo.SoundQueue.EnqueueSound(sound);
                }
                else
                {
                    if (currentSound.UserDataObj != null)
                    {
                        sound = (DemoSound)currentSound.UserDataObj;
                        sound.Update(time);

                        if (sound.Stop())
                        {
                            soundGroup.SetSound(sound);
                            currentSound.UserDataObj = null;
                        }
                    }
                }
            }
        }
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }
            if (!objectBase.Camera.Active)
            {
                return;
            }

            float time = (float)args.Time;

            Vector3 deltaRotation    = vectorZero;
            Vector3 deltaTranslation = vectorZero;
            float   rotationSpeed    = 8.0f;
            float   translationSpeed = 8.0f;
            bool    enableShot       = false;

            DemoMouseState    mouseState    = demo.GetMouseState();
            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (mouseState[MouseButton.Right])
            {
                deltaRotation.Y += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.X - oldMouseState.X) * time);
                deltaRotation.X += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.Y - oldMouseState.Y) * time);
            }

            if (mouseState[MouseButton.Middle] && !oldMouseState[MouseButton.Middle])
            {
                enableShot = true;
            }

            if ((keyboardState[Key.ControlRight] && !oldKeyboardState[Key.ControlRight]) ||
                (keyboardState[Key.ControlLeft] && !oldKeyboardState[Key.ControlLeft]))
            {
                enableShot = true;
            }

            if (keyboardState[Key.W])
            {
                deltaTranslation.Z += translationSpeed * time;
            }

            if (keyboardState[Key.S])
            {
                deltaTranslation.Z -= translationSpeed * time;
            }

            if (keyboardState[Key.D])
            {
                deltaTranslation.X += translationSpeed * time;
            }

            if (keyboardState[Key.A])
            {
                deltaTranslation.X -= translationSpeed * time;
            }

            oldMouseState    = mouseState;
            oldKeyboardState = keyboardState;

            if (deltaRotation.LengthSquared != 0.0f)
            {
                Vector3 euler = vectorZero;
                objectBase.Camera.GetEuler(ref euler);
                Vector3.Add(ref euler, ref deltaRotation, out euler);
                objectBase.Camera.SetEuler(ref euler);

                Matrix4 rotationX, rotationY;
                Matrix4.CreateRotationX(-euler.X, out rotationX);
                Matrix4.CreateRotationY(-euler.Y, out rotationY);
                Matrix4.Mult(ref rotationY, ref rotationX, out cameraRotation);

                objectBase.Camera.SetRotation(ref cameraRotation);

                objectBase.MainWorldTransform.SetTransposeRotation(ref cameraRotation);
                objectBase.RecalculateMainTransform();
            }

            if (deltaTranslation.LengthSquared != 0.0f)
            {
                objectBase.MainWorldTransform.GetRotation(ref rotation);
                Vector3.TransformVector(ref deltaTranslation, ref rotation, out direction);

                objectBase.MainWorldTransform.GetPosition(ref position);
                Vector3.Add(ref position, ref direction, out position);
                objectBase.MainWorldTransform.SetPosition(ref position);

                objectBase.RecalculateMainTransform();
            }

            objectBase.Camera.Projection.CreatePerspectiveLH(1.0f, 11000.0f, 70.0f, demo.WindowWidth, demo.WindowHeight);

            objectBase.MainWorldTransform.GetPosition(ref position);
            objectBase.Camera.GetTransposeRotation(ref cameraRotation);

            objectBase.Camera.View.CreateLookAtLH(ref position, ref cameraRotation, 0.0f);
            objectBase.Camera.UpdateFrustum();

            if (enableShot)
            {
                Vector3 shotScale, shotColor;

                string        frameCountName = scene.SimulationFrameCount.ToString();
                PhysicsObject shot           = scene.Factory.PhysicsObjectManager.Create(shotName + frameCountName);
                PhysicsObject shotBase       = scene.Factory.PhysicsObjectManager.Create(shotBaseName + frameCountName);
                PhysicsObject shotLight      = scene.Factory.PhysicsObjectManager.Create(shotLightName + frameCountName);

                shot.AddChildPhysicsObject(shotBase);
                shot.AddChildPhysicsObject(shotLight);

                shotScale = shotColor = vectorZero;

                shotScale.X = shotScale.Y = shotScale.Z = 0.5f;

                objectBase.MainWorldTransform.GetPosition(ref position);
                objectBase.Camera.GetTransposeRotation(ref cameraRotation);

                direction.X = cameraRotation.Row2.X;
                direction.Y = cameraRotation.Row2.Y;
                direction.Z = cameraRotation.Row2.Z;

                Vector3.Multiply(ref direction, 300.0f, out direction);

                shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot.InitLocalTransform.SetPosition(ref position);
                shot.InitLocalTransform.SetLinearVelocity(ref direction);
                shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot.MaxSimulationFrameCount = 200;
                //shot.EnableLocalGravity = true;

                shotBase.Shape       = sphere;
                shotBase.UserDataStr = sphereName;
                shotBase.InitLocalTransform.SetScale(ref shotScale);
                shotBase.Integral.SetDensity(10.0f);
                shotBase.Material.RigidGroup   = true;
                shotBase.EnableBreakRigidGroup = false;
                shotBase.EnableCollisions      = true;
                shotBase.DisableCollision(objectBase, true);
                shotBase.MaxDisableCollisionFrameCount = 50;

                shotLight.Shape       = sphere;
                shotLight.UserDataStr = sphereName;
                shotLight.CreateLight(true);
                shotLight.Light.Type  = PhysicsLightType.Point;
                shotLight.Light.Range = 20.0f;

                shotColor.X = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Y = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Z = (float)Math.Max(random.NextDouble(), random.NextDouble());

                shotLight.Light.SetDiffuse(ref shotColor);
                shotLight.InitLocalTransform.SetScale(20.0f);
                shotLight.Material.RigidGroup     = true;
                shotLight.EnableBreakRigidGroup   = false;
                shotLight.EnableCollisions        = false;
                shotLight.EnableCursorInteraction = false;
                shotLight.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                scene.UpdateFromInitLocalTransform(shot);
            }

            objectBase.Camera.UpdatePhysicsObjects(true, true, true);
            objectBase.Camera.SortDrawPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortTransparentPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
        }
Esempio n. 15
0
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }
            if (!objectBase.Camera.Active)
            {
                return;
            }

            float time = (float)args.Time;

            Vector3 deltaRotation            = vectorZero;
            Vector3 deltaTranslation         = vectorZero;
            float   rotationSpeed            = 8.0f;
            float   translationSpeed         = 8.0f;
            float   jumpSpeed                = 8.0f;
            float   swimUpSpeed              = 0.2f;
            float   swimUpOnSurfaceSpeed     = 0.06f;
            float   translationInFluidFactor = 0.15f;
            float   soundPositionFactor      = 0.1f;
            bool    enableJump               = false;
            bool    enableSwimUp             = false;
            bool    enableShot               = false;

            bool cameraBodyCollision = cameraBody.IsColliding();
            bool cameraDownCollision = cameraDown.IsColliding();

            DemoMouseState    mouseState    = demo.GetMouseState();
            DemoKeyboardState keyboardState = demo.GetKeyboardState();

            if (mouseState[MouseButton.Right])
            {
                deltaRotation.Y += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.X - oldMouseState.X) * time);
                deltaRotation.X += MathHelper.DegreesToRadians(rotationSpeed * (mouseState.Y - oldMouseState.Y) * time);
            }

            mousePosition.X = mouseState.X;
            mousePosition.Y = mouseState.Y;

            if (!objectBase.Camera.EnableControl)
            {
                if (mouseState[MouseButton.Middle] && !oldMouseState[MouseButton.Middle])
                {
                    enableShot = true;
                }

                if ((keyboardState[Key.ControlRight] && !oldKeyboardState[Key.ControlRight]) ||
                    (keyboardState[Key.ControlLeft] && !oldKeyboardState[Key.ControlLeft]))
                {
                    enableShot = true;
                }
            }

            PhysicsObject cursorA = scene.Factory.PhysicsObjectManager.Find(cursorAName);
            PhysicsObject cursorB = scene.Factory.PhysicsObjectManager.Find(cursorBName);

            if (!demo.EnableMenu)
            {
                if (cursorA != null)
                {
                    cursorA.EnableDrawing = true;
                }

                if (cursorB != null)
                {
                    cursorB.EnableDrawing = true;
                }
            }
            else
            {
                if (cursorA != null)
                {
                    cursorA.EnableDrawing = false;
                }

                if (cursorB != null)
                {
                    cursorB.EnableDrawing = false;
                }
            }

            if (!objectBase.Camera.EnableControl)
            {
                if (keyboardState[Key.W])
                {
                    deltaTranslation.Z += translationSpeed * time;
                }

                if (keyboardState[Key.S])
                {
                    deltaTranslation.Z -= translationSpeed * time;
                }

                if (keyboardState[Key.D])
                {
                    deltaTranslation.X += translationSpeed * time;
                }

                if (keyboardState[Key.A])
                {
                    deltaTranslation.X -= translationSpeed * time;
                }

                if (keyboardState[Key.Space] && !oldKeyboardState[Key.Space])
                {
                    enableJump = true;
                }

                if (keyboardState[Key.Space])
                {
                    enableSwimUp = true;
                }
            }

            if (keyboardState[Key.Tab] && !oldKeyboardState[Key.Tab])
            {
                enableDistance = !enableDistance;
            }

            oldMouseState    = mouseState;
            oldKeyboardState = keyboardState;

            Vector3 gravityDirection = vectorZero;

            scene.GetGravityDirection(ref gravityDirection);

            if (!objectBase.Camera.EnableControl)
            {
                if (deltaRotation.LengthSquared != 0.0f)
                {
                    Vector3 euler = vectorZero;
                    objectBase.Camera.GetEuler(ref euler);
                    Vector3.Add(ref euler, ref deltaRotation, out euler);
                    objectBase.Camera.SetEuler(ref euler);

                    Matrix4 rotationX, rotationY;
                    Matrix4.CreateRotationX(-euler.X, out rotationX);
                    Matrix4.CreateRotationY(-euler.Y, out rotationY);
                    Matrix4.Mult(ref rotationY, ref rotationX, out cameraRotation);

                    objectBase.Camera.SetRotation(ref cameraRotation);

                    Matrix4.CreateRotationY(euler.Y, out rotation);

                    objectBase.RigidGroupOwner.MainWorldTransform.SetRotation(ref rotation);
                    objectBase.RigidGroupOwner.RecalculateMainTransform();
                }
            }
            else
            {
                Vector3 euler          = vectorZero;
                Matrix4 objectRotation = matrixIdentity;
                objectBase.Camera.GetEuler(ref euler);
                Vector3.Add(ref euler, ref deltaRotation, out euler);
                objectBase.RigidGroupOwner.MainWorldTransform.GetRotation(ref objectRotation);

                Matrix4 rotationX, rotationY;
                Matrix4.CreateRotationX(euler.X, out rotationX);
                Matrix4.CreateRotationY(euler.Y, out rotationY);

                Matrix4.Mult(ref rotationX, ref rotationY, out cameraRotation);
                Matrix4.Mult(ref cameraRotation, ref objectRotation, out rotation);

                objectBase.Camera.SetEuler(ref euler);
                objectBase.Camera.SetTransposeRotation(ref rotation);
            }

            if (deltaTranslation.LengthSquared != 0.0f)
            {
                if (objectBase.RigidGroupOwner.IsUnderFluidSurface)
                {
                    objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 10.0f;
                    objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 10.0f;

                    if (enableSwimUp)
                    {
                        objectBase.InitLocalTransform.GetTransposeRotation(ref rotation);
                        Vector3.TransformVector(ref deltaTranslation, ref rotation, out direction);

                        objectBase.MainWorldTransform.GetRotation(ref rotation);
                        Vector3.TransformVector(ref direction, ref rotation, out moveForce);
                        Vector3.Multiply(ref moveForce, translationInFluidFactor * objectBase.RigidGroupOwner.Integral.Mass / (time * time), out moveForce);

                        objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                    }
                    else
                    {
                        objectBase.Camera.GetTransposeRotation(ref rotation);
                        Vector3.TransformVector(ref deltaTranslation, ref rotation, out moveForce);
                        Vector3.Multiply(ref moveForce, translationInFluidFactor * objectBase.RigidGroupOwner.Integral.Mass / (time * time), out moveForce);

                        objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                    }
                }
                else
                {
                    if (cameraDownCollision)
                    {
                        objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 100000.0f;
                        objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 100000.0f;

                        objectBase.InitLocalTransform.GetTransposeRotation(ref rotation);
                        Vector3.TransformVector(ref deltaTranslation, ref rotation, out direction);

                        objectBase.MainWorldTransform.GetRotation(ref rotation);
                        Vector3.TransformVector(ref direction, ref rotation, out moveForce);
                        Vector3.Multiply(ref moveForce, objectBase.RigidGroupOwner.Integral.Mass / (time * time), out moveForce);

                        objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                        cameraDown.UpdateFeedbackForce(ref moveForce);
                    }
                    else
                    {
                        if (objectBase.RigidGroupOwner.IsInFluid)
                        {
                            objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 10.0f;
                            objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 10.0f;

                            objectBase.InitLocalTransform.GetTransposeRotation(ref rotation);
                            Vector3.TransformVector(ref deltaTranslation, ref rotation, out direction);

                            objectBase.MainWorldTransform.GetRotation(ref rotation);
                            Vector3.TransformVector(ref direction, ref rotation, out moveForce);
                            Vector3.Multiply(ref moveForce, translationInFluidFactor * objectBase.RigidGroupOwner.Integral.Mass / (time * time), out moveForce);

                            objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                        }
                    }
                }
            }

            if (enableSwimUp)
            {
                if (cameraDown.IsUnderFluidSurface && cameraBody.IsUnderFluidSurface)
                {
                    objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 10.0f;
                    objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 10.0f;

                    PhysicsObject fluidPhysicsObject = objectBase.RigidGroupOwner.FluidPhysicsObject;
                    fluidPhysicsObject.InternalControllers.FluidController.GetNormal(ref fluidNormal);

                    Vector3.Multiply(ref fluidNormal, swimUpSpeed * objectBase.RigidGroupOwner.Integral.Mass / time, out moveForce);

                    objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                }
                else
                if (!cameraDownCollision && cameraBody.IsInFluid && (deltaTranslation.LengthSquared == 0.0f))
                {
                    objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 10.0f;
                    objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 10.0f;

                    PhysicsObject fluidPhysicsObject = objectBase.RigidGroupOwner.FluidPhysicsObject;
                    fluidPhysicsObject.InternalControllers.FluidController.GetNormal(ref fluidNormal);

                    Vector3.Multiply(ref fluidNormal, swimUpOnSurfaceSpeed * objectBase.RigidGroupOwner.Integral.Mass / time, out moveForce);

                    objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                }
            }

            if (enableJump)
            {
                if (!enableControl && !objectBase.Camera.EnableControl && cameraDownCollision && !cameraDown.IsUnderFluidSurface && !cameraBody.IsUnderFluidSurface)
                {
                    objectBase.RigidGroupOwner.MaxPreUpdateLinearVelocity  = 100000.0f;
                    objectBase.RigidGroupOwner.MaxPostUpdateLinearVelocity = 100000.0f;

                    Vector3.Multiply(ref gravityDirection, -jumpSpeed * objectBase.RigidGroupOwner.Integral.Mass / time, out moveForce);

                    objectBase.RigidGroupOwner.WorldAccumulator.AddWorldForce(ref moveForce);
                    cameraDown.UpdateFeedbackForce(ref moveForce);
                }
            }

            if (enableDistance)
            {
                if (distance > maxDistance)
                {
                    distance -= 2.0f;
                }

                if (enableDistanceCollision)
                {
                    float margin = 1.0f;

                    objectBase.MainWorldTransform.GetPosition(ref startPoint);

                    objectBase.Camera.GetTransposeRotation(ref cameraRotation);

                    direction.X = cameraRotation.Row2.X;
                    direction.Y = cameraRotation.Row2.Y;
                    direction.Z = cameraRotation.Row2.Z;

                    Vector3.Multiply(ref direction, distance, out direction);
                    Vector3.Add(ref startPoint, ref direction, out endPoint);

                    scene.UpdatePhysicsObjectsIntersectedBySegment(ref startPoint, ref endPoint, margin, true);

                    float minDistance = float.MaxValue;
                    float curDistance = 0.0f;

                    for (int i = 0; i < scene.IntersectedPhysicsObjectsCount; i++)
                    {
                        PhysicsObject hitObject = scene.GetIntersectedPhysicsObject(i, ref hitPoint);

                        if (hitObject.RigidGroupOwner == objectBase.RigidGroupOwner)
                        {
                            continue;
                        }

                        //if ((hitObject.InternalControllers.FluidController != null) && hitObject.InternalControllers.FluidController.Enabled)
                        //    continue;

                        if (!hitObject.EnableCollisions)
                        {
                            continue;
                        }

                        Vector3.Subtract(ref startPoint, ref hitPoint, out hitDistance);
                        curDistance = hitDistance.Length;

                        if (curDistance < minDistance)
                        {
                            minDistance = curDistance;
                        }
                    }

                    if (minDistance < Math.Abs(distance))
                    {
                        distance = -minDistance;
                    }
                }
            }
            else
            {
                if (distance < 0.0f)
                {
                    distance += 2.0f;
                }

                if (distance > 0.0f)
                {
                    distance = 0.0f;
                }
            }

            if (enableDistance)
            {
                if (distance > maxDistance)
                {
                    if ((cameraUp != null) && (cameraBody != null) && (cameraDown != null))
                    {
                        objectBase.RigidGroupOwner.EnableDrawing = true;
                        cameraUp.EnableDrawing   = true;
                        cameraBody.EnableDrawing = true;
                        cameraDown.EnableDrawing = true;
                    }
                }
            }
            else
            {
                if (distance >= 0.0f)
                {
                    if ((cameraUp != null) && (cameraBody != null) && (cameraDown != null))
                    {
                        objectBase.RigidGroupOwner.EnableDrawing = false;
                        cameraUp.EnableDrawing   = false;
                        cameraBody.EnableDrawing = false;
                        cameraDown.EnableDrawing = false;
                    }
                }
            }

            enableControl = objectBase.Camera.EnableControl;

            float   gravityDistance       = 0.0f;
            Vector3 gravityLinearVelocity = vectorZero;
            Vector3 tangentLinearVelocity = vectorZero;
            Vector3 velocity = vectorZero;

            objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
            Vector3.Dot(ref gravityDirection, ref velocity, out gravityDistance);
            Vector3.Multiply(ref gravityDirection, gravityDistance, out gravityLinearVelocity);
            Vector3.Subtract(ref velocity, ref gravityLinearVelocity, out tangentLinearVelocity);

            float tangentLength = tangentLinearVelocity.Length;

            if (tangentLength > maxTangentLength)
            {
                tangentLinearVelocity *= maxTangentLength / tangentLength;
            }

            Vector3.Add(ref gravityLinearVelocity, ref tangentLinearVelocity, out velocity);

            objectBase.RigidGroupOwner.MainWorldTransform.SetLinearVelocity(ref velocity);

            objectBase.Camera.Projection.CreatePerspectiveLH(1.0f, 11000.0f, 70.0f, demo.WindowWidth, demo.WindowHeight);

            objectBase.MainWorldTransform.GetPosition(ref position);
            objectBase.Camera.GetTransposeRotation(ref cameraRotation);

            objectBase.Camera.View.CreateLookAtLH(ref position, ref cameraRotation, distance);
            objectBase.Camera.UpdateFrustum();

            objectBase.Camera.View.GetViewMatrix(ref view);
            objectBase.Camera.Projection.GetProjectionMatrix(ref projection);

            Vector3 rayPosition, rayDirection;

            rayPosition = rayDirection = vectorZero;

            objectBase.UnProjectToRay(ref mousePosition, 0, 0, demo.WindowWidth, demo.WindowHeight, 0.0f, 1.0f, ref view, ref matrixIdentity, ref projection, ref rayPosition, ref rayDirection);

            PhysicsObject cursor = scene.Factory.PhysicsObjectManager.Find(cursorName);

            if (cursor != null)
            {
                Vector3 cursorPosition      = vectorZero;
                Matrix4 cursorLocalRotation = matrixIdentity;
                Matrix4 cursorWorldRotation = matrixIdentity;

                cursor.InitLocalTransform.GetPosition(ref cursorPosition);
                cursor.InitLocalTransform.GetRotation(ref cursorLocalRotation);
                cursor.MainWorldTransform.GetRotation(ref cursorWorldRotation);

                objectBase.Camera.GetTransposeRotation(ref cameraRotation);
                Matrix4.Mult(ref cursorLocalRotation, ref cameraRotation, out rotation);

                Vector3.TransformVector(ref cursorPosition, ref cursorWorldRotation, out position);

                cursor.MainWorldTransform.SetRotation(ref rotation);
                Vector3.Add(ref position, ref rayPosition, out position);
                Vector3.Add(ref position, ref rayDirection, out position);
                cursor.MainWorldTransform.SetPosition(ref position);

                cursor.RecalculateMainTransform();
            }

            CursorController cursorController = objectBase.InternalControllers.CursorController;

            if (cursorController.IsDragging)
            {
                if (cursorController.HitPhysicsObject.Integral.IsStatic && (cursorController.HitPhysicsObject.InternalControllers.HeightmapController != null) && cursorController.HitPhysicsObject.InternalControllers.HeightmapController.Enabled)
                {
                    Vector3 cursorStartPosition = vectorZero;
                    Vector3 cursorEndPosition   = vectorZero;

                    cursorController.GetAnchor1(ref cursorStartPosition);
                    cursorController.GetAnchor2(ref cursorEndPosition);

                    Vector3.Subtract(ref cursorEndPosition, ref cursorStartPosition, out direction);

                    float dir = direction.Y;

                    if (dir != 0.0f)
                    {
                        Vector3 scale = vectorZero;

                        cursorController.HitPhysicsObject.MainWorldTransform.GetScale(ref scale);

                        float positionX = cursorStartPosition.X + 0.5f * scale.X;
                        float positionY = cursorStartPosition.Y + 0.5f * scale.Y;
                        float positionZ = cursorStartPosition.Z + 0.5f * scale.Z;

                        cursorController.HitPhysicsObject.InternalControllers.HeightmapController.AddHeight(positionX, positionY, positionZ, dir / scale.Y);
                        cursorController.HitPhysicsObject.InternalControllers.HeightmapController.UpdateBounding();

                        // To change the friction and restitution of the heightmap surface by the cursor, add the following lines of code

                        //cursorController.HitPhysicsObject.InternalControllers.HeightmapController.SetFriction(positionX, positionY, positionZ, 0.0f);
                        //cursorController.HitPhysicsObject.InternalControllers.HeightmapController.SetRestitution(positionX, positionY, positionZ, 2.0f);

                        cursorStartPosition.Y += dir;
                        cursorController.SetAnchor1(ref cursorStartPosition);
                    }
                }

                if (cursorController.HitPhysicsObject.Integral.IsStatic && (cursorController.HitPhysicsObject.InternalControllers.HeightmapController != null) && cursorController.HitPhysicsObject.InternalControllers.HeightmapController.Enabled)
                {
                    Vector3 cursorStartPosition = vectorZero;
                    Vector3 cursorEndPosition   = vectorZero;

                    cursorController.GetAnchor1(ref cursorStartPosition);
                    cursorController.GetAnchor2(ref cursorEndPosition);

                    Vector3.Subtract(ref cursorEndPosition, ref cursorStartPosition, out direction);

                    if (direction.LengthSquared != 0.0f)
                    {
                        // To move the heightmap surface by the cursor, add the following lines of code

                        //cursorController.HitPhysicsObject.MainWorldTransform.GetPosition(ref cursorStartPosition);

                        //Vector3.Add(ref cursorStartPosition, ref direction, out cursorStartPosition);

                        //cursorController.HitPhysicsObject.MainWorldTransform.SetPosition(ref cursorStartPosition);
                        //cursorController.HitPhysicsObject.RecalculateMainTransform();
                    }
                }

                if (cursorController.HitPhysicsObject.Integral.IsStatic && (cursorController.HitPhysicsObject.InternalControllers.FluidController != null) && cursorController.HitPhysicsObject.InternalControllers.FluidController.Enabled)
                {
                    Vector3 cursorStartPosition = vectorZero;
                    Vector3 cursorEndPosition   = vectorZero;

                    cursorController.GetAnchor1(ref cursorStartPosition);
                    cursorController.GetAnchor2(ref cursorEndPosition);

                    Vector3.Subtract(ref cursorEndPosition, ref cursorStartPosition, out direction);

                    if (direction.LengthSquared != 0.0f)
                    {
                        // To move the fluid surface by the cursor, add the following lines of code
                        // and set EnableCursorInteraction flag to true in the Lake class

                        //cursorController.HitPhysicsObject.MainWorldTransform.GetPosition(ref cursorStartPosition);

                        //Vector3.Add(ref cursorStartPosition, ref direction, out cursorStartPosition);

                        //cursorController.HitPhysicsObject.MainWorldTransform.SetPosition(ref cursorStartPosition);
                        //cursorController.HitPhysicsObject.RecalculateMainTransform();
                    }
                }
            }

            objectBase.MainWorldTransform.GetPosition(ref listenerPosition);
            objectBase.Camera.GetTransposeRotation(ref rotation);

            Vector3.Multiply(ref listenerPosition, soundPositionFactor, out position);
            listenerTopDirection.X   = rotation.Row1.X;
            listenerTopDirection.Y   = rotation.Row1.Y;
            listenerTopDirection.Z   = rotation.Row1.Z;
            listenerFrontDirection.X = rotation.Row2.X;
            listenerFrontDirection.Y = rotation.Row2.Y;
            listenerFrontDirection.Z = rotation.Row2.Z;

            listener.Position       = position;
            listener.TopDirection   = listenerTopDirection;
            listener.FrontDirection = listenerFrontDirection;
            listenerRange           = objectBase.Sound.Range;

            if (enableShot)
            {
                Vector3 shotScale, shotColor;

                shotCount = (shotCount + 1) % shotTab.Length;
                string shotCountName = shotCount.ToString();

                PhysicsObject shot      = scene.Factory.PhysicsObjectManager.FindOrCreate(shotName + shotCountName);
                PhysicsObject shotBase  = scene.Factory.PhysicsObjectManager.FindOrCreate(shotBaseName + shotCountName);
                PhysicsObject shotLight = scene.Factory.PhysicsObjectManager.FindOrCreate(shotLightName + shotCountName);

                shot.AddChildPhysicsObject(shotBase);
                shot.AddChildPhysicsObject(shotLight);

                shotTab[shotCount] = shotBase;
                enableShotTab      = true;

                shotScale = shotColor = vectorZero;

                shotScale.X = shotScale.Y = shotScale.Z = 0.5f;
                Vector3.Multiply(ref rayDirection, 300.0f, out rayDirection);

                shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot.InitLocalTransform.SetPosition(ref rayPosition);
                shot.InitLocalTransform.SetLinearVelocity(ref rayDirection);
                shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot.MaxSimulationFrameCount = 200;
                shot.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;
                //shot.EnableLocalGravity = true;

                shotBase.Shape       = sphere;
                shotBase.UserDataStr = sphereName;
                shotBase.InitLocalTransform.SetScale(ref shotScale);
                shotBase.Integral.SetDensity(10.0f);
                shotBase.Material.RigidGroup   = true;
                shotBase.EnableBreakRigidGroup = false;
                shotBase.EnableCollisions      = true;
                shotBase.CreateSound(true);

                if ((cameraUp != null) && (cameraBody != null) && (cameraDown != null))
                {
                    shotBase.DisableCollision(cameraUp, true);
                    shotBase.DisableCollision(cameraBody, true);
                    shotBase.DisableCollision(cameraDown, true);
                    shotBase.MaxDisableCollisionFrameCount = 50;
                }

                shotLight.Shape       = sphere;
                shotLight.UserDataStr = sphereName;
                shotLight.CreateLight(true);
                shotLight.Light.Type  = PhysicsLightType.Point;
                shotLight.Light.Range = 20.0f;

                shotColor.X = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Y = (float)Math.Max(random.NextDouble(), random.NextDouble());
                shotColor.Z = (float)Math.Max(random.NextDouble(), random.NextDouble());

                shotLight.Light.SetDiffuse(ref shotColor);
                shotLight.InitLocalTransform.SetScale(20.0f);
                shotLight.Material.RigidGroup     = true;
                shotLight.Material.UserDataStr    = yellowName;
                shotLight.EnableBreakRigidGroup   = false;
                shotLight.EnableCollisions        = false;
                shotLight.EnableCursorInteraction = false;
                shotLight.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                scene.UpdateFromInitLocalTransform(shot);

                shotSoundGroup = demo.SoundGroups[hitName];
                shotSoundGroup.MaxHitRepeatTime = 0.0f;

                if (shotSound == null)
                {
                    shotSound = shotSoundGroup.GetSound(objectBase.Sound, listener, emitter);
                }

                shotSound.Update(time);

                Vector3.Multiply(ref rayPosition, soundPositionFactor, out shotSound.HitPosition);
                shotSound.HitVolume = 1.0f;

                shotSound.FrontDirection.X = rotation.Row2.X;
                shotSound.FrontDirection.Y = rotation.Row2.Y;
                shotSound.FrontDirection.Z = rotation.Row2.Z;

                demo.SoundQueue.EnqueueSound(shotSound);
            }
            else
            {
                PhysicsObject shotBase;
                DemoSound     shotBaseSound;

                if (shotSound != null)
                {
                    shotSound.Update(time);

                    if (shotSound.Stop())
                    {
                        shotSound.SoundGroup.SetSound(shotSound);
                        shotSound = null;
                    }
                }

                if (enableShotTab)
                {
                    enableShotTab = false;

                    for (int i = 0; i < shotTab.Length; i++)
                    {
                        shotBase = shotTab[i];

                        if (shotBase != null)
                        {
                            if (shotBase.Sound.UserDataObj != null)
                            {
                                enableShotTab = true;
                                shotBaseSound = (DemoSound)shotBase.Sound.UserDataObj;
                                shotBaseSound.Update(time);

                                if (shotBaseSound.Stop())
                                {
                                    shotBaseSound.SoundGroup.SetSound(shotBaseSound);
                                    shotBase.Sound.UserDataObj = null;
                                    shotTab[i] = null;
                                }
                            }
                        }
                    }
                }
            }

            objectBase.Camera.UpdatePhysicsObjects(true, true, true);
            objectBase.Camera.SortDrawPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortTransparentPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortLightPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);

            PhysicsObject  currentPhysicsObject;
            PhysicsSound   currentSound;
            DemoSoundGroup soundGroup;
            DemoSound      sound;

            if (demo.SoundQueue.SoundCount > 0)
            {
                return;
            }

            for (int i = 0; i < scene.TotalPhysicsObjectCount; i++)
            {
                if (demo.SoundQueue.SoundCount >= demo.SoundQueue.MaxSoundCount)
                {
                    break;
                }

                currentPhysicsObject = scene.GetPhysicsObject(i);

                currentSound = !currentPhysicsObject.EnableSoundFromRigidGroupOwner ? currentPhysicsObject.Sound : currentPhysicsObject.RigidGroupOwner.Sound;

                if (currentSound == null)
                {
                    continue;
                }

                if (!currentSound.Enabled)
                {
                    continue;
                }

                if (currentSound.UserDataStr == null)
                {
                    soundGroup = demo.SoundGroups[defaultName];
                }
                else
                {
                    soundGroup = demo.SoundGroups[currentSound.UserDataStr];
                }

                if (currentPhysicsObject.IsSleeping && (currentSound.UserDataObj == null) && !soundGroup.EnableBackground)
                {
                    continue;
                }

                if (currentPhysicsObject.GetSoundData(ref listenerPosition, listenerRange, soundGroup.EnableHit, soundGroup.EnableRoll, soundGroup.EnableSlide, soundGroup.EnableBackground, currentSound.BackgroundVolumeVelocityModulation, ref hitPosition, ref rollPosition, ref slidePosition, ref backgroundPosition, ref hitVolume, ref rollVolume, ref slideVolume, ref backgroundVolume))
                {
                    if (currentSound.UserDataObj == null)
                    {
                        sound = soundGroup.GetSound(currentSound, listener, emitter);
                        currentSound.UserDataObj = sound;
                    }
                    else
                    {
                        sound = (DemoSound)currentSound.UserDataObj;
                    }

                    sound.Update(time);

                    currentPhysicsObject.MainWorldTransform.GetTransposeRotation(ref rotation);

                    Vector3.Multiply(ref hitPosition, soundPositionFactor, out sound.HitPosition);
                    Vector3.Multiply(ref rollPosition, soundPositionFactor, out sound.RollPosition);
                    Vector3.Multiply(ref slidePosition, soundPositionFactor, out sound.SlidePosition);
                    Vector3.Multiply(ref backgroundPosition, soundPositionFactor, out sound.BackgroundPosition);

                    sound.HitVolume        = hitVolume;
                    sound.RollVolume       = rollVolume;
                    sound.SlideVolume      = slideVolume;
                    sound.BackgroundVolume = backgroundVolume;

                    sound.FrontDirection.X = rotation.Row2.X;
                    sound.FrontDirection.Y = rotation.Row2.Y;
                    sound.FrontDirection.Z = rotation.Row2.Z;

                    demo.SoundQueue.EnqueueSound(sound);
                }
                else
                {
                    if (currentSound.UserDataObj != null)
                    {
                        sound = (DemoSound)currentSound.UserDataObj;
                        sound.Update(time);

                        if (sound.Stop())
                        {
                            soundGroup.SetSound(sound);
                            currentSound.UserDataObj = null;
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        void Move(SimulateMethodArgs args)
        {
            Vector3 cameraPosition;

            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            if (!objectBase.Camera.Enabled)
            {
                return;
            }

            if (!objectBase.Camera.Active)
            {
                objectBase.InitLocalTransform.GetPosition(ref startPosition);
                Vector3.Multiply(ref step, stepCount, out cameraPosition);
                Vector3.Add(ref cameraPosition, ref startPosition, out cameraPosition);

                if (stepCount <= maxStepCount)
                {
                    objectBase.MainWorldTransform.SetPosition(ref cameraPosition);
                    objectBase.RecalculateMainTransform();
                    stepCount++;
                }
                else
                {
                    objectBase.Camera.Active = true;
                }
            }

            float time = (float)args.Time;

            bool enableShot = false;

            DemoMouseState mouseState = demo.GetMouseState();

            if (mouseState[MouseButton.Left] && !oldMouseState[MouseButton.Left])
            {
                enableShot = true;
            }

            mousePosition.X = mouseState.X;
            mousePosition.Y = mouseState.Y;

            oldMouseState = mouseState;

            objectBase.Camera.Projection.CreatePerspectiveLH(1.0f, 11000.0f, 70.0f, demo.WindowWidth, demo.WindowHeight);

            objectBase.MainWorldTransform.GetPosition(ref position);
            objectBase.Camera.GetTransposeRotation(ref cameraRotation);

            objectBase.Camera.View.CreateLookAtLH(ref position, ref cameraRotation, 0.0f);
            objectBase.Camera.UpdateFrustum();

            objectBase.Camera.View.GetViewMatrix(ref view);
            objectBase.Camera.Projection.GetProjectionMatrix(ref projection);

            Vector3 rayPosition, rayDirection;

            rayPosition = rayDirection = vectorZero;

            objectBase.UnProjectToRay(ref mousePosition, 0, 0, demo.WindowWidth, demo.WindowHeight, 0.0f, 1.0f, ref view, ref matrixIdentity, ref projection, ref rayPosition, ref rayDirection);

            PhysicsObject cursor = scene.Factory.PhysicsObjectManager.Find(cursorName);

            if (cursor != null)
            {
                Vector3 cursorPosition      = vectorZero;
                Matrix4 cursorLocalRotation = matrixIdentity;
                Matrix4 cursorWorldRotation = matrixIdentity;

                cursor.InitLocalTransform.GetPosition(ref cursorPosition);
                cursor.InitLocalTransform.GetRotation(ref cursorLocalRotation);
                cursor.MainWorldTransform.GetRotation(ref cursorWorldRotation);

                objectBase.Camera.GetTransposeRotation(ref cameraRotation);
                Matrix4.Mult(ref cursorLocalRotation, ref cameraRotation, out rotation);

                Vector3.TransformVector(ref cursorPosition, ref cursorWorldRotation, out position);

                cursor.MainWorldTransform.SetRotation(ref rotation);
                Vector3.Add(ref position, ref rayPosition, out position);
                Vector3.Add(ref position, ref rayDirection, out position);
                cursor.MainWorldTransform.SetPosition(ref position);
            }

            if (enableShot)
            {
                PhysicsObject shot = scene.Factory.PhysicsObjectManager.Create(shotName + scene.SimulationFrameCount.ToString());

                shot.Shape       = sphere;
                shot.UserDataStr = sphereName;

                Vector3 shotScale = vectorZero;
                shotScale.X = shotScale.Y = shotScale.Z = 0.5f;

                Vector3.Multiply(ref rayDirection, 1000.0f, out rayDirection);

                shot.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot.InitLocalTransform.SetPosition(ref rayPosition);
                shot.InitLocalTransform.SetScale(ref shotScale);

                shot.InitLocalTransform.SetLinearVelocity(ref rayDirection);
                shot.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot.Integral.SetDensity(10.0f);
                shot.MaxSimulationFrameCount = 10;
                shot.EnableCursorInteraction = false;
                shot.EnableCollisionResponse = false;
                shot.EnableDrawing           = false;
                shot.EnableCollisions        = true;
                shot.DisableCollision(objectBase, true);
                shot.MaxDisableCollisionFrameCount = 10;

                scene.UpdateFromInitLocalTransform(shot);
            }

            objectBase.Camera.UpdatePhysicsObjects(true, true, true);
            objectBase.Camera.SortDrawPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
            objectBase.Camera.SortTransparentPhysicsObjects(PhysicsCameraSortOrderType.DrawPriorityShapePrimitiveType);
        }
Esempio n. 17
0
        public void Move(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if ((bodyUp == null) || (bodyDown == null) || (turretBodyUp == null) || (turretBodyDown == null) || (turretGun1 == null) || (turretGun2 == null) || (turretConstraint == null))
            {
                return;
            }

            totalTime += time;

            PhysicsObject turret = turretBodyUp.RigidGroupOwner;

            if (objectBase.IsBrokenRigidGroup || turret.IsBrokenRigidGroup || turretConstraint.IsBroken)
            {
                return;
            }

            Vector3 gravityDirection = vectorZero;
            Vector3 upObjectForce    = vectorZero;
            Vector3 upTurretForce    = vectorZero;
            Vector3 distance         = vectorZero;
            Vector3 direction        = vectorZero;

            scene.GetGravityDirection(ref gravityDirection);

            Vector3.Multiply(ref gravityDirection, -scene.GravityAcceleration * objectBase.Integral.Mass, out upObjectForce);
            Vector3.Multiply(ref gravityDirection, -scene.GravityAcceleration * turret.Integral.Mass, out upTurretForce);

            objectBase.WorldAccumulator.AddWorldForce(ref upObjectForce);
            turret.WorldAccumulator.AddWorldForce(ref upTurretForce);

            PhysicsObject amphibian1Body             = scene.Factory.PhysicsObjectManager.Find(amphibian1BodyName);
            PhysicsObject amphibian1TurretBodyDown   = scene.Factory.PhysicsObjectManager.Find(amphibian1TurretBodyDownName);
            Constraint    amphibian1TurretConstraint = scene.Factory.ConstraintManager.Find(amphibian1TurretConstraintName);
            Vector3       bodyDownPosition           = vectorZero;

            if ((amphibian1Body != null) && (amphibian1TurretBodyDown != null) && (amphibian1TurretConstraint != null) && !amphibian1Body.IsBrokenRigidGroup && !amphibian1TurretConstraint.IsBroken)
            {
                Vector3 amphibianTurretPosition = vectorZero;

                amphibian1TurretBodyDown.RigidGroupOwner.MainWorldTransform.GetPosition(ref amphibianTurretPosition);
                bodyDown.MainWorldTransform.GetPosition(ref bodyDownPosition);

                Vector3.Subtract(ref amphibianTurretPosition, ref bodyDownPosition, out distance);
                Vector3.Normalize(ref distance, out direction);
            }

            Vector3 force = vectorZero;
            Vector3 right = vectorZero;

            Vector3.Cross(ref direction, ref unitY, out right);
            Vector3.Multiply(ref right, 100.0f, out right);

            if (frameCount < 200)
            {
                Vector3.Subtract(ref force, ref right, out force);
            }
            else
            {
                Vector3.Add(ref force, ref right, out force);
            }

            if (frameCount > 400)
            {
                frameCount = 0;
            }

            if (distance.Length > 100.0f)
            {
                Vector3.Multiply(ref direction, 1000.0f, out right);
                Vector3.Add(ref force, ref right, out force);
            }

            if (distance.Y > 0.0f)
            {
                force.Y += distance.Y * 100.0f;
            }

            objectBase.WorldAccumulator.AddWorldForce(ref force);
            turret.WorldAccumulator.AddWorldForce(ref force);

            frameCount++;
            shotFrameCount++;

            Vector3 turretAxis        = vectorZero;
            Vector3 turretDirection   = vectorZero;
            Vector3 turretGunPosition = vectorZero;

            Vector3 turretBodyDownPosition = vectorZero;
            Vector3 turretGun1Position     = vectorZero;
            Vector3 turretGun2Position     = vectorZero;

            turretBodyDown.MainWorldTransform.GetPosition(ref turretBodyDownPosition);
            turretGun1.MainWorldTransform.GetPosition(ref turretGun1Position);
            turretGun2.MainWorldTransform.GetPosition(ref turretGun2Position);

            Vector3.Add(ref turretGun1Position, ref turretGun2Position, out turretGunPosition);
            Vector3.Multiply(ref turretGunPosition, 0.5f, out turretGunPosition);
            Vector3.Subtract(ref turretGunPosition, ref turretBodyDownPosition, out turretDirection);
            turretDirection.Normalize();
            Vector3.Cross(ref turretDirection, ref direction, out turretAxis);

            turretDirection.Y = 0.0f;
            direction.Y       = 0.0f;
            float turretAngle = 0.0f;

            Vector3.Dot(ref turretDirection, ref direction, out turretAngle);
            turretAngle = (float)Math.Acos(turretAngle);
            Vector3.Multiply(ref turretAxis, turretAngle, out turretAxis);

            Vector3 velocity = vectorZero;

            turret.MainWorldTransform.GetAngularVelocity(ref velocity);
            Vector3.Subtract(ref velocity, ref turretAxis, out velocity);
            turret.MainWorldTransform.SetAngularVelocity(ref velocity);

            if ((Math.Abs(turretAngle) < 0.1f) && (distance.Length < 100.0f) && (shotFrameCount > maxShotFrameCount))
            {
                shotFrameCount = 0;

                shotCount = (shotCount + 1) % maxShotCount;
                shot1NameBuilder.Remove(shot1NameLength, shot1NameBuilder.Length - shot1NameLength);
                shot1NameBuilder.Append(shotCount);
                shotInstanceIndexName = shot1NameBuilder.ToString();

                shot1BaseNameBuilder.Remove(shot1BaseNameLength, shot1BaseNameBuilder.Length - shot1BaseNameLength);
                shot1BaseNameBuilder.Append(shotCount);
                shotBaseInstanceIndexName = shot1BaseNameBuilder.ToString();

                shot1LightNameBuilder.Remove(shot1LightNameLength, shot1LightNameBuilder.Length - shot1LightNameLength);
                shot1LightNameBuilder.Append(shotCount);
                shotLightInstanceIndexName = shot1LightNameBuilder.ToString();

                shot1      = scene.Factory.PhysicsObjectManager.FindOrCreate(shotInstanceIndexName);
                shot1Base  = scene.Factory.PhysicsObjectManager.FindOrCreate(shotBaseInstanceIndexName);
                shot1Light = scene.Factory.PhysicsObjectManager.FindOrCreate(shotLightInstanceIndexName);

                shot1.AddChildPhysicsObject(shot1Base);
                shot1.AddChildPhysicsObject(shot1Light);

                Matrix4 turretGun1Rotation = matrixIdentity;
                Vector3 shot1Position      = vectorZero;
                Vector3 shot1LocalPosition = vectorZero;

                turretGun1.MainWorldTransform.GetRotation(ref turretGun1Rotation);

                shot1LocalPosition.X = 0.0f;
                shot1LocalPosition.Y = 2.0f;
                shot1LocalPosition.Z = 0.0f;

                Vector3.TransformVector(ref shot1LocalPosition, ref turretGun1Rotation, out shot1Position);
                Vector3.Add(ref shot1Position, ref turretGun1Position, out shot1Position);
                Vector3 shot1Direction = vectorZero;
                Vector3 shot1Scale     = vectorZero;

                shot1Direction.X = turretGun1Rotation.Row1.X;
                shot1Direction.Y = turretGun1Rotation.Row1.Y;
                shot1Direction.Z = turretGun1Rotation.Row1.Z;

                shot1Scale.X = shot1Scale.Y = shot1Scale.Z = 0.5f;

                shot1.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot1.InitLocalTransform.SetPosition(ref shot1Position);

                Vector3.Multiply(ref shot1Direction, 200.0f, out shot1Direction);

                shot1.InitLocalTransform.SetLinearVelocity(ref shot1Direction);
                shot1.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot1.MaxSimulationFrameCount = maxShotSimulationFrameCount;
                shot1.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;

                shot1Base.Shape               = sphere;
                shot1Base.UserDataStr         = sphereName;
                shot1Base.Material.RigidGroup = true;
                shot1Base.InitLocalTransform.SetScale(ref shot1Scale);
                shot1Base.Integral.SetDensity(1.0f);
                shot1Base.EnableCollisions = true;
                shot1Base.DisableCollision(turretGun1, true);
                shot1Base.MaxDisableCollisionFrameCount = 10;
                shot1Base.EnableBreakRigidGroup         = false;
                shot1Base.CreateSound(true);

                shot1Light.Shape       = sphere;
                shot1Light.UserDataStr = sphereName;
                shot1Light.CreateLight(true);
                shot1Light.Light.Type  = PhysicsLightType.Point;
                shot1Light.Light.Range = 20.0f;
                shot1Light.Light.SetDiffuse(1.0f, 0.7f, 0.0f);
                shot1Light.InitLocalTransform.SetScale(20.0f);
                shot1Light.Material.RigidGroup     = true;
                shot1Light.Material.UserDataStr    = yellowName;
                shot1Light.EnableBreakRigidGroup   = false;
                shot1Light.EnableCollisions        = false;
                shot1Light.EnableCursorInteraction = false;
                shot1Light.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                scene.UpdateFromInitLocalTransform(shot1);

                shot2NameBuilder.Remove(shot2NameLength, shot2NameBuilder.Length - shot2NameLength);
                shot2NameBuilder.Append(shotCount);
                shotInstanceIndexName = shot2NameBuilder.ToString();

                shot2BaseNameBuilder.Remove(shot2BaseNameLength, shot2BaseNameBuilder.Length - shot2BaseNameLength);
                shot2BaseNameBuilder.Append(shotCount);
                shotBaseInstanceIndexName = shot2BaseNameBuilder.ToString();

                shot2LightNameBuilder.Remove(shot2LightNameLength, shot2LightNameBuilder.Length - shot2LightNameLength);
                shot2LightNameBuilder.Append(shotCount);
                shotLightInstanceIndexName = shot2LightNameBuilder.ToString();

                shot2      = scene.Factory.PhysicsObjectManager.FindOrCreate(shotInstanceIndexName);
                shot2Base  = scene.Factory.PhysicsObjectManager.FindOrCreate(shotBaseInstanceIndexName);
                shot2Light = scene.Factory.PhysicsObjectManager.FindOrCreate(shotLightInstanceIndexName);

                shot2.AddChildPhysicsObject(shot2Base);
                shot2.AddChildPhysicsObject(shot2Light);

                Matrix4 turretGun2Rotation = matrixIdentity;
                Vector3 shot2Position      = vectorZero;
                Vector3 shot2LocalPosition = vectorZero;

                turretGun2.MainWorldTransform.GetRotation(ref turretGun2Rotation);

                shot2LocalPosition.X = 0.0f;
                shot2LocalPosition.Y = 2.0f;
                shot2LocalPosition.Z = 0.0f;

                Vector3.TransformVector(ref shot2LocalPosition, ref turretGun2Rotation, out shot2Position);
                Vector3.Add(ref shot2Position, ref turretGun1Position, out shot2Position);
                Vector3 shot2Direction = vectorZero;
                Vector3 shot2Scale     = vectorZero;

                shot2Direction.X = turretGun2Rotation.Row1.X;
                shot2Direction.Y = turretGun2Rotation.Row1.Y;
                shot2Direction.Z = turretGun2Rotation.Row1.Z;

                shot2Scale.X = shot2Scale.Y = shot2Scale.Z = 0.5f;

                shot2.InitLocalTransform.SetRotation(ref matrixIdentity);
                shot2.InitLocalTransform.SetPosition(ref shot2Position);

                Vector3.Multiply(ref shot2Direction, 200.0f, out shot2Direction);

                shot2.InitLocalTransform.SetLinearVelocity(ref shot2Direction);
                shot2.InitLocalTransform.SetAngularVelocity(ref vectorZero);
                shot2.MaxSimulationFrameCount = maxShotSimulationFrameCount;
                shot2.EnableRemovePhysicsObjectsFromManagerAfterMaxSimulationFrameCount = false;

                shot2Base.Shape               = sphere;
                shot2Base.UserDataStr         = sphereName;
                shot2Base.Material.RigidGroup = true;
                shot2Base.InitLocalTransform.SetScale(ref shot2Scale);
                shot2Base.Integral.SetDensity(10.0f);
                shot2Base.EnableCollisions = true;
                shot2Base.DisableCollision(turretGun2, true);
                shot2Base.MaxDisableCollisionFrameCount = 10;
                shot2Base.EnableBreakRigidGroup         = false;
                shot2Base.CreateSound(true);

                shot2Light.Shape       = sphere;
                shot2Light.UserDataStr = sphereName;
                shot2Light.CreateLight(true);
                shot2Light.Light.Type  = PhysicsLightType.Point;
                shot2Light.Light.Range = 20.0f;
                shot2Light.Light.SetDiffuse(1.0f, 0.7f, 0.0f);
                shot2Light.InitLocalTransform.SetScale(20.0f);
                shot2Light.Material.RigidGroup     = true;
                shot2Light.Material.UserDataStr    = yellowName;
                shot2Light.EnableBreakRigidGroup   = false;
                shot2Light.EnableCollisions        = false;
                shot2Light.EnableCursorInteraction = false;
                shot2Light.EnableAddToCameraDrawTransparentPhysicsObjects = false;

                scene.UpdateFromInitLocalTransform(shot2);
            }

            Vector3 bodyUpPosition = vectorZero;
            Vector3 upDirection    = vectorZero;

            bodyDown.MainWorldTransform.GetPosition(ref bodyDownPosition);
            bodyUp.MainWorldTransform.GetPosition(ref bodyUpPosition);

            Vector3.Subtract(ref bodyDownPosition, ref bodyUpPosition, out upDirection);
            upDirection.Normalize();

            float   bodyAngle = 0.0f;
            Vector3 axis      = vectorZero;

            Vector3.Dot(ref upDirection, ref gravityDirection, out bodyAngle);
            bodyAngle = (float)Math.Acos(bodyAngle);

            if (Math.Abs(bodyAngle) > 0.005f)
            {
                bodyAngle *= 0.005f / Math.Abs(bodyAngle);
            }

            Vector3.Cross(ref gravityDirection, ref upDirection, out axis);

            objectBase.MainWorldTransform.GetAngularVelocity(ref velocity);
            Vector3.Multiply(ref velocity, 0.98f, out velocity);
            Vector3.Multiply(ref axis, bodyAngle * 400.0f, out axis);
            Vector3.Add(ref velocity, ref axis, out velocity);
            objectBase.MainWorldTransform.SetAngularVelocity(ref velocity);

            Vector3 turretBodyUpPosition = vectorZero;

            turretBodyUp.MainWorldTransform.GetPosition(ref turretBodyUpPosition);

            Vector3.Subtract(ref turretBodyDownPosition, ref turretBodyUpPosition, out upDirection);
            upDirection.Normalize();

            Vector3.Dot(ref upDirection, ref gravityDirection, out bodyAngle);
            bodyAngle = (float)Math.Acos(bodyAngle);

            if (Math.Abs(bodyAngle) > 0.005f)
            {
                bodyAngle *= 0.005f / Math.Abs(bodyAngle);
            }

            Vector3.Cross(ref gravityDirection, ref upDirection, out axis);

            turret.MainWorldTransform.GetAngularVelocity(ref velocity);
            Vector3.Multiply(ref velocity, 0.98f, out velocity);
            Vector3.Multiply(ref axis, bodyAngle * 400.0f, out axis);
            Vector3.Add(ref velocity, ref axis, out velocity);
            turret.MainWorldTransform.SetAngularVelocity(ref velocity);
        }
Esempio n. 18
0
        void Fly(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if (!enableFly)
            {
                return;
            }

            totalStartTime += time;

            bool  rotorUpWorking   = true;
            bool  rotorBackWorking = true;
            float rotorSpeedFactor = 0.0f;

            if (totalStartTime > maxStartTime)
            {
                totalFlyTime    += time;
                rotorSpeedFactor = 1.2f;
            }
            else
            {
                totalFlyTime     = 0.0f;
                rotorSpeedFactor = 0.6f;
            }

            if (totalFlyTime >= maxFlyTime)
            {
                totalStartTime = 0.0f;
                enableFly      = false;

                if (cabinFrontButtonConstraint != null)
                {
                    cabinFrontButtonConstraint.ControlDistanceX = 0.0f;
                }
            }

            if (upRotorConstraint != null)
            {
                if (upRotorConstraint.PhysicsObject1 != null)
                {
                    if (upRotorConstraint.PhysicsObject1.IsBrokenRigidGroup || upRotorConstraint.IsBroken || (totalFlyTime >= maxFlyTime))
                    {
                        rotorUpWorking = false;
                    }
                }

                if (upRotorConstraint.PhysicsObject2 != null)
                {
                    if (upRotorConstraint.PhysicsObject2.IsBrokenRigidGroup || upRotorConstraint.IsBroken || (totalFlyTime >= maxFlyTime))
                    {
                        rotorUpWorking = false;
                    }
                }
            }
            else
            {
                rotorUpWorking = false;
            }

            if (backRotorConstraint != null)
            {
                if (rotorUpWorking)
                {
                    if (backRotorConstraint.PhysicsObject1 != null)
                    {
                        if (backRotorConstraint.PhysicsObject1.IsBrokenRigidGroup || backRotorConstraint.IsBroken)
                        {
                            rotorBackWorking = false;
                        }
                    }

                    if (backRotorConstraint.PhysicsObject2 != null)
                    {
                        if (backRotorConstraint.PhysicsObject2.IsBrokenRigidGroup || backRotorConstraint.IsBroken)
                        {
                            rotorBackWorking = false;
                        }
                    }
                }
                else
                {
                    rotorBackWorking = false;
                }
            }
            else
            {
                rotorBackWorking = false;
            }

            float   rotorUpAngularVelocity   = 0.0f;
            float   rotorBackAngularVelocity = 0.0f;
            Vector3 velocity = vectorZero;

            if ((upRotor != null) && (totalFlyTime < maxFlyTime) && rotorUpWorking)
            {
                Vector3.Multiply(ref unitY, -rotorSpeedFactor * maxRotorUpAngularVelocity, out velocity);
                upRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);
                rotorUpAngularVelocity = velocity.Length;
            }

            if ((backRotor != null) && (totalFlyTime < maxFlyTime) && rotorBackWorking)
            {
                Vector3.Multiply(ref unitZ, rotorSpeedFactor * maxRotorBackAngularVelocity, out velocity);
                backRotor.MainWorldTransform.SetLocalAngularVelocity(ref velocity);
                rotorBackAngularVelocity = velocity.Length;
            }

            Vector3 gravityDirection = vectorZero;

            scene.GetGravityDirection(ref gravityDirection);

            if (rotorUpWorking)
            {
                if ((rotorUpAngularVelocity > maxRotorUpAngularVelocity))
                {
                    float upFactor = 1.0f;
                    if (!rotorBackWorking)
                    {
                        upFactor = 0.5f;
                    }

                    Vector3.Multiply(ref gravityDirection, -maxRotorUpFlyForce * scene.GravityAcceleration * upFactor, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
            }

            if (rotorBackWorking && rotorUpWorking)
            {
                if (rotorUpAngularVelocity > maxRotorUpAngularVelocity)
                {
                    Vector3.Multiply(ref unitY, maxRotorBackFlyCompensationForce, out force);

                    objectBase.WorldAccumulator.AddLocalTorque(ref force);
                }
                else
                {
                    Vector3.Multiply(ref unitY, maxRotorBackStartCompensationForce, out force);

                    objectBase.WorldAccumulator.AddLocalTorque(ref force);
                }
            }

            if ((rotorUpAngularVelocity > maxRotorUpAngularVelocity) && (rotorBackAngularVelocity > maxRotorBackAngularVelocity))
            {
                Vector3 deltaVelocity = vectorZero;
                Vector3 moveDirection = vectorZero;
                Vector3 position      = vectorZero;

                objectBase.MainWorldTransform.GetPosition(ref position);

                if (totalFlyTime < maxFlyTime * 0.2f)
                {
                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref flyPosition1, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
                else
                if (totalFlyTime < maxFlyTime * 0.4f)
                {
                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref flyPosition2, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
                else
                if (totalFlyTime < maxFlyTime * 0.6f)
                {
                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref flyPosition3, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
                else
                if (totalFlyTime < maxFlyTime * 0.8f)
                {
                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref flyPosition4, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
                else
                if (totalFlyTime < maxFlyTime * 0.95f)
                {
                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref endFlyPosition, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }
                else
                if (totalFlyTime < maxFlyTime)
                {
                    objectBase.WorldAccumulator.GetTotalWorldForce(ref force);
                    Vector3.Multiply(ref force, 0.9f, out force);
                    objectBase.WorldAccumulator.SetTotalWorldForce(ref force);

                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, maxMoveDirectionDamping, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);

                    Vector3.Subtract(ref landingPosition, ref position, out moveDirection);
                    moveDirection.Normalize();
                    Vector3.Multiply(ref moveDirection, objectBase.Integral.Mass, out force);

                    objectBase.WorldAccumulator.AddWorldForce(ref force);
                }

                if ((upRotorBody != null) && (upBody2 != null) && (tail4 != null) && (tail3 != null) && (totalFlyTime < maxFlyTime))
                {
                    Vector3 axis              = vectorZero;
                    Vector3 forwardDirection  = vectorZero;
                    Vector3 tailStartPosition = vectorZero;
                    Vector3 tailEndPosition   = vectorZero;

                    tail4.MainWorldTransform.GetPosition(ref tailStartPosition);
                    tail3.MainWorldTransform.GetPosition(ref tailEndPosition);

                    Vector3.Subtract(ref tailEndPosition, ref tailStartPosition, out forwardDirection);
                    forwardDirection.Normalize();

                    float bodyAngle = 0.0f;

                    Vector3.Dot(ref forwardDirection, ref moveDirection, out bodyAngle);
                    bodyAngle = (float)Math.Acos(bodyAngle);
                    Vector3.Cross(ref moveDirection, ref forwardDirection, out axis);

                    objectBase.MainWorldTransform.GetAngularVelocity(ref velocity);
                    Vector3.Multiply(ref velocity, 0.5f, out velocity);
                    Vector3.Multiply(ref axis, bodyAngle * (float)time, out axis);
                    Vector3.Add(ref velocity, ref axis, out velocity);
                    objectBase.MainWorldTransform.SetAngularVelocity(ref velocity);

                    Vector3 upDirection = vectorZero;

                    Vector3 upBodyStartPosition = vectorZero;
                    Vector3 upBodyEndPosition   = vectorZero;

                    upRotorBody.MainWorldTransform.GetPosition(ref upBodyStartPosition);
                    upBody2.MainWorldTransform.GetPosition(ref upBodyEndPosition);

                    Vector3.Subtract(ref upBodyEndPosition, ref upBodyStartPosition, out upDirection);
                    upDirection.Normalize();

                    Vector3.Dot(ref upDirection, ref gravityDirection, out bodyAngle);
                    bodyAngle = (float)Math.Acos(bodyAngle);
                    Vector3.Cross(ref gravityDirection, ref upDirection, out axis);

                    objectBase.MainWorldTransform.GetAngularVelocity(ref velocity);
                    Vector3.Multiply(ref axis, bodyAngle * (float)time, out axis);
                    Vector3.Add(ref velocity, ref axis, out velocity);
                    objectBase.MainWorldTransform.SetAngularVelocity(ref velocity);
                }

                objectBase.MainWorldTransform.GetPosition(ref position);

                if (position.Y > maxFlyHeight)
                {
                    float distance = position.Y - maxFlyHeight;

                    Vector3.Multiply(ref gravityDirection, distance * maxHeightDamping, out deltaVelocity);

                    objectBase.MainWorldTransform.GetLinearVelocity(ref velocity);
                    Vector3.Add(ref velocity, ref deltaVelocity, out velocity);
                    objectBase.MainWorldTransform.SetLinearVelocity(ref velocity);
                }
            }
        }
Esempio n. 19
0
        void GoUp(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;
            bool  move = false;

            if (Math.Abs(rightLimbFront1Constraint.ControlDegAngleY - maxUpFrontAngleY) > Math.Abs(rightFront1AngleYStep))
            {
                move = true;
                if (rightLimbFront1Constraint.ControlDegAngleY < maxUpFrontAngleY)
                {
                    rightLimbFront1Constraint.ControlDegAngleY += rightFront1AngleYStep;
                }
                else
                if (rightLimbFront1Constraint.ControlDegAngleY > maxUpFrontAngleY)
                {
                    rightLimbFront1Constraint.ControlDegAngleY -= rightFront1AngleYStep;
                }
            }

            if (Math.Abs(rightLimbMiddleFront1Constraint.ControlDegAngleY - maxUpMiddleFrontAngleY) > Math.Abs(rightMiddleFront1AngleYStep))
            {
                move = true;
                if (rightLimbMiddleFront1Constraint.ControlDegAngleY < maxUpMiddleFrontAngleY)
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleY += rightMiddleFront1AngleYStep;
                }
                else
                if (rightLimbMiddleFront1Constraint.ControlDegAngleY > maxUpMiddleFrontAngleY)
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleY -= rightMiddleFront1AngleYStep;
                }
            }

            if (Math.Abs(rightLimbMiddleBack1Constraint.ControlDegAngleY - maxUpMiddleBackAngleY) > Math.Abs(rightMiddleBack1AngleYStep))
            {
                move = true;
                if (rightLimbMiddleBack1Constraint.ControlDegAngleY < maxUpMiddleBackAngleY)
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleY += rightMiddleBack1AngleYStep;
                }
                else
                if (rightLimbMiddleBack1Constraint.ControlDegAngleY > maxUpMiddleBackAngleY)
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleY -= rightMiddleBack1AngleYStep;
                }
            }

            if (Math.Abs(rightLimbBack1Constraint.ControlDegAngleY - maxUpBackAngleY) > Math.Abs(rightMiddleBack1AngleYStep))
            {
                move = true;
                if (rightLimbBack1Constraint.ControlDegAngleY < maxUpBackAngleY)
                {
                    rightLimbBack1Constraint.ControlDegAngleY += rightBack1AngleYStep;
                }
                else
                if (rightLimbBack1Constraint.ControlDegAngleY > maxUpBackAngleY)
                {
                    rightLimbBack1Constraint.ControlDegAngleY -= rightBack1AngleYStep;
                }
            }



            if (Math.Abs(leftLimbFront1Constraint.ControlDegAngleY + maxUpFrontAngleY) > Math.Abs(leftFront1AngleYStep))
            {
                move = true;
                if (leftLimbFront1Constraint.ControlDegAngleY > -maxUpFrontAngleY)
                {
                    leftLimbFront1Constraint.ControlDegAngleY += leftFront1AngleYStep;
                }
                else
                if (leftLimbFront1Constraint.ControlDegAngleY < -maxUpFrontAngleY)
                {
                    leftLimbFront1Constraint.ControlDegAngleY -= leftFront1AngleYStep;
                }
            }

            if (Math.Abs(leftLimbMiddleFront1Constraint.ControlDegAngleY + maxUpMiddleFrontAngleY) > Math.Abs(leftMiddleFront1AngleYStep))
            {
                move = true;
                if (leftLimbMiddleFront1Constraint.ControlDegAngleY > -maxUpMiddleFrontAngleY)
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleY += leftMiddleFront1AngleYStep;
                }
                else
                if (leftLimbMiddleFront1Constraint.ControlDegAngleY < -maxUpMiddleFrontAngleY)
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleY -= leftMiddleFront1AngleYStep;
                }
            }

            if (Math.Abs(leftLimbMiddleBack1Constraint.ControlDegAngleY + maxUpMiddleBackAngleY) > Math.Abs(leftMiddleBack1AngleYStep))
            {
                move = true;
                if (leftLimbMiddleBack1Constraint.ControlDegAngleY > -maxUpMiddleBackAngleY)
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleY += leftMiddleBack1AngleYStep;
                }
                else
                if (leftLimbMiddleBack1Constraint.ControlDegAngleY < -maxUpMiddleBackAngleY)
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleY -= leftMiddleBack1AngleYStep;
                }
            }

            if (Math.Abs(leftLimbBack1Constraint.ControlDegAngleY + maxUpBackAngleY) > Math.Abs(leftBack1AngleYStep))
            {
                move = true;
                if (leftLimbBack1Constraint.ControlDegAngleY > -maxUpBackAngleY)
                {
                    leftLimbBack1Constraint.ControlDegAngleY += leftBack1AngleYStep;
                }
                else
                if (leftLimbBack1Constraint.ControlDegAngleY < -maxUpBackAngleY)
                {
                    leftLimbBack1Constraint.ControlDegAngleY -= leftBack1AngleYStep;
                }
            }



            if (Math.Abs(rightLimbFront1Constraint.ControlDegAngleX - maxUp1AngleX) > Math.Abs(rightFront1AngleXStep))
            {
                move = true;
                if (rightLimbFront1Constraint.ControlDegAngleX < maxUp1AngleX)
                {
                    rightLimbFront1Constraint.ControlDegAngleX += rightFront1AngleXStep;
                }
                else
                if (rightLimbFront1Constraint.ControlDegAngleX > maxUp1AngleX)
                {
                    rightLimbFront1Constraint.ControlDegAngleX -= rightFront1AngleXStep;
                }
            }

            if (Math.Abs(rightLimbFront2Constraint.ControlDegAngleX - maxUp2AngleX) > Math.Abs(rightFront2AngleXStep))
            {
                move = true;
                if (rightLimbFront2Constraint.ControlDegAngleX < maxUp2AngleX)
                {
                    rightLimbFront2Constraint.ControlDegAngleX += rightFront2AngleXStep;
                }
                else
                if (rightLimbFront2Constraint.ControlDegAngleX > maxUp2AngleX)
                {
                    rightLimbFront2Constraint.ControlDegAngleX -= rightFront2AngleXStep;
                }
            }

            if (Math.Abs(rightLimbFront3Constraint.ControlDegAngleX - maxUp3AngleX) > Math.Abs(rightFront3AngleXStep))
            {
                move = true;
                if (rightLimbFront3Constraint.ControlDegAngleX < maxUp3AngleX)
                {
                    rightLimbFront3Constraint.ControlDegAngleX += rightFront3AngleXStep;
                }
                else
                if (rightLimbFront3Constraint.ControlDegAngleX > maxUp3AngleX)
                {
                    rightLimbFront3Constraint.ControlDegAngleX -= rightFront3AngleXStep;
                }
            }



            if (Math.Abs(rightLimbMiddleFront1Constraint.ControlDegAngleX - maxUp1AngleX) > Math.Abs(rightMiddleFront1AngleXStep))
            {
                move = true;
                if (rightLimbMiddleFront1Constraint.ControlDegAngleX < maxUp1AngleX)
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleX += rightMiddleFront1AngleXStep;
                }
                else
                if (rightLimbMiddleFront1Constraint.ControlDegAngleX > maxUp1AngleX)
                {
                    rightLimbMiddleFront1Constraint.ControlDegAngleX -= rightMiddleFront1AngleXStep;
                }
            }

            if (Math.Abs(rightLimbMiddleFront2Constraint.ControlDegAngleX - maxUp2AngleX) > Math.Abs(rightMiddleFront2AngleXStep))
            {
                move = true;
                if (rightLimbMiddleFront2Constraint.ControlDegAngleX < maxUp2AngleX)
                {
                    rightLimbMiddleFront2Constraint.ControlDegAngleX += rightMiddleFront2AngleXStep;
                }
                else
                if (rightLimbMiddleFront2Constraint.ControlDegAngleX > maxUp2AngleX)
                {
                    rightLimbMiddleFront2Constraint.ControlDegAngleX -= rightMiddleFront2AngleXStep;
                }
            }

            if (Math.Abs(rightLimbMiddleFront3Constraint.ControlDegAngleX - maxUp3AngleX) > Math.Abs(rightMiddleFront3AngleXStep))
            {
                move = true;
                if (rightLimbMiddleFront3Constraint.ControlDegAngleX < maxUp3AngleX)
                {
                    rightLimbMiddleFront3Constraint.ControlDegAngleX += rightMiddleFront3AngleXStep;
                }
                else
                if (rightLimbMiddleFront3Constraint.ControlDegAngleX > maxUp3AngleX)
                {
                    rightLimbMiddleFront3Constraint.ControlDegAngleX -= rightMiddleFront3AngleXStep;
                }
            }



            if (Math.Abs(rightLimbMiddleBack1Constraint.ControlDegAngleX - maxUp1AngleX) > Math.Abs(rightMiddleBack1AngleXStep))
            {
                move = true;
                if (rightLimbMiddleBack1Constraint.ControlDegAngleX < maxUp1AngleX)
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleX += rightMiddleBack1AngleXStep;
                }
                else
                if (rightLimbMiddleBack1Constraint.ControlDegAngleX > maxUp1AngleX)
                {
                    rightLimbMiddleBack1Constraint.ControlDegAngleX -= rightMiddleBack1AngleXStep;
                }
            }

            if (Math.Abs(rightLimbMiddleBack2Constraint.ControlDegAngleX - maxUp2AngleX) > Math.Abs(rightMiddleBack2AngleXStep))
            {
                move = true;
                if (rightLimbMiddleBack2Constraint.ControlDegAngleX < maxUp2AngleX)
                {
                    rightLimbMiddleBack2Constraint.ControlDegAngleX += rightMiddleBack2AngleXStep;
                }
                else
                if (rightLimbMiddleBack2Constraint.ControlDegAngleX > maxUp2AngleX)
                {
                    rightLimbMiddleBack2Constraint.ControlDegAngleX -= rightMiddleBack2AngleXStep;
                }
            }

            if (Math.Abs(rightLimbMiddleBack3Constraint.ControlDegAngleX - maxUp3AngleX) > Math.Abs(rightMiddleBack3AngleXStep))
            {
                move = true;
                if (rightLimbMiddleBack3Constraint.ControlDegAngleX < maxUp3AngleX)
                {
                    rightLimbMiddleBack3Constraint.ControlDegAngleX += rightMiddleBack3AngleXStep;
                }
                else
                if (rightLimbMiddleBack3Constraint.ControlDegAngleX > maxUp3AngleX)
                {
                    rightLimbMiddleBack3Constraint.ControlDegAngleX -= rightMiddleBack3AngleXStep;
                }
            }



            if (Math.Abs(rightLimbBack1Constraint.ControlDegAngleX - maxUp1AngleX) > Math.Abs(rightBack1AngleXStep))
            {
                move = true;
                if (rightLimbBack1Constraint.ControlDegAngleX < maxUp1AngleX)
                {
                    rightLimbBack1Constraint.ControlDegAngleX += rightBack1AngleXStep;
                }
                else
                if (rightLimbBack1Constraint.ControlDegAngleX > maxUp1AngleX)
                {
                    rightLimbBack1Constraint.ControlDegAngleX -= rightBack1AngleXStep;
                }
            }

            if (Math.Abs(rightLimbBack2Constraint.ControlDegAngleX - maxUp2AngleX) > Math.Abs(rightBack2AngleXStep))
            {
                move = true;
                if (rightLimbBack2Constraint.ControlDegAngleX < maxUp2AngleX)
                {
                    rightLimbBack2Constraint.ControlDegAngleX += rightBack2AngleXStep;
                }
                else
                if (rightLimbBack2Constraint.ControlDegAngleX > maxUp2AngleX)
                {
                    rightLimbBack2Constraint.ControlDegAngleX -= rightBack2AngleXStep;
                }
            }

            if (Math.Abs(rightLimbBack3Constraint.ControlDegAngleX - maxUp3AngleX) > Math.Abs(rightBack3AngleXStep))
            {
                move = true;
                if (rightLimbBack3Constraint.ControlDegAngleX < maxUp3AngleX)
                {
                    rightLimbBack3Constraint.ControlDegAngleX += rightBack3AngleXStep;
                }
                else
                if (rightLimbBack3Constraint.ControlDegAngleX > maxUp3AngleX)
                {
                    rightLimbBack3Constraint.ControlDegAngleX -= rightBack3AngleXStep;
                }
            }



            if (Math.Abs(leftLimbFront1Constraint.ControlDegAngleX + maxUp1AngleX) > Math.Abs(leftFront1AngleXStep))
            {
                move = true;
                if (leftLimbFront1Constraint.ControlDegAngleX > -maxUp1AngleX)
                {
                    leftLimbFront1Constraint.ControlDegAngleX += leftFront1AngleXStep;
                }
                else
                if (leftLimbFront1Constraint.ControlDegAngleX < -maxUp1AngleX)
                {
                    leftLimbFront1Constraint.ControlDegAngleX -= leftFront1AngleXStep;
                }
            }

            if (Math.Abs(leftLimbFront2Constraint.ControlDegAngleX + maxUp2AngleX) > Math.Abs(leftFront2AngleXStep))
            {
                move = true;
                if (leftLimbFront2Constraint.ControlDegAngleX > -maxUp2AngleX)
                {
                    leftLimbFront2Constraint.ControlDegAngleX += leftFront2AngleXStep;
                }
                else
                if (leftLimbFront2Constraint.ControlDegAngleX < -maxUp2AngleX)
                {
                    leftLimbFront2Constraint.ControlDegAngleX -= leftFront2AngleXStep;
                }
            }

            if (Math.Abs(leftLimbFront3Constraint.ControlDegAngleX + maxUp3AngleX) > Math.Abs(leftFront3AngleXStep))
            {
                move = true;
                if (leftLimbFront3Constraint.ControlDegAngleX > -maxUp3AngleX)
                {
                    leftLimbFront3Constraint.ControlDegAngleX += leftFront3AngleXStep;
                }
                else
                if (leftLimbFront3Constraint.ControlDegAngleX < -maxUp3AngleX)
                {
                    leftLimbFront3Constraint.ControlDegAngleX -= leftFront3AngleXStep;
                }
            }



            if (Math.Abs(leftLimbMiddleFront1Constraint.ControlDegAngleX + maxUp1AngleX) > Math.Abs(leftMiddleFront1AngleXStep))
            {
                move = true;
                if (leftLimbMiddleFront1Constraint.ControlDegAngleX > -maxUp1AngleX)
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleX += leftMiddleFront1AngleXStep;
                }
                else
                if (leftLimbMiddleFront1Constraint.ControlDegAngleX < -maxUp1AngleX)
                {
                    leftLimbMiddleFront1Constraint.ControlDegAngleX -= leftMiddleFront1AngleXStep;
                }
            }

            if (Math.Abs(leftLimbMiddleFront2Constraint.ControlDegAngleX + maxUp2AngleX) > Math.Abs(leftMiddleFront2AngleXStep))
            {
                move = true;
                if (leftLimbMiddleFront2Constraint.ControlDegAngleX > -maxUp2AngleX)
                {
                    leftLimbMiddleFront2Constraint.ControlDegAngleX += leftMiddleFront2AngleXStep;
                }
                else
                if (leftLimbMiddleFront2Constraint.ControlDegAngleX < -maxUp2AngleX)
                {
                    leftLimbMiddleFront2Constraint.ControlDegAngleX -= leftMiddleFront2AngleXStep;
                }
            }

            if (Math.Abs(leftLimbMiddleFront3Constraint.ControlDegAngleX + maxUp3AngleX) > Math.Abs(leftMiddleFront3AngleXStep))
            {
                move = true;
                if (leftLimbMiddleFront3Constraint.ControlDegAngleX > -maxUp3AngleX)
                {
                    leftLimbMiddleFront3Constraint.ControlDegAngleX += leftMiddleFront3AngleXStep;
                }
                else
                if (leftLimbMiddleFront3Constraint.ControlDegAngleX < -maxUp3AngleX)
                {
                    leftLimbMiddleFront3Constraint.ControlDegAngleX -= leftMiddleFront3AngleXStep;
                }
            }



            if (Math.Abs(leftLimbMiddleBack1Constraint.ControlDegAngleX + maxUp1AngleX) > Math.Abs(leftMiddleBack1AngleXStep))
            {
                move = true;
                if (leftLimbMiddleBack1Constraint.ControlDegAngleX > -maxUp1AngleX)
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleX += leftMiddleBack1AngleXStep;
                }
                else
                if (leftLimbMiddleBack1Constraint.ControlDegAngleX < -maxUp1AngleX)
                {
                    leftLimbMiddleBack1Constraint.ControlDegAngleX -= leftMiddleBack1AngleXStep;
                }
            }

            if (Math.Abs(leftLimbMiddleBack2Constraint.ControlDegAngleX + maxUp2AngleX) > Math.Abs(leftMiddleBack2AngleXStep))
            {
                move = true;
                if (leftLimbMiddleBack2Constraint.ControlDegAngleX > -maxUp2AngleX)
                {
                    leftLimbMiddleBack2Constraint.ControlDegAngleX += leftMiddleBack2AngleXStep;
                }
                else
                if (leftLimbMiddleBack2Constraint.ControlDegAngleX < -maxUp2AngleX)
                {
                    leftLimbMiddleBack2Constraint.ControlDegAngleX -= leftMiddleBack2AngleXStep;
                }
            }

            if (Math.Abs(leftLimbMiddleBack3Constraint.ControlDegAngleX + maxUp3AngleX) > Math.Abs(leftMiddleBack3AngleXStep))
            {
                move = true;
                if (leftLimbMiddleBack3Constraint.ControlDegAngleX > -maxUp3AngleX)
                {
                    leftLimbMiddleBack3Constraint.ControlDegAngleX += leftMiddleBack3AngleXStep;
                }
                else
                if (leftLimbMiddleBack3Constraint.ControlDegAngleX < -maxUp3AngleX)
                {
                    leftLimbMiddleBack3Constraint.ControlDegAngleX -= leftMiddleBack3AngleXStep;
                }
            }


            if (Math.Abs(leftLimbBack1Constraint.ControlDegAngleX + maxUp1AngleX) > Math.Abs(leftBack1AngleXStep))
            {
                move = true;
                if (leftLimbBack1Constraint.ControlDegAngleX > -maxUp1AngleX)
                {
                    leftLimbBack1Constraint.ControlDegAngleX += leftBack1AngleXStep;
                }
                else
                if (leftLimbBack1Constraint.ControlDegAngleX < -maxUp1AngleX)
                {
                    leftLimbBack1Constraint.ControlDegAngleX -= leftBack1AngleXStep;
                }
            }

            if (Math.Abs(leftLimbBack2Constraint.ControlDegAngleX + maxUp2AngleX) > Math.Abs(leftBack2AngleXStep))
            {
                move = true;
                if (leftLimbBack2Constraint.ControlDegAngleX > -maxUp2AngleX)
                {
                    leftLimbBack2Constraint.ControlDegAngleX += leftBack2AngleXStep;
                }
                else
                if (leftLimbBack2Constraint.ControlDegAngleX < -maxUp2AngleX)
                {
                    leftLimbBack2Constraint.ControlDegAngleX -= leftBack2AngleXStep;
                }
            }

            if (Math.Abs(leftLimbBack3Constraint.ControlDegAngleX + maxUp3AngleX) > Math.Abs(leftBack3AngleXStep))
            {
                move = true;
                if (leftLimbBack3Constraint.ControlDegAngleX > -maxUp3AngleX)
                {
                    leftLimbBack3Constraint.ControlDegAngleX += leftBack3AngleXStep;
                }
                else
                if (leftLimbBack3Constraint.ControlDegAngleX < -maxUp3AngleX)
                {
                    leftLimbBack3Constraint.ControlDegAngleX -= leftBack3AngleXStep;
                }
            }

            moveUp = move;
        }
Esempio n. 20
0
        void SwitchLeft(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if (leftDoorConstraint.IsBroken || leftDoorConstraint.PhysicsObject1.IsBrokenRigidGroup || leftDoorConstraint.PhysicsObject2.IsBrokenRigidGroup)
            {
                leftDoorConstraint.EnableControlAngleY = false;

                cabinBodyLeft1.DisableCollision(leftDoorRight, false);

                cabinBodyLeft2.DisableCollision(leftDoorUp, false);
                cabinBodyLeft2.DisableCollision(leftDoorDown, false);
                cabinBodyLeft2.DisableCollision(leftDoorLeft, false);

                cabinBodyUp1.DisableCollision(leftDoorUp, false);

                cabinBodyUp2.DisableCollision(leftDoorUp, false);
                cabinBodyUp2.DisableCollision(leftDoorRight, false);

                cabinBodyFrontLeft.DisableCollision(leftDoorUp, false);
                cabinBodyFrontLeft.DisableCollision(leftDoorRight, false);
                cabinBodyFrontLeft.DisableCollision(leftDoorDown, false);

                cabinBodyDown1.DisableCollision(leftDoorDown, false);

                cabinBodyDown2.DisableCollision(leftDoorDown, false);

                return;
            }

            PhysicsObject cameraBody = scene.GetPhysicsObjectWithActiveCamera(0).RigidGroupOwner.FindChildPhysicsObject(cameraBodyName, true, true);

            if (cameraBody == null)
            {
                leftDoorConstraint.EnableControlAngleY = true;
                return;
            }

            bool switchColliding = objectBase.IsColliding(cameraBody);
            bool doorColliding   = objectBase.RigidGroupOwner.IsColliding(cameraBody);

            if (switchColliding)
            {
                totalSwitchLeftTime = 0.0;
                leftDoorConstraint.EnableControlAngleY = false;
            }

            if (totalSwitchLeftTime < maxSwitchLeftTime)
            {
                Vector3.Multiply(ref unitY, -2000.0f, out torque);

                objectBase.RigidGroupOwner.WorldAccumulator.SetLocalTorque(ref torque);
            }
            else
            if (totalSwitchLeftTime < 2.0f * maxSwitchLeftTime)
            {
                if (!doorColliding)
                {
                    Vector3.Multiply(ref unitY, 2000.0f, out torque);

                    objectBase.RigidGroupOwner.WorldAccumulator.SetLocalTorque(ref torque);
                }
                else
                {
                    totalSwitchLeftTime = 0.0;
                }
            }
            else
            if (!doorColliding)
            {
                leftDoorConstraint.EnableControlAngleY = true;
            }
            else
            {
                totalSwitchLeftTime = 0.0;
            }

            totalSwitchLeftTime += time;

            if (totalSwitchLeftTime > 2.0f * maxSwitchLeftTime)
            {
                totalSwitchLeftTime = 2.0f * maxSwitchLeftTime;
            }
        }
Esempio n. 21
0
 private void UpdateTransforms(SimulateMethodArgs args)
 {
     MataliPhysicsObject mataliPhysicsObj = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);
     
     mataliPhysicsObj.MainWorldTransform.GetTransformMatrix(ref tempMat1);
     ((IPhysicsObject)mataliPhysicsObj.UserTagObj).PhysicsWorldTransform = tempMat1;
 }
Esempio n. 22
0
        void Transport(SimulateMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            float time = args.Time;

            if (panelButton != null)
            {
                if ((constraint1 != null) && (constraint2 != null) && (constraint3 != null) && (body != null) && (panel != null) && !constraint1.IsBroken && !constraint2.IsBroken && !constraint3.IsBroken && !body.IsBrokenRigidGroup && !panel.IsBrokenRigidGroup)
                {
                    if (enableRun)
                    {
                        panelButton.Material.SetAmbient(0.7f, 0.4f, 0.4f);
                        panelButton.Material.SetDiffuse(1.0f, 0.4f, 0.4f);
                        if ((panelLight != null) && (panelLight.Light != null))
                        {
                            panelLight.Light.SetDiffuse(1.0f, 0.2f, 0.2f);

                            frameCount = (frameCount + 1) % maxFrameCount;

                            if (frameCount == 0)
                            {
                                flipLight = !flipLight;
                            }

                            if (flipLight)
                            {
                                panelLight.Light.Intensity = 1.0f;
                            }
                            else
                            {
                                panelLight.Light.Intensity = 0.2f;
                            }
                        }
                    }
                    else
                    {
                        panelButton.Material.SetAmbient(0.4f, 0.7f, 0.4f);
                        panelButton.Material.SetDiffuse(0.4f, 1.0f, 0.4f);
                        if ((panelLight != null) && (panelLight.Light != null))
                        {
                            panelLight.Light.SetDiffuse(0.2f, 1.0f, 0.2f);
                            panelLight.Light.Intensity = 1.0f;
                        }
                    }
                }
                else
                {
                    panelButton.Material.SetAmbient(0.4f, 0.7f, 0.4f);
                    panelButton.Material.SetDiffuse(0.4f, 1.0f, 0.4f);
                    if ((panelLight != null) && (panelLight.Light != null))
                    {
                        panelLight.Light.Enabled = false;
                    }
                }
            }

            if (!enableRun)
            {
                return;
            }

            if ((constraint2 == null) || (constraint3 == null) || (body == null) || constraint2.IsBroken || constraint3.IsBroken || body.IsBrokenRigidGroup)
            {
                return;
            }

            if (!flipRotation)
            {
                if ((constraint3.ControlDistanceY < constraint3.MaxLimitDistanceY) && (constraint2.ControlDegAngleY <= 0.0))
                {
                    constraint3.ControlDistanceY += distanceSpeed;
                }

                if ((constraint3.ControlDistanceY > constraint3.MinLimitDistanceY) && (constraint2.ControlDegAngleY >= maxAngle))
                {
                    constraint3.ControlDistanceY -= distanceSpeed;
                }

                if ((constraint2.ControlDegAngleY < maxAngle) && (constraint3.ControlDistanceY >= constraint3.MaxLimitDistanceY))
                {
                    constraint2.ControlDegAngleY += rotationSpeed;
                }

                if (constraint3.ControlDistanceY <= constraint3.MinLimitDistanceY)
                {
                    enableRun = false;
                }
            }
            else
            {
                if ((constraint3.ControlDistanceY < constraint3.MaxLimitDistanceY) && (constraint2.ControlDegAngleY >= maxAngle))
                {
                    constraint3.ControlDistanceY += distanceSpeed;
                }

                if ((constraint3.ControlDistanceY > constraint3.MinLimitDistanceY) && (constraint2.ControlDegAngleY <= 0.0f))
                {
                    constraint3.ControlDistanceY -= distanceSpeed;
                }

                if ((constraint2.ControlDegAngleY > 0.0f) && (constraint3.ControlDistanceY >= constraint3.MaxLimitDistanceY))
                {
                    constraint2.ControlDegAngleY -= rotationSpeed;
                }

                if (constraint3.ControlDistanceY <= constraint3.MinLimitDistanceY)
                {
                    enableRun = false;
                }
            }
        }