我正在 SharpGL 中创建 3d 可视化(Visual Studio 2013 的扩展,我们可以在其中使用 OpenGL 库)。我想可视化四面体。它需要从多个点创建 - 用户在应用程序开始时定义向量的总和。我有一个字典,其中包含每个顶点的坐标,我在这两个类中计算:
public class Matrix4
{
private List<Tuple<int, int, int, int>> set = new List<Tuple<int, int, int, int>>();
public Matrix4()
{
}
public Matrix4(int vectorSum)
{
set = GiveMatrix4(vectorSum);
}
public List<Tuple<int, int, int, int>> GiveMatrix4(int vectorSum)
{
List<Tuple<int, int, int, int>> set1 = new List<Tuple<int, int, int, int>>();
for (int i = 0; i <= vectorSum; i++)
{
for (int j = 0; j <= vectorSum; j++)
{
for (int k = 0; k <= vectorSum; k++)
{
for (int l = 0; l <= vectorSum; l++)
{
Tuple<int, int, int, int> vector = new Tuple<int, int, int, int>(i, j, k, l);
if (AddValuesFromVector4(vector) == vectorSum)
{
set1.Add(vector);
continue;
}
}
}
}
}
return set1;
}
public int AddValuesFromVector4(Tuple<int,int,int,int> vector)
{
int sum = 0;
sum = vector.Item1 + vector.Item2 + vector.Item3 + vector.Item4;
return sum;
}
public List<Tuple<int, int, int, int>> Matrix4Set
{
get { return set; }
}
}
Matrix3 类切割一维,我有 3 个坐标的向量:
public class Matrix3
{
private Matrix4 matrix4;
private Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>> pairs = new Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>>();
private int vectorSum;
public Matrix3()
{
}
public Matrix3(int vectorSum)
{
this.vectorSum = vectorSum;
matrix4 = new Matrix4(vectorSum);
pairs = CreateMatrix3(matrix4.Matrix4Set);
}
public int VectorSum
{
get { return vectorSum; }
}
public Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>> CreateMatrix3(List<Tuple<int, int, int, int>> set)
{
Tuple<int, int, int> vector;
Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>> pair = new Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>>();
foreach (var item in set)
{
vector = new Tuple<int, int, int>(item.Item1 - item.Item2 - item.Item3 + item.Item4, item.Item1 + item.Item2 - item.Item3 - item.Item4, item.Item1 - item.Item2 + item.Item3 - item.Item4);
pair.Add(item, vector);
}
return pair;
}
public int Sum(Tuple<int, int, int> vector)
{
int suma = 0;
suma = (int)(vector.Item1 + vector.Item2 + vector.Item3);
return suma;
}
public Dictionary<Tuple<int, int, int, int>, Tuple<int, int, int>> Pairs
{
get { return pairs; }
}
public Matrix4 Matrix4
{
get { return matrix4; }
}
}
之后,我想从我的字典中创建点/球体,我将其保存在 Matrix3 类中:
gl.Begin(OpenGL.GL_POINTS);
gl.PointSize(10.0f);
foreach (var item in matrix3.Pairs.Values)
{
gl.Vertex((float)item.Item1, (float)item.Item2, (float)item.Item3);
}
不幸的是,它不起作用,我在屏幕上看不到任何东西。任何建议将不胜感激。在创建每个点/球体后,我需要旋转它们并根据我将在其他类中计算的度量附加到每个不同的颜色(但这是下一步,首先我想显示这些点/球体并旋转它们) .
我对 OpenGl 完全陌生,这就是我寻找任何样本的原因。
链接到整个项目并筛选我想要获得的内容: https ://drive.google.com/file/d/1IDwl46rdRa9IYxq7w8ZkF4LCeAsUH0mU/view?usp=sharing