private void OnMouseMove(object sender, MouseEventArgs e)
 {
     if (isMouseDown)
     {
         float2 offset  = new float2((e.X - mouseLocation.x) * mouseSensitivity, (e.Y - mouseLocation.y) * mouseSensitivity);
         float  c1      = DeviceFunction.Cos(offset.x);
         float  s1      = DeviceFunction.Sin(offset.x);
         float  t1      = 1 - c1;
         float  c2      = DeviceFunction.Cos(offset.y);
         float  s2      = DeviceFunction.Sin(offset.y);
         float  t2      = 1 - c2;
         float  camDist = L(camera);
         gpu.Launch(RotateDirection, launchParam, dirDevPtr, y, t1, c1, s1, width, height);
         x      = RotateVec(x, y, t1, c1, s1);
         z      = RotateVec(z, y, t1, c1, s1);
         camera = RotateVec(camera, y, t1, c1, s1);
         gpu.Launch(RotateDirection, launchParam, dirDevPtr, x, t2, c2, s2, width, height);
         y      = RotateVec(y, x, t2, c2, s2);
         z      = RotateVec(z, x, t2, c2, s2);
         camera = RotateVec(camera, x, t2, c2, s2);
         Gpu.Copy(dirDevMem, directions);
         x = D(x, L(x));
         y = D(y, L(y));
         z = D(z, L(z));
         ScreenDivider.Panel2.Invalidate();
     }
     mouseLocation = new int2(e.X, e.Y);
 }
Beispiel #2
0
        // Helpers!
        private static void ComputeRippleAtOffset(int x, int y, int width, int height, Action <byte> action)
        {
            var fx = x - width * 0.5f;
            var fy = y - height * 0.5f;

            var d = DeviceFunction.Sqrt(fx * fx + fy * fy);
            var v = (byte)(128f + 127f * DeviceFunction.Cos(d / 10f) / (d / 10f + 1f));

            action(v);
        }
        public static float3 RotateZ(float3 z, float t)
        {
            float3 p = z;
            float  s = DeviceFunction.Sin(t);
            float  c = DeviceFunction.Cos(t);

            p.x = c * z.x + s * z.y;
            p.y = c * z.y - s * z.x;
            return(p);
        }
        public static float3 RotateY(float3 z, float t)
        {
            float3 p = z;
            float  s = DeviceFunction.Sin(t);
            float  c = DeviceFunction.Cos(t);

            p.x = c * z.x - s * z.z;
            p.z = c * z.z + s * z.x;
            return(p);
        }
        public static float3 RotateX(float3 z, float t)
        {
            float3 p = z;
            float  s = DeviceFunction.Sin(t);
            float  c = DeviceFunction.Cos(t);

            p.y = c * z.y + s * z.z;
            p.z = c * z.z - s * z.y;
            return(p);
        }
Beispiel #6
0
        private static void ComputeRippleAtOffset(deviceptr <byte> result, int index, int width, int height)
        {
            var x      = index % width;
            var y      = index / width;
            var offset = ColorComponents * index;

            if (offset < 3 * width * height)
            {
                var fx = x - width * 0.5f;
                var fy = y - height * 0.5f;

                var d = DeviceFunction.Sqrt(fx * fx + fy * fy);
                var v = (byte)(128f + 127f * DeviceFunction.Cos(d / 10f) / (d / 10f + 1f));

                result[offset + 0] = v;
                result[offset + 1] = v;
                result[offset + 2] = v;
            }
        }
Beispiel #7
0
 private static double CalkaGPU(double x, double y)
 {   //cos(x) + sin(x*y) + 0.1*x^2 - 2*y^2
     return(DeviceFunction.Cos(x) + DeviceFunction.Sin(x * y) + 0.1 * x * x - 2 * y * y);
 }