Пример #1
0
        void Render(IntPtr pParam)
        {
            pRender2D.Begin2D();

            TPoint2 pc;

            pc = new TPoint2((float)(350 + Math.Cos(counter / 200.0) * 200), (float)(350 + Math.Sin(counter / 200.0) * 80));
            TPoint2 ps = new TPoint2(1, 1);

            // make floating camera
            pRender2D.SetCamera(ref pc,                               //camera center
                                (float)Math.Sin(counter / 50.0) * 15, //camera angle
                                ref ps                                //camera scale
                                );
            pRender2D.ProjectScreenToCamera(ref stMouseOnScreen, out stMouseInCamera);

            pc = new TPoint2(-750f, -750f);
            ps = new TPoint2(2000f, 2000f);
            pRender2D.DrawTexture(pTextures[7], ref pc, ref ps, 0f, E_EFFECT2D_FLAGS.EF_TILE_TEXTURE);

            //draw stone layer with per vertex blending
            TColor4 white = TColor4.ColorWhite();
            TColor4 col = TColor4.ColorWhite(0);
            TPoint2 p1 = new TPoint2(0f, 225f);
            uint    x, y;

            pTextures[8].GetDimensions(out x, out y);
            TPoint2 pdim = new TPoint2((float)x, (float)y);

            pRender2D.SetVerticesColors(ref col, ref white, ref white, ref col);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref white, ref col, ref col, ref white);
            p1 = new TPoint2(0f + 256f, 225f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref white, ref col, ref col, ref col);
            p1 = new TPoint2(0f + 256f, 225f + 256f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref col, ref white, ref col, ref col);
            p1 = new TPoint2(0f, 225f + 256f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            //// set color mix to semi-transparent black for object shadows
            col = TColor4.ColorBlack(128);
            pRender2D.SetColorMix(ref col);

            for (int i = 0; i < MyMeshes.Length; i++) // all meshes with shadows except copter
            {
                MyMeshes[i].Draw();
            }

            zombie.Render();

            copter.Render((float)counter);

            pRender2D.End2D();
        }
Пример #2
0
        void DrawFont(TRectF screen)
        {
            string  txt;
            uint    width, height;
            TColor4 c;

            txt = "I'm rotating... +_+";
            pFontBold.GetTextDimensions(txt, out width, out height);
            c = TColor4.ColorWhite();
            pFontBold.Draw2D(screen.x + screen.width - width - 10f, 200, txt, ref c, counter % 360);

            txt = "I'm just right aligned text. -_-";
            pFontBold.GetTextDimensions(txt, out width, out height);
            pFontBold.Draw2D((int)(screen.x + screen.width - width), 10, txt, ref c);

            txt = "I have a shadow! ;-)";
            pFontBold.GetTextDimensions(txt, out width, out height);
            c = TColor4.ColorBlack();
            pFontBold.Draw2D((int)(screen.x + screen.width - width - 7f), 53, txt, ref c);
            c = TColor4.ColorWhite();
            pFontBold.Draw2D((int)(screen.x + screen.width - width - 10f), 50, txt, ref c);

            txt = "Cool colored me! ^_^";
            pFontBold.GetTextDimensions(txt, out width, out height);
            TColor4 c1 = TColor4.ColorRed();
            TColor4 c2 = TColor4.ColorGreen();

            pRender2D.SetVerticesColors(ref c1, ref c2, ref c1, ref c2);
            c = TColor4.ColorWhite();
            pFontBold.Draw2D(screen.x + screen.width - width - 10f, 100f, txt, ref c, 0, true);

            txt = "I'm randomly colored... >_<";
            pFont.Draw2D(screen.x + 5f, 10, txt, ref stRandomCol);

            txt = "I'm per vertex colored! -_0";
            TColor4 c3 = TColor4.ColorAqua();
            TColor4 c4 = TColor4.ColorOrange();

            pRender2D.SetVerticesColors(ref c3, ref c3, ref c4, ref c4);
            c = TColor4.ColorWhite();
            pFontBold.Draw2D(screen.x + 5f, 50f, txt, ref c, 0, true);

            txt = "А я могу говорить по-русски! [:-|";
            c   = TColor4.ColorRed();
            pFont.Draw2D(screen.x + 5f, 100, txt, ref c);

            txt = "I'm scaling... o_O";
            pFontBold.SetScale((float)Math.Abs(Math.Sin(counter / 50f)) * 2f);
            c = TColor4.ColorWhite();
            pFontBold.Draw2D(screen.x + 5f, 200, txt, ref c);
            pFontBold.SetScale(1f);

            txt = "I am just very brutal..!";
            pFontHard.GetTextDimensions(txt, out width, out height);
            c = TColor4.ColorOfficialOrange();
            pFontHard.Draw2D((int)(screen.x + (screen.width - width) / 2f), 300f, txt, ref c);
        }
