Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 16th, 2010 | Syntax: C# | Size: 3.26 KB | Hits: 45 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. public void calc2DCoords() {
  2.         // Point(X|Y|X)                 a{x,y,z}        The point in 3D space that is to be projected.
  3.         // Cube.Camera(X|Y|X)   c{x,y,z}        The location of the camera.
  4.         // Cube.Theta(X|Y|X)    0{x,y,z}        The rotation of the camera. When c{x,y,z}=<0,0,0>, and 0{x,y,z}=<0,0,0>, the 3D vector <1,2,0> is projected to the 2D vector <1,2>.
  5.         // Cube.Viewer(X|Y|X)   e{x,y,z}        The viewer's position relative to the display surface.
  6.         // Bsub(X|Y)                    b{x,y}          The 2D projection of a.
  7.         double PointX = X3;
  8.         double PointY = Y3;
  9.         double PointZ = Z3;
  10.         double DsubX, DsubY, DsubZ;
  11.         double BsubX, BsubY;
  12.         distanceFromViewer = Math.Sqrt(Math.Pow((PointX - Cube.ViewerX), 2) + Math.Pow((PointY - Cube.ViewerY), 2) + Math.Pow((PointZ - Cube.ViewerZ), 2));
  13.         DsubX = Math.Cos(Cube.ThetaY) * (Math.Sin(Cube.ThetaZ) * (PointY - Cube.CameraY) + Math.Cos(Cube.ThetaZ) * (PointX - Cube.CameraX)) - Math.Sin(Cube.ThetaY) * (PointZ - Cube.CameraZ);
  14.         DsubY = Math.Sin(Cube.ThetaX) * (Math.Cos(Cube.ThetaY) * (PointZ - Cube.CameraZ) + Math.Sin(Cube.ThetaY) * (Math.Sin(Cube.ThetaZ) * (PointY - Cube.CameraY) + Math.Cos(Cube.ThetaZ) * (PointX - Cube.CameraX))) + Math.Cos(Cube.ThetaX) * (Math.Cos(Cube.ThetaZ) * (PointY - Cube.CameraY) - Math.Sin(Cube.ThetaZ) * (PointX - Cube.CameraX));
  15.         DsubZ = Math.Cos(Cube.ThetaX) * (Math.Cos(Cube.ThetaY) * (PointZ - Cube.CameraZ) + Math.Sin(Cube.ThetaY) * (Math.Sin(Cube.ThetaZ) * (PointY - Cube.CameraY) + Math.Cos(Cube.ThetaZ) * (PointX - Cube.CameraX))) - Math.Sin(Cube.ThetaX) * (Math.Cos(Cube.ThetaZ) * (PointY - Cube.CameraY) - Math.Sin(Cube.ThetaZ) * (PointX - Cube.CameraX));
  16.         BsubX = (DsubX - Cube.ViewerX) / (Cube.ViewerZ / DsubZ);
  17.         BsubY = (DsubY - Cube.ViewerY) / (Cube.ViewerZ / DsubZ);
  18.         X2 = (int)((BsubX * 50) + 250);
  19.         Y2 = (int)((BsubY * 50) + 250);
  20.         /*
  21.         Console.WriteLine("-----------------------------------------------------------------------------------------------");
  22.         Console.WriteLine("DsubX = " + DsubX + " = cos(" + Cube.ThetaY + ")*(sin(" + Cube.ThetaZ + ")*(" + PointY + "-" + Cube.CameraY + ")+cos(" + Cube.ThetaZ + ")*(" + PointX + "-" + Cube.CameraX + "))-sin(" + Cube.ThetaY + ")*(" + PointZ + "-" + Cube.CameraZ + ")");
  23.         Console.WriteLine("DsubY = " + DsubY + " = sin(" + Cube.ThetaX + ")*(cos(" + Cube.ThetaY + ")*(" + PointZ + "-" + Cube.CameraZ + ")+sin(" + Cube.ThetaY + ")*(sin(" + Cube.ThetaZ + ")*(" + PointY + "-" + Cube.CameraY + ")+cos(" + Cube.ThetaZ + ")*(" + PointX + "-" + Cube.CameraY + ")))+cos(" + Cube.ThetaX + ")*(cos(" + Cube.ThetaZ + ")*(" + PointY + "-" + Cube.CameraY + ")-sin(" + Cube.ThetaZ + ")*(" + PointX + "-" + Cube.CameraX + "))");
  24.         Console.WriteLine("DsubZ = " + DsubZ + " = cos(" + Cube.ThetaX + ")*(cos(" + Cube.ThetaY + ")*(" + PointZ + "-" + Cube.CameraZ + ")+sin(" + Cube.ThetaY + ")*(sin(" + Cube.ThetaZ + ")*(" + PointY + "-" + Cube.CameraY + ")+cos(" + Cube.ThetaZ + ")*(" + PointX + "-" + Cube.CameraY + ")))-sin(" + Cube.ThetaX + ")*(cos(" + Cube.ThetaZ + ")*(" + PointY + "-" + Cube.CameraY + ")-sin(" + Cube.ThetaZ + ")*(" + PointX + "-" + Cube.CameraX + "))");
  25.         Console.WriteLine("BsubX = (" + DsubX + " - " + Cube.ViewerX + ") / (" + Cube.ViewerZ + " / " + DsubZ + ")");
  26.         Console.WriteLine("BsubY = (" + DsubY + " - " + Cube.ViewerY + ") / (" + Cube.ViewerZ + " / " + DsubZ + ")");
  27.         Console.WriteLine("X2 = " + X2 + " Y2 = " + Y2);
  28.         */
  29. }