public void Init(Intension intension, Perception perception, FishBody body)
        {
            this.motorControllers.Clear();

            var focusser = perception.GetFocuser();

            var normal = body.modelData.Normal;
            var left   = body.modelData.Left;
            var dir    = focusser.target.obj.obj.Position - body.modelData.GeometryCenter;

            var motorType = focusser.motorPreference.MaxValue.type;

            if (motorType == Focusser.MotorPreference.Type.MoveForward)
            {
                if (this.smc == null)
                {
                    this.smc    = new SwimMC();
                    this.curves = this.smc.ActivationData.ToAnimationCurves();
                }
                if (focusser.target.obj != null)
                {
                    this.smc.UpdateSpeed(focusser.target.obj.distance);
                }
                this.motorControllers.Add(this.smc);
            }
            else if (motorType == Focusser.MotorPreference.Type.TurnLeft)
            {
                if (this.tlmc == null)
                {
                    this.tlmc   = new TurnLeftMC();
                    this.curves = this.tlmc.ActivationData.ToAnimationCurves();
                }
                var angle = this.GetAngleInFish(dir, normal, left);
                this.tlmc.UpdateAngle(angle);
                this.motorControllers.Add(this.tlmc);

                this.smc?.UpdateSpeed(0);
            }
            else if (motorType == Focusser.MotorPreference.Type.TurnRight)
            {
                if (this.trmc == null)
                {
                    this.trmc   = new TurnRightMC();
                    this.curves = this.trmc.ActivationData.ToAnimationCurves();
                }
                var angle = this.GetAngleInFish(dir, normal, left);
                this.trmc.UpdateAngle(angle);
                this.motorControllers.Add(this.trmc);

                this.smc?.UpdateSpeed(0);
            }


            var balance = new BalanceMC();

            balance.UpdateBalance(left, normal);
            this.motorControllers.Add(balance);
        }
        protected void ApplyActivation(float t, FishBody body, MuscleMC mc)
        {
            var types = new List <Spring.Type>()
            {
                Spring.Type.MuscleFront, Spring.Type.MuscleMiddle, Spring.Type.MuscleBack
            };

            foreach (var type in types)
            {
                mc.ActivationData.ApplyActivation(t, type, body.modelData, mc.GetParameter(type));
            }
        }
        protected void Start()
        {
            this.fish = this.GetComponent <FishBody>();
            this.fish.Init();

            this.InitActivations();
            this.UpdateAnimationCurves();
            this.problem = new FishSimulatorOffline.Problem(this.fish, this.GetCurrentMC());
            this.delta   = new IterationDelta();
            this.sim     = new FishSimulatorOffline(problem, this.delta);
            this.sim.TryToRun();
        }
        protected void Start()
        {
            this.fish = this.GetComponent <FishBody>();
            this.fish.Init();
            this.runtimeList = this.fish.modelData.FishGraph.Nodes.ToList();


            this.InitActivations();
            this.UpdateAnimationCurves();
            this.problem = new FishSimulatorOffline.Problem(this.fish.modelData, this.activationData);
            this.delta   = new IterationDelta();
            this.sim     = new FishSimulatorOffline(problem, this.delta);
            this.sim.TryToRun();
        }
        // public FishBrain Brain => this.brain;

        // public bool IsDone { get; set; }

        public void Init()
        {
            this.body = this.GetComponentInChildren <FishBody>();
            this.body.Init();

            this.brain = this.GetComponentInChildren <FishBrain>();
            this.brain.Init();

            this.perception = this.GetComponentInChildren <Perception>();
            this.perception.Init();

            this.logger     = this.logger ?? new FishLogger();
            this.localDelta = this.localDelta ?? new FishSimulator.Delta();

            this.Reset();
            FishSimulatorRunner.Instance.Controller.AddController(this);
        }
        protected void Start()
        {
            this.body = this.GetComponent <FishBody>();
            this.body.Init();

            // this.activationData = new FishActivationDataSwimming(this.interval, this.sampleNum);
            //this.activationData.RandomActivation();
            this.activationData = FishActivationData.Load();
            this.interval       = this.activationData.Interval;
            this.sampleNum      = this.activationData.SampleNum;

            this.curves      = this.activationData.ToAnimationCurves();
            this.activations = this.activationData.ToActivationList();

            var problem = new FishSimulatorOffline.Problem(this.body.modelData, this.activationData);
            var dt      = new IterationDelta();
            var sim     = new FishSimulatorOffline(problem, dt);

            sim.TryToRun();
        }
 public Problem(FishBody fish, MuscleMC mc)
 {
     this.fishBody = fish;
     this.mcData   = mc;
 }
Example #8
0
 public void FocusserUpdate(Intension intension, Desire desire, FishBody body)
 {
     this.focusser.Update(intension, this, desire, body);
 }