示例#1
0
        public void MakeSphere(XYZ pos, int radius, byte code, XYZ_b color)
        {
            Func <XYZ_d, XYZ, XYZ, int, bool> renderer = (XYZ_d delta, XYZ deltaSign, XYZ frameIndex, int nextDir) => { return(false); };

            XYZ    temp     = new XYZ();
            double distance = 0;

            for (int i = -radius; i < radius; i++)
            {
                for (int j = -radius; j < radius; j++)
                {
                    for (int k = -radius; k < radius; k++)
                    {
                        temp.Set(pos).Add(i, j, k);
                        distance = pos.Distance(temp);
                        if (distance < radius && distance > radius - 1)
                        {
                            if (IsInFrame(temp))
                            {
                                // Map[temp.x, temp.y, temp.z].code = code;
                                Map[temp.x, temp.y, temp.z].color.Set(color);
                                Map[temp.x, temp.y, temp.z].OnRendered = renderer_block;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        void Shoot(XYZ_b color, XYZ_d rayDelta)
        {
            XYZ_d delta      = new XYZ_d(rayDelta);
            XYZ_d lpos       = new XYZ_d(delta).Mul(world.frameLength * 2).Add(Position);
            XYZ   frameIndex = new XYZ();

            world.GetFrameIndex(lpos, frameIndex);
            world.ConvertToFramePos(frameIndex, lpos);
            XYZ   frameIndex2   = new XYZ(frameIndex);
            int   nextDir       = 0;
            XYZ_d target        = new XYZ_d();
            XYZ_d deltaSign     = new XYZ_d();
            XYZ_d maxNumOfDelta = new XYZ_d(world.frameLength);

            if (delta.x != 0)
            {
                deltaSign.x = (Math.Abs(delta.x) / delta.x);
            }
            if (delta.y != 0)
            {
                deltaSign.y = (Math.Abs(delta.y) / delta.y);
            }
            if (delta.z != 0)
            {
                deltaSign.z = (Math.Abs(delta.z) / delta.z);
            }

            maxNumOfDelta.Mul(deltaSign).Div(delta);
            target.Set(world.halfFrameLength).Mul(deltaSign); //delta벡터 방향으로 이동시 접촉가능한 경계면들 구하기.
            target.Sub(lpos).Div(delta);                      //경계면들로부터 현재위치의 거리를 구하고 delta로 나누기. deltasign으로 한번 곱했었기때문에 x,y,z축 서로에 대한 정확한 비교값이 나오게된다.
            Task.Factory.StartNew(() =>
            {
                while (!world.isFrameEnabled(frameIndex))
                {
                    world.ConvertToInfinity(frameIndex);
                    world.SetFrame(frameIndex2, false);
                    world.SetFrame(frameIndex, true);
                    world.SetColor(frameIndex, color);

                    if (target.x < target.y)
                    {
                        if (target.x < target.z)
                        {
                            nextDir = 0;
                        }
                        else
                        {
                            nextDir = 2;
                        }
                    }
                    else
                    if (target.y < target.z)
                    {
                        nextDir = 1;
                    }
                    else
                    {
                        nextDir = 2;
                    }
                    target.element[nextDir] += maxNumOfDelta.element[nextDir];
                    frameIndex2.Set(frameIndex);
                    frameIndex.element[nextDir] += (int)deltaSign.element[nextDir];
                    Thread.Sleep(10);
                }

                world.SetFrame(frameIndex2, false);
                XYZ temp        = new XYZ();
                int scale       = 10;
                double distance = 0;
                for (int i = -scale; i < scale; i++)
                {
                    for (int j = -scale; j < scale; j++)
                    {
                        for (int k = -scale; k < scale; k++)
                        {
                            temp.Set(frameIndex).Add(i, j, k);
                            distance = frameIndex.Distance(temp);
                            if (distance < scale)
                            {
                                world.ConvertToInfinity(temp);
                                XYZ_b c = world.GetColor(temp);
                                //gap.x = (int)color.x - (int)c.x;
                                //gap.y = (int)color.y - (int)c.y;
                                //gap.z = (int)color.z - (int)c.z;
                                //gap.Mul((int)(scale - distance)).Div(scale);
                                //c.x = (byte)(c.x + gap.x);
                                //c.y = (byte)(c.y + gap.y);
                                //c.z = (byte)(c.z + gap.z);
                                temp.x = (int)color.x * (int)(scale - distance) / scale;
                                temp.y = (int)color.y * (int)(scale - distance) / scale;
                                temp.z = (int)color.z * (int)(scale - distance) / scale;
                                c.Add((byte)temp.x, (byte)temp.y, (byte)temp.z);
                                // world.SetFrame(temp, false);
                                //world.SetColor(temp, 255, 0, 0);
                            }
                        }
                    }
                }
            });
        }