Ejemplo n.º 1
0
        public override void Fire()
        {
            Init();  //be sure to leave this here to enable use of the na variable
            Module2DModel naModel = (Module2DModel)FindModuleByType(typeof(Module2DModel));

            if (naModel == null)
            {
                return;
            }

            for (int i = 0; i < na.Height; i++)
            {
                //neurons:  0:touch   1:antAngle  2:antDistance 3: sensedLineAngle 4: conf1 5: len1 6: conf2 7: len2 8: touch-ended 9: modelchanged
                if (na.GetNeuronAt(0, i).CurrentCharge == 0)
                {
                    continue;
                }
                float antDist   = na.GetNeuronAt(1, i).CurrentCharge;
                float antAngle  = na.GetNeuronAt(2, i).CurrentCharge;
                float lineAngle = na.GetNeuronAt(3, i).CurrentCharge;
                float p1IsEndpt = na.GetNeuronAt(4, i).CurrentCharge;
                float l1        = na.GetNeuronAt(5, i).CurrentCharge;
                float p2IsEndpt = na.GetNeuronAt(6, i).CurrentCharge;
                float l2        = na.GetNeuronAt(7, i).CurrentCharge;
                float mR        = na.GetNeuronAt(9, i).CurrentCharge;
                float mTheta    = na.GetNeuronAt(10, i).CurrentCharge;
                float mPhi      = na.GetNeuronAt(11, i).CurrentCharge;

                PointPlus motion = new PointPlus()
                {
                    R = mR, Theta = mTheta, Conf = mPhi
                };
                //create the line segment (all coordinates relative to self)
                PointPlus antennaPos = new PointPlus()
                {
                    R = antDist, Theta = antAngle
                };

                float lineAngleAbs = antAngle - lineAngle;

                PointPlus pv1 = new PointPlus()
                {
                    R = l1, Theta = (float)Math.PI + lineAngleAbs
                };
                PointPlus pv2 = new PointPlus()
                {
                    R = l2, Theta = lineAngleAbs
                };

                Point     P1  = antennaPos.P + pv1.V;
                Point     P2  = antennaPos.P + pv2.V;
                PointPlus P1P = new PointPlus()
                {
                    P = P1, Conf = 1 - p1IsEndpt
                };
                PointPlus P2P = new PointPlus()
                {
                    P = P2, Conf = 1 - p2IsEndpt
                };

                bool modelChanged = naModel.AddSegmentFromTouch(P1P, P2P, motion, i);
            }
        }