private void Initialize()
        {
            randomNumberGenerator = new Random();
            string faceFileName = Path.GetDirectoryName(Application.ExecutablePath) + DEFAULT_RELATIVE_FACE_FILE_NAME;

            if (File.Exists(faceFileName))
            {
                face      = (Face)ObjectXmlSerializer.ObtainSerializedObject(faceFileName, typeof(Face));
                face.Name = "Face";
                face.Generate(new List <double> {
                    128
                });
                face.Visible       = true;
                face.SpecularColor = Color.OrangeRed;
                face.Shininess     = 50;

                // A lot of ugly hard-coding here, but OK - just for demonstration:
                face.Object3DList = new List <Object3D>();

                Sphere3D leftEyeBulb = new Sphere3D();
                leftEyeBulb.Generate(new List <double>()
                {
                    0.07, 64, 64
                });
                leftEyeBulb.AmbientColor  = Color.White;
                leftEyeBulb.DiffuseColor  = Color.White;
                leftEyeBulb.SpecularColor = Color.White;
                leftEyeBulb.Shininess     = 50;
                leftEyeBulb.ShowSurfaces  = true;
                // leftEyeBulb.Move(-0.1375, -0.403, 1.145);
                leftEyeBulb.ShadingModel = ShadingModel.Smooth;
                leftEyeBulb.UseLight     = true;
                leftEyeBulb.Name         = "LeftEye";
                leftEyeBulb.Object3DList = new List <Object3D>();

                SphereSegment3D leftEyeIris = new SphereSegment3D();
                leftEyeIris.Generate(new List <double>()
                {
                    0.07, 32, 32, Math.PI / 3
                });
                leftEyeIris.AmbientColor  = Color.Green;
                leftEyeIris.DiffuseColor  = Color.Green;
                leftEyeIris.SpecularColor = Color.White;
                leftEyeIris.Shininess     = 50;
                leftEyeIris.ShowSurfaces  = true;
                //   leftEyeIris.Move(-0.1375, -0.407, 0.145);
                leftEyeIris.Move(0, -0.005, 0);
                leftEyeIris.RotateX(90);
                SphereSegment3D leftEyePupil = new SphereSegment3D();
                leftEyePupil.Generate(new List <double>()
                {
                    0.07, 16, 32, Math.PI / 2 - 0.2
                });
                leftEyePupil.AmbientColor  = Color.Black;
                leftEyePupil.DiffuseColor  = Color.Black;
                leftEyePupil.SpecularColor = Color.White;
                leftEyePupil.Shininess     = 50;
                leftEyePupil.ShowSurfaces  = true;
                leftEyePupil.Move(0, -0.01, 0);
                leftEyePupil.RotateX(90); // , 0, 0);
                                          //   leftEyePupil.RotateX(Math.PI / 2);
                                          //  leftEyePupil.Translate(-0.1375, -0.4758, 0.0725);
                leftEyePupil.ShadingModel = ShadingModel.Smooth;
                leftEyePupil.UseLight     = true;
                SphereSegment3D leftEyeLid = new SphereSegment3D();
                leftEyeLid.Name = "LeftEyeLid";
                leftEyeLid.Generate(new List <double>()
                {
                    0.07, 32, 32, 0.0
                });
                leftEyeLid.AmbientColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
                leftEyeLid.DiffuseColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
                leftEyeLid.SpecularColor = Color.White;
                leftEyeLid.Shininess     = 50;
                leftEyeLid.ShowSurfaces  = true;
                leftEyeLid.RotateX(-36);
                leftEyeLid.Move(0, -0.015, 0);
                leftEyeBulb.Object3DList.Add(leftEyeIris);
                leftEyeBulb.Object3DList.Add(leftEyePupil);
                leftEyeBulb.Object3DList.Add(leftEyeLid);
                face.Object3DList.Add(leftEyeBulb);

                Sphere3D rightEyeBulb = new Sphere3D();
                rightEyeBulb.Generate(new List <double>()
                {
                    0.07, 64, 64
                });
                rightEyeBulb.AmbientColor  = Color.White;
                rightEyeBulb.DiffuseColor  = Color.White;
                rightEyeBulb.SpecularColor = Color.White;
                rightEyeBulb.Shininess     = 50;
                rightEyeBulb.ShowSurfaces  = true;
                //  rightEyeBulb.Move(0.1375, -0.403, 0.145);
                rightEyeBulb.ShadingModel = ShadingModel.Smooth;
                rightEyeBulb.UseLight     = true;
                rightEyeBulb.Name         = "RightEye";
                rightEyeBulb.Object3DList = new List <Object3D>();
                face.Object3DList.Add(rightEyeBulb);
                SphereSegment3D rightEyeIris = new SphereSegment3D();
                rightEyeIris.Generate(new List <double>()
                {
                    0.07, 32, 32, Math.PI / 3
                });
                rightEyeIris.AmbientColor  = Color.Green;
                rightEyeIris.DiffuseColor  = Color.Green;
                rightEyeIris.SpecularColor = Color.White;
                rightEyeIris.Shininess     = 50;
                rightEyeIris.ShowSurfaces  = true;
                rightEyeIris.RotateX(90); //  , 0, 0);
                rightEyeIris.Move(0, -0.005, 0);
                //   rightEyeIris.RotateX(Math.PI / 2);
                //   rightEyeIris.Translate(0.1375, -0.4715, 0.075);
                rightEyeIris.ShadingModel = ShadingModel.Smooth;
                rightEyeIris.UseLight     = true;
                SphereSegment3D rightEyePupil = new SphereSegment3D();
                rightEyePupil.Generate(new List <double>()
                {
                    0.07, 16, 32, Math.PI / 2 - 0.2
                });
                rightEyePupil.AmbientColor  = Color.Black;
                rightEyePupil.DiffuseColor  = Color.Black;
                rightEyePupil.SpecularColor = Color.White;
                rightEyePupil.Shininess     = 50;
                rightEyePupil.ShowSurfaces  = true;
                rightEyePupil.RotateX(90); //, 0, 0);
                rightEyePupil.Move(0, -0.01, 0);
                //  rightEyePupil.RotateX(Math.PI / 2);
                //  rightEyePupil.Translate(0.1375, -0.4758, 0.0725);
                rightEyePupil.ShadingModel = ShadingModel.Smooth;
                rightEyePupil.UseLight     = true;
                SphereSegment3D rightEyeLid = new SphereSegment3D();
                rightEyeLid.Name = "RightEyeLid";
                rightEyeLid.Generate(new List <double>()
                {
                    0.07, 32, 32, 0.0
                });
                rightEyeLid.AmbientColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
                rightEyeLid.DiffuseColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
                rightEyeLid.SpecularColor = Color.White;
                rightEyeLid.Shininess     = 50;
                rightEyeLid.ShowSurfaces  = true;
                rightEyeLid.RotateX(-36); // , 0, 0);
                rightEyeLid.Move(0, -0.015, 0);
                rightEyeBulb.Object3DList.Add(rightEyeIris);
                rightEyeBulb.Object3DList.Add(rightEyePupil);
                rightEyeBulb.Object3DList.Add(rightEyeLid);

                TorusSector3D leftEyebrow = new TorusSector3D();
                leftEyebrow.Name = "LeftEyebrow";
                leftEyebrow.Generate(new List <double> {
                    0.15, 0.01, 30, 30, 3 * Math.PI / 2 - 0.60, 3 * Math.PI / 2 + 0.40
                });
                leftEyebrow.AmbientColor  = Color.Black;
                leftEyebrow.DiffuseColor  = Color.Black;
                leftEyebrow.SpecularColor = Color.White;
                leftEyebrow.Shininess     = 50;
                leftEyebrow.ShowSurfaces  = true;
                leftEyebrow.RotateZ(-11);
                TorusSector3D rightEyebrow = new TorusSector3D();
                rightEyebrow.Name = "RightEyebrow";
                rightEyebrow.Generate(new List <double> {
                    0.15, 0.01, 30, 30, 3 * Math.PI / 2 - 0.60, 3 * Math.PI / 2 + 0.40
                });
                rightEyebrow.AmbientColor  = Color.Black;
                rightEyebrow.DiffuseColor  = Color.Black;
                rightEyebrow.SpecularColor = Color.White;
                rightEyebrow.Shininess     = 50;
                rightEyebrow.ShowSurfaces  = true;
                rightEyebrow.RotateZ(11);
                face.Object3DList.Add(leftEyebrow);
                face.Object3DList.Add(rightEyebrow);

                face.Move(0, 0, -0.5);
                leftEyeBulb.Move(-0.1375, -0.403, 0.645);
                rightEyeBulb.Move(0.1375, -0.403, 0.645);
                leftEyebrow.Move(-0.11, -0.325, 0.73);
                rightEyebrow.Move(0.11, -0.325, 0.73);

                // Close eyes to start with:
                leftEyeLid.RotateX(120);
                rightEyeLid.RotateX(120);
                leftEyebrow.Move(0, -0.005, -0.02);
                rightEyebrow.Move(0, -0.005, -0.02);
                eyesClosed = true;

                Scene3D scene = new Scene3D();
                Light   light = new Light();
                light.IsOn     = true;
                light.Position = new List <float>()
                {
                    0.0f, -3.0f, 1f, 1.0f
                };
                scene.LightList.Add(light);
                scene.AddObject(face);
                viewer3D.Scene           = scene;
                viewer3D.ShowWorldAxes   = false; // true;
                viewer3D.CameraDistance  = 0.8;
                viewer3D.CameraLatitude  = Math.PI / 24;
                viewer3D.CameraLongitude = -Math.PI / 2;
                //  viewer3D.Invalidate();
                viewer3D.StartAnimation();
            }

            normalThreadRunning = true;
            normalThread        = new Thread(new ThreadStart(NormalLoop));
            normalThread.Start();
        }
