1

3D Device

In the picture above you can see a part of my application. I load a file with different values and afterwards I parse them. Then I draw a 3D coordinate system to show the Lab color space. To draw each sphere I use the Mesh - function:

/// <summary>
/// Vertex für die Kugel
/// </summary>
struct Vertex
{
    public float x, y, z; // Position of vertex in 3D space
    public int color;     // Diffuse color of vertex

    /// <summary>
    /// Konstruktor der Vertex
    /// </summary>
    /// <param name="_x">X(A) - Position</param>
    /// <param name="_y">Y(L) - Position</param>
    /// <param name="_z">Z(B) - Position</param>
    /// <param name="_color">Die Farbe</param>
    public Vertex(float _x, float _y, float _z, int _color)
    {
        x = _x; y = _y; z = _z;
        color = _color;
    }

    // Das Format des Vertex
    public static readonly VertexFormats FVF_Flags = VertexFormats.Position | VertexFormats.Diffuse;
}

/// <summary>
/// Erstellt das Mesh
/// </summary>
/// <param name="device">Das 3D Device</param>
/// <param name="color">Die Farbe der Kugel</param>
/// <param name="labValues">Die Lab Werte der Kugel</param>
public void createMesh(Device device, Color color, params float[] labValues)
{
    // Erstellt die Kugel mit der Anbindung an das Device
    mesh = Mesh.Sphere(device, radius, slices, stacks);
    // Kopiert das Mesh zum Erstellen des VertexArrays
    Mesh tempMesh = mesh.Clone(mesh.Options.Value, Vertex.FVF_Flags, device);
    // Erstellt den VertexArray
    Vertex[] vertData = (Vertex[])tempMesh.VertexBuffer.Lock(0, typeof(Vertex), LockFlags.None, tempMesh.NumberVertices);

    // Weist jedem Vertex die Farbe und die Position zu
    for (int i = 0; i < vertData.Length; ++i)
    {
        vertData[i].color = color.ToArgb();
        vertData[i].x += labValues[1];
        vertData[i].y += labValues[0] - 50f;
        vertData[i].z += labValues[2];
    }

    // Gibt den VertexBuffer in der Kopie frei
    tempMesh.VertexBuffer.Unlock();
    // Löscht den Mesh aus dem Speicher
    mesh.Dispose();
    // Legt die Kopie in der Meshinstanz ab
    mesh = tempMesh;
}

One of the functions is to zoom the device. Now I want to add a click event for each sphere to show any informations. But I have no idea how to implement this event. The sphere-object doesn't support any events.

Thank you for your help!!

Jerdak
  • 3,997
  • 1
  • 24
  • 36
Maxim
  • 317
  • 1
  • 5
  • 13

2 Answers2

1

I Don't think it is possible if there are no handlers for a click, but alternative would be to use some sort of transparent overlay panel and trigger the click event on that, then on click get the x and y positions of the mouse and try to locate the sphere from the underlying panel, you can then load the information from that sphere and display.

Just a suggestion and to kick off the conversations for alternate solutions

CR41G14
  • 5,464
  • 5
  • 43
  • 64
0

The solution:

Picking Tutorial

Maxim
  • 317
  • 1
  • 5
  • 13
  • I'm facing a similar problem and the solution that you posted is not active anymore. Can you please tell me what that was? Thanks in advance. – Pratham Sehgal Aug 26 '17 at 07:02