本文整理汇总了C#中Point3.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Point3.Normalize方法的具体用法?C# Point3.Normalize怎么用?C# Point3.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point3
的用法示例。
在下文中一共展示了Point3.Normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Triangle
public Triangle (Point3 a, Point3 b, Point3 c, Point3 na, Point3 nb, Point3 nc, Point3 ta, Point3 tb, Point3 tc, Material material) : base(material) {
this.p0 = a;
this.p1 = b;
this.p2 = c;
if(na == null || nb == null || nc == null) {
Point3 norm = new Point3();
Point3.Cross(p1.X-p0.X, p1.Y-p0.Y, p1.Z-p0.Z, p2.X-p0.X, p2.Y-p0.Y, p2.Z-p0.Z, out norm.X, out norm.Y, out norm.Z);
norm.Normalize();
this.n0 = this.n1 = this.n2 = norm;
}
else {
this.n0 = na;
this.n1 = nb;
this.n2 = nc;
}
if(ta == null || tb == null || tc == null) {
this.t0 = Point3.DummyPoint;
this.t1 = Point3.DummyPoint;
this.t2 = Point3.DummyPoint;
this.bumpx = Point3.DummyPoint;
this.bumpy = Point3.DummyPoint;
}
else {
this.t0 = ta;
this.t1 = tb;
this.t2 = tc;
double txa = tb.X-ta.X;
double tya = tb.Y-ta.Y;
double txb = tc.X-ta.X;
double tyb = tc.Y-ta.Y;
double frac = txb*tya-txa*tyb;
double alpha, beta, gamma;
if(Math.Abs(frac) >= Maths.GlobalEpsilon) {
frac = 1.0d/frac;
alpha = -tyb*frac;
beta = tya*frac;
gamma = 1.0d-alpha-beta;
this.bumpx = new Point3(a.X*gamma+b.X*alpha+c.X*beta,
a.Y*gamma+b.Y*alpha+c.Y*beta,
a.Z*gamma+b.Z*alpha+c.Z*beta);
this.bumpx.Normalize();
alpha = txb*frac;
beta = -txa*frac;
gamma = 1.0d-alpha-beta;
this.bumpy = new Point3(a.X*gamma+b.X*alpha+c.X*beta,
a.Y*gamma+b.Y*alpha+c.Y*beta,
a.Z*gamma+b.Z*alpha+c.Z*beta);
this.bumpy.Normalize();
}
else {
this.bumpx = Point3.DummyPoint;
this.bumpy = Point3.DummyPoint;
}
}
}
示例2: TestNormalizedRotateLikeZVector
public void TestNormalizedRotateLikeZVector()
{
Point3 norm, p;
Random rand = new Random();
for(int i = 0x00; i < TestParameters.PointTest; i++) {
double x = 2.0*rand.NextDouble()-1.0d;
double y = 2.0d*rand.NextDouble()-1.0d;
double z = 2.0d*rand.NextDouble()-1.0d;
p = new Point3(x, y, z);
p.Normalize();
norm = new Point3(0.0d, 0.0d, 1.0d);
norm.NormalizedRotateLikeZVector(p.X, p.Y, p.Z);
Assert.IsTrue(Math.Abs(norm.X-p.X) <= Math.Sqrt(Maths.GlobalEpsilon));
Assert.IsTrue(Math.Abs(norm.Y-p.Y) <= Math.Sqrt(Maths.GlobalEpsilon));
Assert.IsTrue(Math.Abs(norm.Z-p.Z) <= Math.Sqrt(Maths.GlobalEpsilon));
}
}
示例3: Parse
public static Matrix4 Parse(string toParse)
{
if(toParse == null || toParse == string.Empty) {
return null;
}
toParse = toParse.Trim().ToLower();
Match m = rgx.Match(toParse);
if(m.Success) {
if(m.Groups["id"].Captures.Count > 0x00) {
return new Matrix4();
}
else if(m.Groups["rotxyz"].Captures.Count > 0x00) {
double theta = double.Parse(m.Groups["theta"].Value);
switch(m.Groups["dim"].Value) {
case "x":
return Matrix4.CreateRotateXMatrix(theta);
case "y":
return Matrix4.CreateRotateYMatrix(theta);
default :
return Matrix4.CreateRotateZMatrix(theta);
}
}
else if(m.Groups["rotv"].Captures.Count > 0x00) {
double theta = double.Parse(m.Groups["theta"].Value);
Point3 u = new Point3(double.Parse(m.Groups["ux"].Value), double.Parse(m.Groups["uy"].Value), double.Parse(m.Groups["uz"].Value));
u.Normalize();
return CreateRotateMatrix(u, theta);
}
else if(m.Groups["shift"].Captures.Count > 0x00) {
Point3 u = new Point3(double.Parse(m.Groups["ux"].Value), double.Parse(m.Groups["uy"].Value), double.Parse(m.Groups["uz"].Value));
return CreateShiftMatrix(u);
}
else if(m.Groups["scale"].Captures.Count > 0x00) {
Point3 u;
if(m.Groups["uy"].Captures.Count > 0x00) {
u = new Point3(double.Parse(m.Groups["ux"].Value), double.Parse(m.Groups["uy"].Value), double.Parse(m.Groups["uz"].Value));
}
else {
double xyz = double.Parse(m.Groups["ux"].Value);
u = new Point3(xyz, xyz, xyz);
}
return CreateScaleMatrix(u);
}
else if(m.Groups["matrix"].Captures.Count > 0x00) {
double m00 = double.Parse(m.Groups["theta"].Value);
double m01 = double.Parse(m.Groups["ux"].Value);
double m02 = double.Parse(m.Groups["uy"].Value);
double m03 = double.Parse(m.Groups["uz"].Value);
double m10 = double.Parse(m.Groups["m10"].Value);
double m11 = double.Parse(m.Groups["m11"].Value);
double m12 = double.Parse(m.Groups["m12"].Value);
double m13 = double.Parse(m.Groups["m13"].Value);
double m20 = double.Parse(m.Groups["m10"].Value);
double m21 = double.Parse(m.Groups["m11"].Value);
double m22 = double.Parse(m.Groups["m12"].Value);
double m23 = double.Parse(m.Groups["m13"].Value);
return new Matrix4(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);
}
}
return null;
}
示例4: RebuildMatrix
public void RebuildMatrix () {
if(!this.dirty) {
return;
}
this.dirty = false;
Point3 forward = this.lookAt-this.position;
forward.Normalize();
Point3 right = new Point3(forward.Z, 0.0d, -forward.X);
right.Normalize();
Point3 up = Point3.CrossNormalize(forward, right);
forward.Normalize();
this.matrix.LoadColumns(right, up, forward);
this.matrix.RotateZ(this.roll);
this.matrix.Shift(this.position);
}