public void MouseMove(int x, int y) { if (this.mouseDownFlag) { IViewCamera camera = this.Camera; if (camera == null) { return; } Vertex back = this.back; Vertex right = this.right; Vertex up = this.up; Size bound = this.bound; Point downPosition = this.downPosition; { float deltaX = -horizontalRotationFactor * (x - downPosition.X) / bound.Width; float cos = (float)Math.Cos(deltaX); float sin = (float)Math.Sin(deltaX); Vertex newBack = new Vertex( back.X * cos + right.X * sin, back.Y * cos + right.Y * sin, back.Z * cos + right.Z * sin); back = newBack; right = up.VectorProduct(back); back.Normalize(); right.Normalize(); } { float deltaY = verticalRotationFactor * (y - downPosition.Y) / bound.Height; float cos = (float)Math.Cos(deltaY); float sin = (float)Math.Sin(deltaY); Vertex newBack = new Vertex( back.X * cos + up.X * sin, back.Y * cos + up.Y * sin, back.Z * cos + up.Z * sin); back = newBack; up = back.VectorProduct(right); back.Normalize(); up.Normalize(); } camera.Position = camera.Target + back * (float)((camera.Position - camera.Target).Magnitude()); camera.UpVector = up; this.back = back; this.right = right; this.up = up; this.downPosition.X = x; this.downPosition.Y = y; } }
/// <summary> /// Gets the surface normal. /// </summary> /// <param name="parent">The parent.</param> /// <returns></returns> public Vertex GetSurfaceNormal(Polygon parent) { // Do we have enough vertices for a normal? if (indices.Count < 3) { return(new Vertex(0, 0, 0)); } Vertex v1 = parent.Vertices[indices[0].Vertex]; Vertex v2 = parent.Vertices[indices[1].Vertex]; Vertex v3 = parent.Vertices[indices[2].Vertex]; Vertex va = v1 - v2; Vertex vb = v2 - v3; return(va.VectorProduct(vb)); }
public Vertex GetSurfaceNormal(Arc parent) { // Do we have enough vertices for a normal? if (indices.Count < 3) { return(new Vertex(0, 0, 0)); } Vertex v1 = parent.StartPoint; Vertex v2 = parent.SecondPoint; Vertex v3 = parent.EndPoint; Vertex va = v1 - v2; Vertex vb = v2 - v3; return(va.VectorProduct(vb)); }
/// <summary> /// Tests the order of the points. /// /// Seen in the direction, indicated by the third parameter. /// </summary> /// <param name = "p1"> First point. </param> /// <param name = "p2"> Second point. </param> /// <param name = "viewDir"> View direction from which the sense of rotation should be calculated. </param> /// <exception cref="InvalidOperationException">if the points lie on a line</exception> public bool areClockwise(Vertex p1, Vertex p2, Vertex viewDir) { Vertex u = p2 - this; u.Normalize(); Vertex v = p1 - this; v.Normalize(); Vertex w = u.VectorProduct(v); double test = w.ScalarProduct(viewDir); if (Math.Abs(test) < 0.000001) { throw new InvalidOperationException("All points are on one line!"); } return(test < 0); }