Exemple #1
0
        protected void updateHardwareBuffers()
        {
            if (mChainElementList.Count < 2)
            {
                return;
            }

            // Here. we need to compute the position of the camera in the coordinate system of the billboard chain.
            Vector3 eyePos = this.ParentNode._getDerivedOrientation().Inverse() *
                             (mCamera.GetDerivedPosition() - this.ParentNode._getDerivedPosition());

            IntPtr ptrBuff;
            uint   buffIdx   = 0;
            int    chainSize = mChainElementList.Count;

            mVD.vertexCount = (uint)chainSize * 2;

            // Setup the vertex coordinates
            HardwareVertexBufferSharedPtr pPosBuffer = mVD.vertexBufferBinding.getBuffer(POSITION_BINDING);

            ptrBuff = pPosBuffer.Get().Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
            // Compute the position of the vertices in the chain
            for (int i = 0; i < chainSize; i++)
            {
                myBillBoardChainElement bbe = (myBillBoardChainElement)mChainElementList[i];
                Vector3 chainTangent;
                if (i == 0)
                {
                    chainTangent = bbe.position - ((myBillBoardChainElement)mChainElementList[0]).position;
                }
                else if (i == chainSize - 1)
                {
                    chainTangent = ((myBillBoardChainElement)mChainElementList[chainSize - 1]).position -
                                   ((myBillBoardChainElement)mChainElementList[chainSize - 2]).position;
                }
                else
                {
                    chainTangent = ((myBillBoardChainElement)mChainElementList[i + 1]).position -
                                   ((myBillBoardChainElement)mChainElementList[i - 1]).position;
                }

                Vector3 p1 = bbe.position;

                Vector3 vP1ToEye       = eyePos - p1;
                Vector3 vPerpendicular = chainTangent.Cross(vP1ToEye);
                vPerpendicular.Normalize();
                vPerpendicular *= bbe.width;

                Vector3 pos0 = p1 - vPerpendicular;
                Vector3 pos1 = p1 + vPerpendicular;

                // Update the buffer with the 2 vertex positions
                MeshBuilderHelper.SetVertexFloat(ptrBuff, mVBVertexSize, buffIdx++, mVBPostOff,
                                                 pos0.x, pos0.y, pos0.z);
                MeshBuilderHelper.SetVertexFloat(ptrBuff, mVBVertexSize, buffIdx++, mVBPostOff,
                                                 pos1.x, pos1.y, pos1.z);
            }
            pPosBuffer.Get().Unlock();


            // Setup the diffuse color of the vertex
            HardwareVertexBufferSharedPtr pVertexColorBuffer = mVD.vertexBufferBinding.getBuffer(DIFFUSE_COLOR_BINDING);

            ptrBuff = pVertexColorBuffer.Get().Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
            buffIdx = 0;
            for (int i = 0; i < chainSize; i++)
            {
                Color col = ((myBillBoardChainElement)mChainElementList[i]).colour;

                MeshBuilderHelper.SetVertexFloat(ptrBuff, mVCBVertexSize, buffIdx++, mVCBrgbaOff,
                                                 ((float)col.R / 255.0f), ((float)col.G / 255.0f), ((float)col.B / 255.0f), ((float)col.A / 255.0f));
                MeshBuilderHelper.SetVertexFloat(ptrBuff, mVCBVertexSize, buffIdx++, mVCBrgbaOff,
                                                 ((float)col.R / 255.0f), ((float)col.G / 255.0f), ((float)col.B / 255.0f), ((float)col.A / 255.0f));
            }
            pVertexColorBuffer.Get().Unlock();


            // Setup the texture coordinates
            HardwareVertexBufferSharedPtr pTexCoordBuffer = mVD.vertexBufferBinding.getBuffer(TEXCOORD_BINDING);

            ptrBuff = pTexCoordBuffer.Get().Lock(HardwareBuffer.LockOptions.HBL_DISCARD);

            buffIdx = 0;
            for (int i = 0; i < chainSize; i++)
            {
                myBillBoardChainElement bbe = (myBillBoardChainElement)mChainElementList[i];

                MeshBuilderHelper.SetVertexFloat(ptrBuff, mTCVertexSize, buffIdx++, mTCBuvOff,
                                                 bbe.uTexCoord, 0.0f);
                MeshBuilderHelper.SetVertexFloat(ptrBuff, mTCVertexSize, buffIdx++, mTCBuvOff,
                                                 bbe.uTexCoord, 1.0f);
            }
            pTexCoordBuffer.Get().Unlock();
        }
