示例#1
0
        public void CreateMultipleControllers()
        {
            using (CreateCoreAndScene())
            {
                ControllerManager manager = this.Scene.CreateControllerManager();

                BoxControllerDescription descA          = new BoxControllerDescription(new Vector3(1.0f, 1.0f, 1.0f), Vector3.Zero);
                BoxController            boxControllerA = manager.CreateController(descA) as BoxController;
                boxControllerA.Dispose();

                BoxControllerDescription descB          = new BoxControllerDescription(new Vector3(1.0f, 1.0f, 1.0f), Vector3.Zero);
                BoxController            boxControllerB = manager.CreateController(descB) as BoxController;
            }
        }
示例#2
0
        public static void RunCharacterTest()
        {
            Core core = new Core();

            StillDesign.PhysX.Scene scene = core.CreateScene();

            ControllerManager manager = scene.CreateControllerManager();

            CapsuleControllerDescription desc = new CapsuleControllerDescription(2, 10);
            CapsuleController            capsuleController = manager.CreateController <CapsuleController>(desc);


            BoxShapeDescription boxShapeDesc = new BoxShapeDescription(1, 1, 1);
            ActorDescription    actorDesc    = new ActorDescription(boxShapeDesc);

            actorDesc.BodyDescription = new BodyDescription(1f);

            Actor actor = scene.CreateActor(actorDesc);

            //capsuleController.Move( Vector3.Up );

            // Update Physics
            scene.Simulate(1.0f / 60.0f);
            scene.FlushStream();
            scene.FetchResults(SimulationStatus.RigidBodyFinished, true);

            capsuleController.Move(Vector3.Up);

            core.Dispose();
        }
        public void Initialize(StillDesign.PhysX.Scene _scene)
        {
            scene = _scene;

            manager = scene.CreateControllerManager();



            CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(0.5f, 1);

            controllerHitReport            = new PlayerControllerHitReport();
            capsuleControllerDesc.Callback = controllerHitReport;

            /*{
             *  Callback = new ControllerHitReport()
             * };*/

            CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc);

            capsuleController.Position   = player.Position.xna();
            capsuleController.Actor.Name = "PlayerController";
            capsuleController.SetCollisionEnabled(true);


            controller = capsuleController;
        }
        public void CreateControllerTest_InputAlienWave()
        {
            //Erzeugung Testumgebung

            ControllerManager target = new ControllerManager();
            //Nicht benötigt
            object sender = null;


            BehaviourEnum          behaviour   = BehaviourEnum.BlockMovement;
            LinkedList <IGameItem> controllees = new LinkedList <IGameItem>();

            controllees.AddFirst(new Alien(Vector2.Zero, new Vector2(5, 5), 1, 1, new PlayerNormalWeapon(), 7));

            DifficultyLevel difficultyLevel = DifficultyLevel.EasyDifficulty;



            ControllerEventArgs desiredController = new ControllerEventArgs(behaviour, controllees, difficultyLevel); // TODO: Initialize to an appropriate value


            //Test start
            target.CreateController(sender, desiredController);


            //Testergebnis
            Assert.AreEqual(target.Controllers.Count, 1);
        }
示例#5
0
        public override void AddObject(IPhysicObject obj)
        {
            if (obj is PhysxPhysicObject)
            {
                PhysxPhysicObject PhysxPhysicObject = obj as PhysxPhysicObject;
                if (PhysxPhysicObject.Actor == null)
                {
                    PhysxPhysicObject.Actor          = Scene.CreateActor(PhysxPhysicObject.ActorDesc, int.MaxValue);
                    PhysxPhysicObject.Actor.UserData = obj;

                    for (int i = 0; i < PhysxPhysicObject.ActorDesc.Shapes.Count; i++)
                    {
                        PhysxPhysicObject.Actor.Shapes[i].UserData = PhysxPhysicObject.ActorDesc.Shapes[i].UserData;
                    }
                }
                else
                {
                    PhysxPhysicObject.Actor.UserData = obj;
                }
            }

            else if (obj is PhysxClothObject)
            {
                PhysxClothObject PhysxPhysicObject = obj as PhysxClothObject;
                PhysxPhysicObject.Cloth          = Scene.CreateCloth(PhysxPhysicObject.ClothDesc);
                PhysxPhysicObject.Cloth.UserData = obj;
            }

            else if (obj is PhysxFluidObject)
            {
                PhysxFluidObject PhysxPhysicObject = obj as PhysxFluidObject;
                PhysxPhysicObject.Fluid          = Scene.CreateFluid(PhysxPhysicObject.FluidDesc);
                PhysxPhysicObject.Fluid.UserData = obj;
            }

            else if (obj is PhysxCapsuleCharacterObject)
            {
                PhysxCapsuleCharacterObject PhysxPhysicObject = obj as PhysxCapsuleCharacterObject;
                PhysxPhysicObject.Controller          = ControllerManager.CreateController <CapsuleController>(PhysxPhysicObject.CapsuleControllerDescription);
                PhysxPhysicObject.Controller.UserData = obj;
            }

            else if (obj is PhysxBoxCharacterObject)
            {
                PhysxBoxCharacterObject PhysxPhysicObject = obj as PhysxBoxCharacterObject;
                PhysxPhysicObject.Controller          = ControllerManager.CreateController <BoxController>((PhysxPhysicObject.BoxControllerDescription));
                PhysxPhysicObject.Controller.UserData = obj;
            }

            objs.Add(obj);
        }