Пример #3
0
        static void Render(IntPtr pParam)
        {
            string  txt = "Hello, world!";
            TColor4 color = TColor4.ColorWhite();
            uint    w, h;

            mainFont.GetTextDimensions(txt, out w, out h);
            mainFont.Draw2DSimple((int)((SCREEN_WIDTH - w) / 2), (int)((SCREEN_HEIGHT - h) / 2), txt, ref color);
        }
Пример #4
0
        public virtual void Draw()
        {
            if (!_pObjMan.IsDebugMode())
            {
                return;
            }
            TColor4 c = TColor4.ColorWhite();

            _pRender2D.DrawCircle(ref _stPos, (uint)(_fSize / 2f), 32, ref c);
            c = TColor4.ColorRed();
            _pRender2D.DrawCircle(ref _stPos, (uint)(_fSize * _fColScale / 2f), 32, ref c);
        }
Пример #5
0
        public override void Draw()
        {
            string res = _uiScore.ToString();

            uint w, h;

            _pFnt.SetScale(_fSize);
            _pFnt.GetTextDimensions(res, out w, out h);
            _pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL);
            TColor4 c = TColor4.ColorWhite((byte)(255 - _uiCounter * 5));

            _pFnt.Draw2D(_stPos.x - w / 2f, _stPos.y - h / 2f, res, ref c);
        }
Пример #6
0
        void Render(IntPtr pParam)
        {
            pTex.Draw2D(0, 0, ScreenWidth, ScreenHeight, 0, 0);

            uint width, height, framecount;

            TColor4 c = TColor4.ColorWhite();

            const string txt = AppCaption;

            pFont.GetTextDimensions(txt, out width, out height);
            pFont.Draw2DSimple((int)((ScreenWidth - width) / 2),
                               (int)((ScreenHeight - height) / 2), txt, ref c);

            pTexSprite.GetFrameSize(out width, out height);
            pTexSprite.FramesCount(out framecount);
            pTexSprite.Draw2DSimple((int)((ScreenWidth - width) / 2),
                                    5, (counter / 2) % framecount);
        }
Пример #7
0
        void Render(IntPtr pParam)
        {
            TColor4 c;
            uint    w, h;
            string  acTxt;

            // render game objects
            for (int i = 0; i < _clObjects.Count; i++)
            {
                _clObjects[i].Draw();
            }

            // render in-game user interface
            pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL);
            pFnt.SetScale(1f);

            // if player is dead draw message
            if (!IsPlayerExists())
            {
                acTxt = "You are dead! Press \"Enter\" to restart.";
                pFnt.GetTextDimensions(acTxt, out w, out h);
                c = TColor4.ColorRed();
                pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), (int)(Res.GameVpHeight - h) / 2, acTxt, ref c);
            }

            // draw help before game start
            if (_uiScore == 0)
            {
                acTxt = "Use \"Arrows\" to move and \"Space Bar\" to shoot.";
                pFnt.GetTextDimensions(acTxt, out w, out h);
                c = TColor4.ColorWhite();
                pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), (int)(Res.GameVpHeight - h), acTxt, ref c);
            }

            acTxt = "Score: " + _uiScore.ToString();
            pFnt.GetTextDimensions(acTxt, out w, out h);
            c = TColor4.ColorWhite();
            pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), 0, acTxt, ref c);
        }
