问题描述
你好,
谢谢您事先的帮助. :)
我一直在研究3D程序已经有一段时间了,它不使用DirectX或任何其他替代方法(作为一项技术挑战),在.NET框架中使用GDI +.到目前为止,它完全可以与基本照明一起使用,请浏览导航等内容.
到目前为止,在该程序中,当您手动选择任何3D世界中的三角形时,它将以黄色点亮.现在,我想在单击按钮时将该面/三角形集合挤出给定的整数值. (类似于Blender或3DS Max之类的程序)
我曾尝试使用Google搜索,但结果却被冰淇淋挤出机遮盖了:D:p
我想我要问的是正确方向的指针,或有关其背后数学的一些帮助.我可能缺少一些非常简单的内容.
在程序中
三角形结构只是3个位置向量的集合. (使用法线和幅值等方法的全部方法)
Hello,
Thank you for any help in advance. :)
I have been working on a 3D program for a while now that doesn''t use DirectX or any other alternative (As a technical challenge), Uses GDI+ in .NET framework. So far its fully working with basic lighting, walk around navigation e.t.c.
In the program so far when you make a manual selection of triangles in any 3D world it will illuminate them yellow. I would now like to extrude that face/triangle collection a given integer amount on a button click. (Similar to programs like blender or 3DS Max)
I have tried googling but my results are just clouded with ice-cream extruding machines :D :p
I suppose what i''m asking is pointers in the right direction or some help with the math behind it. I''m probably missing something quite simple.
In the program
Triangle structure is a just a collection of 3 location vectors. (With a whole load of methods for normal and magnitude and such like)
推荐答案
//define a vector (will be used also for points)
struct Vector3
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
//default constructor
public Vector3() {}
//constructs a vector from 2 points
public Vector3(Vector3 A, Vector3 B)
{
X = B.X - A.X;
Y = B.Y - A.Y;
Z = B.Z - A.Z;
}
//normalizes this vector
public void Normalize()
{
float d = Math.Sqrt(X * X + Y * Y + Z * Z);
if (d == 0)
return;
X /= d;
Y /= d;
Z /= d;
}
// returns the cross product between vectors u and v
static public Vector3 CrossProduct(Vector3 u, Vector3 v)
{
Vector3 w = new Vector3();
w.X = u.Y * v.Z - u.Z * v.Y;
w.Y = u.Z * v.X - u.X * v.Z;
w.Z = u.X * v.Y - u.Y * v.X;
return w;
}
}
//defines a face
struct Face
{
public Vector3 A { get; set; }
public Vector3 B { get; set; }
public Vector3 C { get; set; }
// returns a normalized normal vector
// use this vector for your extrusion
public Vector3 GetNormal()
{
Vector3 AB = new Vector3(A, B);
Vector3 AC = new Vector3(A, C);
Vector3 n = Vector3.CrossProduct(AB, AC);
n.Normalize();
return n;
}
}
这篇关于在3D空间中拉伸三角形集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!