示例#6
0
        private void setupPhysics()
        {
            CapsuleControllerDesc desc = new CapsuleControllerDesc();

            desc.Position                 = entityNode.Position;
            desc.StepOffset               = 0.01f;
            desc.SlopeLimit               = 0.5f;              // max slope the character can walk
            desc.Radius                   = 2.5f;              //radius of the capsule
            desc.Height                   = CHAR_HEIGHT;       //height of the controller
            desc.ClimbingMode             = CapsuleClimbingModes.Easy;
            desc.UpDirection              = HeightFieldAxes.Y; // Specifies the 'up' direction
            desc.Position                 = entityNode.Position;
            physicsController             = cotrollerManager.CreateController(physicsScene, desc);
            physicsController.Actor.Group = 3;
        }
示例#7
0
        public void LoadPhysics()
        {
            Core  _core  = this.Core;
            Scene _scene = this.Scene;

            #region Some Boxes
            for (int x = 0; x < 5; x++)
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);

                ActorDescription actorDesc = new ActorDescription()
                {
                    Name            = String.Format("Box {0}", x),
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(100, 15 + 3 * x, 20),
                    Shapes          = { boxShapeDesc }
                };

                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            //#region Cloth (Flag)
            //{
            //    // Create a Grid of Points
            //    VertexGrid grid = VertexGrid.CreateGrid( 10, 10 );

            //    ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
            //        clothMeshDesc.AllocateVertices<Vector3>( grid.Points.Length );
            //        clothMeshDesc.AllocateTriangles<int>( grid.Indices.Length / 3 );

            //        clothMeshDesc.VertexCount = grid.Points.Length;
            //        clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

            //        clothMeshDesc.VerticesStream.SetData( grid.Points );
            //        clothMeshDesc.TriangleStream.SetData( grid.Indices );

            //        // We are using 32 bit integers, so make sure the 16 bit flag is removed.
            //        // 32 bits are the default, so this isn't technically needed
            //        clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

            //    // Write the cooked data to memory
            //    MemoryStream memoryStream = new MemoryStream();

            //    Cooking.InitializeCooking();
            //    Cooking.CookClothMesh( clothMeshDesc, memoryStream );
            //    Cooking.CloseCooking();

            //    // Need to reset the position of the stream to the beginning
            //    memoryStream.Position = 0;

            //    ClothMesh clothMesh = _core.CreateClothMesh( memoryStream );

            //    //

            //    ClothDescription clothDesc = new ClothDescription()
            //    {
            //        ClothMesh = clothMesh,
            //        Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
            //        GlobalPose =
            //            Matrix.CreateFromYawPitchRoll( 0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f ) *
            //            Matrix.CreateTranslation( 0, 20, 0 )
            //    };
            //    clothDesc.MeshData.AllocatePositions<Vector3>( grid.Points.Length );
            //    clothDesc.MeshData.AllocateIndices<int>( grid.Indices.Length );

            //    clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            //    clothDesc.MeshData.MaximumIndices = grid.Indices.Length;

            //    clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            //    clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;

            //    _flag = _scene.CreateCloth( clothDesc );

            //    // Flag Pole
            //    ActorDescription flagPoleActorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( 0, 10, 0 ),
            //        Shapes = { new BoxShapeDescription( 1.0f, 20.0f, 1.0f ) }
            //    };

            //    Actor flagPoleActor = _scene.CreateActor( flagPoleActorDesc );

            //    _flag.AttachToShape( flagPoleActor.Shapes[ 0 ], 0 );
            //    _flag.WindAcceleration = new Vector3( 10, 10, 10 );
            //    _flag.BendingStiffness = 0.1f;
            //}
            //#endregion

            #region Revolute Joint
            {
                BoxShapeDescription boxShapeDescA = new BoxShapeDescription(3, 3, 3);
                BoxShapeDescription boxShapeDescB = new BoxShapeDescription(3, 3, 3);

                ActorDescription actorDescA = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(75, 1.5f, 55),
                    Shapes          = { boxShapeDescA }
                };
                Actor actorA = _scene.CreateActor(actorDescA);

                ActorDescription actorDescB = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(70, 1.5f, 55),
                    Shapes          = { boxShapeDescB }
                };
                Actor actorB = _scene.CreateActor(actorDescB);

                //

                RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                    Motor  = new MotorDescription(20, 20.1f, true)
                };
                revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
                revoluteJointDesc.SetGlobalAnchor(new Vector3(73.5f, 1.5f, 55));
                revoluteJointDesc.SetGlobalAxis(new Vector3(1, 0, 0));

                RevoluteJoint revoluteJoint = _scene.CreateJoint(revoluteJointDesc) as RevoluteJoint;
            }
            #endregion

            #region Prismatic Joint with Limit
            {
                Actor actorA, actorB;
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    BodyDescription bodyDesc = new BodyDescription(10.0f);
                    bodyDesc.BodyFlags |= BodyFlag.Kinematic;

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = bodyDesc,
                        GlobalPose      = Matrix.Translation(70, 25, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorA = _scene.CreateActor(actorDesc);
                }
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = new BodyDescription(10.0f),
                        GlobalPose      = Matrix.Translation(70, 15, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorB = _scene.CreateActor(actorDesc);
                }

                PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                };
                prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, 65));
                prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

                PrismaticJoint prismaticJoint = _scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

                LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);
                prismaticJoint.AddLimitPlane(limitPlane);
            }
            #endregion

            #region Fluid
            {
                const int maximumParticles = 1000;

                FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription()
                {
                    DimensionX   = 0.5f,
                    DimensionY   = 0.5f,
                    Rate         = 15,
                    RelativePose = Matrix.Translation(-40, 10, 50),
                    Shape        = EmitterShape.Rectangular,
                    Type         = EmitterType.ConstantFlowRate,
                    RandomAngle  = 0.5f
                };
                fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

                FluidDescription fluidDesc = new FluidDescription()
                {
                    Emitters         = { fluidEmitterDesc },
                    Flags            = FluidFlag.Enabled | FluidFlag.Visualization,
                    MaximumParticles = maximumParticles
                };
                fluidDesc.ParticleWriteData.AllocatePositionBuffer <Vector3>(maximumParticles);
                fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

                Fluid fluid = _scene.CreateFluid(fluidDesc);

                // Ledge
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.RotationX(0.5f) * Matrix.Translation(-40, 5, 52),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }

                // Drain
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                    boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.Translation(-40, 0, 55),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }
            }
            #endregion

            #region Force Field
            {
                BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription()
                {
                    Size = new Vector3(10, 10, 10)
                };

                ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription()
                {
                    Constant = new Vector3(0, 100.0f, 0)
                };

                ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel(kernelDesc);

                ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription()
                {
                    Shapes = { boxForceFieldShapeDesc }
                };

                ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup(shapeGroupDesc);

                BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape(boxForceFieldShapeDesc) as BoxForceFieldShape;
                boxForceFieldShape.Pose = Matrix.Translation(30, 5, 0);

                ForceFieldDescription forceFieldDesc = new ForceFieldDescription()
                {
                    Kernel      = kernel,
                    ShapeGroups = { shapeGroup }
                };
                ForceField forceField = _scene.CreateForceField(forceFieldDesc);
            }
            #endregion

            #region Heightfield
            {
                int rows    = 25;
                int columns = 25;

                HeightFieldSample[] samples = new HeightFieldSample[rows * columns];
                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {
                        // Put a z and x curve together
                        double h = Math.Sin(c) * Math.Cos(r) * short.MaxValue;

                        HeightFieldSample sample = new HeightFieldSample()
                        {
                            Height           = (short)h,
                            MaterialIndex0   = 0,
                            MaterialIndex1   = 1,
                            TessellationFlag = 0
                        };

                        samples[r * columns + c] = sample;
                    }
                }

                HeightFieldDescription heightFieldDesc = new HeightFieldDescription()
                {
                    NumberOfRows    = rows,
                    NumberOfColumns = columns
                };
                heightFieldDesc.SetSamples(samples);

                HeightField heightField = _core.CreateHeightField(heightFieldDesc);

                //

                HeightFieldShapeDescription heightFieldShapeDesc = new HeightFieldShapeDescription()
                {
                    HeightField  = heightField,
                    HoleMaterial = 2,
                    // The max height of our samples is short.MaxValue and we want it to be 1
                    HeightScale = 1.0f / (float)short.MaxValue,
                    RowScale    = 3,
                    ColumnScale = 3
                };
                heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(100, 0, 0),
                    Shapes     = { heightFieldShapeDesc }
                };
                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            //#region Convex Mesh
            //{
            //    ModelMesh mesh = _torusModel.Meshes.First();

            //    Matrix[] transforms = new Matrix[ _torusModel.Bones.Count ];
            //    _torusModel.CopyAbsoluteBoneTransformsTo( transforms );

            //    // Gets the vertices from the mesh
            //    VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[ mesh.MeshParts[ 0 ].NumVertices ];
            //    mesh.VertexBuffer.GetData<VertexPositionNormalTexture>( vertices );

            //    //

            //    // Allocate memory for the points and triangles
            //    var convexMeshDesc = new ConvexMeshDescription()
            //    {
            //        PointCount = vertices.Length
            //    };
            //    convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
            //    convexMeshDesc.AllocatePoints<Vector3>( vertices.Length );

            //    // Write in the points and triangles
            //    // We only want the Position component of the vertex. Also scale down the mesh
            //    foreach( VertexPositionNormalTexture vertex in vertices )
            //    {
            //        Vector3 position = Vector3.Transform( vertex.Position, Matrix.CreateScale( 0.1f, 0.1f, 0.1f ) * transforms[ 0 ] );

            //        convexMeshDesc.PointsStream.Write( position );
            //    }

            //    //

            //    // Cook to memory or to a file
            //    MemoryStream stream = new MemoryStream();
            //    //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

            //    Cooking.InitializeCooking( new ConsoleOutputStream() );
            //    Cooking.CookConvexMesh( convexMeshDesc, stream );
            //    Cooking.CloseCooking();

            //    stream.Position = 0;

            //    ConvexMesh convexMesh = _core.CreateConvexMesh( stream );

            //    ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription( convexMesh );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        BodyDescription = new BodyDescription( 10.0f ),
            //        GlobalPose = Matrix.CreateTranslation( 30, 30, 0 )
            //    };
            //    actorDesc.Shapes.Add( convexShapeDesc );

            //    _torusActor = _scene.CreateActor( actorDesc );
            //}
            //#endregion

            //#region SoftBody
            //if( false ) // Enable to view soft bodies, they run slowly
            //{
            //    XmlDocument doc = new XmlDocument();
            //        doc.Load( "Teapot.xml" );

            //    // Not how NxuStream are meant to used but what ever :S
            //    Vector3[] vertices = ReadVertices( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices" ) );
            //    int[] tetrahedraSingles = ReadTetrahedra( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra" ) );

            //    var softBodyMeshDesc = new SoftBodyMeshDescription()
            //    {
            //        VertexCount = vertices.Length,
            //        TetrahedraCount = tetrahedraSingles.Length / 4 // Tetrahedras come in quadruples of ints
            //    };

            //    softBodyMeshDesc.AllocateVertices<Vector3>( softBodyMeshDesc.VertexCount );
            //    softBodyMeshDesc.AllocateTetrahedra<int>( softBodyMeshDesc.TetrahedraCount ); // Note: T is an int. T is the type of each point

            //    softBodyMeshDesc.VertexStream.SetData( vertices );
            //    softBodyMeshDesc.TetrahedraStream.SetData( tetrahedraSingles );

            //    MemoryStream memoryStream = new MemoryStream();

            //    Cooking.InitializeCooking();
            //    Cooking.CookSoftBodyMesh( softBodyMeshDesc, memoryStream );
            //    Cooking.CloseCooking();

            //    memoryStream.Position = 0;

            //    SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh( memoryStream );

            //    SoftBodyDescription desc = new SoftBodyDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 20, -30 ),
            //        SoftBodyMesh = softBodyMesh
            //    };
            //    desc.Flags |= SoftBodyFlag.Visualization;

            //    desc.MeshData.AllocatePositions<Vector3>( vertices.Length );
            //    desc.MeshData.AllocateIndices<int>( tetrahedraSingles.Length );

            //    SoftBody softBody = _scene.CreateSoftBody( desc );
            //}
            //#endregion

            //#region Reports
            //// Contact report
            //// When the capsule actor hits the ground make it bounce by using the conact report
            //{
            //    CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription( 1, 5 );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 20, 0 ),
            //        BodyDescription = new BodyDescription( 10.0f ),
            //        Name = "Report Capsule",
            //        Shapes = { capsuleShapeDesc }
            //    };

            //    _contactReportActor = _scene.CreateActor( actorDesc );

            //    _scene.SetActorPairFlags( _contactReportActor, _groundActor, ContactPairFlag.All );

            //    _scene.UserContactReport = new ContactReport( this );
            //}

            //// Trigger Reports
            //{
            //    BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 15, 8, 15 );
            //        boxShapeDesc.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 4, 0 ),
            //        Shapes = { boxShapeDesc }
            //    };
            //    _scene.CreateActor( actorDesc );

            //    _scene.UserTriggerReport = new TriggerReport( this );
            //}

            //_scene.UserNotify = new Notify( this );
            //#endregion

            //#region Wheel
            //{
            //    _basicVehicle = new Vehicle( this );
            //}
            //#endregion

            #region Controller
            {
                ControllerManager manager = _scene.CreateControllerManager();

                CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(4, 3);

                CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc);
                capsuleController.Position   = new Vector3(0, 1.5f + 2, -15);
                capsuleController.Actor.Name = "BoxController";
                capsuleController.SetCollisionEnabled(true);
            }
            #endregion
        }
