Beispiel #1
0
        protected override void Init()
        {
            // Create a character controller that allows us to walk around.
            character = new CharacterController(camera, ContainingWorld);

            // For now, attach this entity to a simple sphere physics object.
            character.Body.SetTransformation(mat4.Translate(new vec3(0, 10f, 0)));
            thisEntity.AddComponent(new PhysicsComponent(
                                        character.Body,
                                        mat4.Translate(new vec3(0, character.EyeOffset, 0))));

            // Add Torso mesh.
            thisEntity.AddComponent(rcTorsoShadow = new RenderComponent(new MeshRenderJob(Renderer.Shadow.Mesh, Resources.UseMaterial("::Shadow", UpvoidMiner.ModDomain), Resources.UseMesh("Miner/Torso", UpvoidMiner.ModDomain), mat4.Identity),
                                                                        torsoTransform,
                                                                        true));

            /*psTorsoSteam = CpuParticleSystem.Create2D(new vec3(), ContainingWorld);
             * LocalScript.ParticleEntity.AddComponent(new CpuParticleComponent(psTorsoSteam, mat4.Identity));*/


            // Add camera component.
            thisEntity.AddComponent(cameraComponent = new CameraComponent(camera, mat4.Identity));

            // This digging controller will perform digging and handle digging constraints for us.
            digging = new DiggingController(ContainingWorld, this);

            Gui = new PlayerGui(this);

            AddTriggerSlot("AddItem");

            Inventory.InitCraftingRules();
            generateInitialItems();
        }
Beispiel #2
0
        public DiggingController(World world, Player player)
        {
            Debug.Assert(instance == null, "Singleton is violated");
            instance    = this;
            this.world  = world;
            this.player = player;

            string digParas = "digRadius:float, digPosition:vec3, digDirX:vec3, digDirY:vec3, digDirZ:vec3";

            string sphereExpression = "-digRadius + distance(vec3(x,y,z), digPosition)";

            sphereNode = new CsgExpression(1, sphereExpression, UpvoidMiner.ModDomain, digParas);

            string boxExpression = @"p = vec3(x,y,z) - digPosition;
                dx = abs(dot(p, digDirX));
                dy = abs(dot(p, digDirY));
                dz = abs(dot(p, digDirZ));
                -digRadius + max(dx, max(dy, dz))";

            boxNode = new CsgExpression(1, boxExpression, UpvoidMiner.ModDomain, digParas);

            string cylinderExpression = @"p = vec3(x,y,z) - digPosition;
                dx = abs(dot(p, digDirX));
                dy = abs(dot(p, digDirY));
                dz = abs(dot(p, digDirZ));
                -digRadius + max(dy, length(vec2(dx, dz)))";

            cylinderNode = new CsgExpression(1, cylinderExpression, UpvoidMiner.ModDomain, digParas);

            string playerExpression = @"p = vec3(x,y,z) - playerPosition;
                dx = abs(dot(p, digDirX));
                dy = abs(dot(p, digDirY));
                dz = abs(dot(p, digDirZ));
                -playerRadius + max(dy, length(vec2(dx, dz)))";

            playerNode = new CsgExpression(1, playerExpression, UpvoidMiner.ModDomain, "playerRadius:float, playerPosition:vec3, digDirX:vec3, digDirY:vec3, digDirZ:vec3");
        }