Exemple #2
0
 public void insertChainElement(int index, myBillBoardChainElement e)
 {
     mChainElementList.Insert(index, e);
 }
Exemple #3
0
 public void addChainElement(myBillBoardChainElement e)
 {
     mChainElementList.Add(e);
 }
Exemple #4
0
 public void updateChainElement(int index, myBillBoardChainElement e)
 {
     mChainElementList[index] = e;
 }
Exemple #5
0
        protected override void CreateScene()
        {
            mSceneManager.SetSkyBox(true, "Examples/CloudyNoonSkyBox");

            mLog = LogManager.Singleton.createLog("DemoCustomObjects.log", false, true);
            mLog.LogMessage(string.Format("DemoCustomObjects log {0}", System.DateTime.Now));

            create4LineDebugOverLay();
            Show4LineDebugOverLay();

            Entity    e;
            SceneNode n;


            Plane plane = new Plane();

            plane.Normal.x = 0;
            plane.Normal.y = 1;
            plane.Normal.z = 0;
            plane.D        = 0;
            MeshManager.GetSingleton().CreatePlane("Myplane", "General", plane,
                                                   14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UnitZ);
            e = mSceneManager.CreateEntity("plane", "Myplane");
            e.SetMaterialName("Examples/GrassFloor");
            e.SetCastShadows(false);
            n = mSceneManager.GetRootSceneNode().CreateChildSceneNode("Myplane");
            n.AttachObject(e);


            //##MyLine3D test
            mLog.LogMessage("test line 0");
            myLine = new myLine3D();
            mLog.LogMessage("test line 1");
            myLine.addPoint(new Vector3(0.0f, 9.6f, 0.0f));
            myLine.addPoint(new Vector3(160.0f, 9.6f, 0.0f));
            myLine.addPoint(new Vector3(160.0f, 9.6f, 160.0f));
            myLine.addPoint(new Vector3(0.0f, 9.6f, 160.0f));
            myLine.addPoint(new Vector3(0.0f, 9.6f, 0.0f));
            mLog.LogMessage("test line 2");
            myLine.drawLines();

            mLog.LogMessage("test line 3");
            n = mSceneManager.GetRootSceneNode().CreateChildSceneNode("Line1");
            mLog.LogMessage("test line 4");
            n.AttachObject(myLine);
            mLog.LogMessage("test line 5");
            n.SetPosition(0.0f, 200.0f, 0.0f);
            //##

            /***/
            //## bill board chain
            mLog.LogMessage("test BBC 1");
            mBBC = new DemoCustomObjects.myBillBoardChain(mCamera, 1000);
            mBBC.setMaterial("DemoCustomObjects/smoketrail");
            for (int i = 0; i < 500; i++)
            {
                myBillBoardChainElement ce = new myBillBoardChainElement(
                    new Vector3((float)Math.Sin((double)i / 100.0 * 2.0 * Math.PI),
                                (float)Math.Cos((double)i / 100.0 * 2.0 * Math.PI),
                                (float)i / 100.0f),
                    0.1f,
                    (float)i / 10.0f,
                    Converter.GetColor(1.0f, 1.0f, 1.0f));
                mBBC.addChainElement(ce);
            }
            mBBC.updateBoundingBox();
            // Add it to the scene
            n = mSceneManager.GetRootSceneNode().CreateChildSceneNode("BBC");
            n.AttachObject(mBBC);
            n.SetPosition(0.0f, 100.0f, 0.0f);
            n.SetScale(50.0f, 50.0f, 50.0f);
            mLog.LogMessage("test BBC 2");
            //##
            /***/


            mCamera.Move(new Vector3(0, 300, 600));
            mCamera.LookAt = new Vector3(0, 0, -600);

            SetDebugCaption(2, "keys: Y updates and adds a new point");
            SetDebugCaption(3, "     U updates and deletes the new point");
        }