Пример #8
0
        void RenderPlanetInToTexture()
        {
            TColor4 c = TColor4.ColorWhite(0); // set clear color here because SetRenderTarget will clear color buffer for us

            pRender.SetClearColor(ref c);
            pRender.SetRenderTarget(pTexPlanetRenderIn);

            pRender2D.Begin2D();

            TPoint2 pos = new TPoint2();
            TPoint2 dim = new TPoint2(256f, 256f);

            pRender2D.DrawTexture(pTexMask, ref pos, ref dim, 0f, E_EFFECT2D_FLAGS.EF_BLEND);

            pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_MASK);

            float texOffsetX = counter / 200f;

            // generate two triangles to form a quad and move their texture coordinates horizontally
            TVertex2[] quad =
            {
                new TVertex2(0f,     0f, texOffsetX,      0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f,   0f, 1f + texOffsetX, 0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f),
                new TVertex2(0f,     0f, texOffsetX,      0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f),
                new TVertex2(0f,   256f, 0f + texOffsetX, 1f, 1f, 1f, 1f, 1f)
            };

            pRender2D.DrawTriangles(pTexPlanet, ref quad[0], (uint)quad.Length, E_PRIMITIVE2D_FLAGS.PF_FILL);

            pRender2D.End2D();

            c = TColor4.ColorOfficialBlack();
            pRender.SetClearColor(ref c); // set clear color back
            pRender.SetRenderTarget(null);
        }
Пример #9
0
        void Render(IntPtr pParameter)
        {
            TRectF  sectionRect;
            uint    txt_w, txt_h;
            TColor4 white = TColor4.ColorWhite();;

            pRender2D.Begin2D();

            // First section with primitives. //
            sectionRect = new TRectF(0f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect); // here and below scissor test is used to prevent drawing something to another section of the screen

            DrawPrimitives(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec1 = "Primitives";

            pFont.GetTextDimensions(txtSec1, out txt_w, out txt_h);
            // here and below draw section label near the end of each section
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2), (int)(ScreenHeight / 2 - txt_h), txtSec1, ref white);

            // Second section with font rendering. //
            sectionRect = new TRectF(ScreenWidth / 2f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawFont(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec2 = "Fonts";

            pFont.GetTextDimensions(txtSec2, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2),
                               (int)(ScreenHeight / 2 - txt_h), txtSec2, ref white);

            // Third section with sprites. //
            sectionRect = new TRectF(0f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawSprites(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec3 = "Sprites";

            pFont.GetTextDimensions(txtSec3, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec3, ref white);

            // Fourth section with advanced techniques. //
            sectionRect = new TRectF(ScreenWidth / 2f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawAdvanced(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec4 = "Advanced";

            pFont.GetTextDimensions(txtSec4, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec4, ref white);

            pRender.DisableScissor(); // The way to turn off scissor test, you must do it manually before the end of the frame.

            pRender2D.End2D();
        }
Пример #10
0
        void DrawPrimitives(TRectF screen)
        {
            TColor4 c;
            TRectF  rect;

            rect = new TRectF(5f, 5f, 170f, 170f);
            c    = TColor4.ColorBlue();
            pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE);

            rect = new TRectF(10f, 10f, 160f, 160f);
            c    = TColor4.ColorGray();
            pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL);

            pRender2D.DrawTriangles(null, ref triangles[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL);

            for (int i = 0; i <= 12; i++)
            {
                TPoint2 p = new TPoint2(screen.x, screen.y) + new TPoint2(15f + 12 * i, 15f + 12 * i);
                c = TColor4.ColorTeal();
                pRender2D.DrawPoint(ref p, ref c, (uint)(1 + i));
            }

            for (int i = 0; i < 15; i++)
            {
                pRender2D.SetLineWidth((uint)(1 + i / 2));
                TPoint2 p  = new TPoint2(screen.width - i * 20, screen.height);
                TPoint2 p1 = new TPoint2(screen.width, screen.height - i * 20);
                c = TColor4.ColorOfficialOrange((byte)(255 - i * 17));
                pRender2D.DrawLine(ref p, ref p1, ref c);
            }

            pRender2D.SetLineWidth(2);
            TColor4 c1 = TColor4.ColorAqua(), c2 = TColor4.ColorFuchsia(), c3 = new TColor4(), c4 = new TColor4();

            pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the line
            c = new TColor4();
            TPoint2 p2 = new TPoint2(screen.width, 75f);
            TPoint2 p3 = new TPoint2(200f, screen.height);

            pRender2D.DrawLine(ref p2, ref p3, ref c, E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS);

            pRender2D.SetLineWidth(1);

            c1 = TColor4.ColorGray();
            c2 = TColor4.ColorMagenta();
            c3 = TColor4.ColorOrange();
            c4 = TColor4.ColorViolet();
            pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the rectangle
            rect = new TRectF(250f, 25f, 125f, 125f);
            pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_LINE | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS));

            c1 = TColor4.ColorBlack(0);
            c2 = TColor4.ColorGreen();
            c3 = TColor4.ColorGreen();
            c4 = TColor4.ColorBlack(0);
            pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4);
            rect = new TRectF(260f, 35f, 105f, 105f);
            pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_FILL | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS));

            p2 = new TPoint2(125f, 50f);
            c  = TColor4.ColorOrange();
            pRender2D.DrawCircle(ref p2, 40, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL);

            c = TColor4.ColorWhite();
            for (int i = 0; i < 6; i++)
            {
                pRender2D.DrawCircle(ref p2, (uint)(10 + i * 5), (uint)(4 + i * 2), ref c, E_PRIMITIVE2D_FLAGS.PF_LINE);
            }

            p2 = new TPoint2(200f, 250f);
            p3 = new TPoint2(110f, 34f);
            c  = TColor4.ColorViolet();
            pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL);

            pRender2D.SetLineWidth(3);
            p3 = new TPoint2(100f, 30f);
            c  = TColor4.ColorWhite();
            pRender2D.DrawEllipse(ref p2, ref p3, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE);

            p3 = new TPoint2(80f, 24f);
            c  = TColor4.ColorFuchsia();
            pRender2D.DrawEllipse(ref p2, ref p3, 8, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL);

            p3 = new TPoint2(30f, 75f);
            c  = TColor4.ColorOrange(100);
            pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL);

            pRender2D.DrawPolygon(null, ref star_polygon[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL);
        }