示例#2
0
        public Eye(string name, int sgn)
        {
            Object3DList = new List <Object3D>();

            //Body
            _eyeball = new Sphere3D {
                Object3DList = new List <Object3D>()
            };
            _eyeball.Generate(new List <double> {
                0.105, 32, 32
            });
            _eyeball.AmbientColor  = Color.FromArgb(255, 255, 255);
            _eyeball.DiffuseColor  = Color.FromArgb(255, 255, 255);
            _eyeball.SpecularColor = Color.White;
            _eyeball.Shininess     = 20;
            _eyeball.Name          = name;
            _eyeball.Move(sgn * 0.20, 0.4, 0.7);

            //Iris
            _iris = new Sphere3D {
                Object3DList = new List <Object3D>()
            };
            _iris.Generate(new List <double> {
                0.06, 32, 32
            });
            _iris.AmbientColor  = Color.FromArgb(0, 0, 255);
            _iris.DiffuseColor  = Color.FromArgb(0, 0, 255);
            _iris.SpecularColor = Color.Blue;
            _iris.Move(0, 0.05, 0);

            //Pupil
            _pupil = new Sphere3D();
            _pupil.Generate(new List <double> {
                .03, 32, 32
            });
            _pupil.AmbientColor  = Color.FromArgb(0, 0, 0);
            _pupil.DiffuseColor  = Color.FromArgb(0, 0, 0);
            _pupil.SpecularColor = Color.Black;
            _pupil.Move(0, 0.035, 0);
            _pupil.Shininess = 20;

            //Eyelid
            _lid = new SphereSegment3D();
            _lid.Generate(new List <double> {
                0.108, 32, 32, .01
            });
            _lid.AmbientColor  = Color.DarkSalmon;
            _lid.DiffuseColor  = Color.Black;
            _lid.SpecularColor = Color.DarkSalmon;
            _lid.Move(sgn * 0.20, 0.4, 0.7); //Same as eyeball
            _lid.Move(sgn * 0.01, 0.016, 0);
            _lid.RotateX(40);
            _lid.RotateZ(-sgn * 25);

            //Eyebrow - not part of eyeball
            _eyeBrow = new TorusSector3D();
            _eyeBrow.Generate(new List <double>()
            {
                0.15, 0.02, 32, 32, 0, Math.PI
            });
            _eyeBrow.AmbientColor  = Color.DeepPink;
            _eyeBrow.DiffuseColor  = Color.DeepPink;
            _eyeBrow.SpecularColor = Color.DeepPink;
            _eyeBrow.Move(sgn * 0.2, 0.3, 0.8);
            _eyeBrow.RotateY(-sgn * 25);
            _eyeBrow.RotateX(15);

            //Setup
            Object3DList.Add(_eyeball);
            Object3DList.Add(_lid);
            Object3DList.Add(_eyeBrow);
            _eyeball.Object3DList.Add(_iris);
            _iris.Object3DList.Add(_pupil);
        }
