本文整理汇总了C#中Vector.Sub方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Sub方法的具体用法?C# Vector.Sub怎么用?C# Vector.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.Sub方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateNormal
/**
* CalculateNormal
*/
private void CalculateNormal()
{
Vector ba = new Vector();
Vector bc = new Vector();
Normal = new Vector();
ba.Sub(Vertices[0], Vertices[1]);
bc.Sub(Vertices[2], Vertices[1]);
Normal.Cross(bc, ba);
Normal.Normalize();
}
示例2: Intersect
/**
* Intersect
*
* @param ray
* @param pt
* @return boolean
*/
public override bool Intersect(Ray ray, IntersectPt pt)
{
Vector OC = new Vector();
double l2OC, tCA, t2HC;
OC.Sub(Origin, ray.GetOrigin());
l2OC = OC.SquaredLength();
tCA = OC.Dot(ray.GetDirection());
if(l2OC >= RadiusSquare && tCA <= 0)
{
return (false);
}
t2HC = RadiusSquare - l2OC + tCA * tCA;
if(t2HC < 0)
{
return (false);
}
if(l2OC <= RadiusSquare)
{
pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
if(pt.GetT() < pt.GetThreshold())
{
return (false);
}
pt.SetEnter(false);
pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
}
else
{
pt.SetT(tCA - (double)System.Math.Sqrt(t2HC));
pt.SetEnter(true);
if(pt.GetT() < pt.GetThreshold())
{
pt.SetT(tCA + (double)System.Math.Sqrt(t2HC));
pt.SetEnter(false);
}
pt.GetIntersection().Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, pt.GetT());
}
pt.SetIntersectObj(this);
GetCachePt().Set(ray.GetID(), pt);
return (true);
}
示例3: Normalize
public void Normalize(Vector vector)
{
vector.Sub(avgs, vector); // shift
vector.Multiply(istds, vector); // scale
}
示例4: FindNormal
/**
* FindNormal
*
* @param point
* @param normal
*/
public override void FindNormal(Point point, Vector normal)
{
normal.Sub(point, Origin);
normal.Normalize();
}
示例5: RenderScene
/**
* RenderScene
*/
public void RenderScene(Canvas canvas, int width, int section, int nsections)
{
Vector view = camera.GetViewDir();
Vector up = camera.GetOrthoUp();
Vector plane = new Vector();
Vector horIncr = new Vector();
Vector vertIncr = new Vector();
double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV());
double xlen = ylen * canvas.GetWidth() / canvas.GetHeight();
Point upleft = new Point();
Point upright = new Point();
Point lowleft = new Point();
Point basepoint = new Point();
Point current;
Ray eyeRay = new Ray();
int ypixel, xpixel;
RayID = 1;
plane.Cross(view, up);
view.Scale(camera.GetFocalDist());
up.Scale(ylen);
plane.Scale(-xlen);
upleft.FindCorner(view, up, plane, camera.GetPosition());
plane.Negate();
upright.FindCorner(view, up, plane, camera.GetPosition());
up.Negate();
plane.Negate();
lowleft.FindCorner(view, up, plane, camera.GetPosition());
horIncr.Sub(upright, upleft);
horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth()));
vertIncr.Sub(lowleft, upleft);
vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight()));
basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()),
upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ()));
eyeRay.SetOrigin(camera.GetPosition());
int xstart = section * width / nsections;
int xend = xstart + width / nsections;
Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());
for(ypixel = 0; ypixel < canvas.GetHeight(); ypixel++)
{
current = new Point(basepoint);
for(xpixel = 0; xpixel < canvas.GetWidth(); xpixel++)
{
if(xpixel >= xstart && xpixel < xend)
{
Color color = new Color(0.0f, 0.0f, 0.0f);
eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin());
eyeRay.GetDirection().Normalize();
eyeRay.SetID(RayID);
this.RayID = this.RayID + 1;
Shade(octree, eyeRay, color, 1.0f, 0, 0);
canvas.Write(Brightness, xpixel, ypixel, color);
}
current.Add(horIncr);
}
basepoint.Add(vertIncr);
}
Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());
}