예제 #1
0
 public void selectRandomDirection(AbstractEnvironmentType env, Libutility util, Vector3d preDir)
 {
     if (env.env_type == 1)
     {
         double   randx   = (util.getRandDouble() - 0.5) * 2;
         double   randy   = (util.getRandDouble() - 0.5) * 2;
         double   randz   = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, randz);
         randDir = Vector3d.Add(randDir, preDir);
         Double leng   = randDir.Length;
         Double factor = _cur_speed / leng;
         orientation = Vector3d.Multiply(factor, randDir);
         return;
     }
     else if (env.env_type == 2)
     {
         double   randx   = (util.getRandDouble() - 0.5) * 2;
         double   randy   = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, 0);
         randDir = Vector3d.Add(randDir, preDir);
         randDir.Unitize();
         uv_orientation = Vector3d.Multiply(_cur_speed, randDir);
         orientation    = env.getOrientationFromUv(Location, uv_orientation);
         return;
     }
 }
예제 #2
0
 public bool iniSuccess(int x, int y, int z, AbstractEnvironmentType env, Libutility util)
 {
     if (env.isOccupidByParticleByIndex(x, y, z) == true)
     {
         return(false);
     }
     if (env.isWithinObstacleByIndex(x, y, z) && util.getRandDouble() > PhysaSetting.escape_p)
     {
         return(false);
     }
     return(true);
 }
예제 #3
0
파일: Amoeba.cs 프로젝트: maajor/Physarealm
 public void selectRandomDirection(AbstractEnvironmentType env, Libutility util, Vector3d preDir)
 {
     if (env.env_type == 1)
     {
         double randx = (util.getRandDouble() - 0.5) * 2;
         double randy = (util.getRandDouble() - 0.5) * 2;
         double randz = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, randz);
         randDir = Vector3d.Add(randDir, preDir);
         Double leng = randDir.Length;
         Double factor = _cur_speed / leng;
         orientation = Vector3d.Multiply(factor, randDir);
         return;
     }
     else if (env.env_type == 2)
     {
         double randx = (util.getRandDouble() - 0.5) * 2;
         double randy = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, 0);
         randDir = Vector3d.Add(randDir, preDir);
         randDir.Unitize();
         uv_orientation = Vector3d.Multiply(_cur_speed, randDir);
         orientation = env.getOrientationFromUv(Location, uv_orientation);
         return;
     }
 }
예제 #4
0
파일: Amoeba.cs 프로젝트: maajor/Physarealm
 public bool iniSuccess(int x, int y, int z, AbstractEnvironmentType env, Libutility util)
 {
     if (env.isOccupidByParticleByIndex(x, y, z) == true)
         return false;
     if (env.isWithinObstacleByIndex(x, y, z) && util.getRandDouble() > PhysaSetting.escape_p)
         return false;
     return true;
 }
