private void GenerateMyBubbleMesh() { MyBubbleMesh = new MyVector[BUBBLE_RADIUS * 2, BUBBLE_RADIUS * 2]; float dx, dy, z; for (int x = 0; x < BUBBLE_RADIUS * 2; x++) { for (int y = 0; y < BUBBLE_RADIUS * 2; y++) { dx = BUBBLE_RADIUS - x; dy = BUBBLE_RADIUS - y; z = (float)Math.Sqrt(BUBBLE_RADIUS * BUBBLE_RADIUS - dx * dx - dy * dy); MyBubbleMesh[x, y] = MyVector.NormalizeVector(dx, dy, z); } } }
private Color GetRealColorOfPoint(int x, int y) { MyVector I; //kolor obiektu // MyVector IO; if (FillColorRadioButton.Checked) { IO = new MyVector(currentColor); } else { IO = new MyVector(GetPixelFromTexture(x, y, currentTexture)); } // //kolor światła // MyVector tmpIL; if (LightColorCustomRadioButton.Checked) { tmpIL = IL; } else { tmpIL = new MyVector(1, 1, 1); } // //wektor do światła // MyVector L; if (LightLocationDefaultRadioButton.Checked) // Default { L = new MyVector(0, 0, 1); } else if (LightLocationCenterRadioButtton.Checked) //Center { L = MyVector.NormalizeVector(x - WIDTH / 2, y - HEIGHT / 2, 300); } else // Animation { L = MyVector.NormalizeVector(x - LightLocation.x, y - LightLocation.y, LightLocation.z); } // //wektor normalny // MyVector N; if (!BubbleCheckbox.Checked) { if (NVectorConstantRadioButton.Checked) { N = new MyVector(0, 0, 1); } else { N = GetNVectorFromMap(x, y, currentNormalMap); } } else { if (Distance(currentPoint, new PointF(x, y)) < BUBBLE_RADIUS) //generujemy wektor normalny dla bąbelka { N = MyBubbleMesh[(int)(x - currentPoint.X + BUBBLE_RADIUS), (int)(y - currentPoint.Y + BUBBLE_RADIUS)]; } else { if (NVectorConstantRadioButton.Checked) { N = new MyVector(0, 0, 1); } else { N = GetNVectorFromMap(x, y, currentNormalMap); } } } // MyVector R = 2 * MyVector.ScalarProduct(N, L) * N - L; I = kd * tmpIL * IO * MyVector.ScalarProduct(N, L) + ks * tmpIL * IO * (float)Math.Pow(MyVector.ScalarProduct(V, R), m); I.PrepareToDraw(); return(Color.FromArgb((byte)(I.x * 255), (byte)(I.y * 255), (byte)(I.z * 255))); }