public Cursor() { _coordinates = new Vector4d(0, 0, 0, 1); _windowCoordinate = new Vector4d(0, 0, 0, 1); CreateVertices(); _projection = MatrixProvider.ProjectionMatrix(); _projectionLeft = MatrixProvider.LeftProjectionMatrix(); _projectionRight = MatrixProvider.RightProjectionMatrix(); }
public void DrawStereoscopy(Matrix4d transformacja) { double StereoscopyMin = 1; GL.Enable(EnableCap.VertexProgramPointSize); GL.PointSize(3); GL.Begin(BeginMode.Points); //zmiana odleglosciu oczu Matrix4d projekcja = MatrixProvider.RightProjectionMatrix(); var a = projekcja.Multiply(transformacja.Multiply(_coordinates)); projekcja = MatrixProvider.LeftProjectionMatrix(); var b = projekcja.Multiply(transformacja.Multiply(_coordinates)); var c = a - b; c.X = c.X * 1440 / 2; c.Y = c.Y * 750 / 2; if (c.Length < StereoscopyMin) { GL.Color3(1.0, 0.0, 1.0); GL.Vertex2((a.X + b.X) / 2, (a.Y + b.Y) / 2); } else { GL.Color3(1.0, 0, 0); GL.Vertex2(a.X, a.Y); GL.Color3(0, 0, 1.0); GL.Vertex2(b.X, b.Y); } _windowCoordinates.X = (a.X / 2 + b.X / 2) * 1440 / 2; _windowCoordinates.Y = (a.Y / 2 + b.Y / 2) * 750 / 2; GL.End(); }
public void DrawStereoscopy(Matrix4d transformacja) { const int renderWidth = 1440; const int renderHeight = 750; GL.Begin(BeginMode.Lines); GL.Color3(0.6, 0, 0); Matrix4d projekcja = MatrixProvider.RightProjectionMatrix(); foreach (var relations in _relationsList) { var avertex = transformacja.Multiply(_verticesList[relations.Item1]); var avertex2 = transformacja.Multiply(_verticesList[relations.Item2]); var dx = projekcja.M13 * avertex.Z; var dx2 = projekcja.M13 * avertex2.Z; var vertex = projekcja.Multiply(avertex); var vertex2 = projekcja.Multiply(avertex2); GL.Vertex2(vertex.X, vertex.Y); GL.Vertex2(vertex2.X, vertex2.Y); } GL.End(); Bitmap bmp1 = new Bitmap(renderWidth, renderHeight); System.Drawing.Imaging.BitmapData dat = bmp1.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); GL.ReadPixels(0, 0, renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat.Scan0); bmp1.UnlockBits(dat); //bmp1.Save("D:\\ModelowanieGeometryczne\\a1.bmp", ImageFormat.Bmp); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Begin(BeginMode.Lines); GL.Color3(0, 0, 0.9); projekcja = MatrixProvider.LeftProjectionMatrix(); foreach (var relations in _relationsList) { var avertex = transformacja.Multiply(_verticesList[relations.Item1]); var avertex2 = transformacja.Multiply(_verticesList[relations.Item2]); var dx = projekcja.M13 * avertex.Z; var dx2 = projekcja.M13 * avertex2.Z; var vertex = projekcja.Multiply(avertex); var vertex2 = projekcja.Multiply(avertex2); GL.Vertex2(vertex.X, vertex.Y); GL.Vertex2(vertex2.X, vertex2.Y); } GL.End(); Bitmap bmp2 = new Bitmap(renderWidth, renderHeight); System.Drawing.Imaging.BitmapData dat2 = bmp2.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); GL.ReadPixels(0, 0, renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat2.Scan0); bmp2.UnlockBits(dat2); // bmp2.Save("D:\\ModelowanieGeometryczne\\a2.bmp", ImageFormat.Bmp); GL.Clear(ClearBufferMask.ColorBufferBit); Bitmap bmp3 = bmp2; Color temp, pixeltemp, result; ////DziaĆa dla dowolnego koloru torusa 1 i torusa 2 for (int i = 0; i < renderWidth; i++) { for (int j = 0; j < renderHeight; j++) { temp = bmp1.GetPixel(i, j); if (temp.R == 0 && temp.G == 0 && temp.B == 0) { } else { pixeltemp = bmp3.GetPixel(i, j); result = Color.FromArgb(Math.Min(temp.R + pixeltemp.R, 255), Math.Min(temp.G + pixeltemp.G, 255), Math.Min(temp.B + pixeltemp.B, 255)); bmp3.SetPixel(i, j, result); } } } //Writable bitmap bmp3.Save("D:\\ModelowanieGeometryczne\\a3.bmp", ImageFormat.Bmp); //Color k1 = Color.FromArgb(87, 0, 0); //Color k2 = Color.FromArgb(87, 0, 173); //for (int i = 0; i < RenderWidth; i++) //{ // for (int j = 0; j < RenderHeight; j++) // { // if (bmp1.GetPixel(i, j).R == 0) // { // } // else if (bmp3.GetPixel(i, j).B == 0) // { // //Blending colors overlapped lines. // bmp3.SetPixel(i, j, k1); // } // else // { // bmp3.SetPixel(i, j, k2); // } // } //} //bmp3.Save("D:\\ModelowanieGeometryczne\\a3.bmp", ImageFormat.Bmp); dat2 = bmp2.LockBits(new Rectangle(0, 0, renderWidth, renderHeight), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); GL.DrawPixels(renderWidth, renderHeight, PixelFormat.Bgra, PixelType.UnsignedByte, dat2.Scan0); bmp2.UnlockBits(dat2); }