예제 #5
0
파일: Amoeba.cs 프로젝트: maajor/Physarealm
 public void doMotorBehaviors(AbstractEnvironmentType env, Libutility util)
 {
     _distance_traveled++;
     prev_loc = Location;
     //_cur_speed = _max_speed * (1 - _distance_traveled / _deathDistance);
     _cur_speed = PhysaSetting._speed;
     if (env.getGriddataByIndex(curx, cury, curz) == 1)
         _distance_traveled = 0;
     _moved_successfully = false;
     if (util.getRandDouble() < PhysaSetting._pcd)
     {
       selectRandomDirection(env, util);
       resetFloatingPointPosition(env);
       return;
     }
     Point3d curLoc = Location;
     curLoc.Transform(Transform.Translation(orientation));
     //Location = curLoc;
     tempfloatx = (float)curLoc.X;
     tempfloaty = (float)curLoc.Y;
     tempfloatz = (float)curLoc.Z;
     switch (PhysaSetting.border_type)
     {
         case 0:
             if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz,0))
                 selectRandomDirection(env, util);
             break;
         case 1:
             env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 1);
             break;
         case 2:
             env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0);
             orientation = env.bounceOrientation(curLoc, orientation);
             break;
         default:
             break;
     }
     //if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz))
     //    selectRandomDirection(util);
     Point3d temppos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);
     tempx = (int)temppos.X;
     tempy = (int)temppos.Y;
     tempz = (int)temppos.Z;
     if (env.isOccupidByParticleByIndex(tempx, tempy, tempz))
     {
         selectRandomDirection(env,util);
         return;
     }
     else if (env.isWithinObstacleByIndex(tempx, tempy, tempz) && util.getRandDouble() > PhysaSetting.escape_p)
     {
         selectRandomDirection(env,util);
         return;
     }
     else
     {
         _moved_successfully = true;
         Location = env.projectLocationToEnv(new Point3d(tempfloatx, tempfloaty, tempfloatz));
         env.clearGridCellByIndex(curx, cury, curz);
         //env.agedata[curx, cury, curz]++;
         env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
         curx = tempx;
         cury = tempy;
         curz = tempz;
         //float trailIncrement = calculateTrailIncrement(util);
         //env.increaseTrailByIndex(curx, cury, curz, trailIncrement);
         env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
         //if (_moved_successfully && !_die && _distance_traveled % division_frequency_test == 0)
         if (_moved_successfully && !_die)
             doDivisionTest(env);
     }
 }
예제 #6
0
        public void doMotorBehaviors(AbstractEnvironmentType env, Libutility util)
        {
            _distance_traveled++;
            prev_loc = Location;
            //_cur_speed = _max_speed * (1 - _distance_traveled / _deathDistance);
            _cur_speed = PhysaSetting._speed;
            if (env.getGriddataByIndex(curx, cury, curz) == 1)
            {
                _distance_traveled = 0;
            }
            _moved_successfully = false;
            if (util.getRandDouble() < PhysaSetting._pcd)
            {
                selectRandomDirection(env, util);
                resetFloatingPointPosition(env);
                return;
            }
            Point3d curLoc = Location;

            curLoc.Transform(Transform.Translation(orientation));
            //Location = curLoc;
            tempfloatx = (float)curLoc.X;
            tempfloaty = (float)curLoc.Y;
            tempfloatz = (float)curLoc.Z;
            switch (PhysaSetting.border_type)
            {
            case 0:
                if (env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0))
                {
                    selectRandomDirection(env, util);
                }
                break;

            case 1:
                env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 1);
                break;

            case 2:
                env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0);
                orientation = env.bounceOrientation(curLoc, orientation);
                break;

            default:
                break;
            }
            //if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz))
            //    selectRandomDirection(util);
            Point3d temppos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);

            tempx = (int)temppos.X;
            tempy = (int)temppos.Y;
            tempz = (int)temppos.Z;
            if (env.isOccupidByParticleByIndex(tempx, tempy, tempz))
            {
                selectRandomDirection(env, util);
                return;
            }
            else if (env.isWithinObstacleByIndex(tempx, tempy, tempz) && util.getRandDouble() > PhysaSetting.escape_p)
            {
                selectRandomDirection(env, util);
                return;
            }
            else
            {
                _moved_successfully = true;
                Location            = env.projectLocationToEnv(new Point3d(tempfloatx, tempfloaty, tempfloatz));
                env.clearGridCellByIndex(curx, cury, curz);
                //env.agedata[curx, cury, curz]++;
                env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
                curx = tempx;
                cury = tempy;
                curz = tempz;
                //float trailIncrement = calculateTrailIncrement(util);
                //env.increaseTrailByIndex(curx, cury, curz, trailIncrement);
                env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
                //if (_moved_successfully && !_die && _distance_traveled % division_frequency_test == 0)
                if (_moved_successfully && !_die)
                {
                    doDivisionTest(env);
                }
            }
        }