public static Matrix4d Multiply(this Matrix4d left, Matrix4d right) { Matrix4d result; Matrix4d.Mult(ref left, ref right, out result); return result; }
public Camera() { cameraToWorld = Matrix4d.Identity; WorldToCamera = Matrix4d.Identity; Sensor = new Sensor(); Lens = new ThinLens(); }
/** * @see <a href="gluLookAt.html">gluLookAt</a> */ public void look_at(double eyex, double eyey, double eyez, double centerx, double centery, double centerz, double upx, double upy, double upz) { Matrix4d matrix = new Matrix4d (); Vector4d eye = new Vector4d (eyex, eyey, eyez, 1.0); Vector4d center = new Vector4d (centerx, centery, centerz, 1.0); Vector4d up = new Vector4d (upx, upy, upz, 1.0); Vector4d forward = new Vector4d (); Vector4d side = new Vector4d (); //-- make rotation matrix // forward = center - eye forward.minus (center, eye).normalize (); // side = (forward x up), then normalized side.cross (forward, up).normalize (); // up = side x forward up.cross (side, forward); /* [side_x up_x -forward_x 0] * [side_y up_y -forward_y 0] * [side_z up_z -forward_z 0] * [ 0 0 0 1] */ matrix.set_column (side, up, forward.negate (), Vector4d.ZERO); matrix.set_row (3, 0.0, 0.0, 0.0, 1.0); gl.mult_matrixd (matrix.m); //-- translate eye to origin gl.translated (-eyex, -eyey, -eyez); }
public static Matrix FromMatrix4d(Matrix4d m) { Matrix ret = new Matrix(); ret.M11 = (float)m[0, 0]; ret.M12 = (float)m[0, 1]; ret.M13 = (float)m[0, 2]; ret.M14 = (float)m[0, 3]; ret.M21 = (float)m[1, 0]; ret.M22 = (float)m[1, 1]; ret.M23 = (float)m[1, 2]; ret.M24 = (float)m[1, 3]; ret.M31 = (float)m[2, 0]; ret.M32 = (float)m[2, 1]; ret.M33 = (float)m[2, 2]; ret.M34 = (float)m[2, 3]; ret.M41 = (float)m[3, 0]; ret.M42 = (float)m[3, 1]; ret.M43 = (float)m[3, 2]; ret.M44 = (float)m[3, 3]; return ret; }
public Sensor() { Plane = new Plane() { Normal = -Vector3d.UnitZ }; Width = 1.0; RasterSize = new Size(1, 1); Shift = new Vector3d(0, 0, 2); senzorToCamera = Matrix4d.Identity; CameraToSenzor = Matrix4d.Identity; tilt = Vector3d.Zero; }
/// <summary>Transform a Normal by the (transpose of the) given Matrix</summary> /// <remarks> /// This version doesn't calculate the inverse matrix. /// Use this version if you already have the inverse of the desired transform to hand /// </remarks> /// <param name="norm">The normal to transform</param> /// <param name="invMat">The inverse of the desired transformation</param> /// <param name="result">The transformed normal</param> public static void TransformNormalInverse(ref Vector3d norm, ref Matrix4d invMat, out Vector3d result) { result.X = norm.X * invMat.Row0.X + norm.Y * invMat.Row0.Y + norm.Z * invMat.Row0.Z; result.Y = norm.X * invMat.Row1.X + norm.Y * invMat.Row1.Y + norm.Z * invMat.Row1.Z; result.Z = norm.X * invMat.Row2.X + norm.Y * invMat.Row2.Y + norm.Z * invMat.Row2.Z; }
/// <summary>Transform a direction vector by the given Matrix /// Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored. /// </summary> /// <remarks> /// It is incorrect to call this method passing the same variable for /// <paramref name="result"/> as for <paramref name="vec"/>. /// </remarks> /// <param name="vec">The vector to transform</param> /// <param name="mat">The desired transformation</param> /// <param name="result">The transformed vector</param> public static void TransformVector(ref Vector3d vec, ref Matrix4d mat, out Vector3d result) { result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X; result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y; result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z; }
private double CheckNewPointDistance(int iPoint, Matrix4d myMatrix, List <Vertex> pointsTarget, List <Vertex> pointsSource) { Vertex p1 = pointsTarget[iPoint]; Vertex p2 = pointsSource[iPoint]; List <Vertex> tempPointReference = new List <Vertex>(); List <Vertex> tempPointToBeMatched = new List <Vertex>(); tempPointReference.Add(p1); tempPointToBeMatched.Add(p2); List <Vertex> tempPointRotate = MathUtils.TransformPoints(tempPointToBeMatched, myMatrix); double dist = PointUtils.CalculateTotalDistance(tempPointReference, tempPointRotate); return(dist); }
private static bool CheckIfMatrixIsOK(Matrix4d myMatrix) { //ContainsNaN for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (double.IsNaN(myMatrix[i, 0])) { return(false); } } } return(true); }
public static Matrix4d buildCanonicalOrientationEuclidean(Point4d a, Point4d b) { Point4d orientation = new Point4d(b.x - a.x, b.y - a.y, b.z - a.z); //float r = Mathf.Sqrt(orientation.x * orientation.x + orientation.y * orientation.y + orientation.z * orientation.z); float theta = Mathf.Atan(orientation.y / orientation.x); float phi = Mathf.Atan(Mathf.Sqrt(orientation.x * orientation.x + orientation.y * orientation.y) / orientation.z); Matrix4d rotationMat = new Matrix4d(); rotationMat.rotX(theta); Matrix4d rotationMatResult = new Matrix4d(); rotationMatResult.rotZ(phi); rotationMatResult *= rotationMat; return(rotationMatResult); //TODO: implement }
private double CheckNewPointDistance(int iPoint, Matrix4d myMatrix, PointCloudVertices pointsTarget, PointCloudVertices pointsSource) { Vertex p1 = pointsTarget[iPoint]; Vertex p2 = pointsSource[iPoint]; PointCloudVertices tempPointReference = new PointCloudVertices(); PointCloudVertices tempPointToBeMatched = new PointCloudVertices(); tempPointReference.Add(p1); tempPointToBeMatched.Add(p2); PointCloudVertices tempPointRotate = MathUtilsVTK.TransformPoints(tempPointToBeMatched, myMatrix); double dist = PointCloudVertices.MeanDistance(tempPointReference, tempPointRotate); return(dist); }
static Point3d func(double motor1_angle, double motor2_angle, double laser_distance) { //******** D-H Table *************** Matrix4d A1 = T(0, 0, 0, 0); Matrix4d A2 = T(-motor1_angle, 0, 0, 90); Matrix4d A3 = T(-motor2_angle, 6, 62, 90); Matrix4d A4 = T(0, -(59.2 + laser_distance), 0, 0); Matrix4d M = A1 * A2 * A3 * A4; // Console.WriteLine(M); Point3d p = new Point3d(M[0, 3], M[1, 3], M[2, 3]); return(p); }
public static double AbsSumOfElements3D(this Matrix4d mat4d) { double sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum += Math.Abs(mat4d[i, j]); } } return(sum); }
/// <summary> /// Handle messages for the /// </summary> /// <param name="message"></param> /// <param name="returnValue"></param> /// <returns></returns> public override bool HandleMessage(String Topic, IMessage message, ref object returnValue) { Type messageType = message.GetType(); //Got a CameraMatrixMessage, update the local mvpMatrix if (messageType == typeof(CameraMatrixMessage)) { Matrix4d vpMatrix = (Matrix4d)message.GetData(); mvpMatrix = Matrix4d.CreateTranslation(Pos) * vpMatrix; mLogger.Debug("TestComponent got updated camera message"); return(true); } return(false); }
public static Matrix4d PutTheMatrix4dtogether(this Matrix4d mat4d, Vector3d T, Matrix3d Rotation) { //put the 4d matrix together Matrix3d r3D = Rotation.Clone(); Matrix4d myMatrix = new Matrix4d(); myMatrix = myMatrix.FromMatrix3d(r3D); myMatrix[0, 3] = T.X; myMatrix[1, 3] = T.Y; myMatrix[2, 3] = T.Z; myMatrix[3, 3] = 1f; return(myMatrix); }
/// <summary> /// Goes round the central point (lookAt). /// One complete turn for the whole time interval. /// </summary> protected virtual void setTime(double newTime) { Debug.Assert(Start != End); time = newTime; // Here Start & End define a periodicity, not bounds! // change the camera position: double angle = MathHelper.TwoPi * (time - Start) / (End - Start); Vector3d radial = Vector3d.TransformVector(center0 - lookAt, Matrix4d.CreateRotationY(-angle)); center = lookAt + radial; direction = -radial; direction.Normalize(); prepare(); }
public static void Scale(this Matrix4d mat, double x, double y, double z) { if (x == 1 && y == 1 && z == 1) { return; } Matrix4d matrix = Matrix4d.Identity; matrix[0, 0] = x; matrix[1, 1] = y; matrix[2, 2] = z; Matrix4d.Mult(ref mat, ref matrix, out mat); }
/// <summary> /// Render a cylinder between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="width">The width of the cylinder.</param> /// <param name="view">The relevant view.</param> public void RenderCylinder(Location start, Location end, float width, View3D view) { float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * Utilities.PI180)) * Matrix4d.Scale(len, width, width) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); Models.Cylinder.Draw(); // TODO: Models reference in constructor - or client reference? }
public static double[,] GetTransformMatrixAsDoubleArray(Matrix4d matrix) { double[,] matrixAsDouble = new double[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { matrixAsDouble[i, j] = matrix[i, j]; } } return(matrixAsDouble); }
public void RenderSimpler() { if (!Visible || model.Meshes.Count == 0) { return; } TheClient.SetEnts(); Matrix4d mat = GetTransformationMatrix(); TheClient.MainWorldView.SetMatrix(2, mat); if (model.Meshes[0].vbo.Tex == null) { TheClient.Textures.White.Bind(); } model.Draw(); // TODO: Animation? }
public static float[,] GetTransformMatrixAsFloatArray(Matrix4d matrix) { float[,] matrixAsDouble = new float[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { matrixAsDouble[i, j] = Convert.ToSingle(matrix[i, j]); } } return(matrixAsDouble); }
/// <summary> /// Project the 2D coordinates from the screen coordinates outwards /// from the camera along the lookat vector, taking the frustrum /// into account. The resulting line will be run from the camera /// position along the view axis and end at the back clipping pane. /// </summary> /// <param name="x">The X coordinate on screen</param> /// <param name="y">The Y coordinate on screen</param> /// <returns>A line beginning at the camera location and tracing /// along the 3D projection for at least 1,000,000 units.</returns> public Line CastRayFromScreen(int x, int y) { var near = new Coordinate(x, Height - y, 0); var far = new Coordinate(x, Height - y, 1); var pm = Matrix4d.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(Camera.FOV), Width / (float)Height, 0.1f, 50000); var vm = Matrix4d.LookAt( new Vector3d(Camera.Location.X, Camera.Location.Y, Camera.Location.Z), new Vector3d(Camera.LookAt.X, Camera.LookAt.Y, Camera.LookAt.Z), Vector3d.UnitZ); var viewport = new[] { 0, 0, Width, Height }; var un = MathFunctions.Unproject(near, viewport, pm, vm); var uf = MathFunctions.Unproject(far, viewport, pm, vm); return((un == null || uf == null) ? null : new Line(un, uf)); }
/// <summary> /// Render a cylinder between two points. /// </summary> /// <param name="context">The sourcing render context.</param> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="width">The width of the cylinder.</param> /// <param name="view">The relevant view.</param> public void RenderCylinder(RenderContext context, Location start, Location end, float width, View3D view) { float len = (float)(end - start).Length(); Location vecang = MathUtilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * MathUtilities.PI180)) * Matrix4d.Scale(len, width, width) * Matrix4d.CreateRotationY((float)(vecang.Y * MathUtilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * MathUtilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); Models.Cylinder.Draw(context); }
public static CollisionResult CircleVsUnmovablePoint( double circleRadius, // Point position in game coords. // This is also the collision point. Vector2d pointPosition, // Circle position in game coords. Vector2d circlePosition, Vector2d circleVelocity ) { Vector2d collisionPoint = pointPosition; double velocityMagnitude = circleVelocity.Length; if ((circlePosition - pointPosition).Length < circleRadius) { //var newVelocity = (circlePosition - pointPosition).Normalized() * velocityMagnitude; Vector2d relativeCirclePosition = circlePosition - pointPosition; double relativeAngleOfCircleRadians = Math.Atan2(relativeCirclePosition.Y, relativeCirclePosition.X) - Math.PI / 2; var rotationMatrix = Matrix4d.CreateRotationZ(relativeAngleOfCircleRadians).Inverted(); Vector3d rotatedCirclePosition = Vector3d.Transform(new Vector3d(relativeCirclePosition.X, relativeCirclePosition.Y, 0.0), rotationMatrix); Vector3d rotatedCircleVelocity = Vector3d.Transform(new Vector3d(circleVelocity.X, circleVelocity.Y, 0.0), rotationMatrix); // make the circle's Y velocity positive in this frame of reference, Vector3d postCollisionRotatedCircleVelocity = new Vector3d(rotatedCircleVelocity.X, Math.Abs(rotatedCircleVelocity.Y), 0); // Rotate the new velocity back. Vector3d postCollisionCircleVelocity = Vector3d.Transform(postCollisionRotatedCircleVelocity, rotationMatrix.Inverted()); var newVelocity = postCollisionCircleVelocity.Xy * 1.005; // Return as a positive collision result. return(new CollisionResult { DidCollide = true, NewCirclePosition = circlePosition + newVelocity, NewCircleVelocity = newVelocity }); } else { // Return original velocity return(new CollisionResult { DidCollide = false, NewCirclePosition = circlePosition, NewCircleVelocity = circleVelocity }); } }
public void ComputeCoordinatesSubtree(Matrix4d parentTransform, Node parentNode) { if (parentNode.nodeNumDecendents == 0) { return; } float parentRadiusE = HyperbolicMath.euclideanDistance(parentNode.nodeHemsphereRadius); float lastPhi = 0.0f; Matrix4d rotPhi = HyperbolicTransformation.I4; Point4d childCenterAbsolute = new Point4d(); Point4d childPoleAbsolute = new Point4d(); foreach (Node child in parentNode.nodeChildren) { float childRadiusE = HyperbolicMath.euclideanDistance(child.nodeHemsphereRadius); float childPhi = child.nodeHemspherePhi; if (!(Mathf.Abs(childPhi - lastPhi) < EPSILON)) { lastPhi = childPhi; rotPhi = HyperbolicTransformation.buildZRotation(childPhi); } Matrix4d rot = HyperbolicTransformation.buildXRotation(child.nodeHemsphereTheta); rot = rot * rotPhi; childCenterAbsolute.set(parentRadiusE, 0.0f, 0.0f, 1.0f); rot.transform(childCenterAbsolute); float childPoleE = HyperbolicMath.euclideanDistance(parentNode.nodeHemsphereRadius + child.nodeHemsphereRadius); childPoleAbsolute.set(childPoleE, 0.0f, 0.0f, 1.0f); rot.transform(childPoleAbsolute); parentTransform.transform(childCenterAbsolute); parentTransform.transform(childPoleAbsolute); child.nodeEuclideanPosition = childCenterAbsolute; //graph.setNodeLayoutCoordinates(child, childCenterAbsolute); Matrix4d childTransform = HyperbolicTransformation.buildCanonicalOrientation(childCenterAbsolute, childPoleAbsolute); ComputeCoordinatesSubtree(childTransform, child); } }
//pipe 직경, 중심점 계산 private void button10_Click(object sender, EventArgs e) { try { Point3d p1 = null; Point3d p2 = null; Point3d p3 = null; p1 = Get_Point_from_Textbox(tbPoint1); p2 = Get_Point_from_Textbox(tbPoint2); p3 = Get_Point_from_Textbox(tbPoint3); if ((p1 != null) && (p2 != null) && (p3 != null)) { pipe1 = new Pipe(p1, p2, p3); pipe1.Set_Info_To_TextBox(tbCenter_P1, tbDiameter); //텍스트박스에 중점의 좌표와 직경을 표시해준다. } Console.WriteLine(); Console.WriteLine("pipe1's center point(Laser Origin)"); SHOW_N_S_W_E(pipe1._center_point); Console.WriteLine("pipe1's normal vector"); SHOW_N_S_W_E(pipe1._normal_vector); //******************************** double[] vec1 = { 1, 0, 0, pipe1._center_point.X }; double[] vec2 = { 0, 1, 0, pipe1._center_point.Y }; double[] vec3 = { 0, 0, 1, pipe1._center_point.Z }; double[] vec4 = { 0, 0, 0, 1 }; Matrix4d translation = new Matrix4d(vec1, vec2, vec3, vec4, (int)MyEnum.row_type); Console.WriteLine("translation to pipe1's center point"); Console.WriteLine(translation); Console.WriteLine(); Console.WriteLine("Inverse of translation"); Console.WriteLine(translation.Inverse()); inv_H = translation.Inverse(); } catch (Exception ex) { MessageBox.Show("세 개의 점 데이터가 필요합니다."); Console.WriteLine(ex.Message); } }
public void RenderGrass() { if (TheClient.MainWorldView.FBOid == FBOID.FORWARD_SOLID) { TheClient.s_forw_grass = TheClient.s_forw_grass.Bind(); GL.Uniform1(6, (float)TheClient.GlobalTickTimeLocal); GL.Uniform4(12, new OpenTK.Vector4(ClientUtilities.Convert(TheClient.MainWorldView.FogCol), TheClient.MainWorldView.FogAlpha)); GL.Uniform1(13, TheClient.CVars.r_znear.ValueF); GL.Uniform1(14, TheClient.ZFar()); GL.UniformMatrix4(1, false, ref TheClient.MainWorldView.PrimaryMatrix); } else if (TheClient.MainWorldView.FBOid == FBOID.MAIN) { TheClient.s_fbo_grass = TheClient.s_fbo_grass.Bind(); GL.UniformMatrix4(1, false, ref TheClient.MainWorldView.PrimaryMatrix); } else if (TheClient.MainWorldView.FBOid == FBOID.SHADOWS && TheClient.MainWorldView.TranspShadows) { TheClient.s_shadow_grass = TheClient.s_shadow_grass.Bind(); } else { return; } GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2DArray, 0); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2DArray, 0); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2DArray, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2DArray, TheClient.GrassTextureID); GL.Uniform1(6, (float)GlobalTickTimeLocal); GL.Uniform3(7, ClientUtilities.Convert(ActualWind)); TheClient.Rendering.SetColor(GetSunAdjust()); foreach (Chunk chunk in chToRender) { if (chunk.Plant_VAO != -1) { Matrix4d mat = Matrix4d.CreateTranslation(ClientUtilities.ConvertD(chunk.WorldPosition.ToLocation() * Chunk.CHUNK_SIZE)); TheClient.MainWorldView.SetMatrix(2, mat); GL.BindVertexArray(chunk.Plant_VAO); GL.DrawElements(PrimitiveType.Points, chunk.Plant_C, DrawElementsType.UnsignedInt, IntPtr.Zero); } } TheClient.isVox = true; TheClient.SetEnts(); }
public void DrawStereoscopy(Matrix4d transformacja) { GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One); GL.Begin(BeginMode.Lines); GL.Color3(0.6, 0.0, 0.0); var vertex = transformacja.Multiply(vertices[0]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[1]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[2]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[3]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[4]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[5]); GL.Vertex2(_projectionRight.Multiply(vertex).X, _projectionRight.Multiply(vertex).Y); GL.Color3(0.0, 0.0, 0.6); vertex = transformacja.Multiply(vertices[0]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[1]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[2]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[3]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[4]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); vertex = transformacja.Multiply(vertices[5]); GL.Vertex2(_projectionLeft.Multiply(vertex).X, _projectionLeft.Multiply(vertex).Y); GL.End(); var temp = _projectionLeft.Multiply(transformacja.Multiply(_coordinates)); WindowCoordinate = new Vector4d(temp.X * 720, temp.Y * 375, 0, 0); }
public static void TestScene(IRayScene sc, string param) { Debug.Assert(sc != null); // CSG scene: CSGInnerNode root = new CSGInnerNode(SetOperation.Union); root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel()); root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 0.6, 0.0, 0.0 }, 0.15, 0.8, 0.15, 16)); sc.Intersectable = root; // Background color: sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 }; // Camera: sc.Camera = new StaticCamera(new Vector3d(0.7, 3.0, -10.0), new Vector3d(0.0, -0.2, 1.0), 50.0); // Light sources: sc.Sources = new LinkedList <ILightSource>(); sc.Sources.Add(new AmbientLightSource(0.8)); sc.Sources.Add(new PointLightSource(new Vector3d(-5.0, 3.0, -3.0), 1.0)); // --- NODE DEFINITIONS ---------------------------------------------------- // Base plane Plane pl = new Plane(); pl.SetAttribute(PropertyName.COLOR, new double[] { 0.0, 0.2, 0.0 }); pl.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(0.5, 0.5, new double[] { 1.0, 1.0, 1.0 })); root.InsertChild(pl, Matrix4d.RotateX(-MathHelper.PiOver2) * Matrix4d.CreateTranslation(0.0, -1.0, 0.0)); // Cylinders Cylinder c = new Cylinder(); root.InsertChild(c, Matrix4d.RotateX(MathHelper.PiOver2) * Matrix4d.CreateTranslation(-2.1, 0.0, 1.0)); c = new Cylinder(); c.SetAttribute(PropertyName.COLOR, new double[] { 0.2, 0.0, 0.7 }); c.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(12.0, 1.0, new double[] { 0.0, 0.0, 0.3 })); root.InsertChild(c, Matrix4d.RotateY(-0.4) * Matrix4d.CreateTranslation(1.0, 0.0, 1.0)); c = new Cylinder(0.0, 100.0); c.SetAttribute(PropertyName.COLOR, new double[] { 0.1, 0.7, 0.0 }); root.InsertChild(c, Matrix4d.RotateY(0.2) * Matrix4d.CreateTranslation(5.0, 0.3, 4.0)); c = new Cylinder(-0.5, 0.5); c.SetAttribute(PropertyName.COLOR, new double[] { 0.8, 0.6, 0.0 }); root.InsertChild(c, Matrix4d.Scale(2.0) * Matrix4d.RotateX(1.2) * Matrix4d.CreateTranslation(2.0, 1.8, 16.0)); }
public void Draw(Matrix4d transformacja) { int k = 0; if (Q != null) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { k += 2; BezierArraysBasedOnGregory[0][i, j].Draw(transformacja, k, 1, 0, 0); //BezierArraysBasedOnGregory[1][i, j].Draw(transformacja, k, 0, 1, 0); //BezierArraysBasedOnGregory[2][i, j].Draw(transformacja, k, 0, 0, 1); } } } //foreach (var item in ControlArrayC1) //{ // for (int i = 0; i < 7; i++) // { // item[i].Draw(transformacja, 12, 1, 1, 1); // } //} foreach (var patch in PatchCollection) { patch.DrawPatch(transformacja); } //foreach (var point in EgdePoints) //{ // for (int i = 0; i < 4; i++) // { // point[0][i].Draw(transformacja, 10, 1, 1, 0); // point[1][i].Draw(transformacja, 10, 1, 1, 1); // } //} if (VectorsVisibility) { DrawVectors(transformacja); } }
protected override void setTime(double newTime) { time = newTime; // Animator was already Time-updated. if (!((MT.scene?.Animator ?? null) is ITimeDependentProperty pa) || pa == null || !pa.TryGetValue(name, ref translate)) { return; } // New translation vector. ToParent = origin * Matrix4d.CreateTranslation(translate); FromParent = ToParent.Inverted(); }
private static Matrix4d PutTheMatrix4together(Vector3d T, Matrix3d Rotation) { //put the 4d matrix together Matrix3d r3D = MatrixUtilsOpenTK.Matrix3dfromMatrix3d(Rotation); Matrix4d myMatrix = new Matrix4d(r3D); myMatrix[0, 3] = T.X; myMatrix[1, 3] = T.Y; myMatrix[2, 3] = T.Z; myMatrix[3, 3] = 1D; //myMatrix[0, 3] = T.X; //myMatrix[3, 1] = T.Y; //myMatrix[3, 2] = T.Z; //myMatrix[3, 3] = 1D; return(myMatrix); }
/// <summary> /// Render a line between two points. /// </summary> /// <param name="start">The initial point.</param> /// <param name="end">The ending point.</param> /// <param name="view">The relevant view.</param> public void RenderLine(Location start, Location end, View3D view) { // TODO: Efficiency! float len = (float)(end - start).Length(); Location vecang = Utilities.VectorToAngles(start - end); vecang.Yaw += 180; Matrix4d mat = Matrix4d.Scale(len, 1, 1) * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180)) * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180)) * Matrix4d.CreateTranslation(start.ToOpenTK3D()); view.SetMatrix(2, mat); GL.BindVertexArray(Line._VAO); GL.DrawElements(PrimitiveType.Lines, 2, DrawElementsType.UnsignedInt, IntPtr.Zero); }
public void PreRender(Model model, AABB box) { // TODO: Accelerate this: one big texture rather than 6 small ones? int[] ints = new int[6]; // TODO: Normals too! int fbo = GL.GenFramebuffer(); ints[0] = RenderSide(0, model, box, fbo, Vector3.UnitX, Vector3.UnitZ, Matrix4d.CreateOrthographicOffCenter(box.Min.Y, box.Max.Y, box.Min.Z, box.Max.Z, box.Min.X, box.Max.X)); ints[1] = RenderSide(1, model, box, fbo, -Vector3.UnitX, Vector3.UnitZ, Matrix4d.CreateOrthographicOffCenter(box.Max.Y, box.Min.Y, box.Min.Z, box.Max.Z, box.Min.X, box.Max.X)); ints[2] = RenderSide(2, model, box, fbo, Vector3.UnitY, Vector3.UnitZ, Matrix4d.CreateOrthographicOffCenter(box.Min.X, box.Max.X, box.Min.Z, box.Max.Z, box.Min.Y, box.Max.Y)); ints[3] = RenderSide(3, model, box, fbo, -Vector3.UnitY, Vector3.UnitZ, Matrix4d.CreateOrthographicOffCenter(box.Max.X, box.Min.X, box.Min.Z, box.Max.Z, box.Min.Y, box.Max.Y)); ints[4] = RenderSide(4, model, box, fbo, Vector3.UnitZ, Vector3.UnitX, Matrix4d.CreateOrthographicOffCenter(box.Min.Y, box.Max.Y, box.Min.X, box.Max.X, box.Min.Z, box.Max.Z)); ints[5] = RenderSide(5, model, box, fbo, -Vector3.UnitZ, Vector3.UnitX, Matrix4d.CreateOrthographicOffCenter(box.Max.Y, box.Min.Y, box.Min.X, box.Max.X, box.Min.Z, box.Max.Z)); GL.DeleteFramebuffer(fbo); model.LODHelper = ints; }
public double GetDivisions(Matrix4d transformacja, ObservableCollection <Point> temp) { int j = temp.Count; double length = 0; for (int i = 0; i < j - 1; i++) { Vector4d a = projekcja.Multiply(transformacja.Multiply(temp[i + 1])) - projekcja.Multiply(transformacja.Multiply(temp[i])); a.X *= 1440; a.Y *= 750; length += a.Length; } return(0.1 / length); }
public static Vector4d[] ExtractRowMajor(Matrix4d matrix) { var left = matrix.Column3 + matrix.Column0; var right = matrix.Column3 - matrix.Column0; var bottom = matrix.Column3 + matrix.Column1; var top = matrix.Column3 - matrix.Column1; var near = matrix.Column2; var far = matrix.Column3 - matrix.Column2; return new[] { NormalizePlane(left), NormalizePlane(right), NormalizePlane(bottom), NormalizePlane(top), NormalizePlane(near), NormalizePlane(far), }; }
/// <summary> /// Sets the value of this matrix to the float value of the /// passed matrix4d m1. /// </summary> /// <remarks> /// Sets the value of this matrix to the float value of the /// passed matrix4d m1. /// </remarks> /// <param name="m1">the matrix4d to be converted to float</param> public void Set(Matrix4d m1) { this.m00 = (float)m1.m00; this.m01 = (float)m1.m01; this.m02 = (float)m1.m02; this.m03 = (float)m1.m03; this.m10 = (float)m1.m10; this.m11 = (float)m1.m11; this.m12 = (float)m1.m12; this.m13 = (float)m1.m13; this.m20 = (float)m1.m20; this.m21 = (float)m1.m21; this.m22 = (float)m1.m22; this.m23 = (float)m1.m23; this.m30 = (float)m1.m30; this.m31 = (float)m1.m31; this.m32 = (float)m1.m32; this.m33 = (float)m1.m33; }
public Vector4d multiply_left(Matrix4d A) { return multiply_left (A, this); }
internal void Unproject(object viewport, Matrix4d projection, Matrix4d view, Matrix4d world) { //Microsoft.DirectX.Vector3 test = ConvertDX.FromVector3d(this); //test.Unproject(viewport, ConvertDX.FromMatrix4d(projection), ConvertDX.FromMatrix4d(view), ConvertDX.FromMatrix4d(world)); Viewport2d vp = ConvertDX.ToViewport2d((Microsoft.DirectX.Direct3D.Viewport)viewport); // Convert from viewport coordinates this.X = (this.X - vp.X) / vp.Width; this.Y = (vp.Height + vp.Y - this.Y) / vp.Height; // Make x/y range from -1 to 1 this.X = this.X * 2.0 - 1.0; this.Y = this.Y * 2.0 - 1.0; Matrix4d m = Matrix4d.Invert(world * view * projection); double w = 1.0; MultiplyMatrix(m, ref w); this.X /= w; this.Y /= w; this.Z /= w; }
/// <summary> Sets the value of this matrix to a copy of the /// passed matrix m1. /// </summary> /// <param name="m1">the matrix to be copied /// </param> public void set_Renamed(Matrix4d m1) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m00 = (float) m1.m00; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m01 = (float) m1.m01; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m02 = (float) m1.m02; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m03 = (float) m1.m03; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m10 = (float) m1.m10; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m11 = (float) m1.m11; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m12 = (float) m1.m12; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m13 = (float) m1.m13; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m20 = (float) m1.m20; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m21 = (float) m1.m21; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m22 = (float) m1.m22; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m23 = (float) m1.m23; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m30 = (float) m1.m30; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m31 = (float) m1.m31; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m32 = (float) m1.m32; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" m33 = (float) m1.m33; }
internal void TransformCoordinate(Matrix4d m) { this = new Point3d(this.X * m[0, 0] + this.Y * m[1, 0] + this.Z * m[2, 0] + m[3, 0], this.X * m[0, 1] + this.Y * m[1, 1] + this.Z * m[2, 1] + m[3, 1], this.X * m[0, 2] + this.Y * m[1, 2] + this.Z * m[2, 2] + m[3, 2]); }
public Matrix4d Set(Matrix4d matrix) { M00 = matrix.M00; M01 = matrix.M01; M02 = matrix.M02; M03 = matrix.M03; M10 = matrix.M10; M11 = matrix.M11; M12 = matrix.M12; M13 = matrix.M13; M20 = matrix.M20; M21 = matrix.M21; M22 = matrix.M22; M23 = matrix.M23; M30 = matrix.M30; M31 = matrix.M31; M32 = matrix.M32; M33 = matrix.M33; return this; }
public Matrix4d OuterCross(Vector4d v) { Matrix4d m = new Matrix4d(); m[0, 0] = x * v.x; m[0, 1] = x * v.y; m[0, 2] = x * v.z; m[0, 3] = x * v.w; m[1, 0] = y * v.x; m[1, 1] = y * v.y; m[1, 2] = y * v.z; m[1, 3] = y * v.w; m[2, 0] = z * v.x; m[2, 1] = z * v.y; m[2, 2] = z * v.z; m[2, 3] = z * v.w; m[3, 0] = w * v.x; m[3, 1] = w * v.y; m[3, 2] = w * v.z; m[3, 3] = w * v.w; return m; }
internal void Update(Matrix4d m) { //bottom (down) plane this.planes[0] = new Plane2d( m[0, 3] + m[0, 1], m[1, 3] + m[1, 1], m[2, 3] + m[2, 1], m[3, 3] + m[3, 1] ); //far plane this.planes[1] = new Plane2d( m[0, 3] - m[0, 2], m[1, 3] - m[1, 2], m[2, 3] - m[2, 2], m[3, 3] - m[3, 2] ); //right side plane this.planes[2] = new Plane2d( m[0, 3] - m[0, 0], m[1, 3] - m[1, 0], m[2, 3] - m[2, 0], m[3, 3] - m[3, 0] ); //left side plane this.planes[3] = new Plane2d( m[0, 3] + m[0, 0], m[1, 3] + m[1, 0], m[2, 3] + m[2, 0], m[3, 3] + m[3, 0] ); //near plane this.planes[4] = new Plane2d( m[0, 2], m[1, 2], m[2, 2], m[3, 2]); //top (up) plane this.planes[5] = new Plane2d( m[0, 3] - m[0, 1], m[1, 3] - m[1, 1], m[2, 3] - m[2, 1], m[3, 3] - m[3, 1] ); for (int count = 0; count < 6; count++) this.planes[count].Normalize(); }
/** * @see <a href="gluUnProject.html">gluUnProject</a> */ public double[] un_project(double window_x, double window_y, double window_z, double [] modelview, double [] projection, int [] viewport) { Matrix4d product = new Matrix4d (); Matrix4d.multiply (modelview, projection, product.m); if (product.invert () == null) return null; Vector4d A = new Vector4d (window_x, window_y, window_z, 1.0); // map x and y from window coordinates A.v [0] = (A.v [0] - viewport [0]) / viewport [2]; A.v [1] = (A.v [1] - viewport [1]) / viewport [3]; // map to range -1 to 1, A = 2*A - I A.scalar_multiply (2).scalar_minus (1); A.multiply_right (product); double d = A.v [3]; if (d == 0) return null; double [] result = new double [3]; // vs. 4 result [0] = A.v [0] / d; result [1] = A.v [1] / d; result [2] = A.v [2] / d; return result; }
public Matrix4d scalar_multiply(Matrix4d A, double d) { scalar_multiply (A.m, d, m); return this; }
public Matrix4d multiply(Matrix4d A, Matrix4d B) { double [] C = m; if (A == this || B == this) C = new double [16]; m = multiply (A.m, B.m, C); return this; }
/// <summary> /// Sets the value of this quaternion to the rotational component of /// the passed matrix. /// </summary> /// <remarks> /// Sets the value of this quaternion to the rotational component of /// the passed matrix. /// </remarks> /// <param name="m1">the matrix4d</param> public void Set(Matrix4d m1) { double ww = 0.25 * (m1.m00 + m1.m11 + m1.m22 + m1.m33); if (ww >= 0) { if (ww >= Eps2) { this.w = Math.Sqrt(ww); ww = 0.25 / this.w; this.x = (m1.m21 - m1.m12) * ww; this.y = (m1.m02 - m1.m20) * ww; this.z = (m1.m10 - m1.m01) * ww; return; } } else { this.w = 0; this.x = 0; this.y = 0; this.z = 1; return; } this.w = 0; ww = -0.5 * (m1.m11 + m1.m22); if (ww >= 0) { if (ww >= Eps2) { this.x = Math.Sqrt(ww); ww = 0.5 / this.x; this.y = m1.m10 * ww; this.z = m1.m20 * ww; return; } } else { this.x = 0; this.y = 0; this.z = 1; return; } this.x = 0.0; ww = 0.5 * (1.0 - m1.m22); if (ww >= Eps2) { this.y = Math.Sqrt(ww); this.z = m1.m21 / (2.0 * this.y); return; } this.y = 0; this.z = 1; }
/// <summary> /// Sets the value of this axis-angle to the rotational component of /// the passed matrix. /// </summary> /// <remarks> /// Sets the value of this axis-angle to the rotational component of /// the passed matrix. /// If the specified matrix has no rotational component, the value /// of this AxisAngle4d is set to an angle of 0 about an axis of (0,1,0). /// </remarks> /// <param name="m1">the matrix4d</param> public void Set(Matrix4d m1) { Matrix3d m3d = new Matrix3d(); m1.Get(m3d); x = (float)(m3d.m21 - m3d.m12); y = (float)(m3d.m02 - m3d.m20); z = (float)(m3d.m10 - m3d.m01); double mag = x * x + y * y + z * z; if (mag > Eps) { mag = Math.Sqrt(mag); double sin = 0.5 * mag; double cos = 0.5 * (m3d.m00 + m3d.m11 + m3d.m22 - 1.0); angle = (float)Math.Atan2(sin, cos); double invMag = 1.0 / mag; x = x * invMag; y = y * invMag; z = z * invMag; } else { x = 0.0f; y = 1.0f; z = 0.0f; angle = 0.0f; } }
/// <summary> /// Transform this point with the given <see cref="Matrix4d"/>. /// </summary> /// <param name='m'> /// The given transformation matrix. /// </param> public void Transform(Matrix4d m) { double newx = this.x * m.M11 + this.y * m.M12 + this.z * m.M13 + m.M14; double newy = this.x * m.M21 + this.y * m.M22 + this.z * m.M23 + m.M24; double newz = this.x * m.M31 + this.y * m.M32 + this.z * m.M33 + m.M34; this.x = newx; this.y = newy; this.z = newz; }
private void UpdateTransposeInverse() { if (!transposeInverseDirty) { return; } transposeInverseDirty = false; transposeInverse = Matrix4d.Scale(scale); // TODO: Apply rotation transposeInverse = Matrix4d.Mult(Matrix4d.CreateTranslation(translation), transposeInverse); transposeInverse.Invert(); transposeInverse.Transpose(); }
public Vector4d multiply_right(Vector4d V, Matrix4d A) { double [] B = v; if (V == this) B = new double [4]; v = multiply_right (V.v, A.m, B); return this; }
public static Matrix4d operator *(Matrix4d a, Matrix4d b) { Matrix4d ret = new Matrix4d(); ret.M00 = a.M00 * b.M00 + a.M01 * b.M10 + a.M02 * b.M20 + a.M03 * b.M30; ret.M01 = a.M00 * b.M01 + a.M01 * b.M11 + a.M02 * b.M21 + a.M03 * b.M31; ret.M02 = a.M00 * b.M02 + a.M01 * b.M12 + a.M02 * b.M22 + a.M03 * b.M32; ret.M03 = a.M00 * b.M03 + a.M01 * b.M13 + a.M02 * b.M23 + a.M03 * b.M33; ret.M10 = a.M10 * b.M00 + a.M11 * b.M10 + a.M12 * b.M20 + a.M13 * b.M30; ret.M11 = a.M10 * b.M01 + a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31; ret.M12 = a.M10 * b.M02 + a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32; ret.M13 = a.M10 * b.M03 + a.M11 * b.M13 + a.M12 * b.M23 + a.M13 * b.M33; ret.M20 = a.M20 * b.M00 + a.M21 * b.M10 + a.M22 * b.M20 + a.M23 * b.M30; ret.M21 = a.M20 * b.M01 + a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31; ret.M22 = a.M20 * b.M02 + a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32; ret.M23 = a.M20 * b.M03 + a.M21 * b.M13 + a.M22 * b.M23 + a.M23 * b.M33; ret.M30 = a.M30 * b.M00 + a.M31 * b.M10 + a.M32 * b.M20 + a.M33 * b.M30; ret.M31 = a.M30 * b.M01 + a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31; ret.M32 = a.M30 * b.M02 + a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32; ret.M33 = a.M30 * b.M03 + a.M31 * b.M13 + a.M32 * b.M23 + a.M33 * b.M33; return ret; }
public Vector4d multiply_right(Matrix4d A) { return multiply_right (this, A); }
/// <summary> Constructs a new matrix with the same values as the Matrix4d parameter.</summary> /// <param name="m1">The source matrix. /// </param> public Matrix4f(Matrix4d m1) { set_Renamed(m1); }
public Vector4d multiply_left(Matrix4d A, Vector4d V) { double [] B = v; if (V == this) B = new double [4]; v = multiply_left (A.m, V.v, B); return this; }
/// <summary> Sets the value of this axis-angle to the rotational component of /// the passed matrix. /// If the specified matrix has no rotational component, the value /// of this AxisAngle4f is set to an angle of 0 about an axis of (0,1,0). /// </summary> /// <param name="m1">the matrix4d /// </param> public void set_Renamed(Matrix4d m1) { Matrix3d m3d = new Matrix3d(); m1.get_Renamed(m3d); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" x = (float) (m3d.m21 - m3d.m12); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" y = (float) (m3d.m02 - m3d.m20); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" z = (float) (m3d.m10 - m3d.m01); double mag = x * x + y * y + z * z; if (mag > EPS) { mag = System.Math.Sqrt(mag); double sin = 0.5 * mag; double cos = 0.5 * (m3d.m00 + m3d.m11 + m3d.m22 - 1.0); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" angle = (float) System.Math.Atan2(sin, cos); double invMag = 1.0 / mag; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" x = (float) (x * invMag); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" y = (float) (y * invMag); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" z = (float) (z * invMag); } else { x = 0.0f; y = 1.0f; z = 0.0f; angle = 0.0f; } }
internal void Project(object viewport, Matrix4d projection, Matrix4d view, Matrix4d world) { //Microsoft.DirectX.Vector3 test = ConvertDX.FromVector3d(this); //test.Project(viewport, ConvertDX.FromMatrix4d(projection), ConvertDX.FromMatrix4d(view), ConvertDX.FromMatrix4d(world)); Viewport2d vp = ConvertDX.ToViewport2d((Microsoft.DirectX.Direct3D.Viewport)viewport); Matrix4d m = world * view * projection; double w = 1.0; MultiplyMatrix(m, ref w); this.X /= w; this.Y /= w; this.Z /= w; // Make x/y range from 0 to 1 this.X = this.X * 0.5 + 0.5; this.Y = this.Y * 0.5 + 0.5; // Convert to to viewport coordinates (Y is inverted) this.X = this.X * vp.Width + vp.X; this.Y = vp.Height - this.Y * vp.Height + vp.Y; }
internal void MultiplyMatrix(Matrix4d m, ref double w) { double wprev = w; w = this.X * m[0, 3] + this.Y * m[1, 3] + this.Z * m[2, 3] + wprev * m[3, 3]; this = new Point3d(this.X * m[0, 0] + this.Y * m[1, 0] + this.Z * m[2, 0] + wprev * m[3, 0], this.X * m[0, 1] + this.Y * m[1, 1] + this.Z * m[2, 1] + wprev * m[3, 1], this.X * m[0, 2] + this.Y * m[1, 2] + this.Z * m[2, 2] + wprev * m[3, 2]); }
public Matrix4d invert(Matrix4d A) { double [] B = m; if (A == this) B = new double [16]; m = invert (A.m, B); return A; }