如何为球体(网格)设置点击事件? [英] How to set a click event for a Sphere (Mesh)?

查看:76
本文介绍了如何为球体(网格)设置点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上图中您可以看到我的应用程序的一部分。我加载具有不同值的文件,然后解析它们。然后绘制3D坐标系以显示Lab色彩空间。要绘制每个球体,请使用Mesh-函数:

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.

谢谢您的帮助!

推荐答案

解决方案:

选择教程

这篇关于如何为球体(网格)设置点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