示例#8
0
        void setupLighting()
        {
            /****/
            // Set ambient light
            mSceneManager.SetAmbientLight(Converter.GetColor(0.2f, 0.2f, 0.2f));
            // Point light, movable, reddish
            mLight = mSceneManager.CreateLight("Light2");
            mLight.SetDiffuseColour(mMinLightColour);
            mLight.SetSpecularColour(1.0f, 1.0f, 1.0f);
            mLight.SetAttenuation(8000.0f, 1.0f, 0.0005f, 0.0f);

            // Create light node
            mLightNode = mSceneManager.GetRootSceneNode().CreateChildSceneNode("MovingLightNode");
            mLightNode.AttachObject(mLight);
            // create billboard set
            BillboardSet bbs = mSceneManager.CreateBillboardSet("lightbbs", 1);

            bbs.SetMaterialName("Examples/Flare");
            Billboard bb = bbs.CreateBillboard(0, 0, 0, mMinLightColour);

            // attach
            mLightNode.AttachObject(bbs);



            // create controller, after this is will get updated on its own
            mWFCF   = new WaveformControllerFunction(WaveformType.Sine, 0.0f, 0.5f);
            mCFFPtr = new ControllerFunctionFloatPtr(mWFCF);

            mLightWibbler = new LightWibbler(mLight, bb, mMinLightColour, mMaxLightColour, mMinFlareSize, mMaxFlareSize);
            mCVFPtr       = new ControllerValueFloatPtr(mLightWibbler.mCVFH);

            ControllerManager contMgr = ControllerManager.GetSingleton();

            mLightCtlFlt = contMgr.CreateController(contMgr.GetFrameTimeSource(), mCVFPtr, mCFFPtr);

            mLightNode.SetPosition(new Vector3(300, 250, -300));


            // Create a track for the light
            Animation anim = mSceneManager.CreateAnimation("LightTrack", 20.0f);

            // Spline it for nice curves
            anim.SetInterpolationMode(Animation.InterpolationMode.Spline);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, mLightNode);
            // Setup keyframes
            TransformKeyFrame key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(0.0f)).Handle, false);              // A startposition

            key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f));

            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(2.0f)).Handle, false);             //B
            key.SetTranslate(new Vector3(150.0f, 600.0f, -250.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(4.0f)).Handle, false);             //C
            key.SetTranslate(new Vector3(-150.0f, 650.0f, -100.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(6.0f)).Handle, false);             //D
            key.SetTranslate(new Vector3(-400.0f, 500.0f, -200.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(8.0f)).Handle, false);             //E
            key.SetTranslate(new Vector3(-200.0f, 500.0f, -400.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(10.0f)).Handle, false);            //F
            key.SetTranslate(new Vector3(-100.0f, 450.0f, -200.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(12.0f)).Handle, false);            //G
            key.SetTranslate(new Vector3(-100.0f, 400.0f, 180.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(14.0f)).Handle, false);            //H
            key.SetTranslate(new Vector3(0.0f, 250.0f, 600.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(16.0f)).Handle, false);            //I
            key.SetTranslate(new Vector3(100.0f, 650.0f, 100.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(18.0f)).Handle, false);            //J
            key.SetTranslate(new Vector3(250.0f, 600.0f, 0.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(20.0f)).Handle, false);            //K == A
            key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f));
            // Create a new animation state to track this
            mAnimState = mSceneManager.CreateAnimationState("LightTrack");
            mAnimState.SetEnabled(true);
            /****/
        }