我有两个关于OpenGL混合的问题.
1)我知道我必须首先绘制不透明的物体,然后从后面到前面绘制不透明的物体.所以我把它们放在一个列表中,取决于到中心的距离(0,0,0).但转换(旋转和平移)会影响我测量距离的"中心"吗?
2)其次,如果我绘制的项目是三角形,我该如何测量距离?它的灵魂?到它的中心点?
这可能是一个愚蠢的错误,但我看不到它?!我有定义几何的类和渲染该几何的类.现在它是每个顶点的基本三角形和颜色.
以下是定义所述几何对象数据的代码:
CGeometry* g = new CGeometry();
g->vertexes = new double[3*3];
g->vertexes[0] = 0;
g->vertexes[1] = 0;
g->vertexes[2] = 0;
g->vertexes[3] = 100;
g->vertexes[4] = 100;
g->vertexes[5] = 0;
g->vertexes[6] = 100;
g->vertexes[7] = 0;
g->vertexes[8] = 0;
g->colors = new double[12];
g->colors[0] = 1;
g->colors[1] = 1;
g->colors[2] = 0;
g->colors[3] = 1;
g->colors[4] = 1;
g->colors[5] = 0;
g->colors[6] = 1;
g->colors[7] = 0;
g->colors[8] = 0;
g->colors[9] = 1;
g->colors[10] = 1;
g->colors[11] = 0;
Run Code Online (Sandbox Code Playgroud)
以下是呈现所述数据的代码:
CGeometry* …Run Code Online (Sandbox Code Playgroud) 免责声明:背景是我正在研究的一个项目,作为我的硕士学位的一部分.我猜它有资格作为家庭作业.
(随意跳到底线)
弯曲的3D表面通常显示为一组非常小的三角形.每个三角形都具有以下属性:
这样当它们全部显示在一起时,就会产生光滑表面的错觉.这类似于使用均匀颜色的像素来获得平滑图像的错觉的方式.
我的项目涉及生成和显示构成给定曲面的所有三角形.假设我有生成一组三角形的代码,我该如何显示它们?
生成三角形集的代码是Python.我更喜欢使用Python来显示三角形,但我并不挑剔.
当输入是三角形的3个角的坐标时,如何使用Python在3D中显示三角形.
在Linked in iphone应用程序中,我注意到他们有一个tableview,看到下面的图片看起来有一个三角形指示器向上.