示例#3
0
        private void Initialize()
        {
            randomNumberGenerator = new Random();
            string faceFileName  = Path.GetDirectoryName(Application.ExecutablePath) + FROG_RELATIVE_FACE_FILE_NAME;
            string mouthFileName = Path.GetDirectoryName(Application.ExecutablePath) + FROG_RELATIVE_MOUTH_FILE_NAME;
            string eyeFileName   = Path.GetDirectoryName(Application.ExecutablePath) + FROG_RELATIVE_EYE_FILE_NAME;

            if (File.Exists(faceFileName))
            {
                face      = (Face)ObjectSerializerLibrary.ObjectXmlSerializer.ObtainSerializedObject(faceFileName, typeof(Face));
                face.Name = "Face";
                face.Generate(new List <double> {
                    128
                });
                face.Visible       = true;
                face.SpecularColor = Color.White;
                face.Shininess     = 50;
                face.AmbientColor  = Color.Green;
                // A lot of ugly hard-coding here, but OK - just for demonstration:
                face.Object3DList = new List <Object3D>();

                SphereSegment3D mouth = new SphereSegment3D();
                mouth.Name = "Mouth";
                mouth.Generate(new List <double>()
                {
                    0.85, 16, 16, 0.3
                });
                mouth.AmbientColor  = Color.White;
                mouth.DiffuseColor  = Color.White;
                mouth.SpecularColor = Color.White;
                mouth.RotateX(180);
                mouth.Shininess    = 50;
                mouth.ShowSurfaces = true;
                //mouth.RotateX(-36);
                mouth.Move(0, -0.1f, 0.85f);
                face.Object3DList.Add(mouth);



                #region generateLeftEye
                Sphere3D leftEyeBulb = new Sphere3D();
                leftEyeBulb.Generate(new List <double>()
                {
                    0.20, 64, 64
                });
                leftEyeBulb.AmbientColor  = Color.Yellow;
                leftEyeBulb.DiffuseColor  = Color.White;
                leftEyeBulb.SpecularColor = Color.White;
                leftEyeBulb.Shininess     = 50;
                leftEyeBulb.ShowSurfaces  = true;
                // x z y
                leftEyeBulb.Move(-0.60, 0.34, 0.29);
                leftEyeBulb.ShadingModel = ShadingModel.Smooth;
                leftEyeBulb.UseLight     = true;
                leftEyeBulb.Name         = "LeftEye";
                leftEyeBulb.Object3DList = new List <Object3D>();


                SphereSegment3D leftEyePupil = new SphereSegment3D();
                leftEyePupil.Generate(new List <double>()
                {
                    0.25, 16, 32, Math.PI / 2 - 0.2
                });
                leftEyePupil.AmbientColor  = Color.Black;
                leftEyePupil.DiffuseColor  = Color.Black;
                leftEyePupil.SpecularColor = Color.White;
                leftEyePupil.Shininess     = 50;
                leftEyePupil.ShowSurfaces  = true;
                leftEyePupil.Move(0, 0.05, 0);
                leftEyePupil.RotateX(90); // , 0, 0);
                                          //   leftEyePupil.RotateX(Math.PI / 2);
                                          //  leftEyePupil.Translate(-0.1375, -0.4758, 0.0725);
                leftEyePupil.ShadingModel = ShadingModel.Smooth;
                leftEyePupil.UseLight     = true;


                SphereSegment3D leftEyePupilExtended = new SphereSegment3D();
                leftEyePupilExtended.Generate(new List <double>()
                {
                    0.25, 16, 32, Math.PI / 2 - 0.2
                });
                leftEyePupilExtended.AmbientColor  = Color.Black;
                leftEyePupilExtended.DiffuseColor  = Color.Black;
                leftEyePupilExtended.SpecularColor = Color.White;
                leftEyePupilExtended.Shininess     = 50;
                leftEyePupilExtended.ShowSurfaces  = true;
                leftEyePupilExtended.Move(0, 0.05, 0);
                leftEyePupilExtended.RotateZ(13);
                leftEyePupilExtended.RotateX(87); // , 0, 0);
                //   leftEyePupilExtended.RotateX(Math.PI / 2);
                //  leftEyePupilExtended.Translate(-0.1375, -0.4758, 0.0725);
                leftEyePupilExtended.ShadingModel = ShadingModel.Smooth;
                leftEyePupilExtended.UseLight     = true;


                SphereSegment3D leftEyeLid = new SphereSegment3D();
                leftEyeLid.Name = "LeftEyeLid";
                leftEyeLid.Generate(new List <double>()
                {
                    0.21, 32, 32, 0.0
                });
                leftEyeLid.AmbientColor  = Color.Green; // Typical skin color approximation
                leftEyeLid.DiffuseColor  = Color.Green; // Typical skin color approximation
                leftEyeLid.SpecularColor = Color.White;
                leftEyeLid.Shininess     = 50;
                leftEyeLid.ShowSurfaces  = true;
                leftEyeLid.RotateX(0);
                leftEyeLid.Move(0, 0, 0);
                leftEyeBulb.Object3DList.Add(leftEyePupil);
                leftEyeBulb.Object3DList.Add(leftEyePupilExtended);
                leftEyeBulb.Object3DList.Add(leftEyeLid);
                face.Object3DList.Add(leftEyeBulb);


                SphereSegment3D lowerLeftEyeLid = new SphereSegment3D();
                lowerLeftEyeLid.Name = "LowerLeftEyeLid";
                lowerLeftEyeLid.Generate(new List <double>()
                {
                    0.21, 32, 32, 0.0
                });
                lowerLeftEyeLid.AmbientColor  = Color.Green; // Typical skin color approximation
                lowerLeftEyeLid.DiffuseColor  = Color.Green; // Typical skin color approximation
                lowerLeftEyeLid.SpecularColor = Color.White;
                lowerLeftEyeLid.Shininess     = 50;
                lowerLeftEyeLid.ShowSurfaces  = true;
                lowerLeftEyeLid.RotateX(0);
                lowerLeftEyeLid.RotateY(180);
                lowerLeftEyeLid.Move(0, 0, 0);
                leftEyeBulb.Object3DList.Add(lowerLeftEyeLid);

                //face.Object3DList.Add(leftEyeBulb);
                #endregion
                #region generateRightEye
                Sphere3D rightEyeBulb = new Sphere3D();
                rightEyeBulb.Generate(new List <double>()
                {
                    0.20, 64, 64
                });
                rightEyeBulb.AmbientColor  = Color.Yellow;
                rightEyeBulb.DiffuseColor  = Color.White;
                rightEyeBulb.SpecularColor = Color.White;
                rightEyeBulb.Shininess     = 50;
                rightEyeBulb.ShowSurfaces  = true;
                // x z y
                rightEyeBulb.Move(0.60, 0.34, 0.29);
                rightEyeBulb.ShadingModel = ShadingModel.Smooth;
                rightEyeBulb.UseLight     = true;
                rightEyeBulb.Name         = "RightEye";
                rightEyeBulb.Object3DList = new List <Object3D>();


                SphereSegment3D rightEyePupil = new SphereSegment3D();
                rightEyePupil.Generate(new List <double>()
                {
                    0.25, 16, 32, Math.PI / 2 - 0.2
                });
                rightEyePupil.AmbientColor  = Color.Black;
                rightEyePupil.DiffuseColor  = Color.Black;
                rightEyePupil.SpecularColor = Color.White;
                rightEyePupil.Shininess     = 50;
                rightEyePupil.ShowSurfaces  = true;
                rightEyePupil.Move(0, 0.05, 0);
                rightEyePupil.RotateX(90); // , 0, 0);
                                           //   rightEyePupil.RotateX(Math.PI / 2);
                                           //  rightEyePupil.Translate(-0.1375, -0.4758, 0.0725);
                rightEyePupil.ShadingModel = ShadingModel.Smooth;
                rightEyePupil.UseLight     = true;


                SphereSegment3D rightEyePupilExtended = new SphereSegment3D();
                rightEyePupilExtended.Generate(new List <double>()
                {
                    0.25, 16, 32, Math.PI / 2 - 0.2
                });
                rightEyePupilExtended.AmbientColor  = Color.Black;
                rightEyePupilExtended.DiffuseColor  = Color.Black;
                rightEyePupilExtended.SpecularColor = Color.White;
                rightEyePupilExtended.Shininess     = 50;
                rightEyePupilExtended.ShowSurfaces  = true;
                rightEyePupilExtended.Move(0, 0.05, 0);
                rightEyePupilExtended.RotateZ(13);
                rightEyePupilExtended.RotateX(93); // , 0, 0);
                                                   //   rightEyePupilExtended.RotateX(Math.PI / 2);
                                                   //  rightEyePupilExtended.Translate(-0.1375, -0.4758, 0.0725);
                rightEyePupilExtended.ShadingModel = ShadingModel.Smooth;
                rightEyePupilExtended.UseLight     = true;


                SphereSegment3D rightEyeLid = new SphereSegment3D();
                rightEyeLid.Name = "RightEyeLid";
                rightEyeLid.Generate(new List <double>()
                {
                    0.21, 32, 32, 0.0
                });
                rightEyeLid.AmbientColor  = Color.Green; // Typical skin color approximation
                rightEyeLid.DiffuseColor  = Color.Green; // Typical skin color approximation
                rightEyeLid.SpecularColor = Color.White;
                rightEyeLid.Shininess     = 50;
                rightEyeLid.ShowSurfaces  = true;
                rightEyeLid.RotateX(0);
                rightEyeLid.Move(0, 0, 0);
                rightEyeBulb.Object3DList.Add(rightEyePupil);
                rightEyeBulb.Object3DList.Add(rightEyePupilExtended);
                rightEyeBulb.Object3DList.Add(rightEyeLid);
                face.Object3DList.Add(rightEyeBulb);


                SphereSegment3D lowerRightEyeLid = new SphereSegment3D();
                lowerRightEyeLid.Name = "LowerRightEyeLid";
                lowerRightEyeLid.Generate(new List <double>()
                {
                    0.21, 32, 32, 0.0
                });
                lowerRightEyeLid.AmbientColor  = Color.Green; // Typical skin color approximation
                lowerRightEyeLid.DiffuseColor  = Color.Green; // Typical skin color approximation
                lowerRightEyeLid.SpecularColor = Color.White;
                lowerRightEyeLid.Shininess     = 50;
                lowerRightEyeLid.ShowSurfaces  = true;
                lowerRightEyeLid.RotateX(0);
                lowerRightEyeLid.RotateY(180);
                lowerRightEyeLid.Move(0, 0, 0);
                rightEyeBulb.Object3DList.Add(lowerRightEyeLid);

                #endregion
                face.Move(0, 0, -0.5);
                leftEyeBulb.Move(-0.1375, -0.403, 0.645);
                rightEyeBulb.Move(0.1375, -0.403, 0.645);

                // Close eyes to start with:
                leftEyeLid.RotateX(0);
                rightEyeLid.RotateX(0);
                eyesClosed = true;


                Scene3D scene = new Scene3D();
                Light   light = new Light();
                light.IsOn     = true;
                light.Position = new List <float>()
                {
                    0.0f, -3.0f, 1f, 1.0f
                };
                scene.LightList.Add(light);
                scene.AddObject(face);



                viewer3D.Scene           = scene;
                viewer3D.ShowWorldAxes   = false; // true;
                viewer3D.CameraDistance  = 1.8;
                viewer3D.CameraLatitude  = 0.3;
                viewer3D.CameraLongitude = -1.3; //-Math.PI / 2;

                //viewer3D.Invalidate();

                viewer3D.StartAnimation();
            }

            normalThreadRunning = true;
            normalThread        = new Thread(new ThreadStart(NormalLoop));
            normalThread.Start();
        }