Пример #11
0
        void Render(IntPtr pParam)
        {
            // Attention!
            // The main thing you should keep in the mind is that matrix multiplication order should be
            // reversed when passing matrix to pRender3D->SetMatrix or pRender3D->MultMatrix methods.

            // camera setup
            // here and below matrix multiplication order is reversed
            TMatrix4x4 set = TMatrix4x4.MatrixRotate((float)(Math.Sin(uiCounter / 150f) * 65f), new TPoint3(0f, 1f, 0f)) *
                             TMatrix4x4.MatrixRotate(30f, new TPoint3(1f, 0f, 0f)) *
                             TMatrix4x4.MatrixTranslate(new TPoint3(0f, 0f, -2.5f)) *
                             TMatrix4x4.MatrixIdentity;

            pRender3D.SetMatrix(ref set);

            // Draw entire scene.

            // draw tiled grass floor

            // Some low-level things will be shown below, mainly for education purpose.
            // Of course, there is a way to do the same thing without using low-level API.

            pRender3D.PushMatrix(); // save current matrix

            // multiplicates current matrix with given one
            TMatrix4x4 mult = TMatrix4x4.MatrixScale(new TPoint3(8f, 8f, 8f)) *
                              TMatrix4x4.MatrixRotate(-90f, new TPoint3(1f, 0f, 0f));

            pRender3D.MultMatrix(ref mult);

            set = TMatrix4x4.MatrixScale(new TPoint3(8f, 8f, 8f));

            pCoreRenderer.SetMatrix(ref set, E_MATRIX_TYPE.MT_TEXTURE); // a simple way to tile texture

            // Here is the way for instant rendering of any custom geometry.

            pTexGrass.Bind(0); // current texture setup
            pRender3D.Draw(ref desc, E_CORE_RENDERER_DRAW_MODE.CRDM_TRIANGLE_STRIP, 4);

            set = TMatrix4x4.MatrixIdentity;

            pCoreRenderer.SetMatrix(ref set, E_MATRIX_TYPE.MT_TEXTURE); // return texture matrix to its normal state

            pRender3D.PopMatrix();                                      // return previous matrix

            // Ok, that's all with low-level things in this example.

            // turn off backface culling because of trees leaves (they will look better) and sprites rendering (we want txt and owl to be visible from both sides)
            pRender3D.ToggleBackfaceCulling(false);

            // draw some trees

            // turn on alpha test for correct rendering of trees leaves
            pRender3D.ToggleAlphaTest(true);

            // precalculate similar for all trees transformation part to make it faster
            TMatrix4x4 tree_rotate_and_scale = TMatrix4x4.MatrixScale(new TPoint3(2f, 2f, 2f)) *
                                               TMatrix4x4.MatrixRotate(-90f, new TPoint3(1f, 0f, 0f));

            // some copy-pasted code for each tree to draw all of them

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(2.3f, 0f, 1.2f));
            pRender3D.MultMatrix(ref mult);
            pTexTree1.Bind(0); // way to set current texture
            pMeshTree1.Draw();
            pRender3D.PopMatrix();

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(-2.15f, 0f, -1.75f));
            pRender3D.MultMatrix(ref mult);
            pTexTree1.Bind(0);
            pMeshTree1.Draw();
            pRender3D.PopMatrix();

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(-0.5f, 0f, -1f));
            pRender3D.MultMatrix(ref mult);
            pTexTree2.Bind(0);
            pMeshTree2.Draw();
            pRender3D.PopMatrix();

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(0.75f, 0f, 0.1f));
            pRender3D.MultMatrix(ref mult);
            pTexTree2.Bind(0);
            pMeshTree2.Draw();
            pRender3D.PopMatrix();

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(0.5f, 0f, -1.5f));
            pRender3D.MultMatrix(ref mult);
            pTexTree3.Bind(0);
            pMeshTree3.Draw();
            pRender3D.PopMatrix();

            pRender3D.PushMatrix();
            mult = tree_rotate_and_scale * TMatrix4x4.MatrixTranslate(new TPoint3(-0.75f, 0f, 0.25f));
            pRender3D.MultMatrix(ref mult);
            pTexTree3.Bind(0);
            pMeshTree3.Draw();
            pRender3D.PopMatrix();

            pRender3D.ToggleAlphaTest(false); // we don't need alphatest anymore

            // we use blending for further font and sprite rendering
            pRender3D.ToggleBlending(true);

            // draw text
            pRender3D.PushMatrix();

            const string txt       = "The very basics of the 3D graphics.";
            const float  txt_scale = 0.005f;

            uint w, h;

            pFont.GetTextDimensions(txt, out w, out h);

            mult = TMatrix4x4.MatrixScale(new TPoint3(txt_scale, txt_scale, txt_scale)) *
                   // tex is drawing in rather huge coordinates, so we will downscale it
                   TMatrix4x4.MatrixTranslate(new TPoint3(0f, h / 2f * txt_scale, 1.25f));           // move text up on half of it's height and little forward

            pRender3D.MultMatrix(ref mult);

            TColor4 c = TColor4.ColorOfficialOrange();

            pRender3D.SetColor(ref c); // set current color

            pFont.Draw3D(txt);

            c = TColor4.ColorWhite();
            pRender3D.SetColor(ref c); // return color back to white

            pRender3D.PopMatrix();

            // draw owl animated sprite as billboard
            pRender3D.PushMatrix();

            // here is a way to make a billboard sprite in 3D
            TMatrix4x4 cur_matrix = new TMatrix4x4();

            pRender3D.GetMatrix(out cur_matrix); // first we must get current matrix

            // now we set new current matrix
            TMatrix4x4 matr = TMatrix4x4.MatrixScale(new TPoint3((owlGoLeft ? -1f : 1f), 1f, 1f)) *
                                                          // the way to mirror sprite picture
                              TMatrix4x4.MatrixBillboard( // this function will remove any rotation from given matrix
                TMatrix4x4.MatrixScale(new TPoint3(0.35f, 0.35f, 0.35f)) *
                TMatrix4x4.MatrixTranslate(new TPoint3(owlX, 1f, -0.35f)) *
                cur_matrix);

            pRender3D.SetMatrix(ref matr);

            pTexOwl.Draw3D((uiCounter / 2) % 15); // fast way to render texture as square plane with size 1.0

            pRender3D.PopMatrix();

            pRender3D.ToggleBlending(false);
            pRender3D.ToggleBackfaceCulling(true); // turn backface culling back on here

            // draw monster
            pRender3D.PushMatrix();

            TPoint3 extents = new TPoint3();

            pModelZard.GetExtents(out extents); // retrieves dimensions of the model (ex. extents.x is a half of the models width)

            // here we will let monster go circles
            const float speed         = 1.2f;
            float       angle         = uiCounter / 75f;
            TPoint3     circle_center = new TPoint3(1f, 0f, 0.25f);

            mult = TMatrix4x4.MatrixRotate(-90f, new TPoint3(1f, 0f, 0f)) *
                   TMatrix4x4.MatrixRotate(angle * 180f / (float)Math.PI, new TPoint3(0f, -1f, 0f)) *
                   TMatrix4x4.MatrixTranslate(new TPoint3((float)(Math.Cos(angle) * speed), extents.z,
                                                          (float)(Math.Sin(angle) * speed)) + circle_center);

            pRender3D.MultMatrix(ref mult);

            pTexZard.Bind(0);

            // this model uses frame based animation, we just need to switch between meshes
            uint meshes_count;

            pModelZard.MeshsCount(out meshes_count);
            pModelZard.DrawMesh(uiCounter % meshes_count);

            pRender3D.PopMatrix();
        }
