How to apply click event on VertexBuffer in a DrawingSuface control in Silverlight 5 (3D)
-
Tuesday, April 10, 2012 6:11 AM
Hi All,
I'm working on Silverlight 5(3D) application using drawing surface control.
I'm drawing multiple cubes on a drawing surface control now, how do i get a trigger on click of the particular cube?
here is my code to add cubes to the drawing surface control
for (int i = 0; i < 5; i++) { VertexBuffer vbCube; vbCube = CreateCube(X, Y, Z, Length, Bredth, Depth, Color.Black,Color.Red); resourceGraphicDevice.SetVertexBuffer(vbCube); resourceGraphicDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12); } VertexBuffer CreateCube(float x,float y,float z, float length, float bredth, float depth, Color foreColor, Color backColor) { // cube vertices var vertexCollection = new VertexPositionColor[36]; // Front // C(x, y, z+bredth) // D(x+length, y, z+bredth) // A(x, y+depth, z+bredth) // B(x+length, y+depth, z+bredth) // A-----------------B // | | // | | // | | // C-----------------D // // Back // G(x, y, z) // H(x+length, y, z) // E(x, y+depth, z) // F(x+length, y+depth, z) // E-----------------F // | | // | | // | | // G-----------------H // front coordinates Vector3 cubeA = new Vector3(x, y + depth, z + bredth); Vector3 cubeB = new Vector3(x + length, y + depth, z + bredth); Vector3 cubeC = new Vector3(x, y, z + bredth); Vector3 cubeD = new Vector3(x + length, y, z + bredth); // back coordinates Vector3 cubeE = new Vector3(x, y + depth, z); Vector3 cubeF = new Vector3(x + length, y + depth, z); Vector3 cubeG = new Vector3(x, y, z); Vector3 cubeH = new Vector3(x + length, y, z); // front vertexCollection[0] = new VertexPositionColor(cubeA, foreColor); vertexCollection[1] = new VertexPositionColor(cubeB, foreColor); vertexCollection[2] = new VertexPositionColor(cubeC, backColor); vertexCollection[3] = new VertexPositionColor(cubeB, foreColor); vertexCollection[4] = new VertexPositionColor(cubeD, backColor); vertexCollection[5] = new VertexPositionColor(cubeC, backColor); // back vertexCollection[6] = new VertexPositionColor(cubeG, backColor); vertexCollection[7] = new VertexPositionColor(cubeF, foreColor); vertexCollection[8] = new VertexPositionColor(cubeE, foreColor); vertexCollection[9] = new VertexPositionColor(cubeH, backColor); vertexCollection[10] = new VertexPositionColor(cubeF, foreColor); vertexCollection[11] = new VertexPositionColor(cubeG, backColor); // top vertexCollection[12] = new VertexPositionColor(cubeE, foreColor); vertexCollection[13] = new VertexPositionColor(cubeF, foreColor); vertexCollection[14] = new VertexPositionColor(cubeA, foreColor); vertexCollection[15] = new VertexPositionColor(cubeF, foreColor); vertexCollection[16] = new VertexPositionColor(cubeB, foreColor); vertexCollection[17] = new VertexPositionColor(cubeA, foreColor); // bottom vertexCollection[18] = new VertexPositionColor(cubeH, backColor); vertexCollection[19] = new VertexPositionColor(cubeG, backColor); vertexCollection[20] = new VertexPositionColor(cubeC, backColor); vertexCollection[21] = new VertexPositionColor(cubeD, backColor); vertexCollection[22] = new VertexPositionColor(cubeH, backColor); vertexCollection[23] = new VertexPositionColor(cubeC, backColor); // left vertexCollection[24] = new VertexPositionColor(cubeC, backColor); vertexCollection[25] = new VertexPositionColor(cubeG, backColor); vertexCollection[26] = new VertexPositionColor(cubeA, foreColor); vertexCollection[27] = new VertexPositionColor(cubeA, foreColor); vertexCollection[28] = new VertexPositionColor(cubeG, backColor); vertexCollection[29] = new VertexPositionColor(cubeE, foreColor); // right vertexCollection[30] = new VertexPositionColor(cubeH, backColor); vertexCollection[31] = new VertexPositionColor(cubeD, backColor); vertexCollection[32] = new VertexPositionColor(cubeB, foreColor); vertexCollection[33] = new VertexPositionColor(cubeH, backColor); vertexCollection[34] = new VertexPositionColor(cubeB, foreColor); vertexCollection[35] = new VertexPositionColor(cubeF, foreColor); var vb = new VertexBuffer(resourceGraphicDevice, VertexPositionColor.VertexDeclaration, vertexCollection.Length, BufferUsage.WriteOnly); vb.SetData(0, vertexCollection, 0, vertexCollection.Length, 0); return vb; }
Now, from this code how do i get a click event of a particular cube....?
Nagarjuna Dilip