请注意tableview单元格如何有一个向上指向的小三角形,并且是tableview单元格的一部分.
三角形是图像的--- ^ ---部分.
我在想.你如何使用这个三角形指示器创建一个UITableView,这个效果叫什么?
谢谢
问题是创建一个函数,该函数将三个数字作为输入,并根据这三个数字是否可以形成一个三角形来返回 true 或 false。如果任意两条边之和大于第三条边,则三个数字可以形成一个三角形。
我的回答是:
def is_triangle(a,b,c)
if a+b > c
return true
elsif a+c>b
return true
elsif b+c>a
return true
else
return false
end
end
Run Code Online (Sandbox Code Playgroud)
问题是:我假设的错误返回一直返回真实。请帮忙!
我试图绕过头:
http://msdn.microsoft.com/en-us/library/bb196409.aspx
并且参考不多.它简短,模糊,你可以从中学到什么.
我想创建一个方法,它采用Triangle =(一个3个向量的类)的列表,并渲染它,然后能够用颜色或纹理填充它.
有人能解释一下上面提到的方法吗?因为我正在尝试的是不起作用.我试过添加一个三角形.我在下面的理解,请纠正我错在哪里.
创建"一个三角形"时的方法:
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleStrip,
"array of 3 VertexPositionColor?",
0,
(3? 9?),
"I have no clue what to put here and why I should put it here?",
"What do I put here?",
"If 1 triangle, value should be = 1? 1 Triangle = 1 Primitive"
);
Run Code Online (Sandbox Code Playgroud)
我需要做什么才能做到这一点?根据我传递给我的方法的三角形数量,我是否渲染以及哪些值会根据有多少个三角形而改变?
...如果成功(希望有时候)我该如何填写?
请,没有模糊的简短答案,因为参考文献非常好.
我正在编写Quick Hull算法,其中包括检查点是否位于三角形内.为此,我创建了以下两个函数,如果该点在内部则返回true,否则返回false.
然而,结果是安静意外的意义上的一些点被正确分类,而一些不是,我无法弄清楚问题.有人可以帮我验证我写的代码是否正确.方法是我使用向量来确定一个点是否与三角形的每个边缘的顶点位于同一侧.代码是:
public boolean ptInside(Point first, Point last, Point mx, Point cur) {
boolean b1 = pointInside(first, last, mx, cur);
boolean b2 = pointInside(last, mx, first, cur);
boolean b3 = pointInside(first, mx, last, cur);
return b1 && b2 && b3;
}
public boolean pointInside(Point first, Point last, Point mx, Point cur) {
int x1 = last.xCo - first.xCo;
int y1 = last.yCo - first.yCo;
int x2 = mx.xCo - first.xCo;
int y2 = mx.yCo - first.yCo;
int x3 = …Run Code Online (Sandbox Code Playgroud) 任务是找到一个至少有500个除数的三角形数.
例如28有6个除数: 1,2,4,7,14,28
我的代码适用于多达200个除数,但对于500,它会永远运行...
有没有办法优化代码.比如我想过动态优化和memoization,但找不到办法呢?
int sum = 0;
int counter = 0;
int count = 1;
bool isTrue = true;
while (isTrue)
{
counter = 0;
sum += count;
for (int j = 1; j <= sum; j++)
{
if (sum % j == 0)
{
counter++;
if (counter == 500)
{
isTrue = false;
Console.WriteLine("Triangle number: {0}", sum);
break;
}
}
}
count++;
}
Console.WriteLine("Number of divisors: {0}", counter);
Run Code Online (Sandbox Code Playgroud) 这部分代码行为不端.我想绘制一个用户定义的圆圈网格,每个圆圈都有一个7种颜色的设置列表中的随机颜色.随机数生成器应该这样做.圆圈的网格被绘制得很好,它的颜色让我感到悲伤.我似乎每格最多两种颜色,前十二种是一种颜色,其余颜色是第二种颜色.奇怪的是,因为代码应循环通过颜色生成器,然后绘制一个圆圈并重复.请帮我找一些麻烦的线条,花太多时间自己尝试!
忽略对JEWEL_HEIGHT和类似的引用,它们只是与程序相关的变量名.
int columns = int.Parse(textBoxColumns.Text);
int rows = int.Parse(textBoxRows.Text);
for (int y = 0; (y < rows * 20); y += JEWEL_HEIGHT)
{
for (int x = 0; (x < columns * 20); x += JEWEL_WIDTH)
{
Color brushColor = (Color.Red);
Random randGen = new Random();
int randColor = randGen.Next(7);
if (randColor == 0)
brushColor = (Color.Red);
else if (randColor == 1)
brushColor = (Color.Orange);
else if (randColor == 2)
brushColor = (Color.Yellow);
else if (randColor == 3)
brushColor …Run Code Online (Sandbox Code Playgroud) 如何RectangleF在 C# 中轻松克隆(复制)a?
显然有一些不优雅的方法可以做到这一点,例如new RectangleF(r.Location, r.size),但是肯定有一个.Copyor.Clone方法隐藏在某处吗?但这些都不适合我编译,也似乎没有复制构造函数。我怀疑有一些简单的 C# 标准方法可以复制任何结构,但我还没有找到。
如果重要的话,我的真正目标是创建一个返回矩形偏移版本的方法(因为,令人惊讶的是,RectangleF没有这样的内置 - 它只有一个变异器方法)。我对此最好的尝试是:
public static RectangleF Offset(RectangleF r, PointF offset) {
PointF oldLoc = r.Location;
return new RectangleF(new PointF(oldLoc.X+offset.X, oldLoc.Y+offset.Y), r.Size);
}
Run Code Online (Sandbox Code Playgroud)
(令人震惊的是缺少加法运算符,这使得它变得更加丑陋PointF,但这是另一个问题。)有没有更简单的方法来做到这一点?