Пример #12
0
        void Init(IntPtr pParam)
        {
            // get subsystems

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out p_sub_sys);
            pResMan = (IResourceManager)p_sub_sys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out p_sub_sys);
            pInput = (IInput)p_sub_sys;
            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys);
            pRender = (IRender)p_sub_sys;
            pRender.GetRender2D(out pRender2D);

            // create arrays
            IEngineBaseObject pObj = null;

            pTextures = new ITexture[TexCount];
            pShadows  = new ITexture[ShadowCount];
            pMeshes   = new IMesh[MeshCount];

            // loading data
            pResMan.Load(RESOURCE_PATH + "sounds\\helicopter.wav", out pObj, 0);
            pSound = (ISoundSample)pObj;
            pSound.PlayEx(out pSoundChannel, E_SOUND_SAMPLE_PARAMS.SSP_LOOPED);

            for (int i = 0; i < TexCount; i++)
            {
                uint flags = TexNames[i].Contains("grass") ? (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR | E_TEXTURE_LOAD_FLAGS.TLF_COORDS_REPEAT) : (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D;
                pResMan.Load(RESOURCE_PATH + TexNames[i], out pObj, flags);
                pTextures[i] = (ITexture)pObj;
            }

            pTextures[6].SetFrameSize(256, 256); // zombie sprite splitting

            for (int i = 0; i < MeshCount; i++)
            {
                pResMan.Load(RESOURCE_PATH + MeshNames[i], out pObj, (uint)E_MESH_MODEL_LOAD_FLAGS.MMLF_FORCE_MODEL_TO_MESH);
                pMeshes[i] = (IMesh)pObj;
            }

            // render shadows
            for (int i = 0; i < MeshCount; i++)
            {
                RenderMeshToTexture(out pShadows[i], pMeshes[i], pTextures[i]);
            }

            // render rotor shadow
            pResMan.CreateTexture(out pShadows[5], null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8, E_TEXTURE_CREATION_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR);
            pRender.SetRenderTarget(pShadows[5]);
            TPoint2 coords = new TPoint2(128f, 128f);
            TColor4 col    = TColor4.ColorWhite();

            pRender2D.DrawCircle(ref coords, 100, 64, ref col, E_PRIMITIVE2D_FLAGS.PF_FILL);
            pRender.SetRenderTarget(null);


            // gather, fill and init 3d-objects data
            MyMeshes = new MyMesh[8]
            {
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(900f, 500f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(-250f, 300f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(800f, 200f), new TPoint3(400f, 400f, 400f), 225),
                new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2(0f, 450f), new TPoint3(300f, 300f, 400f), 175),
                new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2(50f, 750f), new TPoint3(300f, 300f, 300f), 175),
                new MyMesh(pMeshes[2], pTextures[2], pShadows[2], new TPoint2(500f, 150f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2(180f, 150f), new TPoint3(400f, 400f, 600f), 200),
                new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2(600f, 550f), new TPoint3(400f, 400f, 600f), 200, 90)
            };

            copter = new Copter(new MyMesh(pMeshes[4], pTextures[4], pShadows[4], new TPoint2(), new TPoint3(600, 600, 600), 200, 0, true), pTextures[5], pShadows[5]);
            zombie = new Zombie(pTextures[6]);
        }
