Ejemplo n.º 1
0
        public override void Spawn(Vector3 position, Quaternion orientation)
        {
            // create scene node
            SceneNode sceneNode = this.CreateSceneNode(position, orientation);
            Entity    entity    = sceneNode.GetAttachedObject(0) as Entity;

            // physics
            BodyDesc bodyDesc = new BodyDesc();

            bodyDesc.LinearVelocity = this.Velocity;

            ActorDesc actorDesc = Engine.Physics.CreateActorDesc(this, entity, position, orientation, this.Scale);

            actorDesc.Density           = this.Density;
            actorDesc.Body              = bodyDesc;
            actorDesc.GlobalPosition    = position;
            actorDesc.GlobalOrientation = orientation.ToRotationMatrix();

            if (this.EnableCCD)
            {
                foreach (ShapeDesc shapeDesc in actorDesc.Shapes)
                {
                    shapeDesc.ShapeFlags = ShapeFlags.DynamicDynamicCCD;
                }
            }

            Actor actor = Engine.Physics.Scene.CreateActor(actorDesc);

            actor.UserData = this;

            ActorNode actorNode = new ActorNode(sceneNode, actor);

            Engine.World.ActorNodes.Add(actorNode);
        }
Ejemplo n.º 2
0
    public bool GetBody(int id, out BodyDesc body)
    {
        body = new BodyDesc();

        if (bodies != null)
        {
            return(bodies.TryGetValue(id, out body));
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
        public void CreateDynamic(
            Vector3 pose,
            Matrix3 oritentaion,
            RigidBodyDescription description,
            Scene scene,
            ShapeDesc shape)
        {
            BodyDesc  bodyDesc  = new BodyDesc();
            ActorDesc actorDesc = new ActorDesc();

            description.ToNxActor(ref actorDesc, ref bodyDesc);
            actorDesc.Body              = bodyDesc;
            actorDesc.GlobalPosition    = pose;
            actorDesc.GlobalOrientation = oritentaion;
            actorDesc.Shapes.Add(shape);
            Actor = scene.CreateActor(actorDesc);
        }
Ejemplo n.º 4
0
        public void ToNxActor(ref ActorDesc actorDesc, ref BodyDesc bodyDesc)
        {
            ToNxActor(ref actorDesc);

            bodyDesc.AngularDamping     = angularDamping;
            bodyDesc.AngularVelocity    = angularVelocity;
            bodyDesc.CCDMotionThreshold = ccdMotionThreshold;
            bodyDesc.LinearDamping      = linearDamping;
            bodyDesc.LinearVelocity     = linearVelocity;
            bodyDesc.Mass                 = mass;
            bodyDesc.MassLocalPose        = massLocalPose;
            bodyDesc.MassSpaceInertia     = massSpaceInertia;
            bodyDesc.MaxAngularVelocity   = maxAngularVelocity;
            bodyDesc.SleepAngularVelocity = sleepAngularVelocity;
            bodyDesc.SleepDamping         = sleepDamping;
            bodyDesc.SleepEnergyThreshold = sleepEnergyThreshold;
            bodyDesc.SleepLinearVelocity  = sleepLinearVelocity;
            bodyDesc.SolverIterationCount = solverIterationCount;
            bodyDesc.WakeUpCounter        = wakeUpCounter;
        }
Ejemplo n.º 5
0
        public override void Spawn(Vector3 position, Quaternion orientation)
        {
            // create scene node
            SceneNode sceneNode = this.CreateSceneNode(position, orientation);
            Entity entity = sceneNode.GetAttachedObject(0) as Entity;

            // physics
            BodyDesc bodyDesc = new BodyDesc();
            bodyDesc.LinearVelocity = this.Velocity;

            ActorDesc actorDesc = Engine.Physics.CreateActorDesc(this, entity, position, orientation, this.Scale);
            actorDesc.Density = this.Density;
            actorDesc.Body = bodyDesc;
            actorDesc.GlobalPosition = position;
            actorDesc.GlobalOrientation = orientation.ToRotationMatrix();

            if (this.EnableCCD)
            {
                foreach (ShapeDesc shapeDesc in actorDesc.Shapes)
                    shapeDesc.ShapeFlags = ShapeFlags.DynamicDynamicCCD;
            }

            Actor actor = Engine.Physics.Scene.CreateActor(actorDesc);
            actor.UserData = this;

            ActorNode actorNode = new ActorNode(sceneNode, actor);
            Engine.World.ActorNodes.Add(actorNode);
        }
Ejemplo n.º 6
0
        public override void init()
        {
            lights.Add(OgreWindow.Instance.mSceneMgr.CreateLight("testLight"));
            lights["testLight"].Type           = Light.LightTypes.LT_POINT;
            lights["testLight"].Position       = new Mogre.Vector3(-117.9847f, 120f, 234.2695f) + Location().toMogre;
            lights["testLight"].DiffuseColour  = ColourValue.White;
            lights["testLight"].SpecularColour = ColourValue.White;

            lights.Add(OgreWindow.Instance.mSceneMgr.CreateLight("testLight2"));
            lights["testLight2"].Type           = Light.LightTypes.LT_POINT;
            lights["testLight2"].Position       = new Mogre.Vector3(1.408661f, 54.81305f, -3.154539f) + Location().toMogre;
            lights["testLight2"].DiffuseColour  = ColourValue.White;
            lights["testLight2"].SpecularColour = ColourValue.White;

            //MeshManager.Singleton.CreatePlane("ground",
            //    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
            //    new Plane(Mogre.Vector3.UNIT_Y, 0),
            //    1500, 1500, 20, 20, true, 1, 5, 5, Mogre.Vector3.UNIT_Z);
            //// Create a ground plane
            //entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("GroundEntity", "ground"));
            //entities["GroundEntity"].CastShadows = false;
            //entities["GroundEntity"].SetMaterialName("dirt");
            //nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("ground"));
            //nodes["ground"].AttachObject(entities["GroundEntity"]);
            //nodes["ground"].Position = new Mogre.Vector3(0f, 0f, 0f) + Location().toMogre;

            //our "ground" is a mushroom :)
            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("mushroom", "\\TongIts\\mushroom.mesh"));
            entities["mushroom"].SetMaterialName("mushroom");
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("mushroom"));
            nodes["mushroom"].AttachObject(entities["mushroom"]);
            nodes["mushroom"].Position = new Mogre.Vector3(0f, -20f, 0f) + Location().toMogre;
            nodes["mushroom"].Scale(new Mogre.Vector3(100f));
            nodes["mushroom"].Roll(new Radian(new Degree(90f)));
            preventMousePick("mushroom");


            #region physics

            // physics
            // attaching a body to the actor makes it dynamic, you can set things like initial velocity
            BodyDesc bodyDesc = new BodyDesc();
            bodyDesc.LinearVelocity = new Mogre.Vector3(0, 2, 5);

            // the actor properties control the mass, position and orientation
            // if you leave the body set to null it will become a static actor and wont move
            ActorDesc actorDesc = new ActorDesc();
            actorDesc.Density           = 4;
            actorDesc.Body              = null;
            actorDesc.GlobalPosition    = nodes["mushroom"].Position;
            actorDesc.GlobalOrientation = nodes["mushroom"].Orientation.ToRotationMatrix();

            // a quick trick the get the size of the physics shape right is to use the bounding box of the entity
            //actorDesc.Shapes.Add(new SphereShapeDesc(1f));//entities["drone"].BoundingBox.HalfSize * scale, entities["drone"].BoundingBox.Center * scale



            PhysXHelpers.StaticMeshData meshdata = new PhysXHelpers.StaticMeshData(entities["mushroom"].GetMesh());
            actorDesc.Shapes.Add(PhysXHelpers.CreateTriangleMesh(meshdata));

            Actor actor = null;
            // finally, create the actor in the physics scene
            try { actor = OgreWindow.Instance.scene.CreateActor(actorDesc); }
            catch { }
            // if (actor == null)
            //    OgreWindow.Instance.CloseForm();
            if (actor != null)
            {
                // create our special actor node to tie together the scene node and actor that we can update its position later
                ActorNode actorNode = new ActorNode(nodes["mushroom"], actor);
                actors.Add(actorNode);
            }
            #endregion



            #region table
            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("tongitstable", "\\TongIts\\tongitstable.mesh"));
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("table"));
            nodes["table"].AttachObject(entities["tongitstable"]);
            nodes["table"].Position = new Mogre.Vector3(0f, 36f, 0f) + Location().toMogre;
            //nodes["table"].Scale(new Mogre.Vector3(4f));
            //preventMousePick("tongitstable");
            // physics
            // attaching a body to the actor makes it dynamic, you can set things like initial velocity
            bodyDesc.LinearVelocity = new Mogre.Vector3(0, 0, 0);

            // the actor properties control the mass, position and orientation
            // if you leave the body set to null it will become a static actor and wont move
            ActorDesc tableActorDesc = new ActorDesc();
            tableActorDesc.Density           = 4;
            tableActorDesc.Body              = null;
            tableActorDesc.GlobalPosition    = nodes["table"].Position;
            tableActorDesc.GlobalOrientation = nodes["table"].Orientation.ToRotationMatrix();
            PhysXHelpers.StaticMeshData tableMeshData = new PhysXHelpers.StaticMeshData(entities["tongitstable"].GetMesh());
            tableActorDesc.Shapes.Add(PhysXHelpers.CreateTriangleMesh(tableMeshData));

            Actor tableActor = null;
            // finally, create the actor in the physics scene
            try { tableActor = OgreWindow.Instance.scene.CreateActor(tableActorDesc); }
            catch { }
            if (tableActor != null)
            {
                actors.Add(new ActorNode(nodes["table"], tableActor));
            }
            #endregion

            #region baseball
            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("baseball", "\\baseball.mesh"));
            entities["baseball"].SetMaterialName("baseball");
            //nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("baseball"));
            nodes.Add(nodes["table"].CreateChildSceneNode("baseball"));
            nodes["baseball"].AttachObject(entities["baseball"]);
            //nodes["baseball"].SetScale(.5f, .5f, .5f);
            nodes["baseball"].SetPosition(Location().x, Location().y, Location().z);
            // nodes["baseball"].SetScale(5f, 5f, 5f);
            #endregion

            #region cards

            Thread.Sleep(5000);

            //only 1 entity needed


            foreach (string suit in suits)
            {
                for (int i = 2; i < 11; i++)
                {
                    string cardname = string.Format("{0} {1}", suit, i);
                    createCardEntity(cardname);
                    createCardSceneNode(cardname);
                    placeCard(0, cardname);
                }
                foreach (string face in faces)
                {
                    string cardname = string.Format("{0} {1}", suit, face);
                    createCardEntity(cardname);
                    createCardSceneNode(cardname);
                    placeCard(0, cardname);
                }
            }

            //MeshManager.Singleton.CreatePlane("spinnycard", "General", new Plane(Mogre.Vector3.UNIT_Y, 0), 200f, 250f, 1, 1, true, 1, 1, 1, Mogre.Vector3.UNIT_X);

            //// physics
            //// attaching a body to the actor makes it dynamic, you can set things like initial velocity
            //BodyDesc cardBodyDesc = null;
            //bodyDesc.LinearVelocity = new Mogre.Vector3(0, 6, 0);

            //// the actor properties control the mass, position and orientation
            //// if you leave the body set to null it will become a static actor and wont move
            //ActorDesc cardActorDesc = new ActorDesc();
            //cardActorDesc.Density = 4;
            //cardActorDesc.Body = cardBodyDesc;
            //cardActorDesc.GlobalPosition = nodes["club 5"].Position;
            //cardActorDesc.GlobalOrientation = nodes["club 5"].Orientation.ToRotationMatrix();
            //PhysXHelpers.StaticMeshData cardMeshData = new PhysXHelpers.StaticMeshData(entities["club 5"].GetMesh());
            //cardActorDesc.Shapes.Add(PhysXHelpers.CreateConvexHull(cardMeshData));

            //Actor cardActor = null;
            //// finally, create the actor in the physics scene
            //try { cardActor = OgreWindow.Instance.scene.CreateActor(cardActorDesc); }
            //catch { }
            //// if (actor == null)
            ////    OgreWindow.Instance.CloseForm();
            //if (cardActor != null)
            //{
            //    actors.Add(new ActorNode(nodes["club 5"], cardActor));
            //}

            #endregion
            resetPlayer(1);
            this.btnLimiter_F.reset();
            this.btnLimiter_F.start();
        }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        while (udpClient.Available > 0)
        {
            IPEndPoint ep = null;

            byte[] bytes;

            bytes = udpClient.Receive(ref ep);

            if (bytes != null)
            {
                string s = System.Text.Encoding.Default.GetString(bytes);

                if (!string.IsNullOrEmpty(s))
                {
                    //print(s);

                    char[] separators = { ' ', '[', ']', '\r', '\n' };

                    string[] toto = s.Split(separators);

                    int index_6d = -1;

                    for (int i = 0; i < toto.Length; i++)
                    {
                        if (toto[i] == "6d")
                        {
                            index_6d = i;

                            break;
                        }
                    }

                    int count = int.Parse(toto[index_6d + 1]);

                    bodies = new Dictionary <int, BodyDesc>();

                    int current_index = index_6d + 2;

                    for (int i = 0; i < count; i++)
                    {
                        BodyDesc body = new BodyDesc();

                        current_index++;

                        body.id = int.Parse(toto[current_index]);

                        current_index++;


                        toto[current_index] = toto[current_index].Replace('.', ',');
                        body.quality        = float.Parse(toto[current_index]);

                        current_index += 2;

                        Matrix4x4 m = Matrix4x4.identity;

                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m03 = 0.001f * float.Parse(toto[current_index]);

                        current_index++;

                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m13 = 0.001f * float.Parse(toto[current_index]);

                        current_index++;

                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m23 = 0.001f * float.Parse(toto[current_index]);

                        current_index += 5;


                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m00 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m10 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m20 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m01 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m11 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m21 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m02 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m12 = float.Parse(toto[current_index]);
                        current_index++;
                        toto[current_index] = toto[current_index].Replace('.', ',');
                        m.m22 = float.Parse(toto[current_index]);

                        Matrix4x4 a = p * m * inv_p;                         // on passe la matrice du repère de la salle au repère de Unity

                        body.position = a.ExtractPosition();

                        /*float temp = body.position.y;
                         * body.position.y = -body.position.z;
                         * body.position.z = temp;*/
                        body.orientation = a.ExtractQuaternion();

                        body.rotationMatrix = a;

                        bodies[body.id] = body;

                        Debug.Log(body.id);

                        current_index += 2;
                    }
                }
            }
        }
    }