Ejemplo n.º 1
0
        void AddBird(string name)
        {
            Bird Bird = new Bird (name, this, m_flowMap);

            // find an initial random location for this Bird
            // somewhere not within an obstacle
            int xInit = m_rnd.Next(m_flowMap.LengthX);
            int yInit = m_rnd.Next(m_flowMap.LengthY);
            int zInit = m_rnd.Next(m_flowMap.LengthZ);

            while( m_flowMap.IsWithinObstacle( xInit, yInit, zInit ) ){
                xInit = m_rnd.Next(m_flowMap.LengthX);
                yInit = m_rnd.Next(m_flowMap.LengthY);
                zInit = m_rnd.Next(m_flowMap.LengthZ);
            }

            Bird.Location = new Vector3 (Convert.ToSingle(xInit), Convert.ToSingle(yInit), Convert.ToSingle(zInit));
            m_flock.Add (Bird);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clear the current flock if it exists and randomly generate a new one
        /// </summary>
        public void ResetFlock()
        {
            flock.Clear();
            flock.Capacity = flockSize;

            Bird tempBird;
            Vector2 tempDir;
            Vector2 tempLoc;

            Random random = new Random();

            for (int i = 0; i < flockSize; i++)
            {
                tempLoc = new Vector2((float)
                    random.Next(boundryWidth), (float)random.Next(boundryHeight));
                tempDir = new Vector2((float)
                    random.NextDouble() - 0.5f, (float)random.NextDouble() - 0.5f);
                tempDir.Normalize();

                tempBird = new Bird(birdTexture, tempDir, tempLoc, 
                    boundryWidth, boundryHeight);
                flock.Add(tempBird);
            }
        }
Ejemplo n.º 3
0
        private void DrawBird(Bird bird)
        {
            SceneObjectPart existing = m_scene.GetSceneObjectPart (bird.Id);

            SceneObjectGroup sog;
            SceneObjectPart rootPart;

            if (existing == null) {
                m_log.InfoFormat("[{0}]: Adding prim {1} in region {2}", m_name, bird.Id, m_scene.RegionInfo.RegionName);
                SceneObjectGroup group = findByName (m_birdPrim);
                sog = CopyPrim (group, bird.Id);
                rootPart = sog.RootPart;
                rootPart.AddFlag(PrimFlags.Temporary);
                rootPart.AddFlag(PrimFlags.Phantom);
                //set prim to phantom
                //sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false);
                m_sogMap [bird.Id] = sog;
                m_scene.AddNewSceneObject (sog, false);
                // Fire script on_rez
                sog.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 1);
                rootPart.ParentGroup.ResumeScripts();
                rootPart.ScheduleFullUpdate();
                sog.DetachFromBackup();
            } else {
                sog = existing.ParentGroup;
                m_sogMap[bird.Id] = sog;
                //rootPart = sog.RootPart;
                //set prim to phantom
                //sog.UpdatePrimFlags(rootPart.LocalId, false, false, true, false);
            }

            Quaternion rotation = CalcRotationToEndpoint (sog, sog.AbsolutePosition, bird.Location);
            sog.UpdateGroupRotationPR( bird.Location, rotation);
        }