Пример #13
0
        void Init(IntPtr pParam)
        {
            TMatrix4x4 mat = TMatrix4x4.MatrixIdentity;

            transform = new TTransformStack(ref mat);
            rand      = new Random();

            IEngineSubSystem p_sub_sys = null;

            IResourceManager p_res_man = null;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out p_sub_sys);
            p_res_man = (IResourceManager)p_sub_sys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys);
            p_render = (IRender)p_sub_sys;
            p_render.GetRender3D(out pRender3D);
            IEngineBaseObject p_obj = null;

            p_res_man.Load(RESOURCE_PATH + "textures\\floor.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            pTexFloor = (ITexture)p_obj;
            p_res_man.Load(RESOURCE_PATH + "sprites\\light.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pTexLight = (ITexture)p_obj;

            // some global lighting

            pRender3D.ToggleLighting(true);
            TColor4 col = TColor4.ColorBlack();

            pRender3D.SetGlobalAmbientLighting(ref col); // turn off ambient lighting

            // setup lights

            // use single directional light to simulate ambient lighting
            p_res_man.CreateLight(out pLightDirect);
            pLightDirect.SetType(E_LIGHT_TYPE.LT_DIRECTIONAL);
            col = TColor4.ColorGray();
            pLightDirect.SetColor(ref col); // dim light
            TPoint3 p3 = new TPoint3(-0.5f, 0.5f, 0.75f);

            pLightDirect.SetDirection(ref p3);
            pLightDirect.SetEnabled(true);

            // Position is ignored for direction lights but is used by engine for debug drawing.
            // Use "rnd3d_draw_lights 1" console command to debug lights.
            p3 = new TPoint3(0f, 7.5f, 0f);
            pLightDirect.SetPosition(ref p3);

            // create light for the table-lamp
            p_res_man.CreateLight(out pLightSpot);
            pLightSpot.SetType(E_LIGHT_TYPE.LT_SPOT);
            col = TColor4.ColorYellow();
            pLightSpot.SetColor(ref col);
            pLightSpot.SetSpotAngle(100f);
            p3 = new TPoint3(0.15f, 0f, -1f);
            pLightSpot.SetDirection(ref p3);
            pLightSpot.SetEnabled(true);

            // create and setup materials and load models

            ITexture  p_tex;
            IMaterial p_mat;

            // desk
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk.dmd", out p_obj, 0);
            pMdlDesk = (IModel)p_obj;
            pMdlDesk.SetModelMaterial(p_mat);

            // table-lamp
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp.dmd", out p_obj, 0);
            pMdlLamp = (IModel)p_obj;
            pMdlLamp.SetModelMaterial(p_mat);

            // chair
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair.dmd", out p_obj, 0);
            pMdlChair = (IModel)p_obj;
            pMdlChair.SetModelMaterial(p_mat);

            // music box
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\mbox_d.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\music_box.dmd", out p_obj, 0);
            pMdlMusicBox = (IModel)p_obj;
            pMdlMusicBox.SetModelMaterial(p_mat);

            // church
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church.dmd", out p_obj, 0);
            pModelChurch = (IModel)p_obj;
            pModelChurch.SetModelMaterial(p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorSilver();
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(25f);
            pModelChurch.SetMeshMaterial(0, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_roof.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            pModelChurch.SetMeshMaterial(1, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_main.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            pModelChurch.SetMeshMaterial(2, p_mat);

            // snow globe
            p_res_man.Load(RESOURCE_PATH + "meshes\\snow_globe.dmd", out p_obj, 0);
            pSnowGlobe = (IModel)p_obj;
            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorWhite();
            p_mat.SetDiffuseColor(ref col);
            pSnowGlobe.SetMeshMaterial(0, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorBrown();
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(25f);
            pSnowGlobe.SetMeshMaterial(2, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorWhite(100);
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(50f);
            p_mat.SetBlending(true, E_BLENDING_EFFECT.BE_NORMAL);

            // When material with blending is set model will sort mesh order for meshes with blending to be the last.
            pSnowGlobe.SetMeshMaterial(1, p_mat);

            // We will use black fog to simulate darkness.
            col = TColor4.ColorBlack();
            pRender3D.SetFogColor(ref col);
            pRender3D.SetLinearFogBounds(12.5f, 20f);
            pRender3D.ToggleFog(true);
        }