예제 #1
0
 public virtual bool Equals(RealThing t)
 {
     if (thingType == t.thingType && color == t.color)
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
        override public void Fire()
        {
            Init();
            if (naIn == null)
            {
                return;
            }

            for (int i = 1; i < naIn.Height; i++)
            {
                //are there objects in the visual field?
                if (naIn.GetNeuronAt(0, i).LastCharge == 0)
                {
                    break;                                         //end of shapes in visual field
                }
                RealThing CT = new RealThing();
                CT.thingType = 0; //we must convert to angular distances
                CT.z         = 5; //we have no idea how far away it is...just its apparent size.

                CT.color = naIn.GetNeuronAt(0, i).LastChargeInt;

                //sizes are given [0,1] in the field of view which is 60-degrees or +/-.16
                CT.sizeX            = (naIn.GetNeuronAt(1, i).LastCharge - .5f) / 3;
                CT.sizeY            = (naIn.GetNeuronAt(2, i).LastCharge - .5f) / 3;
                CT.cx               = (naIn.GetNeuronAt(3, i).LastCharge - .5f) / 3;
                CT.cy               = (naIn.GetNeuronAt(4, i).LastCharge - .5f) / 3;
                CT.allInFieldOfView = naIn.GetNeuronAt(5, i).LastCharge == 1;
                CT.thingType        = (int)naIn.GetNeuronAt(6, i).LastCharge;

                int foundIndex = -1;
                for (int j = 0; j < thingsInReality.Count; j++)
                {
                    RealThing t = thingsInReality[j];
                    //only care about things which might be fully in visual field
                    //camera field of view is 60-degrees so should be x=[-.1666,.1666]

                    if (CT.color == t.color)
                    {
                        if (CT.allInFieldOfView)
                        {
                            //the object is there but has it moved ?
                            while (CT.sizeX - t.sizeX > 0.02 && CT.sizeY - t.sizeY > 0.02) //object is closer (or grown)
                            {
                                float oldz = t.z;
                                t.z          -= .1f; //assume the object hasn't moved and adjust the model
                                t.sizeX      *= t.z / oldz;
                                t.sizeY      *= t.z / oldz;
                                t.sizeChanged = 1;
                            }
                            if (CT.sizeX - t.sizeX < -0.02 && CT.sizeY - t.sizeY < -0.02) //object is further (or shrunk)
                            {
                                float oldz = t.z;
                                t.z          += .1f; //assume the object hasn't moved and adjust the model
                                t.sizeX      *= t.z / oldz;
                                t.sizeY      *= t.z / oldz;
                                t.sizeChanged = 1;
                            }
                            if (!Utils.Close(CT.cx, t.cx) || !Utils.Close(CT.cy, t.cy)) //object has moved
                            {
                                //moved is handled elsewhere
                            }
                        }
                        foundIndex = i;

                        //update the values to match what we see
                        t.cx = CT.cx;
                        t.cy = CT.cy;
                        break; //found a match, quit looking
                    }
                }
                //Object was not found, add it
                if (foundIndex == -1)
                {
                    thingsInReality.Add(CT);
                }
            }
            //find missing objects  is there anything which should be in the visual field which isnt?

            //update the neuron values for the reality model
            na.ClearNeuronChargeInArea();
            for (int i = 0; i < thingsInReality.Count; i++)
            {
                RealThing t    = thingsInReality[i];
                int       xVal = (int)((t.cx / 2 + 0.5) * na.Width);
                while (na.GetNeuronAt(0, xVal).LastChargeInt != 0)
                {
                    xVal++;
                }
                na.GetNeuronAt(xVal, 0).SetValueInt(t.color);
                na.GetNeuronAt(xVal, 1).SetValue(t.cy);
                na.GetNeuronAt(xVal, 2).SetValue(t.z); //need to range properly
                na.GetNeuronAt(xVal, 3).SetValue(t.sizeX);
                na.GetNeuronAt(xVal, 4).SetValue(t.sizeY);
            }
        }