예제 #1
0
        /// <inheritdoc/>
        public override void DrawModel(Entity p)
        {
            IGraphicsApi gfx = game.Graphics;

            gfx.BindTexture(GetTexture(p));
            DrawRotate(-p.HeadXRadians, 0, 0, Head, true);

            DrawPart(Torso);
            DrawRotate(p.anim.leftLegX, 0, 0, LeftLegFront, false);
            DrawRotate(p.anim.rightLegX, 0, 0, RightLegFront, false);
            DrawRotate(p.anim.rightLegX, 0, 0, LeftLegBack, false);
            DrawRotate(p.anim.leftLegX, 0, 0, RightLegBack, false);
            UpdateVB();

            if (Utils.CaselessEquals(p.ModelName, "sheep_nofur"))
            {
                return;
            }
            ModelCache cache = game.ModelCache;

            gfx.BindTexture(cache.Textures[furIndex].TexID);
            DrawRotate(-p.HeadXRadians, 0, 0, FurHead, true);

            DrawPart(FurTorso);
            DrawRotate(p.anim.leftLegX, 0, 0, FurLeftLegFront, false);
            DrawRotate(p.anim.rightLegX, 0, 0, FurRightLegFront, false);
            DrawRotate(p.anim.rightLegX, 0, 0, FurLeftLegBack, false);
            DrawRotate(p.anim.leftLegX, 0, 0, FurRightLegBack, false);
            UpdateVB();
        }
예제 #2
0
 public BlockModel(Game game) : base(game)
 {
     cache    = game.ModelCache;
     Bobbing  = false;
     UsesSkin = false;
     Pushes   = false;
 }
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            minBB = info.MinBB[block];
            maxBB = info.MaxBB[block];
            fullBright = info.FullBright[block];
            if( info.IsSprite[block] ) {
                minBB = Vector3.Zero; maxBB = Vector3.One;
            }
            if( info.IsAir[block] ) return;
            index = 0;

            // isometric coords size: cosY * -scale - sinY * scale
            // we need to divide by (2 * cosY), as the calling function expects size to be in pixels.
            scale = size / (2 * cosY);
            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            pos = Utils.RotateY( Utils.RotateX( pos, cosX, -sinX ), cosY, -sinY );

            if( info.IsSprite[block] ) {
                XQuad( block, 0f, TileSide.Right );
                ZQuad( block, 0f, TileSide.Back );
            } else {
                XQuad( block, Make( maxBB.X ), TileSide.Left );
                ZQuad( block, Make( minBB.Z ), TileSide.Back );
                YQuad( block, Make( maxBB.Y ), TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
예제 #4
0
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            blockHeight = info.Height[block];
            index = 0;
            scale = size;

            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            pos = Utils.RotateY( Utils.RotateX( pos, cosX, -sinX ), cosY, -sinY );

            if( info.IsSprite[block] ) {
                DrawXFace( block, 0f, TileSide.Right );
                DrawZFace( block, 0f, TileSide.Back );
            } else {
                DrawXFace( block, scale, TileSide.Left );
                DrawZFace( block, -scale, TileSide.Back );
                DrawYFace( block, scale * blockHeight, TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
예제 #5
0
        protected override void DrawModel(Player p)
        {
            IGraphicsApi api = game.Graphics;

            api.BindTexture(GetTexture(p.MobTextureId));
            DrawHeadRotate(-p.PitchRadians, 0, 0, Head);

            DrawPart(Torso);
            DrawRotate(p.anim.legXRot, 0, 0, LeftLegFront);
            DrawRotate(-p.anim.legXRot, 0, 0, RightLegFront);
            DrawRotate(-p.anim.legXRot, 0, 0, LeftLegBack);
            DrawRotate(p.anim.legXRot, 0, 0, RightLegBack);
            UpdateVB();

            if (!Fur)
            {
                return;
            }
            ModelCache cache = game.ModelCache;

            api.BindTexture(cache.Textures[furIndex].TexID);
            DrawHeadRotate(-p.PitchRadians, 0, 0, FurHead);

            DrawPart(FurTorso);
            DrawRotate(p.anim.legXRot, 0, 0, FurLeftLegFront);
            DrawRotate(-p.anim.legXRot, 0, 0, FurRightLegFront);
            DrawRotate(-p.anim.legXRot, 0, 0, FurLeftLegBack);
            DrawRotate(p.anim.legXRot, 0, 0, FurRightLegBack);
            UpdateVB();
        }
예제 #6
0
        /// <summary> Sends the updated vertex data to the GPU. </summary>
        protected void UpdateVB()
        {
            ModelCache cache = game.ModelCache;

            game.Graphics.UpdateDynamicIndexedVb(
                DrawMode.Triangles, cache.vb, cache.vertices, index);
            index = 0;
        }
예제 #7
0
        /// <summary> Sends the updated vertex data to the GPU. </summary>
        protected void UpdateVB()
        {
            ModelCache cache = game.ModelCache;

            game.Graphics.UpdateDynamicVb_IndexedTris(
                cache.vb, cache.vertices, index);
            index = 0;
        }
예제 #8
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            try {
                Options.Load();
            } catch( IOException ) {
                Utils.LogWarning( "Unable to load options.txt" );
            }
            ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 );
            Keys = new KeyMap();
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            defaultIb = Graphics.MakeDefaultIb();

            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Graphics.PrintGraphicsInfo();
            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( this );
            EnvRenderer = new StandardEnvRenderer( this );
            if( IPAddress == null ) {
                Network = new Singleplayer.SinglePlayerServer( this );
            } else {
                Network = new NetworkProcessor( this );
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam = new FirstPersonCamera( this );
            thirdPersonCam = new ThirdPersonCamera( this );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            Graphics.SetVSync( this, true );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            Title = Utils.AppName;
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
예제 #9
0
 public IModel( Game game )
 {
     this.game = game;
     graphics = game.Graphics;
     cache = game.ModelCache;
 }
예제 #10
0
 public IModel(Game game)
 {
     this.game = game;
     graphics  = game.Graphics;
     cache     = game.ModelCache;
 }
예제 #11
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
            defaultIb = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ChatLines = Options.GetInt( OptionsKey.ChatLines, 1, 30, 12 );
            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            Drawer2D.UseBitmappedChat = !Options.GetBool( OptionsKey.ArialChatFont, false );

            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            LocalPlayer.SpeedMultiplier = Options.GetInt( OptionsKey.Speed, 1, 50, 10 );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( this );
            EnvRenderer = new StandardEnvRenderer( this );
            if( IPAddress == null ) {
                Network = new Singleplayer.SinglePlayerServer( this );
            } else {
                Network = new NetworkProcessor( this );
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam = new FirstPersonCamera( this );
            thirdPersonCam = new ThirdPersonCamera( this );
            forwardThirdPersonCam = new ForwardThirdPersonCamera( this );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            bool vsync = Options.GetBool( OptionsKey.VSync, true );
            Graphics.SetVSync( this, vsync );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            Graphics.WarnIfNecessary( Chat );
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
예제 #12
0
 public BlockModel(Game game) : base(game)
 {
     cache = game.ModelCache;
 }